'handleUpdateSnoQuantity',
];
public function handleUpdateSnoQuantity($newValue)
{
$this->form->fill([
'Sno_quantity' => $newValue,
]);
}
public function processOrderSNo(){
$plantId = $this->form->getState()['plant_id'];
$plantId = trim($plantId) ?? null;
$processOrder = trim($this->form->getState()['process_order'])?? null;
$customerPo = trim($this->form->getState()['customer_po_master_id'])?? null;
$wirePackNo = trim($this->form->getState()['wire_packing_number'])?? null;
$wirePackNo = trim($wirePackNo) ?? null;
$user = Filament::auth()->user();
$operatorName = $user->name;
if (empty($processOrder) || $processOrder == '')
{
Notification::make()
->title("Process Order can't be empty")
->danger()
->duration(5000)
->send();
$this->form->fill([
'process_order' => null,
'plant_id' => $plantId,
'customer_po_master_id' => $customerPo,
'wire_packing_number' => $wirePackNo,
'Sno_quantity' => 0,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$pattern = '/^([^|]+)\|([^|]+)\|(\d+(\.\d+)?)$/';
if (!preg_match($pattern, $processOrder, $matches))
{
Notification::make()
->title("Scan Valid Qr code ")
->body("Expected Format : (MaterialCode|Process Order-Id|Weight)")
->danger()
->duration(5000)
->send();
$this->form->fill([
'process_order' => null,
'plant_id' => $plantId,
'customer_po_master_id' => $customerPo,
'wire_packing_number' => $wirePackNo,
'Sno_quantity' => 0,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$materialCode = $matches[1];
$processOrderId = $matches[2];
$weight = $matches[3];
$icode = Item::where('code', $materialCode)->first();
if(!$icode)
{
Notification::make()
->title("Unknown Item Code")
->body("Item Code not found '$materialCode'")
->danger()
->duration(5000)
->send();
$this->form->fill([
'process_order' => null,
'plant_id' => $plantId,
'customer_po_master_id' => $customerPo,
'wire_packing_number' => $wirePackNo,
'Sno_quantity' => 0,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$icodeAgaPlant = Item::where('code', $materialCode)->where('plant_id', $plantId)->first();
$plantCode = Plant::where('id', $plantId)->first();
$plantcode = $plantCode->code;
$itemId = $icodeAgaPlant->id;
if(!$icodeAgaPlant)
{
Notification::make()
->title("Unknown Item Code")
->body("Item Code not found '$materialCode' against Plant Code '$plantcode'")
->danger()
->duration(5000)
->send();
$this->form->fill([
'process_order' => null,
'plant_id' => $plantId,
'customer_po_master_id' => $customerPo,
'wire_packing_number' => $wirePackNo,
'Sno_quantity' => 0,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$processOrderAgaPlant = WireMasterPacking::where('process_order', $processOrderId)->where('plant_id', $plantId)->first();
if($processOrderAgaPlant)
{
Notification::make()
->title("Duplicate Process Order")
->body("Duplicate process order found '$processOrderId' against Plant Code '$plantcode'")
->danger()
->duration(5000)
->send();
$this->form->fill([
'process_order' => null,
'plant_id' => $plantId,
'customer_po_master_id' => $customerPo,
'wire_packing_number' => $wirePackNo,
'Sno_quantity' => 0,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
try
{
$existingPallet = WireMasterPacking::where('plant_id', $plantId)
->where('wire_packing_number', $wirePackNo)
->first();
$count = WireMasterPacking::where('plant_id', $plantId)
->where('wire_packing_number', $wirePackNo)
->count('wire_packing_number');
$createdAt = $existingPallet ? $existingPallet->created_at : $clickedAt ?? now();
$createdBy = $existingPallet ? $existingPallet->created_by : $clickedBy ?? $operatorName;
$record = WireMasterPacking::create([
'plant_id' => $plantId,
'item_id' => $itemId,
'wire_packing_number' => $wirePackNo,
'process_order' => $processOrderId,
'customer_po_master_id' => $customerPo,
'weight' => $weight,
'created_by' => $createdBy,
'scanned_by' => $operatorName,
'created_at' => $createdAt,
'scanned_at' => now(),
'updated_by' => $operatorName,
]);
if ($record)
{
$this->snoCount = WireMasterPacking::where('plant_id', $plantId)
->where('wire_packing_number', $wirePackNo)
->count();
$this->dispatch('loadData', $wirePackNo, $plantId);
$this->form->fill([
'plant_id' => $plantId,
'customer_po_master_id' => $customerPo,
'wire_packing_number' => $wirePackNo,
'process_order' => null,
// 'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $this->snoCount,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
}
else
{
Notification::make()
->title("Failed to insert scanned serial number '$processOrderId' into wire master table!")
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $wirePackNo, $plantId);
$this->form->fill([
'plant_id' => $plantId,
'customer_po_master_id' => $customerPo,
'wire_packing_number' => $wirePackNo,
'process_order' => null,
// 'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'scanned_by' => $operatorName,
]);
return;
}
}
catch (\Exception $e)
{
Notification::make()
->title('Error: Serial not inserted.')
->body("Something went wrong while inserting process order '{$processOrderId}' into pallet table!\nScan the new process order to proceed...")
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $wirePackNo, $plantId);
$this->form->fill([
'plant_id' => $plantId,
'customer_po_master_id' => $customerPo,
'wire_packing_number' => $wirePackNo,
'process_order' => null,
// 'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$this->dispatch('loadData', $wirePackNo, $plantId);
}
public function markAsComplete()
{
$plantId = $this->form->getState()['plant_id'];
$plantId = trim($plantId) ?? null;
$pendingPallet = $this->form->getState()['pending_pallet_list'];
$palletNumber = trim($this->form->getState()['wire_packing_number'])?? null;
$palletNumber = trim($palletNumber) ?? null;
$processOrder = trim($this->form->getState()['process_order'])?? null;
$processOrder = trim($processOrder) ?? null;
$user = Filament::auth()->user();
$operatorName = $user->name;
$isCompleted = $this->data['is_completed'] ?? false;
// $this->pendingPallet = $this->form->getState()['pending_pallet_list'];
if (! ($this->data['is_completed'] ?? false)) {
Notification::make()
->title('Completion required')
->body('Please check the "Is Completed" checkbox to finish master packing.')
->warning()
->duration(3000)
->send();
return;
}
$palletExist = WireMasterPacking::where('wire_packing_number', $palletNumber)
->where('plant_id', $plantId)
->first();
if (!$palletExist)
{
Notification::make()
->title("Pallet number '$palletNumber' does not have process orders to save!
Add the valid process order into pallet number to proceed...")
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'process_order' => null,
'plant_id' => $plantId,
'wire_packing_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => 0,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$allCompleted = WireMasterPacking::where('plant_id', $plantId)
->where('wire_packing_number', $palletNumber)
->where('wire_packing_status', '=','Completed')
->first();
if ($allCompleted)
{
Notification::make()
->title("Master Packing pallet number '$palletNumber' already completed the master packing!
Generate the new Master Packing Pallet number or choose from pending pallet list!")
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', '', $plantId);
$this->form->fill([
'process_order' => null,
'plant_id' => $plantId,
'wire_packing_number' => null,
'pending_pallet_list' => null,//$pendingPallet
'Sno_quantity' => 0,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
// $count = PalletValidation::where('plant_id', $plantId)
// ->where('pallet_number', $palletNumber)
// ->count('pallet_number');
if (!$isCompleted)
{
$updated = WireMasterPacking::where('wire_packing_number', $palletNumber)
->where('plant_id', $plantId)
->update([
'updated_at' => now(),
'updated_by' => $operatorName,
]);
if ($updated > 0)
{
Notification::make()
->title("Pallet number '$palletNumber' records saved successfully!")
->success()
->duration(800)
->send();
$this->dispatch('loadData', '', $plantId);
$this->form->fill([
'process_order' => null,
'plant_id' => $plantId,
'wire_packing_number' => null,//$palletNumber
'pending_pallet_list' => null,//$pendingPallet
'Sno_quantity' => 0,//$count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
}
else
{
$updated = WireMasterPacking::where('wire_packing_number', $palletNumber)
->where('plant_id', $plantId)
->update([
'wire_packing_status' => 'Completed',
'updated_at' => now(),
'updated_by' => $operatorName,
]);
if ($updated > 0)
{
Notification::make()
->title("Pallet number '$palletNumber' completed the master packing successfully!")
->success()
->duration(800)
->send();
$this->dispatch('loadData', '', $plantId);
$this->form->fill([
'process_order' => null,
'plant_id' => $plantId,
'wire_packing_number' => null,//$palletNumber
'pending_pallet_list' => null,//$pendingPallet
'Sno_quantity' => 0,//$count
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
}
}
public function processPalletNo()
{
$plantId = $this->form->getState()['plant_id'];
$plantId = trim($plantId) ?? null;
$pendingPallet = $this->form->getState()['pending_pallet_list'];
$palletNumber = trim($this->form->getState()['wire_packing_number']) ?? null;
$customerPo = trim($this->form->getState()['customer_po_master_id'])?? null;
$palletNumber = trim($palletNumber) ?? null;
$processOrder = trim($this->form->getState()['process_order']) ?? null;
$processOrder = trim($processOrder) ?? null;
$user = Filament::auth()->user();
$operatorName = $user->name;
//$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'customer_po_master_id' => $customerPo,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => 0,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
if (!$palletNumber)
{
Notification::make()
->title('Pallet number is required.')
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', '', $plantId);
$this->form->fill([
'process_order' => null,
'plant_id' => $plantId,
'customer_po_master_id' => $customerPo,
'wire_packing_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => 0,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
if (strlen($palletNumber) < 10)
{
Notification::make()
->title("Pallet number '$palletNumber' must be at least 10 digits.")
->danger()
->duration(5000)
->send();
$this->dispatch('loadLocator' ,'',$plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'customer_po_master_id' => $customerPo,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => 0,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$count = WireMasterPacking::where('plant_id', $plantId)
->where('wire_packing_number', $palletNumber)
->count('wire_packing_number');
$palletNotCompleted = WireMasterPacking::where('plant_id', $plantId)
->where('wire_packing_number', $palletNumber)
->where('wire_packing_status', '=','')
->orWhere('wire_packing_status', '=',null)
->first();
if (!$palletNotCompleted)
{
Notification::make()
->title("Already completed for pallet number $palletNumber!")
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'process_order' => null,
'plant_id' => $plantId,
'customer_po_master_id' => $customerPo,
'wire_packing_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$this->form->fill([
'process_order' => null,
'plant_id' => $plantId,
'customer_po_master_id' => $customerPo,
'wire_packing_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
$this->dispatch('loadData', $palletNumber, $plantId);
}
public function processRemoveSNo()
{
$plantId = $this->form->getState()['plant_id'];
$plantId = trim($plantId) ?? null;
$pendingPallet = $this->form->getState()['pending_pallet_list'];
$palletNumber = trim($this->form->getState()['wire_packing_number']) ?? null;
$customerPo = trim($this->form->getState()['customer_po_master_id'])?? null;
$palletNumber = trim($palletNumber) ?? null;
$processOrder = trim($this->form->getState()['removeSno_number']) ?? null;
$processOrder = trim($processOrder) ?? null;
$user = Filament::auth()->user();
$operatorName = $user->name;
if (!$palletNumber)
{
Notification::make()
->title('Master Pallet number is required to remove.')
->danger()
->duration(5000)
->send();
return;
}
$count = WireMasterPacking::where('plant_id', $plantId)
->where('wire_packing_number', $palletNumber)
->count('wire_packing_number');
if (!$processOrder)
{
Notification::make()
->title('Process order is required to remove.')
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'process_order' => null,
'plant_id' => $plantId,
'customer_po_master_id' => $customerPo,
'wire_packing_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$processOrderexist = WireMasterPacking::where('plant_id', $plantId)
->where('process_order', $processOrder)
->first();
if (!$processOrderexist)
{
Notification::make()
->title('Process Order not exists in pallet table.')
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'process_order' => null,
'plant_id' => $plantId,
'customer_po_master_id' => $customerPo,
'wire_packing_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$palletExist = WireMasterPacking::where('plant_id', $plantId)
->where('process_order', $processOrder)
->where('wire_packing_number', '!=', '')
->where('wire_packing_number', '!=', null)
->first();
if ($palletExist && $palletExist->wire_packing_number != $palletNumber)
{
Notification::make()
->title("Scanned process order number exist in pallet number '$palletExist->wire_packing_number'.
Scan the valid exist process order to remove!")
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'process_order' => null,
'plant_id' => $plantId,
'customer_po_master_id' => $customerPo,
'wire_packing_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$deleted = WireMasterPacking::where('plant_id', $plantId)
->where('wire_packing_number', $palletNumber)
->where('process_order', $processOrder)
->forceDelete();
if ($deleted)
{
// Notification::make()
// ->title("Scanned serial number '$serialNumber' successfully removed from pallet table!
Scan the next exist serial number to remove...")
// ->success()
// ->duration(600)
// ->send();
$this->snoCount = WireMasterPacking::where('plant_id', $plantId)
->where('wire_packing_number', $palletNumber)
->count();
$this->form->fill([
'plant_id' => $plantId,
'customer_po_master_id' => $customerPo,
'wire_packing_number' => $palletNumber,
'removeSno_number' => null,
'pending_pallet_list' => $this->pendingPallet,
'Sno_quantity' => $this->snoCount,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
$this->dispatch('loadData', $palletNumber, $plantId);
}
else
{
Notification::make()
->title("Failed to remove scanned process order '$processOrder' from master pallet!")
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'process_order' => null,
'plant_id' => $plantId,
'customer_po_master_id' => $customerPo,
'wire_packing_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
}
//$this->dispatch('removeSno', $serialNumber, $palletNumber, $plantId);
}
public function getFormActions(): array
{
return [];
}
}