This commit is contained in:
ygbanzato 2025-03-12 12:02:15 +00:00
parent bb616e62b5
commit 81cb1ff1b4
5624 changed files with 11174 additions and 4494 deletions

10
.env
View File

@ -19,15 +19,13 @@ DB_PORT=3306
# Alteracoes para funcionar com o servidor, porem não funciona na firma
DB_HOST=ispt-innovation.com
DB_DATABASE=ispt40_version01
# DB_DATABASE=ispt40_version01 - versao com os dados ja testados
DB_DATABASE=ispt40_version01_Test
DB_USERNAME=ispt40
DB_PASSWORD=qu3ro3ntr@r
BROADCAST_DRIVER=pusher
BROADCAST_DRIVER=pusher
CACHE_DRIVER=file
FILESYSTEM_DISK=local

0
app/DataTables/UsersDataTable.php Normal file → Executable file
View File

0
app/Http/Controllers/ClientController.php Normal file → Executable file
View File

View File

@ -1670,8 +1670,8 @@ function normalize($value)
public function showStep3($company_projects_id)
{
$receiveDataCompanyProject = CompanyProject::where('company_projects_id', $company_projects_id)->first();
$receiveDataCompanyProject= CompanyProject::find($company_projects_id)->first();
$equipments = Equipment::where('company_projects_id', $company_projects_id)
->get();

View File

@ -0,0 +1,461 @@
<?php
namespace App\Http\Controllers;
use App\Models\Company;
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();
// $userLogoPath = Auth::user()->user_logo ? asset('user_logos/' . Auth::user()->user_logo) : asset('user_logos/logoISPT4.0.jpg');
// $equipmentData = [];
// foreach ($equipments as $equipment) {
// // Gera o QR Code para cada equipamento
// $qrCode = new QrCode($equipment->equipment_tag);
// $writer = new PngWriter();
// $qrCodeImage = 'data:image/png;base64,' . base64_encode($writer->write($qrCode)->getString());
// // Busca equipamentos associados para cada equipamento
// $associatedEquipments = QrcodesAssociatedEquipment::where('equipment_id', $equipment->equipment_id)->get();
// $associatedArray = [];
// foreach ($associatedEquipments as $associatedEquipment) {
// $associatedArray[$associatedEquipment->id] = $associatedEquipment->component_tag;
// }
// // Adiciona os dados necessários para cada equipamento em um array
// $equipmentData[] = [
// 'detailsEquipment' => $equipment,
// 'userLogoPath' => $userLogoPath,
// 'qrCodeImage' => $qrCodeImage,
// 'associatedArray' => $associatedArray
// ];
// }
// // Passa todos os dados dos equipamentos para a view
// $html = view('projectsClients.showAllEquipmentsForQrCodePdf', [
// 'equipmentData' => $equipmentData,
// 'userLogoPath' => $userLogoPath,
// ])->render();
// // Define a orientação da folha como horizontal (Landscape)
// $mpdf = new \Mpdf\Mpdf([
// 'mode' => 'utf-8',
// 'format' => 'A4-L' // Define o formato como A4 e orientação como Landscape (horizontal)
// ]);
// $mpdf->WriteHTML($html);
// $mpdf->Output('equipamentos_projeto_' . $projectId . '.pdf', 'I');
// }
// public function showAllEquipmentsInProjectForQrCode($projectId)
// {
// $equipments = Equipment::where('company_projects_id', $projectId)->get();
// $equipmentData = [];
// foreach ($equipments as $equipment) {
// $qrCode = new QrCode($equipment->equipment_tag);
// $writer = new PngWriter();
// $qrCodeImage = 'data:image/png;base64,' . base64_encode($writer->write($qrCode)->getString());
// $associatedEquipments = QrcodesAssociatedEquipment::where('equipment_id', $equipment->equipment_id)->get();
// $associatedArray = [];
// foreach ($associatedEquipments as $associatedEquipment) {
// $associatedArray[$associatedEquipment->id] = $associatedEquipment->component_tag;
// }
// $equipmentData[] = [
// 'equipment' => $equipment,
// 'qrCodeImage' => $qrCodeImage,
// 'associatedArray' => $associatedArray
// ];
// }
// $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');
// }
// // dd($equipmentData);
// $html = view('projectsClients.showAllEquipmentsInProjectQrCodePdf', [
// 'equipmentData' => $equipmentData,
// 'logoPath' => $logoPath
// ])->render();
// $mpdf = new \Mpdf\Mpdf([
// 'mode' => 'utf-8',
// 'format' => 'A4'
// ]);
// $mpdf->WriteHTML($html);
// $mpdf->Output('equipamentos_projeto_' . $projectId . '.pdf', 'I');
// }
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 showDetailsEquipmentForQrCode($equipmentId, $projectId)
// {
// $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();
// $logoPath = public_path('companies_logo/' . ($detailsCompany->company_logo ?: 'logoISPT4.0.jpg'));
// if (!file_exists($logoPath)) {
// $logoPath = public_path('companies_logo/logoISPT4.0.jpg');
// }
// $associatedEquipments = QrcodesAssociatedEquipment::where('equipment_id', $detailsEquipment->equipment_id)->get();
// $associatedArray = [];
// $qrCodeImages = [];
// foreach ($associatedEquipments as $associatedEquipment) {
// $associatedArray[$associatedEquipment->id] = $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());
// }
// $html = view('projectsClients.showDetailsEquipmentForQrCodePdf', [
// 'detailsEquipment' => $detailsEquipment,
// 'logoPath' => $logoPath,
// 'qrCodeImages' => $qrCodeImages,
// 'associatedArray' => $associatedArray
// ])->render();
// $mpdf = new \Mpdf\Mpdf(['mode' => 'utf-8', 'format' => 'A4']);
// $mpdf->WriteHTML($html);
// $mpdf->Output('nome_do_arquivo.pdf', 'I');
// }
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'));
$specificAttributes = SpecificAttributesEquipmentType::where('equipment_id', $detailsEquipment->equipment_id)->get();
$specificAttributesArray = [];
foreach ($specificAttributes as $attribute) {
$specificAttributesArray[$attribute->general_attributes_equipment_id] = $attribute->specific_attributes_value;
}
//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());
}
// dd($detailsEquipment->equipmentType->equipment_type_id);
// return view('projectsClients.showDetailsEquipmentForQrCodePdf', [
// 'detailsEquipment' => $detailsEquipment,
// 'logoPath' => $logoPath,
// 'qrCodeImages' => $qrCodeImages,
// 'associatedArray' => $associatedArray,
// 'isptLogoPath'=> $isptLogoPath
// ]);
//falta buscar os atributos especificos
// 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', [
'detailsEquipment' => $detailsEquipment,
'logoPath' => $logoPath,
'qrCodeImages' => $qrCodeImages,
'associatedArray' => $associatedArray,
'isptLogoPath'=> $isptLogoPath
])
->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();
}
}

