Kanban / timesheet update
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\TimeTracking\Application\DTOs;
|
||||
|
||||
/**
|
||||
* One user's time sheet for a week (docs/ui-timesheet.md 4): the
|
||||
* "Aikataulutettu" part (tasks scheduled for the week and tasks with hours
|
||||
* that are not pinned) and the "Lukitut työt" part (pinned tasks that can
|
||||
* still take hours, or have hours this week), both grouped customer A–Ö →
|
||||
* job → task.
|
||||
*/
|
||||
final readonly class TimesheetWeek
|
||||
{
|
||||
/**
|
||||
* @param list<string> $days Y-m-d, Monday to Sunday
|
||||
* @param list<TimesheetCustomerGroup> $scheduled
|
||||
* @param list<TimesheetCustomerGroup> $pinned
|
||||
* @param array<string, int> $dayTotals
|
||||
* @param list<MissingBillingNote> $missingNotes
|
||||
*/
|
||||
public function __construct(
|
||||
public array $days,
|
||||
public array $scheduled,
|
||||
public array $pinned,
|
||||
public array $dayTotals,
|
||||
public int $totalQuarters,
|
||||
public int $unapprovedQuarters,
|
||||
public ?WeekApproval $lastApproval,
|
||||
public array $missingNotes,
|
||||
) {}
|
||||
|
||||
public function isApproved(): bool
|
||||
{
|
||||
return $this->totalQuarters > 0 && $this->unapprovedQuarters === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<TimesheetTaskRow>
|
||||
*/
|
||||
public function rows(): array
|
||||
{
|
||||
$rows = [];
|
||||
|
||||
foreach ([...$this->scheduled, ...$this->pinned] as $customer) {
|
||||
foreach ($customer->jobs as $job) {
|
||||
foreach ($job->rows as $row) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public function row(int $taskId): ?TimesheetTaskRow
|
||||
{
|
||||
foreach ($this->rows() as $row) {
|
||||
if ($row->task->taskId === $taskId) {
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function scheduledTaskCount(): int
|
||||
{
|
||||
return array_sum(array_map(fn (TimesheetCustomerGroup $customer): int => $customer->taskCount(), $this->scheduled));
|
||||
}
|
||||
|
||||
public function pinnedTaskCount(): int
|
||||
{
|
||||
return array_sum(array_map(fn (TimesheetCustomerGroup $customer): int => $customer->taskCount(), $this->pinned));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user