Updated alignments on import
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
This commit is contained in:
@@ -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;
|
||||||
@@ -122,49 +121,45 @@ class PalletValidationImporter extends Importer
|
|||||||
$scannedBy = $this->data['scanned_by'];
|
$scannedBy = $this->data['scanned_by'];
|
||||||
$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();
|
||||||
{
|
if (! $plant) {
|
||||||
$plant = Plant::where('code', $this->data['plant'])->first();
|
$warnMsg[] = 'Plant not found';
|
||||||
if (!$plant) {
|
} else {
|
||||||
$warnMsg[] = "Plant not found";
|
if (Str::length($serialNo) < 9 || Str::length($serialNo) > 20 || ! ctype_alnum($serialNo)) {
|
||||||
}
|
$warnMsg[] = 'Invalid serial number found';
|
||||||
else
|
|
||||||
{
|
|
||||||
if (Str::length($serialNo) < 9 || Str::length($serialNo) > 20 || !ctype_alnum($serialNo)) {
|
|
||||||
$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'
|
||||||
|
|
||||||
foreach ($formats as $format) {
|
foreach ($formats as $format) {
|
||||||
try {
|
try {
|
||||||
@@ -176,7 +171,7 @@ class PalletValidationImporter extends Importer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($cDateTime)) {
|
if (! isset($cDateTime)) {
|
||||||
// throw new \Exception('Invalid date time format');
|
// throw new \Exception('Invalid date time format');
|
||||||
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||||
}
|
}
|
||||||
@@ -191,13 +186,12 @@ class PalletValidationImporter extends Importer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($sDateTime)) {
|
if (! isset($sDateTime)) {
|
||||||
$warnMsg[] = "Invalid 'Scanned DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
$warnMsg[] = "Invalid 'Scanned DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
@@ -206,11 +200,9 @@ 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'.";
|
||||||
@@ -224,14 +216,14 @@ class PalletValidationImporter extends Importer
|
|||||||
// $warnMsg[] = "Invalid locator quantity found";
|
// $warnMsg[] = "Invalid locator quantity found";
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (!empty($warnMsg)) {
|
if (! empty($warnMsg)) {
|
||||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
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']`
|
||||||
@@ -257,10 +250,10 @@ class PalletValidationImporter extends Importer
|
|||||||
|
|
||||||
public static function getCompletedNotificationBody(Import $import): string
|
public static function getCompletedNotificationBody(Import $import): string
|
||||||
{
|
{
|
||||||
$body = 'Your pallet validation import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
|
$body = 'Your pallet validation import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
|
||||||
|
|
||||||
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
||||||
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
|
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $body;
|
return $body;
|
||||||
|
|||||||
Reference in New Issue
Block a user