fix(cashier,chequebook): surface real backend errors; skip redundant balance check on token disbursement

Cashier token-based withdrawal disbursement was re-running the balance/min-balance
checks against the already-approved amount, which always failed since the manager
approval had already deducted the balance — the check now skips for that case
(clerk-created requests still get the full validation).

Cheque book request submission now shows the actual backend error message
(e.g. insufficient-balance rejections) instead of a generic fallback string.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Jaanu423
2026-07-16 11:19:28 +05:30
co-authored by Claude Sonnet 5
parent 0cc79ccd57
commit 24b1d7c087
2 changed files with 33 additions and 21 deletions
@@ -2730,30 +2730,38 @@ export class TransactionEntryComponent implements OnInit, OnDestroy {
} }
if (isWithdrawal) { if (isWithdrawal) {
// 3. Balance check // Token-based cashier disbursement: the manager approval already validated the balance
const withdrawable = this.withdrawableAmount; // and posted the real withdrawal (money already left the account). Re-running the balance/
if (amount > withdrawable) { // min-balance checks here would compare the post-deduction balance against the same
this.showAlert('error', 'Insufficient Balance', [ // already-approved amount again, which fails for almost any real withdrawal.
`Withdrawable Amount: ₹${withdrawable.toLocaleString('en-IN', { minimumFractionDigits: 2 })}`, const isTokenDisbursement = !this.isClerk && !!this.activeWithdrawalRequest;
`Requested Amount: ₹${amount.toLocaleString('en-IN', { minimumFractionDigits: 2 })}`,
'Please reduce the withdrawal amount.'
]);
return;
}
// 4. Min balance if (!isTokenDisbursement) {
const enforceMin = !!this.accountDetails.enforceMinRequiredBalance; // 3. Balance check
const minBalance = Number(this.accountDetails.minRequiredBalance ?? 0); const withdrawable = this.withdrawableAmount;
if (enforceMin && minBalance > 0) { if (amount > withdrawable) {
const balanceAfter = this.currentBalance - amount; this.showAlert('error', 'Insufficient Balance', [
if (balanceAfter < minBalance) { `Withdrawable Amount: ₹${withdrawable.toLocaleString('en-IN', { minimumFractionDigits: 2 })}`,
this.showAlert('error', 'Minimum Balance Violation', [ `Requested Amount: ₹${amount.toLocaleString('en-IN', { minimumFractionDigits: 2 })}`,
`Required minimum balance: ₹${minBalance.toLocaleString('en-IN', { minimumFractionDigits: 2 })}`,
`Balance after withdrawal: ₹${balanceAfter.toLocaleString('en-IN', { minimumFractionDigits: 2 })}`,
'Please reduce the withdrawal amount.' 'Please reduce the withdrawal amount.'
]); ]);
return; return;
} }
// 4. Min balance
const enforceMin = !!this.accountDetails.enforceMinRequiredBalance;
const minBalance = Number(this.accountDetails.minRequiredBalance ?? 0);
if (enforceMin && minBalance > 0) {
const balanceAfter = this.currentBalance - amount;
if (balanceAfter < minBalance) {
this.showAlert('error', 'Minimum Balance Violation', [
`Required minimum balance: ₹${minBalance.toLocaleString('en-IN', { minimumFractionDigits: 2 })}`,
`Balance after withdrawal: ₹${balanceAfter.toLocaleString('en-IN', { minimumFractionDigits: 2 })}`,
'Please reduce the withdrawal amount.'
]);
return;
}
}
} }
// 5. Denomination overdraft — fire whenever denomination is entered for withdrawal // 5. Denomination overdraft — fire whenever denomination is entered for withdrawal
@@ -281,9 +281,13 @@ export class ChequeBooksComponent implements OnInit {
this.notify('Submitted for approval — see Approvals > Cheque Book Requests'); this.notify('Submitted for approval — see Approvals > Cheque Book Requests');
this.loadBooks(); this.loadBooks();
}, },
error: () => { error: (err: any) => {
this.busy = false; this.busy = false;
this.notify('Request failed — check the account is active and the cheque-book facility is enabled', true); const msg =
err?.error?.errors?.[0]?.defaultUserMessage ||
err?.error?.developerMessage ||
'Request failed — check the account is active and the cheque-book facility is enabled';
this.notify(msg, true);
} }
}); });
} }