Added spare packing resource pages
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
This commit is contained in:
@@ -0,0 +1,845 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SparePackingResource\Pages;
|
||||
|
||||
use App\Filament\Resources\SparePackingResource;
|
||||
use App\Models\Item;
|
||||
use App\Models\Plant;
|
||||
use App\Models\SaleOrderMaster;
|
||||
use Filament\Actions;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use App\Models\SparePacking;
|
||||
|
||||
class CreateSparePacking extends CreateRecord
|
||||
{
|
||||
|
||||
public $docNo;
|
||||
|
||||
public $saleOrder;
|
||||
|
||||
public $plantId;
|
||||
|
||||
public $count = 0;
|
||||
|
||||
public $snoCount = 0;
|
||||
|
||||
public $pendingPallet;
|
||||
|
||||
public array $importedSaleOrderList = [];
|
||||
|
||||
protected static string $resource = SparePackingResource::class;
|
||||
|
||||
protected static string $view = 'filament.resources.spare-packing-resource.create-spare-packing';
|
||||
|
||||
protected $listeners = [
|
||||
'updateSnoQuantity' => 'handleUpdateSnoQuantity',
|
||||
];
|
||||
|
||||
public function handleUpdateSnoQuantity($newValue)
|
||||
{
|
||||
$this->form->fill([
|
||||
'Sno_quantity' => $newValue,
|
||||
]);
|
||||
}
|
||||
|
||||
public function processDocNo(){
|
||||
|
||||
$plantId = $this->form->getState()['plant_id'];
|
||||
|
||||
$plantId = trim($plantId) ?? null;
|
||||
|
||||
$docNo = trim($this->form->getState()['document_number'])?? null;
|
||||
|
||||
$saleOrder = trim($this->form->getState()['sale_order_master_id'])?? null;
|
||||
|
||||
$sparePackNo = trim($this->form->getState()['spare_packing_number'])?? null;
|
||||
|
||||
$sparePackNo = trim($sparePackNo) ?? null;
|
||||
|
||||
$user = Filament::auth()->user();
|
||||
|
||||
$operatorName = $user->name;
|
||||
|
||||
if (empty($docNo) || $docNo == '')
|
||||
{
|
||||
Notification::make()
|
||||
->title("Document Number can't be empty")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
// $pattern = '/^([^|]+)\|([^|]+)\|([^|]+)\|(\d+(\.\d+)?)(kg)?$/i';
|
||||
|
||||
// $pattern = '/^([^|]+)\|([^|]+)\|([^|]+)\|(\d+(\.\d+)?)$/i';
|
||||
|
||||
$pattern = '/^([^|]+)\|([^|]+)\|(\d+(\.\d+)?)$/i';
|
||||
|
||||
if (!preg_match($pattern, $docNo, $matches))
|
||||
{
|
||||
Notification::make()
|
||||
->title("Scan Valid Qr code ")
|
||||
->body("Expected Format : (MaterialCode|Document Number|Quantity)")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$materialCode = $matches[1];
|
||||
$docNo = $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([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'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([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$icodeAgaCPoPlant = SaleOrderMaster::where('item_id', $itemId)->where('plant_id', $plantId)->first();
|
||||
|
||||
if(!$icodeAgaCPoPlant)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Unknown Item Code in Customer PO")
|
||||
->body("Item Code '$materialCode' not found in any active Customer PO against Plant Code '$plantcode'")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$processOrderAgaPlant = SparePacking::where('document_number', $docNo)->where('plant_id', $plantId)->first();
|
||||
|
||||
if($processOrderAgaPlant)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Duplicate Document Number")
|
||||
->body("Duplicate document number found '$docNo' against Plant Code '$plantcode'")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$saleOrderRecord = SaleOrderMaster::where('sale_order_number', $saleOrder)
|
||||
->where('plant_id', $plantId)
|
||||
->where('item_id', $itemId)
|
||||
->first();
|
||||
|
||||
if(!$saleOrderRecord)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Sale Order Not Found")
|
||||
->body("Sale Order '$saleOrder' for Item '$materialCode' not found against Plant '$plantcode'")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$alreadyScannedQty = SparePacking::where('sale_order_master_id', $saleOrderRecord->id)
|
||||
->where('plant_id', $plantId)
|
||||
->where('item_id', $itemId)
|
||||
->selectRaw('SUM(CAST(quantity AS NUMERIC)) as total_weight')
|
||||
->value('total_weight');
|
||||
|
||||
$totalQty = round((float)$alreadyScannedQty + (float)$weight, 3);
|
||||
|
||||
|
||||
if($totalQty > round((float)$saleOrderRecord->quantity, 3))
|
||||
{
|
||||
|
||||
Notification::make()
|
||||
->title("Scanned Quantity Exceeds Sale Order Quantity")
|
||||
->body("Scanned quantity '$weight' and already scanned quantity '$alreadyScannedQty' exceeds allowed quantity '{$saleOrderRecord->quantity}' for Sale Order '$saleOrderRecord->sale_order_number' and Item '$materialCode'")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'item_id' => $itemId,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
$existingPallet = SparePacking::where('plant_id', $plantId)
|
||||
->where('spare_packing_number', $sparePackNo)
|
||||
->first();
|
||||
|
||||
$count = SparePacking::where('plant_id', $plantId)
|
||||
->where('spare_packing_number', $sparePackNo)
|
||||
->count('spare_packing_number');
|
||||
|
||||
$createdAt = $existingPallet ? $existingPallet->created_at : $clickedAt ?? now();
|
||||
|
||||
$createdBy = $existingPallet ? $existingPallet->created_by : $clickedBy ?? $operatorName;
|
||||
|
||||
$record = SparePacking::create([
|
||||
'plant_id' => $plantId,
|
||||
'item_id' => $itemId,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'document_number' => $docNo,
|
||||
'sale_order_master_id' => $saleOrderRecord->id,
|
||||
'quantity' => $weight,
|
||||
'created_by' => $createdBy,
|
||||
'scanned_by' => $operatorName,
|
||||
'created_at' => $createdAt,
|
||||
'scanned_at' => now(),
|
||||
'updated_by' => $operatorName,
|
||||
]);
|
||||
|
||||
if ($record)
|
||||
{
|
||||
|
||||
$this->snoCount = SparePacking::where('plant_id', $plantId)
|
||||
->where('spare_packing_number', $sparePackNo)
|
||||
->count();
|
||||
|
||||
$this->dispatch('loadData', $sparePackNo, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'item_id' => $itemId,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'document_number' => 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 '$docNo' into wire master table!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $sparePackNo, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'item_id' => $itemId,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'document_number' => 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 document number '{$docNo}' into pallet table!\nScan the new document number to proceed...")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $sparePackNo, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'document_number' => null,
|
||||
// 'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => $count,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->dispatch('loadData', $sparePackNo, $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()['spare_packing_number'])?? null;
|
||||
|
||||
$palletNumber = trim($palletNumber) ?? null;
|
||||
|
||||
$processOrder = trim($this->form->getState()['document_number'])?? 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 = SparePacking::where('spare_packing_number', $palletNumber)
|
||||
->where('plant_id', $plantId)
|
||||
->first();
|
||||
|
||||
if (!$palletExist)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Pallet number '$palletNumber' does not have process orders to save!<br>Add the valid process order into pallet number to proceed...")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'spare_packing_number' => $palletNumber,
|
||||
'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$allCompleted = SparePacking::where('plant_id', $plantId)
|
||||
->where('spare_packing_number', $palletNumber)
|
||||
->where('spare_packing_status', '=','Completed')
|
||||
->first();
|
||||
|
||||
if ($allCompleted)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Spare Packing pallet number '$palletNumber' already completed the master packing!<br>Generate the new Spare Packing Pallet number or choose from pending pallet list!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', $plantId);
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'spare_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 = SparePacking::where('spare_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([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'spare_packing_number' => null,//$palletNumber
|
||||
'pending_pallet_list' => null,//$pendingPallet
|
||||
'Sno_quantity' => 0,//$count,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$updated = SparePacking::where('spare_packing_number', $palletNumber)
|
||||
->where('plant_id', $plantId)
|
||||
->update([
|
||||
'spare_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([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'spare_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()['spare_packing_number']) ?? null;
|
||||
|
||||
$saleOrder = trim($this->form->getState()['sale_order_master_id'])?? null;
|
||||
|
||||
$palletNumber = trim($palletNumber) ?? null;
|
||||
|
||||
$docNo = trim($this->form->getState()['document_number']) ?? null;
|
||||
|
||||
$docNo = trim($docNo) ?? null;
|
||||
|
||||
$user = Filament::auth()->user();
|
||||
|
||||
$operatorName = $user->name;
|
||||
|
||||
//$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'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([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_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,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $palletNumber,
|
||||
'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$count = SparePacking::where('plant_id', $plantId)
|
||||
->where('spare_packing_number', $palletNumber)
|
||||
->count('spare_packing_number');
|
||||
|
||||
$palletNotCompleted = SparePacking::where('plant_id', $plantId)
|
||||
->where('spare_packing_number', $palletNumber)
|
||||
->where('spare_packing_status', '=','')
|
||||
->orWhere('spare_packing_status', '=',null)
|
||||
->first();
|
||||
|
||||
if (!$palletNotCompleted)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Pallet number not found $palletNumber!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $palletNumber,
|
||||
'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => $count,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $palletNumber,
|
||||
'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => $count,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
|
||||
}
|
||||
|
||||
public function processRemoveDocNo()
|
||||
{
|
||||
$plantId = $this->form->getState()['plant_id'];
|
||||
|
||||
$plantId = trim($plantId) ?? null;
|
||||
|
||||
$pendingPallet = $this->form->getState()['pending_pallet_list'];
|
||||
|
||||
$palletNumber = trim($this->form->getState()['spare_packing_number']) ?? null;
|
||||
|
||||
$customerPo = trim($this->form->getState()['sale_order_master_id'])?? null;
|
||||
|
||||
$palletNumber = trim($palletNumber) ?? null;
|
||||
|
||||
$docNo = trim($this->form->getState()['removeDoc_number']) ?? null;
|
||||
|
||||
$docNo = trim($docNo) ?? null;
|
||||
|
||||
$user = Filament::auth()->user();
|
||||
|
||||
$operatorName = $user->name;
|
||||
|
||||
if (!$palletNumber)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Spare Pallet number is required to remove.')
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
$pattern = '/^([^|]+)\|([^|]+)\|(\d+(\.\d+)?)$/i';
|
||||
|
||||
if (!preg_match($pattern, $docNo, $matches))
|
||||
{
|
||||
Notification::make()
|
||||
->title("Scan Valid Qr code ")
|
||||
->body("Expected Format : (MaterialCode|Document Number|Quantity)")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $customerPo,
|
||||
'spare_packing_number' => $palletNumber,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$materialCode = $matches[1];
|
||||
$docNo = $matches[2];
|
||||
$weight = $matches[3];
|
||||
|
||||
$count = SparePacking::where('plant_id', $plantId)
|
||||
->where('spare_packing_number', $palletNumber)
|
||||
->count('spare_packing_number');
|
||||
|
||||
if (!$docNo)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Document number is required to remove.')
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $customerPo,
|
||||
'spare_packing_number' => $palletNumber,
|
||||
'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => $count,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$processOrderexist = SparePacking::where('plant_id', $plantId)
|
||||
->where('document_number', $docNo)
|
||||
->first();
|
||||
if (!$processOrderexist)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Document number not exists in pallet table.')
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $customerPo,
|
||||
'spare_packing_number' => $palletNumber,
|
||||
'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => $count,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$palletExist = SparePacking::where('plant_id', $plantId)
|
||||
->where('document_number', $docNo)
|
||||
->where('spare_packing_number', '!=', '')
|
||||
->where('spare_packing_number', '!=', null)
|
||||
->first();
|
||||
|
||||
if ($palletExist && $palletExist->spare_packing_number != $palletNumber)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Scanned document number exist in pallet number '$palletExist->spare_packing_number'.<br>Scan the valid exist document number to remove!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $customerPo,
|
||||
'spare_packing_number' => $palletNumber,
|
||||
'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => $count,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$deleted = SparePacking::where('plant_id', $plantId)
|
||||
->where('spare_packing_number', $palletNumber)
|
||||
->where('document_number', $docNo)
|
||||
->forceDelete();
|
||||
|
||||
if ($deleted)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Scanned document number '$docNo' successfully removed from pallet table!<br>Scan the next exist document number to remove...")
|
||||
->success()
|
||||
->duration(600)
|
||||
->send();
|
||||
|
||||
$this->snoCount = SparePacking::where('plant_id', $plantId)
|
||||
->where('spare_packing_number', $palletNumber)
|
||||
->count();
|
||||
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $customerPo,
|
||||
'spare_packing_number' => $palletNumber,
|
||||
'removeDoc_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 document number '$docNo' from master pallet!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $customerPo,
|
||||
'spare_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 [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SparePackingResource\Pages;
|
||||
|
||||
use App\Filament\Resources\SparePackingResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditSparePacking extends EditRecord
|
||||
{
|
||||
protected static string $resource = SparePackingResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\ViewAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
Actions\ForceDeleteAction::make(),
|
||||
Actions\RestoreAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SparePackingResource\Pages;
|
||||
|
||||
use App\Filament\Resources\SparePackingResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListSparePackings extends ListRecords
|
||||
{
|
||||
protected static string $resource = SparePackingResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SparePackingResource\Pages;
|
||||
|
||||
use App\Filament\Resources\SparePackingResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewSparePacking extends ViewRecord
|
||||
{
|
||||
protected static string $resource = SparePackingResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\EditAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user