supplier changes details : kdk

This commit is contained in:
dineshkumarkannan 2018-11-05 17:54:44 +05:30
parent 215de92b41
commit 1db3a58fa8
6 changed files with 431 additions and 53 deletions

View File

@ -1,3 +1,81 @@
<p>
client-info works!
</p>
<!--<pre> {{ m_group | json}}</pre>-->
<mat-card style="padding: 12px;">
<form *ngIf="apiLoadFinish" [formGroup]="_supplierQuesFrom" (submit)="onSubmit()" novalidate>
<div fxLayout="row" fxLayoutAlign="start none">
<div formArrayName="supplier_details" fxFill>
<div *ngFor="let sup of _supplierQuesFrom.controls.supplier_details['controls']; let i=index">
<div [formGroupName]="i">
<div fxLayout="row wrap" fxLayoutGap="12px" fxLayoutAlign="start none">
<div>
<mat-form-field class="ml-xs example-full-width">
<input matInput placeholder="Supplier Name" formControlName="supplier_name">
<!--<mat-error *ngIf="submitted && f.supplier_name.hasError('required')" class="mat-text-warn">You must Include Supplier Name.</mat-error>-->
</mat-form-field>
</div>
<div>
<mat-form-field class="ml-xs example-full-width">
<input matInput placeholder="Contact Person Name" formControlName="contact_person">
<!--<mat-error *ngIf="submitted && f.supplier_name.hasError('required')" class="mat-text-warn">You must Include Supplier Name.</mat-error>-->
</mat-form-field>
</div>
<div>
<mat-form-field class="ml-xs example-full-width">
<input matInput placeholder="Contact Mobile Number" formControlName="mobile_number">
<!--<mat-error *ngIf="submitted && f.supplier_name.hasError('required')" class="mat-text-warn">You must Include Supplier Name.</mat-error>-->
</mat-form-field>
</div>
</div>
<div fxLayout="row wrap" fxLayoutGap="12px" fxLayoutAlign="start none">
<div>
<mat-form-field>
<mat-select (selectionChange)="selectedPM($event)" placeholder="Select Payment Mode" formControlName="payment_mode">
<mat-option *ngFor="let pm of m_paymentModeType" [value]="pm.id">{{ pm.name }}</mat-option>
</mat-select>
</mat-form-field>
</div>
<div *ngIf="sup.get('payment_mode').value == 1 || sup.get('payment_mode').value == 3">
<mat-form-field class="ml-xs example-full-width">
<input matInput placeholder="% of immediate / Advance Payment Purchase to Total Purchase?" formControlName="per_of_immediate_advance_payment">
<!--<mat-error *ngIf="submitted && f.supplier_name.hasError('required')" class="mat-text-warn">You must Include Supplier Name.</mat-error>-->
</mat-form-field>
</div>
<div *ngIf="sup.get('payment_mode').value == 2 || sup.get('payment_mode').value == 3">
<mat-form-field class="ml-xs example-full-width">
<input matInput placeholder="Credit Period" formControlName="credit_period">
<!--<mat-error *ngIf="submitted && f.supplier_name.hasError('required')" class="mat-text-warn">You must Include Supplier Name.</mat-error>-->
</mat-form-field>
</div>
</div>
<div fxLayout="row" fxLayoutGap="12px" fxLayoutAlign="start none">
<div>
<mat-form-field>
<mat-select (selectionChange)="selectedFreqPurchase($event)" placeholder="Select Frequency of Purchase" formControlName="frequency_of_purchase">
<mat-option *ngFor="let feq of m_freqOfPurchase" [value]="feq.id">{{ feq.name }}</mat-option>
</mat-select>
</mat-form-field>
</div>
<div *ngIf="sup.get('frequency_of_purchase').value == 8">
<mat-form-field class="ml-xs example-full-width">
<input matInput placeholder="Others Details" formControlName="freq_purchase_others_text_value">
<!--<mat-error *ngIf="submitted && f.supplier_name.hasError('required')" class="mat-text-warn">You must Include Supplier Name.</mat-error>-->
</mat-form-field>
</div>
<div fxFlex="20">
<span *ngIf="_supplierQuesFrom.controls.supplier_details.controls.length > 1" (click)="removeLanguage(i)">
<button mat-button mat-icon-button class="mr-1 mb-1 hover-icon" matTooltip="Delete" matTooltipPosition="above"><mat-icon>delete</mat-icon></button>
</span>
</div>
</div>
</div>
</div>
<button mat-raised-button mat-icon-button mat-button color="primary" matTooltip="Add More Answer" matTooltipPosition="above"
class="mr-1 mb-1 hover-icon" (click)="addSupplierDetails($event); false"><mat-icon>add</mat-icon></button>
</div>
</div>
<div class="row" style="text-align:right;">
<button mat-raised-button mat-icon-button class="mr-1 mb-1 hover-icon" matTooltip="Reset" matTooltipPosition="above" type="reset"><mat-icon>settings_backup_restore</mat-icon></button>
<button mat-raised-button mat-icon-button class="mr-1 mb-1 hover-icon" matTooltip="Save" matTooltipPosition="above" type="submit"><mat-icon>save</mat-icon></button>
</div>
</form>
</mat-card>

