import { AfterViewInit , ChangeDetectorRef , Component , Input , OnInit } from '@angular/core' ; import { IAmountOwedReport , IGetTimeLogReportInput , ITimeLogFilters , ReportGroupByFilter , ReportGroupFilterEnum } from '@gauzy/contracts' ; import { UntilDestroy , untilDestroyed } from '@ngneat/until-destroy' ; import { debounceTime , tap } from 'rxjs/operators' ; import { Store } from '../../../@core/services/store.service' ; import { TimesheetService } from '../../timesheet/timesheet.service' ; import { TranslateService } from '@ngx-translate/core' ; import { ReportBaseComponent } from '../report-base/report-base.component' ; @ UntilDestroy ( ) @ Component ( { selector : 'ga-amounts-owed-grid' , templateUrl : './amounts-owed-grid.component.html' , styleUrls : [ './amounts-owed-grid.component.scss' ] } ) export class AmountsOwedGridComponent extends ReportBaseComponent implements OnInit , AfterViewInit { logRequest : ITimeLogFilters = this . request ; loading : boolean ; groupBy : ReportGroupByFilter = ReportGroupFilterEnum . date ; dailyData : IAmountOwedReport [ ] ; @ Input ( ) set filters ( value ) { this . logRequest = value || { } ; this . subject$ . next ( true ) ; } constructor ( private readonly timesheetService , protected readonly store , private readonly cd , public readonly translateService ) { super ( store , translateService ) ; } ngOnInit ( ) { this . subject$ . pipe ( debounceTime ( 300 ) , tap ( ( ) => this . loading = true ) , tap ( ( ) => this . getExpenses ( ) ) , untilDestroyed ( this ) ) . subscribe ( ) ; } ngAfterViewInit ( ) { this . cd . detectChanges ( ) ; } filtersChange ( $event ) { this . logRequest = $event ; this . filters = Object . assign ( { } , this . logRequest ) ; this . subject$ . next ( true ) ; } groupByChange ( ) { this . subject$ . next ( true ) ; } getExpenses ( ) { if ( ! this . organization || ! this . logRequest ) { return ; } const request = { ... this . getFilterRequest ( this . logRequest ) , groupBy : this . groupBy } ; this . timesheetService . getOwedAmountReport ( request ) . then ( ( logs ) => { this . dailyData = logs ; } ) . catch ( ( ) => { } ) . finally ( ( ) => ( this . loading = false ) ) ; } }