wip move automatic invoices to plugin
This commit is contained in:
parent
42a1773a87
commit
78bf494182
33 changed files with 7197 additions and 0 deletions
|
|
@ -0,0 +1,31 @@
|
|||
if FoodsoftAutomaticInvoices.enabled?
|
||||
|
||||
PriceCalculation.class_eval do
|
||||
# deposit is always gross
|
||||
def gross_price
|
||||
add_percent(price, tax) + deposit
|
||||
end
|
||||
|
||||
def gross_price_without_deposit
|
||||
add_percent(price, tax)
|
||||
end
|
||||
|
||||
def net_deposit_price
|
||||
remove_percent(deposit, tax)
|
||||
end
|
||||
|
||||
def fc_price_without_deposit
|
||||
add_percent(gross_price_without_deposit, FoodsoftConfig[:price_markup].to_i)
|
||||
end
|
||||
|
||||
def fc_deposit_price
|
||||
add_percent(deposit, FoodsoftConfig[:price_markup].to_i)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def remove_percent(value, percent)
|
||||
(value / ((percent * 0.01) + 1)).round(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
if FoodsoftAutomaticInvoices.enabled?
|
||||
GroupOrderArticle.class_eval do
|
||||
def total_price_without_deposit(order_article = self.order_article)
|
||||
if order_article.order.open?
|
||||
if FoodsoftConfig[:tolerance_is_costly]
|
||||
order_article.price.fc_price_without_deposit * (quantity + tolerance)
|
||||
else
|
||||
order_article.price.fc_price_without_deposit * quantity
|
||||
end
|
||||
else
|
||||
order_article.price.fc_price_without_deposit * result
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
if FoodsoftAutomaticInvoices.enabled?
|
||||
GroupOrder.class_eval do
|
||||
has_one :group_order_invoice
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
if FoodsoftAutomaticInvoices.enabled?
|
||||
OrderArticle.class_eval do
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue