form->getState()['production_order'] ?? '') ?? null; $plantId = trim($this->form->getState()['plant_id'] ?? '') ?? null; 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; } $pOrderExists = ProductionOrder::where('plant_id', $plantId)->where('production_order', $pOrder)->first(); if (! $pOrderExists) { Notification::make() ->title("Production Order '{$pOrder}' does not exist to get print!") ->danger() ->send(); return; } else { return redirect()->route('production-orders.print', ['production_order' => $pOrder]); } } public function printPanel() { $plantId = $this->form->getState()['plant_id'] ?? null; $plantId = filled($plantId) ? (int) $plantId : null; $pOrder = $this->form->getState()['production_order'] ?? null; $pOrder = filled($pOrder) ? trim($pOrder) : 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; } $pOrderExists = ProductionOrder::where('plant_id', $plantId)->where('production_order', $pOrder)->first(); if (! $pOrderExists) { Notification::make() ->title("Production Order '{$pOrder}' does not exist to get print!") ->danger() ->send(); return; } else { return redirect()->route('production-orders.printpanel', ['production_order' => $pOrder, 'plant_code' => $plantCode]); } } // public function printItemSerial() // { // $pOrder = trim($this->form->getState()['production_order'] ?? '') ?? null; // $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; // } // $pOrderExists = ProductionOrder::where('plant_id', $plantId)->where('production_order', $pOrder)->first(); // 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]); // } // } public function printitemserial($production_order, $plantCode) { $order = ProductionOrder::where('production_order', $production_order)->first(); 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 ?? ''; $wareHouseNo = Plant::where('code', $plantCode)->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'); } } protected function getHeaderActions(): array { return [ Actions\EditAction::make(), ]; } }