From 24b1d7c087bad66eb97d7c9cb6ffce797a0f29a8 Mon Sep 17 00:00:00 2001 From: Jaanu423 Date: Thu, 16 Jul 2026 11:19:28 +0530 Subject: [PATCH] fix(cashier,chequebook): surface real backend errors; skip redundant balance check on token disbursement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../transaction-entry.component.ts | 46 +++++++++++-------- .../cheque-books/cheque-books.component.ts | 8 +++- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/app/cashier/transaction-entry/transaction-entry.component.ts b/src/app/cashier/transaction-entry/transaction-entry.component.ts index 9e5feb219..a832befe2 100644 --- a/src/app/cashier/transaction-entry/transaction-entry.component.ts +++ b/src/app/cashier/transaction-entry/transaction-entry.component.ts @@ -2730,30 +2730,38 @@ export class TransactionEntryComponent implements OnInit, OnDestroy { } if (isWithdrawal) { - // 3. Balance check - const withdrawable = this.withdrawableAmount; - if (amount > withdrawable) { - this.showAlert('error', 'Insufficient Balance', [ - `Withdrawable Amount: ₹${withdrawable.toLocaleString('en-IN', { minimumFractionDigits: 2 })}`, - `Requested Amount: ₹${amount.toLocaleString('en-IN', { minimumFractionDigits: 2 })}`, - 'Please reduce the withdrawal amount.' - ]); - return; - } + // Token-based cashier disbursement: the manager approval already validated the balance + // and posted the real withdrawal (money already left the account). Re-running the balance/ + // min-balance checks here would compare the post-deduction balance against the same + // already-approved amount again, which fails for almost any real withdrawal. + const isTokenDisbursement = !this.isClerk && !!this.activeWithdrawalRequest; - // 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 })}`, + if (!isTokenDisbursement) { + // 3. Balance check + const withdrawable = this.withdrawableAmount; + if (amount > withdrawable) { + this.showAlert('error', 'Insufficient Balance', [ + `Withdrawable Amount: ₹${withdrawable.toLocaleString('en-IN', { minimumFractionDigits: 2 })}`, + `Requested Amount: ₹${amount.toLocaleString('en-IN', { minimumFractionDigits: 2 })}`, 'Please reduce the withdrawal amount.' ]); 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 diff --git a/src/app/chequebook/cheque-books/cheque-books.component.ts b/src/app/chequebook/cheque-books/cheque-books.component.ts index 40a43a5ff..f115d9f53 100644 --- a/src/app/chequebook/cheque-books/cheque-books.component.ts +++ b/src/app/chequebook/cheque-books/cheque-books.component.ts @@ -281,9 +281,13 @@ export class ChequeBooksComponent implements OnInit { this.notify('Submitted for approval — see Approvals > Cheque Book Requests'); this.loadBooks(); }, - error: () => { + error: (err: any) => { 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); } }); }