View File

@ -3,13 +3,16 @@
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;
@ -30,49 +33,6 @@
class PreparedProjectController extends Controller
{
// public function showAllEquipmentsInProjectForQrCode($projectId)
// {
// $equipments = Equipment::where('company_projects_id', $projectId)->get();
// $userLogoPath = Auth::user()->user_logo ? asset('user_logos/' . Auth::user()->user_logo) : asset('user_logos/logoISPT4.0.jpg');
// $equipmentData = [];
// foreach ($equipments as $equipment) {
// // Gera o QR Code para cada equipamento
// $qrCode = new QrCode($equipment->equipment_tag);
// $writer = new PngWriter();
// $qrCodeImage = 'data:image/png;base64,' . base64_encode($writer->write($qrCode)->getString());
// // Busca equipamentos associados para cada equipamento
// $associatedEquipments = QrcodesAssociatedEquipment::where('equipment_id', $equipment->equipment_id)->get();
// $associatedArray = [];
// foreach ($associatedEquipments as $associatedEquipment) {
// $associatedArray[$associatedEquipment->id] = $associatedEquipment->component_tag;
// }
// // Adiciona os dados necessários para cada equipamento em um array
// $equipmentData[] = [
// 'detailsEquipment' => $equipment,
// 'userLogoPath' => $userLogoPath,
// 'qrCodeImage' => $qrCodeImage,
// 'associatedArray' => $associatedArray
// ];
// }
// // Passa todos os dados dos equipamentos para a view
// $html = view('projectsClients.showAllEquipmentsForQrCodePdf', [
// 'equipmentData' => $equipmentData,
// 'userLogoPath' => $userLogoPath,
// ])->render();
// // Define a orientação da folha como horizontal (Landscape)
// $mpdf = new \Mpdf\Mpdf([
// 'mode' => 'utf-8',
// 'format' => 'A4-L' // Define o formato como A4 e orientação como Landscape (horizontal)
// ]);
// $mpdf->WriteHTML($html);
// $mpdf->Output('equipamentos_projeto_' . $projectId . '.pdf', 'I');
// }
// public function showAllEquipmentsInProjectForQrCode($projectId)
@ -80,136 +40,178 @@ class PreparedProjectController extends Controller
// $equipments = Equipment::where('company_projects_id', $projectId)->get();
// $equipmentData = [];
// foreach ($equipments as $equipment) {
// $qrCode = new QrCode($equipment->equipment_tag);
// $writer = new PngWriter();
// $qrCodeImage = 'data:image/png;base64,' . base64_encode($writer->write($qrCode)->getString());
// foreach ($equipments as $equipment) {
// $associatedEquipments = QrcodesAssociatedEquipment::where('equipment_id', $equipment->equipment_id)->get();
// $associatedArray = [];
// foreach ($associatedEquipments as $associatedEquipment) {
// $associatedArray[$associatedEquipment->id] = $associatedEquipment->component_tag;
// $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,
// 'qrCodeImage' => $qrCodeImage,
// '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');
// }
// // dd($equipmentData);
// $html = view('projectsClients.showAllEquipmentsInProjectQrCodePdf', [
// 'equipmentData' => $equipmentData,
// 'logoPath' => $logoPath
// 'logoPath' => $logoPath,
// 'isptLogoPath'=> $isptLogoPath
// ])->render();
// $mpdf = new \Mpdf\Mpdf([
// 'mode' => 'utf-8',
// 'format' => 'A4'
// ]);
// $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)
{
$equipments = 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);
// Criar diretório temporário se não existir
if (!file_exists($tempPath)) {
mkdir($tempPath, 0777, true);
}
$files = []; // Armazena os caminhos dos PDFs gerados
$equipmentData = [];
foreach ($equipments as $equipment) {
$associatedEquipments = QrcodesAssociatedEquipment::where('equipment_id', $equipment->equipment_id)->get();
$associatedArray = [];
// 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();
foreach ($associatedEquipments as $associatedEquipment) {
$qrCode = new QrCode($associatedEquipment->component_tag);
$writer = new PngWriter();
$qrCodeImage = 'data:image/png;base64,' . base64_encode($writer->write($qrCode)->getString());
// Buscar atributos específicos do equipamento
$specificAttributes = SpecificAttributesEquipmentType::where('equipment_id', $equipment->equipment_id)->get();
$specificAttributesArray = [];
$associatedArray[] = [
'id' => $associatedEquipment->id,
'component_tag' => $associatedEquipment->component_tag,
'qrCodeImage' => $qrCodeImage
];
foreach ($specificAttributes as $attribute) {
$specificAttributesArray[$attribute->general_attributes_equipment_id] = $attribute->specific_attributes_value;
}
$equipmentData[] = [
'equipment' => $equipment,
'associatedArray' => $associatedArray
];
// 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', [
'detailsEquipment' => $equipment,
'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;
}
$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');
// 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();
}
$html = view('projectsClients.showAllEquipmentsInProjectQrCodePdf', [
'equipmentData' => $equipmentData,
'logoPath' => $logoPath
])->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 showDetailsEquipmentForQrCode($equipmentId, $projectId)
// {
// $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();
// $logoPath = public_path('companies_logo/' . ($detailsCompany->company_logo ?: 'logoISPT4.0.jpg'));
// if (!file_exists($logoPath)) {
// $logoPath = public_path('companies_logo/logoISPT4.0.jpg');
// }
// $associatedEquipments = QrcodesAssociatedEquipment::where('equipment_id', $detailsEquipment->equipment_id)->get();
// $associatedArray = [];
// $qrCodeImages = [];
// foreach ($associatedEquipments as $associatedEquipment) {
// $associatedArray[$associatedEquipment->id] = $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());
// }
// $html = view('projectsClients.showDetailsEquipmentForQrCodePdf', [
// 'detailsEquipment' => $detailsEquipment,
// 'logoPath' => $logoPath,
// 'qrCodeImages' => $qrCodeImages,
// 'associatedArray' => $associatedArray
// ])->render();
// $mpdf = new \Mpdf\Mpdf(['mode' => 'utf-8', 'format' => 'A4']);
// $mpdf->WriteHTML($html);
// $mpdf->Output('nome_do_arquivo.pdf', 'I');
// }
// 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 showDetailsEquipmentForQrCode($equipmentId, $projectId)
{
@ -223,12 +225,33 @@ public function showDetailsEquipmentForQrCode($equipmentId, $projectId)
$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
@ -251,30 +274,20 @@ public function showDetailsEquipmentForQrCode($equipmentId, $projectId)
$qrCodeImages[$associatedEquipment->id] = 'data:image/png;base64,' . base64_encode($writer->write($qrCode)->getString());
}
// dd($detailsEquipment->equipmentType->equipment_type_id);
return view('projectsClients.showDetailsEquipmentForQrCodePdf', [
'detailsEquipment' => $detailsEquipment,
'logoPath' => $logoPath,
'qrCodeImages' => $qrCodeImages,
'associatedArray' => $associatedArray,
'isptLogoPath'=> $isptLogoPath
]);
// // 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', [
// 'detailsEquipment' => $detailsEquipment,
// 'logoPath' => $logoPath,
// 'qrCodeImages' => $qrCodeImages,
// 'associatedArray' => $associatedArray,
// 'isptLogoPath'=> $isptLogoPath
// ])
// ->setOrientation('landscape')
// ->stream('nome_do_arquivo.pdf'); // Exibe o PDF diretamente no navegador
// 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', [
'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
}

