fix deposit is net value
This commit is contained in:
parent
f29ab603b6
commit
90e06a475f
10 changed files with 75 additions and 34 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue