diff --git a/app/Filament/Exports/StockDataMasterExporter.php b/app/Filament/Exports/StockDataMasterExporter.php index 93f7878..70453d2 100644 --- a/app/Filament/Exports/StockDataMasterExporter.php +++ b/app/Filament/Exports/StockDataMasterExporter.php @@ -60,8 +60,61 @@ class StockDataMasterExporter extends Exporter ->label('PANEL BOX SNO'), ExportColumn::make('scanned_status') ->label('SCANNED STATUS'), - ExportColumn::make('scanned_count') - ->label('SCANNED COUNT'), + ExportColumn::make('scanned_quantity') + ->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') ->label('CREATED AT'), ExportColumn::make('updated_at') diff --git a/app/Filament/Pages/CycleCount.php b/app/Filament/Pages/CycleCount.php index f0f2d24..8753f43 100644 --- a/app/Filament/Pages/CycleCount.php +++ b/app/Filament/Pages/CycleCount.php @@ -612,18 +612,34 @@ class CycleCount extends Page // $remainingStock = $stock->quantity - $currentScanned; if($stock->scanned_status == 'Scanned'){ + Notification::make() - ->title('Completed') - ->body("Already Completed the scanning process for the location '$location', item code '$this->itemCode' and doc no '$this->docNo against plant code $plantCode.") - ->warning() + ->title('Duplicate Serial Number') + ->body("Serial number '$this->sNo' has already been scanned in stock data master for the type SFG against plant code '$plantCode'.
Do you want to update in duplicate stock table?") + ->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(); - $this->form->fill([ - 'plant_id' => $plantId, - 'location' => $location, - 'bin' => $bin, - 'qr_code' => null, - ]); + $this->form->fill([ + 'plant_id' => $plantId, + 'location' => $location, + 'bin' => $bin, + 'qr_code' => null, + ]); return; } @@ -887,7 +903,7 @@ class CycleCount extends Page Notification::make() ->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.
Do you want to update in not in stock table?") ->danger() ->actions([ \Filament\Notifications\Actions\Action::make('confirm') @@ -946,7 +962,7 @@ class CycleCount extends Page Notification::make() ->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'.
Do you want to update in not in stock table?") ->danger() ->actions([ \Filament\Notifications\Actions\Action::make('confirm') @@ -1003,7 +1019,7 @@ class CycleCount extends Page 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.") + ->body("Serial number '{$this->sNo}' already exists against plant code '$plantCode' in not in stock table.") ->danger() ->send(); @@ -1019,7 +1035,7 @@ class CycleCount extends Page Notification::make() ->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.
Do you want to update in not in stock table?') ->danger() ->actions([ \Filament\Notifications\Actions\Action::make('confirm') @@ -1075,7 +1091,7 @@ class CycleCount extends Page Notification::make() ->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'.
Do you want to update in not in stock table?") ->danger() ->actions([ \Filament\Notifications\Actions\Action::make('confirm_update') @@ -1129,7 +1145,7 @@ class CycleCount extends Page Notification::make() ->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'.
Do you want to update in not in stock table?") ->danger() ->actions([ \Filament\Notifications\Actions\Action::make('confirm_update') @@ -1183,7 +1199,7 @@ class CycleCount extends Page Notification::make() ->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'.
Do you want to update in not in stock table?") ->danger() ->actions([ \Filament\Notifications\Actions\Action::make('confirm_update') @@ -1239,7 +1255,7 @@ class CycleCount extends Page Notification::make() ->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'.
Do you want to update in not in stock table?") ->danger() ->actions([ \Filament\Notifications\Actions\Action::make('confirm_update') @@ -1357,18 +1373,32 @@ class CycleCount extends Page if($serial->scanned_status == 'Scanned'){ Notification::make() - ->warning() - ->title('Completed') - ->body("Already completed the scanning process Serial number '$this->sNo' for the type SFG against plant code '$plantCode'.") - ->seconds(3) + ->title('Duplicate Serial Number') + ->body("Serial number '$this->sNo' has already been scanned in stock data master for the type SFG against plant code '$plantCode'.
Do you want to update in duplicate stock table?") + ->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(); - $this->form->fill([ - 'plant_id' => $plantId, - 'location' => $location, - 'bin' => $bin, - 'qr_code' => null, - ]); + $this->form->fill([ + 'plant_id' => $plantId, + 'location' => $location, + 'bin' => $bin, + 'qr_code' => null, + ]); return; } @@ -1383,10 +1413,10 @@ class CycleCount extends Page ]); $this->form->fill([ - 'plant_id' => $plantId, - 'location' => $location, - 'bin' => $bin, - 'qr_code' => null, + 'plant_id' => $plantId, + 'location' => $location, + 'bin' => $bin, + 'qr_code' => null, ]); $this->dispatch('refreshSfgNonData', location: $location, plantId: $plantId, serialNumber: $this->sNo, itemCode: $this->itemCode); @@ -1430,7 +1460,7 @@ class CycleCount extends Page if (! $record) { Notification::make() - ->title('Serial Number Not Found
Serial \''.$serialNumber.'\' not found in database for choosed plant.
') + ->title("Serial number '$serialNumber' not found in stock data table
Update 'Stock Data' table or Scan the valid 'Serial Number QR' data to proceed...") ->danger() ->seconds(3) ->send(); @@ -1499,6 +1529,123 @@ class CycleCount extends Page $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.
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'.
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) ->where('plant_id', $plantId) ->where('type', '0') @@ -1509,7 +1656,30 @@ class CycleCount extends Page ->first(); 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'
Do you want to update in not in stock table"; Notification::make() ->title('Invalid Item Code') ->body($message) @@ -1537,23 +1707,93 @@ class CycleCount extends Page 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'.
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'){ Notification::make() - ->title('Duplicate: Item Code') - ->body("Item code '$itemCode' and serial number '$serialNumber' have already been scanned and exist in the Stock Data Master.") + ->title('Duplicate Serial Number') + ->body("Serial number '$this->sNo' has already been scanned in stock data master for the type FG against plant code '$plantCode'.
Do you want to update in duplicate stock table?") ->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(); - $this->dispatch('playWarnSound'); - - $this->form->fill([ - 'plant_id' => $plantId, - 'location' => $location, - 'bin' => $bin, - 'qr_code' => null, - ]); + $this->form->fill([ + 'plant_id' => $plantId, + 'location' => $location, + 'bin' => $bin, + 'qr_code' => null, + ]); 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 { return [ diff --git a/app/Filament/Resources/StockDataMasterResource.php b/app/Filament/Resources/StockDataMasterResource.php index eaf5089..c305c05 100644 --- a/app/Filament/Resources/StockDataMasterResource.php +++ b/app/Filament/Resources/StockDataMasterResource.php @@ -304,12 +304,13 @@ class StockDataMasterResource extends Resource ->label('Advanced Filters') ->form([ Radio::make('type') - ->label('Type') + ->label('Stock Type') ->options([ '0' => 'FG', '1' => 'SFG', ]) ->inline() + ->default('0') ->nullable(), Select::make('Plant') ->label('Select Plant')