Skip to content

Instantly share code, notes, and snippets.

@crispincornett
Last active December 23, 2015 19:59
Show Gist options
  • Save crispincornett/6686108 to your computer and use it in GitHub Desktop.
Save crispincornett/6686108 to your computer and use it in GitHub Desktop.
class Client < ActiveRecord::Base
has_many :accounts
end
class Account < ActiveRecord::Base
belongs_to :client
has_many :invoices
has_many :payments
end
class Invoice < ActiveRecord::Base
belongs_to :account
has_many :line_items
has_many :invoice_payments
end
class LineItem < ActiveRecord::Base
belongs_to :invoice
end
class Payment < ActiveRecord::Base
belongs_to :account
has_many :invoice_payments
end
class InvoicePayment < ActiveRecord::Base
belongs_to :invoice
belongs_to :payment
end
@crispincornett
Copy link
Author

This is the data model I've come up with to track invoices and payments for a client managing many accounts. The customer has requested that all "InvoicePayments" be reviewed before they take effect.

The customer workflow goes like this:

  • Customer collects payments throughout the day (checks are mailed in)
  • Customer enters in payments per account
  • The program automatically distributes the payment among the account's open invoices as InvoicePayments in with 'approved' as false
  • After the customer finishes entering all the payments, they view a report of the unapproved InvoicePayments and verify that the program's total InvoicePayments match up with the hand-verified total of all the checks they received that day
  • The customer approves the pending InvoicePayments (bulk operation)
  • The program marks the unapproved InvoicePayments as approved

The tricky part is how to display the summary of unapproved InvoicePayments, by account then by invoice. Should I be selecting the InvoicePayments that are unapproved, then working back through the relationships? Or maybe set a flag on accounts with unapproved InvoicePayments, so I'm not checking through all the accounts to see if they have an unapproved InvoicePayment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment