diff --git a/src/app/deposits/recurring-deposits/common-resolvers/recurring-deposit-account-actions.resolver.ts b/src/app/deposits/recurring-deposits/common-resolvers/recurring-deposit-account-actions.resolver.ts index 21a35ce3d..5e0b49b32 100644 --- a/src/app/deposits/recurring-deposits/common-resolvers/recurring-deposit-account-actions.resolver.ts +++ b/src/app/deposits/recurring-deposits/common-resolvers/recurring-deposit-account-actions.resolver.ts @@ -30,7 +30,12 @@ export class RecurringDepositsAccountActionsResolver implements Resolve resolve(route: ActivatedRouteSnapshot): Observable { const actionName = route.paramMap.get('name'); const recurringDepositAccountId = route.paramMap.get('recurringDepositAccountId') || route.parent.parent.paramMap.get('recurringDepositAccountId'); - return undefined; + switch (actionName) { + case 'Add Charge': + return this.savingsService.getSavingsChargeTemplateResource(recurringDepositAccountId); + default: + return undefined; + } } } diff --git a/src/app/deposits/recurring-deposits/recurring-deposits-account-actions/add-charge-recurring-deposits-account/add-charge-recurring-deposits-account.component.html b/src/app/deposits/recurring-deposits/recurring-deposits-account-actions/add-charge-recurring-deposits-account/add-charge-recurring-deposits-account.component.html new file mode 100644 index 000000000..ffadc2d06 --- /dev/null +++ b/src/app/deposits/recurring-deposits/recurring-deposits-account-actions/add-charge-recurring-deposits-account/add-charge-recurring-deposits-account.component.html @@ -0,0 +1,93 @@ +
+ + + +
+ + + +
+ + Charge + + + {{ savingsCharge.name + ' (' + savingsCharge.currency.name + ')' }} + + + + Charge is required + + + +
+ + + Amount + + + Amount is required + + + + + Charge Calculation + + + {{ chargeCalculation.value }} + + + + + + Charge time type + + + {{ chargeTime.value }} + + + + + + Due for collection on + + + + + Due for collection on is required + + + + + Due On + + + + + Due Date is required + + + + + Repeats Every + + + +
+ +
+ + + + + + +
+ +
+ +
+ +
diff --git a/src/app/deposits/recurring-deposits/recurring-deposits-account-actions/add-charge-recurring-deposits-account/add-charge-recurring-deposits-account.component.scss b/src/app/deposits/recurring-deposits/recurring-deposits-account-actions/add-charge-recurring-deposits-account/add-charge-recurring-deposits-account.component.scss new file mode 100644 index 000000000..aeead06e0 --- /dev/null +++ b/src/app/deposits/recurring-deposits/recurring-deposits-account-actions/add-charge-recurring-deposits-account/add-charge-recurring-deposits-account.component.scss @@ -0,0 +1,3 @@ +.container { + width: 37rem; +} diff --git a/src/app/deposits/recurring-deposits/recurring-deposits-account-actions/add-charge-recurring-deposits-account/add-charge-recurring-deposits-account.component.spec.ts b/src/app/deposits/recurring-deposits/recurring-deposits-account-actions/add-charge-recurring-deposits-account/add-charge-recurring-deposits-account.component.spec.ts new file mode 100644 index 000000000..610b8f2c1 --- /dev/null +++ b/src/app/deposits/recurring-deposits/recurring-deposits-account-actions/add-charge-recurring-deposits-account/add-charge-recurring-deposits-account.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { AddChargeRecurringDepositsAccountComponent } from './add-charge-recurring-deposits-account.component'; + +describe('AddChargeRecurringDepositsAccountComponent', () => { + let component: AddChargeRecurringDepositsAccountComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ AddChargeRecurringDepositsAccountComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(AddChargeRecurringDepositsAccountComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/deposits/recurring-deposits/recurring-deposits-account-actions/add-charge-recurring-deposits-account/add-charge-recurring-deposits-account.component.ts b/src/app/deposits/recurring-deposits/recurring-deposits-account-actions/add-charge-recurring-deposits-account/add-charge-recurring-deposits-account.component.ts new file mode 100644 index 000000000..d349a75a5 --- /dev/null +++ b/src/app/deposits/recurring-deposits/recurring-deposits-account-actions/add-charge-recurring-deposits-account/add-charge-recurring-deposits-account.component.ts @@ -0,0 +1,141 @@ +/** Angular Imports */ +import { Component, OnInit } from '@angular/core'; +import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms'; +import { Router, ActivatedRoute } from '@angular/router'; +import { DatePipe } from '@angular/common'; + +/** Custom Services */ +import { SavingsService } from 'app/savings/savings.service'; + +/** + * Add Recurring Deposits Charge component. + * Recurring deposits endpoint is not supported so using Savings endpoint. + */ +@Component({ + selector: 'mifosx-add-charge-recurring-deposits-account', + templateUrl: './add-charge-recurring-deposits-account.component.html', + styleUrls: ['./add-charge-recurring-deposits-account.component.scss'] +}) +export class AddChargeRecurringDepositsAccountComponent implements OnInit { + + /** Minimum Due Date allowed. */ + minDate = new Date(2000, 0, 1); + /** Maximum Due Date allowed. */ + maxDate = new Date(); + /** Add Recurring Deposits Charge form. */ + recurringDepositsChargeForm: FormGroup; + /** savings charge options. */ + savingsChargeOptions: any; + /** savings Id of the savings account. */ + recurringDepositAccountId: string; + /** charge details */ + chargeDetails: any; + + /** + * Retrieves charge template data from `resolve` + * @param {FormBuilder} formBuilder Form Builder + * @param {ActivatedRoute} route Activated Route + * @param {Router} router Router + * @param {DatePipe} datePipe Date Pipe + * @param {SavingsService} savingsService Savings Service + */ + constructor( + private formBuilder: FormBuilder, + private route: ActivatedRoute, + private router: Router, + private datePipe: DatePipe, + private savingsService: SavingsService + ) { + this.route.data.subscribe((data: { recurringDepositsAccountActionData: any }) => { + this.savingsChargeOptions = data.recurringDepositsAccountActionData.chargeOptions; + }); + this.recurringDepositAccountId = this.route.parent.snapshot.params['recurringDepositAccountId']; + } + + /** + * Creates the Recurring Deposits Charge form. + */ + ngOnInit() { + this.createRecurringDepositsChargeForm(); + this.buildDependencies(); + } + + buildDependencies() { + this.recurringDepositsChargeForm.controls.chargeId.valueChanges.subscribe(chargeId => { + this.savingsService.getChargeTemplate(chargeId).subscribe((data: any) => { + this.chargeDetails = data; + const chargeTimeType = data.chargeTimeType.id; + if (data.chargeTimeType.value === 'Withdrawal Fee' || data.chargeTimeType.value === 'Saving No Activity Fee') { + this.chargeDetails.dueDateNotRequired = true; + } + if (data.chargeTimeType.value === 'Annual Fee' || data.chargeTimeType.value === 'Monthly Fee') { + this.chargeDetails.chargeTimeTypeAnnualOrMonth = true; + } + if (!this.chargeDetails.dueDateNotRequired && !this.chargeDetails.chargeTimeTypeAnnualOrMonth) { + this.recurringDepositsChargeForm.addControl('dueDate', new FormControl('', Validators.required)); + } else { + this.recurringDepositsChargeForm.removeControl('dueDate'); + } + if (!this.chargeDetails.dueDateNotRequired && this.chargeDetails.chargeTimeTypeAnnualOrMonth) { + this.recurringDepositsChargeForm.addControl('feeOnMonthDay', new FormControl('', Validators.required)); + } else { + this.recurringDepositsChargeForm.removeControl('feeOnMonthDay'); + } + if (chargeTimeType.value === 'Monthly Fee') { + this.recurringDepositsChargeForm.addControl('feeInterval', new FormControl(data.feeInterval, Validators.required)); + } else { + this.recurringDepositsChargeForm.removeControl('feeInterval'); + } + this.recurringDepositsChargeForm.patchValue({ + 'amount': data.amount, + 'chargeCalculationType': data.chargeCalculationType.id, + 'chargeTimeType': data.chargeTimeType.id + }); + }); + }); + } + + /** + * Creates the Recurring Deposits Charge form. + */ + createRecurringDepositsChargeForm() { + this.recurringDepositsChargeForm = this.formBuilder.group({ + 'chargeId': ['', Validators.required], + 'amount': ['', Validators.required], + 'chargeCalculationType': [{ value: '', disabled: true }], + 'chargeTimeType': [{ value: '', disabled: true }] + }); + } + + /** + * Submits savings charge. + */ + submit() { + const savingsCharge = this.recurringDepositsChargeForm.value; + savingsCharge.locale = 'en'; + if (!savingsCharge.feeInterval) { + savingsCharge.feeInterval = this.chargeDetails.feeInterval; + } + if (this.chargeDetails.dueDateNotRequired !== true) { + if (this.chargeDetails.chargeTimeTypeAnnualOrMonth === true) { + const monthDayFormat = 'MMMM-dd'; // TODO: Update once language and date settings are setup + savingsCharge.monthDayFormat = monthDayFormat; + if (savingsCharge.feeOnMonthDay) { + const prevDate = this.recurringDepositsChargeForm.value.feeOnMonthDay; + savingsCharge.feeOnMonthDay = this.datePipe.transform(prevDate, monthDayFormat); + } + } else { + const dateFormat = 'yyyy-MM-dd'; + savingsCharge.dateFormat = dateFormat; + if (savingsCharge.dueDate) { + const prevDate = this.recurringDepositsChargeForm.value.dueDate; + savingsCharge.dueDate = this.datePipe.transform(prevDate, dateFormat); + } + } + } + this.savingsService.createSavingsCharge(this.recurringDepositAccountId, 'charges', savingsCharge).subscribe(() => { + this.router.navigate(['../../'], { relativeTo: this.route }); + }); + } + +} diff --git a/src/app/deposits/recurring-deposits/recurring-deposits-account-actions/recurring-deposits-account-actions.component.html b/src/app/deposits/recurring-deposits/recurring-deposits-account-actions/recurring-deposits-account-actions.component.html index 1e9c0370b..07a67ee80 100644 --- a/src/app/deposits/recurring-deposits/recurring-deposits-account-actions/recurring-deposits-account-actions.component.html +++ b/src/app/deposits/recurring-deposits/recurring-deposits-account-actions/recurring-deposits-account-actions.component.html @@ -3,3 +3,4 @@ + diff --git a/src/app/deposits/recurring-deposits/recurring-deposits-account-actions/recurring-deposits-account-actions.component.ts b/src/app/deposits/recurring-deposits/recurring-deposits-account-actions/recurring-deposits-account-actions.component.ts index 9083d3162..214435386 100644 --- a/src/app/deposits/recurring-deposits/recurring-deposits-account-actions/recurring-deposits-account-actions.component.ts +++ b/src/app/deposits/recurring-deposits/recurring-deposits-account-actions/recurring-deposits-account-actions.component.ts @@ -15,12 +15,14 @@ export class RecurringDepositsAccountActionsComponent { 'Approve': boolean 'Reject': boolean 'Withdraw By Client': boolean + 'Add Charge': boolean } = { 'Activate': false, 'Undo Approval': false, 'Approve': false, 'Reject': false, - 'Withdraw By Client': false + 'Withdraw By Client': false, + 'Add Charge': false }; /** diff --git a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/charges-tab/charges-tab.component.ts b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/charges-tab/charges-tab.component.ts index 5ab80b8ee..1431f8b20 100644 --- a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/charges-tab/charges-tab.component.ts +++ b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/charges-tab/charges-tab.component.ts @@ -13,7 +13,7 @@ import { ActivatedRoute } from '@angular/router'; }) export class ChargesTabComponent implements OnInit { - /** Fixed Deposits Account Data */ + /** Recurring Deposits Account Data */ recurringDepositsAccountData: any; /** Charges Data */ chargesData: any[]; @@ -40,7 +40,7 @@ export class ChargesTabComponent implements OnInit { @ViewChild('chargesTable') chargesTableRef: MatTable; /** - * Retrieves Fixed Deposits Account Data from `resolve`. + * Retrieves Recurring Deposits Account Data from `resolve`. * @param {ActivatedRoute} route Activated Route. */ constructor(private route: ActivatedRoute) { diff --git a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/datatable-tabs/multi-row/multi-row.component.ts b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/datatable-tabs/multi-row/multi-row.component.ts index 04f514d4b..5bc85727d 100644 --- a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/datatable-tabs/multi-row/multi-row.component.ts +++ b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/datatable-tabs/multi-row/multi-row.component.ts @@ -57,7 +57,7 @@ export class MultiRowComponent implements OnInit, OnChanges { private datePipe: DatePipe, private savingsService: SavingsService, private dialog: MatDialog) { - this.accountId = this.route.parent.parent.snapshot.paramMap.get('fixedDepositAccountId'); + this.accountId = this.route.parent.parent.snapshot.paramMap.get('recurringDepositAccountId'); } /** diff --git a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/datatable-tabs/single-row/single-row.component.ts b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/datatable-tabs/single-row/single-row.component.ts index 88c13ccf2..23077423f 100644 --- a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/datatable-tabs/single-row/single-row.component.ts +++ b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/datatable-tabs/single-row/single-row.component.ts @@ -48,7 +48,7 @@ export class SingleRowComponent implements OnInit { private datePipe: DatePipe, private dialog: MatDialog, private savingsService: SavingsService) { - this.accountId = this.route.parent.parent.snapshot.paramMap.get('fixedDepositAccountId'); + this.accountId = this.route.parent.parent.snapshot.paramMap.get('recurringDepositAccountId'); } /** diff --git a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/recurring-deposits-account-view.component.ts b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/recurring-deposits-account-view.component.ts index 574d6e63f..aa00a4828 100644 --- a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/recurring-deposits-account-view.component.ts +++ b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/recurring-deposits-account-view.component.ts @@ -81,6 +81,7 @@ export class RecurringDepositsAccountViewComponent implements OnInit { case 'Approve': case 'Reject': case 'Undo Approval': + case 'Add Charge': case 'Withdraw By Client': this.router.navigate([`actions/${name}`], { relativeTo: this.route }); break; diff --git a/src/app/deposits/recurring-deposits/recurring-deposits-routing.module.ts b/src/app/deposits/recurring-deposits/recurring-deposits-routing.module.ts index 5af43ebc0..78c8fb900 100644 --- a/src/app/deposits/recurring-deposits/recurring-deposits-routing.module.ts +++ b/src/app/deposits/recurring-deposits/recurring-deposits-routing.module.ts @@ -21,6 +21,7 @@ import { RecurringDepositsAccountDataResolver } from './common-resolvers/recurri import { SavingsDatatableResolver } from 'app/savings/common-resolvers/savings-datatable.resolver'; import { SavingsDatatablesResolver } from 'app/savings/common-resolvers/savings-datatables.resolver'; import { RecurringDepositsAccountTemplateResolver } from './common-resolvers/recurring-deposits-account-template.resolver'; +import { RecurringDepositsAccountActionsResolver } from './common-resolvers/recurring-deposit-account-actions.resolver'; const routes: Routes = [ { @@ -95,6 +96,9 @@ const routes: Routes = [ path: 'actions/:name', data: { title: extract('Recurring Deposits Account Actions'), routeParamBreadcrumb: 'name' }, component: RecurringDepositsAccountActionsComponent, + resolve: { + recurringDepositsAccountActionData: RecurringDepositsAccountActionsResolver + } } ] } @@ -110,7 +114,8 @@ const routes: Routes = [ RecurringDepositsAccountDataResolver, SavingsDatatableResolver, SavingsDatatablesResolver, - RecurringDepositsAccountTemplateResolver + RecurringDepositsAccountTemplateResolver, + RecurringDepositsAccountActionsResolver ] }) export class RecurringDepositsRoutingModule {} diff --git a/src/app/deposits/recurring-deposits/recurring-deposits.module.ts b/src/app/deposits/recurring-deposits/recurring-deposits.module.ts index 5058ef2c3..ad7bfdf83 100644 --- a/src/app/deposits/recurring-deposits/recurring-deposits.module.ts +++ b/src/app/deposits/recurring-deposits/recurring-deposits.module.ts @@ -31,6 +31,7 @@ import { UndoApprovalRecurringDepositsAccountComponent } from './recurring-depos import { ApproveRecurringDepositsAccountComponent } from './recurring-deposits-account-actions/approve-recurring-deposits-account/approve-recurring-deposits-account.component'; import { RejectRecurringDepositsAccountComponent } from './recurring-deposits-account-actions/reject-recurring-deposits-account/reject-recurring-deposits-account.component'; import { WithdrawByClientRecurringDepositsAccountComponent } from './recurring-deposits-account-actions/withdraw-by-client-recurring-deposits-account/withdraw-by-client-recurring-deposits-account.component'; +import { AddChargeRecurringDepositsAccountComponent } from './recurring-deposits-account-actions/add-charge-recurring-deposits-account/add-charge-recurring-deposits-account.component'; /** * RecurringDeposits Module @@ -66,7 +67,8 @@ import { WithdrawByClientRecurringDepositsAccountComponent } from './recurring-d UndoApprovalRecurringDepositsAccountComponent, ApproveRecurringDepositsAccountComponent, RejectRecurringDepositsAccountComponent, - WithdrawByClientRecurringDepositsAccountComponent + WithdrawByClientRecurringDepositsAccountComponent, + AddChargeRecurringDepositsAccountComponent ], providers: [DatePipe] })