import { Component, OnInit } from '@angular/core'; import { InstalmentVewModel } from '../../../store/store-model'; import { Subject, Subscription } from 'rxjs'; import { AccountService } from '../../accounts-services'; import { StoreService } from '../../../store/store.services'; import { NotificationService } from '../../../../_services/notification.service'; import { ActivatedRoute } from '@angular/router'; import { LocalService } from '../../../../_services/local.service'; @Component({ selector: 'app-day-book-view', templateUrl: './day-book-view.component.html' }) export class DayBookViewComponent implements OnInit { public instalment: InstalmentVewModel; public accountList: any[] = []; public allAccountList: any[] = []; public dayBookList: any[] = []; public maxDate = new Date(); public saving = false; public TotalTo = 0; public TotalFrom = 0; public showSave = false; public searchEvent = new Subject(); public searchSubcription: Subscription = null; public isEdit = false; constructor( public _accountService: AccountService, public _storeService: StoreService, public _notificationService: NotificationService, private activatedRoute: ActivatedRoute, public _localService: LocalService ) { } ngOnInit() { this.activatedRoute.queryParams.subscribe(params => { const accId = params['id']; if (accId != null) { this.getDayBookDetail(accId); } else { this.instalment = new InstalmentVewModel(); this.instalment.SP_Date = new Date(); this.instalment.IsDayBook = true; this.instalment.Type = 'C'; } }); this.maxDate = new Date(); this.maxDate.setHours(this.maxDate.getHours() + 2); } public getDayBookDetail(e) { this._storeService.getDayBookDetail(e).subscribe((res: any) => { if (res) { // debugger; console.log(res); this.instalment = new InstalmentVewModel(); this.instalment = res; this.instalment.Attachment = res.Attachement; this.instalment.SP_Date = new Date(res.SP_Date); this.getAccount(' ', 'CaB'); this.getAccount(this.instalment.FK_From_Account.Name, 'A'); this.maxDate = new Date(res.SP_Date); this.maxDate.setHours(this.maxDate.getHours() + 2); } }, err => { this._notificationService.notify('danger', err.msg); }); } public getAccount(x: string, event: string) { this._storeService.getAccountBySearch(x, event).subscribe((res: any) => { if (res) { if (event == 'CaB') { this.accountList = res; } else { this.allAccountList = res; } } }, err => { this._notificationService.notify('danger', err.msg); }); } }