Changed over all logic against class characteristics table in bulk sticker printing page
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 16s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 12s
Laravel Larastan / larastan (pull_request) Failing after 35s
Laravel Pint / pint (pull_request) Failing after 45s
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 16s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 12s
Laravel Larastan / larastan (pull_request) Failing after 35s
Laravel Pint / pint (pull_request) Failing after 45s
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\Item;
|
||||
use App\Models\ItemCharacteristic;
|
||||
use App\Models\ClassCharacteristic;
|
||||
use App\Models\Machine;
|
||||
use App\Models\Plant;
|
||||
use App\Models\ProductionOrder;
|
||||
@@ -94,8 +94,13 @@ class BulkStickerPrinting extends Page implements HasForms
|
||||
return;
|
||||
}
|
||||
|
||||
$plantid = $get('plant_id');
|
||||
$machineId = $get('machine_id');
|
||||
|
||||
$plantName = Plant::where('id', $plantid)->value('name');
|
||||
|
||||
$workCenter = Machine::where('id', $machineId)->value('work_center');
|
||||
|
||||
if (empty($machineId)) {
|
||||
Notification::make()
|
||||
->title('Work Center not selected')
|
||||
@@ -106,13 +111,12 @@ class BulkStickerPrinting extends Page implements HasForms
|
||||
return;
|
||||
}
|
||||
|
||||
$productionOrder = StickerOrder::where('production_order', $state)
|
||||
->first();
|
||||
$productionOrder = ClassCharacteristic::where('plant_id', $plantid)->where('machine_id', $machineId)->where('aufnr', $state)->first();
|
||||
|
||||
if (! $productionOrder) {
|
||||
Notification::make()
|
||||
->title('Production Order not found')
|
||||
->body("Production Order '{$state}' was not found.")
|
||||
->body("Production Order '{$state}' was not found against machine '$workCenter' and plant '$plantName'.")
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
@@ -127,7 +131,7 @@ class BulkStickerPrinting extends Page implements HasForms
|
||||
if (! $item) {
|
||||
Notification::make()
|
||||
->title('Item not found')
|
||||
->body("Item ID '{$itemId}' was not found in item master.")
|
||||
->body("Item code '{$itemId}' was not found in item master.")
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
@@ -148,12 +152,12 @@ class BulkStickerPrinting extends Page implements HasForms
|
||||
return;
|
||||
}
|
||||
|
||||
$itemCharacteristic = ItemCharacteristic::where('plant_id', $plantId)->where('item_id', $item->id)->first();
|
||||
$itemCharacteristic = ClassCharacteristic::where('plant_id', $plantId)->where('item_id', $item->id)->first();
|
||||
|
||||
if (! $itemCharacteristic) {
|
||||
Notification::make()
|
||||
->title('Item characteristic not found')
|
||||
->body("No item characteristic found for item '{$itemCode}'.")
|
||||
->title('Class characteristic not found')
|
||||
->body("No class characteristic found for item '{$itemCode}'.")
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
@@ -162,13 +166,13 @@ class BulkStickerPrinting extends Page implements HasForms
|
||||
$itemCharacteristicId = $itemCharacteristic->id;
|
||||
|
||||
$stickerMappings = StickerMappingMaster::where('plant_id', $plantId)
|
||||
->where('item_characteristic_id', $itemCharacteristicId)
|
||||
->where('item_id', $item->id)
|
||||
->get();
|
||||
|
||||
if (! $stickerMappings) {
|
||||
Notification::make()
|
||||
->title('Sticker mapping not found')
|
||||
->body("No sticker mapping found for this plant and item characteristic.")
|
||||
->body("No sticker mapping found for this plant and class characteristic.")
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
@@ -491,7 +495,7 @@ class BulkStickerPrinting extends Page implements HasForms
|
||||
|
||||
$itemId = $itemC->id;
|
||||
|
||||
$item = ItemCharacteristic::where('item_id', $itemId)
|
||||
$item = ClassCharacteristic::where('item_id', $itemId)
|
||||
->where('plant_id',$plantId)
|
||||
->first();
|
||||
|
||||
@@ -575,7 +579,7 @@ class BulkStickerPrinting extends Page implements HasForms
|
||||
|
||||
$structure = StickerStructureDetail::findOrFail($sticker['sticker_id']);
|
||||
|
||||
$itemCharacteristic = ItemCharacteristic::where('plant_id', $plantId)
|
||||
$itemCharacteristic = ClassCharacteristic::where('plant_id', $plantId)
|
||||
->where('id', $sticker['item_characteristic'])
|
||||
->firstOrFail();
|
||||
|
||||
@@ -832,6 +836,26 @@ class BulkStickerPrinting extends Page implements HasForms
|
||||
return;
|
||||
}
|
||||
|
||||
if (strlen($fromSno) < 9) {
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title('Invalid From Serial Number')
|
||||
->body("From Serial Number '$fromSno' should contain minimum 9 digits.")
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (strlen($toSno) < 9) {
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title('Invalid To Serial Number')
|
||||
->body("To Serial Number '$toSno' should contain minimum 9 digits.")
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$fromSerNo = (int) $fromSno;
|
||||
|
||||
$toSerNo = (int) $toSno;
|
||||
@@ -847,9 +871,9 @@ class BulkStickerPrinting extends Page implements HasForms
|
||||
return;
|
||||
}
|
||||
|
||||
$pOrderEx = StickerOrder::where('production_order', $pOrder)->first();
|
||||
$pOrderExist = ClassCharacteristic::where('plant_id',$plantId)->where('aufnr', $pOrder)->first();
|
||||
|
||||
if(!$pOrderEx){
|
||||
if(!$pOrderExist){
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title('Unknown Production Order')
|
||||
@@ -858,22 +882,20 @@ class BulkStickerPrinting extends Page implements HasForms
|
||||
return;
|
||||
}
|
||||
|
||||
$pOrderExist = StickerOrder::where('plant_id', $plantId)->where('production_order', $pOrder)->first();
|
||||
|
||||
if(!$pOrderExist){
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title('Unknown Production Order')
|
||||
->body("Production Order '$pOrder' not found against plant $plantName.")
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
if($pOrderExist){
|
||||
if((int) $pOrderExist->from_serial_number != $fromSerNo || (int) $pOrderExist->to_serial_number != $toSerNo){
|
||||
|
||||
$pOrderExistData = ClassCharacteristic::where('plant_id', $plantId)
|
||||
->where('aufnr', $pOrder)
|
||||
->pluck('gernr')
|
||||
->map(fn ($value) => (int) $value)
|
||||
->toArray();
|
||||
|
||||
if (!in_array((int) $fromSerNo, $pOrderExistData, true) || !in_array((int) $toSerNo, $pOrderExistData, true))
|
||||
{
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title('Unknown Serial Number')
|
||||
->body("The entered serial number range does not match Production Order '$pOrder' for plant '$plantName'.")
|
||||
->body("The entered serial number range does not match Production Order '$pOrder' for plant '$plantName' in class characteristic.")
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
@@ -890,6 +912,25 @@ class BulkStickerPrinting extends Page implements HasForms
|
||||
return;
|
||||
}
|
||||
|
||||
$existingSticker = StickerOrder::where('plant_id', $plantId)
|
||||
->where('production_order', $pOrder)
|
||||
->where('print_status', 'Printed')
|
||||
->where(function ($query) use ($fromSerNo, $toSerNo) {
|
||||
$query->whereIn('from_serial_number', [$fromSerNo, $toSerNo])
|
||||
->orWhereIn('to_serial_number', [$fromSerNo, $toSerNo]);
|
||||
})
|
||||
->first();
|
||||
|
||||
if ($existingSticker) {
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title('Duplicate Sticker')
|
||||
->body("Serial Number '$fromSerNo' or '$toSerNo' already exists in a generated sticker for Production Order '$pOrder' and plant '$plantName'.")
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$structure = StickerStructureDetail::where('sticker_id',$stickerId)->first();
|
||||
|
||||
@@ -904,6 +945,7 @@ class BulkStickerPrinting extends Page implements HasForms
|
||||
}
|
||||
|
||||
$stickerMappingMasterItems = StickerMappingMaster::where('plant_id', $plantId)->get();
|
||||
// dd($plantId, $stickerMappingMasterItems);
|
||||
|
||||
if (!$stickerMappingMasterItems) {
|
||||
|
||||
@@ -961,7 +1003,9 @@ class BulkStickerPrinting extends Page implements HasForms
|
||||
return;
|
||||
}
|
||||
|
||||
$itemCharacteristicId = $stickerMappingMasterItem->item_characteristic_id;
|
||||
$itemCharacteristicId = $stickerMappingMasterItem->item_id;
|
||||
|
||||
$itemCode = Item::where('id', $itemCharacteristicId)->value('code');
|
||||
|
||||
if (!$itemCharacteristicId) {
|
||||
|
||||
@@ -973,30 +1017,93 @@ class BulkStickerPrinting extends Page implements HasForms
|
||||
return;
|
||||
}
|
||||
|
||||
$itemCharacteristic = ItemCharacteristic::where('plant_id', $plantId)->where('id',$itemCharacteristicId)->first();
|
||||
$itemCharacteristic1 = ClassCharacteristic::where('plant_id', $plantId)->where('item_id',$itemCharacteristicId)->first();
|
||||
|
||||
if (!$itemCharacteristic) {
|
||||
if (!$itemCharacteristic1) {
|
||||
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title('Item Characteristic Not Found')
|
||||
->body("Item characteristic '{$itemCharacteristicId}' was not found.")
|
||||
->title('Item Not Found')
|
||||
->body("Item code '{$itemCode}' was not found in class characteristic.")
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
$itemCode = Item::where('id',$itemCharacteristic->item_id)->where('plant_id',$plantId)->value('code');
|
||||
$itemCharacteristicPodr = ClassCharacteristic::where('plant_id', $plantId)->where('aufnr', $pOrder)->where('item_id', $itemCharacteristicId)->first();
|
||||
|
||||
if (!$itemCharacteristicPodr) {
|
||||
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title('Item Not Found')
|
||||
->body("Item code '{$itemCode}' with Job Number '{$pOrder}' was not found against plant '{$plantName}'.")
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$itemCodeMis = $pOrderExist->item_id;
|
||||
|
||||
$itemCodeInPOrd = Item::where('id', $itemCodeMis)->where('plant_id', $plantId)->first();
|
||||
|
||||
$itemCodeInStickerMapping = Item::where('id', $itemCharacteristicId)->where('plant_id', $plantId)->first();
|
||||
|
||||
if($itemCodeMis != $itemCharacteristicId){
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title('Item Mismatch Found')
|
||||
->body("sticker mapping Item code '{$itemCodeInPOrd->code}' and item code '{$itemCodeInStickerMapping->code}' for Job Number '{$pOrder}' was not mapped in sticker mapping against plant '{$plantName}'.")
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$itemCode = Item::where('id', $itemCharacteristicId)->where('plant_id',$plantId)->value('code');
|
||||
|
||||
if (!$itemCode) {
|
||||
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title('Item Not Found')
|
||||
->body('No item code found for the selected item characteristic.')
|
||||
->body("Item code '{$itemCode}' found in item master.")
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
//..
|
||||
|
||||
$matchedMachineId = null;
|
||||
|
||||
for ($i = 1; $i <= 8; $i++) {
|
||||
|
||||
$machineColumn = "sticker{$i}_machine_id";
|
||||
|
||||
if ((string) $stickerMappingMasterItem->{$machineColumn} == (string) $machineId) {
|
||||
|
||||
$matchedMachineId = $stickerMappingMasterItem->{$machineColumn};
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$matchedMachineId) {
|
||||
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title('Machine Not Found')
|
||||
->body("Machine '{$machineId}' is not mapped for Item Code '{$itemCode}' in the selected sticker mapping.")
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
// dd($matchedMachineId);
|
||||
|
||||
$itemCharacteristic = ClassCharacteristic::where('plant_id', $plantId)
|
||||
->where('item_id', $itemCharacteristicId)
|
||||
->where('machine_id', $matchedMachineId)
|
||||
->where('aufnr', $pOrder)
|
||||
->first();
|
||||
|
||||
$elements = StickerDetail::where('sticker_structure_detail_id',$structure->id)->get();
|
||||
|
||||
if ($elements->isEmpty()) {
|
||||
@@ -1048,17 +1155,11 @@ class BulkStickerPrinting extends Page implements HasForms
|
||||
|
||||
$totalStickers = ($toSerNo - $fromSerNo) + 1;
|
||||
|
||||
$item = Item::where('id', $itemCharacteristic->item_id)->where('plant_id', $plantId)->first();
|
||||
$item = Item::where('id', $itemCharacteristicId)->where('plant_id', $plantId)->first();
|
||||
|
||||
$updatePrintStatus = StickerOrder::where('plant_id', $plantId)->where('production_order', $pOrder)->where('from_serial_number', $fromSerNo)->where('to_serial_number', $toSerNo)->first();
|
||||
|
||||
if ($updatePrintStatus->sticker_id == '' || $updatePrintStatus->sticker_id == null) {
|
||||
$updatePrintStatus->update([
|
||||
'sticker_id' => $stickerId,
|
||||
'print_status' => 'Printed',
|
||||
]);
|
||||
}
|
||||
else {
|
||||
if (!$updatePrintStatus) {
|
||||
StickerOrder::create([
|
||||
'plant_id' => $plantId,
|
||||
'item_id' => $item->id,
|
||||
@@ -1068,14 +1169,17 @@ class BulkStickerPrinting extends Page implements HasForms
|
||||
'sticker_id' => $stickerId,
|
||||
'print_status' => 'Printed',
|
||||
]);
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('Sticker Generated')
|
||||
->body("{$totalStickers} sticker(s) generated successfully.")
|
||||
->seconds(3)
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function canAccess(): bool
|
||||
|
||||
Reference in New Issue
Block a user