Class: Skr::Invoice
- Defined in:
- lib/skr/models/invoice.rb
Overview
Invoices constitute a demand for payment for goods that have been delivered to a Customer. A invoice contains:
* Customer contact information
* An inventory location that goods will be taken from.
* The customer provided {PurchaseOrder} Number
* The Payment Terms that were extended. This will control how much time the Customer has to pay the invoice in full.
* One or more SKUs, the quantity desired for each and the selling price for them.
While an Invoice often originates with a SalesOrder, it does not have to. Sales that take place in a retail environment where the customer selects the goods and pays for them immediately do not require a sales order record.
Once an invoice is saved, it immediately removes the SKUs from the SkuLoc and generates corresponding General Ledger entries debiting the asset account and crediting the customers receivables account.
When payment is received against the Invoice, the receivables account is debited and the payments holding account is credited.
invoice = Invoice.new( customer: Customer.find_by_code("ACME")
invoice.lines.build({ sku: Sku.find_by_code('LABOR'), qty: 1, price: 8.27 })
invoice.save
Instance Method Summary collapse
-
#due_date ⇒ DateTime
When the invoice is due.
-
#fully_paid? ⇒ Boolean
Is the invoice paid in full.
-
#initialize(attributes = {}) ⇒ Invoice
constructor
A new instance of Invoice.
- #is_locked? ⇒ Boolean
- #total_hours ⇒ Object
-
#unpaid_amount ⇒ BigDecimal
Total - amount_paid.
Constructor Details
#initialize(attributes = {}) ⇒ Invoice
Returns a new instance of Invoice.
94 95 96 97 98 |
# File 'lib/skr/models/invoice.rb', line 94 def initialize(attributes = {}) super # date must be set, otherwise things like terms that are based off of it fail self.invoice_date ||= Date.today end |
Instance Method Details
#due_date ⇒ DateTime
Returns when the invoice is due.
111 112 113 |
# File 'lib/skr/models/invoice.rb', line 111 def due_date self.terms.due_date_from(invoice_date) end |
#fully_paid? ⇒ Boolean
Returns is the invoice paid in full.
106 107 108 |
# File 'lib/skr/models/invoice.rb', line 106 def fully_paid? unpaid_amount <= 0 end |
#is_locked? ⇒ Boolean
115 116 117 |
# File 'lib/skr/models/invoice.rb', line 115 def is_locked? GlPeriod.is_date_locked?(self.invoice_date) end |
#total_hours ⇒ Object
119 120 121 122 123 |
# File 'lib/skr/models/invoice.rb', line 119 def total_hours lines.reduce(BigDecimal.new('0')){|t, l| l.time_entry ? t + l.qty : t } end |
#unpaid_amount ⇒ BigDecimal
Returns total - amount_paid.
101 102 103 |
# File 'lib/skr/models/invoice.rb', line 101 def unpaid_amount self.total - self.payments.total end |