first(); // if (!$item) { // abort(404, "Item with code {$itemCode} not found."); // } // $itemId = $item->id; // $production = ProductionQuantity::where('item_id', $itemId) // ->where('serial_number', $serial) // ->first(); // if (!$production) { // abort(404, "Production data for item code '{$itemCode}' with serial '{$serial}' not found."); // } // $productionOrder = $production->production_order; // $qrCode = new QrCode($palletNo); // $output = new Output\Png(); // $qrBinary = $output->output($qrCode, 100); // $qrBase64 = base64_encode($qrBinary); // $sticker = StickerMaster::where('item_id', $itemId)->first(); // // Decide number of copies // $copies = 1; // if ($sticker) { // if ($sticker->serial_number_pump == 1) { // // If pump is selected (regardless of motor), 2 copies // $copies = 2; // } elseif ($sticker->serial_number_motor == 1) { // // Only motor selected, 1 copy // $copies = 1; // } // } // return ' // // // // // // // // // // '; // //Get sticker master data // // $sticker = StickerMaster::where('item_id', $itemId)->first(); // // //Decide number of copies // // $copies = 1; // default // // if ($sticker) { // // if ($sticker->serial_number_motor == 1) { // // $copies = 1; // // } elseif (is_null($sticker->serial_number_motor) && $sticker->serial_number_pump == 1) { // // $copies = 2; // // } // // } // // $mpdf = new Mpdf([ // // 'mode' => 'utf-8', // // 'format' => [60, 14], // // 'margin_left' => 0, // // 'margin_right' => 0, // // 'margin_top' => 0, // // 'margin_bottom' => 0, // // ]); // // for ($i = 0; $i < $copies; $i++) { // // $mpdf->WriteHTML($html); // // if ($i < $copies - 1) { // // $mpdf->AddPage(); // // } // // } // // $mpdf->Output('qr-label.pdf', 'I'); // // exit; // } /** * Store a newly created resource in storage. */ public function downloadQrPdf($palletNo) { $parts = explode('|', $palletNo); $itemCode = trim($parts[0]); $serial = isset($parts[1]) ? trim($parts[1]) : null; $item = Item::where('code', $itemCode)->first(); $itemId= $item->id; if (!$item) { abort(404, "Item with code {$itemCode} not found."); } $production = ProductionQuantity::where('item_id', $item->id) ->where('serial_number', $serial) ->first(); if (!$production) { abort(404, "Production data for item code '{$itemCode}' with serial '{$serial}' not found."); } $productionOrder = $production->production_order ?? ''; if ($item->category == 'Submersible Motor') { $copies = 1; } elseif ($item->category == 'Submersible Pump') { $copies = 2; } // 5. Generate QR Code (base64) $qrCode = new QrCode($palletNo); $output = new Output\Png(); $qrBinary = $output->output($qrCode, 100); // 100 = size $qrBase64 = base64_encode($qrBinary); // 6. Return view return view('print-qr', [ 'qrBase64' => $qrBase64, 'serial' => $serial, 'productionOrder' => $productionOrder, 'item' => $item, 'copies'=> $copies, ]); } public function store(Request $request) { // } /** * Display the specified resource. */ public function show(string $id) { // } /** * Update the specified resource in storage. */ public function update(Request $request, string $id) { // } /** * Remove the specified resource from storage. */ public function destroy(string $id) { // } }