fix deposit is net value

This commit is contained in:
viehlieb 2023-09-28 22:42:52 +02:00
parent 6c0c207d1f
commit b7268918d0
10 changed files with 75 additions and 34 deletions

View file

@ -187,12 +187,12 @@ class GroupOrderInvoicePdf < RenderPdf
number_to_currency(goa_total_gross)] number_to_currency(goa_total_gross)]
if separate_deposits && order_article.price.deposit > 0.0 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 goa_total_deposit = goa.result * order_article.price.fc_deposit_price
data << ["zzgl. Pfand", data << ["zzgl. Pfand",
goa.result.to_i, 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), number_to_currency(goa_deposit),
tax.to_s + '%', tax.to_s + '%',
number_to_currency(goa_total_deposit)] number_to_currency(goa_total_deposit)]

View file

@ -4,15 +4,15 @@ module PriceCalculation
# Gross price = net price + deposit + tax. # Gross price = net price + deposit + tax.
# @return [Number] Gross price. # @return [Number] Gross price.
def gross_price def gross_price
add_percent(price + deposit, tax) add_percent(price, tax) + deposit
end end
def gross_price_without_deposit def gross_price_without_deposit
add_percent(price, tax) add_percent(price, tax)
end end
def gross_deposit_price def net_deposit_price
add_percent(deposit, tax) remove_percent(deposit, tax)
end end
# @return [Number] Price for the foodcoop-member. # @return [Number] Price for the foodcoop-member.
@ -25,11 +25,15 @@ module PriceCalculation
end end
def fc_deposit_price def fc_deposit_price
add_percent(gross_deposit_price, FoodsoftConfig[:price_markup].to_i) add_percent(deposit, FoodsoftConfig[:price_markup].to_i)
end end
private private
def remove_percent(value, percent)
(value / ((percent * 0.01) + 1)).round(2)
end
def add_percent(value, percent) def add_percent(value, percent)
(value * ((percent * 0.01) + 1)).round(2) (value * ((percent * 0.01) + 1)).round(2)
end end

View file

@ -207,7 +207,7 @@ class Order < ApplicationRecord
# :fc, guess what... # :fc, guess what...
def sum(type = :gross) def sum(type = :gross)
total = 0 total = 0
if %i[net gross gross_deposit fc_deposit deposit fc].include?(type) if %i[net gross net_deposit gross_without_deposit fc_without_deposit fc_deposit deposit fc].include?(type)
for oa in order_articles.ordered.includes(:article, :article_price) for oa in order_articles.ordered.includes(:article, :article_price)
quantity = oa.units * oa.price.unit_quantity quantity = oa.units * oa.price.unit_quantity
case type case type
@ -215,10 +215,14 @@ class Order < ApplicationRecord
total += quantity * oa.price.price total += quantity * oa.price.price
when :gross when :gross
total += quantity * oa.price.gross_price total += quantity * oa.price.gross_price
when :gross_without_deposit
total += quantity * oa.price.gross_price_without_deposit
when :fc when :fc
total += quantity * oa.price.fc_price total += quantity * oa.price.fc_price
when :gross_deposit when :fc_without_deposit
total += quantity * oa.price.gross_deposit_price total += quantity * oa.price.fc_price_without_deposit
when :net_deposit
total += quantity * oa.price.net_deposit_price
when :fc_deposit when :fc_deposit
total += quantity * oa.price.fc_deposit_price total += quantity * oa.price.fc_deposit_price
when :deposit when :deposit
@ -230,11 +234,7 @@ class Order < ApplicationRecord
for goa in go.group_order_articles for goa in go.group_order_articles
case type case type
when :groups when :groups
total += if FoodsoftConfig[:group_order_invoices]&.[](:separate_deposits) total += goa.result * goa.order_article.price.fc_price
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 when :groups_without_markup
total += goa.result * goa.order_article.price.gross_price total += goa.result * goa.order_article.price.gross_price
end end

View file

@ -99,6 +99,14 @@ class OrderArticle < ApplicationRecord
units * price.unit_quantity * price.gross_price units * price.unit_quantity * price.gross_price
end 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 = '?') def ordered_quantities_different_from_group_orders?(ordered_mark = '!', billed_mark = '?', received_mark = '?')
if !units_received.nil? if !units_received.nil?
(units_received * price.unit_quantity) == group_orders_sum[:quantity] ? false : received_mark (units_received * price.unit_quantity) == group_orders_sum[:quantity] ? false : received_mark

View file

@ -13,12 +13,22 @@
/ /
= number_to_currency(order_article.total_price, :unit => "") = number_to_currency(order_article.total_price, :unit => "")
%td %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 :plain
/ /
= number_to_currency(order_article.total_gross_price, :unit => "") = number_to_currency(order_article.total_deposit_price, :unit => "") unless order_article.price.deposit.zero?
%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 %td
= link_to t('ui.edit'), edit_order_order_article_path(order_article.order, order_article), remote: true, = 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? class: 'btn btn-mini' unless order_article.order.closed?

View file

