From b425d97876670705b2894dc1af6a11b3a7ff6b8d Mon Sep 17 00:00:00 2001 From: viehlieb Date: Thu, 28 Sep 2023 22:42:52 +0200 Subject: [PATCH] wip deposit shows net value --- app/documents/group_order_invoice_pdf.rb | 4 ++-- app/models/concerns/price_calculation.rb | 12 +++++++---- app/models/order.rb | 14 ++++++------- app/models/order_article.rb | 8 ++++++++ .../balancing/_order_article.html.haml | 18 +++++++++++++---- app/views/finance/balancing/_summary.haml | 20 +++++++++++-------- app/views/orders/_articles.html.haml | 9 ++++++++- config/locales/de.yml | 7 ++++--- 8 files changed, 62 insertions(+), 30 deletions(-) diff --git a/app/documents/group_order_invoice_pdf.rb b/app/documents/group_order_invoice_pdf.rb index 899d6cf8..902fd03e 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.deposit + goa_deposit = goa.result * order_article.price.net_deposit_price goa_total_deposit = goa.result * order_article.price.fc_deposit_price data << ["zzgl. Pfand", goa.result.to_i, - number_to_currency(order_article.price.deposit), + number_to_currency(order_article.price.net_deposit_price), 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 47c28bc6..1bd6aa7e 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 + deposit, tax) + add_percent(price, tax) + deposit end def gross_price_without_deposit add_percent(price, tax) end - def gross_deposit_price - add_percent(deposit, tax) + def net_deposit_price + remove_percent(deposit, tax) end # @return [Number] Price for the foodcoop-member. @@ -25,11 +25,15 @@ module PriceCalculation end def fc_deposit_price - add_percent(gross_deposit_price, FoodsoftConfig[:price_markup].to_i) + add_percent(deposit, 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 e275519b..69340a4d 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 gross_deposit fc_deposit deposit fc].include?(type) + if %i[net gross net_deposit gross_without_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,10 +215,12 @@ 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 :gross_deposit - total += quantity * oa.price.gross_deposit_price + when :net_deposit + total += quantity * oa.price.net_deposit_price when :fc_deposit total += quantity * oa.price.fc_deposit_price when :deposit @@ -230,11 +232,7 @@ class Order < ApplicationRecord for goa in go.group_order_articles case type when :groups - 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 + total += goa.result * goa.order_article.price.fc_price 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 14193d15..2c16a56a 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -99,6 +99,14 @@ 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 47db3e31..b48321bc 100644 --- a/app/views/finance/balancing/_order_article.html.haml +++ b/app/views/finance/balancing/_order_article.html.haml @@ -13,12 +13,22 @@ / = number_to_currency(order_article.total_price, :unit => "") %td - = number_to_currency(order_article.price.gross_price, :unit => "") + - 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? :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.total_deposit_price, :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 6516aa69..9de36756 100644 --- a/app/views/finance/balancing/_summary.haml +++ b/app/views/finance/balancing/_summary.haml @@ -6,22 +6,26 @@ %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('.deposit') %td.numeric= number_to_currency(order.sum(:deposit)) %tr - %td= t('.gross_deposit') - %td.numeric= number_to_currency(order.sum(:gross_deposit)) + %td= t('.net_deposit') + %td.numeric= number_to_currency(order.sum(:net_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 1c800cc7..ff010144 100644 --- a/app/views/orders/_articles.html.haml +++ b/app/views/orders/_articles.html.haml @@ -6,6 +6,8 @@ %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' @@ -19,7 +21,10 @@ %td{:colspan => "9"} - order_articles.each do |order_article| - net_price = order_article.price.price - - gross_price = order_article.price.gross_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 - unit_quantity = order_article.price.unit_quantity - units = order_article.units - total_net += units * unit_quantity * net_price @@ -28,6 +33,8 @@ %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/config/locales/de.yml b/config/locales/de.yml index 960ddf53..39340578 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 + deposit: Pfand (brutto) 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 + deposit: Pfand (brutto) price: Nettopreis tax: MwSt unit_quantity: Gebindegröße @@ -929,8 +929,9 @@ de: changed: Daten wurden verändert! duration: von %{starts} bis %{ends} fc_amount: 'FC-Betrag:' - deposit: 'Pfand netto:' + deposit: 'Pfand brutto:' gross_deposit: 'Pfand brutto:' + net_deposit: 'Pfand netto:' fc_deposit: 'Pfand FC-Betrag:' fc_profit: FC Gewinn gross_amount: 'Bruttobetrag:'