refactor: savings module (#1226)

See: #1196
This commit is contained in:
Karan Takalkar
2020-08-25 17:46:54 +05:30
committed by GitHub
parent f215e1aa96
commit efdd779aa9
30 changed files with 129 additions and 103 deletions
@@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
/** rxjs Imports */
import { Observable } from 'rxjs';
import { Observable, forkJoin } from 'rxjs';
/** Custom Services */
import { SavingsService } from '../savings.service';
@@ -34,8 +34,14 @@ export class SavingsAccountActionsResolver implements Resolve<Object> {
return this.savingsService.getSavingsChargeTemplateResource(savingAccountId);
case 'Withdrawal':
case 'Deposit':
case 'Close':
return this.savingsService.getSavingsTransactionTemplateResource(savingAccountId);
case 'Close':
return forkJoin([
this.savingsService.getSavingsTransactionTemplateResource(savingAccountId),
this.savingsService.getSavingsAccountData(savingAccountId)
]);
case 'Apply Annual Fees':
return this.savingsService.getSavingsAccountData(savingAccountId);
default:
return undefined;
}
@@ -25,8 +25,9 @@ export class SavingsAccountTemplateResolver implements Resolve<Object> {
* @returns {Observable<any>}
*/
resolve(route: ActivatedRouteSnapshot): Observable<any> {
const clientId = route.parent.parent.paramMap.get('clientId');
return this.savingsService.getSavingsAccountTemplate(clientId);
const entityId = route.paramMap.get('clientId') || route.paramMap.get('groupId') || route.paramMap.get('centerId');
const isGroup = (route.paramMap.get('groupId') || route.paramMap.get('centerId')) ? true : false;
return this.savingsService.getSavingsAccountTemplate(entityId, undefined, isGroup);
}
}
@@ -103,7 +103,6 @@ export class CreateSavingsAccountComponent {
const monthDayFormat = 'dd MMMM';
const savingsAccount = {
...this.savingsAccount,
clientId: this.savingsAccountTemplate.clientId,
charges: this.savingsAccount.charges.map((charge: any) => ({
chargeId: charge.id,
amount: charge.amount,
@@ -116,6 +115,11 @@ export class CreateSavingsAccountComponent {
monthDayFormat,
locale
};
if (this.savingsAccountTemplate.clientId) {
savingsAccount.clientId = this.savingsAccountTemplate.clientId;
} else {
savingsAccount.groupId = this.savingsAccountTemplate.groupId;
}
this.savingsService.createSavingsAccount(savingsAccount).subscribe((response: any) => {
this.router.navigate(['../', response.resourceId], { relativeTo: this.route });
});
@@ -108,7 +108,6 @@ export class EditSavingsAccountComponent {
const monthDayFormat = 'dd MMMM';
const savingsAccount = {
...this.savingsAccount,
clientId: this.savingsAccountAndTemplate.clientId,
charges: this.savingsAccount.charges.map((charge: any) => ({
chargeId: charge.id,
amount: charge.amount,
@@ -121,6 +120,11 @@ export class EditSavingsAccountComponent {
monthDayFormat,
locale
};
if (this.savingsAccountAndTemplate.clientId) {
savingsAccount.clientId = this.savingsAccountAndTemplate.clientId;
} else {
savingsAccount.groupId = this.savingsAccountAndTemplate.groupId;
}
this.savingsService.updateSavingsAccount(this.savingsAccountAndTemplate.id, savingsAccount).subscribe((response: any) => {
this.router.navigate(['../'], { relativeTo: this.route });
});
@@ -43,8 +43,8 @@ export class ApplyAnnualFeesSavingsAccountComponent implements OnInit {
private route: ActivatedRoute,
private router: Router) {
this.accountId = this.route.parent.snapshot.params['savingAccountId'];
this.route.parent.data.subscribe((data: { savingsAccountData: any }) => {
this.savingsAccountData = data.savingsAccountData;
this.route.data.subscribe((data: { savingsAccountActionData: any }) => {
this.savingsAccountData = data.savingsAccountActionData;
});
}
@@ -45,10 +45,8 @@ export class CloseSavingsAccountComponent implements OnInit {
private route: ActivatedRoute,
private router: Router) {
this.route.data.subscribe((data: { savingsAccountActionData: any }) => {
this.paymentTypeOptions = data.savingsAccountActionData.paymentTypeOptions;
});
this.route.parent.data.subscribe((data: { savingsAccountData: any }) => {
this.transactionAmount = data.savingsAccountData.summary.accountBalance;
this.paymentTypeOptions = data.savingsAccountActionData[0].paymentTypeOptions;
this.transactionAmount = data.savingsAccountActionData[1].summary.accountBalance;
});
this.accountId = this.route.parent.snapshot.params['savingAccountId'];
}
@@ -5,7 +5,6 @@ import { FormControl } from '@angular/forms';
import { DatePipe } from '@angular/common';
/** Custom Dialogs */
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component';
import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component';
/** Custom Models */
@@ -180,15 +179,8 @@ export class SavingsAccountChargesStepComponent implements OnInit, OnChanges {
* @param {any} charge Charge
*/
deleteCharge(charge: any) {
const deleteChargeDialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: `charge ${charge.name}` }
});
deleteChargeDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.chargesDataSource.splice(this.chargesDataSource.indexOf(charge), 1);
this.chargesDataSource = this.chargesDataSource.concat([]);
}
});
this.chargesDataSource.splice(this.chargesDataSource.indexOf(charge), 1);
this.chargesDataSource = this.chargesDataSource.concat([]);
this.pristine = false;
}
@@ -74,9 +74,10 @@ export class SavingsAccountDetailsStepComponent implements OnInit {
* Fetches savings account product template on productId value changes
*/
buildDependencies() {
const clientId = this.savingsAccountTemplate.clientId;
const entityId = this.savingsAccountTemplate.clientId || this.savingsAccountTemplate.groupId;
this.savingsAccountDetailsForm.get('productId').valueChanges.subscribe((productId: string) => {
this.savingsService.getSavingsAccountTemplate(clientId, productId).subscribe((response: any) => {
this.savingsService.getSavingsAccountTemplate(entityId, productId, this.savingsAccountTemplate.groupId ? true : false)
.subscribe((response: any) => {
this.savingsAccountProductTemplate.emit(response);
this.fieldOfficerData = response.fieldOfficerOptions;
if (!this.isFieldOfficerPatched && this.savingsAccountTemplate.fieldOfficerId) {
@@ -248,9 +248,9 @@ export class ChargesTabComponent implements OnInit {
* TODO: Replace by a custom reload component instead of hard-coded back-routing.
*/
private reload() {
const clientId = this.savingsAccountData.clientId;
const url: string = this.router.url;
this.router.navigateByUrl(`/clients/${clientId}/savingsaccounts`, {skipLocationChange: true})
const refreshUrl: string = this.router.url.slice(0, this.router.url.indexOf('savings-accounts') + 'savings-accounts'.length);
this.router.navigateByUrl(refreshUrl, {skipLocationChange: true})
.then(() => this.router.navigate([url]));
}
@@ -21,7 +21,7 @@
</mat-card-title>
<mat-card-subtitle>
<p>
Account #: {{savingsAccountData.accountNo}} | Client Name: {{savingsAccountData.clientName}}<br/>
Account #: {{savingsAccountData.accountNo}} | {{entityType}} Name: {{savingsAccountData.clientName || savingsAccountData.groupName}}<br/>
<span *ngIf="!savingsAccountData.status.rejected && !savingsAccountData.status.submittedAndPendingApproval">
Current Balance: {{savingsAccountData.currency.displaySymbol}}&nbsp;{{savingsAccountData.summary.accountBalance}}<br/>
Available Balance: {{savingsAccountData.currency.displaySymbol}}&nbsp;{{savingsAccountData.summary.availableBalance}}<br/>
@@ -29,6 +29,8 @@ export class SavingsAccountViewComponent implements OnInit {
savingsDatatables: any;
/** Button Configurations */
buttonConfig: SavingsButtonsConfiguration;
/** Entity Type */
entityType: string;
/**
* Fetches savings account data from `resolve`
@@ -44,6 +46,13 @@ export class SavingsAccountViewComponent implements OnInit {
this.savingsAccountData = data.savingsAccountData;
this.savingsDatatables = data.savingsDatatables;
});
if (this.router.url.includes('clients')) {
this.entityType = 'Client';
} else if (this.router.url.includes('groups')) {
this.entityType = 'Group';
} else if (this.router.url.includes('centers')) {
this.entityType = 'Center';
}
}
ngOnInit() {
@@ -101,13 +110,13 @@ export class SavingsAccountViewComponent implements OnInit {
/**
* Refetches data fot the component
* Refetches data foe the component
* TODO: Replace by a custom reload component instead of hard-coded back-routing.
*/
reload() {
const clientId = this.savingsAccountData.clientId;
private reload() {
const url: string = this.router.url;
this.router.navigateByUrl(`/clients/${clientId}/savingsaccounts`, {skipLocationChange: true})
const refreshUrl: string = this.router.url.slice(0, this.router.url.indexOf('savings-accounts') + 'savings-accounts'.length);
this.router.navigateByUrl(refreshUrl, {skipLocationChange: true})
.then(() => this.router.navigate([url]));
}
@@ -135,7 +144,7 @@ export class SavingsAccountViewComponent implements OnInit {
this.router.navigate([`actions/Withdrawal`], { relativeTo: this.route });
break;
case 'Modify Application':
this.router.navigate(['edit-savings-account'], { relativeTo: this.route });
this.router.navigate(['edit'], { relativeTo: this.route });
break;
case 'Delete':
this.deleteSavingsAccount();
@@ -5,7 +5,7 @@
<h3>All Transactions</h3>
</div>
<div class="action-button m-b-20" fxLayout="row" fxLayoutGap="20px" *ngIf="checkStatus()">
<button mat-raised-button color="primary">View Journal Entries</button>
<button mat-raised-button color="primary" [routerLink]="['/accounting', 'journal-entries']">View Journal Entries</button>
<button mat-raised-button color="primary" [routerLink]="['export']">Export</button>
</div>
</div>
@@ -29,7 +29,7 @@ export class TransactionsTabComponent implements OnInit {
constructor(private route: ActivatedRoute,
private router: Router) {
this.route.parent.parent.data.subscribe((data: { savingsAccountData: any }) => {
this.transactionsData = data.savingsAccountData.transactions.filter((transaction: any) => !transaction.reversed);
this.transactionsData = data.savingsAccountData.transactions?.filter((transaction: any) => !transaction.reversed);
this.status = data.savingsAccountData.status.value;
});
}
@@ -49,7 +49,7 @@ export class ViewChargeComponent {
this.route.data.subscribe((data: { savingsAccountCharge: any }) => {
this.chargeData = data.savingsAccountCharge;
});
this.route.parent.parent.data.subscribe((data: { savingsAccountData: any }) => {
this.route.data.subscribe((data: { savingsAccountData: any }) => {
this.savingsAccountData = data.savingsAccountData;
});
}
@@ -194,9 +194,9 @@ export class ViewChargeComponent {
* TODO: Replace by a custom reload component instead of hard-coded back-routing.
*/
private reload() {
const clientId = this.savingsAccountData.clientId;
const url: string = this.router.url.replace(`/${this.chargeData.id}`, '');
this.router.navigateByUrl(`/clients/${clientId}/savingsaccounts`, {skipLocationChange: true})
const refreshUrl: string = this.router.url.slice(0, this.router.url.indexOf('savings-accounts') + 'savings-accounts'.length);
this.router.navigateByUrl(refreshUrl, {skipLocationChange: true})
.then(() => this.router.navigate([url]));
}
+5 -6
View File
@@ -32,14 +32,14 @@ import { SavingsAccountActionsResolver } from './common-resolvers/savings-accoun
import { SavingsTransactionRecieptResolver } from './common-resolvers/savings-transaction-reciept.resolver';
import { SavingsAccountTransactionTemplateResolver } from './common-resolvers/savings-account-transaction-template.resolver';
/** Savings Routes */
const routes: Routes = [
{
path: '',
data: { title: extract('All Savings'), breadcrumb: 'Savings', routeParamBreadcrumb: false },
children: [
{
path: 'create-savings-account',
path: 'create',
data: { title: extract('Create Savings Account'), breadcrumb: 'Create Savings Account' },
component: CreateSavingsAccountComponent,
resolve: {
@@ -49,14 +49,12 @@ const routes: Routes = [
{
path: ':savingAccountId',
data: { title: extract('Saving Account View'), routeParamBreadcrumb: 'savingAccountId' },
resolve: {
savingsAccountData: SavingsAccountViewResolver
},
children: [
{
path: '',
component: SavingsAccountViewComponent,
resolve: {
savingsAccountData: SavingsAccountViewResolver,
savingsDatatables: SavingsDatatablesResolver
},
children: [
@@ -101,7 +99,7 @@ const routes: Routes = [
]
},
{
path: 'edit-savings-account',
path: 'edit',
data: { title: extract('Edit Savings Account'), breadcrumb: 'Edit', routeParamBreadcrumb: false },
component: EditSavingsAccountComponent,
resolve: {
@@ -164,6 +162,7 @@ const routes: Routes = [
data: { routeParamBreadcrumb: 'id' },
component: ViewChargeComponent,
resolve: {
savingsAccountData: SavingsAccountViewResolver,
savingsAccountCharge: SavingsAccountChargeResolver
}
}
+3 -3
View File
@@ -140,11 +140,11 @@ export class SavingsService {
}
/**
* @param clientId Client Id assosciated with savings account.
* @param entityId Entity Id assosciated with savings account.
* @returns {Observable<any>} Savings account template.
*/
getSavingsAccountTemplate(clientId: string, productId?: string): Observable<any> {
let httpParams = new HttpParams().set('clientId', clientId);
getSavingsAccountTemplate(entityId: string, productId?: string, isGroup?: boolean): Observable<any> {
let httpParams = new HttpParams().set( isGroup ? 'groupId' : 'clientId', entityId);
httpParams = productId ? httpParams.set('productId', productId) : httpParams;
return this.http.get('/savingsaccounts/template', { params: httpParams });
}