import { Component, OnInit } from '@angular/core'; import { KGridHelper } from '../../../_helpers/k-grid.class'; import { Subject, Subscription } from 'rxjs'; import { DataStateChangeEvent } from '@progress/kendo-angular-grid'; import { IncomeStatementViewModel } from '../income-statement-report/income-statement-report.component'; import { AccountService } from '../../accounts/accounts-services'; import { NotificationService } from '../../../_services/notification.service'; import { ReportingService } from '../reporting.service'; import { AuthenticationService } from '../../../_services/authentication.service'; import { LocalService } from '../../../_services/local.service'; @Component({ selector: 'app-balance-sheet', templateUrl: './balance-sheet.component.html', }) export class BalanceSheetComponent implements OnInit { public kGrid: KGridHelper = new KGridHelper(); public FromDate = null; public ToDate: Date = null; public _incomeStatement: IncomeStatementViewModel[]; public loading = false; public geting = false; public searchEvent = new Subject(); public searchSubcription: Subscription = null; public selectedAccount: any; state: DataStateChangeEvent; public GrossIncome = 0; public GrossRevneu = 0; public GrossEarnings = 0; public EquityAndCap = 0; public Liabilities = 0; public isIncomeHidden = false; constructor(public _accountService: AccountService, public _notificationService: NotificationService, public _reportingServices: ReportingService, public _authenticationService: AuthenticationService, private _localService: LocalService ) { } ngOnInit() { } getReport() { this.getBalanceSheet(); } getBalanceSheet() { this.loading = true; this.geting = true; this._reportingServices .getBalanceSheet({ ToDate: new Date(this.ToDate) }) .subscribe((res: IncomeStatementViewModel[]) => { console.log(res); this._incomeStatement = []; this._incomeStatement = res; this.EquityAndCap = res[2].Total; this.Liabilities = res[1].Total; this.loading = false; this.geting = false; }, (err) => { console.log(err); }); let todate = this.ToDate; let formdate = new Date(); formdate.setFullYear(this.ToDate.getFullYear() - 30); this._reportingServices .getIncomeStatement({ FromDate: formdate, ToDate: new Date(todate) }) .subscribe((res: IncomeStatementViewModel[]) => { console.log(res); // this._incomeStatement = []; // this._incomeStatement = res; this.GrossRevneu = res[0].Total; this.GrossEarnings = res[1].Total; this.GrossIncome = this.BePositiveNigga(this.GrossRevneu) - this.BePositiveNigga(this.GrossEarnings); let interval = setInterval((e) => { if (this._incomeStatement[2] !== undefined) { this._incomeStatement[2].Total += this.GrossIncome; this.EquityAndCap += this.GrossIncome; clearInterval(interval); } }, 2000); // this.loading = false; // this.geting = false; }, (err) => { console.log(err); }); } public ClearFilter() { this.kGrid.fromDate = null; this.kGrid.toDate = null; } BePositiveNigga(num) { return Math.abs(num); } }