Kanban / timesheet update
This commit is contained in:
@@ -7,6 +7,7 @@ namespace App\Modules\TimeTracking\Application\UseCases;
|
||||
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||
use App\Modules\TimeTracking\Application\Services\TimeBooking;
|
||||
use App\Modules\TimeTracking\Domain\Contracts\TimeEntryRepository;
|
||||
use App\Modules\TimeTracking\Domain\Exceptions\BillingNotesMissing;
|
||||
use App\Modules\Users\Application\Contracts\Clock;
|
||||
|
||||
/**
|
||||
@@ -24,6 +25,8 @@ final class ApproveWeek
|
||||
/**
|
||||
* @param string $monday Y-m-d of the week's Monday.
|
||||
* @return int How many entries were approved now.
|
||||
*
|
||||
* @throws BillingNotesMissing when an unapproved entry has no billing note
|
||||
*/
|
||||
public function execute(int $userId, string $monday, int $approverId): int
|
||||
{
|
||||
@@ -32,8 +35,20 @@ final class ApproveWeek
|
||||
|
||||
return $this->transactions->run(function () use ($userId, $start, $approverId, $now): int {
|
||||
$approved = 0;
|
||||
$entries = $this->entries->forUserBetween($userId, $start, $start->modify('+6 days'));
|
||||
$missing = [];
|
||||
|
||||
foreach ($this->entries->forUserBetween($userId, $start, $start->modify('+6 days')) as $entry) {
|
||||
foreach ($entries as $entry) {
|
||||
if (! $entry->isApproved() && ! $entry->hasBillingNote()) {
|
||||
$missing[] = (int) $entry->id();
|
||||
}
|
||||
}
|
||||
|
||||
if ($missing !== []) {
|
||||
throw new BillingNotesMissing($missing);
|
||||
}
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
if ($entry->isApproved()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user