Files
cbsnexora/src/app/tasks/checker-inbox-and-tasks-tabs/share-addition-requests/share-addition-request-detail-dialog/share-addition-request-detail-dialog.component.ts
T
niteshandClaude Sonnet 5 e53dfb5a66 feat(shares, cashier): Entry Type tagging on Transaction Entry, real GL details on receipts
Adds an Entry Type field to Transaction Entry's GL-crediting rows (Receipt / Collection),
fetched from the backend's GLEntryType code, so the counter can flag what a GL credit is
actually for (General / Share Collection / DD Issue) instead of leaving every GL account
picker throughout Share Advance Collection guessing from the whole chart of accounts.

Apply Share / Additional Share screens:
- GL Account picker narrowed to accounts that actually have an eligible receipt, and only
  auto-selected when exactly one candidate exists -- no more defaulting to whichever account
  sorts first (Cash at Vault).
- Voucher tables show Description and Collected By, and a Detail view exposes the receipt's
  real Dr/Cr GL legs instead of the GL Account dropdown's current unrelated selection.
- Additional Share funds from a single voucher (radio-style selection); ticking a receipt
  syncs the GL Account picker to its own actual account.
- Checker's Additional Share Request review dialog gets the same Description + real GL entry
  detail, expandable per voucher, so approval is never a guess about what will post.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-17 17:45:05 +05:30

155 lines
5.1 KiB
TypeScript

/**
* Copyright since 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import { Component, OnInit, inject } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MAT_DIALOG_DATA, MatDialogRef, MatDialogModule } from '@angular/material/dialog';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { catchError } from 'rxjs/operators';
import { of } from 'rxjs';
import { CashierService } from 'app/cashier/cashier.service';
import { SharesService } from 'app/shares/shares.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Full detail for one additional-share request, opened from the Approval Center list.
*
* Everything a checker needs to decide without leaving the queue: the board resolution, the tranche
* value, and — the piece a bare list row cannot show — the actual proof of funding. A cash tranche
* shows every receipt behind it (a member paying in instalments has more than one), a savings
* tranche shows the account already debited and its balance, so the approval is never a guess about
* where the money came from.
*/
@Component({
selector: 'mifosx-share-addition-request-detail-dialog',
templateUrl: './share-addition-request-detail-dialog.component.html',
styleUrls: ['./share-addition-request-detail-dialog.component.scss'],
standalone: true,
imports: [
CommonModule,
MatDialogModule,
MatButtonModule,
MatIconModule,
MatProgressSpinnerModule
]
})
export class ShareAdditionRequestDetailDialogComponent implements OnInit {
private cashierService = inject(CashierService);
private sharesService = inject(SharesService);
private settingsService = inject(SettingsService);
loading = true;
errorMsg = '';
actioning = false;
detail: any = null;
/** Which voucher's row is currently expanded to show its real Dr/Cr GL legs, or null if none. */
expandedVoucherId: number | null = null;
loadingGlEntriesId: number | null = null;
/** Fetched once per voucher and kept — a checker toggling the same row twice shouldn't re-fetch. */
glEntriesByVoucherId: { [id: number]: { glCode: string; accountName: string; drCr: string; amount: number }[] } = {};
public dialogRef = inject(MatDialogRef<ShareAdditionRequestDetailDialogComponent>);
public data = inject<{ transactionId: number }>(MAT_DIALOG_DATA);
ngOnInit(): void {
this.cashierService
.getShareAdditionRequest(this.data.transactionId)
.pipe(
catchError((err) => {
this.errorMsg = this.readError(err, 'Could not load this request.');
this.loading = false;
return of(null);
})
)
.subscribe((res: any) => {
if (res) {
this.detail = res;
}
this.loading = false;
});
}
/** How many receipts fund this tranche — the lead one plus any further instalments. */
get voucherCount(): number {
return this.detail?.vouchers?.length || 0;
}
/** Shows or hides a voucher's real GL posting, fetching it the first time it is opened. */
toggleVoucherGlEntries(voucherId: number): void {
if (this.expandedVoucherId === voucherId) {
this.expandedVoucherId = null;
return;
}
this.expandedVoucherId = voucherId;
if (this.glEntriesByVoucherId[voucherId]) {
return;
}
this.loadingGlEntriesId = voucherId;
this.cashierService
.getShareAdvanceGlEntries(voucherId)
.pipe(catchError(() => of(null)))
.subscribe((res: any) => {
this.glEntriesByVoucherId[voucherId] = res?.entries || [];
this.loadingGlEntriesId = null;
});
}
approve(): void {
this.act('approveadditionalshares');
}
reject(): void {
this.act('rejectadditionalshares');
}
private act(command: string): void {
if (this.actioning || !this.detail) {
return;
}
this.actioning = true;
this.errorMsg = '';
const data = {
requestedShares: [{ id: this.detail.transactionId }],
dateFormat: this.settingsService.dateFormat,
locale: this.settingsService.language.code
};
this.sharesService
.executeSharesAccountCommand(this.detail.shareAccountId, command, data)
.pipe(
catchError((err) => {
this.errorMsg = this.readError(err, 'The request could not be actioned.');
this.actioning = false;
return of(null);
})
)
.subscribe((res: any) => {
if (res) {
this.dialogRef.close(true);
} else {
this.actioning = false;
}
});
}
cancel(): void {
this.dialogRef.close(false);
}
private readError(err: any, fallback: string): string {
return (
err?.error?.errors?.[0]?.defaultUserMessage ||
err?.error?.defaultUserMessage ||
err?.error?.developerMessage ||
fallback
);
}
}