Merge pull request 'Changed importer production quantities importer logic' (#1423) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 24s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 24s
Reviewed-on: #1423
This commit was merged in pull request #1423.
This commit is contained in:
@@ -83,12 +83,12 @@ class ProductionQuantityImporter extends Importer
|
||||
->example(['01-01-2025 08:00:00', '01-01-2025 19:30:00'])
|
||||
->label('Updated DateTime')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('operator_id')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Operator ID')
|
||||
->example([Filament::auth()->user()->name, Filament::auth()->user()->name])
|
||||
->label('Operator ID')
|
||||
->rules(['required']),
|
||||
// ImportColumn::make('operator_id')
|
||||
// ->requiredMapping()
|
||||
// ->exampleHeader('Operator ID')
|
||||
// ->example([Filament::auth()->user()->name, Filament::auth()->user()->name])
|
||||
// ->label('Operator ID')
|
||||
// ->rules(['required']),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -133,59 +133,64 @@ class ProductionQuantityImporter extends Importer
|
||||
$fromDate = $this->data['created_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;
|
||||
$tdateTime = null;
|
||||
// Try parsing with multiple formats
|
||||
|
||||
// Parse Created DateTime
|
||||
foreach ($formats as $format) {
|
||||
try {
|
||||
$fdateTime = Carbon::createFromFormat($format, $fromDate);
|
||||
break;
|
||||
$fdateTime = Carbon::createFromFormat('!' . $format, trim($fromDate));
|
||||
|
||||
if ($fdateTime !== false) {
|
||||
break;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Optionally collect warning messages
|
||||
// $warnMsg[] = "Date format mismatch with format: $format";
|
||||
$fdateTime = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse Updated DateTime
|
||||
foreach ($formats as $format) {
|
||||
try {
|
||||
$tdateTime = Carbon::createFromFormat($format, $toDate);
|
||||
break;
|
||||
$tdateTime = Carbon::createFromFormat('!' . $format, trim($toDate));
|
||||
|
||||
if ($tdateTime !== false) {
|
||||
break;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Optionally collect warning messages
|
||||
// $warnMsg[] = "Date format mismatch with format: $format";
|
||||
$tdateTime = null;
|
||||
}
|
||||
}
|
||||
|
||||
// $fDateOnly = '';
|
||||
if (! isset($fdateTime)) {
|
||||
// throw new \Exception('Invalid date time format');
|
||||
$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";
|
||||
// Validate Created DateTime
|
||||
if (! $fdateTime) {
|
||||
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YY HH:MM:SS AM/PM";
|
||||
}
|
||||
|
||||
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)) {
|
||||
$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";
|
||||
// }
|
||||
// else if (!$toDate) {
|
||||
// $warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||
|
||||
// $user = User::where('name', $this->data['operator_id'])->first();
|
||||
// if (! $user) {
|
||||
// $warnMsg[] = 'Operator ID not found';
|
||||
// }
|
||||
|
||||
$user = User::where('name', $this->data['operator_id'])->first();
|
||||
if (! $user) {
|
||||
$warnMsg[] = 'Operator ID not found';
|
||||
}
|
||||
$userName = Filament::auth()->user()->name;
|
||||
|
||||
$shift = null;
|
||||
|
||||
@@ -225,8 +230,6 @@ class ProductionQuantityImporter extends Importer
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
ProductionQuantity::updateOrCreate([
|
||||
'serial_number' => $this->data['serial_number'],
|
||||
'plant_id' => $plant->id,
|
||||
@@ -236,7 +239,7 @@ class ProductionQuantityImporter extends Importer
|
||||
'production_order' => $this->data['production_order'] ?? null,
|
||||
'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'],
|
||||
'operator_id' => $this->data['operator_id'],
|
||||
'operator_id' => $userName,
|
||||
]);
|
||||
|
||||
// ProductionQuantity::updateOrCreate([
|
||||
|
||||
Reference in New Issue
Block a user