ultimatepos/Modules/Portal/Http/Controllers/Customer/MaintenanceHubController.php

39 lines
1.3 KiB
PHP

<?php
namespace Modules\Portal\Http\Controllers\Customer;
use Modules\Portal\Http\Controllers\BasePortalController;
use Modules\Portal\Services\CustomerMaintenanceScopeService;
class MaintenanceHubController extends BasePortalController
{
public function index()
{
$this->ensureCrmSubscription();
$scope = CustomerMaintenanceScopeService::forCurrentUser();
$stats = $scope->dashboardStats();
$upcomingServices = collect();
if ($scope->preventiveSchedulesAvailable()) {
$upcomingServices = $scope->preventiveScheduleQuery()
->with(['equipment:id,name', 'project:id,name', 'productionLine:id,name'])
->where('is_active', true)
->whereNotNull('next_due_at')
->orderBy('next_due_at')
->limit(5)
->get();
}
$recentWorkOrders = collect();
if ($scope->workOrdersAvailable()) {
$recentWorkOrders = $scope->workOrderQuery()
->with(['equipment:id,name', 'assignedTechnician:id,first_name,last_name'])
->orderByDesc('updated_at')
->limit(5)
->get();
}
return view('portal::customer.maintenance.index', compact('stats', 'upcomingServices', 'recentWorkOrders'));
}
}