Skip to content

Commit

Permalink
feat: add create saving product component
Browse files Browse the repository at this point in the history
- Add saving product stepper components
- Add create saving product component

Fixes: #189
  • Loading branch information
abhaychawla committed Jul 28, 2019
1 parent 0edfacf commit eec35be
Show file tree
Hide file tree
Showing 37 changed files with 2,093 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/app/products/products-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { CreateLoanProductComponent } from './loan-products/create-loan-product/
import { ViewLoanProductComponent } from './loan-products/view-loan-product/view-loan-product.component';
import { EditLoanProductComponent } from './loan-products/edit-loan-product/edit-loan-product.component';
import { SavingProductsComponent } from './saving-products/saving-products.component';
import { CreateSavingProductComponent } from './saving-products/create-saving-product/create-saving-product.component';
import { ManageTaxConfigurationsComponent } from './manage-tax-configurations/manage-tax-configurations.component';
import { RecurringDepositProductsComponent } from './recurring-deposit-products/recurring-deposit-products.component';
import { ChargesComponent } from './charges/charges.component';
Expand All @@ -28,6 +29,7 @@ import { LoanProductsTemplateResolver } from './loan-products/loan-products-temp
import { LoanProductResolver } from './loan-products/loan-product.resolver';
import { LoanProductAndTemplateResolver } from './loan-products/edit-loan-product/loan-product-and-template.resolver';
import { SavingProductsResolver } from './saving-products/saving-products.resolver';
import { SavingProductsTemplateResolver } from './saving-products/saving-products-template.resolver';
import { RecurringDepositProductsResolver } from './recurring-deposit-products/recurring-deposit-products.resolver';
import { ChargesResolver } from './charges/charges.resolver';
import { FixedDepositProductsResolver } from './fixed-deposit-products/fixed-deposit-products.resolver';
Expand Down Expand Up @@ -97,7 +99,15 @@ const routes: Routes = [
resolve: {
savingProducts: SavingProductsResolver
}
}
},
{
path: 'create',
component: CreateSavingProductComponent,
data: { title: extract('Create Saving Product'), breadcrumb: 'Create' },
resolve: {
savingProductsTemplate: SavingProductsTemplateResolver
}
},
]
},
{
Expand Down Expand Up @@ -169,6 +179,7 @@ const routes: Routes = [
LoanProductResolver,
LoanProductAndTemplateResolver,
SavingProductsResolver,
SavingProductsTemplateResolver,
RecurringDepositProductsResolver,
ChargesResolver,
FixedDepositProductsResolver,
Expand Down
18 changes: 17 additions & 1 deletion src/app/products/products.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ import { ManageTaxComponentsComponent } from './manage-tax-components/manage-tax
import { ViewLoanProductComponent } from './loan-products/view-loan-product/view-loan-product.component';
import { EditLoanProductComponent } from './loan-products/edit-loan-product/edit-loan-product.component';
import { SavingProductsComponent } from './saving-products/saving-products.component';
import { SavingProductDetailsStepComponent } from './saving-products/saving-product-stepper/saving-product-details-step/saving-product-details-step.component';
import { SavingProductCurrencyStepComponent } from './saving-products/saving-product-stepper/saving-product-currency-step/saving-product-currency-step.component';
import { SavingProductTermsStepComponent } from './saving-products/saving-product-stepper/saving-product-terms-step/saving-product-terms-step.component';
import { SavingProductSettingsStepComponent } from './saving-products/saving-product-stepper/saving-product-settings-step/saving-product-settings-step.component';
import { SavingProductChargesStepComponent } from './saving-products/saving-product-stepper/saving-product-charges-step/saving-product-charges-step.component';
import { SavingProductAccountingStepComponent } from './saving-products/saving-product-stepper/saving-product-accounting-step/saving-product-accounting-step.component';
import { SavingProductPreviewStepComponent } from './saving-products/saving-product-stepper/saving-product-preview-step/saving-product-preview-step.component';
import { CreateSavingProductComponent } from './saving-products/create-saving-product/create-saving-product.component';

/**
* Products Module
Expand Down Expand Up @@ -58,7 +66,15 @@ import { SavingProductsComponent } from './saving-products/saving-products.compo
ManageTaxComponentsComponent,
ViewLoanProductComponent,
EditLoanProductComponent,
SavingProductsComponent
SavingProductsComponent,
SavingProductDetailsStepComponent,
SavingProductCurrencyStepComponent,
SavingProductTermsStepComponent,
SavingProductSettingsStepComponent,
SavingProductChargesStepComponent,
SavingProductAccountingStepComponent,
SavingProductPreviewStepComponent,
CreateSavingProductComponent
],
entryComponents: [
],
Expand Down
8 changes: 8 additions & 0 deletions src/app/products/products.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ export class ProductsService {
return this.http.get('/savingsproducts');
}

createSavingProduct(savingProduct: string): Observable<any> {
return this.http.post('/savingsproducts', savingProduct);
}

getSavingProductsTemplate(): Observable<any> {
return this.http.get('/savingsproducts/template');
}

/**
* @returns {Observable<any>} Recurring deposit products data
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<div class="container">

<mat-horizontal-stepper class="mat-elevation-z8" labelPosition="bottom" #savingProductStepper>

<ng-template matStepperIcon="number">
<fa-icon icon="pencil-alt" size="sm"></fa-icon>
</ng-template>

<ng-template matStepperIcon="edit">
<fa-icon icon="pencil-alt" size="sm"></fa-icon>
</ng-template>

<ng-template matStepperIcon="done">
<fa-icon icon="check" size="sm"></fa-icon>
</ng-template>

<ng-template matStepperIcon="error">
<fa-icon icon="exclamation-triangle" size="lg"></fa-icon>
</ng-template>

<ng-template matStepperIcon="preview">
<fa-icon icon="eye" size="sm"></fa-icon>
</ng-template>

<mat-step [stepControl]="savingProductDetailsForm">

<ng-template matStepLabel>DETAILS</ng-template>

<mifosx-saving-product-details-step></mifosx-saving-product-details-step>

</mat-step>

<mat-step [stepControl]="savingProductCurrencyForm">

<ng-template matStepLabel>CURRENCY</ng-template>

<mifosx-saving-product-currency-step [savingProductsTemplate]="savingProductsTemplate"></mifosx-saving-product-currency-step>

</mat-step>

<mat-step [stepControl]="savingProductTermsForm">

<ng-template matStepLabel>TERMS</ng-template>

<mifosx-saving-product-terms-step [savingProductsTemplate]="savingProductsTemplate"></mifosx-saving-product-terms-step>

</mat-step>

<mat-step [stepControl]="savingProductSettingsForm">

<ng-template matStepLabel>SETTINGS</ng-template>

<mifosx-saving-product-settings-step [savingProductsTemplate]="savingProductsTemplate"></mifosx-saving-product-settings-step>

</mat-step>

<mat-step>

<ng-template matStepLabel>CHARGES</ng-template>

<mifosx-saving-product-charges-step
[savingProductsTemplate]="savingProductsTemplate"
[currencyCode]="savingProductCurrencyForm.get('currencyCode')"
>
</mifosx-saving-product-charges-step>

</mat-step>

<mat-step [stepControl]="savingProductAccountingForm">

<ng-template matStepLabel>ACCOUNTING</ng-template>

<mifosx-saving-product-accounting-step
[savingProductsTemplate]="savingProductsTemplate"
[accountingRuleData]="accountingRuleData"
[isDormancyTrackingActive]="savingProductSettingsForm.get('isDormancyTrackingActive')"
[savingProductFormValid]="savingProductFormValid"
>
</mifosx-saving-product-accounting-step>

</mat-step>

<mat-step state="preview" *ngIf="savingProductFormValid" completed>

<ng-template matStepLabel>PREVIEW</ng-template>

<mifosx-saving-product-preview-step
[savingProductsTemplate]="savingProductsTemplate"
[accountingRuleData]="accountingRuleData"
[savingProduct]="savingProduct"
(submit)="submit()"
>
</mifosx-saving-product-preview-step>

</mat-step>

</mat-horizontal-stepper>

</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fa-icon {
position: relative;
left: 5%;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { CreateSavingProductComponent } from './create-saving-product.component';

describe('CreateSavingProductComponent', () => {
let component: CreateSavingProductComponent;
let fixture: ComponentFixture<CreateSavingProductComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CreateSavingProductComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(CreateSavingProductComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';

import { SavingProductDetailsStepComponent } from '../saving-product-stepper/saving-product-details-step/saving-product-details-step.component';
import { SavingProductCurrencyStepComponent } from '../saving-product-stepper/saving-product-currency-step/saving-product-currency-step.component';
import { SavingProductTermsStepComponent } from '../saving-product-stepper/saving-product-terms-step/saving-product-terms-step.component';
import { SavingProductSettingsStepComponent } from '../saving-product-stepper/saving-product-settings-step/saving-product-settings-step.component';
import { SavingProductChargesStepComponent } from '../saving-product-stepper/saving-product-charges-step/saving-product-charges-step.component';
import { SavingProductAccountingStepComponent } from '../saving-product-stepper/saving-product-accounting-step/saving-product-accounting-step.component';

import { ProductsService } from 'app/products/products.service';

@Component({
selector: 'mifosx-create-saving-product',
templateUrl: './create-saving-product.component.html',
styleUrls: ['./create-saving-product.component.scss']
})
export class CreateSavingProductComponent implements OnInit {

@ViewChild(SavingProductDetailsStepComponent) savingProductDetailsStep: SavingProductDetailsStepComponent;
@ViewChild(SavingProductCurrencyStepComponent) savingProductCurrencyStep: SavingProductCurrencyStepComponent;
@ViewChild(SavingProductTermsStepComponent) savingProductTermsStep: SavingProductTermsStepComponent;
@ViewChild(SavingProductSettingsStepComponent) savingProductSettingsStep: SavingProductSettingsStepComponent;
@ViewChild(SavingProductChargesStepComponent) savingProductChargesStep: SavingProductChargesStepComponent;
@ViewChild(SavingProductAccountingStepComponent) savingProductAccountingStep: SavingProductAccountingStepComponent;

savingProductsTemplate: any;
accountingRuleData = ['None', 'Cash'];

constructor(private route: ActivatedRoute,
private productsService: ProductsService,
private router: Router) {
this.route.data.subscribe((data: { savingProductsTemplate: any }) => {
this.savingProductsTemplate = data.savingProductsTemplate;
});
}

ngOnInit() {
}

get savingProductDetailsForm() {
return this.savingProductDetailsStep.savingProductDetailsForm;
}

get savingProductCurrencyForm() {
return this.savingProductCurrencyStep.savingProductCurrencyForm;
}

get savingProductTermsForm() {
return this.savingProductTermsStep.savingProductTermsForm;
}

get savingProductSettingsForm() {
return this.savingProductSettingsStep.savingProductSettingsForm;
}

get savingProductAccountingForm() {
return this.savingProductAccountingStep.savingProductAccountingForm;
}

get savingProductFormValid() {
return (
this.savingProductDetailsForm.valid &&
this.savingProductCurrencyForm.valid &&
this.savingProductTermsForm.valid &&
this.savingProductSettingsForm.valid &&
this.savingProductAccountingForm.valid
);
}

get savingProduct() {
return {
...this.savingProductDetailsStep.savingProductDetails,
...this.savingProductCurrencyStep.savingProductCurrency,
...this.savingProductTermsStep.savingProductTerms,
...this.savingProductSettingsStep.savingProductSettings,
...this.savingProductChargesStep.savingProductCharges,
...this.savingProductAccountingStep.savingProductAccounting
};
}

submit() {
// TODO: Update once language and date settings are setup
const savingProduct = {
...this.savingProduct,
charges: this.savingProduct.charges.map((charge: any) => ({ id: charge.id })),
locale: 'en' // locale required for nominalAnnualInterestRate
};
delete savingProduct.advancedAccountingRules;
this.productsService.createSavingProduct(savingProduct)
.subscribe((response: any) => {
this.router.navigate(['../', response.resourceId], { relativeTo: this.route });
});
}

}
Loading

0 comments on commit eec35be

Please sign in to comment.