51 lines
2 KiB
Ruby
51 lines
2 KiB
Ruby
|
if FoodsoftAutomaticInvoices.enabled?
|
||
|
class Order < ApplicationRecord
|
||
|
# Returns the all round price of a finished order
|
||
|
# :groups returns the sum of all GroupOrders
|
||
|
# :clear returns the price without tax, deposit and markup
|
||
|
# :gross includes tax and deposit(gross). this amount should be equal to suppliers bill
|
||
|
# :gross_without_deposit excludes the depost from the gross price
|
||
|
# :net_deposit returns the deposit without tax (deposit entered by user is default gross)
|
||
|
# :fc_deposit_price returns the deposit with markup
|
||
|
# :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)
|
||
|
for oa in order_articles.ordered.includes(:article, :article_price)
|
||
|
quantity = oa.units * oa.price.unit_quantity
|
||
|
case type
|
||
|
when :net
|
||
|
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 :fc_deposit
|
||
|
total += quantity * oa.price.fc_deposit_price
|
||
|
when :deposit
|
||
|
total += quantity * oa.price.deposit
|
||
|
end
|
||
|
end
|
||
|
elsif %i[groups groups_without_markup].include?(type)
|
||
|
for go in group_orders.includes(group_order_articles: { order_article: %i[article article_price] })
|
||
|
for goa in go.group_order_articles
|
||
|
case type
|
||
|
when :groups
|
||
|
total += goa.result * goa.order_article.price.fc_price
|
||
|
when :groups_without_markup
|
||
|
total += goa.result * goa.order_article.price.gross_price
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
total
|
||
|
end
|
||
|
end
|
||
|
end
|