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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
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\Enums\EntryBillingModel;
|
||||
use App\Modules\TimeTracking\Domain\Exceptions\TimeApproved;
|
||||
use App\Modules\TimeTracking\Domain\Exceptions\TimeEntryNotFound;
|
||||
|
||||
/**
|
||||
* "Muokkaa kirjausta" on the time sheet: the laskutusperuste, billing note
|
||||
* and internal comment of the user's entry on a task and day.
|
||||
*/
|
||||
final class DescribeTimeEntry
|
||||
{
|
||||
public function __construct(
|
||||
private TimeEntryRepository $entries,
|
||||
private TransactionManager $transactions,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws TimeEntryNotFound
|
||||
* @throws TimeApproved
|
||||
*/
|
||||
public function execute(int $userId, int $taskId, string $day, ?EntryBillingModel $billingModel, ?string $billingNote, ?string $internalComment): void
|
||||
{
|
||||
$date = TimeBooking::day($day);
|
||||
|
||||
$this->transactions->run(function () use ($userId, $taskId, $date, $billingModel, $billingNote, $internalComment): void {
|
||||
$entry = $this->entries->findForDay($userId, $taskId, $date) ?? throw new TimeEntryNotFound(0);
|
||||
|
||||
$entry->describe($billingModel, $billingNote, $internalComment);
|
||||
$this->entries->save($entry);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\TimeTracking\Application\UseCases;
|
||||
|
||||
use App\Modules\Jobs\Application\Contracts\TaskQueries;
|
||||
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||
use App\Modules\TimeTracking\Domain\Contracts\PinnedTaskRepository;
|
||||
use App\Modules\TimeTracking\Domain\Exceptions\TaskNotBookable;
|
||||
use App\Modules\TimeTracking\Domain\Exceptions\TimeLocked;
|
||||
use App\Modules\Users\Application\Contracts\Clock;
|
||||
|
||||
/**
|
||||
* Pins tasks to the "Lukitut työt" part of a user's time sheet (★), or
|
||||
* unpins them. Only tasks that can take hours (open task of an unlocked
|
||||
* job) can be pinned; unpinning always works.
|
||||
*/
|
||||
final class PinTimesheetTasks
|
||||
{
|
||||
public function __construct(
|
||||
private PinnedTaskRepository $pins,
|
||||
private TaskQueries $tasks,
|
||||
private TransactionManager $transactions,
|
||||
private Clock $clock,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param list<int> $taskIds
|
||||
*
|
||||
* @throws TaskNotBookable
|
||||
* @throws TimeLocked
|
||||
*/
|
||||
public function pin(int $userId, array $taskIds): void
|
||||
{
|
||||
$now = $this->clock->now();
|
||||
|
||||
$this->transactions->run(function () use ($userId, $taskIds, $now): void {
|
||||
foreach ($taskIds as $taskId) {
|
||||
$task = $this->tasks->bookableTask($taskId) ?? throw new TaskNotBookable($taskId);
|
||||
|
||||
if ($task->isLocked()) {
|
||||
throw new TimeLocked;
|
||||
}
|
||||
|
||||
$this->pins->pin($userId, $taskId, $now);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function unpin(int $userId, int $taskId): void
|
||||
{
|
||||
$this->transactions->run(fn () => $this->pins->unpin($userId, $taskId));
|
||||
}
|
||||
|
||||
/**
|
||||
* "Poista kaikki kiinnitykset".
|
||||
*/
|
||||
public function unpinAll(int $userId): int
|
||||
{
|
||||
return $this->transactions->run(fn (): int => $this->pins->unpinAll($userId));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user