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
|
2012-04-20 18:33:47 +02:00
|
|
|
validates_numericality_of :amount, :deposit, :deposit_credit
|
2009-01-08 16:33:27 +01:00
|
|
|
|
2011-05-11 12:21:21 +02:00
|
|
|
scope :unpaid, :conditions => { :paid_on => nil }
|
2009-01-10 19:36:58 +01:00
|
|
|
|
2012-04-20 18:33:47 +02:00
|
|
|
# Replace numeric seperator with database format
|
|
|
|
localize_input_of :amount, :deposit, :deposit_credit
|
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
|
2011-05-07 20:50:39 +02:00
|
|
|
|
2011-05-07 21:55:24 +02:00
|
|
|
|
2011-05-07 20:50:39 +02:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: invoices
|
|
|
|
#
|
2011-05-07 21:55:24 +02:00
|
|
|
# id :integer(4) not null, primary key
|
|
|
|
# supplier_id :integer(4)
|
|
|
|
# delivery_id :integer(4)
|
|
|
|
# order_id :integer(4)
|
2011-05-07 20:50:39 +02:00
|
|
|
# number :string(255)
|
|
|
|
# date :date
|
|
|
|
# paid_on :date
|
|
|
|
# note :text
|
|
|
|
# amount :decimal(8, 2) default(0.0), not null
|
|
|
|
# deposit :decimal(8, 2) default(0.0), not null
|
|
|
|
# deposit_credit :decimal(8, 2) default(0.0), not null
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
|
|
|
#
|
|
|
|
|