diff --git a/app/documents/group_order_invoice_pdf.rb b/app/documents/group_order_invoice_pdf.rb index 902fd03e..899d6cf8 100644 --- a/app/documents/group_order_invoice_pdf.rb +++ b/app/documents/group_order_invoice_pdf.rb @@ -187,12 +187,12 @@ class GroupOrderInvoicePdf < RenderPdf number_to_currency(goa_total_gross)] if separate_deposits && order_article.price.deposit > 0.0 - goa_deposit = goa.result * order_article.price.net_deposit_price + goa_deposit = goa.result * order_article.price.deposit goa_total_deposit = goa.result * order_article.price.fc_deposit_price data << ["zzgl. Pfand", goa.result.to_i, - number_to_currency(order_article.price.net_deposit_price), + number_to_currency(order_article.price.deposit), number_to_currency(goa_deposit), tax.to_s + '%', number_to_currency(goa_total_deposit)] diff --git a/app/models/concerns/price_calculation.rb b/app/models/concerns/price_calculation.rb index 1bd6aa7e..47c28bc6 100644 --- a/app/models/concerns/price_calculation.rb +++ b/app/models/concerns/price_calculation.rb @@ -4,15 +4,15 @@ module PriceCalculation # Gross price = net price + deposit + tax. # @return [Number] Gross price. def gross_price - add_percent(price, tax) + deposit + add_percent(price + deposit, tax) end def gross_price_without_deposit add_percent(price, tax) end - def net_deposit_price - remove_percent(deposit, tax) + def gross_deposit_price + add_percent(deposit, tax) end # @return [Number] Price for the foodcoop-member. @@ -25,15 +25,11 @@ module PriceCalculation end def fc_deposit_price - add_percent(deposit, FoodsoftConfig[:price_markup].to_i) + add_percent(gross_deposit_price, FoodsoftConfig[:price_markup].to_i) end private - def remove_percent(value, percent) - (value / ((percent * 0.01) + 1)).round(2) - end - def add_percent(value, percent) (value * ((percent * 0.01) + 1)).round(2) end diff --git a/app/models/order.rb b/app/models/order.rb index e071bee0..e275519b 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -207,7 +207,7 @@ class Order < ApplicationRecord # :fc, guess what... def sum(type = :gross) total = 0 - if %i[net gross net_deposit gross_without_deposit fc_without_deposit fc_deposit deposit fc].include?(type) + if %i[net gross gross_deposit fc_deposit deposit fc].include?(type) for oa in order_articles.ordered.includes(:article, :article_price) quantity = oa.units * oa.price.unit_quantity case type @@ -215,14 +215,10 @@ class Order < ApplicationRecord total += quantity * oa.price.price when :gross total += quantity * oa.price.gross_price - when :gross_without_deposit - total += quantity * oa.price.gross_price_without_deposit when :fc total += quantity * oa.price.fc_price - when :fc_without_deposit - total += quantity * oa.price.fc_price_without_deposit - when :net_deposit - total += quantity * oa.price.net_deposit_price + when :gross_deposit + total += quantity * oa.price.gross_deposit_price when :fc_deposit total += quantity * oa.price.fc_deposit_price when :deposit @@ -234,7 +230,11 @@ class Order < ApplicationRecord for goa in go.group_order_articles case type when :groups - total += goa.result * goa.order_article.price.fc_price + total += if FoodsoftConfig[:group_order_invoices]&.[](:separate_deposits) + goa.result * (goa.order_article.price.fc_price + goa.order_article.price.fc_deposit_price) + else + goa.result * goa.order_article.price.fc_price + end when :groups_without_markup total += goa.result * goa.order_article.price.gross_price end diff --git a/app/models/order_article.rb b/app/models/order_article.rb index 2c16a56a..14193d15 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -99,14 +99,6 @@ class OrderArticle < ApplicationRecord units * price.unit_quantity * price.gross_price end - def total_gross_price_without_deposit - units * price.unit_quantity * price.gross_price_without_deposit - end - - def total_deposit_price - units * price.unit_quantity * price.deposit - end - def ordered_quantities_different_from_group_orders?(ordered_mark = '!', billed_mark = '?', received_mark = '?') if !units_received.nil? (units_received * price.unit_quantity) == group_orders_sum[:quantity] ? false : received_mark diff --git a/app/views/finance/balancing/_order_article.html.haml b/app/views/finance/balancing/_order_article.html.haml index b48321bc..47db3e31 100644 --- a/app/views/finance/balancing/_order_article.html.haml +++ b/app/views/finance/balancing/_order_article.html.haml @@ -13,22 +13,12 @@ / = number_to_currency(order_article.total_price, :unit => "") %td - - if FoodsoftConfig[:group_order_invoices]&.[](:separate_deposits) - = number_to_currency(order_article.price.gross_price_without_deposit, :unit => "") - :plain - / - = number_to_currency(order_article.total_gross_price_without_deposit, :unit => "") - -else - = number_to_currency(order_article.price.gross_price, :unit => "") - :plain - / - = number_to_currency(order_article.total_gross_price, :unit => "") -%td= number_to_percentage(order_article.price.tax) unless order_article.price.tax.zero? -%td - = number_to_currency(order_article.price.deposit, :unit => "") unless order_article.price.deposit.zero? + = number_to_currency(order_article.price.gross_price, :unit => "") :plain / - = number_to_currency(order_article.total_deposit_price, :unit => "") unless order_article.price.deposit.zero? + = number_to_currency(order_article.total_gross_price, :unit => "") +%td= number_to_percentage(order_article.price.tax) unless order_article.price.tax.zero? +%td= number_to_currency(order_article.price.deposit, :unit => "") unless order_article.price.deposit.zero? %td = link_to t('ui.edit'), edit_order_order_article_path(order_article.order, order_article), remote: true, class: 'btn btn-mini' unless order_article.order.closed? diff --git a/app/views/finance/balancing/_summary.haml b/app/views/finance/balancing/_summary.haml index 42f3e3ed..6516aa69 100644 --- a/app/views/finance/balancing/_summary.haml +++ b/app/views/finance/balancing/_summary.haml @@ -6,29 +6,22 @@ %tr %td= t('.net_amount') %td.numeric= number_to_currency(order.sum(:net)) + %tr + %td= t('.gross_amount') + %td.numeric= number_to_currency(order.sum(:gross)) + %tr + %td= t('.fc_amount') + %td.numeric= number_to_currency(order.sum(:fc)) - if FoodsoftConfig[:group_order_invoices]&.[](:separate_deposits) - %tr - %td= t('.gross_amount') - %td.numeric= number_to_currency(order.sum(:gross_without_deposit)) - %tr - %td= t('.fc_amount') - %td.numeric= number_to_currency(order.sum(:fc_without_deposit)) %tr %td= t('.deposit') %td.numeric= number_to_currency(order.sum(:deposit)) %tr - %td= t('.net_deposit') - %td.numeric= number_to_currency(order.sum(:net_deposit)) + %td= t('.gross_deposit') + %td.numeric= number_to_currency(order.sum(:gross_deposit)) %tr %td= t('.fc_deposit') %td.numeric= number_to_currency(order.sum(:fc_deposit)) - - else - %tr - %td= t('.gross_amount') - %td.numeric= number_to_currency(order.sum(:gross)) - %tr - %td= t('.fc_amount') - %td.numeric= number_to_currency(order.sum(:fc)) %tr %td= t('.groups_amount') %td.numeric= number_to_currency(order.sum(:groups)) diff --git a/app/views/orders/_articles.html.haml b/app/views/orders/_articles.html.haml index ff010144..1c800cc7 100644 --- a/app/views/orders/_articles.html.haml +++ b/app/views/orders/_articles.html.haml @@ -6,8 +6,6 @@ %th= t '.prices' - if order.stockit? %th= t '.units_ordered' - - if FoodsoftConfig[:group_order_invoices]&.[](:separate_deposits) - %th= t '.deposit' - else %th= 'Members' %th= t '.units_full' @@ -21,10 +19,7 @@ %td{:colspan => "9"} - order_articles.each do |order_article| - net_price = order_article.price.price - - if FoodsoftConfig[:group_order_invoices]&.[](:separate_deposits) - - gross_price = order_article.price.gross_price_without_deposit - - else - - gross_price = order_article.price.gross_price + - gross_price = order_article.price.gross_price - unit_quantity = order_article.price.unit_quantity - units = order_article.units - total_net += units * unit_quantity * net_price @@ -33,8 +28,6 @@ %td.name=h order_article.article.name %td= order_article.article.unit %td= "#{number_to_currency(net_price)} / #{number_to_currency(gross_price)}" - - if FoodsoftConfig[:group_order_invoices]&.[](:separate_deposits) - %td= "#{number_to_currency(order_article.price.deposit)}" - if order.stockit? %td= units - else diff --git a/app/views/orders/show.html.haml b/app/views/orders/show.html.haml index 1587f8e1..e76db249 100644 --- a/app/views/orders/show.html.haml +++ b/app/views/orders/show.html.haml @@ -32,8 +32,8 @@ = raw t '.description2', ordergroups: ordergroup_count(@order), article_count: @order.order_articles.ordered.count, - net_sum: number_to_currency(@order.sum(:net) + @order.sum(:net_deposit)), - gross_sum: number_to_currency(@order.sum(:fc)) + net_sum: number_to_currency(@order.sum(:net)), + gross_sum: number_to_currency(@order.sum(:gross)) - unless @order.comments.blank? = link_to t('.comments_link'), '#comments' diff --git a/config/locales/de.yml b/config/locales/de.yml index 13a2e3dc..960ddf53 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -5,7 +5,7 @@ de: article_category: Kategorie availability: Artikel ist verfügbar? availability_short: verf. - deposit: Pfand (brutto) + deposit: Pfand fc_price: Endpreis fc_price_desc: Preis incl. MwSt, Pfand und Foodcoop-Aufschlag. fc_price_short: FC-Preis @@ -29,7 +29,7 @@ de: description: Beschreibung name: Name article_price: - deposit: Pfand (brutto) + deposit: Pfand price: Nettopreis tax: MwSt unit_quantity: Gebindegröße @@ -929,12 +929,10 @@ de: changed: Daten wurden verändert! duration: von %{starts} bis %{ends} fc_amount: 'FC-Betrag:' - deposit: 'Pfand brutto:' + deposit: 'Pfand netto:' gross_deposit: 'Pfand brutto:' - net_deposit: 'Pfand netto:' fc_deposit: 'Pfand FC-Betrag:' fc_profit: FC Gewinn - fc_amount: FC-Betrag (brutto) gross_amount: 'Bruttobetrag:' groups_amount: 'Gruppenbeträge:' net_amount: 'Nettobetrag:' @@ -1636,7 +1634,7 @@ de: pickup: und kann am %{pickup} abgeholt werden starts: läuft von %{starts} starts_ends: läuft von %{starts} bis %{ends} - description2: "%{ordergroups} haben %{article_count} Artikel mit einem Gesamtwert von %{net_sum} / %{gross_sum} (netto / brutto + fc + Pfand) bestellt." + description2: "%{ordergroups} haben %{article_count} Artikel mit einem Gesamtwert von %{net_sum} / %{gross_sum} (netto / brutto) bestellt." group_orders: 'Gruppenbestellungen:' search_placeholder: articles: Suche nach Artikeln ... diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index 91a2f8ea..3a810827 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -64,10 +64,7 @@ describe Article do article.tax = 12 expect(article.gross_price).to eq((article.price * 1.12).round(2)) article.deposit = 1.20 - if FoodsoftConfig[:group_order_invoices]&.[](:separate_deposits) - expect(article.gross_price_without_deposit).to eq((article.price * 1.12 + 1.20).round(2)) - expect(article.gross_price).to eq(((article.price + 1.20) * 1.12).round(2)) - end + expect(article.gross_price).to eq(((article.price + 1.20) * 1.12).round(2)) end it 'gross price >= net price' do