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

80 lines
2.4 KiB
PHP

<?php
namespace Modules\Portal\Http\Controllers\Customer;
use Modules\Portal\Http\Controllers\BasePortalController;
use Modules\Portal\Services\CustomerMaintenanceScopeService;
class ProjectController extends BasePortalController
{
public function index()
{
$this->ensureCrmSubscription();
$scope = CustomerMaintenanceScopeService::forCurrentUser();
$projects = $scope->projectQuery()
->with(['tasks' => function ($q) {
$q->select('id', 'pjt_project_id', 'subject', 'status', 'due_date');
}])
->orderByDesc('created_at')
->paginate(20);
return view('portal::customer.projects.index', compact('projects'));
}
public function show($id)
{
$this->ensureCrmSubscription();
$scope = CustomerMaintenanceScopeService::forCurrentUser();
if (! $scope->ownsProject((int) $id)) {
abort(404);
}
$project = $scope->projectQuery()
->with(['tasks', 'members', 'contact'])
->findOrFail($id);
$productionLines = $scope->productionLineQuery()
->where('project_id', $project->id)
->withCount('equipment')
->get();
$equipment = $scope->equipmentQuery()
->where('project_id', $project->id)
->with(['productionLine:id,name', 'category:id,name'])
->orderBy('name')
->get();
$schedules = $scope->preventiveScheduleQuery()
->where('project_id', $project->id)
->with('equipment:id,name')
->orderBy('next_due_at')
->get();
$workOrders = $scope->workOrderQuery()
->where('project_id', $project->id)
->with(['equipment:id,name', 'assignedTechnician:id,first_name,last_name'])
->orderByDesc('created_at')
->limit(15)
->get();
$missions = $scope->fieldMissionQuery()
->where('source_type', 'project')
->where('source_id', $project->id)
->with(['leadUser:id,first_name,last_name'])
->orderByDesc('created_at')
->limit(10)
->get();
return view('portal::customer.projects.show', compact(
'project',
'productionLines',
'equipment',
'schedules',
'workOrders',
'missions'
));
}
}