import { Component, OnInit } from '@angular/core'; import { KGridHelper } from '../../../_helpers/k-grid.class'; import { NotificationService } from '../../../_services/notification.service'; import { ReportingService } from '../reporting.service'; import { AuthenticationService } from '../../../_services/authentication.service'; import { State, SortDescriptor, orderBy, process } from '@progress/kendo-data-query'; import { DataStateChangeEvent, PageChangeEvent } from '@progress/kendo-angular-grid'; import { LocalService } from '../../../_services/local.service'; @Component({ selector: 'app-inventory-report', templateUrl: './inventory-report.component.html', }) export class InventoryReportComponent implements OnInit { public kGrid: KGridHelper = new KGridHelper(); public openDilog = false; constructor(public _notificationService: NotificationService, public _reportingServices: ReportingService, public _authenticationService: AuthenticationService, public _localService: LocalService) { } public state: State = { skip: 0, take: 5, // Initial filter descriptor filter: { logic: 'and', filters: [] } }; ngOnInit() { this.initializeProps(); this.getEmployeelist(); } private initializeProps() { this.kGrid.loading = false; this.kGrid.pageSize = 20; this.kGrid.pageSizes = [20, 50, 100]; } public getEmployeelist() { this.kGrid.loading = true; this._reportingServices.getInventoryReport(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 = this.parseDate(response.DtlList); console.log(this.kGrid.data); this.kGrid.totalRecords = response.TotalCount; this.kGrid.gridView = process(this.kGrid.data, this.state); this.kGrid.gridView = { data: this.kGrid.data, total: this.kGrid.totalRecords }; this.kGrid.loading = false; console.log(this.kGrid.gridView); }, err => this.handleError(err) ); } parseDate(list) { for (let i = 0; i < list.length; i++) { if (list[i].Assign_Qty == 1) { list[i].Assign_Qty = "Assigned" } else { list[i].Assign_Qty = "Unassigned" } } return list; } public dataStateChange(state: DataStateChangeEvent): void { debugger; this.state = state; this.kGrid.gridView = process(this.kGrid.data, this.state); } 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.getEmployeelist(); } private handleError(err: any) { this.kGrid.loading = false; if (err.status == 403) { this._authenticationService.logout(); } } onBinClick(aid: number) { alert(aid); } public changePagesize(value: any) { this.kGrid.pageSize = +value; this.kGrid.skip = 0; this.getEmployeelist(); } public columns: string[] = [ "Sr", "In_Qty", "Sale_Qty", "Assign_Qty", "Status" , "Item_Type", "Code", "RegistrationNo", "Item_Name", "Brand" , "Model_Year", "Color", "City", "Size", "Measure", "Purchase_Price", "Sale_Price", "Description" , "Bike_Engg_Power", "Bike_Insured_By", "Bike_Salik", "Bike_Garage", "Mobile_Ram", "Mobile_InternalMemory", "Sim_Plan_Banifits", "ItemCategory" , "Exp_Date", "Remarks" ]; public columnsLabel: string[] = [ "Sr", "In Qty", "Sale Qty", "Assign Qty", "Status" , "Item Type", "Code", "Registration No", "Item Name", "Brand" , "Model Year", "Color", "City", "Size", "Measure", "Purchase Price", "Sale Price", "Description" , "Engg. Power", "Insured By", "Salik", "Garage", "Ram", "InternalMemory", "Plan Banifits", "Item Category" , "Ex Date", "Remarks" ]; public close(status) { this.getEmployeelist(); this.openDilog = false; } public hiddenColumns: string[] = []; public isHidden(columnName: string): boolean { var c = this.columns[this.columnsLabel.indexOf(columnName)] return this.hiddenColumns.indexOf(c) > -1; } public isHiddenGrid(columnName: string): boolean { return this.hiddenColumns.indexOf(columnName) > -1; } public isDisabled(columnName: string): boolean { var c = this.columns[this.columnsLabel.indexOf(columnName)] return this.columns.length - this.hiddenColumns.length === 1 && !this.isHidden(columnName); } public hideColumn(columnName: string): void { var c = this.columns[this.columnsLabel.indexOf(columnName)] const hiddenColumns = this.hiddenColumns; if (!this.isHidden(columnName)) { hiddenColumns.push(c); } else { hiddenColumns.splice(hiddenColumns.indexOf(c), 1); } } }