import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { CoustomerServices } from '../../coustome-services'; import { CoustomerContrectViewMode } from '../../coustomer-class'; import { NotificationService } from '../../../../_services/notification.service'; import { Attachments } from '../../../store/store-model'; import { StoreService } from '../../../store/store.services'; import { LocalService } from '../../../../_services/local.service'; @Component({ selector: 'app-contrect-dtl', templateUrl: './contrect-dtl.component.html', }) export class ContrectDtlComponent implements OnInit { public contrect: CoustomerContrectViewMode; public employeeList: any[] = []; public attachmentList: any[] = []; public selectedEmp: any; public returnDate: Date; public assingDate = new Date(); public nowDate = new Date(); public openDilogCat = false; public openDilogConfirmation = false; public openRemoveEmpDilog = false; public attachments = new Attachments(); public saving = false; constructor(private activatedRoute: ActivatedRoute, public _notificationService: NotificationService, public _storeService: StoreService, private _coustomerServices: CoustomerServices, private _localService: LocalService) { } ngOnInit() { this.activatedRoute.queryParams.subscribe(params => { const accId = params['id']; if (accId != null) { this.getContrectDetail(accId); } else { this.contrect = new CoustomerContrectViewMode(); this.contrect.ContrectDate = new Date(); this.contrect.Accessories = []; } }); } public ChangeStatus() { this._coustomerServices.ChangeCOntrectStatus(this.contrect.Id).subscribe((res: any) => { if (res) { if (res.msg == "Y") { this._notificationService.notify("success", "Status Change Successfully"); this.contrect.Status = !this.contrect.Status } else this._notificationService.notify("danger", res.msg); } }, err => { }); } public getAttachment(e) { this._storeService.getAttachments(e, "con").subscribe((res: any) => { if (res) { this.attachmentList = res.res; console.log(res); } }, err => { }) } public getContrectDetail(id: number) { this._coustomerServices.getContretcById(id).subscribe((res: any) => { if (res) { this.contrect = res.con; this.contrect.ContrectDate = new Date(res.con.ContrectDate) this.contrect.StartDate = new Date(res.con.StartDate) this.contrect.EndDate = new Date(res.con.EndDate) this.attachments.FK_Contrect_Id = this.contrect.Id; this.getAttachment(this.contrect.Id); } }, err => { }); } public getAssingedEmployee() { if (this.employeeList.length > 0) return; this._coustomerServices.getAssingedEmployee(this.contrect.Id).subscribe((res: any) => { if (res) { this.employeeList = res } }, err => { }); } public openDilogRemoveEmp(x: any) { this.selectedEmp = x; this.assingDate = new Date(x.StartDate); this.openRemoveEmpDilog = true; } public close(status) { this.openRemoveEmpDilog = false; } public SaveReturn(e) { var date = this.returnDate.toLocaleString(); this._coustomerServices.saveUnassindEmployee(this.selectedEmp.FK_Employee, date, this.contrect.Id).subscribe( (response: any) => { debugger; this.openRemoveEmpDilog = false; if (response.err == "N") { this._notificationService.notify("success", "UnAssinged Successfully!"); this.returnDate = null; this.getAssignedEmployee(); } else { this._notificationService.notify("danger", response.msg); this.returnDate = null; } }); } public getAssignedEmployee() { this._coustomerServices.getAssingedEmployee(this.contrect.Id).subscribe((res: any) => { if (res) { this.employeeList = res } }, err => { }); } public RemoveDoc(e) { } public closeCat(status) { this.openDilogCat = false; this.openDilogConfirmation = false; } public getFIle(event) { debugger; this.attachments.file = event.target.files[0]; } public saveCatlog() { if (this.attachments.file == null) { this._notificationService.notify("danger", "Select a file first!"); return; } this.saving = true; this._storeService.saveAttachment(this.attachments).subscribe((res: any) => { this._notificationService.notify("success", "Catlog Save Successfully"); this.attachments = new Attachments(); this.saving = false; this.attachments.FK_Contrect_Id = this.contrect.Id; // this.getAttachment(this.itemId); // this.getAttachment(this.itemId) this.getAttachment(this.contrect.Id); this.closeCat('y'); }, err => { this._notificationService.notify("danger", err.error); this.saving = false; }) } }