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:
@@ -139,7 +139,7 @@ class CreateInvoiceValidation extends CreateRecord
|
||||
|
||||
$user1 = Filament::auth()->user();
|
||||
|
||||
$user1->notify(new PushAlertNotification());
|
||||
// $user1->notify(new PushAlertNotification());
|
||||
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Exports\ItemCharacteristicExporter;
|
||||
use App\Filament\Imports\ItemCharacteristicImporter;
|
||||
use App\Filament\Resources\ItemCharacteristicResource\Pages;
|
||||
use App\Filament\Resources\ItemCharacteristicResource\RelationManagers;
|
||||
use App\Models\Item;
|
||||
@@ -15,6 +17,8 @@ use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
|
||||
class ItemCharacteristicResource extends Resource
|
||||
{
|
||||
@@ -924,6 +928,22 @@ class ItemCharacteristicResource extends Resource
|
||||
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||
Tables\Actions\RestoreBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->headerActions([
|
||||
ImportAction::make()
|
||||
->label('Import Item Characteristics')
|
||||
->color('warning')
|
||||
->importer(ItemCharacteristicImporter::class)
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view import item characteristics');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->label('Export Item Characteristics')
|
||||
->color('warning')
|
||||
->exporter(ItemCharacteristicExporter::class)
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view export item characteristics');
|
||||
}),
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
@@ -82,9 +82,6 @@ class ItemResource extends Resource
|
||||
Forms\Components\TextInput::make('category')
|
||||
->label('Category')
|
||||
->placeholder('Scan the Category'),
|
||||
Forms\Components\TextInput::make('category')
|
||||
->label('Category')
|
||||
->placeholder('Scan the Category'),
|
||||
Forms\Components\TextInput::make('code')
|
||||
->required()
|
||||
->placeholder('Scan the valid code')
|
||||
|
||||
@@ -216,7 +216,10 @@ class LineResource extends Resource
|
||||
])
|
||||
->hint(fn ($get) => $get('lTypeError') ? $get('lTypeError') : null)
|
||||
->hintColor('danger'),
|
||||
|
||||
Forms\Components\TextInput::make('line_capacity')
|
||||
->label('Line Capacity')
|
||||
->required()
|
||||
->reactive(),
|
||||
Forms\Components\TextInput::make('no_of_operation')
|
||||
->label('No of Operation')
|
||||
->required()
|
||||
@@ -1061,6 +1064,11 @@ class LineResource extends Resource
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('line_capacity')
|
||||
->label('Line Capacity')
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('no_of_operation')
|
||||
->label('No of Operation')
|
||||
->alignCenter()
|
||||
|
||||
@@ -3,10 +3,28 @@
|
||||
namespace App\Filament\Resources\ProcessOrderResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ProcessOrderResource;
|
||||
use App\Models\ProcessOrder;
|
||||
use Filament\Actions;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateProcessOrder extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ProcessOrderResource::class;
|
||||
|
||||
protected function afterCreate(): void
|
||||
{
|
||||
$plantId = $this->data['plant_id'];
|
||||
$processOrder = $this->data['process_order'];
|
||||
$updatedQty = (float) $this->data['updated_order_quantity'];
|
||||
|
||||
ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->update([
|
||||
'updated_order_quantity' => $updatedQty,
|
||||
'updated_by' => Filament::auth()->user()->name,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,13 +3,78 @@
|
||||
namespace App\Filament\Resources\ProcessOrderResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ProcessOrderResource;
|
||||
use App\Models\ProcessOrder;
|
||||
use Filament\Actions;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditProcessOrder extends EditRecord
|
||||
{
|
||||
protected static string $resource = ProcessOrderResource::class;
|
||||
|
||||
protected function beforeSave(): void
|
||||
{
|
||||
$plantId = $this->data['plant_id'] ?? null;
|
||||
$processOrder = $this->data['process_order'] ?? null;
|
||||
$extraQty = (float) ($this->data['updated_order_quantity'] ?? 0);
|
||||
$extraQtyRaw = $this->data['updated_order_quantity'] ?? '';
|
||||
|
||||
if (!preg_match('/^\d+(\.\d{1,3})?$/', $extraQtyRaw)) {
|
||||
Notification::make()
|
||||
->title('Invalid Quantity')
|
||||
->body('Only positive numbers with up to 3 decimal places are allowed.')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
$this->halt(); // stop save
|
||||
}
|
||||
|
||||
if ($extraQty < 0)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Invalid Quantity')
|
||||
->body('Negative values are not allowed.')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
$this->halt();
|
||||
}
|
||||
|
||||
if ($extraQty > 0) {
|
||||
|
||||
$order = ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->first();
|
||||
|
||||
if ($order) {
|
||||
|
||||
$baseQty = (float) $order->order_quantity;
|
||||
$maxAllowed = $baseQty * 0.10;
|
||||
|
||||
$maxFinalQty = $baseQty + $maxAllowed;
|
||||
|
||||
if ($extraQty > $maxFinalQty) {
|
||||
Notification::make()
|
||||
->title('Limit Exceeded')
|
||||
->body("You can only increase the order by 10% (Max allowed: {$maxFinalQty}).")
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
$this->halt(); // stops save
|
||||
}
|
||||
|
||||
ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->update([
|
||||
'updated_order_quantity' => $extraQty,
|
||||
'updated_by' => Filament::auth()->user()?->name,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -437,7 +437,7 @@ class ProductionPlanResource extends Resource
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('line.name')
|
||||
->label('Plant')
|
||||
->label('Line')
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->searchable(),
|
||||
@@ -476,7 +476,6 @@ class ProductionPlanResource extends Resource
|
||||
// ->label('Shift')
|
||||
// ->alignCenter()
|
||||
// ->sortable(), // ->searchable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->dateTime()
|
||||
|
||||
@@ -158,9 +158,6 @@ class EditRfqTransporterBid extends EditRecord
|
||||
$body
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
|
||||
@@ -15,6 +15,9 @@ use Storage;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Livewire\Livewire;
|
||||
use Str;
|
||||
use Firebase\JWT\JWT;
|
||||
use Firebase\JWT\Key;
|
||||
|
||||
|
||||
class CreateSerialValidation extends CreateRecord
|
||||
{
|
||||
@@ -67,6 +70,8 @@ class CreateSerialValidation extends CreateRecord
|
||||
|
||||
$invoiceNumber = trim($invoiceNumber);
|
||||
|
||||
$parts = explode('.', $invoiceNumber);
|
||||
|
||||
$this->showCapacitorInput = false;
|
||||
|
||||
$user = Filament::auth()->user();
|
||||
@@ -90,9 +95,60 @@ class CreateSerialValidation extends CreateRecord
|
||||
|
||||
//..GET SERIAL INVOICE API
|
||||
|
||||
// $decodedJwt = JWT::decode($invoiceNumber, new Key('dummy_key', 'HS256')); // replace 'dummy_key' with actual key if needed
|
||||
|
||||
// if (!$decodedJwt || !isset($decodedJwt->data)) {
|
||||
// Notification::make()
|
||||
// ->title("Invalid e-Invoice QR data or format received...")
|
||||
// ->info()
|
||||
// ->seconds(1)
|
||||
// ->send();
|
||||
// return;
|
||||
// }
|
||||
|
||||
// $documentData = $decodedJwt->data; // This should be JSON string containing DocNo
|
||||
|
||||
// // Extract DocNo using regex
|
||||
// preg_match('/"DocNo"\s*:\s*"([^"]+)"/', $documentData, $matches);
|
||||
// if (isset($matches[1])) {
|
||||
// $this->invoiceNumber = $matches[1];
|
||||
// } else {
|
||||
// Notification::make()
|
||||
// ->title("DocNo not found in QR data...")
|
||||
// ->info()
|
||||
// ->seconds(1)
|
||||
// ->send();
|
||||
// return;
|
||||
// }
|
||||
//..
|
||||
|
||||
// Decode JWT payload
|
||||
$payloadJson = base64_decode(strtr($parts[1], '-_', '+/'));
|
||||
|
||||
|
||||
$payload = json_decode($payloadJson, true);
|
||||
|
||||
|
||||
if (!isset($payload['data'])) {
|
||||
throw new \Exception('Invalid payload');
|
||||
}
|
||||
|
||||
$documentData = $payload['data'];
|
||||
|
||||
|
||||
|
||||
// Extract DocNo
|
||||
preg_match('/"DocNo"\s*:\s*"([^"]+)"/', $documentData, $matches);
|
||||
|
||||
if (!isset($matches[1])) {
|
||||
// throw new \Exception('DocNo not found');
|
||||
}
|
||||
|
||||
if (isset($matches[1])) {
|
||||
$invoiceNumber = $matches[1];
|
||||
//dd($invoiceNumber);
|
||||
}
|
||||
|
||||
$updateStatus = $this->form->getState()['update_invoice'] ?? null;
|
||||
|
||||
$this->invoiceNumber = trim($this->form->getState()['invoice_number']) ?? $invoiceNumber;
|
||||
|
||||
@@ -124,36 +124,57 @@ class StickerStructureDetailResource extends Resource
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')
|
||||
->label('ID')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('No.')
|
||||
->label('No.')
|
||||
->getStateUsing(function ($record, $livewire, $column, $rowLoop) {
|
||||
$paginator = $livewire->getTableRecords();
|
||||
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
|
||||
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
|
||||
|
||||
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('plant.code')
|
||||
->label('Plant Code')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('itemCharacteristic.item.code')
|
||||
->label('Item')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('sticker_id')
|
||||
->label('Sticker ID'),
|
||||
->label('Sticker ID')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('sticker_width')
|
||||
->label('Sticker Width'),
|
||||
->label('Sticker Width')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('sticker_height')
|
||||
->label('Sticker Height'),
|
||||
->label('Sticker Height')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('sticker_lmargin')
|
||||
->label('Sticker Left Margin'),
|
||||
->label('Sticker Left Margin')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('sticker_rmargin')
|
||||
->label('Sticker Right Margin'),
|
||||
->label('Sticker Right Margin')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('sticker_tmargin')
|
||||
->label('Sticker Top Margin'),
|
||||
->label('Sticker Top Margin')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('sticker_bmargin')
|
||||
->label('Sticker Bottom Margin'),
|
||||
->label('Sticker Bottom Margin')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->alignCenter()
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->label('Updated At')
|
||||
->alignCenter()
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('deleted_at')
|
||||
->label('Deleted At')
|
||||
->alignCenter()
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
|
||||
@@ -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