92 lines
3.5 KiB
PHP
92 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Models\CompanyProject;
|
|
use App\Models\ConstructionWorkstation;
|
|
use App\Models\Equipment;
|
|
use App\Models\EquipmentType;
|
|
use App\Models\OrderEquipmentTasks;
|
|
|
|
use Yajra\DataTables\Facades\DataTables;
|
|
|
|
class ExecutionProjectController extends Controller
|
|
{
|
|
public function receiveExecutionProject($ProjectId)
|
|
{
|
|
|
|
$DatasProject = CompanyProject::find($ProjectId);
|
|
$equipmentsTypes = EquipmentType::all();
|
|
|
|
// return view('projectsClients/executionProject')
|
|
return view('projectsClients/executionProject')
|
|
->with('DatasProject', $DatasProject)
|
|
->with('equipmentsTypes', $equipmentsTypes);
|
|
}
|
|
|
|
public function receiveWorkstationExecutionProject($receiveNumberProject)
|
|
{
|
|
|
|
$model = ConstructionWorkstation::where('company_projects_id', $receiveNumberProject)->with('workstationsAssociationTasks');
|
|
|
|
return DataTables::of($model)
|
|
// ->addColumn('workstations_Association_Tasks', function ($row) {
|
|
// return $row->workstationsAssociationTasks->pluck('elemental_tasks_id')->implode('-');
|
|
// })
|
|
->toJson();
|
|
}
|
|
|
|
public function receiveEquipmentIdForShowModal($EquipmentID)
|
|
{
|
|
$equipment = Equipment::find($EquipmentID);
|
|
|
|
$task_codes = $equipment->orderEquipmentTasks->map(function ($task) {
|
|
return $task->elementalTask->elemental_tasks_code;
|
|
})->toArray();
|
|
|
|
return response()->json(['task_codes' => $task_codes]);
|
|
}
|
|
|
|
public function receiveEquipmentsExecutionProject($receiveNumberProject)
|
|
{
|
|
// Recebe os dados vindos da funcao 'data' criada na view
|
|
$equipment_type_id = request('equipment_type_id');
|
|
$ambits_id = request('ambits_id');
|
|
|
|
//Recebe sempre apenas os equipamentos relacionados a obra
|
|
$model = Equipment::where('company_projects_id', $receiveNumberProject);
|
|
|
|
// Caso 'equipment_type_id' seja '#', mostra todos os equipamentos
|
|
if ($equipment_type_id == '#') {
|
|
$model = Equipment::query()->with(['equipmentType', 'unit', 'equipmentAssociationAmbit.ambitsEquipment']);
|
|
}
|
|
// Caso 'equipment_type_id' não seja '#', filtra os equipamentos por tipo e ambito (caso 'ambits_id' não seja '#')
|
|
else {
|
|
$equipment_type_id = intval($equipment_type_id);
|
|
$model = Equipment::where('equipments.equipment_type_id', $equipment_type_id)
|
|
->join('equipment_association_ambits', 'equipments.equipment_id', '=', 'equipment_association_ambits.equipment_id')
|
|
->with(['equipmentType', 'unit', 'equipmentAssociationAmbit.ambitsEquipment']);
|
|
|
|
if ($ambits_id != '#') {
|
|
$ambits_id = intval($ambits_id);
|
|
$model->where('equipment_association_ambits.ambits_id', $ambits_id);
|
|
}
|
|
}
|
|
|
|
return DataTables::of($model)
|
|
->addColumn('equipment_type', function ($row) {
|
|
return $row->equipmentType->equipment_type_name;
|
|
})
|
|
->addColumn('Ambits', function ($row) {
|
|
return $row->equipmentAssociationAmbit->ambitsEquipment->ambits_description;
|
|
})
|
|
->addColumn('order_tasks', function ($row) {
|
|
return $row->orderEquipmentTasks->map(function ($task) {
|
|
return $task->elementalTask->elemental_tasks_code;
|
|
})->implode('-');
|
|
})
|
|
->toJson();
|
|
}
|
|
}
|