549 lines
23 KiB
PHP
Executable File
549 lines
23 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Company;
|
|
use App\Models\EquipmentAssociationAmbit;
|
|
use App\Models\EquipmentWorkHistory;
|
|
use App\Models\Plant;
|
|
use App\Models\QrcodesAssociatedEquipment;
|
|
use App\Models\SpecificAttributesEquipmentType;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Yajra\DataTables\DataTables;
|
|
use ZipArchive;
|
|
|
|
|
|
use App\Models\CompanyProject;
|
|
use App\Models\Equipment;
|
|
use App\Models\EquipmentType;
|
|
use App\Models\Unit;
|
|
use App\Models\AmbitsEquipment;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use App\Services\PdfWrapper;
|
|
|
|
// use PDF;
|
|
|
|
use Mpdf\Mpdf;
|
|
|
|
use Endroid\QrCode\QrCode;
|
|
use Endroid\QrCode\Writer\PngWriter;
|
|
|
|
|
|
class PreparedProjectController extends Controller
|
|
{
|
|
|
|
|
|
// public function showAllEquipmentsInProjectForQrCode($projectId)
|
|
// {
|
|
// $equipments = Equipment::where('company_projects_id', $projectId)->get();
|
|
|
|
// $equipmentData = [];
|
|
|
|
// foreach ($equipments as $equipment) {
|
|
// $associatedEquipments = QrcodesAssociatedEquipment::where('equipment_id', $equipment->equipment_id)->get();
|
|
// $associatedArray = [];
|
|
// foreach ($associatedEquipments as $associatedEquipment) {
|
|
// $qrCode = new QrCode($associatedEquipment->component_tag);
|
|
// $writer = new PngWriter();
|
|
// $qrCodeImage = 'data:image/png;base64,' . base64_encode($writer->write($qrCode)->getString());
|
|
// $associatedArray[] = [
|
|
// 'id' => $associatedEquipment->id,
|
|
// 'component_tag' => $associatedEquipment->component_tag,
|
|
// 'qrCodeImage' => $qrCodeImage
|
|
// ];
|
|
// }
|
|
// $equipmentData[] = [
|
|
// 'equipment' => $equipment,
|
|
// 'associatedArray' => $associatedArray
|
|
// ];
|
|
// }
|
|
|
|
|
|
// foreach ($equipments as $equipment) {
|
|
// // Buscar os equipamentos associados ao QR Code
|
|
// $associatedEquipments = QrcodesAssociatedEquipment::where('equipment_id', $equipment->equipment_id)->get();
|
|
// $associatedArray = [];
|
|
// $qrCodeImages = []; // Inicializa a variável dentro do loop para cada equipamento
|
|
|
|
// foreach ($associatedEquipments as $associatedEquipment) {
|
|
// // Extrair o texto após o '@'
|
|
// $componentParts = explode('@', $associatedEquipment->component_tag);
|
|
// $tagName = $componentParts[0];
|
|
// $tagType = $componentParts[1] ?? 'Tipo não especificado';
|
|
|
|
// // Gerar QR Code
|
|
// $qrCode = new QrCode($associatedEquipment->component_tag);
|
|
// $writer = new PngWriter();
|
|
// $qrCodeImage = 'data:image/png;base64,' . base64_encode($writer->write($qrCode)->getString());
|
|
|
|
// // Armazena os dados associados
|
|
// $associatedArray[] = [
|
|
// 'id' => $associatedEquipment->id,
|
|
// 'component_tag' => $associatedEquipment->component_tag,
|
|
// 'qrCodeImage' => $qrCodeImage
|
|
// ];
|
|
|
|
// // Armazena a imagem do QR Code associada ao ID do equipamento
|
|
// $qrCodeImages[$associatedEquipment->id] = $qrCodeImage;
|
|
// }
|
|
|
|
// // Adiciona os dados completos do equipamento na lista final
|
|
// $equipmentData[] = [
|
|
// 'equipment' => $equipment,
|
|
// 'associatedArray' => $associatedArray,
|
|
// 'qrCodeImages' => $qrCodeImages // Agora esta variável é corretamente definida
|
|
// ];
|
|
// }
|
|
// $isptLogoPath = public_path('/img/ispt/ispt.jpg');
|
|
|
|
|
|
// // dd($equipmentData);
|
|
|
|
// $detailsCompanyProject = CompanyProject::find($projectId);
|
|
// $detailsPlant = Plant::where('plant_id', $detailsCompanyProject->plant_id)->first();
|
|
// $detailsCompany = Company::where('company_id', $detailsPlant->company_id)->first();
|
|
// $logoPath = public_path('companies_logo/' . ($detailsCompany->company_logo ?: 'logoISPT4.0.jpg'));
|
|
|
|
// if (!file_exists($logoPath)) {
|
|
// $logoPath = public_path('companies_logo/logoISPT4.0.jpg');
|
|
// }
|
|
|
|
// $html = view('projectsClients.showAllEquipmentsInProjectQrCodePdf', [
|
|
// 'equipmentData' => $equipmentData,
|
|
// 'logoPath' => $logoPath,
|
|
// 'isptLogoPath'=> $isptLogoPath
|
|
// ])->render();
|
|
|
|
// $mpdf = new Mpdf(['mode' => 'utf-8', 'format' => 'A4']);
|
|
|
|
// $mpdf->useSubstitutions = false; // Reduce processing
|
|
// $mpdf->simpleTables = true; // Simplifies tables into basic HTML
|
|
|
|
// $mpdf->WriteHTML($html);
|
|
// $mpdf->Output('equipamentos_projeto_' . $projectId . '.pdf', 'I');
|
|
// }
|
|
|
|
|
|
// public function showAllEquipmentsInProjectForQrCode($projectId)
|
|
// {
|
|
// $detailsEquipment = Equipment::where('company_projects_id', $projectId)->get();
|
|
// $zipFileName = 'equipamentos_projeto_' . $projectId . '.zip';
|
|
// $tempPath = storage_path('app/public/temp_pdfs/');
|
|
// $zipPath = storage_path('app/public/' . $zipFileName);
|
|
|
|
// // Busca os dados do equipamento
|
|
// $receiveEquipmentWorkHistory = EquipmentWorkHistory::where('equipment_id', $detailsEquipment->equipment_id)
|
|
// ->where('company_projects_id', $detailsEquipment->company_projects_id)
|
|
// ->first();
|
|
// //Recebe os dados do Ambito para o equipamento atual
|
|
// $receiveAmbit = EquipmentAssociationAmbit::where('equipmentWorkHistorys_id', $receiveEquipmentWorkHistory->equipmentWorkHistorys_id)->first();
|
|
|
|
// //Guarda os Detalhes recebidos das outras variavies como Ambito e Numero Ispt
|
|
// $detailsEquipment->istp_number = $receiveEquipmentWorkHistory->ispt_number;
|
|
// $detailsEquipment->equipment_ambit = $receiveAmbit->ambitsEquipment->ambits_description;
|
|
|
|
|
|
// // Criar diretório temporário se não existir
|
|
// if (!file_exists($tempPath)) {
|
|
// mkdir($tempPath, 0777, true);
|
|
// }
|
|
|
|
// $files = []; // Armazena os caminhos dos PDFs gerados
|
|
|
|
// foreach ($detailsEquipment as $equipment) {
|
|
// // Buscar detalhes do equipamento
|
|
// $detailsCompanyProject = CompanyProject::find($projectId);
|
|
// $detailsPlant = Plant::where('plant_id', $detailsCompanyProject->plant_id)->first();
|
|
// $detailsCompany = Company::where('company_id', $detailsPlant->company_id)->first();
|
|
|
|
// // Usar a mesma estrutura da função principal
|
|
// $specificAttributesArray = [];
|
|
|
|
// $specificAttributes = SpecificAttributesEquipmentType::where('equipment_id', $detailsEquipment->equipment_id)->get();
|
|
|
|
// foreach ($specificAttributes as $attribute) {
|
|
// $specificAttributesArray[$attribute->general_attributes_equipment_id] = $attribute->specific_attributes_value;
|
|
// }
|
|
|
|
|
|
// // Buscar equipamentos associados ao QR Code
|
|
// $associatedEquipments = QrcodesAssociatedEquipment::where('equipment_id', $equipment->equipment_id)->get();
|
|
// $associatedArray = [];
|
|
// $qrCodeImages = [];
|
|
|
|
// foreach ($associatedEquipments as $associatedEquipment) {
|
|
// $componentParts = explode('@', $associatedEquipment->component_tag);
|
|
// $associatedArray[$associatedEquipment->id] = isset($componentParts[1]) ? $componentParts[1] : $associatedEquipment->component_tag;
|
|
|
|
// // Gerar QR Code
|
|
// $qrCode = new QrCode($associatedEquipment->component_tag);
|
|
// $writer = new PngWriter();
|
|
// $qrCodeImages[$associatedEquipment->id] = 'data:image/png;base64,' . base64_encode($writer->write($qrCode)->getString());
|
|
// }
|
|
|
|
// // Caminho do logo da empresa
|
|
// $logoPath = public_path('companies_logo/' . ($detailsCompany->company_logo ?: 'logoISPT4.0.jpg'));
|
|
// if (!file_exists($logoPath)) {
|
|
// $logoPath = public_path('companies_logo/logoISPT4.0.jpg');
|
|
// }
|
|
// $isptLogoPath = public_path('/img/ispt/ispt.jpg');
|
|
|
|
// //Criar uma nova instância do PdfWrapper para cada equipamento
|
|
// $pdfWrapper = new PdfWrapper();
|
|
// $pdf = $pdfWrapper->loadView('projectsClients.showDetailsEquipmentForQrCodePdf', [
|
|
// 'detailsCompanyProject' => $detailsCompanyProject,
|
|
// 'detailsEquipment' => $detailsEquipment,
|
|
// 'logoPath' => $logoPath,
|
|
// 'qrCodeImages' => $qrCodeImages,
|
|
// 'associatedArray' => $associatedArray,
|
|
// 'isptLogoPath' => $isptLogoPath
|
|
// ])->setOrientation('landscape');
|
|
|
|
// // Nome do arquivo PDF
|
|
// $pdfFileName = $equipment->equipment_tag . '.pdf';
|
|
// $pdfFilePath = $tempPath . $pdfFileName;
|
|
|
|
// // Salvar o PDF
|
|
// $pdf->save($pdfFilePath);
|
|
// $files[] = $pdfFilePath;
|
|
// }
|
|
|
|
// // Criar arquivo ZIP e adicionar os PDFs gerados
|
|
// $zip = new ZipArchive;
|
|
// if ($zip->open($zipPath, ZipArchive::CREATE) === TRUE) {
|
|
// foreach ($files as $file) {
|
|
// $zip->addFile($file, basename($file));
|
|
// }
|
|
// $zip->close();
|
|
// }
|
|
|
|
// // Remover arquivos PDF individuais após criar o ZIP
|
|
// foreach ($files as $file) {
|
|
// unlink($file);
|
|
// }
|
|
|
|
// // Retornar o arquivo ZIP para download
|
|
// return response()->download($zipPath)->deleteFileAfterSend(true);
|
|
// }
|
|
|
|
public function showAllEquipmentsInProjectForQrCode($projectId)
|
|
{
|
|
$equipments = Equipment::where('company_projects_id', $projectId)->get(); // ← nome mais apropriado
|
|
$zipFileName = 'equipamentos_projeto_' . $projectId . '.zip';
|
|
$tempPath = storage_path('app/public/temp_pdfs/');
|
|
$zipPath = storage_path('app/public/' . $zipFileName);
|
|
|
|
// Criar diretório temporário se não existir
|
|
if (!file_exists($tempPath)) {
|
|
mkdir($tempPath, 0777, true);
|
|
}
|
|
|
|
$files = []; // Armazena os caminhos dos PDFs gerados
|
|
|
|
foreach ($equipments as $equipment) {
|
|
// Reutilizamos $detailsEquipment dentro do loop para compatibilidade com a view
|
|
$detailsEquipment = $equipment;
|
|
|
|
// Buscar dados do histórico de trabalho e âmbito
|
|
$receiveEquipmentWorkHistory = EquipmentWorkHistory::where('equipment_id', $detailsEquipment->equipment_id)
|
|
->where('company_projects_id', $detailsEquipment->company_projects_id)
|
|
->first();
|
|
|
|
// Adicionar campo personalizado ao equipamento
|
|
$detailsEquipment->istp_number = $receiveEquipmentWorkHistory->ispt_number ?? 'N/A';
|
|
|
|
$receiveAmbit = EquipmentAssociationAmbit::where('equipmentWorkHistorys_id', $receiveEquipmentWorkHistory->equipmentWorkHistorys_id ?? null)
|
|
->first();
|
|
|
|
$detailsEquipment->equipment_ambit = $receiveAmbit->ambitsEquipment->ambits_description ?? 'N/A';
|
|
|
|
// Buscar detalhes do projeto, planta e empresa
|
|
$detailsCompanyProject = CompanyProject::find($projectId);
|
|
$detailsPlant = Plant::where('plant_id', $detailsCompanyProject->plant_id)->first();
|
|
$detailsCompany = Company::where('company_id', $detailsPlant->company_id)->first();
|
|
|
|
// Buscar atributos específicos do equipamento
|
|
$specificAttributes = SpecificAttributesEquipmentType::where('equipment_id', $detailsEquipment->equipment_id)->get();
|
|
$specificAttributesArray = [];
|
|
|
|
foreach ($specificAttributes as $attribute) {
|
|
$specificAttributesArray[$attribute->general_attributes_equipment_id] = $attribute->specific_attributes_value;
|
|
}
|
|
|
|
// Equipamentos associados ao QR Code
|
|
$associatedEquipments = QrcodesAssociatedEquipment::where('equipment_id', $detailsEquipment->equipment_id)->get();
|
|
$associatedArray = [];
|
|
$qrCodeImages = [];
|
|
|
|
foreach ($associatedEquipments as $associatedEquipment) {
|
|
$componentParts = explode('@', $associatedEquipment->component_tag);
|
|
$associatedArray[$associatedEquipment->id] = $componentParts[1] ?? $associatedEquipment->component_tag;
|
|
|
|
$qrCode = new QrCode($associatedEquipment->component_tag);
|
|
$writer = new PngWriter();
|
|
$qrCodeImages[$associatedEquipment->id] = 'data:image/png;base64,' . base64_encode($writer->write($qrCode)->getString());
|
|
}
|
|
|
|
// Caminho do logo da empresa
|
|
$logoPath = public_path('companies_logo/' . ($detailsCompany->company_logo ?: 'logoISPT4.0.jpg'));
|
|
if (!file_exists($logoPath)) {
|
|
$logoPath = public_path('companies_logo/logoISPT4.0.jpg');
|
|
}
|
|
|
|
$isptLogoPath = public_path('/img/ispt/ispt.jpg');
|
|
|
|
// Criar PDF
|
|
$pdfWrapper = new PdfWrapper();
|
|
$pdf = $pdfWrapper->loadView('projectsClients.showDetailsEquipmentForQrCodePdf', [
|
|
'detailsCompanyProject' => $detailsCompanyProject,
|
|
'detailsEquipment' => $detailsEquipment,
|
|
'logoPath' => $logoPath,
|
|
'qrCodeImages' => $qrCodeImages,
|
|
'associatedArray' => $associatedArray,
|
|
'isptLogoPath' => $isptLogoPath,
|
|
'specificAttributesArray' => $specificAttributesArray
|
|
])->setOrientation('landscape');
|
|
|
|
// Nome do PDF com o número ISPT, sanitizado
|
|
$istpNumber = preg_replace('/[^a-zA-Z0-9_-]/', '_', $detailsEquipment->istp_number);
|
|
$pdfFileName = $istpNumber . '.pdf';
|
|
$pdfFilePath = $tempPath . $pdfFileName;
|
|
|
|
// Salvar o PDF
|
|
$pdf->save($pdfFilePath);
|
|
$files[] = $pdfFilePath;
|
|
}
|
|
|
|
// Criar ZIP com os PDFs
|
|
$zip = new ZipArchive;
|
|
if ($zip->open($zipPath, ZipArchive::CREATE) === TRUE) {
|
|
foreach ($files as $file) {
|
|
$zip->addFile($file, basename($file));
|
|
}
|
|
$zip->close();
|
|
}
|
|
|
|
// Limpar PDFs temporários
|
|
foreach ($files as $file) {
|
|
unlink($file);
|
|
}
|
|
|
|
// Retornar ZIP para download
|
|
return response()->download($zipPath)->deleteFileAfterSend(true);
|
|
}
|
|
|
|
|
|
|
|
|
|
public function showDetailsEquipmentForQrCode($equipmentId, $projectId)
|
|
{
|
|
// Busca os detalhes do equipamento, projeto e empresa
|
|
$detailsEquipment = Equipment::find($equipmentId);
|
|
$detailsCompanyProject = CompanyProject::find($projectId);
|
|
$detailsPlant = Plant::where('plant_id', $detailsCompanyProject->plant_id)->first();
|
|
$detailsCompany = Company::where('company_id', $detailsPlant->company_id)->first();
|
|
|
|
// Definir o caminho da logo da empresa
|
|
$logoPath = public_path('companies_logo/' . ($detailsCompany->company_logo ?: 'logoISPT4.0.jpg'));
|
|
|
|
|
|
//Recebe os atributos especificos
|
|
$specificAttributes = SpecificAttributesEquipmentType::where('equipment_id', $detailsEquipment->equipment_id)->get();
|
|
|
|
$specificAttributesArray = [];
|
|
|
|
foreach ($specificAttributes as $attribute) {
|
|
$specificAttributesArray[$attribute->general_attributes_equipment_id] = $attribute->specific_attributes_value;
|
|
}
|
|
|
|
// Busca os dados do equipamento
|
|
$receiveEquipmentWorkHistory = EquipmentWorkHistory::where('equipment_id', $detailsEquipment->equipment_id)
|
|
->where('company_projects_id', $detailsEquipment->company_projects_id)
|
|
->first();
|
|
|
|
//Recebe os dados do Ambito para o equipamento atual
|
|
$receiveAmbit = EquipmentAssociationAmbit::where('equipmentWorkHistorys_id', $receiveEquipmentWorkHistory->equipmentWorkHistorys_id)->first();
|
|
|
|
$detailsEquipment->istp_number = $receiveEquipmentWorkHistory->ispt_number;
|
|
$detailsEquipment->equipment_ambit = $receiveAmbit->ambitsEquipment->ambits_description;
|
|
|
|
//Deve-se criar melhor os campos para testar no Qr-Code
|
|
|
|
// Verificar se o caminho do logo existe, se não, usa um logo padrão
|
|
if (!file_exists($logoPath)) {
|
|
$logoPath = public_path('companies_logo/logoISPT4.0.jpg');
|
|
}
|
|
|
|
$isptLogoPath = public_path('/img/ispt/ispt.jpg');
|
|
|
|
// Associar equipamentos ao QR Code
|
|
$associatedEquipments = QrcodesAssociatedEquipment::where('equipment_id', $detailsEquipment->equipment_id)->get();
|
|
$associatedArray = [];
|
|
$qrCodeImages = [];
|
|
|
|
|
|
// Gerar QR Codes para cada equipamento associado
|
|
foreach ($associatedEquipments as $associatedEquipment) {
|
|
// Extrair o texto após o '@'
|
|
$componentParts = explode('@', $associatedEquipment->component_tag);
|
|
$associatedArray[$associatedEquipment->id] = isset($componentParts[1]) ? $componentParts[1] : $associatedEquipment->component_tag;
|
|
|
|
// Gerar QR Code
|
|
$qrCode = new QrCode($associatedEquipment->component_tag);
|
|
$writer = new PngWriter();
|
|
|
|
// Converter o QR Code para imagem base64
|
|
$qrCodeImages[$associatedEquipment->id] = 'data:image/png;base64,' . base64_encode($writer->write($qrCode)->getString());
|
|
}
|
|
|
|
// Usar PdfWrapper para gerar o PDF
|
|
$pdfWrapper = new PdfWrapper();
|
|
// Gera e retorna o PDF com os detalhes e QR Codes
|
|
return $pdfWrapper
|
|
->loadView('projectsClients.showDetailsEquipmentForQrCodePdf', [
|
|
'detailsCompanyProject' => $detailsCompanyProject,
|
|
'detailsEquipment' => $detailsEquipment,
|
|
'logoPath' => $logoPath,
|
|
'qrCodeImages' => $qrCodeImages,
|
|
'associatedArray' => $associatedArray,
|
|
'isptLogoPath' => $isptLogoPath,
|
|
'specificAttributesArray' => $specificAttributesArray
|
|
])
|
|
->setOrientation('landscape')
|
|
->stream('nome_do_arquivo.pdf'); // Exibe o PDF diretamente no navegador
|
|
|
|
}
|
|
|
|
|
|
public function PreparedProject($ProjectId)
|
|
{
|
|
|
|
$numberProject = CompanyProject::find($ProjectId);
|
|
|
|
$equipmentsTypes = EquipmentType::all();
|
|
|
|
// Carrega todos os equipamentos para um dado projeto
|
|
$equipmentsProjects = Equipment::where('company_projects_id', $ProjectId)->get();
|
|
|
|
// Carrega as relações aninhadas
|
|
$equipmentsProjects->load('equipmentWorkHistory.equipmentAssociationAmbit.ambitsEquipment');
|
|
|
|
// Adiciona o 'ambits_description' a cada equipamento
|
|
foreach ($equipmentsProjects as $equipment) {
|
|
// Obtém o primeiro EquipmentWorkHistory (se existir)
|
|
$equipmentWorkHistory = $equipment->equipmentWorkHistory->first();
|
|
|
|
// Se existe um EquipmentWorkHistory, tenta obter o 'ambits_description'
|
|
if ($equipmentWorkHistory) {
|
|
// Tenta obter o EquipmentAssociationAmbit e o AmbitsEquipment relacionados
|
|
$equipmentAssociationAmbit = $equipmentWorkHistory->equipmentAssociationAmbit;
|
|
if ($equipmentAssociationAmbit) {
|
|
$ambitsEquipment = $equipmentAssociationAmbit->ambitsEquipment;
|
|
if ($ambitsEquipment) {
|
|
// Se existir um AmbitsEquipment, define o 'ambits_description'
|
|
$equipment->ambits_description = $ambitsEquipment->ambits_description;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Se alguma das relações não existir, define 'ambits_description' como null
|
|
if (!isset($equipment->ambits_description)) {
|
|
$equipment->ambits_description = null;
|
|
}
|
|
}
|
|
|
|
//Retorna todas as Fabricas Unit, com base na Instalação
|
|
$checkUnits = DB::table('units')
|
|
->join('plants', 'units.plant_id', '=', 'plants.plant_id')
|
|
->join('company_projects', 'plants.plant_id', '=', 'company_projects.plant_id')
|
|
->select('units.*')
|
|
->where('company_projects.company_projects_id', '=', $numberProject->company_projects_id)
|
|
->get();
|
|
|
|
return view('projectsClients/preparedProject')
|
|
->with('equipmentsTypes', $equipmentsTypes)
|
|
->with('units', $checkUnits)
|
|
->with('numberProject', $numberProject)
|
|
->with('equipmentsProjects', $equipmentsProjects);
|
|
|
|
}
|
|
|
|
public function getAmbits($equipmentType)
|
|
{
|
|
$ambits = DB::table('ambits_equipments')
|
|
->select('ambits_equipments.*')
|
|
->where('ambits_equipments.equipment_type_id', $equipmentType)
|
|
->get();
|
|
return response()->json($ambits);
|
|
}
|
|
|
|
public function editProjectForArticulated(Request $request)
|
|
{
|
|
|
|
$numberProject = CompanyProject::find($request->ProjectId);
|
|
|
|
$numberProject->order_project = 1;
|
|
$numberProject->save();
|
|
|
|
return redirect()->route('home');
|
|
}
|
|
|
|
public function getData1()
|
|
{
|
|
|
|
$equipment_type_id = request('equipment_type_id');
|
|
$unit_id = request('unit_id');
|
|
$ambits_id = request('ambits_id');
|
|
|
|
// Equipment::all()->where('company_projects_id', $ProjectId);
|
|
|
|
// 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 Âmbito (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);
|
|
}
|
|
}
|
|
if (request()->has('inspec') && request('inspec') != '#') {
|
|
$inspectionFilter = request('inspec') === 'Sim';
|
|
$model->whereHas('orderEquipmentTasks', function ($query) use ($inspectionFilter) {
|
|
$query->where('inspection', $inspectionFilter ? 'Sim' : 'Nao');
|
|
});
|
|
}
|
|
|
|
|
|
// Aplica o filtro de 'unit_id', se aplicável
|
|
if ($unit_id != '#') {
|
|
$unit_id = intval($unit_id);
|
|
$model->where('equipments.unit_id', $unit_id);
|
|
}
|
|
|
|
// Gera a tabela de dados
|
|
return DataTables::of($model)
|
|
->addColumn('equipment_type', function ($row) {
|
|
return $row->equipmentType->equipment_type_name;
|
|
})
|
|
->addColumn('Unit', function ($row) {
|
|
return $row->unit->unit_name;
|
|
})
|
|
->addColumn('Ambits', function ($row) {
|
|
return $row->equipmentAssociationAmbit->ambitsEquipment->ambits_description;
|
|
})
|
|
->addColumn('Inspec', function ($row) {
|
|
return $row->hasInspectionYes() ? 'Sim' : 'Nao';
|
|
})
|
|
->toJson();
|
|
}
|
|
}
|