import { Component, OnInit, ViewChild } from '@angular/core'; import { EmployeeAssiginingModel } from '../../coustomer-class'; import { Subject, Subscription } from 'rxjs'; import { debounceTime } from 'rxjs/operators'; import { CoustomerServices } from '../../coustome-services'; import { NotificationService } from '../../../../_services/notification.service'; import { ActivatedRoute } from '@angular/router'; import { LocalService } from '../../../../_services/local.service'; import { FormCanDeactivate } from '../../../../_guards/form-can-deactivate'; import { NgForm } from '@angular/forms'; @Component({ selector: 'app-employee-assiging', templateUrl: './employee-assiging.component.html', }) export class EmployeeAssigingComponent extends FormCanDeactivate implements OnInit { @ViewChild('f') form: NgForm; public assiging = null; public contrectList: any[] = []; public empList: any[] = []; public empDtl: any[] = []; public searchEvent = new Subject(); public searchSubcription: Subscription = null; public saving = false; public maxDate = new Date(); public minDate = null; constructor(private _coustomerServices: CoustomerServices, public _notificationService: NotificationService, private activatedRoute: ActivatedRoute, private _localService: LocalService ) { super(); } ngOnInit() { this.activatedRoute.queryParams.subscribe(params => { const accId = params['id']; if (accId != null) { this.getContrectList(" "); //this.getAvalibelEmployee(" "); this.getAssingedEmpDtl(accId); } else { this.assiging = new EmployeeAssiginingModel(); this.assiging.AssiginingDate = new Date(); this.assiging.Mode = "Permanent"; } }); this.handleSearchEvents(); } public getAssingedEmpDtl(e) { this._coustomerServices.getAssingedEmpDtl(e).subscribe((res: any) => { if (res) { this.empList.push(res.FK_Employee); this.assiging = new EmployeeAssiginingModel(); this.assiging = res; if (res.CreationDate != null) this.assiging.AssiginingDate = new Date(res.CreationDate); else{ this.assiging.AssiginingDate = new Date(); } if (res.StartDate != null) this.assiging.StartDate = new Date(res.StartDate); if (res.EndDate != null) this.assiging.EndDate = new Date(res.EndDate); } }, err => { this._notificationService.notify("danger", err.error); }); } public onSubmit() { this.saving = true; let con: any = Object.assign({}, this.assiging); if (this.assiging.StartDate) con.StartDate = this.assiging.StartDate.toDateString(); if (this.assiging.EndDate) con.EndDate = this.assiging.EndDate.toDateString(); this._coustomerServices.saveEmployForContrect(con).subscribe((res: any) => { this._notificationService.notify("success", "Save Successfully!"); this.assiging = new EmployeeAssiginingModel(); this.assiging.AssiginingDate = new Date(); this.assiging.Mode = "Permanent"; this.saving = false; }, err => { this._notificationService.notify("danger", err.error); }); } public getContrectList(x: string) { this._coustomerServices.getContrectListDDL(x , 'Internal').subscribe((res: any) => { if (res) { debugger; this.contrectList = res; } }, err => { this._notificationService.notify("danger", err.msg); }) } public getAvalibelEmployee(x: string) { this._coustomerServices.getAvalibelEmployee(x, this.assiging.Mode).subscribe((res: any) => { if (res) { this.empList = res; } }, err => { this._notificationService.notify("danger", err.msg); }) } public ModeChange(e) { this.assiging = new EmployeeAssiginingModel(); this.assiging.AssiginingDate = new Date(); this.assiging.Mode = e; } public SetMinDate() { debugger; var d = this.empList.find(x => x.Id == this.assiging.FK_Employee.Id).lD; if (d != "") { this.minDate = new Date(d); } else { this.minDate = null; } } public ClearForm() { } public FeatchEmpdetail() { this._coustomerServices.getEmployeeDetail(this.assiging.FK_Employee.Id, this.assiging.FK_Contrect.Id).subscribe((res: any) => { if (res) { this.empDtl = res; } }, err => { this._notificationService.notify("danger", err.msg); }) } public handleSearchEvents() { this.searchSubcription = this.searchEvent.pipe( debounceTime(400)).subscribe((x: any) => { console.log(x); if (x) { debugger; if (x.filter == "Customer") { this.getContrectList(x.event); } if (x.filter == "FK_Employee") { this.getAvalibelEmployee(x.event); } } }); } }