After Quality Validation changes
This commit is contained in:
@@ -14,6 +14,7 @@ use Filament\Tables\Table;
|
|||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
|
|
||||||
|
|
||||||
class QualityValidationResource extends Resource
|
class QualityValidationResource extends Resource
|
||||||
{
|
{
|
||||||
protected static ?string $model = QualityValidation::class;
|
protected static ?string $model = QualityValidation::class;
|
||||||
@@ -87,6 +88,11 @@ class QualityValidationResource extends Resource
|
|||||||
|
|
||||||
$serialNumber = trim($parts[1]);
|
$serialNumber = trim($parts[1]);
|
||||||
|
|
||||||
|
// Store serial number before resetting fields
|
||||||
|
$previousSerialNumber = $serialNumber;
|
||||||
|
|
||||||
|
$previousItemCode = $itemCode;
|
||||||
|
|
||||||
if (strlen($itemCode) < 6) {
|
if (strlen($itemCode) < 6) {
|
||||||
$set('validationError', 'Item code must be at least 6 digits.');
|
$set('validationError', 'Item code must be at least 6 digits.');
|
||||||
$set('item_id', null);
|
$set('item_id', null);
|
||||||
@@ -120,14 +126,13 @@ class QualityValidationResource extends Resource
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//$set('validationError', null);
|
//$set('validationError', null);
|
||||||
|
|
||||||
$plantId = $get('plant_id'); // Get selected plant
|
$plantId = $get('plant_id'); // Get selected plant
|
||||||
|
|
||||||
if (!$plantId) {
|
if (!$plantId) {
|
||||||
$set('validationError', 'Please select a plant first.');
|
$set('validationError', 'Please select a plant first.');
|
||||||
$set('item_id', null);
|
$set('item_id', null);
|
||||||
$set('sticker_master_id', null);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,8 +168,36 @@ class QualityValidationResource extends Resource
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$serialExists = QualityValidation::where('sticker_master_id', $stickerMaster->id)
|
||||||
|
->where(function ($query) use ($serialNumber, $serialFields) {
|
||||||
|
foreach ($serialFields as $column) {
|
||||||
|
$query->orWhere($column, $serialNumber);
|
||||||
|
}
|
||||||
|
})->exists();
|
||||||
|
|
||||||
|
if ($serialExists) {
|
||||||
|
$set('validationError', 'Already scanning process completed.');
|
||||||
|
$set('item_id', "$previousItemCode|$previousSerialNumber"); // Restore original QR code
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the serial number exists in any column of any row
|
||||||
|
$serialExists = QualityValidation::where(function ($query) use ($serialNumber, $serialFields) {
|
||||||
|
foreach ($serialFields as $column) {
|
||||||
|
$query->orWhere($column, $serialNumber);
|
||||||
|
}
|
||||||
|
})->exists();
|
||||||
|
|
||||||
|
|
||||||
|
if ($serialExists) {
|
||||||
|
$set('validationError', 'Serial number already exists in quality validation.');
|
||||||
|
// Restore the serial number before returning
|
||||||
|
$set('item_id', "$itemCode|$previousSerialNumber"); // Reinsert full QR code
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Clear validation error if all inputs match
|
// Clear validation error if all inputs match
|
||||||
$set('validationError', null);
|
$set('validationError', null);
|
||||||
|
|
||||||
// Filter columns with value `1`
|
// Filter columns with value `1`
|
||||||
$visibleColumns = [];
|
$visibleColumns = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user