fix deposit is net value

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

View file

@ -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)]

View file

@ -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

View file

@ -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_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,14 @@ 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 :fc_without_deposit
total += quantity * oa.price.fc_price_without_deposit
when :net_deposit
total += quantity * oa.price.net_deposit_price
when :fc_deposit
total += quantity * oa.price.fc_deposit_price
when :deposit
@ -230,11 +234,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

View file

@ -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

View file

@ -13,12 +13,22 @@
/
= 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?
%td
= number_to_currency(order_article.price.deposit, :unit => "") unless order_article.price.deposit.zero?
:plain
/
= 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?

View file

@ -6,22 +6,29 @@
%tr
%td= t('.net_amount')
%td.numeric= number_to_currency(order.sum(:net))
- 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))
%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))
- if FoodsoftConfig[:group_order_invoices]&.[](:separate_deposits)
%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))
%tr
%td= t('.fc_deposit')
%td.numeric= number_to_currency(order.sum(:fc_deposit))
%tr
%td= t('.groups_amount')
%td.numeric= number_to_currency(order.sum(:groups))

View file

@ -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,6 +21,9 @@
%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
- unit_quantity = order_article.price.unit_quantity
- units = order_article.units
@ -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

View file

@ -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)),
gross_sum: number_to_currency(@order.sum(:gross))
net_sum: number_to_currency(@order.sum(:net) + @order.sum(:net_deposit)),
gross_sum: number_to_currency(@order.sum(:fc))
- unless @order.comments.blank?
= link_to t('.comments_link'), '#comments'

View file

@ -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,10 +929,12 @@ 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
fc_amount: FC-Betrag (brutto)
gross_amount: 'Bruttobetrag:'
groups_amount: 'Gruppenbeträge:'
net_amount: 'Nettobetrag:'
@ -1634,7 +1636,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) bestellt."
description2: "%{ordergroups} haben %{article_count} Artikel mit einem Gesamtwert von %{net_sum} / %{gross_sum} (netto / brutto + fc + Pfand) bestellt."
group_orders: 'Gruppenbestellungen:'
search_placeholder:
articles: Suche nach Artikeln ...

View file

@ -64,8 +64,11 @@ 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
end
it 'gross price >= net price' do
expect(article.gross_price).to be >= article.price