diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb new file mode 100644 index 00000000..85422eb7 --- /dev/null +++ b/app/controllers/finance/balancing_controller.rb @@ -0,0 +1,244 @@ +class Finance::BalancingController < ApplicationController + before_filter :authenticate_finance + + def index + @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' + render :partial => 'editResults' + when 'groupsOverview' + render :partial => 'groupsOverview' + when 'articlesOverview' + render :partial => 'articlesOverview' + when "editNote" + render :partial => "editNote" + end + end + + def newArticleResult + @order = Order.find(params[:id]) + @article = @order.order_article_results.build(:tax => 7, :deposit => 0) + render :update do |page| + page["edit_box"].replace_html :partial => "newArticleResult" + page["edit_box"].show + end + end + + def createArticleResult + render :update do |page| + @article = OrderArticleResult.new(params[:order_article_result]) + @article.fc_markup = APP_CONFIG[:price_markup] + @article.make_gross if @article.tax && @article.deposit && @article.net_price + if @article.valid? + @article.save + @order = @article.order + page["edit_box"].hide + page["order_summary"].replace_html :partial => 'summary' + page.insert_html :bottom, "result_table", :partial => "articleResults" + page["order_article_result_#{@article.id}"].visual_effect :highlight, :duration => 2 + page["group_order_article_results_#{@article.id}"].show + else + page["edit_box"].replace_html :partial => "newArticleResult" + 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["order_summary"].replace_html :partial => 'summary' + page["order_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 destroyArticleResult + if @article = OrderArticleResult.find(params[:id]).destroy + @order = @article.order + render :update do |page| + page["order_article_result_#{@article.id}"].remove + page["group_order_article_results_#{@article.id}"].remove + page["order_summary"].replace_html :partial => 'summary' + page["order_summary"].visual_effect :highlight, :duration => 2 + end + end + end + + def newGroupResult + @result = OrderArticleResult.find(params[:id]).group_order_article_results.build + render :update do |page| + page["edit_box"].replace_html :partial => "newGroupResult" + page["edit_box"].show + end + end + + # Creates a new GroupOrderArticleResult + # If the the chosen OrderGroup hasn't ordered yet, a GroupOrderResult will created + def createGroupResult + @result = GroupOrderArticleResult.new(params[:group_order_article_result]) + order = @result.order_article_result.order + orderGroup = OrderGroup.find(params[:group_order_article_result][:group_order_result_id]) + # creates a new GroupOrderResult if necessary + unless @result.group_order_result = GroupOrderResult.find(:first, + :conditions => ["group_order_results.group_name = ? AND group_order_results.order_id = ?", orderGroup.name, order.id ]) + @result.group_order_result = GroupOrderResult.create(:order => order, :group_name => orderGroup.name) + end + render :update do |page| + if @result.valid? && @result.save + @result.group_order_result.updatePrice #updates the price attribute + article = @result.order_article_result + page["edit_box"].hide + page.insert_html :after, "groups_results_#{article.id}", :partial => "groupResults" + page["group_order_article_result_#{@result.id}"].visual_effect :highlight, :duration => 2 + page["groups_amount"].replace_html number_to_currency(article.order.sumPrice('groups')) + page["fcProfit"].replace_html number_to_currency(article.order.fcProfit) + page["fcProfit"].visual_effect :highlight, :duration => 2 + + # get the new sums for quantity and price and replace it + total = article.total + page["totalArticleQuantity_#{article.id}"].replace_html total[:quantity] + page["totalArticlePrice_#{article.id}"].replace_html number_to_currency(total[:price]) + else + page["edit_box"].replace_html :partial => "newGroupResult" + end + end + end + + def updateGroupResult + @result = GroupOrderArticleResult.find(params[:id]) + render :update do |page| + if params[:group_order_article_result] + if @result.update_attribute(:quantity, params[:group_order_article_result][:quantity]) + order = @result.group_order_result.order + groups_amount = order.sumPrice("groups") + article = @result.order_article_result + total = article.total + + page["edit_box"].hide + page["groups_amount"].replace_html number_to_currency(groups_amount) + page["fcProfit"].replace_html number_to_currency(order.fcProfit) + page["groups_amount"].visual_effect :highlight, :duration => 2 + page["fcProfit"].visual_effect :highlight, :duration => 2 + page["group_order_article_result_#{@result.id}"].replace_html :partial => "groupResult" + page["group_order_article_result_#{@result.id}"].visual_effect :highlight, :duration => 2 + page["totalArticleQuantity_#{article.id}"].replace_html total[:quantity] + page["totalArticlePrice_#{article.id}"].replace_html total[:price] + page["sum_of_article_#{article.id}"].visual_effect :highlight, :duration => 2 + end + else + page["edit_box"].replace_html :partial => 'editGroupResult' + page["edit_box"].show + end + end + end + + def destroyGroupResult + @result = GroupOrderArticleResult.find(params[:id]) + if @result.destroy + render :update do |page| + article = @result.order_article_result + page["group_order_article_result_#{@result.id}"].remove + page["groups_amount"].replace_html number_to_currency(article.order.sumPrice('groups')) + page["fcProfit"].replace_html number_to_currency(article.order.fcProfit) + page["fcProfit"].visual_effect :highlight, :duration => 2 + total = article.total # get total quantity and price for the ArticleResult + page["totalArticleQuantity_#{article.id}"].replace_html total[:quantity] + page["totalArticleQuantity_#{article.id}"].visual_effect :highlight, :duration => 2 + page["totalArticlePrice_#{article.id}"].replace_html number_to_currency(total[:price]) + page["totalArticlePrice_#{article.id}"].visual_effect :highlight, :duration => 2 + end + end + end + + def editOrderSummary + @order = Order.find(params[:id]) + render :update do |page| + page["edit_box"].replace_html :partial => 'editSummary' + page["edit_box"].show + end + end + + def updateOrderSummary + @order = Order.find(params[:id]) + render :update do |page| + if @order.update_attributes(params[:order]) + page["edit_box"].hide + page["order_summary"].replace_html :partial => "summary" + page["clear_invoice"].visual_effect :highlight, :duration => 2 + else + page["edit_box"].replace_html :partial => 'editSummary' + end + end + end + + def updateOrderNote + @order = Order.find(params[:id]) + render :update do |page| + if @order.update_attribute(:note, params[:order][:note]) + page["note"].replace_html simple_format(@order.note) + page["results"].replace_html :partial => "groupsOverview" + else + page["results"].replace_html :partial => "editNote" + end + end + end + + # before the order will booked, a view lists all OrderGroups and its order_prices + def confirm + @order = Order.find(params[:id]) + end + + # Balances the Order, Update of the OrderGroup.account_balances + def close + @order = Order.find(params[:id]) + begin + @order.balance(@current_user) + 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 + redirect_to :action =>"editOrder", :id => @order + end + end + + # Set all GroupOrders that belong to this finished order to status 'booked'. + def setAllBooked + @order = Order.find(params[:id]) + if (@order.finished?) + @order.booked = true + @order.updated_by = @current_user + @order.save! + 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 diff --git a/app/controllers/finance_controller.rb b/app/controllers/finance_controller.rb index 067f7513..5761ea93 100644 --- a/app/controllers/finance_controller.rb +++ b/app/controllers/finance_controller.rb @@ -1,259 +1,10 @@ class FinanceController < ApplicationController before_filter :authenticate_finance - - # Messages - MSG_TRANSACTION_SUCCESS = 'Transaktion erfolgreich angelegt.' - ERROR_TRANSACTION_FAILED = 'Transaktion konnte nicht angelegt werden!' - MSG_ORDER_SET_BOOKED = 'Die Bestellung wurde auf "gebucht" gesetzt.' - ERROR_ORDER_NOT_FINISHED = 'Die Bestellung ist noch nicht beendet.' - MSG_ORDER_BALANCED = "Bestellung wurde erfolgreich abgerechnet, die Kontostände aktualisiert." - ERROR_BALANCE_ORDER = "Ein Fehler ist beim Abrechnen aufgetreten: " - + def index @financial_transactions = FinancialTransaction.find(:all, :order => "created_on DESC", :limit => 8) @orders = Order.find(:all, :conditions => 'finished = 1 AND booked = 0', :order => 'ends DESC') @unpaid_invoices = Invoice.unpaid end - # list finished orders for the order-clearing - def listOrders - @orders = Order.paginate_all_by_finished true, :page => params[:page], :per_page => 10, :order => 'ends DESC' - end - - def editOrder - @order = Order.find(params[:id]) - @comments = @order.comments - case params[:view] - when 'editResults' - render :partial => 'editResults' - when 'groupsOverview' - render :partial => 'groupsOverview' - when 'articlesOverview' - render :partial => 'articlesOverview' - when "editNote" - render :partial => "editNote" - end - end - - def newArticleResult - @order = Order.find(params[:id]) - @article = @order.order_article_results.build(:tax => 7, :deposit => 0) - render :update do |page| - page["edit_box"].replace_html :partial => "newArticleResult" - page["edit_box"].show - end - end - - def createArticleResult - render :update do |page| - @article = OrderArticleResult.new(params[:order_article_result]) - @article.fc_markup = APP_CONFIG[:price_markup] - @article.make_gross if @article.tax && @article.deposit && @article.net_price - if @article.valid? - @article.save - @order = @article.order - page["edit_box"].hide - page["order_summary"].replace_html :partial => 'summary' - page.insert_html :bottom, "result_table", :partial => "articleResults" - page["order_article_result_#{@article.id}"].visual_effect :highlight, :duration => 2 - page["group_order_article_results_#{@article.id}"].show - else - page["edit_box"].replace_html :partial => "newArticleResult" - 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["order_summary"].replace_html :partial => 'summary' - page["order_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 destroyArticleResult - if @article = OrderArticleResult.find(params[:id]).destroy - @order = @article.order - render :update do |page| - page["order_article_result_#{@article.id}"].remove - page["group_order_article_results_#{@article.id}"].remove - page["order_summary"].replace_html :partial => 'summary' - page["order_summary"].visual_effect :highlight, :duration => 2 - end - end - end - - def newGroupResult - @result = OrderArticleResult.find(params[:id]).group_order_article_results.build - render :update do |page| - page["edit_box"].replace_html :partial => "newGroupResult" - page["edit_box"].show - end - end - - # Creates a new GroupOrderArticleResult - # If the the chosen OrderGroup hasn't ordered yet, a GroupOrderResult will created - def createGroupResult - @result = GroupOrderArticleResult.new(params[:group_order_article_result]) - order = @result.order_article_result.order - orderGroup = OrderGroup.find(params[:group_order_article_result][:group_order_result_id]) - # creates a new GroupOrderResult if necessary - unless @result.group_order_result = GroupOrderResult.find(:first, - :conditions => ["group_order_results.group_name = ? AND group_order_results.order_id = ?", orderGroup.name, order.id ]) - @result.group_order_result = GroupOrderResult.create(:order => order, :group_name => orderGroup.name) - end - render :update do |page| - if @result.valid? && @result.save - @result.group_order_result.updatePrice #updates the price attribute - article = @result.order_article_result - page["edit_box"].hide - page.insert_html :after, "groups_results_#{article.id}", :partial => "groupResults" - page["group_order_article_result_#{@result.id}"].visual_effect :highlight, :duration => 2 - page["groups_amount"].replace_html number_to_currency(article.order.sumPrice('groups')) - page["fcProfit"].replace_html number_to_currency(article.order.fcProfit) - page["fcProfit"].visual_effect :highlight, :duration => 2 - - # get the new sums for quantity and price and replace it - total = article.total - page["totalArticleQuantity_#{article.id}"].replace_html total[:quantity] - page["totalArticlePrice_#{article.id}"].replace_html number_to_currency(total[:price]) - else - page["edit_box"].replace_html :partial => "newGroupResult" - end - end - end - - def updateGroupResult - @result = GroupOrderArticleResult.find(params[:id]) - render :update do |page| - if params[:group_order_article_result] - if @result.update_attribute(:quantity, params[:group_order_article_result][:quantity]) - order = @result.group_order_result.order - groups_amount = order.sumPrice("groups") - article = @result.order_article_result - total = article.total - - page["edit_box"].hide - page["groups_amount"].replace_html number_to_currency(groups_amount) - page["fcProfit"].replace_html number_to_currency(order.fcProfit) - page["groups_amount"].visual_effect :highlight, :duration => 2 - page["fcProfit"].visual_effect :highlight, :duration => 2 - page["group_order_article_result_#{@result.id}"].replace_html :partial => "groupResult" - page["group_order_article_result_#{@result.id}"].visual_effect :highlight, :duration => 2 - page["totalArticleQuantity_#{article.id}"].replace_html total[:quantity] - page["totalArticlePrice_#{article.id}"].replace_html total[:price] - page["sum_of_article_#{article.id}"].visual_effect :highlight, :duration => 2 - end - else - page["edit_box"].replace_html :partial => 'editGroupResult' - page["edit_box"].show - end - end - end - - def destroyGroupResult - @result = GroupOrderArticleResult.find(params[:id]) - if @result.destroy - render :update do |page| - article = @result.order_article_result - page["group_order_article_result_#{@result.id}"].remove - page["groups_amount"].replace_html number_to_currency(article.order.sumPrice('groups')) - page["fcProfit"].replace_html number_to_currency(article.order.fcProfit) - page["fcProfit"].visual_effect :highlight, :duration => 2 - total = article.total # get total quantity and price for the ArticleResult - page["totalArticleQuantity_#{article.id}"].replace_html total[:quantity] - page["totalArticleQuantity_#{article.id}"].visual_effect :highlight, :duration => 2 - page["totalArticlePrice_#{article.id}"].replace_html number_to_currency(total[:price]) - page["totalArticlePrice_#{article.id}"].visual_effect :highlight, :duration => 2 - end - end - end - - def editOrderSummary - @order = Order.find(params[:id]) - render :update do |page| - page["edit_box"].replace_html :partial => 'editSummary' - page["edit_box"].show - end - end - - def updateOrderSummary - @order = Order.find(params[:id]) - render :update do |page| - if @order.update_attributes(params[:order]) - page["edit_box"].hide - page["order_summary"].replace_html :partial => "summary" - page["clear_invoice"].visual_effect :highlight, :duration => 2 - else - page["edit_box"].replace_html :partial => 'editSummary' - end - end - end - - def updateOrderNote - @order = Order.find(params[:id]) - render :update do |page| - if @order.update_attribute(:note, params[:order][:note]) - page["note"].replace_html simple_format(@order.note) - page["results"].replace_html :partial => "groupsOverview" - else - page["results"].replace_html :partial => "editNote" - end - end - end - - # before the order will booked, a view lists all OrderGroups and its order_prices - def confirmOrder - @order = Order.find(params[:id]) - end - - # Balances the Order, Update of the OrderGroup.account_balances - def balanceOrder - @order = Order.find(params[:id]) - begin - @order.balance(@current_user) - flash[:notice] = MSG_ORDER_BALANCED - redirect_to :action => "index" - rescue => e - flash[:error] = ERROR_BALANCE_ORDER + e - redirect_to :action =>"editOrder", :id => @order - end - end - - # Set all GroupOrders that belong to this finished order to status 'booked'. - def setAllBooked - @order = Order.find(params[:id]) - if (@order.finished?) - @order.booked = true - @order.updated_by = @current_user - @order.save! - flash[:notice] = MSG_ORDER_SET_BOOKED - redirect_to :action => 'listOrders', :id => @order - else - flash[:error] = ERROR_ORDER_NOT_FINISHED - redirect_to :action => 'listOrders', :id => @order - end - end - end \ No newline at end of file diff --git a/app/helpers/finance/orders_helper.rb b/app/helpers/finance/orders_helper.rb new file mode 100644 index 00000000..f399dcc8 --- /dev/null +++ b/app/helpers/finance/orders_helper.rb @@ -0,0 +1,2 @@ +module Finance::OrdersHelper +end diff --git a/app/models/order.rb b/app/models/order.rb index 90031439..8d85b3d9 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -45,7 +45,10 @@ class Order < ActiveRecord::Base # easyier find of next or previous model acts_as_ordered :order => "ends" - + + named_scope :finished, :conditions => { :finished => true }, + :order => 'ends DESC', :include => :supplier + # Custom attribute setter that accepts decimal numbers using localized decimal separator. def invoice_amount=(amount) self[:invoice_amount] = String.delocalized_decimal(amount) diff --git a/app/views/finance/_articleResult.haml b/app/views/finance/balancing/_articleResult.haml similarity index 100% rename from app/views/finance/_articleResult.haml rename to app/views/finance/balancing/_articleResult.haml diff --git a/app/views/finance/_articleResultForm.haml b/app/views/finance/balancing/_articleResultForm.haml similarity index 100% rename from app/views/finance/_articleResultForm.haml rename to app/views/finance/balancing/_articleResultForm.haml diff --git a/app/views/finance/_articleResults.haml b/app/views/finance/balancing/_articleResults.haml similarity index 100% rename from app/views/finance/_articleResults.haml rename to app/views/finance/balancing/_articleResults.haml diff --git a/app/views/finance/_articlesOverview.haml b/app/views/finance/balancing/_articlesOverview.haml similarity index 100% rename from app/views/finance/_articlesOverview.haml rename to app/views/finance/balancing/_articlesOverview.haml diff --git a/app/views/finance/_editArticleResult.haml b/app/views/finance/balancing/_editArticleResult.haml similarity index 100% rename from app/views/finance/_editArticleResult.haml rename to app/views/finance/balancing/_editArticleResult.haml diff --git a/app/views/finance/_editGroupResult.haml b/app/views/finance/balancing/_editGroupResult.haml similarity index 100% rename from app/views/finance/_editGroupResult.haml rename to app/views/finance/balancing/_editGroupResult.haml diff --git a/app/views/finance/_editNote.haml b/app/views/finance/balancing/_editNote.haml similarity index 71% rename from app/views/finance/_editNote.haml rename to app/views/finance/balancing/_editNote.haml index 9d1084ad..dbba65c3 100644 --- a/app/views/finance/_editNote.haml +++ b/app/views/finance/balancing/_editNote.haml @@ -7,4 +7,4 @@ %p = submit_tag "Speichern" | - = link_to_remote 'Abbrechen', :update => 'results', :url => { :action => 'editOrder', :id => @order, :view => 'groupsOverview' }, :before => "Element.show('loader')", :success => "Element.hide('loader')" \ No newline at end of file + = link_to_remote 'Abbrechen', :update => 'results', :url => { :action => 'edit', :id => @order, :view => 'groupsOverview' }, :before => "Element.show('loader')", :success => "Element.hide('loader')" \ No newline at end of file diff --git a/app/views/finance/_editResults.haml b/app/views/finance/balancing/_editResults.haml similarity index 100% rename from app/views/finance/_editResults.haml rename to app/views/finance/balancing/_editResults.haml diff --git a/app/views/finance/_editSummary.haml b/app/views/finance/balancing/_editSummary.haml similarity index 100% rename from app/views/finance/_editSummary.haml rename to app/views/finance/balancing/_editSummary.haml diff --git a/app/views/finance/_groupOrderArticleResults.haml b/app/views/finance/balancing/_groupOrderArticleResults.haml similarity index 100% rename from app/views/finance/_groupOrderArticleResults.haml rename to app/views/finance/balancing/_groupOrderArticleResults.haml diff --git a/app/views/finance/_groupResult.haml b/app/views/finance/balancing/_groupResult.haml similarity index 100% rename from app/views/finance/_groupResult.haml rename to app/views/finance/balancing/_groupResult.haml diff --git a/app/views/finance/_groupResults.haml b/app/views/finance/balancing/_groupResults.haml similarity index 100% rename from app/views/finance/_groupResults.haml rename to app/views/finance/balancing/_groupResults.haml diff --git a/app/views/finance/_groupsOverview.haml b/app/views/finance/balancing/_groupsOverview.haml similarity index 100% rename from app/views/finance/_groupsOverview.haml rename to app/views/finance/balancing/_groupsOverview.haml diff --git a/app/views/finance/_newArticleResult.haml b/app/views/finance/balancing/_newArticleResult.haml similarity index 100% rename from app/views/finance/_newArticleResult.haml rename to app/views/finance/balancing/_newArticleResult.haml diff --git a/app/views/finance/_newGroupResult.haml b/app/views/finance/balancing/_newGroupResult.haml similarity index 100% rename from app/views/finance/_newGroupResult.haml rename to app/views/finance/balancing/_newGroupResult.haml diff --git a/app/views/finance/_summary.haml b/app/views/finance/balancing/_summary.haml similarity index 100% rename from app/views/finance/_summary.haml rename to app/views/finance/balancing/_summary.haml diff --git a/app/views/finance/confirmOrder.haml b/app/views/finance/balancing/confirm.html.haml similarity index 77% rename from app/views/finance/confirmOrder.haml rename to app/views/finance/balancing/confirm.html.haml index 02e455ec..40712c12 100644 --- a/app/views/finance/confirmOrder.haml +++ b/app/views/finance/balancing/confirm.html.haml @@ -11,6 +11,6 @@ %td= number_to_currency(groupResult.price) %p %div{:style => "float:left"} - = button_to "Abschließen", :action => "balanceOrder", :id => @order + = button_to "Abschließen", :action => "close", :id => @order %div{:style => "float:right"} - = link_to 'Zurück zur Abrechnung', :action => "editOrder", :id => @order \ No newline at end of file + = link_to 'Zurück zur Abrechnung', :action => "new", :id => @order \ No newline at end of file diff --git a/app/views/finance/listOrders.haml b/app/views/finance/balancing/index.html.haml similarity index 86% rename from app/views/finance/listOrders.haml rename to app/views/finance/balancing/index.html.haml index ecc9f7a1..44cd30b9 100644 --- a/app/views/finance/listOrders.haml +++ b/app/views/finance/balancing/index.html.haml @@ -23,14 +23,14 @@ %tbody - @orders.each do |order| %tr{:class => cycle("even","odd", :name => "order")} - %td= link_to truncate(order.name), :action => "editOrder", :id => order + %td= link_to truncate(order.name), :action => "new", :id => order %td=h order.supplier ? order.supplier.name : _('nonexistent') %td=h format_time(order.ends) unless order.ends.nil? %td= order.booked ? "abgerechnet (#{number_to_currency order.fcProfit})" : "beendet" %td= order.updated_by.nil? ? '??' : order.updated_by.nick %td - unless order.booked - = link_to "abrechnen", :action => "editOrder", :id => order + = link_to "abrechnen", :action => "new", :id => order | = link_to 'auf "gebucht" setzen', {:action => 'setAllBooked', :id => order}, :confirm => 'Wirklich alle Gruppenbestellungen für diese Bestellung auf "gebucht" setzen?', :method => "post" - else diff --git a/app/views/finance/editOrder.haml b/app/views/finance/balancing/new.html.haml similarity index 68% rename from app/views/finance/editOrder.haml rename to app/views/finance/balancing/new.html.haml index 557200f6..c89f02d1 100644 --- a/app/views/finance/editOrder.haml +++ b/app/views/finance/balancing/new.html.haml @@ -1,4 +1,5 @@ %h1 Bestellung abrechnen + - if @order.booked %p %b Achtung, Bestellung wurde schon abgerechnet! @@ -15,7 +16,7 @@ .column_content %ul - unless @order.booked - %li= link_to "Bestellung abschließen", :action => "confirmOrder", :id => @order + %li= link_to "Bestellung abschließen", :action => "confirm", :id => @order .right_column{:style => 'clear:both;width: 28%'} .box_title @@ -28,7 +29,7 @@ %p Hier kannst Du deine Abrechnung kommentieren %small Protokoll bearbeiten: = link_to_remote image_tag("b_edit.png", :size => "16x16", :border => "0"), | - :update => 'results', :url => { :action => 'editOrder', :id => @order, :view => 'editNote' }, | + :update => 'results', :url => { :action => 'new', :id => @order, :view => 'editNote' }, | :before => "Element.show('loader')", :success => "Element.hide('loader')" | %hr/ #comments @@ -38,9 +39,9 @@ .box_title #editOrderNav %ul - %li= link_to_remote 'Gruppenübersicht', :update => 'results', :url => { :action => 'editOrder', :id => @order, :view => 'groupsOverview' }, :before => "Element.show('loader')", :success => "Element.hide('loader')" - %li= link_to_remote 'Artikelübersicht', :update => 'results', :url => { :action => 'editOrder', :id => @order, :view => 'articlesOverview' }, :before => "Element.show('loader')", :success => "Element.hide('loader')" - %li= link_to_remote 'Bestellung bearbeiten', :update => 'results', :url => { :action => 'editOrder', :id => @order, :view => 'editResults' }, :before => "Element.show('loader')", :success => "Element.hide('loader')" + %li= link_to_remote 'Gruppenübersicht', :update => 'results', :url => { :action => 'new', :id => @order, :view => 'groupsOverview' }, :before => "Element.show('loader')", :success => "Element.hide('loader')" + %li= link_to_remote 'Artikelübersicht', :update => 'results', :url => { :action => 'new', :id => @order, :view => 'articlesOverview' }, :before => "Element.show('loader')", :success => "Element.hide('loader')" + %li= link_to_remote 'Bestellung bearbeiten', :update => 'results', :url => { :action => 'new', :id => @order, :view => 'editResults' }, :before => "Element.show('loader')", :success => "Element.hide('loader')" .column_content #results = render :partial => 'groupsOverview' diff --git a/app/views/finance/index.haml b/app/views/finance/index.haml index c40935f2..f7a07d0a 100644 --- a/app/views/finance/index.haml +++ b/app/views/finance/index.haml @@ -3,7 +3,7 @@ .box_title %h2 Unpaid invoices .column_content - %p= link_to "Show all invoices", invoices_path + %p= link_to "Show all invoices", finance_invoices_path %table.list %thead %tr @@ -17,13 +17,13 @@ %td= format_date(invoice.date) %td= number_to_currency(invoice.amount) %td=h invoice.supplier.name - %td= link_to "Edit", edit_invoice_path(invoice) + %td= link_to "Edit", edit_finance_invoice_path(invoice) .box_title %h2 letzte Überweisungen .column_content %p - = link_to "Bestellgruppen", :action => "listOrdergroups" + = link_to "Bestellgruppen", :controller => 'finance/transactions' %table.list %thead %tr @@ -43,7 +43,7 @@ .box_title %h2 noch nicht abgerechnet .column_content - %p= link_to "Bestellungsübersicht", :action => "listOrders" + %p= link_to "Bestellungsübersicht", :controller => 'finance/orders' - unless @orders.empty? %table.list %thead diff --git a/app/views/layouts/_main_tabnav.html.erb b/app/views/layouts/_main_tabnav.html.erb index 236fe492..9b6b9d6f 100644 --- a/app/views/layouts/_main_tabnav.html.erb +++ b/app/views/layouts/_main_tabnav.html.erb @@ -26,11 +26,11 @@ { :name => "Suppliers", :url => suppliers_path, :access? => (u.role_suppliers?) } ] }, - { :name => "Finance", :url => "/finance", :active => ["finance", "invoices", "transactions"], + { :name => "Finance", :url => "/finance", :active => ["finance", "invoices", "transactions", "balancing"], :access? => (u.role_finance?), :subnav => [ { :name => "Manage accounts", :url => "/finance/transactions" }, - { :name => "Balance orders", :url => "/finance/listOrders" }, + { :name => "Balance orders", :url => "/finance/balancing" }, { :name => "Invoices", :url => finance_invoices_path } ] }, diff --git a/config/routes.rb b/config/routes.rb index 08c96876..34c129b5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,9 +3,9 @@ ActionController::Routing::Routes.draw do |map| map.namespace :finance do |finance| finance.resources :invoices finance.connect 'transactions/:action/:id', :controller => 'transactions' + finance.connect 'balancing/:action/:id', :controller => 'balancing' end - #map.resources :invoices map.resources :suppliers, :has_many => [:deliveries], :collection => { :shared_suppliers => :get } diff --git a/test/functional/finance/balancing_controller_test.rb b/test/functional/finance/balancing_controller_test.rb new file mode 100644 index 00000000..e3bcfe98 --- /dev/null +++ b/test/functional/finance/balancing_controller_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class Finance::OrdersControllerTest < ActionController::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end