diff --git a/app/Http/Controllers/CreateProjectController.php b/app/Http/Controllers/CreateProjectController.php index 560370de..41139a98 100755 --- a/app/Http/Controllers/CreateProjectController.php +++ b/app/Http/Controllers/CreateProjectController.php @@ -1218,6 +1218,7 @@ public function receiveIdEquipment(Equipment $equipment) public function processStep2(Request $request) { + // Valide e processe os dados do formulário $file = $request->file('documento'); diff --git a/app/Http/Controllers/PreparedProjectController.php b/app/Http/Controllers/PreparedProjectController.php index 70e44093..b2f774f0 100755 --- a/app/Http/Controllers/PreparedProjectController.php +++ b/app/Http/Controllers/PreparedProjectController.php @@ -18,6 +18,7 @@ use App\Models\Unit; use App\Models\AmbitsEquipment; use Illuminate\Support\Facades\Auth; +use App\Services\PdfWrapper; // use PDF; @@ -174,23 +175,12 @@ public function showAllEquipmentsInProjectForQrCode($projectId) } - // public function showDetailsEquipmentForQrCode($equipmentId, $projectId) // { // $detailsEquipment = Equipment::find($equipmentId); - - // // Gera o QR Code - // $qrCode = new QrCode($detailsEquipment->equipment_tag); - // $writer = new PngWriter(); - - // // Converte o QR Code para base64 para incorporar na página - // $qrCodeImage = 'data:image/png;base64,' . base64_encode($writer->write($qrCode)->getString()); - // $detailsCompanyProject = CompanyProject::find($projectId); // $detailsPlant = Plant::where('plant_id', $detailsCompanyProject->plant_id)->first(); - - // $detailsCompany= Company::where('company_id', $detailsPlant->company_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)) { @@ -198,61 +188,94 @@ public function showAllEquipmentsInProjectForQrCode($projectId) // } // $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, - // 'qrCodeImage' => $qrCodeImage, + // 'qrCodeImages' => $qrCodeImages, // 'associatedArray' => $associatedArray // ])->render(); - // // Define a orientação da folha como horizontal (Landscape) - // $mpdf = new \Mpdf\Mpdf([ - // 'mode' => 'utf-8', - // 'format' => 'A4' // Define o formato como A4 e orientação como Landscape (horizontal) - // ]); + // $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')); + + // 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) { - $associatedArray[$associatedEquipment->id] = $associatedEquipment->component_tag; + // 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()); } - $html = view('projectsClients.showDetailsEquipmentForQrCodePdf', [ + // dd($detailsEquipment->equipmentType->equipment_type_id); + + return view('projectsClients.showDetailsEquipmentForQrCodePdf', [ 'detailsEquipment' => $detailsEquipment, 'logoPath' => $logoPath, 'qrCodeImages' => $qrCodeImages, - 'associatedArray' => $associatedArray - ])->render(); + '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 - $mpdf = new \Mpdf\Mpdf(['mode' => 'utf-8', 'format' => 'A4']); - $mpdf->WriteHTML($html); - $mpdf->Output('nome_do_arquivo.pdf', 'I'); } @@ -306,7 +329,7 @@ public function PreparedProject($ProjectId) ->with('units', $checkUnits) ->with('numberProject', $numberProject) ->with('equipmentsProjects', $equipmentsProjects); - + } public function getAmbits($equipmentType) diff --git a/app/Http/Controllers/ProjectoDatacontroller.php b/app/Http/Controllers/ProjectoDatacontroller.php index c919c34b..da569625 100755 --- a/app/Http/Controllers/ProjectoDatacontroller.php +++ b/app/Http/Controllers/ProjectoDatacontroller.php @@ -21,9 +21,6 @@ use ZipArchive; - - - use Yajra\DataTables\Facades\DataTables; use Carbon\Carbon; diff --git a/app/Models/Equipment.php b/app/Models/Equipment.php index 40d20a40..3013f2f6 100755 --- a/app/Models/Equipment.php +++ b/app/Models/Equipment.php @@ -43,13 +43,6 @@ public function specificAttributes() ->orderBy('general_attributes_equipaments.general_attributes_equipment_description', 'asc'); } - //Trocar para EquipmentWorkHistory - public function equipmentAssociationAmbit() - { - //Antiga hasMany , apenas colocado hasOne para funcionar o datatables - return $this->hasOne(EquipmentAssociationAmbit::class, 'equipment_id', 'equipment_id'); - } - public function orderEquipmentTasks() { return $this->hasMany(OrderEquipmentTasks::class, 'equipment_id', 'equipment_id'); diff --git a/app/Models/EquipmentAssociationAmbit.php b/app/Models/EquipmentAssociationAmbit.php index 771bedbf..28e6d1d0 100755 --- a/app/Models/EquipmentAssociationAmbit.php +++ b/app/Models/EquipmentAssociationAmbit.php @@ -25,4 +25,8 @@ public function Equipment(){ return $this->belongsTo(Equipment::class,'equipment_id', 'equipment_id'); } + public function equipmentWorkHistory() + { + return $this->belongsTo(EquipmentWorkHistory::class, 'equipmentWorkHistorys_id', 'equipmentWorkHistorys_id'); + } } diff --git a/app/Services/PdfWrapper.php b/app/Services/PdfWrapper.php index 21511fce..686f7df2 100644 --- a/app/Services/PdfWrapper.php +++ b/app/Services/PdfWrapper.php @@ -10,12 +10,20 @@ class PdfWrapper { protected Browsershot $pdfGenerator; protected string $html; + protected $orientation = 'portrait'; public function __construct() { $this->pdfGenerator = new Browsershot(); } + // Método para configurar a orientação (paisagem ou retrato) + public function setOrientation($orientation): self + { + $this->orientation = $orientation; + return $this; + } + // Load view and render HTML public function loadView(string $bladeFile, array $data = []): self { @@ -50,6 +58,7 @@ public function generate(): Browsershot return $this->pdfGenerator ->html($this->html) ->format('A4') + ->landscape($this->orientation === 'landscape') // Verifica se deve ser paisagem ->scale(0.7) ->fullPage() ->setOption('printBackground', true) diff --git a/public/templateExcel/Valves_Template.xlsx b/public/templateExcel/Valves_Template.xlsx index 29d05803..9438b91b 100644 Binary files a/public/templateExcel/Valves_Template.xlsx and b/public/templateExcel/Valves_Template.xlsx differ diff --git a/resources/views/projectsClients/showDetailsEquipmentForQrCodePdf.blade copy.php b/resources/views/projectsClients/showDetailsEquipmentForQrCodePdf.blade copy.php new file mode 100644 index 00000000..67e564f3 --- /dev/null +++ b/resources/views/projectsClients/showDetailsEquipmentForQrCodePdf.blade copy.php @@ -0,0 +1,176 @@ + + + +
+ + + +
+
+ {{ $associatedArray[$key] }}
+
+
+
+
+
+ @elseif($detailsEquipment->equipmentType->equipment_type_id == 1)
+ {{ $associatedArray[$key] }}
+{{ $associatedArray[$key] }}
+