Merge pull request 'Added logic for sfg cycle count in cycle count page' (#467) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 16s

Reviewed-on: #467
This commit was merged in pull request #467.
This commit is contained in:
2026-03-10 09:48:31 +00:00
2 changed files with 510 additions and 52 deletions

View File

@@ -69,13 +69,6 @@ class CycleCount extends Page
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
}) })
->required(), ->required(),
// Select::make('type')
// ->label('Type')
// ->reactive()
// ->options([
// '0' => 'FG',
// '1' => 'SFG',
// ]),
TextInput::make('location') TextInput::make('location')
->label('Location') ->label('Location')
->reactive() ->reactive()
@@ -87,7 +80,9 @@ class CycleCount extends Page
TextInput::make('bin') TextInput::make('bin')
->label('Bin') ->label('Bin')
->readOnly(fn (callable $get) => ! $get('plant_id') || ! $get('location')) ->readOnly(fn (callable $get) => ! $get('plant_id') || ! $get('location'))
->reactive(), ->reactive()
->required()
->rules(['min:6']),
TextInput::make('qr_code') TextInput::make('qr_code')
->label('QR Code') ->label('QR Code')
->reactive() ->reactive()
@@ -329,6 +324,27 @@ class CycleCount extends Page
if(!$locationExist){ if(!$locationExist){
$existingInOtherLocation = NotInStock::where('plant_id', $plantId)
->where('serial_number', $this->sNo)
->first();
if ($existingInOtherLocation) {
Notification::make()
->title('Serial Number : Not In Stock')
->body("Serial number '{$this->sNo}' already exists against plant code '$plantCode' in not in stock table.")
->danger()
->send();
$this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
return;
}
Notification::make() Notification::make()
->title('Unknown Location') ->title('Unknown Location')
->body("Location '$location' not found for the type SFG.") ->body("Location '$location' not found for the type SFG.")
@@ -366,6 +382,27 @@ class CycleCount extends Page
if(!$locationAgaPlant){ if(!$locationAgaPlant){
$existingInOtherLocation = NotInStock::where('plant_id', $plantId)
->where('serial_number', $this->sNo)
->first();
if ($existingInOtherLocation) {
Notification::make()
->title('Serial Number : Not In Stock')
->body("Serial number '{$this->sNo}' already exists against plant code '$plantCode' in not in stock table.")
->danger()
->send();
$this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
return;
}
Notification::make() Notification::make()
->title('Unknown Location') ->title('Unknown Location')
->body("Location '$location' not found for the type SFG against plant code '$plantCode'.") ->body("Location '$location' not found for the type SFG against plant code '$plantCode'.")
@@ -404,6 +441,27 @@ class CycleCount extends Page
if(!$locationItemAgaPlant){ if(!$locationItemAgaPlant){
$existingInOtherLocation = NotInStock::where('plant_id', $plantId)
->where('serial_number', $this->sNo)
->first();
if ($existingInOtherLocation) {
Notification::make()
->title('Serial Number : Not In Stock')
->body("Serial number '{$this->sNo}' already exists against plant code '$plantCode' in not in stock table.")
->danger()
->send();
$this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
return;
}
Notification::make() Notification::make()
->title('Item Not Found in Location') ->title('Item Not Found in Location')
->body("Item Code '$this->itemCode' is not available in location '$location' (Type: SFG) for Plant Code '$plantCode'.") ->body("Item Code '$this->itemCode' is not available in location '$location' (Type: SFG) for Plant Code '$plantCode'.")
@@ -436,6 +494,27 @@ class CycleCount extends Page
if ($locationItemAgaPlant->batch != $this->batch) { if ($locationItemAgaPlant->batch != $this->batch) {
$existingInOtherLocation = NotInStock::where('plant_id', $plantId)
->where('serial_number', $this->sNo)
->first();
if ($existingInOtherLocation) {
Notification::make()
->title('Serial Number : Not In Stock')
->body("Serial number '{$this->sNo}' already exists against plant code '$plantCode' in not in stock table.")
->danger()
->send();
$this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
return;
}
Notification::make() Notification::make()
->title('Batch Mismatch') ->title('Batch Mismatch')
->body("Location '$location' exists for item code '$this->itemCode', but it belongs to batch '{$locationItemAgaPlant->batch}'.") ->body("Location '$location' exists for item code '$this->itemCode', but it belongs to batch '{$locationItemAgaPlant->batch}'.")
@@ -468,6 +547,27 @@ class CycleCount extends Page
if ($locationItemAgaPlant->doc_no != $this->docNo) { if ($locationItemAgaPlant->doc_no != $this->docNo) {
$existingInOtherLocation = NotInStock::where('plant_id', $plantId)
->where('serial_number', $this->sNo)
->first();
if ($existingInOtherLocation) {
Notification::make()
->title('Serial Number : Not In Stock')
->body("Serial number '{$this->sNo}' already exists against plant code '$plantCode' in not in stock table.")
->danger()
->send();
$this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
return;
}
Notification::make() Notification::make()
->title('Document Mismatch') ->title('Document Mismatch')
->body("Location '$location' exists for item code '$this->itemCode', but it belongs to document number '{$locationItemAgaPlant->doc_no}'.") ->body("Location '$location' exists for item code '$this->itemCode', but it belongs to document number '{$locationItemAgaPlant->doc_no}'.")
@@ -549,6 +649,7 @@ class CycleCount extends Page
$stock->update([ $stock->update([
'bin' => $bin, 'bin' => $bin,
'batch' => $this->batch,
'scanned_quantity' => $newScannedQty, 'scanned_quantity' => $newScannedQty,
'scanned_status' => $status 'scanned_status' => $status
]); ]);
@@ -757,43 +858,171 @@ class CycleCount extends Page
$stickerMasterId = $stickerExists->id; $stickerMasterId = $stickerExists->id;
$quanExist = StockDataMaster::where('plant_id', $plantId) $locationExist = StockDataMaster::where('location', $location)
->where('serial_number', $this->sNo) ->where('type', '1')
->first();
if(!$locationExist){
$existingInOtherLocation = NotInStock::where('plant_id', $plantId)
->where('serial_number', $this->sNo)
->first();
if ($existingInOtherLocation) {
Notification::make()
->title('Serial Number : Not In Stock')
->body("Serial number '{$this->sNo}' already exists against plant code '$plantCode' in not in stock table.")
->danger()
->send();
$this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
return;
}
Notification::make()
->title('Unknown Location')
->body("location '$location' not found in stock data master for the type SFG")
->danger()
->actions([
\Filament\Notifications\Actions\Action::make('confirm')
->label('Yes, Update')
->button()
->dispatch('confirmSerialUpdate', [
'plantId' => $plantId,
'location' => $location,
'bin' => $bin,
'serial_number' => $this->sNo,
'stickerMasterId' => $stickerMasterId,
'batch' => $this->batch,
'docNo' => $this->docNo,
'quantity' => $this->quantity
]),
])
->send();
$this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
return;
}
$locationAgaPlant = StockDataMaster::where('plant_id', $plantId)
->where('location', $location) ->where('location', $location)
->where('type', '1') ->where('type', '1')
->first(); ->first();
if($quanExist->quantity == '' || $quanExist->quantity == null){ if(!$locationAgaPlant){
Notification::make()
->warning() $existingInOtherLocation = NotInStock::where('plant_id', $plantId)
->title('Unknown Quantity') ->where('serial_number', $this->sNo)
->body("Quantity is missing for serial number '$this->sNo' (Type: SFG) in Plant Code '$plantCode'. Please update it in Stock Data Master.") ->first();
->seconds(3)
->send(); if ($existingInOtherLocation) {
Notification::make()
->title('Serial Number : Not In Stock')
->body("Serial number '{$this->sNo}' already exists against plant code '$plantCode' in not in stock table.")
->danger()
->send();
$this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
return; return;
}
Notification::make()
->title('Unknown Location')
->body("location '$location' not found in stock data master for the type SFG against plant code '$plantCode'.")
->danger()
->actions([
\Filament\Notifications\Actions\Action::make('confirm')
->label('Yes, Update')
->button()
->dispatch('confirmSerialUpdate', [
'plantId' => $plantId,
'location' => $location,
'bin' => $bin,
'serial_number' => $this->sNo,
'stickerMasterId' => $stickerMasterId,
'batch' => $this->batch,
'docNo' => $this->docNo,
'quantity' => $this->quantity
]),
])
->send();
$this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
return;
} }
elseif ((int) $quanExist->quantity > 1) {
if($bin == '' || $bin == null){
Notification::make() Notification::make()
->warning() ->title('Unknown Bin')
->title('Invalid Quantity') ->body("Bin can't be empty!")
->body("Quantity should be '1' against '$this->sNo' for the type SFG against plant code '$plantCode'!Please update quantity in stock data master.") ->danger()
->seconds(3)
->send(); ->send();
return; $this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
return;
} }
$serialExist = StockDataMaster::where('serial_number', $this->sNo)->where('type', '1')->first(); $serialExist = StockDataMaster::where('serial_number', $this->sNo)->where('type', '1')->first();
if(!$serialExist){ if(!$serialExist){
$existingInOtherLocation = NotInStock::where('plant_id', $plantId)
->where('serial_number', $this->sNo)
->first();
if ($existingInOtherLocation) {
Notification::make()
->title('Serial Number : Not In Stock')
->body("Serial number '{$this->sNo}' already exists against plant code '$plantCode' in not in stock table.")
->danger()
->send();
$this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
return;
}
Notification::make() Notification::make()
->title('Unknown Serial Number') ->title('Unknown Serial Number')
->body('Scanned serial number not found in stock data master for the type SFG') ->body('Scanned serial number not found in stock data master for the type SFG')
->danger() ->danger()
->actions([ ->actions([
\Filament\Notifications\Actions\Action::make('confirm_update') \Filament\Notifications\Actions\Action::make('confirm')
->label('Yes, Update') ->label('Yes, Update')
->button() ->button()
->dispatch('confirmSerialUpdate', [ ->dispatch('confirmSerialUpdate', [
@@ -823,6 +1052,27 @@ class CycleCount extends Page
if(!$serialAgaPlant){ if(!$serialAgaPlant){
$sNoExist = NotInStock::where('plant_id', $plantId)
->where('serial_number', $this->sNo)
->first();
if ($sNoExist) {
Notification::make()
->title('Serial Number : Not In Stock')
->body("Serial number '{$this->sNo}' already exists against plant code '$plantCode' in not in stock table.")
->danger()
->send();
$this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
return;
}
Notification::make() Notification::make()
->title('Unknown Serial Number') ->title('Unknown Serial Number')
->body("Scanned serial number not found in stock data master for the type SFG against plant code '$plantCode'") ->body("Scanned serial number not found in stock data master for the type SFG against plant code '$plantCode'")
@@ -856,6 +1106,27 @@ class CycleCount extends Page
if ($serialAgaPlant->location != $location) { if ($serialAgaPlant->location != $location) {
$sNoExistLocation = NotInStock::where('plant_id', $plantId)
->where('serial_number', $this->sNo)
->first();
if ($sNoExistLocation) {
Notification::make()
->title('Serial Number : Not In Stock')
->body("Serial number '{$this->sNo}' already exists against plant code '$plantCode' in not in stock table.")
->danger()
->send();
$this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
return;
}
Notification::make() Notification::make()
->title('Invalid Location') ->title('Invalid Location')
->body("Serial number '$this->sNo' does not belong to location '$location' for the type SFG against plant code '$plantCode'.") ->body("Serial number '$this->sNo' does not belong to location '$location' for the type SFG against plant code '$plantCode'.")
@@ -889,6 +1160,27 @@ class CycleCount extends Page
if ($serialAgaPlant->sticker_master_id != $stickerMasterId) { if ($serialAgaPlant->sticker_master_id != $stickerMasterId) {
$sNoExistLocation = NotInStock::where('plant_id', $plantId)
->where('serial_number', $this->sNo)
->first();
if ($sNoExistLocation) {
Notification::make()
->title('Serial Number : Not In Stock')
->body("Serial number '{$this->sNo}' already exists against plant code '$plantCode' in not in stock table.")
->danger()
->send();
$this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
return;
}
Notification::make() Notification::make()
->title('Invalid Item Code') ->title('Invalid Item Code')
->body("Serial number '$this->sNo' does not belong to item code '$this->itemCode' for the type SFG against plant code '$plantCode'.") ->body("Serial number '$this->sNo' does not belong to item code '$this->itemCode' for the type SFG against plant code '$plantCode'.")
@@ -923,6 +1215,28 @@ class CycleCount extends Page
if ($serialAgaPlant->batch != '' || $serialAgaPlant->batch != null) { if ($serialAgaPlant->batch != '' || $serialAgaPlant->batch != null) {
if($serialAgaPlant->batch != $this->batch){ if($serialAgaPlant->batch != $this->batch){
$sNoExistLocation = NotInStock::where('plant_id', $plantId)
->where('serial_number', $this->sNo)
->first();
if ($sNoExistLocation) {
Notification::make()
->title('Serial Number : Not In Stock')
->body("Serial number '{$this->sNo}' already exists against plant code '$plantCode' in not in stock table.")
->danger()
->send();
$this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
return;
}
Notification::make() Notification::make()
->title('Invalid Batch') ->title('Invalid Batch')
->body("Serial number '$this->sNo' does not belong to batch '$this->batch' for the type SFG against plant code '$plantCode'.") ->body("Serial number '$this->sNo' does not belong to batch '$this->batch' for the type SFG against plant code '$plantCode'.")
@@ -1003,26 +1317,40 @@ class CycleCount extends Page
->where('type', '1') ->where('type', '1')
->first(); ->first();
// if($serial->quantity == '' || $serial->quantity == null){ if($serial->quantity == '' || $serial->quantity == null){
// Notification::make() Notification::make()
// ->warning() ->warning()
// ->title('Unknown Quantity') ->title('Unknown Quantity')
// ->body("Quantity is missing for serial number '$this->sNo' (Type: SFG) in Plant Code '$plantCode'. Please update it in Stock Data Master.") ->body("Quantity is missing for serial number '$this->sNo' (Type: SFG) in Plant Code '$plantCode'. Please update it in Stock Data Master.")
// ->seconds(3) ->seconds(3)
// ->send(); ->send();
// return; $this->form->fill([
// } 'plant_id' => $plantId,
// elseif ((int) $serial->quantity > 1) { 'location' => $location,
// Notification::make() 'bin' => $bin,
// ->warning() 'qr_code' => null,
// ->title('Invalid Quantity') ]);
// ->body("Quantity should be '1' against '$this->sNo' for the type SFG against plant code '$plantCode'!Please update quantity in stock data master.")
// ->seconds(3)
// ->send();
// return; return;
// } }
elseif ((int) $serial->quantity > 1) {
Notification::make()
->warning()
->title('Invalid Quantity')
->body("Quantity should be '1' against '$this->sNo' for the type SFG against plant code '$plantCode'!Please update quantity in stock data master.")
->seconds(3)
->send();
$this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
return;
}
if ($serial) { if ($serial) {
@@ -1034,6 +1362,13 @@ class CycleCount extends Page
->body("Already completed the scanning process Serial number '$this->sNo' for the type SFG against plant code '$plantCode'.") ->body("Already completed the scanning process Serial number '$this->sNo' for the type SFG against plant code '$plantCode'.")
->seconds(3) ->seconds(3)
->send(); ->send();
$this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
return; return;
} }
@@ -1047,6 +1382,13 @@ class CycleCount extends Page
'updated_by' => $operatorName 'updated_by' => $operatorName
]); ]);
$this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
$this->dispatch('refreshSfgNonData', location: $location, plantId: $plantId, serialNumber: $this->sNo, itemCode: $this->itemCode); $this->dispatch('refreshSfgNonData', location: $location, plantId: $plantId, serialNumber: $this->sNo, itemCode: $this->itemCode);
} }
} }
@@ -1105,8 +1447,61 @@ class CycleCount extends Page
return; return;
} }
$plant = Plant::find($plantId);
if ($plant) {
$plantCode = $plant->code;
} else {
$plantCode = null;
}
$item = Item::where('plant_id', $plantId)
->where('code', $itemCode)
->first();
if(!$item){
Notification::make()
->title('Invalid Item Code')
->body("Item code '$this->itemCode' not found for the type FG against plant code '$plantCode'.")
->danger()
->send();
$this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
return;
}
$itemId = $item->id;
$stickerMaster = StickerMaster::where('plant_id', $plantId)
->where('item_id', $itemId)
->first();
if(!$stickerMaster){
Notification::make()
->title('Invalid Item Code')
->body("Item code '$this->itemCode' not found in sticker master for the type FG against plant code '$plantCode'.")
->danger()
->send();
$this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
return;
}
$stickerMasterId = $stickerMaster->id;
$record = StockDataMaster::where('serial_number', $serialNumber) $record = StockDataMaster::where('serial_number', $serialNumber)
->where('plant_id', $plantId) ->where('plant_id', $plantId)
->where('type', '0')
->whereHas('stickerMasterRelation.item', function ($query) use ($itemCode, $plantId) { ->whereHas('stickerMasterRelation.item', function ($query) use ($itemCode, $plantId) {
$query->where('plant_id', $plantId) $query->where('plant_id', $plantId)
->where('code', $itemCode); ->where('code', $itemCode);
@@ -1114,19 +1509,37 @@ class CycleCount extends Page
->first(); ->first();
if (! $record) { if (! $record) {
$this->serialNumber = $serialNumber; $message = "serial number not found '$serialNumber' for the type FG against item code '$itemCode' and plant code '$plantCode'";
$this->itemCode = $itemCode; Notification::make()
$this->plantId = $plantId; ->title('Invalid Item Code')
$this->location = $location; ->body($message)
$this->bin = $bin; ->danger()
->actions([
\Filament\Notifications\Actions\Action::make('confirm_update')
->label('Yes, Update')
->button()
->dispatch('confirmSerialFGUpdate', [
'plantId' => $plantId,
'location' => $location,
'bin' => $bin,
'serial_number' => $this->sNo,
'stickerMasterId' => $stickerMasterId,
]),
])
->send();
$this->mountAction('confirmAddToNotInStock'); $this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
return; return;
} }
if($record->scanned_status == 'Scanned'){ if($record->scanned_status == 'Scanned'){
Notification::make() Notification::make()
->title('Duplicate: Item Code') ->title('Duplicate: Item Code')
->body("Item code '$itemCode' and serial number '$serialNumber' have already been scanned and exist in the Stock Data Master.") ->body("Item code '$itemCode' and serial number '$serialNumber' have already been scanned and exist in the Stock Data Master.")
->danger() ->danger()

View File

@@ -52,7 +52,7 @@ class StockDataTable extends Component
public bool $isSfg = false; public bool $isSfg = false;
public $itemCode, $serialNumber; public $itemCode, $serialNumber, $serial_number;
public $scannedSfgData = []; public $scannedSfgData = [];
@@ -64,6 +64,8 @@ class StockDataTable extends Component
'refreshSfgData' => 'loadSfgData', 'refreshSfgData' => 'loadSfgData',
'refreshSfgNonData' => 'loadSfgNonQuanData', 'refreshSfgNonData' => 'loadSfgNonQuanData',
'confirmStockUpdate', 'confirmStockUpdate',
'confirmSerialUpdate',
'confirmSerialFGUpdate'
]; ];
public $capacitorInput = ''; public $capacitorInput = '';
@@ -80,6 +82,8 @@ class StockDataTable extends Component
public $stickerMasterId; public $stickerMasterId;
public $sNo;
public function confirmStockUpdate($plantId, $location, $bin, $stickerMasterId, $batch, $docNo, $quantity) public function confirmStockUpdate($plantId, $location, $bin, $stickerMasterId, $batch, $docNo, $quantity)
{ {
@@ -124,13 +128,54 @@ class StockDataTable extends Component
} }
} }
public function confirmSerialUpdate($plantId, $location, $bin, $sNo, $stickerMasterId, $batch, $docNo, $quantity) public function confirmSerialUpdate($plantId, $location, $bin, $serial_number, $stickerMasterId, $batch, $docNo, $quantity)
{
$sNo = $serial_number;
$record = NotInStock::where('plant_id', $plantId)
->where('location', $location)
->where('sticker_master_id', $stickerMasterId)
->where('serial_number', $sNo)
->where('bin', $bin)
->first();
if (!$record) {
NotInStock::create([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'sticker_master_id' => $stickerMasterId,
'type' => '1',
'serial_number' => $sNo ?? null,
'batch' => $batch ?? null,
'doc_no' => $docNo ?? null,
'scanned_quantity' => $quantity ?? '1',
]);
Notification::make()
->title('Record inserted successfully in not in stock table.')
->success()
->send();
} else {
$record->update([
'batch' => $batch ?? null,
]);
Notification::make()
->title('Record updated in not in stock table.')
->success()
->send();
}
}
public function confirmSerialFGUpdate($plantId, $location, $bin, $sNo, $stickerMasterId)
{ {
$record = NotInStock::where('plant_id', $plantId) $record = NotInStock::where('plant_id', $plantId)
->where('location', $location) ->where('location', $location)
->where('sticker_master_id', $stickerMasterId) ->where('sticker_master_id', $stickerMasterId)
->where('doc_no', $docNo)
->where('bin', $bin) ->where('bin', $bin)
->first(); ->first();