Skip to content

Commit

Permalink
Merge pull request #3 from eporsche/bugfix
Browse files Browse the repository at this point in the history
Fixed a bug where absence approval used wrong employee
  • Loading branch information
eporsche committed May 1, 2021
2 parents b1d28f1 + 280a4ab commit 625cae6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
20 changes: 10 additions & 10 deletions app/Actions/ApproveAbscence.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@ public function approve(User $user, Location $location, $absenceId)

$absence = Absence::findOrFail($absenceId);

DB::transaction(function () use ($absence, $user, $location) {
$this->bookVacationDays($absence, $user);
$this->createAbsenceIndex($absence, $user, $location);
DB::transaction(function () use ($absence, $location) {
$this->bookVacationDays($absence);
$this->createAbsenceIndex($absence, $location);
$absence->markAsConfirmed();
if (Daybreak::hasCaldavFeature()) {
CreateCaldavEvent::dispatch($absence, $user)
CreateCaldavEvent::dispatch($absence)
->afterCommit();
}
SendAbsenceApproved::dispatch($user, $absence)->afterCommit();
SendAbsenceApproved::dispatch($absence)->afterCommit();
});
}

public function bookVacationDays($absence, $user)
public function bookVacationDays($absence)
{
if (!$absence->absenceType->affectsVacation()) {
return;
}

//TODO: distribute absence days between available vacation entitlements
$currentVacationEntitlement = $user->currentVacationEntitlement();
$currentVacationEntitlement = $absence->employee->currentVacationEntitlement();
if (!isset($currentVacationEntitlement) || !$currentVacationEntitlement->hasEnoughUnusedVacationDays($absence->vacation_days)) {
throw ValidationException::withMessages([
'error' => [__('Sorry, there is no fitting vacation entitlement for this absence.')],
Expand All @@ -66,14 +66,14 @@ public function bookVacationDays($absence, $user)
$currentVacationEntitlement->useVacationDays($absence);
}

public function createAbsenceIndex($absence, $user, $location)
public function createAbsenceIndex($absence, $location)
{
if (!$absence->absenceType->affectsEvaluation()) {
return;
}

$calendar = (new EmployeeAbsenceCalendar(
$user,
$absence->employee,
$location,
new CarbonPeriod(
$absence->starts_at,
Expand Down Expand Up @@ -103,7 +103,7 @@ public function createAbsenceIndex($absence, $user, $location)
'date' => $day->getDate(),
'hours' => $day->getPaidHours(),
'absence_type_id' => $absence->absence_type_id,
'user_id' => $user->id,
'user_id' => $absence->employee->id,
'location_id' => $location->id
]);
}
Expand Down
9 changes: 3 additions & 6 deletions app/Jobs/SendAbsenceApproved.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ class SendAbsenceApproved implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

protected $user;

protected $absence;

public function __construct(User $user, Absence $absence)
public function __construct(Absence $absence)
{
$this->user = $user;
$this->absence = $absence;
}

Expand All @@ -35,9 +32,9 @@ public function handle()
{
$users = User::all()->filter
->hasLocationRole($this->absence->location, 'admin')
->merge(collect([$this->user]));
->merge(collect([$this->absence->employee]));

Mail::to($users)
->send(new AbsenceStatusApproved($this->user, $this->absence));
->send(new AbsenceStatusApproved($this->absence->employee, $this->absence));
}
}

0 comments on commit 625cae6

Please sign in to comment.