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

56 lines
1.7 KiB
PHP

<?php
namespace Modules\Portal\Http\Controllers\Customer;
use Modules\Portal\Http\Controllers\BasePortalController;
use Modules\Portal\Services\CustomerMaintenanceScopeService;
class ProductionLineController extends BasePortalController
{
public function index()
{
$this->ensureCrmSubscription();
$scope = CustomerMaintenanceScopeService::forCurrentUser();
$lines = $scope->productionLineQuery()
->with(['project:id,name'])
->withCount('equipment')
->orderBy('name')
->paginate(20);
return view('portal::customer.production_lines.index', compact('lines'));
}
public function show($id)
{
$this->ensureCrmSubscription();
$scope = CustomerMaintenanceScopeService::forCurrentUser();
if (! $scope->ownsProductionLine((int) $id)) {
abort(404);
}
$line = $scope->productionLineQuery()
->with([
'project',
'equipment' => fn ($q) => $q->orderBy('name'),
])
->findOrFail($id);
$schedules = $scope->preventiveScheduleQuery()
->where('production_line_id', $line->id)
->with('equipment:id,name')
->orderBy('next_due_at')
->get();
$workOrders = $scope->workOrderQuery()
->where('production_line_id', $line->id)
->with(['equipment:id,name', 'assignedTechnician:id,first_name,last_name'])
->orderByDesc('created_at')
->limit(15)
->get();
return view('portal::customer.production_lines.show', compact('line', 'schedules', 'workOrders'));
}
}