fix conflict issue in sticker pdf service
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 12s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 13s
Gemini PR Review / Gemini PR Review (pull_request) Successful in 20s
Laravel Pint / pint (pull_request) Failing after 2m32s
Laravel Larastan / larastan (pull_request) Failing after 5m36s
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 12s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 13s
Gemini PR Review / Gemini PR Review (pull_request) Successful in 20s
Laravel Pint / pint (pull_request) Failing after 2m32s
Laravel Larastan / larastan (pull_request) Failing after 5m36s
This commit is contained in:
@@ -387,20 +387,179 @@ class CreateStickerValidation extends CreateRecord
|
||||
// ]);
|
||||
|
||||
}
|
||||
|
||||
// foreach ($stickers as $sticker) {
|
||||
|
||||
// // $printerName = $this->getCupsPrinterNameByIp($sticker['print_ip']);
|
||||
|
||||
// \Log::info("Looking up printer for IP: " . $sticker['print_ip']);
|
||||
// $printerName = $this->getCupsPrinterNameByIp($sticker['print_ip']);
|
||||
// \Log::info("Found printer: " . ($printerName ?? 'NULL'));
|
||||
|
||||
// if (! $printerName) {
|
||||
// Notification::make()
|
||||
// ->danger()
|
||||
// ->title('Printer Not Found')
|
||||
// ->body("No CUPS printer configured for IP: {$sticker['print_ip']}")
|
||||
// ->send();
|
||||
// return;
|
||||
// }
|
||||
|
||||
// $structure = StickerStructureDetail::findOrFail($sticker['sticker_id']);
|
||||
// $itemCharacteristic = ItemCharacteristic::where('plant_id', $this->plantId)
|
||||
// ->where('id', $sticker['item_characteristic'])
|
||||
// ->firstOrFail();
|
||||
|
||||
// $dynamicElements = StickerDetail::where(
|
||||
// 'sticker_structure_detail_id',
|
||||
// $structure->id
|
||||
// )->where('element_type', 'Dynamic')->get();
|
||||
|
||||
|
||||
|
||||
// /** STEP 3: Stream PDF to CUPS (STDIN) */
|
||||
// $process = proc_open(
|
||||
// 'lp -d ' . escapeshellarg($printerName) . ' -o fit-to-page -',
|
||||
// [
|
||||
// ['pipe', 'r'], // STDIN
|
||||
// ['pipe', 'w'], // STDOUT
|
||||
// ['pipe', 'w'], // STDERR
|
||||
// ],
|
||||
// $pipes
|
||||
// );
|
||||
|
||||
|
||||
// if (! is_resource($process)) {
|
||||
// Notification::make()
|
||||
// ->danger()
|
||||
// ->title('Print Failed')
|
||||
// ->body('Unable to start CUPS print process.')
|
||||
// ->send();
|
||||
// return;
|
||||
// // continue;
|
||||
// }
|
||||
|
||||
// $pdfContent = (new StickerPdfService())->generatePdf1(
|
||||
// $structure->sticker_id,
|
||||
// $dynamicElements,
|
||||
// $itemCharacteristic,
|
||||
// $serialNumber,
|
||||
// $serNo
|
||||
// );
|
||||
|
||||
// fwrite($pipes[0], $pdfContent);
|
||||
// fclose($pipes[0]);
|
||||
|
||||
// $stderr = stream_get_contents($pipes[2]);
|
||||
// fclose($pipes[1]);
|
||||
// fclose($pipes[2]);
|
||||
|
||||
// $status = proc_close($process);
|
||||
|
||||
// if ($status != 0) {
|
||||
// Notification::make()
|
||||
// ->danger()
|
||||
// ->title('Print Failed')
|
||||
// ->body("CUPS error: {$stderr}")
|
||||
// ->send();
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
foreach ($stickers as $sticker)
|
||||
{
|
||||
|
||||
\Log::info("Looking up printer for IP: " . $sticker['print_ip']);
|
||||
|
||||
$printerName = $this->getCupsPrinterNameByIp($sticker['print_ip']);
|
||||
|
||||
\Log::info("Found printer: " . ($printerName ?? 'NULL'));
|
||||
|
||||
if (! $printerName) {
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title('Printer Not Found')
|
||||
->body("No CUPS printer configured for IP: {$sticker['print_ip']}")
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
$structure = StickerStructureDetail::findOrFail($sticker['sticker_id']);
|
||||
|
||||
$itemCharacteristic = ItemCharacteristic::where('plant_id', $this->plantId)
|
||||
->where('id', $sticker['item_characteristic'])
|
||||
->firstOrFail();
|
||||
|
||||
$dynamicElements = StickerDetail::where(
|
||||
'sticker_structure_detail_id',
|
||||
$structure->id
|
||||
)->where('element_type', 'Dynamic')->get();
|
||||
|
||||
$pdfContent = (new StickerPdfService())->generatePdf1(
|
||||
$structure->sticker_id,
|
||||
$dynamicElements,
|
||||
$itemCharacteristic,
|
||||
$serialNumber,
|
||||
$serNo
|
||||
);
|
||||
|
||||
$tempPdfPath = storage_path('app/temp_sticker_' . uniqid() . '.pdf');
|
||||
file_put_contents($tempPdfPath, $pdfContent);
|
||||
|
||||
exec(
|
||||
"lp -d " . escapeshellarg($printerName) . " " . escapeshellarg($tempPdfPath),
|
||||
$output,
|
||||
$status
|
||||
);
|
||||
|
||||
\Log::info("LP Output:", $output);
|
||||
\Log::info("LP Status: " . $status);
|
||||
|
||||
if ($status != 0) {
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title('Print Failed')
|
||||
->body("CUPS error while printing.")
|
||||
->send();
|
||||
|
||||
if (file_exists($tempPdfPath)) {
|
||||
unlink($tempPdfPath);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (file_exists($tempPdfPath)) {
|
||||
unlink($tempPdfPath);
|
||||
}
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('Sticker Printed')
|
||||
->body("Sticker for Serial Number: $serialNumber printed successfully!")
|
||||
->seconds(3)
|
||||
->send();
|
||||
|
||||
// [$itemCode, $serialNumber] = explode('|', $serNo);
|
||||
|
||||
// $this->dispatch('open-sticker-pdf', [
|
||||
// 'url' => url("/sticker/pdf/{$itemCode}/{$serialNumber}/$this->plantId/$this->ref_number")
|
||||
// ]);
|
||||
|
||||
}
|
||||
|
||||
protected function getCupsPrinterNameByIp(string $ip): ?string
|
||||
{
|
||||
|
||||
// exec('lpstat -v 2>&1', $output, $status);
|
||||
|
||||
exec('lpstat -h cups:631 -v 2>&1', $output, $status);
|
||||
|
||||
if ($status != 0 || empty($output)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($output as $line){
|
||||
foreach ($output as $line) {
|
||||
$parts = explode(':', $line, 2);
|
||||
if (count($parts) < 2) continue;
|
||||
|
||||
@@ -411,6 +570,7 @@ class CreateStickerValidation extends CreateRecord
|
||||
return $printerName;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user