84 lines
2.4 KiB
PHP
84 lines
2.4 KiB
PHP
<?php
|
|
|
|
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, 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
|
|
{
|
|
public function __construct(
|
|
private BillingQueries $billing,
|
|
private QuickSaleQueries $sales,
|
|
private UserAccountQueries $users,
|
|
private HolidayCalendar $holidays,
|
|
private MaintenanceQueries $maintenance,
|
|
private StockQueries $stock,
|
|
) {}
|
|
|
|
public function openDraftId(): ?int
|
|
{
|
|
foreach ($this->billing->exports() as $export) {
|
|
if ($export->status === ExportStatus::Draft) {
|
|
return $export->id;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function unclosedCashDaysBefore(string $day): array
|
|
{
|
|
return $this->sales->unclosedDaysBefore($day);
|
|
}
|
|
|
|
public function staff(): array
|
|
{
|
|
$staff = [];
|
|
|
|
foreach ($this->users->activeUserOptions() as $user) {
|
|
if ($user->role !== Role::Subcontractor) {
|
|
$staff[$user->id] = $user->name;
|
|
}
|
|
}
|
|
|
|
return $staff;
|
|
}
|
|
|
|
public function holidaysBetween(string $from, string $to): array
|
|
{
|
|
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));
|
|
}
|
|
}
|