Improve invoice view

This commit is contained in:
Martin Lensment 2015-04-09 17:55:27 +03:00
parent 43e111add0
commit 6a47f38e80
14 changed files with 167 additions and 44 deletions

View file

@ -7,4 +7,24 @@ class Invoice < ActiveRecord::Base
def seller_address
[seller_street, seller_city, seller_state, seller_zip].reject(&:blank?).compact.join(', ')
end
def buyer_address
[buyer_street, buyer_city, buyer_state, buyer_zip].reject(&:blank?).compact.join(', ')
end
def items
invoice_items
end
def total_without_vat
items.map(&:item_total_without_vat).sum
end
def total_vat
total_without_vat * vat_prc
end
def total
total_without_vat + total_vat
end
end

View file

@ -1,3 +1,7 @@
class InvoiceItem < ActiveRecord::Base
belongs_to :invoice
def item_total_without_vat
amount * price
end
end

View file

@ -67,9 +67,9 @@ class Registrar < ActiveRecord::Base
invoice_items_attributes: [
{
description: 'prepayment',
item_unit: 'piece',
item_amount: 1,
item_price: amount
unit: 'piece',
amount: 1,
price: amount
}
]
)