Added seperate method for random serial generation
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 15s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 18s
Laravel Pint / pint (pull_request) Successful in 4m49s
Laravel Larastan / larastan (pull_request) Failing after 6m39s
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 15s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 18s
Laravel Pint / pint (pull_request) Successful in 4m49s
Laravel Larastan / larastan (pull_request) Failing after 6m39s
This commit is contained in:
@@ -25,6 +25,8 @@ use Filament\Forms\Components\Section;
|
|||||||
use Filament\Forms\Components\Select;
|
use Filament\Forms\Components\Select;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Livewire\Attributes\On;
|
||||||
|
use Filament\Forms\Set;
|
||||||
|
|
||||||
class BulkStickerPrinting extends Page implements HasForms
|
class BulkStickerPrinting extends Page implements HasForms
|
||||||
{
|
{
|
||||||
@@ -36,12 +38,19 @@ class BulkStickerPrinting extends Page implements HasForms
|
|||||||
|
|
||||||
public array $filters = [];
|
public array $filters = [];
|
||||||
|
|
||||||
|
public array $serialNumbers = [''];
|
||||||
|
|
||||||
public $serNo;
|
public $serNo;
|
||||||
|
|
||||||
public $ref_number;
|
public $ref_number;
|
||||||
|
|
||||||
//public $workCenter;
|
//public $workCenter;
|
||||||
|
|
||||||
|
public function mount(): void
|
||||||
|
{
|
||||||
|
$this->form->fill();
|
||||||
|
}
|
||||||
|
|
||||||
public function form(Form $form): Form
|
public function form(Form $form): Form
|
||||||
{
|
{
|
||||||
return $form
|
return $form
|
||||||
@@ -85,8 +94,7 @@ class BulkStickerPrinting extends Page implements HasForms
|
|||||||
TextInput::make('production_order')
|
TextInput::make('production_order')
|
||||||
->label('Production Order')
|
->label('Production Order')
|
||||||
->reactive()
|
->reactive()
|
||||||
->readOnly()
|
->readOnly(),
|
||||||
->required(),
|
|
||||||
// ->afterStateUpdated(function ($state, callable $set, $get) {
|
// ->afterStateUpdated(function ($state, callable $set, $get) {
|
||||||
|
|
||||||
// for ($i = 1; $i <= 8; $i++) {
|
// for ($i = 1; $i <= 8; $i++) {
|
||||||
@@ -979,6 +987,7 @@ class BulkStickerPrinting extends Page implements HasForms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function generateStickerId()
|
public function generateStickerId()
|
||||||
{
|
{
|
||||||
$state = $this->form->getState();
|
$state = $this->form->getState();
|
||||||
@@ -1432,6 +1441,378 @@ class BulkStickerPrinting extends Page implements HasForms
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[On('generate-sticker-id')]
|
||||||
|
public function generateStickerId2(string $serialNumbers)
|
||||||
|
{
|
||||||
|
$state = $this->form->getState();
|
||||||
|
|
||||||
|
$plantId = trim($state['plant_id'] ?? '');
|
||||||
|
|
||||||
|
$machineId = trim($state['machine_id'] ?? '');
|
||||||
|
|
||||||
|
$stickerId = $state['sticker_id'] ?? null;
|
||||||
|
|
||||||
|
$pOrder = $state['production_order'] ?? null;
|
||||||
|
|
||||||
|
$fromSno = trim($state['from_serial_number'] ?? '');
|
||||||
|
|
||||||
|
$toSno = trim($state['to_serial_number'] ?? '');
|
||||||
|
|
||||||
|
$serialNumbersArray = array_filter(array_map('trim', explode(',', $serialNumbers)));
|
||||||
|
|
||||||
|
if (count($serialNumbersArray) > 50) {
|
||||||
|
Notification::make()
|
||||||
|
->title('Too Many Serial Numbers')
|
||||||
|
->body('You can enter a maximum of 50 serial numbers.')
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$plantName = Plant::where('id', $plantId)->value('name');
|
||||||
|
|
||||||
|
if (!$stickerId) {
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->danger()
|
||||||
|
->title('Sticker ID Not Selected')
|
||||||
|
->body('Please Choose a Sticker ID.')
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pOrderExist = ClassCharacteristic::where('plant_id',$plantId)->where('aufnr', $pOrder)->first();
|
||||||
|
|
||||||
|
if(!$pOrderExist){
|
||||||
|
Notification::make()
|
||||||
|
->danger()
|
||||||
|
->title('Unknown Production Order')
|
||||||
|
->body("Production Order '$pOrder' not found.")
|
||||||
|
->send();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($pOrderExist){
|
||||||
|
|
||||||
|
$existingSerialNumbers = ClassCharacteristic::where('plant_id', $plantId)
|
||||||
|
->where('aufnr', $pOrder)
|
||||||
|
->whereIn('gernr', $serialNumbersArray)
|
||||||
|
->pluck('gernr')
|
||||||
|
->map(fn ($value) => trim((string) $value))
|
||||||
|
->unique()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
$invalidSerialNumbers = array_values(
|
||||||
|
array_diff($serialNumbersArray, $existingSerialNumbers)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!empty($invalidSerialNumbers)) {
|
||||||
|
Notification::make()
|
||||||
|
->danger()
|
||||||
|
->title('Unknown Serial Numbers')
|
||||||
|
->body(
|
||||||
|
"The following serial numbers do not belong to Production Order '$pOrder' "
|
||||||
|
. "for plant '$plantName': "
|
||||||
|
. implode(', ', $invalidSerialNumbers)
|
||||||
|
)
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$existingStickers = StickerOrder::where('plant_id', $plantId)
|
||||||
|
->where('production_order', $pOrder)
|
||||||
|
->where('sticker_id', $stickerId)
|
||||||
|
->where('print_status', 'Printed')
|
||||||
|
->whereIn('serial_number', $serialNumbersArray)
|
||||||
|
->pluck('serial_number')
|
||||||
|
->unique()
|
||||||
|
->values()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
if (!empty($existingStickers)) {
|
||||||
|
Notification::make()
|
||||||
|
->danger()
|
||||||
|
->title('Duplicate Sticker')
|
||||||
|
->body("The following serial numbers already exist in generated stickers for ". "Sticker '$stickerId', Production Order '$pOrder', and plant '$plantName': ". implode(', ', $existingStickers))
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$structure = StickerStructureDetail::where('sticker_id',$stickerId)->first();
|
||||||
|
|
||||||
|
if (!$structure) {
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->danger()
|
||||||
|
->title('Sticker Structure Not Found')
|
||||||
|
->body("No sticker structure found for sticker ID '{$stickerId}'.")
|
||||||
|
->send();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//.New Logic
|
||||||
|
|
||||||
|
$stickerMappingMasterItems = StickerMappingMaster::where('plant_id', $plantId)->where('item_id', $pOrderExist->item_id)->get();
|
||||||
|
|
||||||
|
if ($stickerMappingMasterItems->isEmpty()) {
|
||||||
|
Notification::make()
|
||||||
|
->danger()
|
||||||
|
->title('Sticker Mapping Not Found')
|
||||||
|
->body("No sticker mapping found for plant ID '{$plantId}'.")
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$structureIds = $stickerMappingMasterItems
|
||||||
|
->flatMap(function ($mapping) {
|
||||||
|
$ids = [];
|
||||||
|
|
||||||
|
for ($i = 1; $i <= 8; $i++) {
|
||||||
|
$column = "sticker_structure{$i}_id";
|
||||||
|
|
||||||
|
if (!empty($mapping->{$column})) {
|
||||||
|
$ids[] = $mapping->{$column};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ids;
|
||||||
|
})
|
||||||
|
->unique()
|
||||||
|
->values();
|
||||||
|
|
||||||
|
$detailsById = StickerStructureDetail::whereIn('id', $structureIds)
|
||||||
|
->get()
|
||||||
|
->keyBy('id');
|
||||||
|
|
||||||
|
$structure = null;
|
||||||
|
$stickerMappingMasterItem = null;
|
||||||
|
|
||||||
|
foreach ($stickerMappingMasterItems as $mapping) {
|
||||||
|
for ($i = 1; $i <= 8; $i++) {
|
||||||
|
$column = "sticker_structure{$i}_id";
|
||||||
|
$structureId = $mapping->{$column};
|
||||||
|
|
||||||
|
if (empty($structureId)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$detail = $detailsById->get($structureId);
|
||||||
|
|
||||||
|
if (!$detail) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((string) $detail->sticker_id === (string) $stickerId) {
|
||||||
|
$structure = $detail;
|
||||||
|
$stickerMappingMasterItem = $mapping;
|
||||||
|
break 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$structure) {
|
||||||
|
Notification::make()
|
||||||
|
->danger()
|
||||||
|
->title('Sticker Mapping Not Found')
|
||||||
|
->body("No mapping found for sticker ID '{$stickerId}' and plant ID '{$plantId}'.")
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// $checkItem = StickerMappingMaster::where('plant_id', $plantId)->where('item_id', $pOrderExist->item_id)->where('sticker_structure1_id', $structure->id)->first();
|
||||||
|
|
||||||
|
$itemCode = Item::where('id', $pOrderExist->item_id)->value('code');
|
||||||
|
|
||||||
|
$plantCode = Plant::where('id', $plantId)->value('code');
|
||||||
|
|
||||||
|
// if (!$checkItem) {
|
||||||
|
|
||||||
|
// Notification::make()
|
||||||
|
// ->danger()
|
||||||
|
// ->title('Item Not Found')
|
||||||
|
// ->body("Item code '$itemCode' not found in sticker mapping master for selected sticker ID '{$stickerId}'.")
|
||||||
|
// ->send();
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
$itemCharacteristic1 = ClassCharacteristic::where('plant_id', $plantId)->where('aufnr', $pOrder)->where('item_id', $pOrderExist->item_id)->first();
|
||||||
|
|
||||||
|
if (!$itemCharacteristic1) {
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->danger()
|
||||||
|
->title('Item Not Found')
|
||||||
|
->body("Item code '{$itemCode}' was not found against job number '$pOrder' in class characteristic.")
|
||||||
|
->send();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$matchedMachineId = null;
|
||||||
|
|
||||||
|
for ($i = 1; $i <= 8; $i++) {
|
||||||
|
|
||||||
|
$structureColumn = "sticker_structure{$i}_id";
|
||||||
|
$machineColumn = "sticker{$i}_machine_id";
|
||||||
|
|
||||||
|
$mappedStructureId = $stickerMappingMasterItem->{$structureColumn} ?? null;
|
||||||
|
|
||||||
|
if (
|
||||||
|
$mappedStructureId !== null &&
|
||||||
|
(string) $mappedStructureId === (string) $structure->id
|
||||||
|
) {
|
||||||
|
$matchedMachineId = $stickerMappingMasterItem->{$machineColumn} ?? null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$selectedMachineId = trim((string) $machineId);
|
||||||
|
$mappedMachineId = trim((string) $matchedMachineId);
|
||||||
|
|
||||||
|
if ($mappedMachineId === '' || $mappedMachineId !== $selectedMachineId) {
|
||||||
|
Notification::make()
|
||||||
|
->danger()
|
||||||
|
->title('Machine Mapping Mismatch')
|
||||||
|
->body("Selected machine '{$selectedMachineId}' does not match the mapped machine '{$mappedMachineId}'.")
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$itemCharacteristic = ClassCharacteristic::where('plant_id', $plantId)
|
||||||
|
->where('item_id', $pOrderExist->item_id)
|
||||||
|
->where('machine_id', $machineId)
|
||||||
|
->where('aufnr', $pOrder)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if(!$itemCharacteristic){
|
||||||
|
Notification::make()
|
||||||
|
->danger()
|
||||||
|
->title('Record Not Found')
|
||||||
|
->body("Record not found in class characteristic against job '$pOrder', item '$itemCode' and plant '$plantCode'.")
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$elements = StickerDetail::where('sticker_structure_detail_id',$structure->id)->get();
|
||||||
|
|
||||||
|
if ($elements->isEmpty()) {
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->danger()
|
||||||
|
->title('Sticker Details Not Found')
|
||||||
|
->body('No sticker details configured for the selected sticker.')
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$stickerService = new StickerPdfService();
|
||||||
|
|
||||||
|
$template = $stickerService->generateTemplate(
|
||||||
|
$structure->sticker_id,
|
||||||
|
$elements,
|
||||||
|
$itemCharacteristic,
|
||||||
|
$itemCode,
|
||||||
|
$plantId,
|
||||||
|
$machineId
|
||||||
|
);
|
||||||
|
|
||||||
|
$pdfContent = $stickerService->generateMultipleBulkFromTemplate(
|
||||||
|
$template,
|
||||||
|
$serialNumbersArray,
|
||||||
|
$itemCode,
|
||||||
|
);
|
||||||
|
|
||||||
|
$fileName = 'bulk_sticker_'. '_'. uniqid(). '.pdf';
|
||||||
|
|
||||||
|
$tempPdfPath = storage_path('app/' . $fileName);
|
||||||
|
|
||||||
|
file_put_contents(
|
||||||
|
$tempPdfPath,
|
||||||
|
$pdfContent
|
||||||
|
);
|
||||||
|
|
||||||
|
$pdfUrl = route(
|
||||||
|
'sticker.preview',
|
||||||
|
[
|
||||||
|
'path' => $fileName,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->dispatch('open-sticker-pdf',urls: [$pdfUrl]);
|
||||||
|
|
||||||
|
$totalStickers = count($serialNumbersArray);
|
||||||
|
|
||||||
|
$item = Item::where('id', $pOrderExist->item_id)->where('plant_id', $plantId)->first();
|
||||||
|
|
||||||
|
foreach ($serialNumbersArray as $serialNumber) {
|
||||||
|
|
||||||
|
$serialNumber = trim($serialNumber);
|
||||||
|
|
||||||
|
$exists = StickerOrder::where('plant_id', $plantId)
|
||||||
|
->where('production_order', $pOrder)
|
||||||
|
->where('sticker_id', $stickerId)
|
||||||
|
->where('serial_number', $serialNumber)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$exists) {
|
||||||
|
StickerOrder::create([
|
||||||
|
'plant_id' => $plantId,
|
||||||
|
'item_id' => $item->id,
|
||||||
|
'production_order' => $pOrder,
|
||||||
|
'serial_number' => $serialNumber,
|
||||||
|
'sticker_id' => $stickerId,
|
||||||
|
'print_status' => 'Printed',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->success()
|
||||||
|
->title('Sticker Generated')
|
||||||
|
->body("{$totalStickers} sticker(s) generated successfully.")
|
||||||
|
->seconds(3)
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[On('production-order-updated')]
|
||||||
|
public function updateProductionOrder(string $productionOrder): void
|
||||||
|
{
|
||||||
|
$this->filters['production_order'] = $productionOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[On('sticker-options')]
|
||||||
|
public function stickerStructure(array $stickerOptions): void
|
||||||
|
{
|
||||||
|
$this->filters['sticker_options'] = $stickerOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[On('production-order-clear')]
|
||||||
|
public function updateProductionOrderClear(): void
|
||||||
|
{
|
||||||
|
$this->filters['production_order'] = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[On('sticker-options-clear')]
|
||||||
|
public function stickerStructureClear(): void
|
||||||
|
{
|
||||||
|
$this->filters['sticker_options'] = null;
|
||||||
|
}
|
||||||
|
|
||||||
public static function canAccess(): bool
|
public static function canAccess(): bool
|
||||||
{
|
{
|
||||||
return Auth::check() && Auth::user()->can('view sticker bulk print page');
|
return Auth::check() && Auth::user()->can('view sticker bulk print page');
|
||||||
|
|||||||
Reference in New Issue
Block a user