import { Component, OnInit } from '@angular/core'; import { KGridHelper } from '../../../_helpers/k-grid.class'; import { NotificationService } from '../../../_services/notification.service'; import { AccountService } from '../../accounts/accounts-services'; import { AuthenticationService } from '../../../_services/authentication.service'; import { SortDescriptor, orderBy } from '@progress/kendo-data-query'; import { PageChangeEvent } from '@progress/kendo-angular-grid'; import { StoreService } from '../store.services'; import { Router } from '@angular/router'; import { ClaimsService } from '../../../_services/claims.service'; import { ClaimKeys } from '../../../_helpers/claimkeys.class'; import { LocalService } from '../../../_services/local.service'; @Component({ selector: 'app-sp-list-view', templateUrl: './sp-list-view.component.html', }) export class SpListViewComponent implements OnInit { public kGrid: KGridHelper = new KGridHelper(); public calingUrl: string; public listHeder: string; public addNewUrl: string; constructor(private router: Router, public _notificationService: NotificationService, public _storeService: StoreService, public _authenticationService: AuthenticationService, public _claimService: ClaimsService, public _localService: LocalService) { } ngOnInit() { this.calingUrl = this.router.url; this.initializeProps(); if (this.calingUrl == '/store/p-list') { this.kGrid.spType = 2; this.listHeder = 'Purchase'; this.addNewUrl = '/store/purchase/'; } else if (this.calingUrl == '/store/s-list') { this.kGrid.spType = 1; this.listHeder = 'Sales'; this.addNewUrl = '/store/sales/'; } else { this.kGrid.spType = 3; this.listHeder = 'Return'; this.addNewUrl = '/store/purchase-return/'; } this.getSPList(); } private initializeProps() { this.kGrid.loading = false; this.kGrid.pageSize = 20; this.kGrid.pageSizes = [20, 50, 100]; } public getSPList() { this.kGrid.loading = true; this._storeService.getSpItemList(this.kGrid.spType, 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) ); } 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.getSPList(); } 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.getSPList(); } public GoForEdit(e: any) { if (e.PaidAmount > 0) { this._notificationService.notify("danger", "Sorry This Order Can't be Edit Any More."); } else { if (e.FK_Inv_Type.Id == 2) { this.router.navigate(['/store/edit-purchase'], { queryParams: { id: e.Id } }); } else { if (e.FK_Inv_Type.Id == 1) { this.router.navigate(['/store/edit-sales'], { queryParams: { id: e.Id } }); } else { this.router.navigate(['/store/edit-return'], { queryParams: { id: e.Id } }); } } } } }