Updated alignments on import
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s

This commit is contained in:
dhanabalan
2026-01-13 16:31:43 +05:30
parent 5bacc0cba7
commit b9cb492d37

View File

@@ -12,7 +12,6 @@ use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import; use Filament\Actions\Imports\Models\Import;
use Str; use Str;
class PalletValidationImporter extends Importer class PalletValidationImporter extends Importer
{ {
protected static ?string $model = PalletValidation::class; protected static ?string $model = PalletValidation::class;
@@ -123,45 +122,41 @@ class PalletValidationImporter extends Importer
$updatedBy = $this->data['updated_by']; $updatedBy = $this->data['updated_by'];
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) { if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = "Invalid plant code found"; $warnMsg[] = 'Invalid plant code found';
} } else {
else $plant = Plant::where('code', $plantCod)->first();
{
$plant = Plant::where('code', $this->data['plant'])->first();
if (! $plant) { if (! $plant) {
$warnMsg[] = "Plant not found"; $warnMsg[] = 'Plant not found';
} } else {
else
{
if (Str::length($serialNo) < 9 || Str::length($serialNo) > 20 || ! ctype_alnum($serialNo)) { if (Str::length($serialNo) < 9 || Str::length($serialNo) > 20 || ! ctype_alnum($serialNo)) {
$warnMsg[] = "Invalid serial number found"; $warnMsg[] = 'Invalid serial number found';
} }
if (Str::length($palletNo) > 0 && Str::length($palletNo) < 10) { if (Str::length($palletNo) > 0 && Str::length($palletNo) < 10) {
$warnMsg[] = "Invalid pallet number found"; $warnMsg[] = 'Invalid pallet number found';
} }
if (Str::length($palletStat) > 0 && $palletStat != 'Completed') { if (Str::length($palletStat) > 0 && $palletStat != 'Completed') {
$warnMsg[] = "Invalid pallet status found"; $warnMsg[] = 'Invalid pallet status found';
} }
if (Str::length($locatorNo) > 0 && Str::length($locatorNo) < 7) { if (Str::length($locatorNo) > 0 && Str::length($locatorNo) < 7) {
$warnMsg[] = "Invalid locator number found"; $warnMsg[] = 'Invalid locator number found';
} }
if (Str::length($palletNo) <= 0 && Str::length($locatorNo) <= 0) { if (Str::length($palletNo) <= 0 && Str::length($locatorNo) <= 0) {
$warnMsg[] = "Pallet and locator number found"; $warnMsg[] = 'Pallet and locator number found';
} }
if (Str::length($locatorQty) < 0 || ! is_numeric($locatorQty) || $locatorQty < 0 || $locatorQty > 2) { if (Str::length($locatorQty) < 0 || ! is_numeric($locatorQty) || $locatorQty < 0 || $locatorQty > 2) {
$warnMsg[] = "Invalid locator quantity found"; $warnMsg[] = 'Invalid locator quantity found';
} }
$created = User::where('name', $createdBy)->first(); $created = User::where('name', $createdBy)->first();
if (! $created) { if (! $created) {
$warnMsg[] = "Created by not found"; $warnMsg[] = 'Created by not found';
} }
$scanned = User::where('name', $scannedBy)->first(); $scanned = User::where('name', $scannedBy)->first();
if (! $scanned) { if (! $scanned) {
$warnMsg[] = "Scanned by not found"; $warnMsg[] = 'Scanned by not found';
} }
$updated = User::where('name', $updatedBy)->first(); $updated = User::where('name', $updatedBy)->first();
if (! $updated) { if (! $updated) {
$warnMsg[] = "Updated by not found"; $warnMsg[] = 'Updated by not found';
} }
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; // '07-05-2025 08:00' or '07-05-2025 08:00:00' $formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; // '07-05-2025 08:00' or '07-05-2025 08:00:00'
@@ -196,8 +191,7 @@ class PalletValidationImporter extends Importer
} }
foreach ($formats as $format) { foreach ($formats as $format) {
try try {
{
$uDateTime = Carbon::createFromFormat($format, $updatedAt); $uDateTime = Carbon::createFromFormat($format, $updatedAt);
break; break;
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -208,9 +202,7 @@ class PalletValidationImporter extends Importer
if (! isset($uDateTime)) { if (! isset($uDateTime)) {
$warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS"; $warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
} } else {
else
{
if (isset($cDateTime) && isset($uDateTime)) { if (isset($cDateTime) && isset($uDateTime)) {
if ($cDateTime->greaterThan($uDateTime)) { if ($cDateTime->greaterThan($uDateTime)) {
$warnMsg[] = "'Created DataTime' is greater than 'Updated DateTime'."; $warnMsg[] = "'Created DataTime' is greater than 'Updated DateTime'.";
@@ -231,7 +223,7 @@ class PalletValidationImporter extends Importer
PalletValidation::updateOrCreate( PalletValidation::updateOrCreate(
[ [
'plant_id' => $plant->id, 'plant_id' => $plant->id,
'serial_number' => $serialNo 'serial_number' => $serialNo,
], ],
[ [
'pallet_number' => $palletNo, 'pallet_number' => $palletNo,
@@ -243,9 +235,10 @@ class PalletValidationImporter extends Importer
'updated_at' => $uDateTime->format('Y-m-d H:i:s'), 'updated_at' => $uDateTime->format('Y-m-d H:i:s'),
'created_by' => $createdBy, 'created_by' => $createdBy,
'scanned_by' => $scannedBy, 'scanned_by' => $scannedBy,
'updated_by' => $updatedBy 'updated_by' => $updatedBy,
] ]
); );
return null; return null;
// // return PalletValidation::firstOrNew([ // // return PalletValidation::firstOrNew([
// // // Update existing records, matching them by `$this->data['column_name']` // // // Update existing records, matching them by `$this->data['column_name']`