@@ -0,0 +1,92 @@
|
||||
<div class="container">
|
||||
|
||||
<mat-card>
|
||||
|
||||
<form [formGroup]="holidayForm" (ngSubmit)="submit()">
|
||||
|
||||
<mat-card-content>
|
||||
|
||||
<div fxLayout="column">
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Name</mat-label>
|
||||
<input matInput required autofocus formControlName="name">
|
||||
<mat-error *ngIf="holidayForm.controls.name.hasError('required')">
|
||||
Name <strong>is required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>From Date</mat-label>
|
||||
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="fromDatePicker" required formControlName="fromDate">
|
||||
<mat-datepicker-toggle matSuffix [for]="fromDatePicker"></mat-datepicker-toggle>
|
||||
<mat-datepicker #fromDatePicker></mat-datepicker>
|
||||
<mat-error *ngIf="holidayForm.controls.fromDate.hasError('required')">
|
||||
From Date <strong>is required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>To Date</mat-label>
|
||||
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="toDatePicker" required formControlName="toDate">
|
||||
<mat-datepicker-toggle matSuffix [for]="toDatePicker"></mat-datepicker-toggle>
|
||||
<mat-datepicker #toDatePicker></mat-datepicker>
|
||||
<mat-error *ngIf="holidayForm.controls.toDate.hasError('required')">
|
||||
To Date <strong>is required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Repayment Scheduling Type</mat-label>
|
||||
<mat-select required formControlName="reschedulingType">
|
||||
<mat-option *ngFor="let repayments of repaymentSchedulingTypes" [value]="repayments.id">
|
||||
{{ repayments.value }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
<mat-error *ngIf="holidayForm.controls.reschedulingType.hasError('required')">
|
||||
Repayment Scheduling Type is <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field *ngIf="holidayForm.contains('repaymentsRescheduledTo')">
|
||||
<mat-label>Repayment scheduled to</mat-label>
|
||||
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="repaymentDatePicker" required formControlName="repaymentsRescheduledTo">
|
||||
<mat-datepicker-toggle matSuffix [for]="repaymentDatePicker"></mat-datepicker-toggle>
|
||||
<mat-datepicker #repaymentDatePicker></mat-datepicker>
|
||||
<mat-error *ngIf="holidayForm.controls.repaymentsRescheduledTo.hasError('required')">
|
||||
Repayment Scheduled To <strong>is required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Description</mat-label>
|
||||
<input matInput formControlName="description">
|
||||
</mat-form-field>
|
||||
|
||||
<!-- TODO: Replace multi-select by custom angular material tree -->
|
||||
<mat-form-field>
|
||||
<mat-label>Applicable Offices</mat-label>
|
||||
<mat-select required formControlName="offices" multiple>
|
||||
<mat-option *ngFor="let office of officesData" [value]="{ officeId: office.id }">
|
||||
{{ office.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
<mat-error *ngIf="holidayForm.controls.offices.hasError('required')">
|
||||
Offices 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]="!holidayForm.valid">Submit</button>
|
||||
</mat-card-actions>
|
||||
|
||||
</form>
|
||||
|
||||
</mat-card>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,3 @@
|
||||
.container{
|
||||
max-width: 37rem;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { CreateHolidayComponent } from './create-holiday.component';
|
||||
|
||||
describe('CreateHolidayComponent', () => {
|
||||
let component: CreateHolidayComponent;
|
||||
let fixture: ComponentFixture<CreateHolidayComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ CreateHolidayComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(CreateHolidayComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,108 @@
|
||||
/** Angular Imports. */
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { DatePipe } from '@angular/common';
|
||||
|
||||
/** Custom Services. */
|
||||
import { OrganizationService } from 'app/organization/organization.service';
|
||||
|
||||
/**
|
||||
* Create Holiday component.
|
||||
* TODO: Develop a custom angular checkbox tree and replace offices select.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'mifosx-create-holiday',
|
||||
templateUrl: './create-holiday.component.html',
|
||||
styleUrls: ['./create-holiday.component.scss']
|
||||
})
|
||||
export class CreateHolidayComponent implements OnInit {
|
||||
|
||||
/** Create Holiday form. */
|
||||
holidayForm: FormGroup;
|
||||
/** Repayment Scheduling data. */
|
||||
repaymentSchedulingTypes: any;
|
||||
/** Offices Data */
|
||||
officesData: any;
|
||||
/** Minimum Date allowed. */
|
||||
minDate = new Date(2000, 0, 1);
|
||||
/** Maximum Date allowed. */
|
||||
maxDate = new Date();
|
||||
|
||||
/**
|
||||
* Get offices and holiday template from `Resolver`.
|
||||
* @param {FormBuilder} formBuilder Form Builder.
|
||||
* @param {ActivatedRoute} route Activated Route.
|
||||
* @param {DatePipe} datePipe Date Pipe.
|
||||
* @param {OrganizationService} organizationService Organization Service.
|
||||
* @param {Router} router Router.
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private route: ActivatedRoute,
|
||||
private datePipe: DatePipe,
|
||||
private organizationService: OrganizationService,
|
||||
private router: Router ) {
|
||||
this.route.data.subscribe((data: { offices: any, holidayTemplate: any }) => {
|
||||
this.officesData = data.offices;
|
||||
this.repaymentSchedulingTypes = data.holidayTemplate;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.setHolidayForm();
|
||||
this.buildDependencies();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Holiday Form.
|
||||
*/
|
||||
setHolidayForm() {
|
||||
this.holidayForm = this.formBuilder.group({
|
||||
'name': ['', Validators.required],
|
||||
'fromDate': ['', Validators.required],
|
||||
'toDate': ['', Validators.required],
|
||||
'reschedulingType': ['', Validators.required],
|
||||
'description': [''],
|
||||
'offices': ['', Validators.required]
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the conditional controls.
|
||||
*/
|
||||
buildDependencies() {
|
||||
this.holidayForm.get('reschedulingType').valueChanges.subscribe((option: any) => {
|
||||
if (option === 2) {
|
||||
this.holidayForm.addControl('repaymentsRescheduledTo', new FormControl('', Validators.required));
|
||||
} else {
|
||||
this.holidayForm.removeControl('repaymentsRescheduledTo');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits the create holiday Form.
|
||||
*/
|
||||
submit() {
|
||||
const dateFormat = 'yyyy-MM-dd';
|
||||
const locale = 'en';
|
||||
this.holidayForm.patchValue({
|
||||
'fromDate': this.datePipe.transform(this.holidayForm.value.fromDate, dateFormat),
|
||||
'toDate': this.datePipe.transform(this.holidayForm.value.toDate, dateFormat),
|
||||
});
|
||||
if (this.holidayForm.contains('repaymentsRescheduledTo')) {
|
||||
this.holidayForm.patchValue({
|
||||
'repaymentsRescheduledTo': this.datePipe.transform(this.holidayForm.value.repaymentsRescheduledTo, dateFormat)
|
||||
});
|
||||
}
|
||||
const holiday = {
|
||||
...this.holidayForm.value,
|
||||
dateFormat,
|
||||
locale
|
||||
};
|
||||
this.organizationService.createHoliday(holiday).subscribe((response: any) => {
|
||||
this.router.navigate(['../', response.resourceId], { relativeTo: this.route });
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
.container{
|
||||
max-width: 37rem;
|
||||
max-width: 37rem;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<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 Holiday
|
||||
</button>
|
||||
|
||||
@@ -61,6 +61,7 @@ import { BulkLoanReassignmnetComponent } from './bulk-loan-reassignmnet/bulk-loa
|
||||
import { EditLoanProvisioningCriteriaComponent } from './loan-provisioning-criteria/edit-loan-provisioning-criteria/edit-loan-provisioning-criteria.component';
|
||||
import { StandingInstructionsHistoryComponent } from './standing-instructions-history/standing-instructions-history.component';
|
||||
import { FundMappingComponent } from './fund-mapping/fund-mapping.component';
|
||||
import { CreateHolidayComponent } from './holidays/create-holiday/create-holiday.component';
|
||||
|
||||
/** Custom Resolvers */
|
||||
import { LoanProvisioningCriteriaResolver } from './loan-provisioning-criteria/common-resolvers/loan-provisioning-criteria.resolver';
|
||||
@@ -607,6 +608,15 @@ const routes: Routes = [
|
||||
offices: OfficesResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'create',
|
||||
component: CreateHolidayComponent,
|
||||
data: { title: extract('Create Holiday'), breadcrumb: 'Create' },
|
||||
resolve: {
|
||||
offices: OfficesResolver,
|
||||
holidayTemplate: HolidayTemplateResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
data: { title: extract('View Holidays'), routeParamBreadcrumb: 'id' },
|
||||
|
||||
@@ -68,6 +68,7 @@ import { CreateLoanProvisioningCriteriaComponent } from './loan-provisioning-cri
|
||||
import { EditLoanProvisioningCriteriaComponent } from './loan-provisioning-criteria/edit-loan-provisioning-criteria/edit-loan-provisioning-criteria.component';
|
||||
import { StandingInstructionsHistoryComponent } from './standing-instructions-history/standing-instructions-history.component';
|
||||
import { FundMappingComponent } from './fund-mapping/fund-mapping.component';
|
||||
import { CreateHolidayComponent } from './holidays/create-holiday/create-holiday.component';
|
||||
|
||||
/**
|
||||
* Organization Module
|
||||
@@ -142,6 +143,7 @@ import { FundMappingComponent } from './fund-mapping/fund-mapping.component';
|
||||
EditLoanProvisioningCriteriaComponent,
|
||||
StandingInstructionsHistoryComponent,
|
||||
FundMappingComponent,
|
||||
CreateHolidayComponent,
|
||||
]
|
||||
})
|
||||
export class OrganizationModule { }
|
||||
|
||||
@@ -608,6 +608,15 @@ export class OrganizationService {
|
||||
return this.http.get('/holidays/template');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Holiday.
|
||||
* @param holidayData Holiday data to be created.
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
createHoliday(holidayData: any): Observable<any> {
|
||||
return this.http.post('/holidays', holidayData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Holiday.
|
||||
* @param holidayId Holiday Id to be updated.
|
||||
|
||||
Reference in New Issue
Block a user