2012-04-16 08:48:01 +02:00
|
|
|
# encoding: utf-8
|
2009-01-10 22:22:16 +01:00
|
|
|
class Finance::BalancingController < ApplicationController
|
|
|
|
before_filter :authenticate_finance
|
2012-05-12 10:55:20 +02:00
|
|
|
|
2009-01-10 22:22:16 +01:00
|
|
|
def index
|
2012-06-21 17:19:00 +02:00
|
|
|
@financial_transactions = FinancialTransaction.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
|
2012-07-27 18:03:46 +02:00
|
|
|
@order = Order.find(params[:order_id])
|
|
|
|
flash.now.alert = "Achtung, Bestellung wurde schon abgerechnet" if @order.closed?
|
2009-01-10 22:22:16 +01:00
|
|
|
@comments = @order.comments
|
2009-04-01 00:46:01 +02:00
|
|
|
|
|
|
|
if params['sort']
|
2009-05-04 17:56:52 +02:00
|
|
|
sort = case params['sort']
|
2009-04-01 00:46:01 +02:00
|
|
|
when "name" then "articles.name"
|
|
|
|
when "order_number" then "articles.order_number"
|
|
|
|
when "name_reverse" then "articles.name DESC"
|
|
|
|
when "order_number_reverse" then "articles.order_number DESC"
|
|
|
|
end
|
|
|
|
else
|
2009-05-04 17:56:52 +02:00
|
|
|
sort = "id"
|
2009-04-01 00:46:01 +02:00
|
|
|
end
|
|
|
|
|
2012-05-12 11:18:46 +02:00
|
|
|
@articles = @order.order_articles.ordered.includes(:article).order(sort)
|
2009-05-04 17:56:52 +02:00
|
|
|
|
2009-04-03 17:50:17 +02:00
|
|
|
if params[:sort] == "order_number"
|
2012-05-12 11:18:46 +02:00
|
|
|
@articles = @articles.to_a.sort { |a,b| a.article.order_number.gsub(/[^[:digit:]]/, "").to_i <=> b.article.order_number.gsub(/[^[:digit:]]/, "").to_i }
|
2009-04-03 17:50:17 +02:00
|
|
|
elsif params[:sort] == "order_number_reverse"
|
2012-05-12 11:18:46 +02:00
|
|
|
@articles = @articles.to_a.sort { |a,b| b.article.order_number.gsub(/[^[:digit:]]/, "").to_i <=> a.article.order_number.gsub(/[^[:digit:]]/, "").to_i }
|
2009-04-03 17:50:17 +02:00
|
|
|
end
|
|
|
|
|
2012-07-27 18:03:46 +02:00
|
|
|
render layout: false if request.xhr?
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|
|
|
|
|
2012-07-27 18:03:46 +02:00
|
|
|
def edit_note
|
|
|
|
@order = Order.find(params[:id])
|
|
|
|
render :layout => false
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|
|
|
|
|
2012-07-27 18:03:46 +02:00
|
|
|
def update_note
|
|
|
|
@order = Order.find(params[:id])
|
|
|
|
if @order.update_attributes(params[:order])
|
|
|
|
render :layout => false
|
2009-01-29 21:28:22 +01:00
|
|
|
else
|
2012-07-27 18:03:46 +02:00
|
|
|
render :action => :edit_note, :layout => false
|
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])
|
2012-07-27 18:03:46 +02:00
|
|
|
@order.close!(@current_user)
|
|
|
|
redirect_to finance_balancing_url, notice: "Bestellung wurde erfolgreich abgerechnet, die Kontostände aktualisiert."
|
|
|
|
|
|
|
|
rescue => error
|
|
|
|
redirect_to finance_balancing_url, alert: "Ein Fehler ist beim Abrechnen aufgetreten: #{error.message}"
|
2009-01-10 22:22:16 +01:00
|
|
|
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])
|
2012-07-27 18:03:46 +02:00
|
|
|
@order.close_direct!(@current_user)
|
|
|
|
redirect_to finance_balancing_url, notice: "Bestellung wurde geschlossen."
|
|
|
|
rescue => error
|
|
|
|
redirect_to finance_balancing_url, alert: "Bestellung kann nicht geschlossen werden: #{error.message}"
|
2009-01-10 22:22:16 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|