diff --git a/app/Filament/Resources/ProductionOrderResource/Pages/EditProductionOrder.php b/app/Filament/Resources/ProductionOrderResource/Pages/EditProductionOrder.php index f59857a..7af79dd 100644 --- a/app/Filament/Resources/ProductionOrderResource/Pages/EditProductionOrder.php +++ b/app/Filament/Resources/ProductionOrderResource/Pages/EditProductionOrder.php @@ -122,74 +122,38 @@ class EditProductionOrder extends EditRecord // } // } - public function printitemserial($production_order, $plantCode) + public function printItemSerial() { - $order = ProductionOrder::where('production_order', $production_order)->first(); + $pOrder = trim($this->form->getState()['production_order'] ?? '') ?? null; - if (!$order) { - abort(404, 'Production Order not found'); + $plantId = trim($this->form->getState()['plant_id'] ?? '') ?? null; + + $plantCode = Plant::where('id', $plantId)->value('code'); + + if (empty($plantId)) { + Notification::make() + ->title('Plant name cannot be empty!') + ->danger() + ->send(); + return; + } elseif (empty($pOrder)) { + Notification::make() + ->title('Production order cannot be empty!') + ->danger() + ->send(); + return; } - else{ - $fromSerial = (int) $order->from_serial_number; - $toSerial = (int) $order->to_serial_number; - $itemCode = $order->item->code ?? ''; - $itemDes = $order->item->description ?? ''; - $wareHouseNo = Plant::where('code', $plantCode)->first(); + $pOrderExists = ProductionOrder::where('plant_id', $plantId)->where('production_order', $pOrder)->first(); - $wareNo = $wareHouseNo->warehouse_number ?? null; - - $now = Carbon::now(); - $year = $now->format('y'); - $month = $now->format('m'); - - $stickers = []; - - for ($i = $fromSerial; $i <= $toSerial; $i++) - { - - $serial = str_pad($i, 6, '0', STR_PAD_LEFT); - - if(!empty($wareNo)){ - $serial = substr($serial, 0, 4) . $wareNo . substr($serial, 4); - $qrData = $itemCode . '|' . $serial; - } else { - $qrData = $itemCode . '|' . $serial; - $serial = str_pad($i, 6, '0', STR_PAD_LEFT); - } - - // $qrData = $itemCode . '|' . $serial; - - // $serialCount = substr(str_pad($i, 6, '0', STR_PAD_LEFT), -6); - - // $serialWithWarehouse = substr($serial, 0, 4) . $wareNo . substr($serial, 4); - - // $qrData = $itemCode . '|' . $serialWithWarehouse; - - // $panel = $plantCode . $wareNo . '/' . $itemCode . '/' . $year.$month . '/' . $serialCount; - - // $qrBase64 = base64_encode( - // QrCode::format('png')->size(100)->generate($qrData) - // ); - - $qrCode = new QrCode($qrData); - $output = new Output\Png; - // $qrBinary = $output->output($qrCode, 100); - $qrBinary = $output->output($qrCode, 600); - $qrBase64 = base64_encode($qrBinary); - - $stickers[] = [ - 'serial' => $serial, - 'qr' => 'data:image/png;base64,' . $qrBase64, - 'production_order' => $itemCode, - 'description' => $itemDes ?? '' - ]; - } - - $pdf = Pdf::loadView('production-orders.printItemSerial', compact('stickers')) - ->setPaper([0, 0, 170, 40]); - - return $pdf->stream('stickers.pdf'); + if (! $pOrderExists) { + Notification::make() + ->title("Production Order '{$pOrder}' does not exist to get print!") + ->danger() + ->send(); + return; + } else { + return redirect()->route('production-orders.printItemSerial', ['production_order' => $pOrder, 'plant_code' => $plantCode]); } } diff --git a/app/Filament/Resources/ProductionOrderResource/Pages/ViewProductionOrder.php b/app/Filament/Resources/ProductionOrderResource/Pages/ViewProductionOrder.php index 389bb68..18b1d19 100644 --- a/app/Filament/Resources/ProductionOrderResource/Pages/ViewProductionOrder.php +++ b/app/Filament/Resources/ProductionOrderResource/Pages/ViewProductionOrder.php @@ -124,74 +124,38 @@ class ViewProductionOrder extends ViewRecord // } // } - public function printitemserial($production_order, $plantCode) + public function printItemSerial() { - $order = ProductionOrder::where('production_order', $production_order)->first(); + $pOrder = trim($this->form->getState()['production_order'] ?? '') ?? null; - if (!$order) { - abort(404, 'Production Order not found'); + $plantId = trim($this->form->getState()['plant_id'] ?? '') ?? null; + + $plantCode = Plant::where('id', $plantId)->value('code'); + + if (empty($plantId)) { + Notification::make() + ->title('Plant name cannot be empty!') + ->danger() + ->send(); + return; + } elseif (empty($pOrder)) { + Notification::make() + ->title('Production order cannot be empty!') + ->danger() + ->send(); + return; } - else{ - $fromSerial = (int) $order->from_serial_number; - $toSerial = (int) $order->to_serial_number; - $itemCode = $order->item->code ?? ''; - $itemDes = $order->item->description ?? ''; - $wareHouseNo = Plant::where('code', $plantCode)->first(); + $pOrderExists = ProductionOrder::where('plant_id', $plantId)->where('production_order', $pOrder)->first(); - $wareNo = $wareHouseNo->warehouse_number ?? null; - - $now = Carbon::now(); - $year = $now->format('y'); - $month = $now->format('m'); - - $stickers = []; - - for ($i = $fromSerial; $i <= $toSerial; $i++) - { - - $serial = str_pad($i, 6, '0', STR_PAD_LEFT); - - if(!empty($wareNo)){ - $serial = substr($serial, 0, 4) . $wareNo . substr($serial, 4); - $qrData = $itemCode . '|' . $serial; - } else { - $qrData = $itemCode . '|' . $serial; - $serial = str_pad($i, 6, '0', STR_PAD_LEFT); - } - - // $qrData = $itemCode . '|' . $serial; - - // $serialCount = substr(str_pad($i, 6, '0', STR_PAD_LEFT), -6); - - // $serialWithWarehouse = substr($serial, 0, 4) . $wareNo . substr($serial, 4); - - // $qrData = $itemCode . '|' . $serialWithWarehouse; - - // $panel = $plantCode . $wareNo . '/' . $itemCode . '/' . $year.$month . '/' . $serialCount; - - // $qrBase64 = base64_encode( - // QrCode::format('png')->size(100)->generate($qrData) - // ); - - $qrCode = new QrCode($qrData); - $output = new Output\Png; - // $qrBinary = $output->output($qrCode, 100); - $qrBinary = $output->output($qrCode, 600); - $qrBase64 = base64_encode($qrBinary); - - $stickers[] = [ - 'serial' => $serial, - 'qr' => 'data:image/png;base64,' . $qrBase64, - 'production_order' => $itemCode, - 'description' => $itemDes ?? '' - ]; - } - - $pdf = Pdf::loadView('production-orders.printItemSerial', compact('stickers')) - ->setPaper([0, 0, 170, 40]); - - return $pdf->stream('stickers.pdf'); + if (! $pOrderExists) { + Notification::make() + ->title("Production Order '{$pOrder}' does not exist to get print!") + ->danger() + ->send(); + return; + } else { + return redirect()->route('production-orders.printItemSerial', ['production_order' => $pOrder, 'plant_code' => $plantCode]); } } diff --git a/app/Http/Controllers/ProductionOrderController.php b/app/Http/Controllers/ProductionOrderController.php index 873c779..8476172 100644 --- a/app/Http/Controllers/ProductionOrderController.php +++ b/app/Http/Controllers/ProductionOrderController.php @@ -189,7 +189,7 @@ class ProductionOrderController extends Controller $qrCode = new QrCode($qrData); $output = new Output\Png; // $qrBinary = $output->output($qrCode, 100); - $qrBinary = $output->output($qrCode, 600); + $qrBinary = $output->output($qrCode, 100); $qrBase64 = base64_encode($qrBinary); $stickers[] = [