+60
@@ -0,0 +1,60 @@
|
||||
<div class="container">
|
||||
|
||||
<mat-card>
|
||||
|
||||
<form [formGroup]="taxComponentForm" (ngSubmit)="submit()">
|
||||
|
||||
<mat-card-content>
|
||||
|
||||
<div fxLayout="column">
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Name</mat-label>
|
||||
<input matInput required formControlName="name">
|
||||
<mat-error *ngIf="taxComponentForm.controls.name.hasError('required')">
|
||||
Name is <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Percentage</mat-label>
|
||||
<input matInput required formControlName="percentage">
|
||||
<mat-error *ngIf="taxComponentForm.controls.name.hasError('required')">
|
||||
Percentage is <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field *ngIf="taxComponentData.creditAccountType.value">
|
||||
<mat-label>Credit Account Type</mat-label>
|
||||
<input matInput formControlName="creditAccountType">
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field *ngIf="taxComponentData.creditAccount.name">
|
||||
<mat-label>Credit Account</mat-label>
|
||||
<input matInput formControlName="creditAccount">
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Start Date</mat-label>
|
||||
<input matInput [min]="minDate" [matDatepicker]="startDatePicker" required formControlName="startDate">
|
||||
<mat-datepicker-toggle matSuffix [for]="startDatePicker"></mat-datepicker-toggle>
|
||||
<mat-datepicker #startDatePicker></mat-datepicker>
|
||||
<mat-error *ngIf="taxComponentForm.controls.startDate.hasError('required')">
|
||||
Start Date is <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
</div>
|
||||
|
||||
</mat-card-content>
|
||||
|
||||
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
|
||||
<button type="button" mat-raised-button [routerLink]="['../']">Cancel</button>
|
||||
<button mat-raised-button color="primary" [disabled]="!taxComponentForm.valid">Submit</button>
|
||||
</mat-card-actions>
|
||||
|
||||
</form>
|
||||
|
||||
</mat-card>
|
||||
|
||||
</div>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
.container {
|
||||
max-width: 37rem;
|
||||
}
|
||||
+25
@@ -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<EditTaxComponentComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ EditTaxComponentComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(EditTaxComponentComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
+84
@@ -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 });
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<div class="container m-b-20" fxLayout="row" fxLayout.lt-md="column" fxLayoutAlign="end" fxLayoutGap="2%">
|
||||
<button mat-raised-button color="primary">
|
||||
<button mat-raised-button color="primary" [routerLink]="['edit']">
|
||||
<fa-icon icon="edit"></fa-icon>
|
||||
Edit
|
||||
</button>
|
||||
|
||||
@@ -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 { }
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<any>}
|
||||
*/
|
||||
updateTaxComponent(taxComponentId: string, taxComponent: any): Observable<any> {
|
||||
return this.http.put(`/taxes/component/${taxComponentId}`, taxComponent);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Observable<any>} Tax Groups data
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user