Changed logic in cycle count page and added stock count in export page #472

Merged
jothi merged 1 commits from ranjith-dev into master 2026-03-11 07:32:40 +00:00
3 changed files with 341 additions and 59 deletions

View File

@@ -60,8 +60,61 @@ class StockDataMasterExporter extends Exporter
->label('PANEL BOX SNO'), ->label('PANEL BOX SNO'),
ExportColumn::make('scanned_status') ExportColumn::make('scanned_status')
->label('SCANNED STATUS'), ->label('SCANNED STATUS'),
ExportColumn::make('scanned_count') ExportColumn::make('scanned_quantity')
->label('SCANNED COUNT'), ->label('SCANNED QUANTITY'),
ExportColumn::make('system_stock')
->label('SYSTEM STOCK')
->state(fn ($record) => $record->quantity),
ExportColumn::make('scanned_stock')
->label('SCANNED STOCK')
->state(fn ($record) => $record->scanned_quantity),
ExportColumn::make('duplicate_stock')
->label('DUPLICATE STOCK')
->state(function ($record) {
return \App\Models\DuplicateStock::where('stock_data_master_id', $record->id)->count();
}),
ExportColumn::make('not_in_stock')
->label('NOT IN STOCK')
->state(function ($record) {
return \App\Models\NotInStock::where('serial_number', $record->serial_number)
->where('plant_id', $record->plant_id)
->count();
}),
ExportColumn::make('physical_stock')
->label('PHYSICAL STOCK')
->state(function ($record) {
$duplicate = \App\Models\DuplicateStock::where('stock_data_master_id', $record->id)->count();
$notInStock = \App\Models\NotInStock::where('serial_number', $record->serial_number)
->where('plant_id', $record->plant_id)
->count();
$scanned = $record->scanned_quantity ?? 0;
return $scanned + $duplicate + $notInStock;
}),
ExportColumn::make('stock_difference')
->label('STOCK DIFFERENCE COUNT')
->state(function ($record) {
$duplicate = \App\Models\DuplicateStock::where('stock_data_master_id', $record->id)->count();
$notInStock = \App\Models\NotInStock::where('serial_number', $record->serial_number)
->where('plant_id', $record->plant_id)
->count();
$scanned = (int) $record->scanned_quantity;
$physicalStock = $scanned + $duplicate + $notInStock;
$systemStock = (int) $record->quantity;
$difference = $physicalStock - $systemStock;
return max($difference, 0);
}),
ExportColumn::make('created_at') ExportColumn::make('created_at')
->label('CREATED AT'), ->label('CREATED AT'),
ExportColumn::make('updated_at') ExportColumn::make('updated_at')

View File

