Changed logic in invoice in transit import page
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 10s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 17s
Laravel Pint / pint (pull_request) Successful in 2m36s
Laravel Larastan / larastan (pull_request) Failing after 3m36s
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 10s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 17s
Laravel Pint / pint (pull_request) Successful in 2m36s
Laravel Larastan / larastan (pull_request) Failing after 3m36s
This commit is contained in:
@@ -351,12 +351,12 @@ class InvoiceInTransitResource extends Resource
|
|||||||
if (empty($transportName)) {
|
if (empty($transportName)) {
|
||||||
$invalidTransportName[] = "Row {$index}";
|
$invalidTransportName[] = "Row {$index}";
|
||||||
}
|
}
|
||||||
if (empty($LRBAWNo)) {
|
// if (empty($LRBAWNo)) {
|
||||||
$invalidLRBLAWNo[] = "Row {$index}";
|
// $invalidLRBLAWNo[] = "Row {$index}";
|
||||||
}
|
// }
|
||||||
if (empty($LRBAWDt)) {
|
// if (empty($LRBAWDt)) {
|
||||||
$invalidLRBLAWDt[] = "Row {$index}";
|
// $invalidLRBLAWDt[] = "Row {$index}";
|
||||||
}
|
// }
|
||||||
if (empty($pendingDays)) {
|
if (empty($pendingDays)) {
|
||||||
$invalidPenDay[] = "Row {$index}";
|
$invalidPenDay[] = "Row {$index}";
|
||||||
}
|
}
|
||||||
@@ -367,50 +367,56 @@ class InvoiceInTransitResource extends Resource
|
|||||||
$invalidPlaCoFound[] = $plantCode;
|
$invalidPlaCoFound[] = $plantCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($LRBAWNo){
|
||||||
|
if(strlen($LRBAWNo) < 2){
|
||||||
|
$invalidLRBLAWNo[] = $LRBAWNo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$plant = Plant::where('code', $plantCode)->first();
|
$plant = Plant::where('code', $plantCode)->first();
|
||||||
|
|
||||||
// $plantId = $plant->id;
|
// $plantId = $plant->id;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($invalidPlantCode) || ! empty($invalidRecPlant) || ! empty($invalidRecPlantName) || ! empty($invalidInvNo) || ! empty($invalidInvDt) || ! empty($invalidICode) || ! empty($invalidDesc) || ! empty($invalidQty) || ($invalidTransportName) || ! empty($invalidLRBLAWNo) || ! empty($invalidLRBLAWDt) || ! empty($invalidPenDay)) {
|
if (! empty($invalidPlantCode) || ! empty($invalidRecPlant) || ! empty($invalidRecPlantName) || ! empty($invalidInvNo) || ! empty($invalidInvDt) || ! empty($invalidICode) || ! empty($invalidDesc) || ! empty($invalidQty) || ($invalidTransportName) || ! empty($invalidPenDay)) {
|
||||||
$errorMsg = '';
|
$errorMsg = '';
|
||||||
|
|
||||||
if (! empty($invalidPlantCode)) {
|
if (! empty($invalidPlantCode)) {
|
||||||
$errorMsg .= 'Missing Receiving Plant in rows: '.implode(', ', $invalidPlantCode).'<br>';
|
$errorMsg .= 'Missing Receiving Plant Code in rows: '.implode(', ', $invalidPlantCode).'<br>';
|
||||||
}
|
}
|
||||||
if (! empty($invalidRecPlant)) {
|
if (! empty($invalidRecPlant)) {
|
||||||
$errorMsg .= 'Missing Receiving Plant Name in rows: '.implode(', ', $invalidRecPlant).'<br>';
|
$errorMsg .= 'Missing Receiving Plant in rows: '.implode(', ', $invalidRecPlant).'<br>';
|
||||||
}
|
}
|
||||||
if (! empty($invalidRecPlantName)) {
|
if (! empty($invalidRecPlantName)) {
|
||||||
$errorMsg .= 'Missing Transit Days in rows: '.implode(', ', $invalidRecPlantName).'<br>';
|
$errorMsg .= 'Missing Receiving Plant Name in rows: '.implode(', ', $invalidRecPlantName).'<br>';
|
||||||
}
|
}
|
||||||
if (! empty($invalidInvNo)) {
|
if (! empty($invalidInvNo)) {
|
||||||
$errorMsg .= 'Missing Transport Name in rows: '.implode(', ', $invalidInvNo).'<br>';
|
$errorMsg .= 'Missing Invoice Number in rows: '.implode(', ', $invalidInvNo).'<br>';
|
||||||
}
|
}
|
||||||
if (! empty($invalidInvDt)) {
|
if (! empty($invalidInvDt)) {
|
||||||
$errorMsg .= 'Missing Receiving Plant in rows: '.implode(', ', $invalidInvDt).'<br>';
|
$errorMsg .= 'Missing Invoice Dates in rows: '.implode(', ', $invalidInvDt).'<br>';
|
||||||
}
|
}
|
||||||
if (! empty($invalidICode)) {
|
if (! empty($invalidICode)) {
|
||||||
$errorMsg .= 'Missing Receiving Plant Name in rows: '.implode(', ', $invalidICode).'<br>';
|
$errorMsg .= 'Missing Item Code in rows: '.implode(', ', $invalidICode).'<br>';
|
||||||
}
|
}
|
||||||
if (! empty($invalidDesc)) {
|
if (! empty($invalidDesc)) {
|
||||||
$errorMsg .= 'Missing Transit Days in rows: '.implode(', ', $invalidDesc).'<br>';
|
$errorMsg .= 'Missing Item Description in rows: '.implode(', ', $invalidDesc).'<br>';
|
||||||
}
|
}
|
||||||
if (! empty($invalidQty)) {
|
if (! empty($invalidQty)) {
|
||||||
$errorMsg .= 'Missing Transport Name in rows: '.implode(', ', $invalidQty).'<br>';
|
$errorMsg .= 'Missing Quantity in rows: '.implode(', ', $invalidQty).'<br>';
|
||||||
}
|
}
|
||||||
if (! empty($invalidTransportName)) {
|
if (! empty($invalidTransportName)) {
|
||||||
$errorMsg .= 'Missing Receiving Plant in rows: '.implode(', ', $invalidTransportName).'<br>';
|
$errorMsg .= 'Missing Transport Name in rows: '.implode(', ', $invalidTransportName).'<br>';
|
||||||
}
|
|
||||||
if (! empty($invalidLRBLAWNo)) {
|
|
||||||
$errorMsg .= 'Missing Receiving Plant Name in rows: '.implode(', ', $invalidLRBLAWNo).'<br>';
|
|
||||||
}
|
|
||||||
if (! empty($invalidLRBLAWDt)) {
|
|
||||||
$errorMsg .= 'Missing Transit Days in rows: '.implode(', ', $invalidLRBLAWDt).'<br>';
|
|
||||||
}
|
}
|
||||||
|
// if (! empty($invalidLRBLAWNo)) {
|
||||||
|
// $errorMsg .= 'Missing Receiving Plant Name in rows: '.implode(', ', $invalidLRBLAWNo).'<br>';
|
||||||
|
// }
|
||||||
|
// if (! empty($invalidLRBLAWDt)) {
|
||||||
|
// $errorMsg .= 'Missing Transit Days in rows: '.implode(', ', $invalidLRBLAWDt).'<br>';
|
||||||
|
// }
|
||||||
if (! empty($invalidPenDay)) {
|
if (! empty($invalidPenDay)) {
|
||||||
$errorMsg .= 'Missing Transport Name in rows: '.implode(', ', $invalidPenDay).'<br>';
|
$errorMsg .= 'Missing Pending Days in rows: '.implode(', ', $invalidPenDay).'<br>';
|
||||||
}
|
}
|
||||||
|
|
||||||
Notification::make()
|
Notification::make()
|
||||||
@@ -454,19 +460,30 @@ class InvoiceInTransitResource extends Resource
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! empty($invalidLRBLAWNo)) {
|
||||||
|
$invalidLRBLAWNo = array_unique($invalidLRBLAWNo);
|
||||||
|
Notification::make()
|
||||||
|
->title('Invalid LR/BL/AW Number')
|
||||||
|
->body('LR/BL/AW Number should contain length minimum 2 digits:<br>'.implode(', ', $invalidLRBLAWNo))
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
if ($disk->exists($path)) {
|
||||||
|
$disk->delete($path);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$mandatoryColumns = 23;
|
$mandatoryColumns = 23;
|
||||||
|
|
||||||
$firstRow = $rows[0] ?? [];
|
$firstRow = $rows[0] ?? [];
|
||||||
|
|
||||||
if (count($firstRow) < $mandatoryColumns) {
|
if (count($firstRow) < $mandatoryColumns) {
|
||||||
|
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('Invalid Excel Format')
|
->title('Invalid Excel Format')
|
||||||
->body('Few columns not found. Columns A to W are mandatory.')
|
->body('Few columns not found. Columns A to W are mandatory.')
|
||||||
->danger()
|
->danger()
|
||||||
->persistent()
|
->persistent()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -530,7 +547,7 @@ class InvoiceInTransitResource extends Resource
|
|||||||
if (! empty($OBDDate)) {
|
if (! empty($OBDDate)) {
|
||||||
if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $OBDDate)) {
|
if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $OBDDate)) {
|
||||||
[$day, $month, $year] = preg_split('/[-\/]/', $OBDDate);
|
[$day, $month, $year] = preg_split('/[-\/]/', $OBDDate);
|
||||||
$formattedDate = "{$year}-{$month}-{$day}";
|
$formatted = "{$year}-{$month}-{$day}";
|
||||||
} elseif (is_numeric($OBDDate)) {
|
} elseif (is_numeric($OBDDate)) {
|
||||||
$formatted = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($OBDDate)->format('Y-m-d');
|
$formatted = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($OBDDate)->format('Y-m-d');
|
||||||
} else {
|
} else {
|
||||||
@@ -540,6 +557,16 @@ class InvoiceInTransitResource extends Resource
|
|||||||
$formatted = null;
|
$formatted = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$rowNumber = $index + 1;
|
||||||
|
if ($LRBAWNo == '' || $LRBAWDt == '') {
|
||||||
|
// $missedInvoices[] = $invoiceNo;
|
||||||
|
// $missedInvoices[$invoiceNo][] = $index + 1;
|
||||||
|
// continue;
|
||||||
|
$key = $invoiceNo ?: 'Row '.$rowNumber;
|
||||||
|
$missedInvoices[$key][$rowNumber] = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$inserted = InvoiceInTransit::create([
|
$inserted = InvoiceInTransit::create([
|
||||||
'plant_id' => $plant->id,
|
'plant_id' => $plant->id,
|
||||||
'receiving_plant' => $receivingPlant,
|
'receiving_plant' => $receivingPlant,
|
||||||
@@ -567,10 +594,28 @@ class InvoiceInTransitResource extends Resource
|
|||||||
'created_by' => $operatorName,
|
'created_by' => $operatorName,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$formattedMissed = [];
|
||||||
|
|
||||||
|
if (!empty($missedInvoices)) {
|
||||||
|
$formattedMissed = array_map(
|
||||||
|
fn($rows, $invoice) =>
|
||||||
|
$invoice . ' (Row: ' . implode(', ', array_keys($rows)) . ')',
|
||||||
|
$missedInvoices,
|
||||||
|
array_keys($missedInvoices)
|
||||||
|
);
|
||||||
|
}
|
||||||
if ($inserted) {
|
if ($inserted) {
|
||||||
|
$message = "Invoice in transit uploaded successfully!";
|
||||||
|
|
||||||
|
if (!empty($formattedMissed)) {
|
||||||
|
$message .= "\n\nSkipped Invoices (Missing LR/Date):\n"
|
||||||
|
. implode("\n", $formattedMissed);
|
||||||
|
}
|
||||||
|
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('Upload Success')
|
->title('Upload Completed')
|
||||||
->body('Invoice in transit uploaded successfully!')
|
->body($message)
|
||||||
->success()
|
->success()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user