diff --git a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/client-info/client-info.component.html b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/client-info/client-info.component.html index 0c0a40381..2582904d1 100644 --- a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/client-info/client-info.component.html +++ b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/client-info/client-info.component.html @@ -1,3 +1,81 @@ -

- client-info works! -

+ + +
+
+
+
+
+
+
+ + + + +
+
+ + + + +
+
+ + + + +
+
+
+
+ + + {{ pm.name }} + + +
+
+ + + + +
+
+ + + + +
+
+
+
+ + + {{ feq.name }} + + +
+
+ + + + +
+ +
+ + + +
+
+
+
+ +
+
+
+ + +
+
+
\ No newline at end of file diff --git a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/client-info/client-info.component.ts b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/client-info/client-info.component.ts index 80ae7153a..5e373360f 100644 --- a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/client-info/client-info.component.ts +++ b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/client-info/client-info.component.ts @@ -1,5 +1,27 @@ -import { Component, OnInit } from '@angular/core'; +/** Common Imports */ +import { + Component, + OnInit, + Inject, + Input +} from '@angular/core'; +import { + FormBuilder, + FormGroup, + Validators, + FormArray, +} from '@angular/forms'; + +import { NotifierService } from 'angular-notifier'; + +import { + MatDialog, + MatDialogRef, + MAT_DIALOG_DATA +} from '@angular/material'; +/** Service */ +import { PdTrigerService } from '../../../../../pd-service/pd-triger.service'; @Component({ selector: 'app-client-info', templateUrl: './client-info.component.html', @@ -7,9 +29,233 @@ import { Component, OnInit } from '@angular/core'; }) export class ClientInfoComponent implements OnInit { - constructor() { } + @Input() pdid: number; + + public _supplierQuesFrom: FormGroup; + public submitted = false; + public m_paymentModeType= [ + { + 'id': "1", + 'name': 'Immediate Or Advanced Payment' + }, + { + 'id': "2", + 'name': 'Credit' + }, + { + 'id': "3", + 'name': 'Combination of Both' + }, + ]; + + public m_freqOfPurchase= [ + { + 'id': "1", + 'name': 'Daily' + }, + { + 'id': "2", + 'name': 'Weekly' + }, + { + 'id': "3", + 'name': 'Monthly' + }, + { + 'id': "4", + 'name': 'Every 3 months' + }, + { + 'id': "5", + 'name': 'Half yearly' + }, + { + 'id': "6", + 'name': 'Yearly' + }, + { + 'id': "7", + 'name': 'As and when required' + }, + { + 'id': "8", + 'name': 'Others' + } + ] + + constructor( + private _formBuilder: FormBuilder, + private pdTrigerService: PdTrigerService) { } ngOnInit() { + + this.getPdSupplierFormDetails(); + } +apiLoadFinish: boolean = false; + getPdSupplierFormDetails() { + this.pdTrigerService.getPDFormDetailsWithID(this.pdid, '1').subscribe( + data => { + if (data) { + if(data.dataStatus){ + this.formLoadData(data.records) + } else { + this.formLoadData(null) + } + this.apiLoadFinish = true; + } else { + // this.noRecordFound = true; + } + } + ); } + formLoadData(val) { + if(val !== null) { + let value = val; + this._supplierQuesFrom = this._formBuilder.group({ + pdid: [this.pdid], + formid: ['1'], + main_raw_materials: [value.main_raw_materials, Validators.compose([Validators.required])], + supplier_details: this._formBuilder.array([ + // this.initDetails(), + ]) + }); + this.addSupplierDetailsWithData(value.supplier_details); + } else { + this._supplierQuesFrom = this._formBuilder.group({ + pdid: [this.pdid], + formid: ['1'], + main_raw_materials: [null, Validators.compose([Validators.required])], + supplier_details: this._formBuilder.array([ + this.initDetails(), + ]) + }); + } + } + + // convenience getter for easy access to form fields + get f() { return this._supplierQuesFrom.controls; } + + // Dynamic Form field creation Functionality : START ===> + initDetails() { + return this._formBuilder.group({ + supplier_name: ['', Validators.compose([Validators.required])], + contact_person: ['', Validators.compose([Validators.required])], + mobile_number: ['', Validators.compose([Validators.required])], + payment_mode: ['', Validators.compose([Validators.required])], + per_of_immediate_advance_payment:[''], + credit_period:[''], + frequency_of_purchase: ['', Validators.compose([Validators.required])], + freq_purchase_others_text_value: [''] + }); + } + + initDetailsWithdata(data) { + return this._formBuilder.group({ + supplier_name: [data.supplier_name, Validators.compose([Validators.required])], + contact_person: [data.contact_person, Validators.compose([Validators.required])], + mobile_number: [data.mobile_number, Validators.compose([Validators.required])], + payment_mode: [data.payment_mode, Validators.compose([Validators.required])], + per_of_immediate_advance_payment:[data.per_of_immediate_advance_payment || ''], + credit_period:[data.credit_period || ''], + frequency_of_purchase: [data.frequency_of_purchase, Validators.compose([Validators.required])], + freq_purchase_others_text_value: [data.freq_purchase_others_text_value || ''] + }); + } + + addSupplierDetailsWithData(supp_data) { + +var result = Object.keys(supp_data).map(function(key) { + return supp_data[key]; +}); + if (result.length > 0) { + for (let val of result) { + let vals = { + supplier_name: val.supplier_name, + contact_person: val.contact_person, + mobile_number: val.mobile_number, + payment_mode: val.payment_mode, + per_of_immediate_advance_payment: val.per_of_immediate_advance_payment, + credit_period: val.credit_period, + frequency_of_purchase: val.frequency_of_purchase, + freq_purchase_others_text_value: val.freq_purchase_others_text_value + }; + const control = this._supplierQuesFrom.controls['supplier_details']; + control.push(this.initDetailsWithdata(vals)); + } + } + } + + addSupplierDetails(e) { + const control = this._supplierQuesFrom.controls['supplier_details']; + control.push(this.initDetails()); + } + removeLanguage(i: number) { + const control = this._supplierQuesFrom.controls['supplier_details']; + control.removeAt(i); + } + + public paymentModeTextBox: number; + selectedPM(e) { + this.paymentModeTextBox = e.value; + // this.f.supplier_details.controls.get('payment_mode_value'); + } + + public freqPurchaseTextBox: number; + selectedFreqPurchase(e){ + this.freqPurchaseTextBox = e.value; + } + + + /** To Save/Edited Popup Data */ + onSubmit() { + this.submitted = true; + // stop here if form is invalid + if (this._supplierQuesFrom.invalid) { + return; + } else { + var answerFormValues = this._supplierQuesFrom.value; + + //To Remove The "Null" With Key also + Object.keys(answerFormValues).forEach((key) => (answerFormValues[key] == null) && delete answerFormValues[key]); + alert(JSON.stringify(answerFormValues)); + //Add BRANCH data with help Service File + this.pdTrigerService.savePDFormDetailsWithID(answerFormValues).subscribe( + dataresult => { + if (dataresult.status == 200) { + // console.log(dataresult); + // this.notifier.notify('success', 'Record Saved Successfully.!'); + // this.dialogRef.close(); + // alert("sample alert for Saving"); + } + else { + // this.notifier.notify('warning', 'Something Wents Wrong Try Again.!'); + // this.errorMessage = "Some Thing Wents Wrong Try Again !"; + } + }, error => { + // this.notifier.notify('warning', 'Something Wents Wrong Try Again.!'); + // this.errorMessage = "Something Wents Wrong Try Again !"; + // this.dialogRef.close(); + }); + //After Saving the BRANCH data then popup close + // this.dialogRef.close(); + } + } + + /** To Reset Popup Data */ + onReset() { + // this._addQuesFrom.reset(); + } + + // { + // 'main_raw_materials': 'sdkjfal', + // 'supplier_details' ; [ + // { + // 'supplier_name':'ldskjfalks', + // 'payment_mode': '1', + // 'payment_mode_value':'' + // } + // ] + // } + } diff --git a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/supplier-info/supplier-info.component.html b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/supplier-info/supplier-info.component.html index 952ecbda0..152e6d3a5 100644 --- a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/supplier-info/supplier-info.component.html +++ b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/supplier-info/supplier-info.component.html @@ -1,6 +1,6 @@ -
+
diff --git a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/supplier-info/supplier-info.component.ts b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/supplier-info/supplier-info.component.ts index 9f52ed182..3a2f64e99 100644 --- a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/supplier-info/supplier-info.component.ts +++ b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/supplier-info/supplier-info.component.ts @@ -35,50 +35,50 @@ export class SupplierInfoComponent implements OnInit { public submitted = false; public m_paymentModeType= [ { - 'id': 1, + 'id': "1", 'name': 'Immediate Or Advanced Payment' }, { - 'id': 2, + 'id': "2", 'name': 'Credit' }, { - 'id': 3, + 'id': "3", 'name': 'Combination of Both' }, ]; public m_freqOfPurchase= [ { - 'id': 1, + 'id': "1", 'name': 'Daily' }, { - 'id': 2, + 'id': "2", 'name': 'Weekly' }, { - 'id': 3, + 'id': "3", 'name': 'Monthly' }, { - 'id': 4, + 'id': "4", 'name': 'Every 3 months' }, { - 'id': 5, + 'id': "5", 'name': 'Half yearly' }, { - 'id': 6, + 'id': "6", 'name': 'Yearly' }, { - 'id': 7, + 'id': "7", 'name': 'As and when required' }, { - 'id': 8, + 'id': "8", 'name': 'Others' } ] @@ -88,25 +88,20 @@ export class SupplierInfoComponent implements OnInit { private pdTrigerService: PdTrigerService) { } ngOnInit() { - this._supplierQuesFrom = this._formBuilder.group({ - main_raw_materials: [null, Validators.compose([Validators.required])], - supplier_details: this._formBuilder.array([ - this.initDetails(), - ]) - }); + this.getPdSupplierFormDetails(); } - +apiLoadFinish: boolean = false; getPdSupplierFormDetails() { this.pdTrigerService.getPDFormDetailsWithID(this.pdid, '1').subscribe( data => { if (data) { - if (data.records) { - // this.noRecordFound = false; - // this.entityBillingInfoRecord = data.records; - } else { - // this.noRecordFound = true; - } + if(data.dataStatus){ + this.formLoadData(data.records) + } else { + this.formLoadData(null) + } + this.apiLoadFinish = true; } else { // this.noRecordFound = true; } @@ -114,6 +109,30 @@ export class SupplierInfoComponent implements OnInit { ); } + formLoadData(val) { + if(val !== null) { + let value = val; + this._supplierQuesFrom = this._formBuilder.group({ + pdid: [this.pdid], + formid: ['1'], + main_raw_materials: [value.main_raw_materials, Validators.compose([Validators.required])], + supplier_details: this._formBuilder.array([ + // this.initDetails(), + ]) + }); + this.addSupplierDetailsWithData(value.supplier_details); + } else { + this._supplierQuesFrom = this._formBuilder.group({ + pdid: [this.pdid], + formid: ['1'], + main_raw_materials: [null, Validators.compose([Validators.required])], + supplier_details: this._formBuilder.array([ + this.initDetails(), + ]) + }); + } + } + // convenience getter for easy access to form fields get f() { return this._supplierQuesFrom.controls; } @@ -131,6 +150,42 @@ export class SupplierInfoComponent implements OnInit { }); } + initDetailsWithdata(data) { + return this._formBuilder.group({ + supplier_name: [data.supplier_name, Validators.compose([Validators.required])], + contact_person: [data.contact_person, Validators.compose([Validators.required])], + mobile_number: [data.mobile_number, Validators.compose([Validators.required])], + payment_mode: [data.payment_mode, Validators.compose([Validators.required])], + per_of_immediate_advance_payment:[data.per_of_immediate_advance_payment || ''], + credit_period:[data.credit_period || ''], + frequency_of_purchase: [data.frequency_of_purchase, Validators.compose([Validators.required])], + freq_purchase_others_text_value: [data.freq_purchase_others_text_value || ''] + }); + } + + addSupplierDetailsWithData(supp_data) { + +var result = Object.keys(supp_data).map(function(key) { + return supp_data[key]; +}); + if (result.length > 0) { + for (let val of result) { + let vals = { + supplier_name: val.supplier_name, + contact_person: val.contact_person, + mobile_number: val.mobile_number, + payment_mode: val.payment_mode, + per_of_immediate_advance_payment: val.per_of_immediate_advance_payment, + credit_period: val.credit_period, + frequency_of_purchase: val.frequency_of_purchase, + freq_purchase_others_text_value: val.freq_purchase_others_text_value + }; + const control = this._supplierQuesFrom.controls['supplier_details']; + control.push(this.initDetailsWithdata(vals)); + } + } + } + addSupplierDetails(e) { const control = this._supplierQuesFrom.controls['supplier_details']; control.push(this.initDetails()); @@ -164,26 +219,26 @@ export class SupplierInfoComponent implements OnInit { //To Remove The "Null" With Key also Object.keys(answerFormValues).forEach((key) => (answerFormValues[key] == null) && delete answerFormValues[key]); alert(JSON.stringify(answerFormValues)); - // //Add BRANCH data with help Service File - // this.questionsService.addQuestionMasterDetails(answerFormValues).subscribe( - // dataresult => { - // if (dataresult.status == 200) { - // console.log(dataresult); - // this.notifier.notify('success', 'Record Saved Successfully.!'); - // this.dialogRef.close(); - // // alert("sample alert for Saving"); - // } - // else { - // this.notifier.notify('warning', 'Something Wents Wrong Try Again.!'); - // this.errorMessage = "Some Thing Wents Wrong Try Again !"; - // } - // }, error => { - // this.notifier.notify('warning', 'Something Wents Wrong Try Again.!'); - // this.errorMessage = "Something Wents Wrong Try Again !"; - // this.dialogRef.close(); - // }); - // //After Saving the BRANCH data then popup close - // // this.dialogRef.close(); + //Add BRANCH data with help Service File + this.pdTrigerService.savePDFormDetailsWithID(answerFormValues).subscribe( + dataresult => { + if (dataresult.status == 200) { + // console.log(dataresult); + // this.notifier.notify('success', 'Record Saved Successfully.!'); + // this.dialogRef.close(); + // alert("sample alert for Saving"); + } + else { + // this.notifier.notify('warning', 'Something Wents Wrong Try Again.!'); + // this.errorMessage = "Some Thing Wents Wrong Try Again !"; + } + }, error => { + // this.notifier.notify('warning', 'Something Wents Wrong Try Again.!'); + // this.errorMessage = "Something Wents Wrong Try Again !"; + // this.dialogRef.close(); + }); + //After Saving the BRANCH data then popup close + // this.dialogRef.close(); } } diff --git a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/start-pd.component.html b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/start-pd.component.html index 7a6677638..bc826bf96 100644 --- a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/start-pd.component.html +++ b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/start-pd.component.html @@ -383,7 +383,7 @@ -

client

+
diff --git a/ng6-seed/src/app/personal-discussion/pd-service/pd-triger.service.ts b/ng6-seed/src/app/personal-discussion/pd-service/pd-triger.service.ts index 213e638bd..06398801e 100644 --- a/ng6-seed/src/app/personal-discussion/pd-service/pd-triger.service.ts +++ b/ng6-seed/src/app/personal-discussion/pd-service/pd-triger.service.ts @@ -191,7 +191,7 @@ export class PdTrigerService { // common Pd form details get for the Pd Process getPDFormDetailsWithID(pdID, formID ):Observable { - return this._http.post(this.apiUrl+"getPDFormDetails",{"pdid":pdID,"pd_form_id" : formID}) + return this._http.post(this.apiUrl+"getPDFormDetails",{"pd_id":pdID,"pd_form_id" : formID}) .pipe( catchError(this.handleError('operation', [])) ) @@ -200,7 +200,6 @@ getPDFormDetailsWithID(pdID, formID ):Observable { // save Pd form details savePDFormDetailsWithID(saveData: any): Observable { saveData.fk_createdby = this._aws.getlocale(); - saveData.fk_createdon = currentdate; // saveData[0].fk_updatedby = this._aws.getlocale(); // saveData[0].updatedon = currentdate;