View File

@ -1284,7 +1284,6 @@ public function receiveWorkstationProject($receiveNumberProject,Request $request
$typePage = $request->input('typePage');
// Apenas para verificação, você pode usar dd() para ver o valor
dd($typePage);
$model = ConstructionWorkstation::where('company_projects_id', $receiveNumberProject)->with('workstationsAssociationTasks');

View File

@ -165,7 +165,6 @@ public function receiveQuestionsEquipment($equipmentID)
}
public function receiveAnswersEquipment(Request $request, $control_equipment_workstation_id)
{
//No request recebemos ID(NUmero da tarela elementar) , esta variavel vai receber este ID apos selerar o id da string
// $elementalTaskID = 0;
// Deve receber as perguntas e respostas para a tarefa selecionada
@ -341,7 +340,6 @@ public function getEquipmentData($equipment_id, $component_tag)
$specificAttributesArray[$attribute->general_attributes_equipment_id] = $attribute->specific_attributes_value;
}
$tagType = explode('@', $component_tag)[1]; // Isola o tipo da tag após o '@'

0
app/Models/AssociationCompanyUser.php Normal file → Executable file
View File

0
app/Models/Company.php Normal file → Executable file
View File

0
app/Models/EquipmentComment.php Normal file → Executable file
View File

0
app/Models/EquipmentWorkHistory.php Normal file → Executable file
View File

