When an invoice is approved, we need to check that there's enough money in each of the funds. This happens before we move money from encumbered to awaiting payment.
Upon approving an invoice:
- Generate the voucher, voucherLines, and persist
- For each fund distribution roll up the amounts on a per-fund basis
- Make a call to finance for each fund by the combined amount calculated above to make sure it's below the remaining amount we can expend for that budget
- Create an invoice-transaction-summary w/ expected number of pending payments and payments/credits
- For each fund distribution w/ an encumbrance, make a call to POST /finance/pending-payment to move money from encumbered to awaiting payment, and possibly release remaining encumbered money.
- Update the invoice status
bold items are in scope of this story
NOTE: While we're rolling up numbers on a per-external-account basis for the first step, we might be able to easily obtain and save the per-fund numbers for the 2nd/3rd steps along the way.
For (3), this is actually determined by several different criteria. See the wiki for details including a flowchart. There are a couple things that might allow you to bypass the following calculation (inactive budget, restrictExpenditures=false, etc.), but generally speaking this will come down to applying the following formula for each budget and comparing with the amounts from (2):
[remaining amount we can expend] = (allocated * allowableExpenditure) - (allocated - (unavailable + available)) - (awaitingPayment + expended)
- The checks described above are made against finance upon invoice approval
- Unit tests are updated
- API tests are updated