Changed importer production quantities importer logic
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 16s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 20s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 19s
Laravel Pint / pint (pull_request) Successful in 3m50s
Laravel Larastan / larastan (pull_request) Failing after 4m41s

This commit is contained in:
dhanabalan
2026-11-16 09:49:22 +05:30
parent 2061811546
commit 07b0ce2d90

View File

@@ -83,12 +83,12 @@ class ProductionQuantityImporter extends Importer
->example(['01-01-2025 08:00:00', '01-01-2025 19:30:00']) ->example(['01-01-2025 08:00:00', '01-01-2025 19:30:00'])
->label('Updated DateTime') ->label('Updated DateTime')
->rules(['required']), ->rules(['required']),
ImportColumn::make('operator_id') // ImportColumn::make('operator_id')
->requiredMapping() // ->requiredMapping()
->exampleHeader('Operator ID') // ->exampleHeader('Operator ID')
->example([Filament::auth()->user()->name, Filament::auth()->user()->name]) // ->example([Filament::auth()->user()->name, Filament::auth()->user()->name])
->label('Operator ID') // ->label('Operator ID')
->rules(['required']), // ->rules(['required']),
]; ];
} }
@@ -133,59 +133,64 @@ class ProductionQuantityImporter extends Importer
$fromDate = $this->data['created_at']; $fromDate = $this->data['created_at'];
$toDate = $this->data['updated_at']; $toDate = $this->data['updated_at'];
$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:s A', // 13-11-26 01:31:26 PM
'd-m-y h:i A', // 13-11-26 01:31 PM
];
$fdateTime = null; $fdateTime = null;
$tdateTime = null; $tdateTime = null;
// Try parsing with multiple formats
// Parse Created DateTime
foreach ($formats as $format) { foreach ($formats as $format) {
try { try {
$fdateTime = Carbon::createFromFormat($format, $fromDate); $fdateTime = Carbon::createFromFormat('!' . $format, trim($fromDate));
if ($fdateTime !== false) {
break; break;
}
} catch (\Exception $e) { } catch (\Exception $e) {
// Optionally collect warning messages $fdateTime = null;
// $warnMsg[] = "Date format mismatch with format: $format";
} }
} }
// Parse Updated DateTime
foreach ($formats as $format) { foreach ($formats as $format) {
try { try {
$tdateTime = Carbon::createFromFormat($format, $toDate); $tdateTime = Carbon::createFromFormat('!' . $format, trim($toDate));
if ($tdateTime !== false) {
break; break;
}
} catch (\Exception $e) { } catch (\Exception $e) {
// Optionally collect warning messages $tdateTime = null;
// $warnMsg[] = "Date format mismatch with format: $format";
} }
} }
// $fDateOnly = ''; // Validate Created DateTime
if (! isset($fdateTime)) { if (! $fdateTime) {
// throw new \Exception('Invalid date time format'); $warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YY HH:MM:SS AM/PM";
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
}
// else {
// $fDateOnly = $fdateTime->toDateString();
// }
if (! isset($tdateTime)) {
$warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
} }
if (isset($fdateTime) && isset($tdateTime)) { // Validate Updated DateTime
if (! $tdateTime) {
$warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YY HH:MM:SS AM/PM";
}
// Compare Created and Updated DateTime
if ($fdateTime && $tdateTime) {
if ($fdateTime->greaterThan($tdateTime)) { if ($fdateTime->greaterThan($tdateTime)) {
$warnMsg[] = "'Created DataTime' is greater than 'Updated DateTime'."; $warnMsg[] = "'Created DateTime' is greater than 'Updated DateTime'.";
} }
} }
// if (!$fromDate) {
// $warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS"; // $user = User::where('name', $this->data['operator_id'])->first();
// } // if (! $user) {
// else if (!$toDate) { // $warnMsg[] = 'Operator ID not found';
// $warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
// } // }
$user = User::where('name', $this->data['operator_id'])->first(); $userName = Filament::auth()->user()->name;
if (! $user) {
$warnMsg[] = 'Operator ID not found';
}
$shift = null; $shift = null;
@@ -225,8 +230,6 @@ class ProductionQuantityImporter extends Importer
} }
} }
ProductionQuantity::updateOrCreate([ ProductionQuantity::updateOrCreate([
'serial_number' => $this->data['serial_number'], 'serial_number' => $this->data['serial_number'],
'plant_id' => $plant->id, 'plant_id' => $plant->id,
@@ -236,7 +239,7 @@ class ProductionQuantityImporter extends Importer
'production_order' => $this->data['production_order'] ?? null, 'production_order' => $this->data['production_order'] ?? null,
'created_at' => $fdateTime->format('Y-m-d H:i:s'), // $this->data['created_at'], 'created_at' => $fdateTime->format('Y-m-d H:i:s'), // $this->data['created_at'],
'updated_at' => $tdateTime->format('Y-m-d H:i:s'), // $this->data['updated_at'], 'updated_at' => $tdateTime->format('Y-m-d H:i:s'), // $this->data['updated_at'],
'operator_id' => $this->data['operator_id'], 'operator_id' => $userName,
]); ]);
// ProductionQuantity::updateOrCreate([ // ProductionQuantity::updateOrCreate([