Skip to content

Commit bf0c77c

Browse files
authored
Merge pull request #33 from eporsche/future_vacation_entitlements_bugfix
ablity to approve future vacation entitlements
2 parents 28ff3a6 + 6b3fa3b commit bf0c77c

File tree

3 files changed

+66
-13
lines changed

3 files changed

+66
-13
lines changed

app/Models/VacationEntitlement.php

+5
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ public function isTransferred()
188188
return $this->transferVacationDays()->exists();
189189
}
190190

191+
public function scopeNotExpired($query)
192+
{
193+
return $query->whereNotIn('status', ['expired']);
194+
}
195+
191196
public function scopeNotUsed($query)
192197
{
193198
return $query->whereNotIn('status', ['used']);

app/Traits/HasVacations.php

+6-13
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,19 @@ public function vacationEntitlements()
2020

2121
public function availableVacationEntitlements()
2222
{
23-
return $this->vacationEntitlements()->notUsed();
23+
return $this->vacationEntitlements()
24+
->notUsed()
25+
->notExpired();
2426
}
2527

2628
public function currentVacationEntitlement()
2729
{
2830
$today = now()->startOfDay();
29-
$available = $this->availableVacationEntitlements()
30-
->where('starts_at','<=',$today)
31+
return $this->availableVacationEntitlements()
3132
->where('ends_at','>=',$today)
3233
->orderBy('ends_at','ASC')
33-
->get();
34-
35-
$feasibleEntitlements = $available->filter(function (VacationEntitlement $entitlement) {
36-
if(!$entitlement->isExpired() && !$entitlement->isUsed()) {
37-
return $entitlement;
38-
}
39-
});
40-
41-
return $feasibleEntitlements->first();
42-
34+
->get()
35+
->first();
4336
}
4437

4538
public function latestVacationEntitlement()

tests/Feature/EvaluationTest.php

+55
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,61 @@ public function test_can_use_vacation_entitlement()
199199
]);
200200
}
201201

202+
public function test_can_submit_future_vacation_entitlement()
203+
{
204+
$this->travelTo(Carbon::parse('2021-01-01'));
205+
206+
$absenceType = AbsenceType::forceCreate([
207+
'location_id' => $this->location->id,
208+
'title' => 'Urlaub',
209+
'affect_vacation_times' => true,
210+
'affect_evaluations' => true,
211+
'evaluation_calculation_setting' => 'absent_to_target'
212+
]);
213+
214+
$this->user->absenceTypes()->sync($absenceType);
215+
216+
/**
217+
* @var AddsVacationEntitlements
218+
*/
219+
$action = app(AddsVacationEntitlements::class);
220+
$action->add($this->user, [
221+
'name' => "yearly allowance",
222+
'starts_at' => "01.01.2022",
223+
'ends_at' => "31.12.2022",
224+
'days' => 10,
225+
'expires' => false,
226+
'transfer_remaining' => false
227+
]);
228+
229+
/**
230+
* @var AddsAbsences
231+
*/
232+
$action = app(AddsAbsences::class);
233+
234+
$action->add($this->user, $this->location, $this->user->id, [
235+
'absence_type_id' => $absenceType->id,
236+
'starts_at' => '29.11.2022 00:00',
237+
'ends_at' => '30.11.2022 00:00',
238+
'full_day' => true,
239+
'status' => 'confirmed'
240+
]);
241+
242+
Bus::fake();
243+
244+
/**
245+
* @var ApprovesAbsence
246+
*/
247+
$approver = app(ApprovesAbsence::class);
248+
249+
$approver->approve(
250+
$this->user,
251+
$this->location,
252+
Absence::first()->id
253+
);
254+
255+
}
256+
202257
public function test_can_submit_vacation()
203258
{
204259
$absenceType = AbsenceType::forceCreate([

0 commit comments

Comments
 (0)