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:
@@ -10,7 +10,6 @@ use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
|||||||
use Filament\Actions\Imports\ImportColumn;
|
use Filament\Actions\Imports\ImportColumn;
|
||||||
use Filament\Actions\Imports\Importer;
|
use Filament\Actions\Imports\Importer;
|
||||||
use Filament\Actions\Imports\Models\Import;
|
use Filament\Actions\Imports\Models\Import;
|
||||||
use Filament\Facades\Filament;
|
|
||||||
use Str;
|
use Str;
|
||||||
|
|
||||||
class LocatorInvoiceValidationImporter extends Importer
|
class LocatorInvoiceValidationImporter extends Importer
|
||||||
@@ -115,53 +114,49 @@ class LocatorInvoiceValidationImporter 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 {
|
||||||
|
$plant = Plant::where('code', $plantCod)->first();
|
||||||
|
if (! $plant) {
|
||||||
|
$warnMsg[] = 'Plant not found';
|
||||||
|
} else {
|
||||||
|
if (Str::length($invoiceNo) < 5 || ! ctype_alnum($invoiceNo)) {
|
||||||
|
$warnMsg[] = 'Invalid invoice number found';
|
||||||
}
|
}
|
||||||
else
|
if (Str::length($serialNo) < 9 || Str::length($serialNo) > 20 || ! ctype_alnum($serialNo)) {
|
||||||
{
|
$warnMsg[] = 'Invalid serial number found';
|
||||||
$plant = Plant::where('code', $this->data['plant'])->first();
|
|
||||||
if (!$plant) {
|
|
||||||
$warnMsg[] = "Plant not found";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (Str::length($invoiceNo) < 5 || !ctype_alnum($invoiceNo)) {
|
|
||||||
$warnMsg[] = "Invalid invoice number found";
|
|
||||||
}
|
|
||||||
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($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($scannedStat) > 0 && $scannedStat != 'Scanned') {
|
if (Str::length($scannedStat) > 0 && $scannedStat != 'Scanned') {
|
||||||
$warnMsg[] = "Invalid scanned status found";
|
$warnMsg[] = 'Invalid scanned status found';
|
||||||
}
|
}
|
||||||
if ($uploadStat != 'Y' && $uploadStat != 'N') {
|
if ($uploadStat != 'Y' && $uploadStat != 'N') {
|
||||||
$warnMsg[] = "Invalid upload status found";
|
$warnMsg[] = 'Invalid upload status 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';
|
||||||
}
|
}
|
||||||
if (Str::length($scannedBy) > 0) {
|
if (Str::length($scannedBy) > 0) {
|
||||||
$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';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Str::length($updatedBy) > 0) {
|
if (Str::length($updatedBy) > 0) {
|
||||||
$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 {
|
||||||
@@ -173,13 +168,12 @@ class LocatorInvoiceValidationImporter 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";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Str::length($scannedAt) > 0)
|
if (Str::length($scannedAt) > 0) {
|
||||||
{
|
|
||||||
foreach ($formats as $format) {
|
foreach ($formats as $format) {
|
||||||
try {
|
try {
|
||||||
$sDateTime = Carbon::createFromFormat($format, $scannedAt);
|
$sDateTime = Carbon::createFromFormat($format, $scannedAt);
|
||||||
@@ -190,13 +184,12 @@ class LocatorInvoiceValidationImporter 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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Str::length($updatedAt) > 0)
|
if (Str::length($updatedAt) > 0) {
|
||||||
{
|
|
||||||
foreach ($formats as $format) {
|
foreach ($formats as $format) {
|
||||||
try {
|
try {
|
||||||
$uDateTime = Carbon::createFromFormat($format, $updatedAt);
|
$uDateTime = Carbon::createFromFormat($format, $updatedAt);
|
||||||
@@ -207,11 +200,9 @@ class LocatorInvoiceValidationImporter 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'.";
|
||||||
@@ -226,14 +217,14 @@ class LocatorInvoiceValidationImporter 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
LocatorInvoiceValidation::updateOrCreate(
|
LocatorInvoiceValidation::updateOrCreate(
|
||||||
[
|
[
|
||||||
'plant_id' => $plant->id,
|
'plant_id' => $plant->id,
|
||||||
'serial_number' => $serialNo
|
'serial_number' => $serialNo,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'invoice_number' => $invoiceNo,
|
'invoice_number' => $invoiceNo,
|
||||||
@@ -246,9 +237,10 @@ class LocatorInvoiceValidationImporter extends Importer
|
|||||||
'updated_at' => (Str::length($updatedAt) > 0) ? $uDateTime->format('Y-m-d H:i:s') : null,
|
'updated_at' => (Str::length($updatedAt) > 0) ? $uDateTime->format('Y-m-d H:i:s') : null,
|
||||||
'created_by' => $createdBy,
|
'created_by' => $createdBy,
|
||||||
'scanned_by' => $scannedBy,
|
'scanned_by' => $scannedBy,
|
||||||
'updated_by' => $updatedBy
|
'updated_by' => $updatedBy,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
// // return LocatorInvoiceValidation::firstOrNew([
|
// // return LocatorInvoiceValidation::firstOrNew([
|
||||||
// // // Update existing records, matching them by `$this->data['column_name']`
|
// // // Update existing records, matching them by `$this->data['column_name']`
|
||||||
@@ -260,10 +252,10 @@ class LocatorInvoiceValidationImporter extends Importer
|
|||||||
|
|
||||||
public static function getCompletedNotificationBody(Import $import): string
|
public static function getCompletedNotificationBody(Import $import): string
|
||||||
{
|
{
|
||||||
$body = 'Your locator invoice validation import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
|
$body = 'Your locator invoice 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