@@ -9,6 +9,7 @@ import { Entry } from 'src/app/modules/shared/models';
99import { DataSource } from 'src/app/modules/shared/models/data-source.model' ;
1010import { EntryState } from '../../../time-clock/store/entry.reducer' ;
1111import { getReportDataSource } from '../../../time-clock/store/entry.selectors' ;
12+ import { TotalHours } from '../../models/total-hours-report' ;
1213import { User } from 'src/app/modules/users/models/users' ;
1314import { LoadUsers , UserActionTypes } from 'src/app/modules/users/store/user.actions' ;
1415import { ParseDateTimeOffset } from '../../../shared/formatters/parse-date-time-offset/parse-date-time-offset' ;
@@ -67,6 +68,7 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
6768 isLoading$ : Observable < boolean > ;
6869 reportDataSource$ : Observable < DataSource < Entry > > ;
6970 rerenderTableSubscription : Subscription ;
71+ resultSum : TotalHours ;
7072 dateTimeOffset : ParseDateTimeOffset ;
7173
7274 constructor ( private store : Store < EntryState > , private actionsSubject$ : ActionsSubject , private storeUser : Store < User > ) {
@@ -85,6 +87,7 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
8587
8688 ngOnInit ( ) : void {
8789 this . rerenderTableSubscription = this . reportDataSource$ . subscribe ( ( ds ) => {
90+ this . sumDates ( ds . data ) ;
8891 this . rerenderDataTable ( ) ;
8992 } ) ;
9093 this . uploadUsers ( ) ;
@@ -124,6 +127,26 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
124127 const durationColumnIndex = 3 ;
125128 return column === durationColumnIndex ? moment . duration ( dataFormated ) . asHours ( ) . toFixed ( 2 ) : dataFormated ;
126129 }
130+
131+ sumDates ( arrayData : Entry [ ] ) : TotalHours {
132+ this . resultSum = new TotalHours ( ) ;
133+ let arrayDurations = new Array ( ) ;
134+ arrayData . forEach ( entry => {
135+ let start = moment ( entry . end_date ) . diff ( moment ( entry . start_date ) ) ;
136+ arrayDurations . push ( moment . utc ( start ) . format ( "HH:mm:ss" ) ) ;
137+ } ) ;
138+
139+ let totalDurations = arrayDurations . slice ( 1 )
140+ . reduce ( ( prev , cur ) => {
141+ return prev . add ( cur ) ;
142+ } ,
143+ moment . duration ( arrayDurations [ 0 ] ) ) ;
144+ let daysInHours = totalDurations . days ( ) * 24 ;
145+ this . resultSum . hours = totalDurations . hours ( ) + daysInHours ;
146+ this . resultSum . minutes = totalDurations . minutes ( ) ;
147+ this . resultSum . seconds = totalDurations . seconds ( ) ;
148+ return this . resultSum ;
149+ }
127150
128151 user ( userId : string ) {
129152 this . selectedUserId . emit ( userId ) ;
0 commit comments