Ledger Allocating Payments

From Emersion
Revision as of 09:45, 3 July 2017 by Scarpenter (talk) (Ledger Examples)
Jump to: navigation, search

Overview

One of the single most important functions of the system is how payments work and service providers need to have a good understanding of how Emersion's system operates in terms of payment handling. Specifically, there are rules around the critical task of the allocation of a payment to an invoice.

  • An unallocated payment is a payment recorded against an account that has not yet been allocated to an invoice.
  • An allocated payment is a payment that has been applied to an invoice to reduce the amount payable.

Users can enter payments and allocate them to specific invoices immediately, or allow the system to auto-allocate the payment to invoices using the default set of rules (see below). Payments can also be allocated to invoices at a later time. Regardless of the choice made by the user, and regardless of the method of payment (Credit card, BPAY, Cash, Bank Deposit, etc) the payment is recorded by the ledger journal in exactly the same way.

All payments in the system enter the system as unallocated.

How 'Auto-Allocate' Works

When users select to 'auto-allocate' the payment, the system will:

  1. Create an unallocated payment.
  2. Look for the oldest invoice with an amount still outstanding.
  3. Apply the payment to this invoice.
  4. If the payment was for an amount greater than the amount owing on the oldest invoice, the system will look for the next oldest invoice with an amount that is outstanding, and apply money from the payment to this invoice.

This cycle is repeated until all invoices are paid and none are outstanding. In the case of any surplus funds that are left, these will be stored as an unallocated payment.

The Ledger Journal and Payments

The sections from here down pertain to the

All payments in the system are initially entered as unallocated payments. When the payment is then allocated, the first step is to create an 'offsetUnallocatedPayment' transaction, which is the inverse of the payment amount. Then - the system will create an 'allocateUnallocatedPayment' transaction for any invoices that are outstanding, or invoices that are created in the initial payment's PAYMENT_DETAIL serialized array. Where there is an amount left over, the system will create another 'unallocatedPayment' for the remainder so it can be allocated when there is an outstanding invoice.

The various transactions that allocate the payment amount to an invoice are linked back to the original payment via a 'reference_key'.

Ledger Examples

Single Payment Allocation to single outstanding invoice

Account 123456 has 1 invoice for 100, and a $100 payment is made against that invoice.

Date

Ledger Journal ID

Transaction Type

Handler Type

Handler ID

Amount

Reference Key

Description of Transaction

15/02/2017

100000'

invoice

UmbrellaInvoiceId

987654

$100

invoice issued to customer

17/02/2017

100001

unallocatedPayment

UmbrellaAccountId

123456

-$100

payment received

17/02/2017

100002

offsetUnallocatedPayment

UmbrellaAccountId

123456

$100

unallocatedPaymentId:100001

Transaction is to 'cancel out' the payment so that it can be allocated to an invoice. The reference_key references the original journal id of the unallocated payment

17/02/2017

100003

allocateUnallocatedPayment

UmbrellaInvoiceId

987654

-$100

offsetUnallocatedPaymentId:100001

Payment is allocated to an invoice

Single Payment Allocation to multiple outstanding invoices

Account 123456 has 2 invoices outstanding, 1 for $25 and 1 for $45, and a $70 payment is made against those invoices

Date

Ledger Journal ID

Transaction Type

Handler Type

Handler ID

Amount

Reference Key

Description of Transaction

15/01/2017

100000

invoice

UmbrellaInvoiceId

887445

$25

invoice issued to customer

15/02/2017

104050

invoice

UmbrellaInvoiceId

971000

$45

invoice issued to customer

17/02/2017

104100

unallocatedPayment

UmbrellaAccountId

123456

$-70

payment received

17/02/2017

104101

offsetUnallocatedPayment

UmbrellaAccountId

123456

$70

unallocatedPayment:104100

Transaction to cancel out payment so that it can be allocated

17/02/2017

104102

allocateUnallocatedPayment

UmbrellaInvoiceId

887445

$-25

offsetUnallocatedPaymentId:104100