import { Component, OnInit } from '@angular/core'; import { KGridHelper } from '../../../_helpers/k-grid.class'; import { NotificationService } from '../../../_services/notification.service'; import { StoreService } from '../store.services'; import { AuthenticationService } from '../../../_services/authentication.service'; import { SortDescriptor, orderBy } from '@progress/kendo-data-query'; import { PageChangeEvent } from '@progress/kendo-angular-grid'; import { LocalService } from '../../../_services/local.service'; @Component({ selector: 'app-item-assing-list', templateUrl: './item-assing-list.component.html', }) export class ItemAssingListComponent implements OnInit { public kGrid: KGridHelper = new KGridHelper(); public openDilog = false; public selectedItem: any; public nowDate = new Date(); public assingDate = new Date(); public returnDate: Date; public assigingPrintList: any[] = []; public itemToDelete: any; public returnQty: number; public maxReturnQty: number; public openDeleteConfirmationDialog = false; public deleting = false; constructor(public _notificationService: NotificationService, public _storeService: StoreService, public _authenticationService: AuthenticationService, public _localService: LocalService) { } ngOnInit() { this.initializeProps(); this.getAssignedItems(); } private initializeProps() { this.kGrid.loading = false; this.kGrid.pageSize = 20; this.kGrid.pageSizes = [20, 50, 100]; } public getAssignedItems() { this.kGrid.loading = true; this._storeService.getAssignedItems(this.kGrid.skip, this.kGrid.pageSize, this.kGrid.searchQuery, this.kGrid.hfId, this.kGrid.geoLvlCode, this.kGrid.hfType, this.kGrid.stockId).subscribe( (response: any) => { this.kGrid.data = []; this.kGrid.data = response.DtlList; this.kGrid.totalRecords = response.TotalCount; this.kGrid.gridView = { data: this.kGrid.data, total: this.kGrid.totalRecords }; this.kGrid.loading = false; console.log(this.kGrid.gridView); }, err => this.handleError(err) ); } OnDeleteItem(item) { this.itemToDelete = item; this.openDeleteConfirmationDialog = true; } ConfirmDelete() { this.deleting = true; this._storeService.removeStockassigning(this.itemToDelete.Id).subscribe((res: any) => { this._notificationService.notify("success", "Deleted Successfully!"); this.deleting = false; this.getAssignedItems(); this.close(''); }, (err) => { this._notificationService.notify("danger", "Something Went Wrong!"); }); } public sortChange(sort: SortDescriptor[]): void { if (sort[0].field == 'asd') { return; } this.kGrid.sort = sort; this.sortData(); } private sortData() { this.kGrid.gridView = { data: orderBy(this.kGrid.data, this.kGrid.sort), total: this.kGrid.totalRecords }; } public pageChange(event: PageChangeEvent): void { this.kGrid.skip = event.skip; this.getAssignedItems(); } private handleError(err: any) { this.kGrid.loading = false; if (err.status == 403) { this._authenticationService.logout(); } } onBinClick(aid: number) { alert(aid); } public openDilogFun(x: any) { this.selectedItem = x; this.maxReturnQty = x.Issue_Qty; this.returnQty = x.Issue_Qty; this.assingDate = new Date(x.Issue_Date); if (this.selectedItem.Return_Status == true) { this._notificationService.notify("success", "Already Returend!"); return; } this.openDilog = true; console.log(this.selectedItem); } public changePagesize(value: any) { this.kGrid.pageSize = +value; this.kGrid.skip = 0; this.getAssignedItems(); } public close(status) { this.openDilog = false; this.openDeleteConfirmationDialog = false; } public SaveReturn(e) { var date = this.returnDate.toLocaleString(); this._storeService.saveReturnItem(this.selectedItem.Id, date, this.returnQty).subscribe( (response: any) => { debugger; var i = { FK_Item_Name: this.selectedItem.FK_Item_Name, EmpName: this.selectedItem.FK_Employee.Name, returnDate: this.returnDate, returnQty: this.returnQty }; this.assigingPrintList.push(i); this.openDilog = false; this._notificationService.notify("success", "Return Successfully!"); this.returnDate = null; this.getAssignedItems(); }, err => this.handleError(err) ); } }