538 lines
17 KiB
TypeScript
538 lines
17 KiB
TypeScript
import { Component,
|
|
OnInit,
|
|
Inject } from '@angular/core';
|
|
import { FormBuilder,
|
|
FormGroup,
|
|
Validators,
|
|
FormControl } from '@angular/forms';
|
|
import { MatDialog,
|
|
MatDialogRef,
|
|
MAT_DIALOG_DATA } from '@angular/material';
|
|
/** Service */
|
|
import { MastersService } from '../../service/masters/masters.service';
|
|
import { PdTeamService } from '../../service/masters/pd-team.service';
|
|
import { NotifierService } from 'angular-notifier';
|
|
|
|
@Component({
|
|
selector: 'app-pd-team-dialog',
|
|
templateUrl: './pd-team-dialog.component.html',
|
|
styleUrls: ['./pd-team-dialog.component.scss']
|
|
})
|
|
|
|
|
|
export class PdTeamDialogComponent implements OnInit {
|
|
|
|
public _pdTeamForm: FormGroup;
|
|
private notifier: NotifierService;
|
|
color = 'primary';
|
|
citydatas: any[];
|
|
lenderdatas: any[];
|
|
errorMessage:string;
|
|
selectedValueForLender: any;
|
|
selectedValueForCity: any;
|
|
tempArray: Array<{lenderid: number, cityid: number}> = [];
|
|
PDTeamMapping: any[];
|
|
AllPDTeamMapData: any[];
|
|
PDTeamMaplen:any = 0;
|
|
|
|
|
|
constructor(private _formBuilder: FormBuilder,notifier: NotifierService,
|
|
private dialogRef: MatDialogRef<PdTeamDialogComponent>,
|
|
private _pdTeamService: PdTeamService,
|
|
private _masterService: MastersService,
|
|
@Inject(MAT_DIALOG_DATA) public data: any) {
|
|
this.notifier = notifier;
|
|
}
|
|
|
|
|
|
ngOnInit() {
|
|
this.PdTeamFormDatas();
|
|
if(isNaN(this.data.pdteam_id)){}
|
|
else{
|
|
this._pdTeamService.getAllPdTeamMapListWithPK(this.data.pdteam_id) // note, removed this.countries =
|
|
.subscribe(
|
|
dataresult => {
|
|
if(dataresult.dataStatus == true){
|
|
this.PDTeamMapping = dataresult.records;
|
|
this.PDTeamMaplen = this.PDTeamMapping.length;
|
|
}
|
|
});
|
|
}
|
|
this._pdTeamService.getAllPdTeamMapList() // note, removed this.countries =
|
|
.subscribe(
|
|
dataresult => {
|
|
if(dataresult.dataStatus == true){
|
|
this.AllPDTeamMapData = dataresult.records;
|
|
}
|
|
});
|
|
|
|
/** For City Drop Datas*/
|
|
this._masterService.getAllMasterData('CITY')
|
|
.subscribe(
|
|
dataresult => {
|
|
if (dataresult.status == 200) {
|
|
this.citydatas = dataresult.records;
|
|
this.citydatas = this.citydatas.filter(city=>city.isactive == 1 );
|
|
}
|
|
|
|
}, error => this.errorMessage = <any> error);
|
|
|
|
/** For Entity Drop Datas*/
|
|
this._masterService.getAllMasterData('ENTITY')
|
|
.subscribe(
|
|
dataresult => {
|
|
if (dataresult.status == 200) {
|
|
this.lenderdatas = dataresult.records;
|
|
this.lenderdatas = this.lenderdatas.filter(entity=>entity.isactive == 1 );
|
|
}
|
|
|
|
}, error => this.errorMessage = <any> error);
|
|
|
|
}
|
|
|
|
/** Pd Team Form Datas */
|
|
PdTeamFormDatas(){
|
|
this._pdTeamForm = this._formBuilder.group({
|
|
|
|
pdteam_id: [this.data.pdteam_id],
|
|
team_name: [this.data.team_name, Validators.compose([Validators.required])],
|
|
fk_city_id: [null, Validators.compose([Validators.required])],
|
|
fk_lender_id: [null, Validators.compose([Validators.required])],
|
|
temp_array: [this.tempArray]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// isactivePDTeamChild(PD.pdteam_map_id,PD.isactive)
|
|
isactivePDTeamChild(id: number,isactive : number) {
|
|
|
|
let ActiveDatas = isactive == 0
|
|
? { 'pdteam_map_id':id,'isactive': '1'}
|
|
: { 'pdteam_map_id':id,'isactive': '0'}
|
|
|
|
//private _masterService: MastersService,
|
|
this._masterService.editMasterDetails(ActiveDatas,'PDTEAMMAP')
|
|
.subscribe(dataresult=>{
|
|
if (dataresult.dataStatus == true){
|
|
//alert("Successfully InActive !");
|
|
this.notifier.notify('success', 'Record Successfully InActive.!');
|
|
}
|
|
else{
|
|
|
|
//alert("SomeThing Wents Wrong Try Again !");
|
|
this.notifier.notify('warning', 'Sorry Try Again !');
|
|
}
|
|
});
|
|
}
|
|
|
|
// deletePdTeamMap(arr: any) {
|
|
// //console.log(arr);
|
|
// //var PrimaryKeyWithValue ={'pdteam_map_id':arr.id};
|
|
// //fk_team_id
|
|
// this._pdTeamService.updatePdTeam(arr)
|
|
// .subscribe( data => { });
|
|
// this._pdTeamService.deletePdTeamMap(arr)
|
|
// .subscribe( data => { });
|
|
// //this.getPdTeam();
|
|
// }
|
|
|
|
deletePdTeamMap(PdTeamMaparr,i) {
|
|
let datas :any = [];
|
|
this._pdTeamService.deletePdTeamMapDetails(PdTeamMaparr)
|
|
.subscribe(data => {
|
|
datas = data;
|
|
if(datas.dataStatus == true){
|
|
this.PDTeamMapping.splice(i, 1);
|
|
//alert('Deleted Successfully');
|
|
|
|
}
|
|
|
|
});
|
|
}
|
|
|
|
|
|
removevalue(i:number) {
|
|
//const index: number = this.tempArray.indexOf(i);
|
|
if (i !== -1) {
|
|
this.tempArray.splice(i, 1);
|
|
}
|
|
//console.log('delete function',this.tempArray);
|
|
|
|
}
|
|
|
|
doSomething(){
|
|
var check = 0 ;
|
|
// console.log(this._pdTeamForm.controls['fk_city_id'].value.city_id);
|
|
// console.log(this._pdTeamForm.controls['fk_lender_id'].value.entity_id);
|
|
if((this._pdTeamForm.controls['fk_city_id'].value.city_id != '')
|
|
&&(this._pdTeamForm.controls['fk_lender_id'].value.entity_id != ''))
|
|
{
|
|
|
|
this.tempArray.forEach(item => {
|
|
if((item.cityid['city_id'] == this._pdTeamForm.controls['fk_city_id'].value.city_id) &&
|
|
(item.lenderid['entity_id'] == this._pdTeamForm.controls['fk_lender_id'].value.entity_id))
|
|
{
|
|
check++;
|
|
//alert('');
|
|
this.notifier.notify('info', 'Already Exists.!');
|
|
}
|
|
});
|
|
|
|
if(this.AllPDTeamMapData !== undefined){
|
|
|
|
this.AllPDTeamMapData.forEach(item => {
|
|
if(item.fk_team_id != this._pdTeamForm.controls['pdteam_id'].value){
|
|
if((item.fk_city_id == this._pdTeamForm.controls['fk_city_id'].value.city_id) &&
|
|
(item.fk_lender_id == this._pdTeamForm.controls['fk_lender_id'].value.entity_id))
|
|
{
|
|
check++;
|
|
//this.notifier.notify('success', 'Already Exists.!');
|
|
//alert('Already Exists on Other Team "'+item.team_name+'"');
|
|
this.notifier.notify( 'info', 'Already Exists on Other Team'+item.team_name );
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
if(isNaN(this.data.pdteam_id)) {}
|
|
else{
|
|
// console.log(this.PDTeamMapping.length);
|
|
if(this.PDTeamMapping !== undefined){
|
|
this.PDTeamMapping.forEach(item => {
|
|
if((item.fk_city_id == this._pdTeamForm.controls['fk_city_id'].value.city_id) &&
|
|
(item.fk_lender_id == this._pdTeamForm.controls['fk_lender_id'].value.entity_id))
|
|
{
|
|
check++;
|
|
//alert('Already Exists');
|
|
this.notifier.notify( 'info', 'Already Exists');
|
|
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
// this.tempArray.forEach(this.data, function (value, key) {
|
|
|
|
// if((value.cityid.city_id == this._pdTeamForm.controls['fk_city_id'].value.city_id) &&
|
|
// (value.lenderid.entity_id == this._pdTeamForm.controls['fk_lender_id'].value.entity_id))
|
|
// {
|
|
// check++;
|
|
// console.log('for loop');
|
|
// }
|
|
// });
|
|
|
|
if(check == 0){
|
|
|
|
if((this._pdTeamForm.controls['fk_lender_id'].value != null) && (this._pdTeamForm.controls['fk_city_id'].value != null)){
|
|
|
|
this.tempArray.push({
|
|
'lenderid':this._pdTeamForm.controls['fk_lender_id'].value,
|
|
'cityid': this._pdTeamForm.controls['fk_city_id'].value
|
|
})
|
|
|
|
}
|
|
//console.log('if condition',check);
|
|
}
|
|
else{
|
|
//console.log('else condition',check);
|
|
}
|
|
// console.log('Temparray',this.tempArray);
|
|
// console.log(this._pdTeamForm.controls['fk_city_id'].value);
|
|
// console.log(this._pdTeamForm.controls['fk_lender_id'].value);
|
|
|
|
|
|
}
|
|
|
|
/** For Popup Close Button */
|
|
onNoClick(): void {
|
|
this.dialogRef.close();
|
|
}
|
|
// OnSumbitForAdd(){
|
|
// this._pdTeamForm.controls['team_name'].value;
|
|
// this._pdTeamService.addPdTeamDetail(pdTeamFormValues).subscribe(
|
|
// dataresult=>{
|
|
// if (dataresult.dataStatus == true){ }
|
|
// })
|
|
// }
|
|
/** To Save/Edited Popup Data */
|
|
onSubmit() {
|
|
|
|
var pdTeamFormValues = this._pdTeamForm.value;
|
|
|
|
if(isNaN(this.data.pdteam_id)) {
|
|
//console.log(pdTeamFormValues);
|
|
//To Remove The "Null" With Key
|
|
Object.keys(pdTeamFormValues).forEach(
|
|
//getAllPdTeam();
|
|
(key) => ( pdTeamFormValues[key] == null) && delete pdTeamFormValues[key] &&
|
|
delete pdTeamFormValues['fk_lender_id'] && delete pdTeamFormValues['fk_city_id']);
|
|
|
|
|
|
//this.lenderdatas = this.lenderdatas.filter(entity=>entity.isactive == 1 );
|
|
//this.lenderdatas = this.lenderdatas.filter(entity=>entity.isactive == 1 );
|
|
//console.log(pdTeamFormValues);
|
|
//this._memberService.addMasterDetails(OccupationFormValues,'OCCUPATIONMEMBERS').subscribe(
|
|
this._pdTeamService.addPdTeamDetail(pdTeamFormValues).subscribe(
|
|
dataresult=>{
|
|
console.log(dataresult);
|
|
if (dataresult.dataStatus == true){
|
|
//After Saving the data then popup close
|
|
this.dialogRef.close();
|
|
//Need To Dispaly saving Datas
|
|
// alert("Data Saved Successfully");
|
|
this.notifier.notify('success', 'Record Saved Successfully.!');
|
|
}
|
|
else{
|
|
//alert("");
|
|
this.notifier.notify('warning', 'SomeThing Wents Wrong Try Again !');
|
|
}
|
|
|
|
});
|
|
} else {
|
|
Object.keys(pdTeamFormValues).forEach(
|
|
(key) => delete pdTeamFormValues['fk_lender_id'] && delete pdTeamFormValues['fk_city_id']);
|
|
|
|
this._pdTeamService.editPdTeamDetail(pdTeamFormValues).subscribe(
|
|
|
|
dataresult=>{
|
|
if (dataresult.dataStatus == true){
|
|
//After Editing the data then popup close
|
|
this.dialogRef.close();
|
|
//Need To Display saving Datas
|
|
//alert("Data Edited Successfully");
|
|
this.notifier.notify('success', 'Record Edited Successfully.!');
|
|
}
|
|
else{
|
|
//alert("SomeThing Wents Wrong Try Again !");
|
|
this.notifier.notify('warning', 'SomeThing Wents Wrong Try Again !');
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
// onSubmit() {
|
|
// if (isNaN(this.data.ID)) {
|
|
// this._memberService.addMembersOccupation(this._occupationForm.value);
|
|
// this.dialogRef.close();
|
|
// } else {
|
|
// this._memberService.editMembersOccupation(this._occupationForm.value);
|
|
// this.dialogRef.close();
|
|
// }
|
|
// }
|
|
|
|
/** To Reset Popup Data For Add*/
|
|
|
|
onResetForAdd(){
|
|
this._pdTeamForm.reset();
|
|
this.tempArray = [];
|
|
//console.log(this.tempArray);
|
|
}
|
|
|
|
/** To Reset Popup Data For Edit*/
|
|
onResetForEdit(){
|
|
this.PdTeamFormDatas();
|
|
this.tempArray = [];
|
|
}
|
|
isEmptyObject(obj) {
|
|
return (obj && (Object.keys(obj).length === 0));
|
|
}
|
|
|
|
}
|
|
|
|
/** End Of Pd Dialog Component */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
import { Component,
|
|
OnInit,
|
|
ViewChild,
|
|
Inject } from '@angular/core';
|
|
import { FormBuilder,
|
|
FormGroup,
|
|
FormArray,
|
|
Validators,
|
|
FormControl } from '@angular/forms';
|
|
import { MatDialog,
|
|
MatOption,
|
|
MatDialogRef,
|
|
MAT_DIALOG_DATA } from '@angular/material';
|
|
|
|
/** Service *
|
|
import { MastersService } from '../../../../service/masters/masters.service';
|
|
import { PdTeamService } from '../../../../service/masters/pd-team.service';
|
|
|
|
@Component({
|
|
selector: 'app-pd-team-dialog',
|
|
templateUrl: './pd-team-dialog.component.html',
|
|
styleUrls: ['./pd-team-dialog.component.scss']
|
|
})
|
|
|
|
export class PdTeamDialogComponent implements OnInit {
|
|
|
|
public _pdTeamForm: FormGroup;
|
|
citydatas: any[];
|
|
lenderdatas: any[];
|
|
errorMessage:string;
|
|
|
|
@ViewChild('allSelected') private allSelected: MatOption;
|
|
|
|
constructor(private _formBuilder: FormBuilder,
|
|
private dialogRef: MatDialogRef<PdTeamDialogComponent>,
|
|
private _MastersService: MastersService,
|
|
private _PdTeamService: PdTeamService,
|
|
@Inject(MAT_DIALOG_DATA) public data: any) { }
|
|
|
|
ngOnInit() {
|
|
|
|
this._pdTeamForm = this._formBuilder.group({
|
|
|
|
pdteam_id: [this.data.pdteam_id],
|
|
team_name: [this.data.team_name, Validators.compose([Validators.required])],
|
|
fk_city_id: [this.data.fk_city_id, Validators.compose([Validators.required])],
|
|
fk_lender_id: [this.data.fk_lender_id, Validators.compose([Validators.required])],
|
|
// city_ids: this._formBuilder.array([
|
|
// this._formBuilder.group({
|
|
// pdteam_city_mapping_id: [this.data.pdteam_city_mapping_id],
|
|
// fk_team_id:[this.data.pdteam_id],
|
|
// fk_city_id: [this.data.fk_city_id]
|
|
// })
|
|
// ])
|
|
// city_ids: [this._formBuilder.group({
|
|
// pdteam_city_mapping_id: [this.data.pdteam_city_mapping_id],
|
|
// fk_team_id:[this.data.pdteam_id],
|
|
// fk_city_id: [this.data.fk_city_id, Validators.compose([Validators.required])],
|
|
// })
|
|
// ]
|
|
// fk_city_id: this._formBuilder.array([this.data.fk_city_id, Validators.compose([Validators.required])])
|
|
|
|
});
|
|
console.log(this._pdTeamForm);
|
|
|
|
/** For SelectDrop Datas For Multiple Datas*
|
|
// this._MastersService.getAllMasterData('CITY')
|
|
// .subscribe(
|
|
// data => {
|
|
// let userRole:any = [];
|
|
// if (data.status == 200) {
|
|
// this.citydatas = data.records;
|
|
// this.citydatas = this.citydatas.filter(city=>city.isactive == 1 );
|
|
// if(this.data.pdteam_id != null){
|
|
// for (let cities of this.data[0]) {
|
|
// //console.log(role);
|
|
// userRole.push(this.citydatas.filter(city => city.city_id == cities.fk_city_id)[0]);
|
|
// this._pdTeamForm.controls['fk_city_id'].setValue(userRole);
|
|
// }
|
|
// console.log(userRole);
|
|
// }
|
|
// }
|
|
// }, error => this.errorMessage = <any> error);
|
|
|
|
/** For Drop Datas*
|
|
this._MastersService.getAllMasterData('CITY')
|
|
.subscribe(
|
|
dataresult => {
|
|
if (dataresult.status == 200) {
|
|
this.citydatas = dataresult.records;
|
|
this.citydatas = this.citydatas.filter(city=>city.isactive == 1 );
|
|
}
|
|
|
|
}, error => this.errorMessage = <any> error);
|
|
|
|
/** For Drop Datas*
|
|
this._MastersService.getAllMasterData('ENTITY')
|
|
.subscribe(
|
|
dataresult => {
|
|
if (dataresult.status == 200) {
|
|
this.lenderdatas = dataresult.records;
|
|
this.lenderdatas = this.lenderdatas.filter(entity=>entity.isactive == 1 );
|
|
}
|
|
|
|
}, error => this.errorMessage = <any> error);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//pdteam_id, team_name, createdon, fk_createdby, updatedon, fk_updatedby, isactive
|
|
/** For Popup Close Button *
|
|
onNoClick(): void {
|
|
this.dialogRef.close();
|
|
}
|
|
//pdteam_id, team_name, createdon, fk_createdby, updatedon, fk_updatedby, isactive
|
|
/** To Save/Edited Popup Data *
|
|
onSubmit() {
|
|
|
|
var pdTeamFormValues = this._pdTeamForm.value;
|
|
|
|
console.log('b4 null val pdTeamFormValues',pdTeamFormValues);
|
|
if(isNaN(this.data.pdteam_id)) {
|
|
|
|
Object.keys(pdTeamFormValues).forEach(
|
|
(key) => (pdTeamFormValues[key] == null) && delete pdTeamFormValues[key]
|
|
);
|
|
|
|
console.log('After null val pdTeamFormValues',pdTeamFormValues);
|
|
// // var start_index = 2
|
|
// // var number_of_elements_to_remove = 1;
|
|
// // var removed_elements = pdTeamFormValues.splice(start_index, number_of_elements_to_remove);
|
|
// // console.log(removed_elements);
|
|
// //["k"]
|
|
|
|
// pdTeamFormValues.splice(3, 1);
|
|
// console.log(pdTeamFormValues);
|
|
|
|
this._PdTeamService.addPdTeamDetail(pdTeamFormValues).subscribe(
|
|
dataresult=>{
|
|
if (dataresult.dataStatus == true){
|
|
//After Saving the data then popup close
|
|
this.dialogRef.close();
|
|
//Need To Dispaly saving Datas
|
|
alert("Data Saved Successfully");
|
|
}
|
|
else{
|
|
alert("SomeThing Wents Wrong Try Again !");
|
|
}
|
|
|
|
});
|
|
} else { alert('Not Yet Completed Edit Function'); }
|
|
// //this._MastersService.editProductMaster(this._pdTeamForm.value);
|
|
// this._MastersService.editMasterDetails(this._pdTeamForm.value,'PDTEAM').subscribe( dataresult=>{
|
|
// if (dataresult.dataStatus == true){
|
|
// //After Editing0 the data then popup close
|
|
// this.dialogRef.close();
|
|
// //Need To Display saving Datas
|
|
// alert("Data Edited Successfully");
|
|
// }
|
|
// else{
|
|
// alert("SomeThing Wents Wrong Try Again !");
|
|
// }
|
|
// });
|
|
// }
|
|
}
|
|
|
|
/** To Reset Popup Data /
|
|
onReset(){
|
|
this._pdTeamForm.reset();
|
|
}
|
|
|
|
}
|
|
/** End Of Product Master Component*/
|
|
|
|
|
|
|
|
|
|
|