#*********************************************************************************************************** # TODO # # Should all amounts be using amount_ids? Particularly payments, which can be in multiple currencies # Money amounts in commerce are floats - that doesn't seem right???? #*********************************************************************************************************** class InvoicingServices < ActiveRecord::Migration def self.up # Create invoices unless table_exists?(:invoices) create_table :invoices do |t| t.column :description, :string t.column :message, :string t.column :product_id, :integer t.column :invoice_date, :date t.column :external_identifier, :string t.column :external_id_source, :string t.references :invoice_type t.timestamps end end # Create invoice types (not in silverston models - may be removed in future releases) unless table_exists?(:invoice_types) create_table :invoice_types do |t| t.column :parent_id, :integer t.column :lft, :integer t.column :rgt, :integer #custom columns go here t.column :description, :string t.column :comments, :string t.column :internal_identifier, :string t.column :external_identifier, :string t.column :external_id_source, :string t.timestamps end end # Create invoice items unless table_exists?(:invoice_items) create_table :invoice_items do |t| #foreign keys t.column :invoice_id, :integer t.column :invoice_item_type_id, :integer #these columns support the polymporphic relationship to invoice-able items t.column :invoiceable_item_type, :string t.column :invoiceable_item_id, :integer #non-key columns t.column :item_seq_id, :integer t.column :item_description, :string t.column :taxable_flag, :integer t.column :quantity, :float t.column :amount, :float t.timestamps end end # Create invoice item types unless table_exists?(:invoice_item_types) create_table :invoice_item_types do |t| t.column :parent_id, :integer t.column :lft, :integer t.column :rgt, :integer #custom columns go here t.column :description, :string t.column :comments, :string t.column :internal_identifier, :string t.column :external_identifier, :string t.column :external_id_source, :string t.timestamps end end # Create invoice_party_roles unless table_exists?(:invoice_party_roles) create_table :invoice_party_roles do |t| t.column :description, :string t.column :invoice_id, :integer t.column :party_id, :integer t.column :role_type_id, :integer t.column :external_identifier, :string t.column :external_id_source, :string t.timestamps end end #********************************************************************************************* # This is a deferred specialization of FinancialTxnAccount - see rak or rh for details #********************************************************************************************* # # Create billing accounts # unless table_exists?(:billing_accounts) # create_table :billing_accounts do |t| # t.column :description, :string # t.column :from_date, :date # t.column :thru_date, :date # # t.timestamps # end # end # Create billing contact mechanisms unless table_exists?(:billing_contact_mechanisms) create_table :billing_contact_mechanisms do |t| t.column :description, :string #these columns support a polymorphic relationship to the contact mechanism for an invoice and billing account #this allows for the use of email, postal addresses and other contact points to be used in billing t.column :contact_mechanism_type, :string t.column :contact_mechanism_id, :integer t.timestamps end end #********************************************************************************************* # This is a deferred extension of the base payments model in ecomm - see rak or rh for details #********************************************************************************************* # # Create payments # unless table_exists?(:payments) # create_table :payments do |t| # # t.column :effective_date, :date # # t.column :internal_identifier, :string # t.column :external_identifier, :string # t.column :external_id_source, :string # # #Payments here is set up to point to an amount which allows it to be # #in multiple currencies # t.column :money_amount_id, :integer # t.column :comment, :string # # t.timestamps # end # end # Create payment applictions unless table_exists?(:payment_applications) create_table :payment_applications do |t| t.column :payment_id, :integer #these columns support the polymporphic relationship to the entities to which payments can be applied #this will be innvoices, invoice items or accounts t.column :payment_applied_to_type, :string t.column :payment_applied_to_id, :integer #Payments here is set up to point to an amount which allows it to be #in multiple currencies t.column :applied_money_amount_id, :integer t.column :comment, :string t.timestamps end end # Create payment party roles unless table_exists?(:payment_party_roles) create_table :payment_party_roles do |t| t.column :description, :string t.column :payment_id, :integer t.column :party_id, :integer t.column :role_type_id, :integer t.column :external_identifier, :string t.column :external_id_source, :string t.timestamps end end end def self.down [ :invoices, :invoice_types, :invoice_items, :invoice_item_types, :invoice_party_roles, :billing_accounts, :billing_contact_mechanisms, :payment_applications, :payment_party_roles ].each do |tbl| if table_exists?(tbl) drop_table tbl end end end end