Created
February 2, 2012 15:50
-
-
Save ariejan/1724096 to your computer and use it in GitHub Desktop.
Idea of new Invoicing design.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Batch | |
end | |
class Invoice < ActiveRecord::Base | |
belongs_to :invoicable, polymorphic: true | |
belongs_to :invoicer, polymorphic: true | |
has_many :invoice_lines | |
def amount | |
invoice_lines.sum(&:amount) | |
end | |
end | |
class ParentInvoice < Invoice | |
end | |
class ChildminderInvoice < Invoice | |
end | |
class InvoiceLine | |
attr_accessor :description, :amount_per_unit, :units, :amount | |
attr_accessor :line_type | |
attr_accessor :order | |
# line_type: [:header, :item] | |
end | |
class Person | |
has_many :invoices, as: :invoicable | |
has_many :sent_invoices, as: :invoicer, class_name: "Invoice" | |
end | |
class Franchisee | |
has_many :sent_invoices, as: :invoicer, class_name: "Invoice" | |
end | |
class ParentInvoiceGenerator | |
def self.invoice_for_all_parents(year, month) | |
people = people_elegilble_for_invoice(year, month) | |
people.each { |person| invoice_for_parent(person, year, month) } | |
end | |
def self.invoice_for_parent(person, year, month) | |
invoice = ParentInvoice.new | |
#... | |
end | |
private | |
def people_eligible_for_invoice(year, month) | |
# Do query here | |
end | |
end | |
class ChildminderInvoiceGenerator | |
def self.invoice_for_childminder(person, year, month) | |
invoice = Invoice.new(invoice_type: :childminder) | |
#... | |
invoice.invoice_lines << InvoiceLine(descrtion: | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment