Export report table to CSV file using defined delimiter (#1798)
Co-authored-by: Jose Alberto Hernandez <alberto@blue-daemon.local>
This commit is contained in:
co-authored by
Jose Alberto Hernandez
parent
dd4b37c060
commit
3b140e6f34
+1
-1
@@ -50,7 +50,7 @@
|
||||
|
||||
<ng-container matColumnDef="fromDate">
|
||||
<th mat-header-cell *matHeaderCellDef matTooltip="Interest effective from date" mat-sort-header> From Date </th>
|
||||
<td mat-cell *matCellDef="let floatingRatePeriod"> {{ floatingRatePeriod.fromDate | dateFormat : 'dd MMMM yyyy' }} </td>
|
||||
<td mat-cell *matCellDef="let floatingRatePeriod"> {{ floatingRatePeriod.fromDate | dateFormat }} </td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="interestRate">
|
||||
|
||||
+9
-23
@@ -12,8 +12,8 @@ import { LoanProductAccountingStepComponent } from '../loan-product-stepper/loan
|
||||
|
||||
/** Custom Services */
|
||||
import { ProductsService } from 'app/products/products.service';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
import { GlobalConfiguration } from 'app/system/configurations/global-configurations-tab/configuration.model';
|
||||
import { LoanProducts } from '../loan-products';
|
||||
|
||||
@Component({
|
||||
selector: 'mifosx-create-loan-product',
|
||||
@@ -31,34 +31,28 @@ export class CreateLoanProductComponent implements OnInit {
|
||||
|
||||
loanProductsTemplate: any;
|
||||
accountingRuleData = ['None', 'Cash', 'Accrual (periodic)', 'Accrual (upfront)'];
|
||||
itemsByDefault: any[] = [];
|
||||
|
||||
/**
|
||||
* @param {ActivatedRoute} route Activated Route.
|
||||
* @param {ProductsService} productsService Product Service.
|
||||
* @param {SettingsService} settingsService Settings Service
|
||||
* @param {LoanProducts} loanProducts LoanProducts
|
||||
* @param {Router} router Router for navigation.
|
||||
*/
|
||||
|
||||
constructor(private route: ActivatedRoute,
|
||||
private productsService: ProductsService,
|
||||
private settingsService: SettingsService,
|
||||
private loanProducts: LoanProducts,
|
||||
private router: Router) {
|
||||
this.route.data.subscribe((data: { loanProductsTemplate: any, configurations: any }) => {
|
||||
this.loanProductsTemplate = data.loanProductsTemplate;
|
||||
const assetAccountData = this.loanProductsTemplate.accountingMappingOptions.assetAccountOptions || [];
|
||||
const liabilityAccountData = this.loanProductsTemplate.accountingMappingOptions.liabilityAccountOptions || [];
|
||||
this.loanProductsTemplate.accountingMappingOptions.assetAndLiabilityAccountOptions = assetAccountData.concat(liabilityAccountData);
|
||||
const itemsByDefault: string[] = [];
|
||||
data.configurations.globalConfiguration.forEach((config: GlobalConfiguration) => {
|
||||
if (config.name === 'days-before-repayment-is-due') {
|
||||
this.loanProductsTemplate['dueDaysForRepaymentEvent'] = config.value;
|
||||
itemsByDefault.push('dueDaysForRepaymentEvent');
|
||||
} else if (config.name === 'days-after-repayment-is-overdue') {
|
||||
this.loanProductsTemplate['overDueDaysForRepaymentEvent'] = config.value;
|
||||
itemsByDefault.push('overDueDaysForRepaymentEvent');
|
||||
}
|
||||
this.loanProductsTemplate['itemsByDefault'] = itemsByDefault;
|
||||
});
|
||||
|
||||
this.itemsByDefault = loanProducts.setItemsByDefault(data.configurations);
|
||||
this.loanProductsTemplate['itemsByDefault'] = this.itemsByDefault;
|
||||
this.loanProductsTemplate = loanProducts.updateLoanProductDefaults(this.loanProductsTemplate);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -106,15 +100,7 @@ export class CreateLoanProductComponent implements OnInit {
|
||||
}
|
||||
|
||||
submit() {
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const loanProduct = {
|
||||
...this.loanProduct,
|
||||
charges: this.loanProduct.charges.map((charge: any) => ({ id: charge.id })),
|
||||
dateFormat,
|
||||
locale: this.settingsService.language.code
|
||||
};
|
||||
delete loanProduct.allowAttributeConfiguration;
|
||||
delete loanProduct.advancedAccountingRules;
|
||||
const loanProduct = this.loanProducts.buildPayload(this.loanProduct, this.itemsByDefault);
|
||||
|
||||
this.productsService.createLoanProduct(loanProduct)
|
||||
.subscribe((response: any) => {
|
||||
|
||||
@@ -12,8 +12,8 @@ import { LoanProductAccountingStepComponent } from '../loan-product-stepper/loan
|
||||
|
||||
/** Custom Services */
|
||||
import { ProductsService } from 'app/products/products.service';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
import { GlobalConfiguration } from 'app/system/configurations/global-configurations-tab/configuration.model';
|
||||
import { LoanProducts } from '../loan-products';
|
||||
|
||||
@Component({
|
||||
selector: 'mifosx-edit-loan-product',
|
||||
@@ -31,38 +31,28 @@ export class EditLoanProductComponent implements OnInit {
|
||||
|
||||
loanProductAndTemplate: any;
|
||||
accountingRuleData = ['None', 'Cash', 'Accrual (periodic)', 'Accrual (upfront)'];
|
||||
itemsByDefault: GlobalConfiguration[] = [];
|
||||
|
||||
/**
|
||||
* @param {ActivatedRoute} route Activated Route.
|
||||
* @param {ProductsService} productsService Product Service.
|
||||
* @param {SettingsService} settingsService Settings Service
|
||||
* @param {LoanProducts} loanProducts LoanProducts
|
||||
* @param {Router} router Router for navigation.
|
||||
*/
|
||||
|
||||
constructor(private route: ActivatedRoute,
|
||||
private productsService: ProductsService,
|
||||
private settingsService: SettingsService,
|
||||
private loanProducts: LoanProducts,
|
||||
private router: Router) {
|
||||
this.route.data.subscribe((data: { loanProductAndTemplate: any, configurations: any }) => {
|
||||
this.loanProductAndTemplate = data.loanProductAndTemplate;
|
||||
const assetAccountData = this.loanProductAndTemplate.accountingMappingOptions.assetAccountOptions || [];
|
||||
const liabilityAccountData = this.loanProductAndTemplate.accountingMappingOptions.liabilityAccountOptions || [];
|
||||
this.loanProductAndTemplate.accountingMappingOptions.assetAndLiabilityAccountOptions = assetAccountData.concat(liabilityAccountData);
|
||||
const itemsByDefault: string[] = [];
|
||||
data.configurations.globalConfiguration.forEach((config: GlobalConfiguration) => {
|
||||
if (config.name === 'days-before-repayment-is-due') {
|
||||
if (this.loanProductAndTemplate['dueDaysForRepaymentEvent'] == null) {
|
||||
this.loanProductAndTemplate['dueDaysForRepaymentEvent'] = config.value;
|
||||
itemsByDefault.push('dueDaysForRepaymentEvent');
|
||||
}
|
||||
} else if (config.name === 'days-after-repayment-is-overdue') {
|
||||
if (this.loanProductAndTemplate['overDueDaysForRepaymentEvent'] == null) {
|
||||
this.loanProductAndTemplate['overDueDaysForRepaymentEvent'] = config.value;
|
||||
itemsByDefault.push('overDueDaysForRepaymentEvent');
|
||||
}
|
||||
}
|
||||
this.loanProductAndTemplate['itemsByDefault'] = itemsByDefault;
|
||||
});
|
||||
|
||||
this.itemsByDefault = loanProducts.setItemsByDefault(data.configurations);
|
||||
this.loanProductAndTemplate['itemsByDefault'] = this.itemsByDefault;
|
||||
this.loanProductAndTemplate = loanProducts.updateLoanProductDefaults(this.loanProductAndTemplate);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -119,16 +109,8 @@ export class EditLoanProductComponent implements OnInit {
|
||||
}
|
||||
|
||||
submit() {
|
||||
// TODO: Update once language and date settings are setup
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const loanProduct = {
|
||||
...this.loanProduct,
|
||||
charges: this.loanProduct.charges.map((charge: any) => ({ id: charge.id })),
|
||||
dateFormat,
|
||||
locale: this.settingsService.language.code
|
||||
};
|
||||
delete loanProduct.allowAttributeConfiguration;
|
||||
delete loanProduct.advancedAccountingRules;
|
||||
const loanProduct = this.loanProducts.buildPayload(this.loanProduct, this.itemsByDefault);
|
||||
|
||||
this.productsService.updateLoanProduct(this.loanProductAndTemplate.id, loanProduct)
|
||||
.subscribe((response: any) => {
|
||||
this.router.navigate(['../../', response.resourceId], { relativeTo: this.route });
|
||||
|
||||
+6
-7
@@ -1,5 +1,6 @@
|
||||
import { Component, OnInit, Input } from '@angular/core';
|
||||
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
|
||||
import { LoanProducts } from '../../loan-products';
|
||||
|
||||
@Component({
|
||||
selector: 'mifosx-loan-product-settings-step',
|
||||
@@ -28,9 +29,8 @@ export class LoanProductSettingsStepComponent implements OnInit {
|
||||
interestRecalculationOnDayTypeData: any;
|
||||
delinquencyBucketData: any;
|
||||
|
||||
itemsByDefault: string[] = [];
|
||||
|
||||
constructor(private formBuilder: FormBuilder) {
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private loanProducts: LoanProducts) {
|
||||
this.createLoanProductSettingsForm();
|
||||
this.setConditionalControls();
|
||||
}
|
||||
@@ -60,7 +60,6 @@ export class LoanProductSettingsStepComponent implements OnInit {
|
||||
this.interestRecalculationOnDayTypeData = Array.from({ length: 28 }, (_, index) => index + 1);
|
||||
this.delinquencyBucketData = this.loanProductsTemplate.delinquencyBucketOptions;
|
||||
|
||||
this.itemsByDefault = this.loanProductsTemplate.itemsByDefault || [];
|
||||
this.loanProductSettingsForm.patchValue({
|
||||
'amortizationType': this.loanProductsTemplate.amortizationType.id,
|
||||
'interestType': this.loanProductsTemplate.interestType.id,
|
||||
@@ -187,8 +186,8 @@ export class LoanProductSettingsStepComponent implements OnInit {
|
||||
'graceOnArrearsAgeing': [true]
|
||||
}),
|
||||
'delinquencyBucketId': ['', Validators.required],
|
||||
'dueDaysForRepaymentEvent': ['', Validators.required],
|
||||
'overDueDaysForRepaymentEvent': ['', Validators.required]
|
||||
'dueDaysForRepaymentEvent': [''],
|
||||
'overDueDaysForRepaymentEvent': ['']
|
||||
});
|
||||
}
|
||||
|
||||
@@ -362,7 +361,7 @@ export class LoanProductSettingsStepComponent implements OnInit {
|
||||
}
|
||||
|
||||
styleByDefault(input: string): string {
|
||||
if (this.itemsByDefault.includes(input)) {
|
||||
if (this.loanProducts.isItemByDefault(input)) {
|
||||
return 'by-default';
|
||||
}
|
||||
return '';
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
import { GlobalConfiguration } from 'app/system/configurations/global-configurations-tab/configuration.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class LoanProducts {
|
||||
|
||||
globalConfigurations: string[] = ['days-before-repayment-is-due', 'days-after-repayment-is-overdue'];
|
||||
propertyNames: string[] = ['dueDaysForRepaymentEvent', 'overDueDaysForRepaymentEvent'];
|
||||
|
||||
constructor(private settingsService: SettingsService) { }
|
||||
|
||||
public setItemsByDefault(configurations: any) {
|
||||
const itemsByDefault: GlobalConfiguration[] = [];
|
||||
configurations.globalConfiguration.forEach((config: GlobalConfiguration) => {
|
||||
if (this.globalConfigurations.includes(config.name)) {
|
||||
itemsByDefault.push(config);
|
||||
}
|
||||
});
|
||||
return itemsByDefault;
|
||||
}
|
||||
|
||||
public updateLoanProductDefaults(loanProductTemplate: any) {
|
||||
const itemsByDefault: GlobalConfiguration[] = loanProductTemplate['itemsByDefault'];
|
||||
itemsByDefault.forEach((config: GlobalConfiguration) => {
|
||||
const propertyName = this.resolvePropertyName(config.name);
|
||||
if (propertyName !== '') {
|
||||
loanProductTemplate[propertyName] = config.value;
|
||||
}
|
||||
});
|
||||
return loanProductTemplate;
|
||||
}
|
||||
|
||||
public buildPayload(loanProductData: any, itemsByDefault: any) {
|
||||
const dateFormat: string = this.settingsService.dateFormat;
|
||||
const locale: string = this.settingsService.language.code;
|
||||
|
||||
const loanProduct = {
|
||||
...loanProductData,
|
||||
charges: loanProductData.charges.map((charge: any) => ({ id: charge.id })),
|
||||
dateFormat,
|
||||
locale
|
||||
};
|
||||
// Remove unnecessary properties
|
||||
delete loanProduct.allowAttributeConfiguration;
|
||||
delete loanProduct.advancedAccountingRules;
|
||||
|
||||
// Set Default values If they were not set
|
||||
itemsByDefault.forEach((config: GlobalConfiguration) => {
|
||||
const propertyName = this.resolvePropertyName(config.name);
|
||||
if (propertyName !== '') {
|
||||
if (!loanProduct[propertyName] || loanProduct[propertyName] === '') {
|
||||
loanProduct[propertyName] = config.value;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return loanProduct;
|
||||
}
|
||||
|
||||
public isItemByDefault(propertyName: string): boolean {
|
||||
return (this.propertyNames.includes(propertyName));
|
||||
}
|
||||
|
||||
private resolvePropertyName(configName: string): string {
|
||||
if (this.globalConfigurations.includes(configName)) {
|
||||
const idx = this.globalConfigurations.indexOf(configName);
|
||||
if (idx > -1) {
|
||||
return this.propertyNames[idx];
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user