Add machines with day-by-day work lists for job tasks

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-26 16:43:55 +02:00
co-authored by Claude Sonnet 5.5
parent 0de0e332b2
commit aac579257a
59 changed files with 3803 additions and 1 deletions
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace App\Modules\Machines\Domain\Services;
/**
* Where a task goes in a day's work list by default (spec 19.4): after
* quick sale orders, then by priority (higher first) and due date (earlier
* first, none last). Rows moved by hand keep their places; a new task
* goes before the first task it outranks.
*/
final class QueueOrder
{
/**
* @param list<array{isOrder: bool, rank: int, dueOn: ?string}> $rows The day's open rows in order.
* @return int The index to insert the new task at.
*/
public static function insertionIndex(array $rows, int $rank, ?string $dueOn): int
{
foreach ($rows as $index => $row) {
if ($row['isOrder']) {
continue;
}
if (self::before($rank, $dueOn, $row['rank'], $row['dueOn'])) {
return $index;
}
}
return count($rows);
}
private static function before(int $rank, ?string $dueOn, int $otherRank, ?string $otherDueOn): bool
{
if ($rank !== $otherRank) {
return $rank > $otherRank;
}
if ($dueOn === null) {
return false;
}
return $otherDueOn === null || $dueOn < $otherDueOn;
}
}