Fix Loan products to use global settings in default (#1809)

Co-authored-by: Jose Alberto Hernandez <alberto@blue-daemon.local>
This commit is contained in:
José Alberto Hernández
2023-07-23 20:28:43 -06:00
committed by GitHub
co-authored by Jose Alberto Hernandez
parent 3b140e6f34
commit 640f3b46f7
6 changed files with 26 additions and 9 deletions
@@ -47,7 +47,10 @@
<div fxFlexFill>
<span fxFlex="40%">Principal:</span>
<span fxFlex="60%">{{ loansAccount.principal }} {{loansAccountProductTemplate.currency.DisplaySymbol}}</span>
<span fxFlex="60%">
{{ loansAccount.principalAmount | currency:loansAccountProductTemplate.currency.code:'symbol-narrow':'1.2-2'}}
<span class="m-l-5">{{loansAccountProductTemplate.currency.code}}</span>
</span>
</div>
<div fxFlexFill>
@@ -20,12 +20,12 @@
<td mat-cell *matCellDef="let charge"> {{ charge.chargeTimeType.value }} </td>
</ng-container>
<ng-container matColumnDef="submittedDate">
<ng-container matColumnDef="dueDate" *ngIf="!useDueDate">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Submitted On </th>
<td mat-cell *matCellDef="let charge"> {{ charge.submittedOnDate | dateFormat }} </td>
</ng-container>
<ng-container matColumnDef="dueDate">
<ng-container matColumnDef="dueDate" *ngIf="useDueDate">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Due as of </th>
<td mat-cell *matCellDef="let charge"> {{ charge.dueDate | dateFormat }} </td>
</ng-container>
@@ -20,6 +20,8 @@ import { FormfieldBase } from 'app/shared/form-dialog/formfield/model/formfield-
import { InputBase } from 'app/shared/form-dialog/formfield/model/input-base';
import { DatepickerBase } from 'app/shared/form-dialog/formfield/model/datepicker-base';
import { Dates } from 'app/core/utils/dates';
import { SystemService } from 'app/system/system.service';
import { GlobalConfiguration } from 'app/system/configurations/global-configurations-tab/configuration.model';
@Component({
selector: 'mifosx-charges-tab',
@@ -35,10 +37,12 @@ export class ChargesTabComponent implements OnInit {
/** Status */
status: any;
/** Columns to be displayed in charges table. */
displayedColumns: string[] = ['name', 'feepenalty', 'paymentdueat', 'submittedDate', 'dueDate', 'calculationtype', 'due', 'paid', 'waived', 'outstanding', 'actions'];
displayedColumns: string[] = ['name', 'feepenalty', 'paymentdueat', 'dueDate', 'calculationtype', 'due', 'paid', 'waived', 'outstanding', 'actions'];
/** Data source for charges table. */
dataSource: MatTableDataSource<any>;
useDueDate = true;
/** Paginator for charges table. */
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
/** Sorter for charges table. */
@@ -54,13 +58,17 @@ export class ChargesTabComponent implements OnInit {
private dateUtils: Dates,
private router: Router,
public dialog: MatDialog,
private settingsService: SettingsService) {
private settingsService: SettingsService,
private systemService: SystemService) {
this.route.parent.data.subscribe(( data: { loanDetailsData: any }) => {
this.loanDetails = data.loanDetailsData;
});
}
ngOnInit() {
this.systemService.getConfigurationByName('charge-accrual-date').subscribe((config: GlobalConfiguration) => {
this.useDueDate = (config.stringValue === 'due-date');
});
this.chargesData = this.loanDetails.charges;
this.status = this.loanDetails.status.value;
let actionFlag;
@@ -52,7 +52,7 @@ export class CreateLoanProductComponent implements OnInit {
this.itemsByDefault = loanProducts.setItemsByDefault(data.configurations);
this.loanProductsTemplate['itemsByDefault'] = this.itemsByDefault;
this.loanProductsTemplate = loanProducts.updateLoanProductDefaults(this.loanProductsTemplate);
this.loanProductsTemplate = loanProducts.updateLoanProductDefaults(this.loanProductsTemplate, false);
});
}
@@ -52,7 +52,7 @@ export class EditLoanProductComponent implements OnInit {
this.itemsByDefault = loanProducts.setItemsByDefault(data.configurations);
this.loanProductAndTemplate['itemsByDefault'] = this.itemsByDefault;
this.loanProductAndTemplate = loanProducts.updateLoanProductDefaults(this.loanProductAndTemplate);
this.loanProductAndTemplate = loanProducts.updateLoanProductDefaults(this.loanProductAndTemplate, true);
});
}
@@ -22,12 +22,18 @@ export class LoanProducts {
return itemsByDefault;
}
public updateLoanProductDefaults(loanProductTemplate: any) {
public updateLoanProductDefaults(loanProductTemplate: any, isForUpdate: boolean) {
const itemsByDefault: GlobalConfiguration[] = loanProductTemplate['itemsByDefault'];
itemsByDefault.forEach((config: GlobalConfiguration) => {
const propertyName = this.resolvePropertyName(config.name);
if (propertyName !== '') {
loanProductTemplate[propertyName] = config.value;
if (isForUpdate) {
if (!loanProductTemplate[propertyName] || loanProductTemplate[propertyName] === '') {
loanProductTemplate[propertyName] = config.value;
}
} else {
loanProductTemplate[propertyName] = config.value;
}
}
});
return loanProductTemplate;