import { Injectable } from '@angular/core' ; import { HttpClient , HttpParams } from '@angular/common/http' ; import { ITimeLog , IGetTimeLogInput , IManualTimeInput , TimesheetStatus , ITimesheet , IGetTimesheetInput , IGetTimeLogConflictInput , IGetTimeSlotInput , ITimeSlot , IGetTimeLogReportInput , IAmountOwedReport , IGetTimeLimitReportInput , ITimeLimitReport , IClientBudgetLimitReport , IProjectBudgetLimitReport , IProjectBudgetLimitReportInput , IClientBudgetLimitReportInput } from '@gauzy/contracts' ; import { toParams } from '@gauzy/common-angular' ; import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject' ; import { Observable , firstValueFrom } from 'rxjs' ; import { API_PREFIX } from '../../@core/constants/app.constants' ; @ Injectable ( { providedIn : 'root' } ) export class TimesheetService { interval : any ; private _updateLog$ : BehaviorSubject < boolean > = new BehaviorSubject ( false ) ; public updateLog$ : Observable < boolean > = this . _updateLog$ . asObservable ( ) ; constructor ( private http ) { } updateLogs ( value ) { this . _updateLog$ . next ( value ) ; } addTime ( request ) { return firstValueFrom ( this . http . post < ITimeLog > ( `${ API_PREFIX }/timesheet/time-log` , request ) ) ; } updateTime ( id , request ) { return firstValueFrom ( this . http . put < ITimeLog > ( `${ API_PREFIX }/timesheet/time-log/` + id , request ) ) ; } checkOverlaps ( request ) { return firstValueFrom ( this . http . get < ITimeLog [ ] > ( `${ API_PREFIX }/timesheet/time-log/conflict` , { params : toParams ( request ) } ) ) ; } getTimeSheet ( id ) { return firstValueFrom ( this . http . get ( `${ API_PREFIX }/timesheet/` + id ) ) . then ( ( data ) => { return data ; } ) ; } getTimeSheets ( request ? ) { return firstValueFrom ( this . http . get ( `${ API_PREFIX }/timesheet` , { params : toParams ( request ) } ) ) . then ( ( data ) => { return data ; } ) ; } getTimeSheetCount ( request ? ) { return firstValueFrom ( this . http . get ( `${ API_PREFIX }/timesheet/count` , { params : toParams ( request ) } ) ) . then ( ( data ) => { return data ; } ) ; } updateStatus ( ids , status ) { return firstValueFrom ( this . http . put ( `${ API_PREFIX }/timesheet/status` , { ids , status } ) ) . then ( ( data ) => { return data ; } ) ; } submitTimesheet ( ids , status ) { return firstValueFrom ( this . http . put ( `${ API_PREFIX }/timesheet/submit` , { ids , status } ) ) . then ( ( data ) => { return data ; } ) ; } getTimeLogs ( request ? ) { const params = toParams ( request ) ; return firstValueFrom ( this . http . get < ITimeLog [ ] > ( `${ API_PREFIX }/timesheet/time-log` , { params } ) ) ; } getDailyReport ( request ? ) { const params = toParams ( request ) ; return firstValueFrom ( this . http . get ( `${ API_PREFIX }/timesheet/time-log/report/daily` , { params } ) ) ; } getOwedAmountReport ( request ? ) { const params = toParams ( request ) ; return firstValueFrom ( this . http . get < IAmountOwedReport [ ] > ( `${ API_PREFIX }/timesheet/time-log/report/owed-report` , { params } ) ) ; } getOwedAmountReportChartData ( request ? ) { const params = toParams ( request ) ; return firstValueFrom ( this . http . get ( `${ API_PREFIX }/timesheet/time-log/report/owed-chart-data` , { params } ) ) ; } getDailyReportChart ( request ) { const params = toParams ( request ) ; return firstValueFrom ( this . http . get ( `${ API_PREFIX }/timesheet/time-log/report/daily-chart` , { params } ) ) ; } getWeeklyReportChart ( request ? ) { const params = toParams ( request ) ; return firstValueFrom ( this . http . get ( `${ API_PREFIX }/timesheet/time-log/report/weekly` , { params } ) ) ; } getTimeLimit ( request ) { return firstValueFrom ( this . http . get < ITimeLimitReport [ ] > ( `${ API_PREFIX }/timesheet/time-log/time-limit` , { params : toParams ( request ) } ) ) ; } getProjectBudgetLimit ( request ) { return firstValueFrom ( this . http . get < IProjectBudgetLimitReport [ ] > ( `${ API_PREFIX }/timesheet/time-log/project-budget-limit` , { params : toParams ( request ) } ) ) ; } getClientBudgetLimit ( request ) { return firstValueFrom ( this . http . get < IClientBudgetLimitReport [ ] > ( `${ API_PREFIX }/timesheet/time-log/client-budget-limit` , { params : toParams ( request ) } ) ) ; } getTimeLog ( id , findOptions ) { const params = toParams ( findOptions ) ; return firstValueFrom ( this . http . get ( `${ API_PREFIX }/timesheet/time-log/${ id }` , { params } ) ) . then ( ( data ) => { return data ; } ) ; } getTimeSlot ( id , request ? ) { const params = toParams ( request ) ; return firstValueFrom ( this . http . get < ITimeSlot > ( `${ API_PREFIX }/timesheet/time-slot/${ id }` , { params } ) ) ; } getTimeSlots ( request ? ) { const params = toParams ( request ) ; return firstValueFrom ( this . http . get < ITimeSlot [ ] > ( `${ API_PREFIX }/timesheet/time-slot` , { params } ) ) ; } deleteTimeSlots ( ids ? ) { const params = toParams ( { ids } ) ; return firstValueFrom ( this . http . delete ( `${ API_PREFIX }/timesheet/time-slot` , { params } ) ) ; } deleteLogs ( logIds ) { let payload = new HttpParams ( ) ; if ( typeof logIds === 'string' ) { logIds = [ logIds ] ; } logIds . forEach ( ( id ) => { payload = payload . append ( `logIds[]` , id ) ; } ) ; return firstValueFrom ( this . http . delete ( `${ API_PREFIX }/timesheet/time-log` , { params : payload } ) ) ; } }