diff --git a/src/app/products/manage-tax-components/edit-tax-component/edit-tax-component.component.html b/src/app/products/manage-tax-components/edit-tax-component/edit-tax-component.component.html new file mode 100644 index 000000000..92c27e7d0 --- /dev/null +++ b/src/app/products/manage-tax-components/edit-tax-component/edit-tax-component.component.html @@ -0,0 +1,60 @@ +
+ + + +
+ + + +
+ + + Name + + + Name is required + + + + + Percentage + + + Percentage is required + + + + + Credit Account Type + + + + + Credit Account + + + + + Start Date + + + + + Start Date is required + + + +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/products/manage-tax-components/edit-tax-component/edit-tax-component.component.scss b/src/app/products/manage-tax-components/edit-tax-component/edit-tax-component.component.scss new file mode 100644 index 000000000..d774f68da --- /dev/null +++ b/src/app/products/manage-tax-components/edit-tax-component/edit-tax-component.component.scss @@ -0,0 +1,3 @@ +.container { + max-width: 37rem; +} diff --git a/src/app/products/manage-tax-components/edit-tax-component/edit-tax-component.component.spec.ts b/src/app/products/manage-tax-components/edit-tax-component/edit-tax-component.component.spec.ts new file mode 100644 index 000000000..4de1f6c84 --- /dev/null +++ b/src/app/products/manage-tax-components/edit-tax-component/edit-tax-component.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { EditTaxComponentComponent } from './edit-tax-component.component'; + +describe('EditTaxComponentComponent', () => { + let component: EditTaxComponentComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ EditTaxComponentComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(EditTaxComponentComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/products/manage-tax-components/edit-tax-component/edit-tax-component.component.ts b/src/app/products/manage-tax-components/edit-tax-component/edit-tax-component.component.ts new file mode 100644 index 000000000..7f26611db --- /dev/null +++ b/src/app/products/manage-tax-components/edit-tax-component/edit-tax-component.component.ts @@ -0,0 +1,84 @@ +/** Angular Imports */ +import { Component, OnInit } from '@angular/core'; +import { FormGroup, FormBuilder, Validators } from '@angular/forms'; +import { Router, ActivatedRoute } from '@angular/router'; +import { DatePipe } from '@angular/common'; + +/** Custom Services */ +import { ProductsService } from '../../products.service'; + +/** + * Edit tax component. + */ +@Component({ + selector: 'mifosx-edit-tax-component', + templateUrl: './edit-tax-component.component.html', + styleUrls: ['./edit-tax-component.component.scss'] +}) +export class EditTaxComponentComponent implements OnInit { + + /** Minimum date allowed. */ + minDate = new Date(2000, 0, 1); + /** Tax Component form. */ + taxComponentForm: FormGroup; + /** Tax Component data. */ + taxComponentData: any; + + /** + * Retrieves the offices data from `resolve`. + * @param {FormBuilder} formBuilder Form Builder. + * @param {ProductsService} productsService Products Service. + * @param {ActivatedRoute} route Activated Route. + * @param {Router} router Router for navigation. + * @param {DatePipe} datePipe Date Pipe to format date. + */ + constructor(private formBuilder: FormBuilder, + private productsService: ProductsService, + private route: ActivatedRoute, + private router: Router, + private datePipe: DatePipe) { + this.route.data.subscribe((data: { taxComponent: any }) => { + this.taxComponentData = data.taxComponent; + }); + } + + /** + * Creates the edit tax component form. + */ + ngOnInit() { + this.editTaxComponent(); + } + + /** + * Edit tax component form. + */ + editTaxComponent() { + this.taxComponentForm = this.formBuilder.group({ + 'name': [this.taxComponentData.name, [Validators.required]], + 'percentage': [this.taxComponentData.percentage, [Validators.required, Validators.pattern('^(0*[1-9][0-9]*(\\.[0-9]+)?|0+\\.[0-9]*[1-9][0-9]*)$'), Validators.max(100)]], + 'startDate': [this.taxComponentData.startDate && new Date(this.taxComponentData.startDate)], + 'creditAccountType': [{value: this.taxComponentData.creditAccountType.value, disabled: true}], + 'creditAccount': [{value: this.taxComponentData.creditAccount.name, disabled: true}] + }); + } + + /** + * Submits the edit tax component form and edits tax component, + * if successfull redirects to tax component. + */ + submit() { + const prevStartDate: Date = this.taxComponentForm.value.startDate; + // TODO: Update once language and date settings are setup + const dateFormat = 'yyyy-MM-dd'; + this.taxComponentForm.patchValue({ + startDate: this.datePipe.transform(prevStartDate, dateFormat) + }); + const taxComponent = this.taxComponentForm.value; + taxComponent.locale = 'en'; + taxComponent.dateFormat = dateFormat; + this.productsService.updateTaxComponent(this.taxComponentData.id, taxComponent).subscribe((response: any) => { + this.router.navigate(['../../', response.resourceId], { relativeTo: this.route }); + }); + } + +} diff --git a/src/app/products/manage-tax-components/view-tax-component/view-tax-component.component.html b/src/app/products/manage-tax-components/view-tax-component/view-tax-component.component.html index d02c8930b..577478c84 100644 --- a/src/app/products/manage-tax-components/view-tax-component/view-tax-component.component.html +++ b/src/app/products/manage-tax-components/view-tax-component/view-tax-component.component.html @@ -1,5 +1,5 @@
- diff --git a/src/app/products/products-routing.module.ts b/src/app/products/products-routing.module.ts index 05d8d6b56..bb29ad00d 100644 --- a/src/app/products/products-routing.module.ts +++ b/src/app/products/products-routing.module.ts @@ -37,6 +37,7 @@ import { ManageTaxComponentsComponent } from './manage-tax-components/manage-tax import { ManageTaxGroupsComponent } from './manage-tax-groups/manage-tax-groups.component'; import { ViewTaxComponentComponent } from './manage-tax-components/view-tax-component/view-tax-component.component'; import { CreateTaxComponentComponent } from './manage-tax-components/create-tax-component/create-tax-component.component'; +import { EditTaxComponentComponent } from './manage-tax-components/edit-tax-component/edit-tax-component.component'; /** Custom Resolvers */ import { LoanProductsResolver } from './loan-products/loan-products.resolver'; @@ -238,7 +239,15 @@ const routes: Routes = [ resolve: { taxComponent: TaxComponentResolver } - } + }, + { + path: 'edit', + data: { title: extract('Edit Tax Component'), breadcrumb: 'Edit', routeParamBreadcrumb: false }, + component: EditTaxComponentComponent, + resolve: { + taxComponent: TaxComponentResolver + } + }, ] } ] @@ -387,7 +396,8 @@ const routes: Routes = [ TaxComponentResolver, FloatingRateResolver, FloatingRatesResolver, - TaxComponentTemplateResolver + TaxComponentTemplateResolver, + EditTaxComponentComponent ] }) export class ProductsRoutingModule { } diff --git a/src/app/products/products.module.ts b/src/app/products/products.module.ts index 47105ead2..10e433e47 100644 --- a/src/app/products/products.module.ts +++ b/src/app/products/products.module.ts @@ -68,6 +68,7 @@ import { ViewFloatingRateComponent } from './floating-rates/view-floating-rate/v import { EditFloatingRateComponent } from './floating-rates/edit-floating-rate/edit-floating-rate.component'; import { FloatingRatePeriodDialogComponent } from './floating-rates/floating-rate-period-dialog/floating-rate-period-dialog.component'; import { CreateTaxComponentComponent } from './manage-tax-components/create-tax-component/create-tax-component.component'; +import { EditTaxComponentComponent } from './manage-tax-components/edit-tax-component/edit-tax-component.component'; /** * Products Module @@ -141,7 +142,8 @@ import { CreateTaxComponentComponent } from './manage-tax-components/create-tax- DepositProductIncentiveFormDialogComponent, ManageTaxGroupsComponent, ViewTaxComponentComponent, - CreateTaxComponentComponent + CreateTaxComponentComponent, + EditTaxComponentComponent ], entryComponents: [ FloatingRatePeriodDialogComponent diff --git a/src/app/products/products.service.ts b/src/app/products/products.service.ts index d411e8b56..5d2b4d3cf 100644 --- a/src/app/products/products.service.ts +++ b/src/app/products/products.service.ts @@ -165,6 +165,14 @@ export class ProductsService { return this.http.post('/taxes/component', taxComponent); } + /* + * @param {string} taxComponentId tax Component ID of tax Component to be edited. + * @returns {Observable} + */ + updateTaxComponent(taxComponentId: string, taxComponent: any): Observable { + return this.http.put(`/taxes/component/${taxComponentId}`, taxComponent); + } + /** * @returns {Observable} Tax Groups data */