diff --git a/src/app/organization/holidays/create-holiday/create-holiday.component.html b/src/app/organization/holidays/create-holiday/create-holiday.component.html new file mode 100644 index 000000000..088d31e8e --- /dev/null +++ b/src/app/organization/holidays/create-holiday/create-holiday.component.html @@ -0,0 +1,92 @@ +
+ + + +
+ + + +
+ + + Name + + + Name is required + + + + + From Date + + + + + From Date is required + + + + + To Date + + + + + To Date is required + + + + + Repayment Scheduling Type + + + {{ repayments.value }} + + + + Repayment Scheduling Type is required + + + + + Repayment scheduled to + + + + + Repayment Scheduled To is required + + + + + Description + + + + + + Applicable Offices + + + {{ office.name }} + + + + Offices is required + + + +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/organization/holidays/create-holiday/create-holiday.component.scss b/src/app/organization/holidays/create-holiday/create-holiday.component.scss new file mode 100644 index 000000000..690b3262a --- /dev/null +++ b/src/app/organization/holidays/create-holiday/create-holiday.component.scss @@ -0,0 +1,3 @@ +.container{ + max-width: 37rem; +} diff --git a/src/app/organization/holidays/create-holiday/create-holiday.component.spec.ts b/src/app/organization/holidays/create-holiday/create-holiday.component.spec.ts new file mode 100644 index 000000000..b8964339e --- /dev/null +++ b/src/app/organization/holidays/create-holiday/create-holiday.component.spec.ts @@ -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; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CreateHolidayComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CreateHolidayComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/organization/holidays/create-holiday/create-holiday.component.ts b/src/app/organization/holidays/create-holiday/create-holiday.component.ts new file mode 100644 index 000000000..476fd662e --- /dev/null +++ b/src/app/organization/holidays/create-holiday/create-holiday.component.ts @@ -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 }); + }); + } + +} diff --git a/src/app/organization/holidays/edit-holiday/edit-holiday.component.scss b/src/app/organization/holidays/edit-holiday/edit-holiday.component.scss index 0f0bec918..690b3262a 100644 --- a/src/app/organization/holidays/edit-holiday/edit-holiday.component.scss +++ b/src/app/organization/holidays/edit-holiday/edit-holiday.component.scss @@ -1,3 +1,3 @@ .container{ - max-width: 37rem; + max-width: 37rem; } diff --git a/src/app/organization/holidays/holidays.component.html b/src/app/organization/holidays/holidays.component.html index decd3daae..ed8be2255 100644 --- a/src/app/organization/holidays/holidays.component.html +++ b/src/app/organization/holidays/holidays.component.html @@ -1,6 +1,6 @@
- diff --git a/src/app/organization/organization-routing.module.ts b/src/app/organization/organization-routing.module.ts index a872488e8..121142e75 100644 --- a/src/app/organization/organization-routing.module.ts +++ b/src/app/organization/organization-routing.module.ts @@ -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' }, diff --git a/src/app/organization/organization.module.ts b/src/app/organization/organization.module.ts index cff8c19ca..92215dc2a 100644 --- a/src/app/organization/organization.module.ts +++ b/src/app/organization/organization.module.ts @@ -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 { } diff --git a/src/app/organization/organization.service.ts b/src/app/organization/organization.service.ts index 5ed1473fa..3ecae14ff 100644 --- a/src/app/organization/organization.service.ts +++ b/src/app/organization/organization.service.ts @@ -608,6 +608,15 @@ export class OrganizationService { return this.http.get('/holidays/template'); } + /** + * Create Holiday. + * @param holidayData Holiday data to be created. + * @returns {Observable} + */ + createHoliday(holidayData: any): Observable { + return this.http.post('/holidays', holidayData); + } + /** * Update Holiday. * @param holidayId Holiday Id to be updated.