View File

@ -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 = <FormArray>this._supplierQuesFrom.controls['supplier_details'];
control.push(this.initDetailsWithdata(vals));
}
}
}
addSupplierDetails(e) {
const control = <FormArray>this._supplierQuesFrom.controls['supplier_details'];
control.push(this.initDetails());
}
removeLanguage(i: number) {
const control = <FormArray>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':''
// }
// ]
// }
}

View File

@ -1,6 +1,6 @@
<!--<pre> {{ m_group | json}}</pre>-->
<mat-card style="padding: 12px;">
<form [formGroup]="_supplierQuesFrom" (submit)="onSubmit()" novalidate>
<form *ngIf="apiLoadFinish" [formGroup]="_supplierQuesFrom" (submit)="onSubmit()" novalidate>
<div fxLayout="row" fxLayoutAlign="start none">
<div class="example-full-width">
<mat-form-field fxFill>

View File

@ -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;
if(data.dataStatus){
this.formLoadData(data.records)
} else {
// this.noRecordFound = true;
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 = <FormArray>this._supplierQuesFrom.controls['supplier_details'];
control.push(this.initDetailsWithdata(vals));
}
}
}
addSupplierDetails(e) {
const control = <FormArray>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) {
//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 {
// alert("sample alert for Saving");
}
else {
// this.notifier.notify('warning', 'Something Wents Wrong Try Again.!');
// this.errorMessage = "Some Thing Wents Wrong Try Again !";
// }
// }, error => {
}
}, 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();
});
//After Saving the BRANCH data then popup close
// this.dialogRef.close();
}
}

View File

@ -383,7 +383,7 @@
<!-- start client type questions -->
<ng-container *ngSwitchCase="2">
<p>client</p>
<app-client-info [pdid]="startPD"></app-client-info>
</ng-container>
<!-- end client type questions -->

View File

@ -191,7 +191,7 @@ export class PdTrigerService {
// common Pd form details get for the Pd Process
getPDFormDetailsWithID(pdID, formID ):Observable<any> {
return this._http.post<any>(this.apiUrl+"getPDFormDetails",{"pdid":pdID,"pd_form_id" : formID})
return this._http.post<any>(this.apiUrl+"getPDFormDetails",{"pd_id":pdID,"pd_form_id" : formID})
.pipe(
catchError(this.handleError('operation', []))
)
@ -200,7 +200,6 @@ getPDFormDetailsWithID(pdID, formID ):Observable<any> {
// save Pd form details
savePDFormDetailsWithID(saveData: any): Observable<any> {
saveData.fk_createdby = this._aws.getlocale();
saveData.fk_createdon = currentdate;
// saveData[0].fk_updatedby = this._aws.getlocale();
// saveData[0].updatedon = currentdate;