import { Component, OnInit } from '@angular/core'; import { KGridHelper } from '../../../_helpers/k-grid.class'; import { Subject, Subscription } from 'rxjs'; import { ActivatedRoute } from '@angular/router'; import { NotificationService } from '../../../_services/notification.service'; import { EmployeeServices } from '../../employee/employee-services'; import { SettingServices } from '../../settings/setting.services'; import { StoreService } from '../../store/store.services'; import { LocalService } from '../../../_services/local.service'; import { debounceTime } from 'rxjs/operators'; import { SortDescriptor } from '@progress/kendo-data-query'; import { PageChangeEvent } from '@progress/kendo-angular-grid'; import { AdvancesService } from '../advances-services'; import { AdvanceViewModel, AdvanceInstallmentViewModel } from '../advances-class'; @Component({ selector: 'app-advance-installment-list', templateUrl: './advance-installment-list.component.html' }) export class AdvanceInstallmentListComponent implements OnInit { public openDilog = false; public openDilogCat = false; public saving = false; public deleting = false; public openDeleteConfirmationDialog = false; public kGrid: KGridHelper = new KGridHelper(); public searchEvent = new Subject(); public searchSubcription: Subscription = null; public _advanceModel: AdvanceViewModel; public _advanceInstallmentVm: AdvanceInstallmentViewModel; constructor(public activatedRoute: ActivatedRoute, public _advancesService: AdvancesService, public _notificationService: NotificationService, public _settingService: SettingServices, public _storeService: StoreService, public _localService: LocalService) { } ngOnInit() { this.initializeProps(); this.activatedRoute.queryParams.subscribe(params => { const id = params['id']; if (id != null) { this.GetInstallmentsByMastId(id); } else { this.getAdvancesInstallmentList(); } }); } GetInstallmentsByMastId(id) { this.kGrid.loading = true; this._advancesService.GetAdvanceInstallmentListByMastId(id).subscribe((res: any) => { console.log(res); this.kGrid.data = []; this.kGrid.data = res; this.kGrid.totalRecords = res.length; this.kGrid.gridView = { data: this.kGrid.data, total: this.kGrid.totalRecords }; this.kGrid.loading = false; console.log(this.kGrid.gridView); }, (err) => { console.log(err); }); } getAdvancesInstallmentList() { this.kGrid.loading = true; this._advancesService.GetAdvanceInstallmentList().subscribe((res: any) => { console.log(res); this.kGrid.data = []; this.kGrid.data = res; this.kGrid.totalRecords = res.length; this.kGrid.gridView = { data: this.kGrid.data, total: this.kGrid.totalRecords }; this.kGrid.loading = false; console.log(this.kGrid.gridView); }, (err) => { console.log(err); }); } private initializeProps() { this.kGrid.loading = false; this.kGrid.pageSize = 20; this.kGrid.pageSizes = [20, 50, 100]; } // public getAccount(x: string, event: string) { // this._storeService.getAccountBySearch(x, event).subscribe((res: any) => { // if (res) { // if (event === 'E') { // this.employeeAccountList = res; // } // if (event === 'Incom') { // this.incomeAccountList = res; // } // if (event === 'CaB') { // this.paymentAccountList = res; // } // if (event === 'Exp') { // this.expenseAccountList = res; // } // } // }, err => { // this._notificationService.notify('danger', err.msg); // }); // } public getVisaExpenseHeads() { this._settingService.getVisaExpenseHeadList().subscribe((res: any) => { // this.visaExpensheadList = res; console.log(res); }, (err) => { this._notificationService.notify('danger', err.msg); }); } OpenVisaInstallmentDialog(item) { // this.openAddVisaInstalmentDialog = true; // this._visaInstallmentVM = item; // this._visaInstallmentVM.CreatedDate = new Date(item.CreatedDate); // this._visaInstallmentVM.InstallmentNo = (this._visaMasterDetailVM.PaidInstallments + 1); // this._visaInstallmentVM.Fk_EmployeAccount = this._visaMasterDetailVM.Fk_EmployeAccount; // this._visaInstallmentVM.InstallmentAmount = this._remainingAmount / this._remainingInstalments; // console.log(this._visaMasterDetailVM.Fk_EmployeAccount); // this.getAccount(' ', 'E'); // this.getAccount(' ', 'Incom'); // this.getAccount(' ', 'CaB'); // this.getVisaExpenseHeads(); // this.validateVisaInstalmentCode('-1'); } onSubmitVisaInstallment() { // let iv = new ItemViewModel(); // iv.Id = this._visaMasterDetailVM.Id; // this._visaInstallmentVM.Fk_VisaMasterDetail = iv; // this._visaService.saveVisaInstalment(this._visaInstallmentVM).subscribe((res) => { // this.Close(); // this._notificationService.notify('success', 'Visa Installment Saved Successfully'); // this._visaInstallmentVM = new VisaInstallmentVieModel(); // this.getInstallmentList(); // }, (err) => { // this._notificationService.notify('danger', 'Something Went Wrong'); // }); } OpenDeleteConfirmationDialog(item) { this.openDeleteConfirmationDialog = true; this._advanceInstallmentVm = item; } Close() { this.openDeleteConfirmationDialog = false; // this.openAddVisaInstalmentDialog = false; } ConfirmDelete() { this.deleting = true; this._advancesService.DeleteAdvanceInstallment(this._advanceInstallmentVm.Id).subscribe((res) => { this._notificationService.notify('success', 'Record Delete Successfully'); this.Close(); this.deleting = false; this._advanceInstallmentVm = new AdvanceInstallmentViewModel(); this.getAdvancesInstallmentList(); }, (err) => { this.deleting = false; this._notificationService.notify('danger', 'Something Went Wrong'); }); } // public handleSearchEvents() { // this.searchSubcription = this.searchEvent.pipe( // debounceTime(400)).subscribe((x: any) => { // console.log(x); // if (x) { // if (x.filter == 'FK_Exp_Acc') { // this.getAccount(x.event, 'E'); // this.getAccount(x.event, 'Exp'); // this.getAccount(x.event, 'Incom'); // this.getAccount(x.event, 'CaB'); // } // this.getVisaExpenseHeads(); // } // }); // } public changePagesize(value: any) { this.kGrid.pageSize = +value; this.kGrid.skip = 0; this.getAdvancesInstallmentList(); } public sortChange(sort: SortDescriptor[]): void { if (sort[0].field == 'asd') { return; } this.kGrid.sort = sort; // this.sortData(); } public pageChange(event: PageChangeEvent): void { this.kGrid.skip = event.skip; this.getAdvancesInstallmentList(); } }