Brings in the Product Approval feature (anshul.rathore) — a unified Approvals
screen for Loan/Savings/Current/Share/FD/RD/Charge product requests:
- Merges two existing pending-request sources into one list: staged product
edits (m_saving_product_temp, via /{producttype}/pending) and native
maker-checker entries (/makercheckers) for product CREATE/DELETE and
LOANPRODUCT/CHARGE of any action.
- Checker Inbox no longer lists product requests at all — they now live only
in Product Approval, so a checker isn't checking two queues for the same
thing. Clicking a non-product row now navigates straight to that entity's
own view page when one exists, instead of always opening a detail dialog.
- View Checker Inbox dialog gains a caller-supplied heading (used when opened
from Product Approval) and a notice steering staged product edits back to
Product Approval instead of being actioned in place.
- Route renamed pending-savings-products -> product-approval, with the old
path kept as a redirect for existing bookmarks/links.
8 files conflicted with dev's own recent Checker Inbox work (popup-based
detail view, e8097bc2/63134f17) and were resolved by hand, keeping both
sides' real functionality rather than picking one branch wholesale:
- product-edit-diff-dialog.component.{ts,html,scss}: kept dev's diff dialog
(resolves GL account ids to names, aliases fields like currencyCode against
the stored product, normalises the two date shapes the API uses) over
maker-checker's simpler raw-value version.
- pending-savings-products.component.{ts,html}: kept maker-checker's full
isPendingEdit()-based dispatch (dev's version was a strict subset of it).
- view-checker-inbox.component.{ts,html,scss}: kept dev's per-entry Delete
action and maker-checker's recursive Command-payload tree renderer and
custom heading side by side.
Also recovered two regressions the merge introduced silently (no conflict
markers, so `git merge` gave no warning):
- tasks.service.ts lost deleteMakerChecker() entirely — restored.
- Checker Inbox's bulk Delete action (button, deleteChecker()/
bulkDeleteChecker(), and its .cv-btn-delete style) was dropped across three
files — restored to match dev's pre-merge behaviour exactly.
And one duplicate the merge produced without a conflict marker: two
independent viewEntry() implementations landed in checker-inbox.component.ts
(TS2393, caught at build). Kept maker-checker's entity-view-page-routing
version — a superset of dev's dialog-only version — and dropped the duplicate,
along with a leftover diagnostic console.log.
372 lines
13 KiB
TypeScript
372 lines
13 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/.
|
|
*/
|
|
|
|
/** Angular Imports */
|
|
import { Component, OnInit, inject } from '@angular/core';
|
|
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
|
import { SelectionModel } from '@angular/cdk/collections';
|
|
import { UntypedFormBuilder, UntypedFormGroup, ReactiveFormsModule } from '@angular/forms';
|
|
import {
|
|
MatTableDataSource,
|
|
MatTable,
|
|
MatColumnDef,
|
|
MatHeaderCellDef,
|
|
MatHeaderCell,
|
|
MatCellDef,
|
|
MatCell,
|
|
MatHeaderRowDef,
|
|
MatHeaderRow,
|
|
MatRowDef,
|
|
MatRow
|
|
} from '@angular/material/table';
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
import { MatIcon } from '@angular/material/icon';
|
|
|
|
/** Custom Services */
|
|
import { TasksService } from '../../tasks.service';
|
|
import { SettingsService } from 'app/settings/settings.service';
|
|
|
|
/** Dialog Components */
|
|
import { ConfirmationDialogComponent } from 'app/shared/confirmation-dialog/confirmation-dialog.component';
|
|
import { ViewCheckerInboxComponent } from '../../view-checker-inbox/view-checker-inbox.component';
|
|
import { Dates } from 'app/core/utils/dates';
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
|
|
import { MatCheckbox } from '@angular/material/checkbox';
|
|
import { DateFormatPipe } from '../../../pipes/date-format.pipe';
|
|
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
|
|
import { isProductEntity, isTempTableAccountEdit } from '../../product-entities';
|
|
|
|
@Component({
|
|
selector: 'mifosx-checker-inbox',
|
|
templateUrl: './checker-inbox.component.html',
|
|
styleUrls: ['./checker-inbox.component.scss'],
|
|
imports: [
|
|
...STANDALONE_SHARED_IMPORTS,
|
|
FaIconComponent,
|
|
MatTable,
|
|
MatColumnDef,
|
|
MatHeaderCellDef,
|
|
MatHeaderCell,
|
|
MatCheckbox,
|
|
MatCellDef,
|
|
MatCell,
|
|
MatHeaderRowDef,
|
|
MatHeaderRow,
|
|
MatRowDef,
|
|
MatRow,
|
|
DateFormatPipe,
|
|
MatIcon
|
|
]
|
|
})
|
|
export class CheckerInboxComponent implements OnInit {
|
|
private route = inject(ActivatedRoute);
|
|
private dialog = inject(MatDialog);
|
|
private dateUtils = inject(Dates);
|
|
private router = inject(Router);
|
|
private translateService = inject(TranslateService);
|
|
private tasksService = inject(TasksService);
|
|
private settingsService = inject(SettingsService);
|
|
private formBuilder = inject(UntypedFormBuilder);
|
|
|
|
/** Data to be displayed */
|
|
searchData: any;
|
|
/** Maker Checker Template */
|
|
makerCheckerTemplate: any;
|
|
/** Checks if there is any data based on the search */
|
|
noSearchedData = false;
|
|
/** Checks if there is any checker data */
|
|
checkerData = false;
|
|
/** Show/hide advanced search form */
|
|
showAdvancedSearch = false;
|
|
/** Maker Checker Search Form */
|
|
makerCheckerSearchForm: UntypedFormGroup;
|
|
/** Minimum date allowed. */
|
|
minDate = new Date(2000, 0, 1);
|
|
/** Maximum date allowed. */
|
|
maxDate = new Date(2100, 0, 1);
|
|
/** DataSource */
|
|
dataSource: MatTableDataSource<any>;
|
|
/** Selecting rows from table */
|
|
selection: SelectionModel<any>;
|
|
/** Displayed Column in table */
|
|
displayedColumns: string[] = [
|
|
'select',
|
|
'id',
|
|
'madeOnDate',
|
|
'status',
|
|
'user',
|
|
'action',
|
|
'entity'
|
|
];
|
|
|
|
/**
|
|
* The Checker Inbox holds non-product pending requests only. Two groups are routed elsewhere:
|
|
*
|
|
* - Product requests of every action (CREATE, UPDATE, DELETE) belong to Approvals -> Product
|
|
* Approval, which merges them with the product edits staged in m_saving_product_temp so a
|
|
* checker sees one queue per product rather than two.
|
|
* - Savings/current account edits are staged the same way as product edits and belong to
|
|
* Approvals -> Pending Account Edits. Approving them here would call
|
|
* /makercheckers/{id}?command=approve, which replays the original command handler and never
|
|
* touches the staging table, leaving its lock held forever.
|
|
*/
|
|
private excludeRoutedElsewhere(items: any[]): any[] {
|
|
return (items || []).filter(
|
|
(item: any) => !isProductEntity(item?.entityName) && !isTempTableAccountEdit(item?.entityName, item?.actionName)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Retrieves the maker checker data from `resolve`.
|
|
* @param {ActivatedRoute} route Activated Route.
|
|
* @param {Dialog} dialog MatDialog.
|
|
* @param {Dates} dateUtils Date Utils.
|
|
* @param {router} router Router.
|
|
* @param {SettingsService} settingsService Settings Service.
|
|
* @param {TasksService} tasksService Tasks Service.
|
|
* @param {FormBuilder} formBuilder Form Builder.
|
|
*/
|
|
constructor() {
|
|
this.route.data.subscribe((data: { makerCheckerResource: any; makerCheckerTemplate: any }) => {
|
|
const raw = data.makerCheckerResource;
|
|
this.searchData = this.excludeRoutedElsewhere(Array.isArray(raw) ? raw : (raw?.pageItems ?? []));
|
|
this.checkerData = this.searchData.length > 0;
|
|
this.makerCheckerTemplate = data.makerCheckerTemplate ?? {};
|
|
this.dataSource = new MatTableDataSource(this.searchData);
|
|
this.selection = new SelectionModel(true, []);
|
|
});
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.createMakerCheckerSearchForm();
|
|
}
|
|
|
|
/**
|
|
* Creates the standing instruction form.
|
|
*/
|
|
createMakerCheckerSearchForm() {
|
|
this.makerCheckerSearchForm = this.formBuilder.group({
|
|
makerDateTimeFrom: [''],
|
|
makerDateTimeto: [''],
|
|
actionName: [''],
|
|
entityName: [''],
|
|
resourceId: ['']
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Toggle advanced search form visibility.
|
|
*/
|
|
toggleAdvancedSearch() {
|
|
this.showAdvancedSearch = !this.showAdvancedSearch;
|
|
}
|
|
|
|
search() {
|
|
const dateFormat = this.settingsService.dateFormat;
|
|
const makerCheckerSearchParams = {
|
|
...this.makerCheckerSearchForm.value,
|
|
makerDateTimeFrom: this.dateUtils.formatDate(this.makerCheckerSearchForm.value.makerDateTimeFrom, dateFormat),
|
|
makerDateTimeto: this.dateUtils.formatDate(this.makerCheckerSearchForm.value.makerDateTimeto, dateFormat)
|
|
};
|
|
this.tasksService.getMakerCheckerData(makerCheckerSearchParams).subscribe((response: any) => {
|
|
this.searchData = this.excludeRoutedElsewhere(response);
|
|
if (this.searchData.length === 0) {
|
|
this.noSearchedData = true;
|
|
} else {
|
|
this.noSearchedData = false;
|
|
}
|
|
this.dataSource = new MatTableDataSource(this.searchData);
|
|
this.selection = new SelectionModel(true, []);
|
|
});
|
|
}
|
|
|
|
/** Whether the number of selected elements matches the total number of rows. */
|
|
isAllSelected() {
|
|
const numSelected = this.selection.selected.length;
|
|
const numRows = this.dataSource.data.length;
|
|
return numSelected === numRows;
|
|
}
|
|
|
|
/** Selects all rows if they are not all selected; otherwise clear selection. */
|
|
masterToggle() {
|
|
this.isAllSelected()
|
|
? this.selection.clear()
|
|
: this.dataSource.data.forEach((row: any) => this.selection.select(row));
|
|
}
|
|
|
|
/** The label for the checkbox on the passed row */
|
|
checkboxLabel(row?: any): string {
|
|
if (!row) {
|
|
return `${this.isAllSelected() ? 'select' : 'deselect'} all`;
|
|
}
|
|
return `${this.selection.isSelected(row) ? 'deselect' : 'select'} row ${row.position + 1}`;
|
|
}
|
|
|
|
approveChecker() {
|
|
const approveCheckerDialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
|
data: {
|
|
heading: this.translateService.instant('labels.heading.Approve Checker'),
|
|
dialogContext: this.translateService.instant('labels.dialogContext.Are you sure you want to approve checker')
|
|
}
|
|
});
|
|
approveCheckerDialogRef.afterClosed().subscribe((response: { confirm: any }) => {
|
|
if (response.confirm) {
|
|
this.bulkCheckerApproveorReject('approve');
|
|
}
|
|
});
|
|
}
|
|
|
|
rejectChecker() {
|
|
const rejectCheckerDialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
|
data: {
|
|
heading: this.translateService.instant('labels.heading.Reject Checker'),
|
|
dialogContext: this.translateService.instant('labels.dialogContext.Are you sure you want to reject checker')
|
|
}
|
|
});
|
|
rejectCheckerDialogRef.afterClosed().subscribe((response: { confirm: any }) => {
|
|
if (response.confirm) {
|
|
this.bulkCheckerApproveorReject('reject');
|
|
}
|
|
});
|
|
}
|
|
|
|
deleteChecker() {
|
|
const deleteCheckerDialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
|
data: {
|
|
heading: this.translateService.instant('labels.heading.Delete Checker'),
|
|
dialogContext: this.translateService.instant('labels.dialogContext.Are you sure you want to delete checker')
|
|
}
|
|
});
|
|
deleteCheckerDialogRef.afterClosed().subscribe((response: { confirm: any }) => {
|
|
if (response.confirm) {
|
|
this.bulkDeleteChecker();
|
|
}
|
|
});
|
|
}
|
|
|
|
bulkCheckerApproveorReject(action: any) {
|
|
const selectedAccounts = this.selection.selected.length;
|
|
const listSelectedAccounts = this.selection.selected;
|
|
let approvedAccounts = 0;
|
|
listSelectedAccounts.forEach((element: any) => {
|
|
this.tasksService.executeMakerCheckerAction(element.id, action).subscribe((response: any) => {
|
|
approvedAccounts++;
|
|
if (selectedAccounts === approvedAccounts) {
|
|
this.reload();
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
bulkDeleteChecker() {
|
|
const selectedAccounts = this.selection.selected.length;
|
|
const listSelectedAccounts = this.selection.selected;
|
|
let approvedAccounts = 0;
|
|
listSelectedAccounts.forEach((element: any) => {
|
|
this.tasksService.deleteMakerChecker(element.id).subscribe((response: any) => {
|
|
approvedAccounts++;
|
|
if (selectedAccounts === approvedAccounts) {
|
|
this.reload();
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
applyFilter(filterValue: string = '') {
|
|
this.dataSource.filter = filterValue.trim().toLowerCase();
|
|
}
|
|
|
|
/**
|
|
* Maps a maker-checker entityName to the Angular route path for that entity's existing view page.
|
|
* Returns null for entity types that have no dedicated view page in this application.
|
|
*/
|
|
private entityRoute(entityName: string, resourceId: string | number): string | null {
|
|
const id = resourceId;
|
|
switch ((entityName ?? '').toUpperCase()) {
|
|
case 'LOANPRODUCT':
|
|
return `/products/loan-products/${id}`;
|
|
case 'SAVINGSPRODUCT':
|
|
return `/products/saving-products/${id}`;
|
|
case 'CURRENTPRODUCT':
|
|
return `/products/current-products/${id}`;
|
|
case 'SHAREPRODUCT':
|
|
return `/products/share-products/${id}`;
|
|
case 'FIXEDDEPOSITPRODUCT':
|
|
return `/products/fixed-deposit-products/${id}`;
|
|
case 'RECURRINGDEPOSITPRODUCT':
|
|
return `/products/recurring-deposit-products/${id}`;
|
|
case 'CHARGE':
|
|
return `/products/charges/${id}`;
|
|
case 'GLACCOUNT':
|
|
return `/accounting/chart-of-accounts/gl-accounts/view/${id}`;
|
|
case 'CLIENT':
|
|
return `/clients/${id}/general`;
|
|
case 'LOAN':
|
|
return `/loans/${id}`;
|
|
case 'SAVINGSACCOUNT':
|
|
return `/savings-accounts/${id}`;
|
|
case 'CURRENTACCOUNT':
|
|
return `/current-accounts/${id}`;
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Handles a row click in the Checker Inbox.
|
|
*
|
|
* Priority:
|
|
* 1. If the row has a known entityName and a resourceId → navigate to the entity's existing
|
|
* view page (read-only; no maker-checker action buttons are present on those pages).
|
|
* 2. If no resourceId is available (e.g. a DELETE action where the entity no longer exists)
|
|
* → show a brief informational snackbar.
|
|
* 3. If the entityName is unrecognised → fall back to the existing ViewCheckerInboxComponent
|
|
* dialog so the checker can still view the command details and action the entry.
|
|
*/
|
|
viewEntry(row: any): void {
|
|
const entityName: string = row.entityName ?? '';
|
|
const resourceId = row.resourceId;
|
|
const route = this.entityRoute(entityName, resourceId);
|
|
|
|
if (route && resourceId != null) {
|
|
// Navigate to the existing entity view page (no maker-checker buttons there).
|
|
this.router.navigate([route]);
|
|
return;
|
|
}
|
|
|
|
// resourceId is absent (CREATE rows: entity does not exist yet until approved),
|
|
// or entityName is unmapped — fall back to the detail dialog so the checker
|
|
// can still view the command payload and action the entry.
|
|
this.dialog
|
|
.open(ViewCheckerInboxComponent, {
|
|
data: { checkerId: row.id },
|
|
autoFocus: false
|
|
})
|
|
.afterClosed()
|
|
.subscribe((result: any) => {
|
|
// Only reload when something was actually actioned — a plain close must not throw away the
|
|
// checker's current search, which reload() does by re-navigating the route.
|
|
if (result?.refreshed) {
|
|
this.reload();
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Refetches data for the component
|
|
* TODO: Replace by a custom reload component instead of hard-coded back-routing.
|
|
*/
|
|
reload() {
|
|
const url: string = this.router.url;
|
|
this.router
|
|
.navigateByUrl(`/checker-inbox-and-tasks`, { skipLocationChange: true })
|
|
.then(() => this.router.navigate([url]));
|
|
}
|
|
}
|