Kanban / timesheet update
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\TimeTracking\Application\DTOs;
|
||||
|
||||
/**
|
||||
* An unapproved entry of the week without a billing note.
|
||||
*/
|
||||
final readonly class MissingBillingNote
|
||||
{
|
||||
public function __construct(
|
||||
public int $taskId,
|
||||
public string $day,
|
||||
public int $quarters,
|
||||
public string $customerName,
|
||||
public string $jobNumber,
|
||||
public string $taskTitle,
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\TimeTracking\Application\DTOs;
|
||||
|
||||
/**
|
||||
* A user's hours in a month: in all, billable or within a fixed price, and
|
||||
* internal (not billable), by each entry's laskutusperuste.
|
||||
*/
|
||||
final readonly class MonthSummary
|
||||
{
|
||||
public function __construct(
|
||||
public string $month,
|
||||
public int $totalQuarters,
|
||||
public int $billableQuarters,
|
||||
public int $internalQuarters,
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\TimeTracking\Application\DTOs;
|
||||
|
||||
use App\Modules\TimeTracking\Domain\Enums\EntryBillingModel;
|
||||
|
||||
/**
|
||||
* The user's entry on one task and day of the time sheet.
|
||||
*/
|
||||
final readonly class TimesheetCell
|
||||
{
|
||||
public function __construct(
|
||||
public int $quarters,
|
||||
public ?string $billingNote,
|
||||
public ?string $internalComment,
|
||||
public ?EntryBillingModel $billingModel,
|
||||
public bool $approved,
|
||||
) {}
|
||||
|
||||
public function hasBillingNote(): bool
|
||||
{
|
||||
return $this->billingNote !== null && trim($this->billingNote) !== '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\TimeTracking\Application\DTOs;
|
||||
|
||||
/**
|
||||
* A customer on the time sheet (level 1), in its own colour, with its jobs.
|
||||
*/
|
||||
final readonly class TimesheetCustomerGroup
|
||||
{
|
||||
/**
|
||||
* @param list<TimesheetJobGroup> $jobs
|
||||
*/
|
||||
public function __construct(
|
||||
public int $customerId,
|
||||
public string $name,
|
||||
public ?string $headerColor,
|
||||
public array $jobs,
|
||||
) {}
|
||||
|
||||
public function taskCount(): int
|
||||
{
|
||||
return array_sum(array_map(fn (TimesheetJobGroup $job): int => count($job->rows), $this->jobs));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\TimeTracking\Application\DTOs;
|
||||
|
||||
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||||
use App\Modules\TimeTracking\Domain\Enums\EntryBillingModel;
|
||||
|
||||
/**
|
||||
* A customer job on the time sheet (level 2) with its task rows.
|
||||
*/
|
||||
final readonly class TimesheetJobGroup
|
||||
{
|
||||
/**
|
||||
* @param list<TimesheetTaskRow> $rows
|
||||
*/
|
||||
public function __construct(
|
||||
public int $jobId,
|
||||
public string $number,
|
||||
public string $name,
|
||||
public JobStatus $status,
|
||||
public ?string $paymentBasis,
|
||||
public int $accumulatedQuarters,
|
||||
public array $rows,
|
||||
) {}
|
||||
|
||||
public function billingModel(): EntryBillingModel
|
||||
{
|
||||
return EntryBillingModel::forPaymentBasis($this->paymentBasis);
|
||||
}
|
||||
|
||||
public function isContinuing(): bool
|
||||
{
|
||||
return $this->status === JobStatus::Ongoing;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\TimeTracking\Application\DTOs;
|
||||
|
||||
use App\Modules\Jobs\Application\DTOs\BookableTask;
|
||||
use App\Modules\TimeTracking\Domain\Enums\EntryBillingModel;
|
||||
|
||||
/**
|
||||
* A task row of the time sheet (level 3): its entries by day.
|
||||
*/
|
||||
final readonly class TimesheetTaskRow
|
||||
{
|
||||
/**
|
||||
* @param array<string, TimesheetCell> $cells by Y-m-d
|
||||
*/
|
||||
public function __construct(
|
||||
public BookableTask $task,
|
||||
public array $cells,
|
||||
public int $totalQuarters,
|
||||
public bool $pinned,
|
||||
) {}
|
||||
|
||||
public function cell(string $day): ?TimesheetCell
|
||||
{
|
||||
return $this->cells[$day] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The laskutusperuste new entries get: from the job's payment basis.
|
||||
*/
|
||||
public function defaultBillingModel(): EntryBillingModel
|
||||
{
|
||||
return EntryBillingModel::forPaymentBasis($this->task->paymentBasis);
|
||||
}
|
||||
}
|
||||
@@ -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