0
app/Models/FormAccessToken.php Normal file → Executable file
View File

0
app/Models/HistoryOfEquipmentAmbitsInTheProject.php Normal file → Executable file
View File

0
app/Models/ProjectExcelLog.php Normal file → Executable file
View File

View File

0
app/Models/TaskEquipmentComment.php Normal file → Executable file
View File

0
app/Services/PdfWrapper copy.php Normal file → Executable file
View File

0
app/Services/PdfWrapper.php Normal file → Executable file
View File

0
config/datatables-buttons.php Normal file → Executable file
View File

0
node_modules/.package-lock.json generated vendored Normal file → Executable file
View File

0
node_modules/@babel/code-frame/LICENSE generated vendored Normal file → Executable file
View File

0
node_modules/@babel/code-frame/README.md generated vendored Normal file → Executable file
View File

0
node_modules/@babel/code-frame/lib/index.js generated vendored Normal file → Executable file
View File

0
node_modules/@babel/code-frame/lib/index.js.map generated vendored Normal file → Executable file
View File

0
node_modules/@babel/code-frame/package.json generated vendored Normal file → Executable file
View File

0
node_modules/@babel/helper-validator-identifier/LICENSE generated vendored Normal file → Executable file
View File

0
node_modules/@babel/helper-validator-identifier/README.md generated vendored Normal file → Executable file
View File

