Fix: Loan product edition with Adv Allocation for Payment and Credit

This commit is contained in:
Jose Alberto Hernandez
2024-02-09 11:31:27 +01:00
committed by Adam Saghy
parent f643b15949
commit d2525445db
8 changed files with 91 additions and 60 deletions
@@ -356,7 +356,7 @@
</span>
</div>
<div fxFlexFill *ngIf="isAdvancedPaymentAllocation">
<div fxFlexFill *ngIf="isAdvancedPaymentAllocation && creditAllocations.length > 0">
<span fxFlex="47%">Advanced Credit Allocation Transactions:</span>
<span fxFlex="53%">
<mat-accordion>
@@ -14,7 +14,7 @@ import { LoanProductAccountingStepComponent } from '../loan-product-stepper/loan
import { ProductsService } from 'app/products/products.service';
import { GlobalConfiguration } from 'app/system/configurations/global-configurations-tab/configuration.model';
import { LoanProducts } from '../loan-products';
import { AdvancedPaymentAllocation, AdvancedPaymentStrategy, CreditAllocation, PaymentAllocation, PaymentAllocationOrder, PaymentAllocationTransactionTypes } from '../loan-product-stepper/loan-product-payment-strategy-step/payment-allocation-model';
import { AdvancedCreditAllocation, AdvancedPaymentAllocation, AdvancedPaymentStrategy, CreditAllocation, PaymentAllocation, PaymentAllocationOrder, PaymentAllocationTransactionTypes } from '../loan-product-stepper/loan-product-payment-strategy-step/payment-allocation-model';
@Component({
selector: 'mifosx-edit-loan-product',
@@ -39,7 +39,7 @@ export class EditLoanProductComponent implements OnInit {
paymentAllocation: PaymentAllocation[] = [];
creditAllocation: CreditAllocation[] = [];
advancedPaymentAllocations: AdvancedPaymentAllocation[] = [];
advancedCreditAllocations: AdvancedPaymentAllocation[] = [];
advancedCreditAllocations: AdvancedCreditAllocation[] = [];
/**
* @param {ActivatedRoute} route Activated Route.
@@ -97,7 +97,6 @@ export class EditLoanProductComponent implements OnInit {
buildAdvancedPaymentAllocation(): void {
this.advancedPaymentAllocations = this.advancedPaymentStrategy.buildAdvancedPaymentAllocationList(this.loanProductAndTemplate);
this.advancedCreditAllocations = this.advancedPaymentStrategy.buildAdvancedCreditAllocationList(this.loanProductAndTemplate);
console.log(this.advancedCreditAllocations);
}
setPaymentAllocation(paymentAllocation: PaymentAllocation[]): void {
@@ -24,8 +24,8 @@
<td mat-cell *matCellDef="let paymentAllocation; let rowIndex = index"> {{ (rowIndex + 1) }} </td>
</ng-container>
<ng-container matColumnDef="paymentAllocation">
<th mat-header-cell *matHeaderCellDef>{{ 'labels.inputs.Payment Allocation' | translate }}</th>
<ng-container matColumnDef="allocationRule">
<th mat-header-cell *matHeaderCellDef>{{ 'labels.inputs.Payment Allocation Rule' | translate }}</th>
<td mat-cell *matCellDef="let paymentAllocation"> {{ paymentAllocation.value }} </td>
</ng-container>
@@ -34,7 +34,7 @@
</table>
</div>
<div class="mat-elevation-z8 container m-t-15" *ngIf="creditAllocationsData">
<div class="mat-elevation-z8 container m-t-15 m-b-15" *ngIf="creditAllocationsData">
<table mat-table [dataSource]="creditAllocationsData" #table cdkDropList
[cdkDropListData]="creditAllocationsData" (cdkDropListDropped)="dropTable($event, true)">
@@ -50,8 +50,8 @@
<td mat-cell *matCellDef="let creditAllocation; let rowIndex = index"> {{ (rowIndex + 1) }} </td>
</ng-container>
<ng-container matColumnDef="paymentAllocation">
<th mat-header-cell *matHeaderCellDef>{{ 'labels.inputs.Payment Allocation' | translate }}</th>
<ng-container matColumnDef="allocationRule">
<th mat-header-cell *matHeaderCellDef>{{ 'labels.inputs.Credit Allocation Rule' | translate }}</th>
<td mat-cell *matCellDef="let creditAllocation"> {{ creditAllocation.value }} </td>
</ng-container>
@@ -1,5 +1,5 @@
import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
import { AdvancedPaymentAllocation, AdvancedPaymentStrategy, CreditAllocationOrder, FutureInstallmentAllocationRule, PaymentAllocationOrder, PaymentAllocationTransactionType } from '../payment-allocation-model';
import { AdvancedCreditAllocation, AdvancedPaymentAllocation, AdvancedPaymentStrategy, CreditAllocationOrder, FutureInstallmentAllocationRule, PaymentAllocationOrder, PaymentAllocationTransactionType } from '../payment-allocation-model';
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
import { MatTable } from '@angular/material/table';
import { MatDialog } from '@angular/material/dialog';
@@ -14,15 +14,16 @@ import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.co
export class AdvancePaymentAllocationTabComponent implements OnInit {
@Input() advancedPaymentAllocation: AdvancedPaymentAllocation;
@Input() advancedCreditAllocation: AdvancedCreditAllocation;
@Output() paymentAllocationChange = new EventEmitter<boolean>();
@Output() allocationChanged = new EventEmitter<boolean>();
@Output() transactionTypeRemoved = new EventEmitter<PaymentAllocationTransactionType>();
paymentAllocationsData: PaymentAllocationOrder[] | null = null;
creditAllocationsData: CreditAllocationOrder[] | null = null;
/** Columns to be displayed in the table. */
displayedColumns: string[] = ['actions', 'order', 'paymentAllocation'];
displayedColumns: string[] = ['actions', 'order', 'allocationRule'];
futureInstallmentAllocationRule = new UntypedFormControl('', Validators.required);
@@ -32,14 +33,13 @@ export class AdvancePaymentAllocationTabComponent implements OnInit {
private advancedPaymentStrategy: AdvancedPaymentStrategy) { }
ngOnInit(): void {
console.log(this.advancedPaymentAllocation);
if (this.advancedCreditAllocation) {
this.creditAllocationsData = this.advancedCreditAllocation?.creditAllocationOrder;
}
if (this.advancedPaymentAllocation) {
if (this.advancedPaymentAllocation.creditAllocationOrder) {
this.creditAllocationsData = this.advancedPaymentAllocation.creditAllocationOrder;
}
if (this.advancedPaymentAllocation.paymentAllocationOrder) {
this.paymentAllocationsData = this.advancedPaymentAllocation.paymentAllocationOrder;
}
this.paymentAllocationsData = this.advancedPaymentAllocation?.paymentAllocationOrder;
if (this.advancedPaymentAllocation.futureInstallmentAllocationRule) {
this.futureInstallmentAllocationRule.patchValue(this.advancedPaymentAllocation.futureInstallmentAllocationRule.code);
}
@@ -47,7 +47,7 @@ export class AdvancePaymentAllocationTabComponent implements OnInit {
this.advancedPaymentAllocation.futureInstallmentAllocationRules.forEach((item: FutureInstallmentAllocationRule) => {
if (value === item.code) {
this.advancedPaymentAllocation.futureInstallmentAllocationRule = item;
this.paymentAllocationChange.emit(true);
this.allocationChanged.emit(true);
}
});
});
@@ -61,14 +61,14 @@ export class AdvancePaymentAllocationTabComponent implements OnInit {
this.paymentAllocationsData = [...this.paymentAllocationsData];
this.advancedPaymentAllocation.paymentAllocationOrder = this.paymentAllocationsData;
this.table.renderRows();
this.paymentAllocationChange.emit(true);
this.allocationChanged.emit(true);
} else {
const prevIndex = this.creditAllocationsData.findIndex((d: any) => d === event.item.data);
moveItemInArray(this.creditAllocationsData, prevIndex, event.currentIndex);
this.creditAllocationsData = [...this.creditAllocationsData];
this.advancedPaymentAllocation.creditAllocationOrder = this.creditAllocationsData;
this.advancedCreditAllocation.creditAllocationOrder = this.creditAllocationsData;
this.table.renderRows();
this.paymentAllocationChange.emit(true);
this.allocationChanged.emit(true);
}
}
@@ -80,12 +80,19 @@ export class AdvancePaymentAllocationTabComponent implements OnInit {
}
removeTransaction(): void {
let transaction: PaymentAllocationTransactionType = null;
if (this.advancedPaymentAllocation && this.advancedPaymentAllocation.transaction) {
transaction = this.advancedPaymentAllocation.transaction;
} else if (this.advancedCreditAllocation && this.advancedCreditAllocation.transaction) {
transaction = this.advancedCreditAllocation.transaction;
transaction.credit = true;
}
const dialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: ` the Transaction Type ${this.advancedPaymentAllocation.transaction.value}` }
data: { deleteContext: ` the Transaction Type ${transaction.value}` }
});
dialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.transactionTypeRemoved.emit(this.advancedPaymentAllocation.transaction);
this.transactionTypeRemoved.emit(transaction);
}
});
}
@@ -1,12 +1,22 @@
<mat-tab-group animationDuration="0ms" fxLayout="row wrap" fxLayoutGap="2%"
fxLayout.lt-md="column">
<mat-tab *ngFor="let advancedPaymentAllocation of advancedAllocations">
<mat-tab *ngFor="let advancedPaymentAllocation of advancedPaymentAllocations">
<ng-template mat-tab-label>
{{advancedPaymentAllocation.transaction.code}}
</ng-template>
<mifosx-advance-payment-allocation-tab [advancedPaymentAllocation]="advancedPaymentAllocation"
(paymentAllocationChange)="paymentAllocationChanged($event)"
(allocationChange)="allocationChanged($event)"
(transactionTypeRemoved)="transactionTypeRemoved($event)">
</mifosx-advance-payment-allocation-tab>
</mat-tab>
<mat-tab *ngFor="let advancedCreditAllocation of advancedCreditAllocations">
<ng-template mat-tab-label>
{{advancedCreditAllocation.transaction.code}}
</ng-template>
<mifosx-advance-payment-allocation-tab [advancedCreditAllocation]="advancedCreditAllocation"
(allocationChange)="allocationChanged($event)"
(transactionTypeRemoved)="transactionTypeRemoved($event)">
</mifosx-advance-payment-allocation-tab>
</mat-tab>
@@ -1,5 +1,5 @@
import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
import { AdvancedPaymentAllocation, AdvancedPaymentStrategy, CreditAllocation, PaymentAllocation, PaymentAllocationOrder, PaymentAllocationTransactionType } from './payment-allocation-model';
import { AdvancedCreditAllocation, AdvancedPaymentAllocation, AdvancedPaymentStrategy, CreditAllocation, CreditAllocationOrder, PaymentAllocation, PaymentAllocationOrder, PaymentAllocationTransactionType } from './payment-allocation-model';
import { MatDialog } from '@angular/material/dialog';
import { FormfieldBase } from 'app/shared/form-dialog/formfield/model/formfield-base';
import { SelectBase } from 'app/shared/form-dialog/formfield/model/select-base';
@@ -14,13 +14,12 @@ import { TranslateService } from '@ngx-translate/core';
})
export class LoanProductPaymentStrategyStepComponent implements OnInit {
advancedAllocations: AdvancedPaymentAllocation[] = [];
@Input() advancedPaymentAllocations: AdvancedPaymentAllocation[] = [];
@Input() advancedCreditAllocations: AdvancedPaymentAllocation[] = [];
@Input() advancedCreditAllocations: AdvancedCreditAllocation[] = [];
@Input() advancedPaymentAllocationTransactionTypes: PaymentAllocationTransactionType[] = [];
@Input() paymentAllocationOrderDefault: PaymentAllocationOrder[];
@Input() advancedCreditAllocationTransactionTypes: PaymentAllocationTransactionType[] = [];
@Input() creditAllocationOrderDefault: PaymentAllocationOrder[];
@Input() creditAllocationOrderDefault: CreditAllocationOrder[];
@Output() paymentAllocationChange = new EventEmitter<boolean>();
@Output() setPaymentAllocation = new EventEmitter<PaymentAllocation[]>();
@@ -33,18 +32,15 @@ export class LoanProductPaymentStrategyStepComponent implements OnInit {
private translateService: TranslateService) { }
ngOnInit(): void {
this.advancedAllocations = this.advancedPaymentAllocations.concat(this.advancedCreditAllocations);
this.sendAllocations();
}
sendAllocations(): void {
this.setPaymentAllocation.emit(this.advancedPaymentStrategy.buildPaymentAllocations(this.advancedPaymentAllocations));
if (this.advancedCreditAllocations?.length > 0) {
this.setCreditAllocation.emit(this.advancedPaymentStrategy.buildCreditAllocations(this.advancedCreditAllocations));
}
this.setCreditAllocation.emit(this.advancedPaymentStrategy.buildCreditAllocations(this.advancedCreditAllocations));
}
paymentAllocationChanged(changed: boolean): void {
allocationChanged(changed: boolean): void {
this.paymentAllocationChange.emit(changed);
this.sendAllocations();
}
@@ -105,8 +101,6 @@ export class LoanProductPaymentStrategyStepComponent implements OnInit {
);
}
this.paymentAllocationChange.emit(true);
this.advancedAllocations = this.advancedPaymentAllocations.concat(this.advancedCreditAllocations);
this.tabGroup.selectedIndex = (this.advancedAllocations.length - 1);
this.sendAllocations();
}
});
@@ -48,9 +48,13 @@ export class PaymentAllocationTransactionTypes {
export class AdvancedPaymentAllocation {
transaction: PaymentAllocationTransactionType;
paymentAllocationOrder?: PaymentAllocationOrder[];
futureInstallmentAllocationRule?: FutureInstallmentAllocationRule;
futureInstallmentAllocationRules?: FutureInstallmentAllocationRule[];
paymentAllocationOrder: PaymentAllocationOrder[];
futureInstallmentAllocationRule: FutureInstallmentAllocationRule;
futureInstallmentAllocationRules: FutureInstallmentAllocationRule[];
}
export class AdvancedCreditAllocation {
transaction: PaymentAllocationTransactionType;
creditAllocationOrder?: CreditAllocationOrder[];
}
@@ -65,21 +69,21 @@ export class AdvancePaymentAllocationData {
})
export class AdvancedPaymentStrategy {
public buildAdvancedCreditAllocationList(loanProduct: any): AdvancedPaymentAllocation[] {
const advancedPaymentAllocation: AdvancedPaymentAllocation[] = [];
public buildAdvancedCreditAllocationList(loanProduct: any): AdvancedCreditAllocation[] {
const advancedCreditAllocation: AdvancedCreditAllocation[] = [];
const advancedCreditAllocationTransactionTypes: PaymentAllocationTransactionType[] =
loanProduct.creditAllocationTransactionTypes;
const advancedPaymentAllocationTypes: CreditAllocationOrder[] = loanProduct.creditAllocationAllocationTypes;
if (loanProduct.creditAllocation) {
loanProduct.creditAllocation.forEach((item: CreditAllocation) => {
advancedPaymentAllocation.push({
advancedCreditAllocation.push({
transaction: this.getItemByCode(item.transactionType, advancedCreditAllocationTransactionTypes),
creditAllocationOrder: this.buildCurrentCreditAllocationOrder(item.creditAllocationOrder,
advancedPaymentAllocationTypes),
});
});
}
return advancedPaymentAllocation;
return advancedCreditAllocation;
}
public buildAdvancedPaymentAllocationList(loanProduct: any): AdvancedPaymentAllocation[] {
@@ -125,10 +129,10 @@ export class AdvancedPaymentStrategy {
}
public buildAdvancedCreditAllocation(transaction: PaymentAllocationTransactionType,
currentItems: PaymentAllocationOrder[]): AdvancedPaymentAllocation {
currentItems: CreditAllocationOrder[]): AdvancedCreditAllocation {
return {
transaction: transaction,
paymentAllocationOrder: this.buildPaymentAllocationTransactionOrder(true, currentItems, currentItems)
creditAllocationOrder: this.buildCreditAllocationTransactionOrder(true, currentItems, currentItems)
};
}
@@ -148,22 +152,40 @@ export class AdvancedPaymentStrategy {
return paymentAllocationOrder;
}
public buildCreditAllocationTransactionOrder(forDefault: boolean, currentItems: CreditAllocationOrder[], defaultItems: CreditAllocationOrder[]): CreditAllocationOrder[] {
const paymentAllocationOrder: CreditAllocationOrder[] = [];
if (forDefault) {
return defaultItems;
} else {
currentItems.forEach((currentItem: CreditAllocationOrder) => {
defaultItems.forEach((item: CreditAllocationOrder) => {
if (currentItem.id === item.id) {
paymentAllocationOrder.push(item);
}
});
});
}
return paymentAllocationOrder;
}
public buildPaymentAllocations(advancedPaymentAllocations: AdvancedPaymentAllocation[]): PaymentAllocation[] {
const paymentAllocations: PaymentAllocation[] = [];
advancedPaymentAllocations.forEach((paymentAllocation: AdvancedPaymentAllocation) => {
paymentAllocations.push({
transactionType: paymentAllocation.transaction.code,
paymentAllocationOrder: this.buildPaymentAllocationOrder(paymentAllocation.paymentAllocationOrder),
futureInstallmentAllocationRule: paymentAllocation.futureInstallmentAllocationRule.code
});
if (paymentAllocation.paymentAllocationOrder) {
paymentAllocations.push({
transactionType: paymentAllocation.transaction.code,
paymentAllocationOrder: this.buildPaymentAllocationOrder(paymentAllocation.paymentAllocationOrder),
futureInstallmentAllocationRule: paymentAllocation.futureInstallmentAllocationRule.code
});
}
});
return paymentAllocations;
}
public buildCreditAllocations(advancedCreditAllocations: AdvancedPaymentAllocation[]): CreditAllocation[] {
public buildCreditAllocations(advancedCreditAllocations: AdvancedCreditAllocation[]): CreditAllocation[] {
const creditAllocations: CreditAllocation[] = [];
advancedCreditAllocations.forEach((creditAllocation: AdvancedPaymentAllocation) => {
advancedCreditAllocations.forEach((creditAllocation: AdvancedCreditAllocation) => {
creditAllocations.push({
transactionType: creditAllocation.transaction.code,
creditAllocationOrder: this.buildCreditAllocationOrder(creditAllocation.creditAllocationOrder)
@@ -173,7 +195,7 @@ export class AdvancedPaymentStrategy {
return creditAllocations;
}
public buildPaymentAllocationOrder(paymentAllocationOrder: PaymentAllocationOrder[]): PaymentAllocationOrder[] {
private buildPaymentAllocationOrder(paymentAllocationOrder: PaymentAllocationOrder[]): PaymentAllocationOrder[] {
const paymentAllocations: any[] = [];
paymentAllocationOrder.forEach((item: any, index: number) => {
paymentAllocations.push({
@@ -185,7 +207,7 @@ export class AdvancedPaymentStrategy {
return paymentAllocations;
}
public buildCreditAllocationOrder(creditAllocationOrder: CreditAllocationOrder[]): CreditAllocationOrder[] {
private buildCreditAllocationOrder(creditAllocationOrder: CreditAllocationOrder[]): CreditAllocationOrder[] {
const creditAllocations: CreditAllocationOrder[] = [];
creditAllocationOrder.forEach((item: any, index: number) => {
creditAllocations.push({
@@ -197,7 +219,7 @@ export class AdvancedPaymentStrategy {
return creditAllocations;
}
public buildCurrentPaymentAllocationOrder(currentItems: any[], defaultItems: PaymentAllocationOrder[]):
private buildCurrentPaymentAllocationOrder(currentItems: any[], defaultItems: PaymentAllocationOrder[]):
PaymentAllocationOrder[] {
const paymentAllocationOrder: PaymentAllocationOrder[] = [];
currentItems.forEach((item: any) => {
@@ -206,7 +228,7 @@ export class AdvancedPaymentStrategy {
return paymentAllocationOrder;
}
public buildCurrentCreditAllocationOrder(currentItems: any[], defaultItems: CreditAllocationOrder[]):
private buildCurrentCreditAllocationOrder(currentItems: any[], defaultItems: CreditAllocationOrder[]):
CreditAllocationOrder[] {
const creditAllocationOrder: CreditAllocationOrder[] = [];
currentItems.forEach((item: any) => {
@@ -215,7 +237,7 @@ export class AdvancedPaymentStrategy {
return creditAllocationOrder;
}
public getItemByCode(code: string,
private getItemByCode(code: string,
options: any[]): any {
let transaction: any;
options.forEach((option: any) => {
@@ -32,7 +32,6 @@ export class SearchPageComponent {
constructor(private route: ActivatedRoute,
private router: Router) {
this.route.data.subscribe(( data: { searchResults: any }) => {
console.log(data.searchResults);
this.dataSource = new MatTableDataSource(data.searchResults);
this.dataSource.paginator = this.paginator;
this.hasResults = (data.searchResults.length > 0);