diff --git a/src/app/clients/client-stepper/client-datatable-step/client-datatable-step.component.html b/src/app/clients/client-stepper/client-datatable-step/client-datatable-step.component.html new file mode 100644 index 000000000..6fd114f57 --- /dev/null +++ b/src/app/clients/client-stepper/client-datatable-step/client-datatable-step.component.html @@ -0,0 +1,48 @@ +
+ +
+ +
+ + + {{getInputName(datatableInput)}} + + + + {{ code.value }} + + + + + + + + + + + + + + + + {{getInputName(datatableInput)}} + +
+ +
+ +
+ + +
+ +
diff --git a/src/app/clients/client-stepper/client-datatable-step/client-datatable-step.component.scss b/src/app/clients/client-stepper/client-datatable-step/client-datatable-step.component.scss new file mode 100644 index 000000000..8817bcc31 --- /dev/null +++ b/src/app/clients/client-stepper/client-datatable-step/client-datatable-step.component.scss @@ -0,0 +1,7 @@ +.date-picker { + width: 92%; +} + +mat-checkbox { + margin-top: 30px; +} diff --git a/src/app/clients/client-stepper/client-datatable-step/client-datatable-step.component.spec.ts b/src/app/clients/client-stepper/client-datatable-step/client-datatable-step.component.spec.ts new file mode 100644 index 000000000..3ab8e5631 --- /dev/null +++ b/src/app/clients/client-stepper/client-datatable-step/client-datatable-step.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ClientDatatableStepComponent } from './client-datatable-step.component'; + +describe('ClientDatatableStepComponent', () => { + let component: ClientDatatableStepComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ ClientDatatableStepComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(ClientDatatableStepComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/clients/client-stepper/client-datatable-step/client-datatable-step.component.ts b/src/app/clients/client-stepper/client-datatable-step/client-datatable-step.component.ts new file mode 100644 index 000000000..85d5f0ca2 --- /dev/null +++ b/src/app/clients/client-stepper/client-datatable-step/client-datatable-step.component.ts @@ -0,0 +1,104 @@ +import { Component, Input, OnInit } from '@angular/core'; +import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; +import { Dates } from 'app/core/utils/dates'; +import { SettingsService } from 'app/settings/settings.service'; + +@Component({ + selector: 'mifosx-client-datatable-step', + templateUrl: './client-datatable-step.component.html', + styleUrls: ['./client-datatable-step.component.scss'] +}) +export class ClientDatatableStepComponent implements OnInit { + /** Input Fields Data */ + @Input() datatableData: any; + /** Create Input Form */ + datatableForm: FormGroup; + + datatableInputs: any = []; + + constructor(private formBuilder: FormBuilder, + private settingsService: SettingsService, + private dateUtils: Dates) { } + + ngOnInit(): void { + this.datatableInputs = this.datatableData.columnHeaderData.filter((column: any) => { + return ((column.columnName !== 'id') && (column.columnName !== 'client_id') && (column.columnName !== 'created_at') && (column.columnName !== 'updated_at')); + }); + const inputItems: any = {}; + this.datatableInputs.forEach((input: any) => { + input.controlName = this.getInputName(input); + if (!input.isColumnNullable) { + if (this.isNumeric(input.columnDisplayType)) { + inputItems[input.controlName] = new FormControl(0, [Validators.required]); + } else { + inputItems[input.controlName] = new FormControl('', [Validators.required]); + } + } else { + inputItems[input.controlName] = new FormControl(''); + } + }); + this.datatableForm = this.formBuilder.group(inputItems); + } + + getInputName(datatableInput: any): string { + if (datatableInput.columnName && datatableInput.columnName.includes('_cd_')) { + return datatableInput.columnName.split('_cd_')[0]; + } + return datatableInput.columnName; + } + + isNumeric(columnType: string) { + return this.isColumnType(columnType, 'INTEGER') || this.isColumnType(columnType, 'DECIMAL'); + } + + isDate(columnType: string) { + return this.isColumnType(columnType, 'DATE') || this.isColumnType(columnType, 'DATETIME'); + } + + isBoolean(columnType: string) { + return this.isColumnType(columnType, 'BOOLEAN'); + } + + isDropdown(columnType: string) { + return this.isColumnType(columnType, 'CODELOOKUP'); + } + + isString(columnType: string) { + return this.isColumnType(columnType, 'STRING'); + } + + isColumnType(columnType: string, expectedType: string) { + return (columnType === expectedType); + } + + get payload(): any { + const dateFormat = this.settingsService.dateFormat; + const datatableDataValues = this.datatableForm.value; + const data = { + locale: this.settingsService.language.code + }; + let existDate = false; + this.datatableInputs.forEach((input: any) => { + const controlName = this.getInputName(input); + if (this.isNumeric(input.columnDisplayType)) { + data[input.columnName] = datatableDataValues[controlName] * 1; + } else if (this.isDate(input.columnDisplayType)) { + data[input.columnName] = this.dateUtils.formatDate(datatableDataValues[controlName], dateFormat); + existDate = true; + } else { + data[input.columnName] = datatableDataValues[controlName]; + } + }); + + if (existDate) { + data['dateFormat'] = dateFormat; + } + + const payload = { + registeredTableName: this.datatableData.registeredTableName, + data: data + }; + return payload; + } + +} diff --git a/src/app/clients/client-stepper/client-general-step/client-general-step.component.ts b/src/app/clients/client-stepper/client-general-step/client-general-step.component.ts index 845963a61..59925fd45 100644 --- a/src/app/clients/client-stepper/client-general-step/client-general-step.component.ts +++ b/src/app/clients/client-stepper/client-general-step/client-general-step.component.ts @@ -81,7 +81,7 @@ export class ClientGeneralStepComponent implements OnInit { 'dateOfBirth': [''], 'clientTypeId': [''], 'clientClassificationId': [''], - 'submittedOnDate': [''] + 'submittedOnDate': [this.settingsService.businessDate, Validators.required] }); } diff --git a/src/app/clients/clients-view/datatable-tab/single-row/single-row.component.html b/src/app/clients/clients-view/datatable-tab/single-row/single-row.component.html index 006478747..cf3956b9d 100644 --- a/src/app/clients/clients-view/datatable-tab/single-row/single-row.component.html +++ b/src/app/clients/clients-view/datatable-tab/single-row/single-row.component.html @@ -11,9 +11,29 @@   Delete All - - - {{columnHeader.columnName}} : {{dataObject.data[0].row[i]}} - - - \ No newline at end of file + + +
+ +
+ {{columnHeader.columnName}} +
+ +
+ + {{dataObject.data[0].row[i] | dateFormat}} + + + {{dataObject.data[0].row[i] | datetimeFormat}} + + + {{dataObject.data[0].row[i] | number}} + + + {{dataObject.data[0].row[i]}} + +
+
+
+ + diff --git a/src/app/clients/clients-view/datatable-tab/single-row/single-row.component.scss b/src/app/clients/clients-view/datatable-tab/single-row/single-row.component.scss index ce3593d7b..78ed25b89 100644 --- a/src/app/clients/clients-view/datatable-tab/single-row/single-row.component.scss +++ b/src/app/clients/clients-view/datatable-tab/single-row/single-row.component.scss @@ -6,3 +6,8 @@ margin-left: 1%; } } + +.table-data { + margin-top: 20px; + align-items: center; +} diff --git a/src/app/clients/clients.module.ts b/src/app/clients/clients.module.ts index 124a6c701..13d24c865 100644 --- a/src/app/clients/clients.module.ts +++ b/src/app/clients/clients.module.ts @@ -58,6 +58,7 @@ import { ClientFamilyMemberDialogComponent } from './client-stepper/client-famil import { CaptureImageDialogComponent } from './clients-view/custom-dialogs/capture-image-dialog/capture-image-dialog.component'; import { CreateSelfServiceUserComponent } from './clients-view/client-actions/create-self-service-user/create-self-service-user.component'; import { AddClientCollateralComponent } from './clients-view/client-actions/add-client-collateral/add-client-collateral.component'; +import { ClientDatatableStepComponent } from './client-stepper/client-datatable-step/client-datatable-step.component'; /** @@ -122,7 +123,8 @@ import { AddClientCollateralComponent } from './clients-view/client-actions/add- ClientFamilyMemberDialogComponent, CaptureImageDialogComponent, CreateSelfServiceUserComponent, - AddClientCollateralComponent + AddClientCollateralComponent, + ClientDatatableStepComponent ], providers: [ ] diff --git a/src/app/clients/create-client/create-client.component.html b/src/app/clients/create-client/create-client.component.html index cf5d38992..6db15d6ac 100644 --- a/src/app/clients/create-client/create-client.component.html +++ b/src/app/clients/create-client/create-client.component.html @@ -50,7 +50,15 @@ - + + + {{datatable.registeredTableName}} + + + + + + PREVIEW diff --git a/src/app/clients/create-client/create-client.component.ts b/src/app/clients/create-client/create-client.component.ts index bf4b3e039..2e0e1afeb 100644 --- a/src/app/clients/create-client/create-client.component.ts +++ b/src/app/clients/create-client/create-client.component.ts @@ -1,5 +1,5 @@ /** Angular Imports */ -import { Component, ViewChild } from '@angular/core'; +import { Component, QueryList, ViewChild, ViewChildren } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; /** Custom Services */ @@ -9,11 +9,11 @@ import { ClientsService } from '../clients.service'; import { ClientGeneralStepComponent } from '../client-stepper/client-general-step/client-general-step.component'; import { ClientFamilyMembersStepComponent } from '../client-stepper/client-family-members-step/client-family-members-step.component'; import { ClientAddressStepComponent } from '../client-stepper/client-address-step/client-address-step.component'; +import { ClientDatatableStepComponent } from '../client-stepper/client-datatable-step/client-datatable-step.component'; /** Custom Services */ import { SettingsService } from 'app/settings/settings.service'; - /** * Create Client Component. */ @@ -30,6 +30,8 @@ export class CreateClientComponent { @ViewChild(ClientFamilyMembersStepComponent, { static: true }) clientFamilyMembersStep: ClientFamilyMembersStepComponent; /** Client Address Step */ @ViewChild(ClientAddressStepComponent, { static: true }) clientAddressStep: ClientAddressStepComponent; + /** Get handle on dtclient tags in the template */ + @ViewChildren('dtclient') clientDatatables: QueryList; /** Client Template */ clientTemplate: any; @@ -77,6 +79,21 @@ export class CreateClientComponent { }; } } + + areFormvalids(): boolean { + let areValids = this.clientGeneralForm.valid; + if (this.clientTemplate.isAddressEnabled) { + areValids = areValids && (this.clientAddressStep.address.address.length > 0); + } + if (this.clientTemplate.datatables && this.clientTemplate.datatables.length > 0 && this.clientDatatables) { + this.clientDatatables.forEach((clientDatatable: ClientDatatableStepComponent) => { + areValids = areValids && clientDatatable.datatableForm.valid; + }); + } + + return areValids; + } + /** * Submits the create client form. */ @@ -89,6 +106,15 @@ export class CreateClientComponent { dateFormat, locale }; + + if (this.clientTemplate.datatables && this.clientTemplate.datatables.length > 0) { + const datatables: any[] = []; + this.clientDatatables.forEach((clientDatatable: ClientDatatableStepComponent) => { + datatables.push(clientDatatable.payload); + }); + clientData['datatables'] = datatables; + } + this.clientsService.createClient(clientData).subscribe((response: any) => { this.router.navigate(['../', response.resourceId], { relativeTo: this.route }); });