@ -6,22 +6,29 @@
%tr %tr
%td= t('.net_amount') %td= t('.net_amount')
%td.numeric= number_to_currency(order.sum(:net)) %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) - 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 %tr
%td= t('.deposit') %td= t('.deposit')
%td.numeric= number_to_currency(order.sum(:deposit)) %td.numeric= number_to_currency(order.sum(:deposit))
%tr %tr
%td= t('.gross_deposit') %td= t('.net_deposit')
%td.numeric= number_to_currency(order.sum(:gross_deposit)) %td.numeric= number_to_currency(order.sum(:net_deposit))
%tr %tr
%td= t('.fc_deposit') %td= t('.fc_deposit')
%td.numeric= number_to_currency(order.sum(: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 %tr
%td= t('.groups_amount') %td= t('.groups_amount')
%td.numeric= number_to_currency(order.sum(:groups)) %td.numeric= number_to_currency(order.sum(:groups))

View file

@ -6,6 +6,8 @@
%th= t '.prices' %th= t '.prices'
- if order.stockit? - if order.stockit?
%th= t '.units_ordered' %th= t '.units_ordered'
- if FoodsoftConfig[:group_order_invoices]&.[](:separate_deposits)
%th= t '.deposit'
- else - else
%th= 'Members' %th= 'Members'
%th= t '.units_full' %th= t '.units_full'
@ -19,7 +21,10 @@
%td{:colspan => "9"} %td{:colspan => "9"}
- order_articles.each do |order_article| - order_articles.each do |order_article|
- net_price = order_article.price.price - 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 - unit_quantity = order_article.price.unit_quantity
- units = order_article.units - units = order_article.units
- total_net += units * unit_quantity * net_price - total_net += units * unit_quantity * net_price
@ -28,6 +33,8 @@
%td.name=h order_article.article.name %td.name=h order_article.article.name
%td= order_article.article.unit %td= order_article.article.unit
%td= "#{number_to_currency(net_price)} / #{number_to_currency(gross_price)}" %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? - if order.stockit?
%td= units %td= units
- else - else

View file

@ -32,8 +32,8 @@
= raw t '.description2', = raw t '.description2',
ordergroups: ordergroup_count(@order), ordergroups: ordergroup_count(@order),
article_count: @order.order_articles.ordered.count, article_count: @order.order_articles.ordered.count,
net_sum: number_to_currency(@order.sum(:net)), net_sum: number_to_currency(@order.sum(:net) + @order.sum(:net_deposit)),
gross_sum: number_to_currency(@order.sum(:gross)) gross_sum: number_to_currency(@order.sum(:fc))
- unless @order.comments.blank? - unless @order.comments.blank?
= link_to t('.comments_link'), '#comments' = link_to t('.comments_link'), '#comments'

View file

@ -5,7 +5,7 @@ de:
article_category: Kategorie article_category: Kategorie
availability: Artikel ist verfügbar? availability: Artikel ist verfügbar?
availability_short: verf. availability_short: verf.
deposit: Pfand deposit: Pfand (brutto)
fc_price: Endpreis fc_price: Endpreis
fc_price_desc: Preis incl. MwSt, Pfand und Foodcoop-Aufschlag. fc_price_desc: Preis incl. MwSt, Pfand und Foodcoop-Aufschlag.
fc_price_short: FC-Preis fc_price_short: FC-Preis
@ -29,7 +29,7 @@ de:
description: Beschreibung description: Beschreibung
name: Name name: Name
article_price: article_price:
deposit: Pfand deposit: Pfand (brutto)
price: Nettopreis price: Nettopreis
tax: MwSt tax: MwSt
unit_quantity: Gebindegröße unit_quantity: Gebindegröße
@ -929,10 +929,12 @@ de:
changed: Daten wurden verändert! changed: Daten wurden verändert!
duration: von %{starts} bis %{ends} duration: von %{starts} bis %{ends}
fc_amount: 'FC-Betrag:' fc_amount: 'FC-Betrag:'
deposit: 'Pfand netto:' deposit: 'Pfand brutto:'
gross_deposit: 'Pfand brutto:' gross_deposit: 'Pfand brutto:'
net_deposit: 'Pfand netto:'
fc_deposit: 'Pfand FC-Betrag:' fc_deposit: 'Pfand FC-Betrag:'
fc_profit: FC Gewinn fc_profit: FC Gewinn
fc_amount: FC-Betrag (brutto)
gross_amount: 'Bruttobetrag:' gross_amount: 'Bruttobetrag:'
groups_amount: 'Gruppenbeträge:' groups_amount: 'Gruppenbeträge:'
net_amount: 'Nettobetrag:' net_amount: 'Nettobetrag:'
@ -1634,7 +1636,7 @@ de:
pickup: und kann am %{pickup} abgeholt werden pickup: und kann am %{pickup} abgeholt werden
starts: läuft von %{starts} starts: läuft von %{starts}
starts_ends: läuft von %{starts} bis %{ends} starts_ends: läuft von %{starts} bis %{ends}
description2: "%{ordergroups} haben %{article_count} Artikel mit einem Gesamtwert von %{net_sum} / %{gross_sum} (netto / brutto) bestellt." description2: "%{ordergroups} haben %{article_count} Artikel mit einem Gesamtwert von %{net_sum} / %{gross_sum} (netto / brutto + fc + Pfand) bestellt."
group_orders: 'Gruppenbestellungen:' group_orders: 'Gruppenbestellungen:'
search_placeholder: search_placeholder:
articles: Suche nach Artikeln ... articles: Suche nach Artikeln ...

View file

@ -64,7 +64,10 @@ describe Article do
article.tax = 12 article.tax = 12
expect(article.gross_price).to eq((article.price * 1.12).round(2)) expect(article.gross_price).to eq((article.price * 1.12).round(2))
article.deposit = 1.20 article.deposit = 1.20
expect(article.gross_price).to eq(((article.price + 1.20) * 1.12).round(2)) 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
end end
it 'gross price >= net price' do it 'gross price >= net price' do