import { Component, OnInit } from '@angular/core'; import { KGridHelper } from '../../../_helpers/k-grid.class'; import { NotificationService } from '../../../_services/notification.service'; import { ReportingService, ExpenseFiltersViewModel } from '../reporting.service'; import { AuthenticationService } from '../../../_services/authentication.service'; import { State, SortDescriptor, orderBy, process } from '@progress/kendo-data-query'; import { LocalService } from '../../../_services/local.service'; import { PageChangeEvent, DataStateChangeEvent } from '@progress/kendo-angular-grid'; import { StoreService } from '../../store/store.services'; import { Subject, Subscription } from 'rxjs'; import { debounceTime } from 'rxjs/operators'; import { ItemViewModel, Sale_PurchaseDetailViewModel } from '../../store/store-model'; @Component({ selector: 'app-expense-report', templateUrl: './expense-report.component.html' }) export class ExpenseReportComponent implements OnInit { public kGrid: KGridHelper = new KGridHelper(); public openDilog = false; public options: ExpenseFiltersViewModel; public searchEvent = new Subject(); public searchSubcription: Subscription = null; public sp_item = new Sale_PurchaseDetailViewModel(); constructor(public _notificationService: NotificationService, public _reportingServices: ReportingService, public _authenticationService: AuthenticationService, public _storeService: StoreService, public _localService: LocalService) { } public state: State = { skip: 0, take: 5, // Initial filter descriptor filter: { logic: 'and', filters: [] } }; public colorList: any[] = []; public brandsList: any[] = []; public modelYearList: any[] = []; public engPower: any[] = []; public cityList: any[] = []; public garageList: any[] = []; public cusaccountList: any[]; public supAccount: any[]; public itemList: any = []; public geting = false; public itemNameList: any[] = []; ngOnInit() { this.options = new ExpenseFiltersViewModel(); this.getCatlogs('Item Name', ''); this.getCatlogs('Color', ''); this.getCatlogs('Brand', ''); this.getCatlogs('City', ''); this.getCatlogs('Measure', ''); this.getCatlogs('Bike_Garage', ''); this.getCatlogs('Model_Year', ''); this.getCatlogs('Item Name', ''); this.getCatlogs('Bike_Engg_Power', ''); this.getCatlogs('Mobile_Ram', ''); this.getCatlogs('Mobile_InternalMemory', ''); this.getCatlogs('Size', ''); this.getCatlogs('Bike_Insured_By', ''); this.getCatlogs('Sim_Plan_Banifits', ''); this.getItem(' '); this.getAccount('', 'CCS'); this.getAccount('', 'S'); 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.getExpenseReport(this.options).subscribe( (response: any) => { console.log(response) this.kGrid.data = []; this.kGrid.data = this.parseDate(response); console.log(this.kGrid.data); this.kGrid.totalRecords = response.length; 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) ); } public getCatlogs(x: string, event: string) { this.brandsList = []; this._storeService.getFilterdCatlogs(x, event).subscribe((res: any) => { if (res) { if (x == 'Brand') { this.brandsList = res; } if (x == 'Color') { this.colorList = res; } if (x == 'City') { this.cityList = res; } if (x == 'Item Name') { this.itemNameList = res; } if (x == 'Model_Year') { this.modelYearList = res; } if (x == 'Bike_Engg_Power') { this.engPower = res; } if (x == 'Bike_Garage') { this.garageList = res; } // if (x == 'Mobile_Ram') { // this.ramlist = res; // } // if (x == 'Mobile_InternalMemory') { // this.internalMamList = res; // } // if (x == 'Size') { // this.sizeList = res; // } // if (x == 'Bike_Insured_By') { // this.insuredByList = res; // } // if (x == 'Sim_Plan_Banifits') // this.planBanfitsList = res; } }, err => { this._notificationService.notify('danger', err.msg); }); } public dropdownValueChanged = (value, filter) => { if (!value) { return; } if (filter === 'itemCode') { debugger; console.log(this.itemList); let item = this.itemList.find(x => x.Code === value); this.options.Item = new ItemViewModel(item.Id, item.Name); // this.sp_item.FK_Item_Id = this.itemList.find(x => x.Code === value).Id; // this.sp_item.Item_Name = this.itemList.find(x => x.Code === value).Name; // this.sp_item.UOM = this.itemList.find(x => x.Code === value).Measure; // this.sp_item.Rate = this.itemList.find(x => x.Code === value).Purchase_Price; // this.sp_item.Item_Type = this.itemList.find(x => x.Code === value).Item_Type; // if (this.sp_item.Item_Type === 'Product') { // this.getStockStats(this.sp_item.FK_Item_Id); // let exBatches: any = this.itemList.find(x => x.Code === value).ExistingBatches; // this.batchesOfSelectedItems = exBatches; // } } } public getAccount(x: string, event: string) { debugger; this._storeService.getAccountBySearch(x, event).subscribe((res: any) => { if (res) { // if (event == 'Exp') // this.accountList = res; if (event == 'CCS') { this.cusaccountList = res; } if (event == 'S') { this.supAccount = res; } } }, err => { this._notificationService.notify('danger', err.msg); }); } public getItem(x: string) { this._storeService.getItemBySearch(x).subscribe((res: any) => { if (res) { this.itemList = res; console.log(res); } }, err => { this._notificationService.notify('danger', err.msg); }); } 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 handleSearchEvents() { this.searchSubcription = this.searchEvent.pipe( debounceTime(400)).subscribe((x: any) => { console.log(x); this.brandsList = []; if (x) { debugger; if (x.event.length > 1) x.event = x.event.replace(/\s/g, ''); // if (x.filter == 'code') { // this.validateItemCode(x.event); // } if (x.filter == 'Brand') { this.getCatlogs('Brand', x.event); } if (x.filter == 'Color') { this.getCatlogs('Color', x.event); } if (x.filter == 'City') { this.getCatlogs('City', x.event); } if (x.filter == 'Measure') { this.getCatlogs('Measure', x.event); } if (x.filter == 'Item Name') { this.getCatlogs('Item Name', x.event); } if (x.filter == 'Model_Year') { this.getCatlogs('Model_Year', x.event); } if (x.filter == 'Bike_Engg_Power') { this.getCatlogs('Bike_Engg_Power', x.event); } if (x.filter == 'Bike_Garage') { this.getCatlogs('Bike_Garage', x.event); } if (x.filter == 'Mobile_Ram') { this.getCatlogs('Mobile_Ram', x.event); } if (x.filter == 'Mobile_InternalMemory') { this.getCatlogs('Mobile_InternalMemory', x.event); } if (x.filter == 'Size') { this.getCatlogs('Size', x.event); } if (x.filter == 'Bike_Insured_By') { this.getCatlogs('Bike_Insured_By', x.event); } if (x.filter == 'Sim_Plan_Banifits') { this.getCatlogs('Sim_Plan_Banifits', x.event); } if (x.filter == 'Contract_Expire_Date') { this.getCatlogs('Contract_Expire_Date', x.event); } if (x.filter == 'account') { this.getAccount(x.event, 'Exp'); } if (x.filter == 'cutomer') { this.getAccount(x.event, 'CCS'); } if (x.filter == 'FK_Billing_Account') { this.getAccount(x.event, 'S'); } if (x.filter === 'itemCode') { this.getItem(x.event); // if (x.event !== '') { // } } } }); } 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[] = [ 'Fk_Item', 'Code', 'Decsription', 'ExpenseHead', 'TransactionDate', 'StartDate', 'EndDate', 'Customer', 'Employe', 'Amount' ]; public columnsLabel: string[] = [ 'Item Code','Expense Code', 'Decsription', 'Expense Head', 'Transaction Date', 'From Date', 'To Date', 'Customer', 'Employe Name', 'Expense Amount' ]; 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); } } }