changed update scenario logic in invoice out validations page
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 11s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 16s
Laravel Pint / pint (pull_request) Successful in 2m50s
Laravel Larastan / larastan (pull_request) Failing after 3m39s

This commit is contained in:
dhanabalan
2026-01-20 11:54:24 +05:30
parent d41371a32d
commit ad143d723a

View File

@@ -398,12 +398,12 @@ class InvoiceOutValidationResource extends Resource
// }
$successCount = 0;
$updateCount = 0;
$insertCount = 0;
$failedRecords = [];
DB::beginTransaction();
try {
foreach ($rows as $index => $row) {
foreach ($rows as $index => $row)
{
if ($index == 0) {
continue;
}
@@ -443,43 +443,28 @@ class InvoiceOutValidationResource extends Resource
}
}
$record = InvoiceOutValidation::where('plant_id', $plant->id)
$exists = InvoiceOutValidation::where('plant_id', $plant->id)
->where('qr_code', $qrcode)
->first();
$curStat = $record ? 'Updation' : 'Insertion';
if ($record) {
$record->update([
InvoiceOutValidation::updateOrCreate(
[
'plant_id' => $plant->id,
'qr_code' => $qrcode,
],
[
'scanned_at' => $formattedDate,
'scanned_by' => $scannedBy,
'updated_by' => $operatorName,
]);
$inserted = $record;
} else {
// Record does not exist, create with 'created_by'
$inserted = InvoiceOutValidation::create([
'plant_id' => $plant->id,
'qr_code' => $qrcode,
'scanned_at' => $formattedDate,
'scanned_by' => $scannedBy,
'created_by' => $operatorName,
]);
}
// $inserted = InvoiceOutValidation::create([
// 'plant_id' => $plant->id,
// 'qr_code' => $qrcode,
// 'scanned_at' => $formattedDate,
// 'scanned_by' => $scannedBy,
// 'created_by' => $operatorName
// ]);
if (! $inserted) {
throw new \Exception("{$curStat} failed for QR : {$qrcode}");
}
]
);
$exists ? $updateCount++ : $insertCount++;
$successCount++;
} catch (\Exception $e) {
}
catch (\Exception $e) {
$failedRecords[] = [
'row' => $rowNumber,
'qrcode' => $qrcode ?? null,
@@ -488,34 +473,31 @@ class InvoiceOutValidationResource extends Resource
}
}
DB::commit();
if (count($failedRecords) > 0) {
$failedSummary = collect($failedRecords)
->map(fn ($f) => "Row {$f['row']} ({$f['qrcode']}) : {$f['error']}")
->take(5) // limit preview to first 5 errors
->take(5)
->implode("\n");
Notification::make()
->title('Partial Import Warning')
->body("'{$successCount}' records inserted. ".count($failedRecords)." failed.\n\n{$failedSummary}")
->body(
"Total Success: {$successCount}\n" .
"Inserted: {$insertCount}\n" .
"Updated: {$updateCount}\n" .
"Failed: " . count($failedRecords) . "\n\n" .
$failedSummary
)
->warning()
->send();
} else {
}
else
{
Notification::make()
->title('Import Success')
->body("Successfully imported '{$successCount}' records.")
->success()
->send();
}
} catch (\Exception $e) {
DB::rollBack();
Notification::make()
->title('Import Failed')
->body("No records were inserted. Error : {$e->getMessage()}")
->danger()
->send();
}
}
})
->visible(function () {