Skip to content

Commit 28ff3a6

Browse files
authored
Merge pull request #32 from eporsche/working_hours_bugfix
small bugfix for working hour calc
2 parents 07517c6 + bf17a70 commit 28ff3a6

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

app/Actions/RemoveTimeTracking.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function remove(User $user, Location $location, int $removeTimeTrackingFo
1313
{
1414
tap($location->timeTrackings()->whereKey($timeTrackingId)->first(), function ($timeTracking) use ($user, $location) {
1515

16-
Gate::forUser($user)->authorize('removeAbsence', [
16+
Gate::forUser($user)->authorize('removeTimeTracking', [
1717
TimeTracking::class,
1818
$timeTracking,
1919
$location

app/Traits/HasEvaluation.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
namespace App\Traits;
44

55
use App\Models\TargetHour;
6+
use App\Models\TimeTracking;
7+
use Brick\Math\BigDecimal;
68

79
trait HasEvaluation
810
{
911
public function workingHoursForDate($date)
1012
{
1113
$working_hours = $this->timeTrackings()
1214
->whereDate('starts_at',$date)
13-
->first();
15+
->get();
1416

15-
return optional($working_hours)->balance;
17+
return $working_hours->reduce(function (BigDecimal $total, TimeTracking $timeTracking) {
18+
return $total->plus($timeTracking->balance);
19+
}, BigDecimal::zero());
1620
}
1721

1822
public function absentHoursForDate($date)

resources/views/time_trackings/time-tracking-manager.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
:hours="$hours"
147147
:minutes="$minutes"
148148
:user="$this->user"
149+
:managingTimeTrackingForId="$managingTimeTrackingForId"
149150
:employeeSimpleSelectOptions="$employeeSimpleSelectOptions"
150151
:pauseTimeForm="$pauseTimeForm"
151152
:timeTrackingIdBeingUpdated="$timeTrackingIdBeingUpdated"

tests/Feature/AbsenceTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use App\Models\AbsenceType;
1111
use App\Contracts\AddsAbsences;
1212
use App\Contracts\ApprovesAbsence;
13+
use Illuminate\Support\Facades\Bus;
1314
use App\Contracts\AddsVacationEntitlements;
1415
use App\Http\Livewire\Absence\AbsenceManager;
1516

@@ -268,6 +269,8 @@ public function test_can_approve_two_week_vacation()
268269
'status' => 'pending'
269270
]);
270271

272+
Bus::fake();
273+
271274
$action = app(ApprovesAbsence::class);
272275

273276
$action->approve(

0 commit comments

Comments
 (0)