Class: Skr::Invoice

Inherits:
Model
  • Object
show all
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

Constructor Details

#initialize(attributes = {}) ⇒ Invoice

Returns a new instance of Invoice.



85
86
87
88
89
# File 'lib/skr/models/invoice.rb', line 85

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_dateDateTime

Returns when the invoice is due.

Returns:

  • (DateTime)

    when the invoice is due



102
103
104
# File 'lib/skr/models/invoice.rb', line 102

def due_date
    self.terms.due_date_from(invoice_date)
end

#fully_paid?Boolean

Returns is the invoice paid in full.

Returns:

  • (Boolean)

    is the invoice paid in full



97
98
99
# File 'lib/skr/models/invoice.rb', line 97

def fully_paid?
    unpaid_amount <= 0
end

#is_locked?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/skr/models/invoice.rb', line 106

def is_locked?
    GlPeriod.is_date_locked?(self.invoice_date)
end

#unpaid_amountBigDecimal

Returns total - amount_paid.

Returns:

  • (BigDecimal)

    total - amount_paid



92
93
94
# File 'lib/skr/models/invoice.rb', line 92

def unpaid_amount
    self.total - amount_paid
end