diff --git a/app/Http/Controllers/ProductionOrderController.php b/app/Http/Controllers/ProductionOrderController.php index ea22dc10..0ccb5c9c 100644 --- a/app/Http/Controllers/ProductionOrderController.php +++ b/app/Http/Controllers/ProductionOrderController.php @@ -146,65 +146,140 @@ class ProductionOrderController extends Controller } } - public function printpanel2($production_order, $plantCode){ + // public function printpanel2($production_order, $plantCode){ + // $order = ProductionOrder::where('production_order', $production_order)->first(); + + // $wareHouseNo = Plant::where('code', $plantCode)->first(); + + // $wareNo = $wareHouseNo->warehouse_number ?? null; + + // if (!$order) { + // abort(404, 'Production Order not found'); + // } + // else{ + // $fromSerial = (int) $order->from_serial_number; + // $toSerial = (int) $order->to_serial_number; + // $itemCode = $order->item->code ?? ''; + // $itemDes = $order->item->description ?? ''; + // $now = Carbon::now(); + // $year = $now->format('y'); + // // $month = $now->format('m'); + // // $month = $now->format('m'); + + // // $stickers = []; + + // // for ($i = $fromSerial; $i <= $toSerial; $i++) + // // { + + // // $currentSerial = (string) $i; + + // // $year = substr($currentSerial, -10, 2); + + // // $month = substr($currentSerial, -8, 2); + + // // $serial = str_pad($i, 6, '0', STR_PAD_LEFT); + // // $serialCount = substr(str_pad($i, 6, '0', STR_PAD_LEFT), -6); + + // // $qrData = $plantCode . $wareNo . '/' . $itemCode . '/' . $year.$month . '/' . $serialCount; + + // // $panel = $plantCode . $wareNo . '/' . $itemCode . '/' . $year.$month . '/' . $serialCount; + + // // $qrCode = new QrCode($qrData); + // // $output = new Output\Png; + // // $qrBinary = $output->output($qrCode, 100); + // // $qrBase64 = base64_encode($qrBinary); + + // // $stickers[] = [ + // // 'serial' => $panel, + // // 'qr' => 'data:image/png;base64,' . $qrBase64, + // // 'production_order' => $production_order, + // // 'description' => $itemDes ?? '' + // // ]; + // // } + + // $pdf = Pdf::loadView('production-orders.printpanel2', compact('stickers')) + // ->setPaper([0, 0, 113.39, 113.39]); + + // return $pdf->stream('stickers.pdf'); + // } + // } + + public function printpanel2($production_order, $plantCode) + { $order = ProductionOrder::where('production_order', $production_order)->first(); - $wareHouseNo = Plant::where('code', $plantCode)->first(); - - $wareNo = $wareHouseNo->warehouse_number ?? null; - if (!$order) { abort(404, 'Production Order not found'); } - else{ - $fromSerial = (int) $order->from_serial_number; - $toSerial = (int) $order->to_serial_number; - $itemCode = $order->item->code ?? ''; - $itemDes = $order->item->description ?? ''; - $now = Carbon::now(); - $year = $now->format('y'); - // $month = $now->format('m'); - // $month = $now->format('m'); - $stickers = []; + $fromSerial = (int) $order->from_serial_number; + $toSerial = (int) $order->to_serial_number; - for ($i = $fromSerial; $i <= $toSerial; $i++) - { + $itemCode = $order->item->code ?? ''; + $itemDes = $order->item->description ?? ''; - $currentSerial = (string) $i; + $stickers = []; - $year = substr($currentSerial, -10, 2); + for ($i = $fromSerial; $i <= $toSerial; $i += 2) { + $row = []; + + for ($j = 0; $j < 2; $j++) { + + $current = $i + $j; + + if ($current > $toSerial) { + break; + } + + // Original encoded serial number + $currentSerial = (string) $current; + + // Extract year and month + $year = substr($currentSerial, -10, 2); $month = substr($currentSerial, -8, 2); - $serial = str_pad($i, 6, '0', STR_PAD_LEFT); - $serialCount = substr(str_pad($i, 6, '0', STR_PAD_LEFT), -6); + // Extract only the last 6 digits + $serialCount = substr($currentSerial, -6); - $qrData = $plantCode . $wareNo . '/' . $itemCode . '/' . $year.$month . '/' . $serialCount; - - $panel = $plantCode . $wareNo . '/' . $itemCode . '/' . $year.$month . '/' . $serialCount; + // QR format: PlantCode/ItemCode/YearMonth/Serial + $qrData = $plantCode . '/' . + $itemCode . '/' . + $year . $month . '/' . + $serialCount; + // Generate QR code $qrCode = new QrCode($qrData); + $output = new Output\Png; + $qrBinary = $output->output($qrCode, 100); + $qrBase64 = base64_encode($qrBinary); - $stickers[] = [ - 'serial' => $panel, + $row[] = [ + 'serial' => $qrData, 'qr' => 'data:image/png;base64,' . $qrBase64, 'production_order' => $production_order, - 'description' => $itemDes ?? '' + 'description' => $itemDes, ]; } - $pdf = Pdf::loadView('production-orders.printpanel2', compact('stickers')) - ->setPaper([0, 0, 113.39, 113.39]); - - return $pdf->stream('stickers.pdf'); + $stickers[] = $row; } + + $pdf = Pdf::loadView( + 'production-orders.printpanel2', + compact('stickers') + )->setPaper([0, 0, 113.39, 113.39]); + + return $pdf->stream('stickers.pdf'); } + + + public function printitemserial($production_order, $plantCode) { $order = ProductionOrder::where('production_order', $production_order)->first(); diff --git a/resources/views/production-orders/printpanel2.blade.php b/resources/views/production-orders/printpanel2.blade.php index 6f06fe3e..06783c0b 100644 --- a/resources/views/production-orders/printpanel2.blade.php +++ b/resources/views/production-orders/printpanel2.blade.php @@ -97,22 +97,29 @@
-@foreach($stickers as $sticker) - @php - $descSize = 4; - @endphp - +@foreach($stickers as $row)