From eefb325bddb2897414c20965dbb13ed940513562 Mon Sep 17 00:00:00 2001
From: Muskan Khedia <36980003+muskankhedia@users.noreply.github.com>
Date: Wed, 5 Aug 2020 16:55:58 +0530
Subject: [PATCH] feat: add edit fixed deposits product (#1178)
Fixes: #466
Refer: #187
---
.../edit-fixed-deposit-product.component.html | 112 ++++++++++++++++
.../edit-fixed-deposit-product.component.scss | 0
...it-fixed-deposit-product.component.spec.ts | 25 ++++
.../edit-fixed-deposit-product.component.ts | 115 ++++++++++++++++
...d-deposit-product-and-template.resolver.ts | 32 +++++
...posit-product-accounting-step.component.ts | 54 ++++++++
...-deposit-product-charges-step.component.ts | 8 +-
...deposit-product-currency-step.component.ts | 16 ++-
...eposit-product-details-step.component.html | 7 +-
...-deposit-product-details-step.component.ts | 13 +-
...duct-interest-rate-chart-step.component.ts | 126 ++++++++++++++++++
...deposit-product-settings-step.component.ts | 20 +++
...ed-deposit-product-terms-step.component.ts | 8 ++
.../view-fixed-deposit-product.component.html | 19 +--
src/app/products/products-routing.module.ts | 27 ++--
src/app/products/products.module.ts | 4 +-
src/app/products/products.service.ts | 9 ++
17 files changed, 566 insertions(+), 29 deletions(-)
create mode 100644 src/app/products/fixed-deposit-products/edit-fixed-deposit-product/edit-fixed-deposit-product.component.html
create mode 100644 src/app/products/fixed-deposit-products/edit-fixed-deposit-product/edit-fixed-deposit-product.component.scss
create mode 100644 src/app/products/fixed-deposit-products/edit-fixed-deposit-product/edit-fixed-deposit-product.component.spec.ts
create mode 100644 src/app/products/fixed-deposit-products/edit-fixed-deposit-product/edit-fixed-deposit-product.component.ts
create mode 100644 src/app/products/fixed-deposit-products/edit-fixed-deposit-product/fixed-deposit-product-and-template.resolver.ts
diff --git a/src/app/products/fixed-deposit-products/edit-fixed-deposit-product/edit-fixed-deposit-product.component.html b/src/app/products/fixed-deposit-products/edit-fixed-deposit-product/edit-fixed-deposit-product.component.html
new file mode 100644
index 000000000..7951bcf79
--- /dev/null
+++ b/src/app/products/fixed-deposit-products/edit-fixed-deposit-product/edit-fixed-deposit-product.component.html
@@ -0,0 +1,112 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ DETAILS
+
+
+
+
+
+
+
+
+ CURRENCY
+
+
+
+
+
+
+
+
+ TERMS
+
+
+
+
+
+
+
+
+ SETTINGS
+
+
+
+
+
+
+
+
+ INTEREST RATE CHART
+
+
+
+
+
+
+
+
+ CHARGES
+
+
+
+
+
+
+
+
+ ACCOUNTING
+
+
+
+
+
+
+
+
+ PREVIEW
+
+
+
+
+
+
+
+
+
diff --git a/src/app/products/fixed-deposit-products/edit-fixed-deposit-product/edit-fixed-deposit-product.component.scss b/src/app/products/fixed-deposit-products/edit-fixed-deposit-product/edit-fixed-deposit-product.component.scss
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/app/products/fixed-deposit-products/edit-fixed-deposit-product/edit-fixed-deposit-product.component.spec.ts b/src/app/products/fixed-deposit-products/edit-fixed-deposit-product/edit-fixed-deposit-product.component.spec.ts
new file mode 100644
index 000000000..f796f3055
--- /dev/null
+++ b/src/app/products/fixed-deposit-products/edit-fixed-deposit-product/edit-fixed-deposit-product.component.spec.ts
@@ -0,0 +1,25 @@
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { EditFixedDepositProductComponent } from './edit-fixed-deposit-product.component';
+
+describe('EditFixedDepositProductComponent', () => {
+ let component: EditFixedDepositProductComponent;
+ let fixture: ComponentFixture;
+
+ beforeEach(async(() => {
+ TestBed.configureTestingModule({
+ declarations: [ EditFixedDepositProductComponent ]
+ })
+ .compileComponents();
+ }));
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(EditFixedDepositProductComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
diff --git a/src/app/products/fixed-deposit-products/edit-fixed-deposit-product/edit-fixed-deposit-product.component.ts b/src/app/products/fixed-deposit-products/edit-fixed-deposit-product/edit-fixed-deposit-product.component.ts
new file mode 100644
index 000000000..35839bb13
--- /dev/null
+++ b/src/app/products/fixed-deposit-products/edit-fixed-deposit-product/edit-fixed-deposit-product.component.ts
@@ -0,0 +1,115 @@
+import { Component, OnInit, ViewChild } from '@angular/core';
+import { ActivatedRoute, Router } from '@angular/router';
+
+import { FixedDepositProductDetailsStepComponent } from '../fixed-deposit-product-stepper/fixed-deposit-product-details-step/fixed-deposit-product-details-step.component';
+import { FixedDepositProductCurrencyStepComponent } from '../fixed-deposit-product-stepper/fixed-deposit-product-currency-step/fixed-deposit-product-currency-step.component';
+import { FixedDepositProductTermsStepComponent } from '../fixed-deposit-product-stepper/fixed-deposit-product-terms-step/fixed-deposit-product-terms-step.component';
+import { FixedDepositProductSettingsStepComponent } from '../fixed-deposit-product-stepper/fixed-deposit-product-settings-step/fixed-deposit-product-settings-step.component';
+import { FixedDepositProductInterestRateChartStepComponent } from '../fixed-deposit-product-stepper/fixed-deposit-product-interest-rate-chart-step/fixed-deposit-product-interest-rate-chart-step.component';
+import { FixedDepositProductChargesStepComponent } from '../fixed-deposit-product-stepper/fixed-deposit-product-charges-step/fixed-deposit-product-charges-step.component';
+import { FixedDepositProductAccountingStepComponent } from '../fixed-deposit-product-stepper/fixed-deposit-product-accounting-step/fixed-deposit-product-accounting-step.component';
+
+import { ProductsService } from 'app/products/products.service';
+
+@Component({
+ selector: 'mifosx-edit-fixed-deposit-product',
+ templateUrl: './edit-fixed-deposit-product.component.html',
+ styleUrls: ['./edit-fixed-deposit-product.component.scss']
+})
+export class EditFixedDepositProductComponent implements OnInit {
+
+ @ViewChild(FixedDepositProductDetailsStepComponent) fixedDepositProductDetailsStep: FixedDepositProductDetailsStepComponent;
+ @ViewChild(FixedDepositProductCurrencyStepComponent) fixedDepositProductCurrencyStep: FixedDepositProductCurrencyStepComponent;
+ @ViewChild(FixedDepositProductTermsStepComponent) fixedDepositProductTermsStep: FixedDepositProductTermsStepComponent;
+ @ViewChild(FixedDepositProductSettingsStepComponent) fixedDepositProductSettingsStep: FixedDepositProductSettingsStepComponent;
+ @ViewChild(FixedDepositProductInterestRateChartStepComponent) fixedDepositProductInterestRateChartStep: FixedDepositProductInterestRateChartStepComponent;
+ @ViewChild(FixedDepositProductChargesStepComponent) fixedDepositProductChargesStep: FixedDepositProductChargesStepComponent;
+ @ViewChild(FixedDepositProductAccountingStepComponent) fixedDepositProductAccountingStep: FixedDepositProductAccountingStepComponent;
+
+ fixedDepositProductsTemplate: any;
+ accountingRuleData = ['None', 'Cash'];
+
+ constructor(private route: ActivatedRoute,
+ private productsService: ProductsService,
+ private router: Router) {
+ this.route.data.subscribe((data: { fixedDepositProductAndTemplate: any }) => {
+ this.fixedDepositProductsTemplate = data.fixedDepositProductAndTemplate;
+ });
+ }
+
+ ngOnInit() {
+ }
+
+ get fixedDepositProductDetailsForm() {
+ return this.fixedDepositProductDetailsStep.fixedDepositProductDetailsForm;
+ }
+
+ get fixedDepositProductCurrencyForm() {
+ return this.fixedDepositProductCurrencyStep.fixedDepositProductCurrencyForm;
+ }
+
+ get fixedDepositProductTermsForm() {
+ return this.fixedDepositProductTermsStep.fixedDepositProductTermsForm;
+ }
+
+ get fixedDepositProductSettingsForm() {
+ return this.fixedDepositProductSettingsStep.fixedDepositProductSettingsForm;
+ }
+
+ get fixedDepositProductInterestRateChartForm() {
+ return this.fixedDepositProductInterestRateChartStep.fixedDepositProductInterestRateChartForm;
+ }
+
+ get fixedDepositProductAccountingForm() {
+ return this.fixedDepositProductAccountingStep.fixedDepositProductAccountingForm;
+ }
+
+ get fixedDepositProductFormValidAndNotPrinstine() {
+ return (
+ this.fixedDepositProductDetailsForm.valid &&
+ this.fixedDepositProductCurrencyForm.valid &&
+ this.fixedDepositProductTermsForm.valid &&
+ this.fixedDepositProductSettingsForm.valid &&
+ this.fixedDepositProductInterestRateChartForm.valid &&
+ this.fixedDepositProductAccountingForm.valid &&
+ (
+ this.fixedDepositProductDetailsForm.pristine ||
+ this.fixedDepositProductCurrencyForm.pristine ||
+ this.fixedDepositProductTermsForm.pristine ||
+ this.fixedDepositProductSettingsForm.pristine ||
+ this.fixedDepositProductInterestRateChartForm.pristine ||
+ this.fixedDepositProductAccountingForm.pristine
+ )
+ );
+ }
+
+ get fixedDepositProduct() {
+ return {
+ ...this.fixedDepositProductDetailsStep.fixedDepositProductDetails,
+ ...this.fixedDepositProductCurrencyStep.fixedDepositProductCurrency,
+ ...this.fixedDepositProductTermsStep.fixedDepositProductTerms,
+ ...this.fixedDepositProductSettingsStep.fixedDepositProductSettings,
+ ...this.fixedDepositProductInterestRateChartStep.fixedDepositProductInterestRateChart,
+ ...this.fixedDepositProductChargesStep.fixedDepositProductCharges,
+ ...this.fixedDepositProductAccountingStep.fixedDepositProductAccounting
+ };
+ }
+
+ submit() {
+ // TODO: Update once language and date settings are setup
+ const fixedDepositProduct = {
+ ...this.fixedDepositProduct,
+ charges: this.fixedDepositProduct.charges.map((charge: any) => ({ id: charge.id })),
+ locale: 'en' // locale required for depositAmount
+ };
+ if (!fixedDepositProduct.description) {
+ fixedDepositProduct.description = '';
+ }
+ delete fixedDepositProduct.advancedAccountingRules;
+ this.productsService.updateFixedDepositProduct(this.fixedDepositProductsTemplate.id, fixedDepositProduct)
+ .subscribe((response: any) => {
+ this.router.navigate(['../'], { relativeTo: this.route });
+ });
+ }
+
+}
diff --git a/src/app/products/fixed-deposit-products/edit-fixed-deposit-product/fixed-deposit-product-and-template.resolver.ts b/src/app/products/fixed-deposit-products/edit-fixed-deposit-product/fixed-deposit-product-and-template.resolver.ts
new file mode 100644
index 000000000..8926adae2
--- /dev/null
+++ b/src/app/products/fixed-deposit-products/edit-fixed-deposit-product/fixed-deposit-product-and-template.resolver.ts
@@ -0,0 +1,32 @@
+/** Angular Imports */
+import { Injectable } from '@angular/core';
+import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
+
+/** rxjs Imports */
+import { Observable } from 'rxjs';
+
+/** Custom Services */
+import { ProductsService } from '../../products.service';
+
+/**
+ * Fixed Deposits Account Template resolver.
+ */
+@Injectable()
+export class FixedDepositProductAndTemplateResolver implements Resolve