2009-01-08 16:33:27 +01:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: invoices
|
|
|
|
#
|
2009-02-02 16:35:43 +01:00
|
|
|
# id :integer not null, primary key
|
|
|
|
# supplier_id :integer
|
|
|
|
# delivery_id :integer
|
2009-01-29 01:57:51 +01:00
|
|
|
# number :string(255)
|
|
|
|
# date :date
|
|
|
|
# paid_on :date
|
|
|
|
# note :text
|
|
|
|
# amount :decimal(8, 2) default(0.0), not null
|
2009-08-01 13:41:22 +02:00
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
2009-02-02 16:35:43 +01:00
|
|
|
# order_id :integer
|
2009-01-29 01:57:51 +01:00
|
|
|
# deposit :decimal(8, 2) default(0.0), not null
|
|
|
|
# deposit_credit :decimal(8, 2) default(0.0), not null
|
2009-01-08 16:33:27 +01:00
|
|
|
#
|
|
|
|
|
|
|
|
class Invoice < ActiveRecord::Base
|
|
|
|
|
|
|
|
belongs_to :supplier
|
2009-01-18 17:42:51 +01:00
|
|
|
belongs_to :delivery
|
2009-01-29 01:57:51 +01:00
|
|
|
belongs_to :order
|
2009-01-08 16:33:27 +01:00
|
|
|
|
|
|
|
validates_presence_of :supplier_id
|
|
|
|
|
2009-01-10 19:36:58 +01:00
|
|
|
named_scope :unpaid, :conditions => { :paid_on => nil }
|
|
|
|
|
2009-01-08 16:33:27 +01:00
|
|
|
# Custom attribute setter that accepts decimal numbers using localized decimal separator.
|
|
|
|
def amount=(amount)
|
|
|
|
self[:amount] = String.delocalized_decimal(amount)
|
|
|
|
end
|
2009-01-29 01:57:51 +01:00
|
|
|
|
|
|
|
# Custom attribute setter that accepts decimal numbers using localized decimal separator.
|
|
|
|
def deposit=(deposit)
|
|
|
|
self[:deposit] = String.delocalized_decimal(deposit)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Custom attribute setter that accepts decimal numbers using localized decimal separator.
|
|
|
|
def deposit_credit=(deposit)
|
|
|
|
self[:deposit_credit] = String.delocalized_decimal(deposit)
|
|
|
|
end
|
2009-01-29 21:28:22 +01:00
|
|
|
|
|
|
|
# Amount without deposit
|
|
|
|
def net_amount
|
|
|
|
amount - deposit + deposit_credit
|
|
|
|
end
|
2009-01-08 16:33:27 +01:00
|
|
|
end
|