2009-01-10 22:22:16 +01:00
|
|
|
class Finance::BalancingController < ApplicationController
|
|
|
|
before_filter :authenticate_finance
|
2009-01-30 22:27:55 +01:00
|
|
|
verify :method => :post, :only => [:close, :close_direct]
|
2009-01-29 21:28:22 +01:00
|
|
|
|
2009-01-10 22:22:16 +01:00
|
|
|
def index
|
2009-01-19 16:40:06 +01:00
|
|
|
@financial_transactions = FinancialTransaction.find(:all, :order => "created_on DESC", :limit => 8)
|
2009-01-30 22:27:55 +01:00
|
|
|
@orders = Order.finished_not_closed
|
2009-01-19 16:40:06 +01:00
|
|
|
@unpaid_invoices = Invoice.unpaid
|
|
|
|
end
|
|
|
|
|
|
|
|
def list
|
2009-01-10 22:22:16 +01:00
|
|
|
@orders = Order.finished.paginate :page => params[:page], :per_page => 10, :order => 'ends DESC'
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@order = Order.find(params[:id])
|
|
|
|
@comments = @order.comments
|
|
|
|
case params[:view]
|
|
|
|
when 'editResults'
|
2009-01-29 21:28:22 +01:00
|
|
|
render :partial => 'edit_results_by_articles'
|
2009-01-10 22:22:16 +01:00
|
|
|
when 'groupsOverview'
|
2009-01-29 21:28:22 +01:00
|
|
|
render :partial => 'shared/articles_by_groups', :locals => {:order => @order}
|
2009-01-10 22:22:16 +01:00
|
|
|
when 'articlesOverview'
|
2009-01-29 21:28:22 +01:00
|
|
|
render :partial => 'shared/articles_by_articles', :locals => {:order => @order}
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-29 21:28:22 +01:00
|
|
|
def edit_note
|
2009-01-10 22:22:16 +01:00
|
|
|
@order = Order.find(params[:id])
|
2009-01-29 21:28:22 +01:00
|
|
|
render :partial => 'edit_note'
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|
|
|
|
|
2009-01-29 21:28:22 +01:00
|
|
|
def update_note
|
|
|
|
@order = Order.find(params[:id])
|
2009-01-10 22:22:16 +01:00
|
|
|
render :update do |page|
|
2009-01-29 21:28:22 +01:00
|
|
|
if @order.update_attributes(params[:order])
|
|
|
|
page["note"].replace_html simple_format(@order.note)
|
2009-01-10 22:22:16 +01:00
|
|
|
page["edit_box"].hide
|
|
|
|
else
|
2009-01-29 21:28:22 +01:00
|
|
|
page["results"].replace_html :partial => "edit_note"
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-29 21:28:22 +01:00
|
|
|
#TODO: Implement create/update of articles/article_prices...
|
|
|
|
# def new_order_article
|
|
|
|
# @order = Order.find(params[:id])
|
|
|
|
# order_article = @order.order_articles.build(:tax => 7, :deposit => 0)
|
|
|
|
# render :update do |page|
|
|
|
|
# page["edit_box"].replace_html :partial => "new_order_article", :locals => {:order_article => order_article}
|
|
|
|
# page["edit_box"].show
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# def create_order_article
|
|
|
|
# @order = Order.find(params[:order_article][:order_id])
|
|
|
|
# order_article = OrderArticle.new(params[:order_article])
|
|
|
|
#
|
|
|
|
# render :update do |page|
|
|
|
|
# if order_article.save
|
|
|
|
# page["edit_box"].hide
|
|
|
|
# page["summary"].replace_html :partial => 'summary'
|
|
|
|
# page.insert_html :bottom, "result_table", :partial => "order_article_result", :locals => {:order_article => order_article}
|
|
|
|
# page["order_article_#{order_article.id}"].visual_effect :highlight, :duration => 2
|
|
|
|
# page["group_order_articles_#{order_article.id}"].show
|
|
|
|
# else
|
|
|
|
# page["edit_box"].replace_html :partial => "new_order_article", :locals => {:order_article => order_article}
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# def editArticleResult
|
|
|
|
# @article = OrderArticleResult.find(params[:id])
|
|
|
|
# render :update do |page|
|
|
|
|
# page["edit_box"].replace_html :partial => 'editArticleResult'
|
|
|
|
# page["edit_box"].show
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# def updateArticleResult
|
|
|
|
# @article = OrderArticleResult.find(params[:id])
|
|
|
|
# @article.attributes=(params[:order_article_result]) # update attributes but doesn't save
|
|
|
|
# @article.make_gross
|
|
|
|
# @order = @article.order
|
|
|
|
# @ordered_articles = @order.order_article_results
|
|
|
|
# @group_orders = @order.group_order_results
|
|
|
|
# render :update do |page|
|
|
|
|
# if @article.save
|
|
|
|
# page["edit_box"].hide
|
|
|
|
# page["summary"].replace_html :partial => 'summary'
|
|
|
|
# page["summary"].visual_effect :highlight, :duration => 2
|
|
|
|
# page["order_article_result_#{@article.id}"].replace_html :partial => 'articleResult'
|
|
|
|
# page['order_article_result_'+@article.id.to_s].visual_effect :highlight, :delay => 0.5, :duration => 2
|
|
|
|
# page["group_order_article_results_#{@article.id}"].replace_html :partial => "groupOrderArticleResults"
|
|
|
|
# else
|
|
|
|
# page['edit_box'].replace_html :partial => 'editArticleResult'
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
|
|
|
|
def destroy_order_article
|
|
|
|
order_article = OrderArticle.find(params[:id])
|
|
|
|
order_article.destroy
|
|
|
|
@order = order_article.order
|
2009-01-10 22:22:16 +01:00
|
|
|
render :update do |page|
|
2009-01-29 21:28:22 +01:00
|
|
|
page["order_article_#{order_article.id}"].remove
|
|
|
|
page["group_order_articles_#{order_article.id}"].remove
|
|
|
|
page["summary"].replace_html :partial => 'summary', :locals => {:order => @order}
|
|
|
|
page["summary"].visual_effect :highlight, :duration => 2
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-29 21:28:22 +01:00
|
|
|
def new_group_order_article
|
|
|
|
group_order_article = OrderArticle.find(params[:id]).group_order_articles.build
|
2009-01-10 22:22:16 +01:00
|
|
|
render :update do |page|
|
2009-01-29 21:28:22 +01:00
|
|
|
page["edit_box"].replace_html :partial => "new_group_order_article",
|
|
|
|
:locals => {:group_order_article => group_order_article}
|
2009-01-10 22:22:16 +01:00
|
|
|
page["edit_box"].show
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-29 21:28:22 +01:00
|
|
|
# Creates a new GroupOrderArticle
|
|
|
|
# If the the chosen Ordergroup hasn't ordered yet, a GroupOrder will also be created
|
|
|
|
def create_group_order_article
|
|
|
|
goa = GroupOrderArticle.new(params[:group_order_article])
|
|
|
|
order_article = goa.order_article
|
|
|
|
order = order_article.order
|
|
|
|
|
|
|
|
# creates a new GroupOrder if necessary
|
|
|
|
group_order = GroupOrder.first :conditions => {:order_id => order.id, :ordergroup_id => goa.ordergroup_id}
|
|
|
|
unless group_order
|
|
|
|
goa.create_group_order(:order_id => order.id, :ordergroup_id => goa.ordergroup_id)
|
|
|
|
else
|
|
|
|
goa.group_order = group_order
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|
2009-01-29 21:28:22 +01:00
|
|
|
|
2009-01-10 22:22:16 +01:00
|
|
|
render :update do |page|
|
2009-01-29 21:28:22 +01:00
|
|
|
if goa.save
|
|
|
|
goa.group_order.update_price! # Updates the price attribute of new GroupOrder
|
2009-01-10 22:22:16 +01:00
|
|
|
page["edit_box"].hide
|
|
|
|
|
2009-01-29 21:28:22 +01:00
|
|
|
page["group_order_articles_#{order_article.id}"].replace_html :partial => 'group_order_articles',
|
|
|
|
:locals => {:order_article => order_article}
|
|
|
|
page["group_order_article_#{goa.id}"].visual_effect :highlight, :duration => 2
|
|
|
|
|
|
|
|
page["summary"].replace_html :partial => 'summary', :locals => {:order => order}
|
|
|
|
page["order_profit"].visual_effect :highlight, :duration => 2
|
2009-01-10 22:22:16 +01:00
|
|
|
else
|
2009-01-29 21:28:22 +01:00
|
|
|
page["edit_box"].replace_html :partial => "new_group_order_article",
|
|
|
|
:locals => {:group_order_article => goa}
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-29 21:28:22 +01:00
|
|
|
def edit_group_order_article
|
|
|
|
group_order_article = GroupOrderArticle.find(params[:id])
|
|
|
|
render :partial => 'edit_group_order_article',
|
|
|
|
:locals => {:group_order_article => group_order_article}
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|
|
|
|
|
2009-01-29 21:28:22 +01:00
|
|
|
def update_group_order_article
|
|
|
|
goa = GroupOrderArticle.find(params[:id])
|
|
|
|
|
2009-01-10 22:22:16 +01:00
|
|
|
render :update do |page|
|
2009-01-29 21:28:22 +01:00
|
|
|
if goa.update_attributes(params[:group_order_article])
|
|
|
|
goa.group_order.update_price! # Updates the price attribute of new GroupOrder
|
2009-01-10 22:22:16 +01:00
|
|
|
|
|
|
|
page["edit_box"].hide
|
2009-01-29 21:28:22 +01:00
|
|
|
page["group_order_articles_#{goa.order_article.id}"].replace_html :partial => 'group_order_articles',
|
|
|
|
:locals => {:order_article => goa.order_article}
|
|
|
|
page["summary"].replace_html :partial => 'summary', :locals => {:order => goa.order_article.order}
|
|
|
|
page["order_profit"].visual_effect :highlight, :duration => 2
|
2009-01-10 22:22:16 +01:00
|
|
|
else
|
2009-01-29 21:28:22 +01:00
|
|
|
page["edit_box"].replace_html :partial => 'edit_group_order_article'
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-29 21:28:22 +01:00
|
|
|
def destroy_group_order_article
|
|
|
|
goa = GroupOrderArticle.find(params[:id])
|
|
|
|
goa.destroy
|
|
|
|
goa.group_order.update_price! # Updates the price attribute of new GroupOrder
|
|
|
|
|
2009-01-10 22:22:16 +01:00
|
|
|
render :update do |page|
|
2009-01-29 21:28:22 +01:00
|
|
|
page["edit_box"].hide
|
|
|
|
page["group_order_articles_#{goa.order_article.id}"].replace_html :partial => 'group_order_articles',
|
|
|
|
:locals => {:order_article => goa.order_article}
|
|
|
|
page["group_order_article_#{goa.id}"].visual_effect :highlight, :duration => 2
|
|
|
|
page["summary"].replace_html :partial => 'summary', :locals => {:order => goa.order_article.order}
|
|
|
|
page["order_profit"].visual_effect :highlight, :duration => 2
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-14 12:46:01 +01:00
|
|
|
# before the order will booked, a view lists all Ordergroups and its order_prices
|
2009-01-10 22:22:16 +01:00
|
|
|
def confirm
|
|
|
|
@order = Order.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2009-01-14 12:46:01 +01:00
|
|
|
# Balances the Order, Update of the Ordergroup.account_balances
|
2009-01-10 22:22:16 +01:00
|
|
|
def close
|
|
|
|
@order = Order.find(params[:id])
|
|
|
|
begin
|
2009-01-30 22:27:55 +01:00
|
|
|
@order.close!(@current_user)
|
2009-01-10 22:22:16 +01:00
|
|
|
flash[:notice] = "Bestellung wurde erfolgreich abgerechnet, die Kontostände aktualisiert."
|
|
|
|
redirect_to :action => "index"
|
|
|
|
rescue => e
|
|
|
|
flash[:error] = "Ein Fehler ist beim Abrechnen aufgetreten: " + e
|
2009-01-30 22:27:55 +01:00
|
|
|
redirect_to :action => "new", :id => @order
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-29 21:28:22 +01:00
|
|
|
# Close the order directly, without automaticly updating ordergroups account balances
|
|
|
|
def close_direct
|
2009-01-10 22:22:16 +01:00
|
|
|
@order = Order.find(params[:id])
|
2009-01-29 21:28:22 +01:00
|
|
|
if @order.finished?
|
|
|
|
@order.update_attributes(:state => 'closed', :updated_by => @current_user)
|
2009-01-10 22:22:16 +01:00
|
|
|
flash[:notice] = 'Die Bestellung wurde auf "gebucht" gesetzt.'
|
|
|
|
redirect_to :action => 'listOrders', :id => @order
|
|
|
|
else
|
|
|
|
flash[:error] = 'Die Bestellung ist noch nicht beendet.'
|
|
|
|
redirect_to :action => 'listOrders', :id => @order
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|