Add expected_amount to Invoice
expected_amount returns the sum of all associated orders together with the transport costs.
This commit is contained in:
parent
093313f0f3
commit
052d297bff
4 changed files with 31 additions and 2 deletions
|
|
@ -41,6 +41,24 @@ class Invoice < ApplicationRecord
|
|||
amount - deposit + deposit_credit
|
||||
end
|
||||
|
||||
def orders_sum
|
||||
orders
|
||||
.joins(order_articles: [:article_price])
|
||||
.sum("COALESCE(order_articles.units_received, order_articles.units_billed, order_articles.units_to_order)" \
|
||||
+ "* article_prices.unit_quantity" \
|
||||
+ "* ROUND((article_prices.price + article_prices.deposit) * (100 + article_prices.tax) / 100, 2)")
|
||||
end
|
||||
|
||||
def orders_transport_sum
|
||||
orders.sum(:transport)
|
||||
end
|
||||
|
||||
def expected_amount
|
||||
return net_amount unless orders.any?
|
||||
|
||||
orders_sum + orders_transport_sum
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def valid_attachment
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue