Track machine counters and maintenance with counter and time intervals
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -5,8 +5,8 @@ declare(strict_types=1);
|
||||
namespace App\Modules\Dashboard\Application\Contracts;
|
||||
|
||||
/**
|
||||
* What the management panel needs from Billing, Sales, Users and the
|
||||
* holiday calendar. Days are Y-m-d.
|
||||
* What the management panel needs from Billing, Sales, Users, Machines,
|
||||
* Inventory and the holiday calendar. Days are Y-m-d.
|
||||
*/
|
||||
interface DashboardAdmin
|
||||
{
|
||||
@@ -35,4 +35,16 @@ interface DashboardAdmin
|
||||
* @return list<string>
|
||||
*/
|
||||
public function holidaysBetween(string $from, string $to): array;
|
||||
|
||||
/**
|
||||
* Machine maintenance that is late (maintenance requests), by machine.
|
||||
*
|
||||
* @return list<array{machineId: int, machine: string, item: string}>
|
||||
*/
|
||||
public function lateMaintenance(): array;
|
||||
|
||||
/**
|
||||
* How many stock items are at or below their reorder level.
|
||||
*/
|
||||
public function stockItemsToOrder(): int;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ final readonly class ManagementOverview
|
||||
* @param array<string, int> $jobCounts
|
||||
* @param list<WorkTask> $oldestOverdueTasks
|
||||
* @param list<PersonLoad> $workloads
|
||||
* @param list<array{machineId: int, machine: string, item: string}> $lateMaintenance
|
||||
*/
|
||||
public function __construct(
|
||||
public array $pendingApprovals,
|
||||
@@ -42,5 +43,7 @@ final readonly class ManagementOverview
|
||||
public string $thisMonday,
|
||||
public string $nextMonday,
|
||||
public array $workloads,
|
||||
public array $lateMaintenance = [],
|
||||
public int $stockItemsToOrder = 0,
|
||||
) {}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,8 @@ final readonly class ManagementOverviewQuery
|
||||
$thisMonday->format('Y-m-d'),
|
||||
$nextMonday->format('Y-m-d'),
|
||||
$this->workloads($thisMonday, $nextMonday),
|
||||
$this->admin->lateMaintenance(),
|
||||
$this->admin->stockItemsToOrder(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,14 +5,18 @@ namespace App\Modules\Dashboard\Infrastructure\Adapters;
|
||||
use App\Modules\Billing\Application\Contracts\BillingQueries;
|
||||
use App\Modules\Billing\Domain\Enums\ExportStatus;
|
||||
use App\Modules\Dashboard\Application\Contracts\DashboardAdmin;
|
||||
use App\Modules\Inventory\Application\Contracts\StockQueries;
|
||||
use App\Modules\Machines\Application\Contracts\MaintenanceQueries;
|
||||
use App\Modules\Machines\Domain\Enums\MaintenanceLevel;
|
||||
use App\Modules\Sales\Application\Contracts\QuickSaleQueries;
|
||||
use App\Modules\Shared\Application\UseCases\HolidayCalendar;
|
||||
use App\Modules\Users\Application\Contracts\UserAccountQueries;
|
||||
use App\Modules\Users\Domain\Enums\Role;
|
||||
|
||||
/**
|
||||
* Billing drafts, cash days, people and holidays for the management panel
|
||||
* through the Billing, Sales, Users and Shared modules.
|
||||
* Billing drafts, cash days, people, holidays, late maintenance and stock
|
||||
* to order for the management panel through the Billing, Sales, Users,
|
||||
* Shared, Machines and Inventory modules.
|
||||
*/
|
||||
class AdminForDashboard implements DashboardAdmin
|
||||
{
|
||||
@@ -21,6 +25,8 @@ class AdminForDashboard implements DashboardAdmin
|
||||
private QuickSaleQueries $sales,
|
||||
private UserAccountQueries $users,
|
||||
private HolidayCalendar $holidays,
|
||||
private MaintenanceQueries $maintenance,
|
||||
private StockQueries $stock,
|
||||
) {}
|
||||
|
||||
public function openDraftId(): ?int
|
||||
@@ -56,4 +62,22 @@ class AdminForDashboard implements DashboardAdmin
|
||||
{
|
||||
return $this->holidays->activeDatesBetween($from, $to);
|
||||
}
|
||||
|
||||
public function lateMaintenance(): array
|
||||
{
|
||||
$late = [];
|
||||
|
||||
foreach ($this->maintenance->due() as $item) {
|
||||
if ($item->level === MaintenanceLevel::Overdue) {
|
||||
$late[] = ['machineId' => $item->machineId, 'machine' => $item->machineName, 'item' => $item->name];
|
||||
}
|
||||
}
|
||||
|
||||
return $late;
|
||||
}
|
||||
|
||||
public function stockItemsToOrder(): int
|
||||
{
|
||||
return count($this->stock->items(onlyReorder: true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +104,29 @@ new class extends Component
|
||||
</li>
|
||||
@endif
|
||||
@endcan
|
||||
@can('machines.use')
|
||||
@if ($overview->lateMaintenance !== [])
|
||||
<li>
|
||||
<x-link :href="route('machines.show', $overview->lateMaintenance[0]['machineId']).'#maintenance-heading'" navigate>
|
||||
{{ trans_choice('dashboard.todo.maintenance', count($overview->lateMaintenance), ['count' => count($overview->lateMaintenance)]) }}
|
||||
</x-link>
|
||||
<ul class="mt-1 ml-4 list-disc">
|
||||
@foreach ($overview->lateMaintenance as $late)
|
||||
<li>{{ __('dashboard.todo.maintenance_line', ['machine' => $late['machine'], 'item' => $late['item']]) }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</li>
|
||||
@endif
|
||||
@endcan
|
||||
@can('inventory.view')
|
||||
@if ($overview->stockItemsToOrder > 0)
|
||||
<li>
|
||||
<x-link :href="route('inventory.index', ['tilattavat' => 1])" navigate>
|
||||
{{ trans_choice('dashboard.todo.stock', $overview->stockItemsToOrder, ['count' => $overview->stockItemsToOrder]) }}
|
||||
</x-link>
|
||||
</li>
|
||||
@endif
|
||||
@endcan
|
||||
@can('reports.view')
|
||||
<li>
|
||||
<x-link :href="route('reports.unbilled')" navigate>{{ __('dashboard.todo.unbilled', ['amount' => $this->money($overview->unbilledValueCents)]) }}</x-link>
|
||||
|
||||
Reference in New Issue
Block a user