@@ -612,18 +612,34 @@ class CycleCount extends Page
// $remainingStock = $stock->quantity - $currentScanned; // $remainingStock = $stock->quantity - $currentScanned;
if($stock->scanned_status == 'Scanned'){ if($stock->scanned_status == 'Scanned'){
Notification::make() Notification::make()
->title('Completed') ->title('Duplicate Serial Number')
->body("Already Completed the scanning process for the location '$location', item code '$this->itemCode' and doc no '$this->docNo against plant code $plantCode.") ->body("Serial number '$this->sNo' has already been scanned in stock data master for the type SFG against plant code '$plantCode'.<br>Do you want to update in duplicate stock table?")
->warning() ->danger()
->actions([
\Filament\Notifications\Actions\Action::make('confirm')
->label('Yes, Update')
->button()
->dispatch('confirmDuplicateUpdate', [
'plantId' => $plantId,
'location' => $location,
'bin' => $bin,
'serial_number' => $this->sNo,
'stickerMasterId' => $stickerMasterId,
'batch' => $this->batch,
'docNo' => $this->docNo,
'quantity' => $this->quantity
]),
])
->send(); ->send();
$this->form->fill([ $this->form->fill([
'plant_id' => $plantId, 'plant_id' => $plantId,
'location' => $location, 'location' => $location,
'bin' => $bin, 'bin' => $bin,
'qr_code' => null, 'qr_code' => null,
]); ]);
return; return;
} }
@@ -887,7 +903,7 @@ class CycleCount extends Page
Notification::make() Notification::make()
->title('Unknown Location') ->title('Unknown Location')
->body("location '$location' not found in stock data master for the type SFG") ->body("location '$location' not found in stock data master for the type SFG.<br>Do you want to update in not in stock table?")
->danger() ->danger()
->actions([ ->actions([
\Filament\Notifications\Actions\Action::make('confirm') \Filament\Notifications\Actions\Action::make('confirm')
@@ -946,7 +962,7 @@ class CycleCount extends Page
Notification::make() Notification::make()
->title('Unknown Location') ->title('Unknown Location')
->body("location '$location' not found in stock data master for the type SFG against plant code '$plantCode'.") ->body("location '$location' not found in stock data master for the type SFG against plant code '$plantCode'.<br>Do you want to update in not in stock table?")
->danger() ->danger()
->actions([ ->actions([
\Filament\Notifications\Actions\Action::make('confirm') \Filament\Notifications\Actions\Action::make('confirm')
@@ -1003,7 +1019,7 @@ class CycleCount extends Page
if ($existingInOtherLocation) { if ($existingInOtherLocation) {
Notification::make() Notification::make()
->title('Serial Number : Not In Stock') ->title('Serial Number : Not In Stock')
->body("Serial number '{$this->sNo}' already exists against plant code '$plantCode' in not in stock table.") ->body("Serial number '{$this->sNo}' already exists against plant code '$plantCode' in not in stock table.")
->danger() ->danger()
->send(); ->send();
@@ -1019,7 +1035,7 @@ class CycleCount extends Page
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.<br>Do you want to update in not in stock table?')
->danger() ->danger()
->actions([ ->actions([
\Filament\Notifications\Actions\Action::make('confirm') \Filament\Notifications\Actions\Action::make('confirm')
@@ -1075,7 +1091,7 @@ class CycleCount extends Page
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'.<br>Do you want to update in not in stock table?")
->danger() ->danger()
->actions([ ->actions([
\Filament\Notifications\Actions\Action::make('confirm_update') \Filament\Notifications\Actions\Action::make('confirm_update')
@@ -1129,7 +1145,7 @@ class CycleCount extends Page
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'.<br>Do you want to update in not in stock table?")
->danger() ->danger()
->actions([ ->actions([
\Filament\Notifications\Actions\Action::make('confirm_update') \Filament\Notifications\Actions\Action::make('confirm_update')
@@ -1183,7 +1199,7 @@ class CycleCount extends Page
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'.<br>Do you want to update in not in stock table?")
->danger() ->danger()
->actions([ ->actions([
\Filament\Notifications\Actions\Action::make('confirm_update') \Filament\Notifications\Actions\Action::make('confirm_update')
@@ -1239,7 +1255,7 @@ class CycleCount extends Page
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'.<br>Do you want to update in not in stock table?")
->danger() ->danger()
->actions([ ->actions([
\Filament\Notifications\Actions\Action::make('confirm_update') \Filament\Notifications\Actions\Action::make('confirm_update')
@@ -1357,18 +1373,32 @@ class CycleCount extends Page
if($serial->scanned_status == 'Scanned'){ if($serial->scanned_status == 'Scanned'){
Notification::make() Notification::make()
->warning() ->title('Duplicate Serial Number')
->title('Completed') ->body("Serial number '$this->sNo' has already been scanned in stock data master for the type SFG against plant code '$plantCode'.<br>Do you want to update in duplicate stock table?")
->body("Already completed the scanning process Serial number '$this->sNo' for the type SFG against plant code '$plantCode'.") ->danger()
->seconds(3) ->actions([
\Filament\Notifications\Actions\Action::make('confirm')
->label('Yes, Update')
->button()
->dispatch('confirmDuplicateUpdate', [
'plantId' => $plantId,
'location' => $location,
'bin' => $bin,
'serial_number' => $this->sNo,
'stickerMasterId' => $stickerMasterId,
'batch' => $this->batch,
'docNo' => $this->docNo,
'quantity' => $this->quantity
]),
])
->send(); ->send();
$this->form->fill([ $this->form->fill([
'plant_id' => $plantId, 'plant_id' => $plantId,
'location' => $location, 'location' => $location,
'bin' => $bin, 'bin' => $bin,
'qr_code' => null, 'qr_code' => null,
]); ]);
return; return;
} }
@@ -1383,10 +1413,10 @@ class CycleCount extends Page
]); ]);
$this->form->fill([ $this->form->fill([
'plant_id' => $plantId, 'plant_id' => $plantId,
'location' => $location, 'location' => $location,
'bin' => $bin, 'bin' => $bin,
'qr_code' => null, '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);
@@ -1430,7 +1460,7 @@ class CycleCount extends Page
if (! $record) { if (! $record) {
Notification::make() Notification::make()
->title('<b><span style="color:red;">Serial Number Not Found<br>Serial \''.$serialNumber.'\' not found in database for choosed plant.</span></b>') ->title("Serial number '$serialNumber' not found in stock data table<br>Update 'Stock Data' table or Scan the valid 'Serial Number QR' data to proceed...")
->danger() ->danger()
->seconds(3) ->seconds(3)
->send(); ->send();
@@ -1499,6 +1529,123 @@ class CycleCount extends Page
$stickerMasterId = $stickerMaster->id; $stickerMasterId = $stickerMaster->id;
$locationExist = StockDataMaster::where('location', $location)
->where('type', '0')
->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 FG.<br>Do you want to update in not in stock table?")
->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('type', '0')
->first();
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()
->title('Unknown Location')
->body("location '$location' not found in stock data master for the type FG against plant code '$plantCode'.<br>Do you want to update in not in stock table?")
->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;
}
$record = StockDataMaster::where('serial_number', $serialNumber) $record = StockDataMaster::where('serial_number', $serialNumber)
->where('plant_id', $plantId) ->where('plant_id', $plantId)
->where('type', '0') ->where('type', '0')
@@ -1509,7 +1656,30 @@ class CycleCount extends Page
->first(); ->first();
if (! $record) { if (! $record) {
$message = "serial number not found '$serialNumber' for the type FG against item code '$itemCode' and plant code '$plantCode'";
$sNoExistLocation = NotInStock::where('plant_id', $plantId)
->where('serial_number', $this->sNo)
->where('type', '0')
->first();
if ($sNoExistLocation) {
Notification::make()
->title('Serial Number : Not In Stock')
->body("Serial number '{$this->sNo}' already exists for the type FG 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;
}
$message = "serial number not found '$serialNumber' for the type FG against item code '$itemCode' and plant code '$plantCode'<br>Do you want to update in not in stock table";
Notification::make() Notification::make()
->title('Invalid Item Code') ->title('Invalid Item Code')
->body($message) ->body($message)
@@ -1537,23 +1707,93 @@ class CycleCount extends Page
return; return;
} }
$serialRecord = StockDataMaster::where('serial_number', $serialNumber)
->where('plant_id', $plantId)
->where('type', '0')
->with('stickerMasterRelation.item')
->first();
if ($serialRecord && $serialRecord->stickerMasterRelation->item->code != $itemCode) {
$sNoExistLocation = NotInStock::where('plant_id', $plantId)
->where('serial_number', $this->sNo)
->where('type', '0')
->first();
if ($sNoExistLocation) {
Notification::make()
->title('Serial Number : Not In Stock')
->body("Serial number '{$this->sNo}' already exists for the type FG 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 Item Code')
->body("Item code not found '$this->itemCode' in stock data master for the type FG against plant code '$plantCode'.<br>Do you want to update in duplicate stock table?")
->danger()
->actions([
\Filament\Notifications\Actions\Action::make('confirm')
->label('Yes, Update')
->button()
->dispatch('confirmSerialFGUpdate', [
'plantId' => $plantId,
'location' => $location,
'bin' => $bin,
'serial_number' => $this->sNo,
'stickerMasterId' => $stickerMasterId,
]),
])
->send();
$this->form->fill([
'plant_id' => $plantId,
'location' => $location,
'bin' => $bin,
'qr_code' => null,
]);
return;
}
if($record->scanned_status == 'Scanned'){ if($record->scanned_status == 'Scanned'){
Notification::make() Notification::make()
->title('Duplicate: Item Code') ->title('Duplicate Serial Number')
->body("Item code '$itemCode' and serial number '$serialNumber' have already been scanned and exist in the Stock Data Master.") ->body("Serial number '$this->sNo' has already been scanned in stock data master for the type FG against plant code '$plantCode'.<br>Do you want to update in duplicate stock table?")
->danger() ->danger()
->seconds(3) ->actions([
\Filament\Notifications\Actions\Action::make('confirm')
->label('Yes, Update')
->button()
->dispatch('confirmDuplicateUpdate', [
'plantId' => $plantId,
'location' => $location,
'bin' => $bin,
'serial_number' => $this->sNo,
'stickerMasterId' => $stickerMasterId,
'batch' => $this->batch,
'docNo' => $this->docNo,
'quantity' => $this->quantity
]),
])
->send(); ->send();
$this->dispatch('playWarnSound'); $this->form->fill([
'plant_id' => $plantId,
$this->form->fill([ 'location' => $location,
'plant_id' => $plantId, 'bin' => $bin,
'location' => $location, 'qr_code' => null,
'bin' => $bin, ]);
'qr_code' => null,
]);
return; return;
@@ -1884,18 +2124,6 @@ class CycleCount extends Page
} }
} }
public function processLocation($value){
$location = $value;
$plantId = $this->form->getState()['plant_id'];
$plantId = trim($plantId) ?? null;
// $this->dispatch('')
// $this->dispatch('refreshInvoiceData', location: $location, plantId: $plantId);
}
protected function getHeaderActions(): array protected function getHeaderActions(): array
{ {
return [ return [

View File

@@ -304,12 +304,13 @@ class StockDataMasterResource extends Resource
->label('Advanced Filters') ->label('Advanced Filters')
->form([ ->form([
Radio::make('type') Radio::make('type')
->label('Type') ->label('Stock Type')
->options([ ->options([
'0' => 'FG', '0' => 'FG',
'1' => 'SFG', '1' => 'SFG',
]) ])
->inline() ->inline()
->default('0')
->nullable(), ->nullable(),
Select::make('Plant') Select::make('Plant')
->label('Select Plant') ->label('Select Plant')