How Applied Credits and Auto-Closing Work
Source: invoice.rb:753-791, credit_application_items_controller.rb:7-65
- Applying a credit reduces the invoice's balance_due by the credit amount
- If balance_due drops to zero or below, the invoice status automatically changes to closed
- The customer account is credited for the applied amount; branch accounts are also updated if applicable
- For credit-type invoices, the credit closes when applied_credit_amount >= total
- Removing an applied credit increases balance_due back and reverts the invoice status to processed (if balance_due becomes positive again)
- The customer account is debited back when a credit application is removed
- Credit application items are validated as a batch: if any single item fails validation, none are saved and error messages include the line item number
- Credit application items are only viewable for processed/closed credits (not open ones)
- Credit application items sync to MYOB and Sage in background threads (not Xero or QuickBooks)
Support scenarios
- "My invoice automatically closed when I applied a credit" -> when the credit fully covers the balance_due, the invoice auto-closes
- "I reversed a credit application and the invoice went back to processed" -> removing the credit restored a positive balance_due, which reopens the invoice
- "All my credit applications failed" -> batch validation means one bad item blocks all of them; check the error message for which line number failed
- "Credit application didn't sync to Xero" -> credit applications only sync to MYOB and Sage, not Xero or QuickBooks