0
node_modules/@babel/helper-validator-identifier/lib/identifier.js generated vendored Normal file → Executable file
View File

0
node_modules/@babel/helper-validator-identifier/lib/identifier.js.map generated vendored Normal file → Executable file
View File

0
node_modules/@babel/helper-validator-identifier/lib/index.js generated vendored Normal file → Executable file
View File

0
node_modules/@babel/helper-validator-identifier/lib/index.js.map generated vendored Normal file → Executable file
View File

0
node_modules/@babel/helper-validator-identifier/lib/keyword.js generated vendored Normal file → Executable file
View File

0
node_modules/@babel/helper-validator-identifier/lib/keyword.js.map generated vendored Normal file → Executable file
View File

0
node_modules/@babel/helper-validator-identifier/package.json generated vendored Normal file → Executable file
View File

View File

0
node_modules/@babel/highlight/LICENSE generated vendored Normal file → Executable file
View File

0
node_modules/@babel/highlight/README.md generated vendored Normal file → Executable file
View File

0
node_modules/@babel/highlight/lib/index.js generated vendored Normal file → Executable file
View File

0
node_modules/@babel/highlight/lib/index.js.map generated vendored Normal file → Executable file
View File

0
node_modules/@babel/highlight/package.json generated vendored Normal file → Executable file
View File

0
node_modules/@esbuild/linux-x64/README.md generated vendored Normal file → Executable file
View File

0
node_modules/@esbuild/linux-x64/package.json generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/README.md generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/CLI.d.ts generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/CLI.d.ts.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/CLI.js generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/CLI.js.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/Cache.d.ts generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/Cache.d.ts.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/Cache.js generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/Cache.js.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/browser-data.d.ts generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/browser-data.d.ts.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/browser-data.js generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/browser-data.js.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/chrome-headless-shell.d.ts generated vendored Normal file → Executable file
View File

View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/chrome-headless-shell.js generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/chrome-headless-shell.js.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/chrome.d.ts generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/chrome.d.ts.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/chrome.js generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/chrome.js.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/chromedriver.d.ts generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/chromedriver.d.ts.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/chromedriver.js generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/chromedriver.js.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/chromium.d.ts generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/chromium.d.ts.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/chromium.js generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/chromium.js.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/firefox.d.ts generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/firefox.d.ts.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/firefox.js generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/firefox.js.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/types.d.ts generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/types.d.ts.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/types.js generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/browser-data/types.js.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/debug.d.ts generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/debug.d.ts.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/debug.js generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/debug.js.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/detectPlatform.d.ts generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/detectPlatform.d.ts.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/detectPlatform.js generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/detectPlatform.js.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/fileUtil.d.ts generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/fileUtil.d.ts.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/fileUtil.js generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/fileUtil.js.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/httpUtil.d.ts generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/httpUtil.d.ts.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/httpUtil.js generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/httpUtil.js.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/install.d.ts generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/install.d.ts.map generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/install.js generated vendored Normal file → Executable file
View File

0
node_modules/@puppeteer/browsers/lib/cjs/install.js.map generated vendored Normal file → Executable file
View File

Some files were not shown because too many files have changed in this diff Show More