import { Component, OnInit } from '@angular/core'; import { RootService } from '../../../_services/root.service'; import { StockService } from '../stock.service'; import { NotificationService } from '../../../_services/notification.service'; import { GridComponent, GridDataResult, DataStateChangeEvent } from '@progress/kendo-angular-grid'; import { process, State } from '@progress/kendo-data-query'; import { StockDemandMasterViewModel } from '../MedStock.class'; import { AuthenticationService } from '../../../_services/authentication.service'; import { LocalService } from '../../../_services/local.service'; @Component({ selector: 'app-stock-demand', templateUrl: './stock-demand.component.html', styles: [] }) export class StockDemandComponent implements OnInit { public MedList: any[] = []; public saving = false; public yearList = [2019, 2020] public loading = false; public stockM: StockDemandMasterViewModel = new StockDemandMasterViewModel(); public state: State = { // skip: 0, //take: 5, // Initial filter descriptor filter: { logic: 'and', filters: [{ field: 'Name', operator: 'contains', value: '' }] } }; public gridData: GridDataResult = process(this.MedList, this.state); public dataStateChange(state: DataStateChangeEvent): void { this.state = state; this.gridData = process(this.MedList, this.state); } constructor(private _authenticationService: AuthenticationService, private _rootService: RootService, private _stockService: StockService, public _notificationService: NotificationService, private _localService: LocalService) { } ngOnInit() { this.stockM.Year = new Date().getFullYear(); this.drpYearOnChange(); } drpYearOnChange() { this.loading = true; this._stockService.getExistingDemands(this.stockM.Year).subscribe( (res: any) => { if (res) { this.stockM = res; this.loading = false; } }, err => { this.loading = false; this.handleError(err); } ); } saveDemand(obj: any) { debugger; this.saving = true; obj.DemandMaster = new StockDemandMasterViewModel(); obj.DemandMaster.Year = this.stockM.Year; this._stockService.saveDemand(obj).subscribe( (res: any) => { this.saving = false; this._notificationService.notify("success", "Demand Save Successfully"); }, err => { this.saving = false; this.handleError(err); } ); } private handleError(err: any) { if (err.status == 403) { this._authenticationService.logout(); } } }