Skip to content

Commit

Permalink
Merge branch 'upstream_master' into advancly
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Alberto Hernandez committed Feb 9, 2024
2 parents 9e6aae0 + d252544 commit 4d0db11
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ <h3 class="mat-h3" fxFlexFill>Loan Schedule</h3>
</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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -39,7 +39,7 @@ export class EditLoanProductComponent implements OnInit {
paymentAllocation: PaymentAllocation[] = [];
creditAllocation: CreditAllocation[] = [];
advancedPaymentAllocations: AdvancedPaymentAllocation[] = [];
advancedCreditAllocations: AdvancedPaymentAllocation[] = [];
advancedCreditAllocations: AdvancedCreditAllocation[] = [];

/**
* @param {ActivatedRoute} route Activated Route.
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ <h4 class="m-b-15 right" fxFlex="90%">You can drag and drop the rows to set a Pa
<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>

Expand All @@ -34,7 +34,7 @@ <h4 class="m-b-15 right" fxFlex="90%">You can drag and drop the rows to set a Pa
</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)">

Expand All @@ -50,8 +50,8 @@ <h4 class="m-b-15 right" fxFlex="90%">You can drag and drop the rows to set a Pa
<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>

Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);

Expand All @@ -32,22 +33,21 @@ 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);
}
this.futureInstallmentAllocationRule.valueChanges.subscribe((value: any) => {
this.advancedPaymentAllocation.futureInstallmentAllocationRules.forEach((item: FutureInstallmentAllocationRule) => {
if (value === item.code) {
this.advancedPaymentAllocation.futureInstallmentAllocationRule = item;
this.paymentAllocationChange.emit(true);
this.allocationChanged.emit(true);
}
});
});
Expand All @@ -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);
}
}

Expand All @@ -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);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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[]>();
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
});
Expand Down
Loading

0 comments on commit 4d0db11

Please sign in to comment.