+96
@@ -0,0 +1,96 @@
|
||||
<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 type="number" matInput required formControlName="percentage">
|
||||
<mat-error *ngIf="taxComponentForm.controls.percentage.hasError('required')">
|
||||
Percentage is <strong>required</strong>
|
||||
</mat-error>
|
||||
<mat-error *ngIf="taxComponentForm.controls.percentage.hasError('pattern') ||
|
||||
taxComponentForm.controls.percentage.hasError('max')">
|
||||
Percentage <strong>should</strong> be larger than 0 and at most 100
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Debit Account Type</mat-label>
|
||||
<mat-select formControlName="debitAccountType">
|
||||
<mat-option *ngFor="let debitAccountType of debitAccountTypeData" [value]="debitAccountType.id">
|
||||
{{ debitAccountType.value }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field *ngIf="taxComponentForm.controls.debitAccountType.value">
|
||||
<mat-label>Debit Account</mat-label>
|
||||
<mat-select required formControlName="debitAcountId">
|
||||
<mat-option *ngFor="let debitAccount of debitAccountData" [value]="debitAccount.id">
|
||||
{{ debitAccount.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
<mat-error *ngIf="taxComponentForm.controls.debitAcountId.hasError('required')">
|
||||
Debit account is <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Credit Account Type</mat-label>
|
||||
<mat-select formControlName="creditAccountType">
|
||||
<mat-option *ngFor="let creditAccountType of creditAccountTypeData" [value]="creditAccountType.id">
|
||||
{{ creditAccountType.value }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field *ngIf="taxComponentForm.controls.creditAccountType.value">
|
||||
<mat-label>Credit Account</mat-label>
|
||||
<mat-select required formControlName="creditAcountId">
|
||||
<mat-option *ngFor="let creditAccount of creditAccountData" [value]="creditAccount.id">
|
||||
{{ creditAccount.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
<mat-error *ngIf="taxComponentForm.controls.creditAcountId.hasError('required')">
|
||||
Credit account is <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Start date</mat-label>
|
||||
<input matInput [min]="minDate" [max]="maxDate" [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 { CreateTaxComponentComponent } from './create-tax-component.component';
|
||||
|
||||
describe('CreateTaxComponentComponent', () => {
|
||||
let component: CreateTaxComponentComponent;
|
||||
let fixture: ComponentFixture<CreateTaxComponentComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ CreateTaxComponentComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(CreateTaxComponentComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
/** 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 { ProductsService } from '../../products.service';
|
||||
|
||||
/**
|
||||
* Create Tax Component component.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'mifosx-create-tax-component',
|
||||
templateUrl: './create-tax-component.component.html',
|
||||
styleUrls: ['./create-tax-component.component.scss']
|
||||
})
|
||||
export class CreateTaxComponentComponent implements OnInit {
|
||||
|
||||
/** Minimum start date allowed. */
|
||||
minDate = new Date();
|
||||
/** Maximum start date allowed. */
|
||||
maxDate = new Date(new Date().setFullYear(new Date().getFullYear() + 10));
|
||||
/** Tax Component form. */
|
||||
taxComponentForm: FormGroup;
|
||||
/** Tax Component template data. */
|
||||
taxComponentTemplateData: any;
|
||||
/** Credit Account Type data. */
|
||||
creditAccountTypeData: any;
|
||||
/** Credit Account data. */
|
||||
creditAccountData: any;
|
||||
/** Debit Account Type data. */
|
||||
debitAccountTypeData: any;
|
||||
/** Debit Account data. */
|
||||
debitAccountData: any;
|
||||
|
||||
/**
|
||||
* Retrieves the tax Component template 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: { taxComponentTemplate: any }) => {
|
||||
this.taxComponentTemplateData = data.taxComponentTemplate;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the tax Component form
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.createTaxComponentForm();
|
||||
this.setConditionalControls();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the tax Component form
|
||||
*/
|
||||
createTaxComponentForm() {
|
||||
this.creditAccountTypeData = this.debitAccountTypeData = this.taxComponentTemplateData.glAccountTypeOptions;
|
||||
this.taxComponentForm = this.formBuilder.group({
|
||||
'name': ['', Validators.required],
|
||||
'percentage': ['', [Validators.required, Validators.pattern('^(0*[1-9][0-9]*(\\.[0-9]+)?|0+\\.[0-9]*[1-9][0-9]*)$'), Validators.max(100)]],
|
||||
'creditAccountType': [''],
|
||||
'debitAccountType': [''],
|
||||
'startDate': ['', Validators.required],
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the conditional controls of the tax Component form
|
||||
*/
|
||||
setConditionalControls() {
|
||||
this.taxComponentForm.get('debitAccountType').valueChanges.subscribe(debitAccountTypeId => {
|
||||
this.debitAccountData = this.getAccountsData(debitAccountTypeId);
|
||||
this.taxComponentForm.addControl('debitAcountId', new FormControl('', Validators.required));
|
||||
});
|
||||
this.taxComponentForm.get('creditAccountType').valueChanges.subscribe(creditAccountTypeId => {
|
||||
this.creditAccountData = this.getAccountsData(creditAccountTypeId);
|
||||
this.taxComponentForm.addControl('creditAcountId', new FormControl('', Validators.required));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} accountTypeId Account type ID of account type.
|
||||
* @returns {any} Accounts data
|
||||
*/
|
||||
getAccountsData(accountTypeId: number) {
|
||||
switch (accountTypeId) {
|
||||
case 1:
|
||||
return this.taxComponentTemplateData.glAccountOptions.assetAccountOptions;
|
||||
case 2:
|
||||
return this.taxComponentTemplateData.glAccountOptions.liabilityAccountOptions;
|
||||
case 3:
|
||||
return this.taxComponentTemplateData.glAccountOptions.equityAccountOptions;
|
||||
case 4:
|
||||
return this.taxComponentTemplateData.glAccountOptions.incomeAccountOptions;
|
||||
case 5:
|
||||
return this.taxComponentTemplateData.glAccountOptions.expenseAccountOptions;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits the tax Component form and creates the tax Component,
|
||||
* if successful redirects to Tax Components.
|
||||
*/
|
||||
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.createTaxComponent(taxComponent).subscribe((response: any) => {
|
||||
this.router.navigate(['../', response.resourceId], { relativeTo: this.route });
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
|
||||
<button mat-raised-button color="primary">
|
||||
<button mat-raised-button color="primary" [routerLink]="['create']">
|
||||
<fa-icon icon="plus"></fa-icon>
|
||||
Create Tax Component
|
||||
</button>
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/** Angular Imports */
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Resolve } from '@angular/router';
|
||||
|
||||
/** rxjs Imports */
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
/** Custom Services */
|
||||
import { ProductsService } from '../products.service';
|
||||
|
||||
/**
|
||||
* Tax Component template data resolver.
|
||||
*/
|
||||
@Injectable()
|
||||
export class TaxComponentTemplateResolver implements Resolve<Object> {
|
||||
|
||||
/**
|
||||
* @param {ProductsService} productsService Products service.
|
||||
*/
|
||||
constructor(private productsService: ProductsService) {}
|
||||
|
||||
/**
|
||||
* Returns the tax components template data.
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
resolve(): Observable<any> {
|
||||
return this.productsService.getTaxComponentTemplate();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,6 +36,7 @@ import { EditFloatingRateComponent } from './floating-rates/edit-floating-rate/e
|
||||
import { ManageTaxComponentsComponent } from './manage-tax-components/manage-tax-components.component';
|
||||
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';
|
||||
|
||||
/** Custom Resolvers */
|
||||
import { LoanProductsResolver } from './loan-products/loan-products.resolver';
|
||||
@@ -61,6 +62,7 @@ import { FloatingRateResolver } from './floating-rates/floating-rate.resolver';
|
||||
import { ManageTaxComponentsResolver } from './manage-tax-components/manage-tax-components.resolver';
|
||||
import { ManageTaxGroupsResolver } from './manage-tax-groups/manage-tax-groups.resolver';
|
||||
import { TaxComponentResolver } from './manage-tax-components/tax-component.resolver';
|
||||
import { TaxComponentTemplateResolver } from './manage-tax-components/tax-component-template.resolver';
|
||||
|
||||
/** Products Routes */
|
||||
const routes: Routes = [
|
||||
@@ -218,6 +220,14 @@ const routes: Routes = [
|
||||
taxComponents: ManageTaxComponentsResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'create',
|
||||
component: CreateTaxComponentComponent,
|
||||
data: { title: extract('Create Tax Component'), breadcrumb: 'Create' },
|
||||
resolve: {
|
||||
taxComponentTemplate: TaxComponentTemplateResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
data: { title: extract('View Tax Component'), routeParamBreadcrumb: 'id' },
|
||||
@@ -376,7 +386,8 @@ const routes: Routes = [
|
||||
ManageTaxGroupsResolver,
|
||||
TaxComponentResolver,
|
||||
FloatingRateResolver,
|
||||
FloatingRatesResolver
|
||||
FloatingRatesResolver,
|
||||
TaxComponentTemplateResolver
|
||||
]
|
||||
})
|
||||
export class ProductsRoutingModule { }
|
||||
|
||||
@@ -67,6 +67,7 @@ import { CreateFloatingRateComponent } from './floating-rates/create-floating-ra
|
||||
import { ViewFloatingRateComponent } from './floating-rates/view-floating-rate/view-floating-rate.component';
|
||||
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';
|
||||
|
||||
/**
|
||||
* Products Module
|
||||
@@ -139,7 +140,8 @@ import { FloatingRatePeriodDialogComponent } from './floating-rates/floating-rat
|
||||
FixedDepositProductPreviewStepComponent,
|
||||
DepositProductIncentiveFormDialogComponent,
|
||||
ManageTaxGroupsComponent,
|
||||
ViewTaxComponentComponent
|
||||
ViewTaxComponentComponent,
|
||||
CreateTaxComponentComponent
|
||||
],
|
||||
entryComponents: [
|
||||
FloatingRatePeriodDialogComponent
|
||||
|
||||
@@ -150,6 +150,21 @@ export class ProductsService {
|
||||
return this.http.get(`/taxes/component/${taxComponentId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Observable<any>} Tax Components Template data.
|
||||
*/
|
||||
getTaxComponentTemplate(): Observable<any> {
|
||||
return this.http.get('/taxes/component/template');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} taxComponent Tax Component to be created.
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
createTaxComponent(taxComponent: any): Observable<any> {
|
||||
return this.http.post('/taxes/component', taxComponent);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Observable<any>} Tax Groups data
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user