Enhance invoice validation by adding plant type checks and improving error handling for imports
This commit is contained in:
@@ -203,30 +203,35 @@ class InvoiceDataValidationResource extends Resource
|
||||
$invalidCusLocation = [];
|
||||
$invalidUser = [];
|
||||
$userNotFound = [];
|
||||
$invalidPlantType = [];
|
||||
|
||||
foreach ($rows as $index => $row)
|
||||
{
|
||||
if ($index == 0) continue; // Skip header
|
||||
|
||||
$plantCode = trim($row[0]);
|
||||
$DisChaDesc = trim($row[1]);
|
||||
$CustomerCode = trim($row[2]);
|
||||
$DocNo = trim($row[3]);
|
||||
$DocDate = trim($row[4]);
|
||||
$CusTradeName = trim($row[5]);
|
||||
$CusLocation = trim($row[6]);
|
||||
|
||||
if (empty($plantCode)) $invalidPlantCode[] = "Row {$index}";
|
||||
//if (empty($DisChaDesc)) $invalidDisChaDesc[] = "Row {$index}";
|
||||
if (empty($CustomerCode)) $invalidCustomerCode[] = "Row {$index}";
|
||||
$DisChaDesc = trim($row[3]);
|
||||
$plantCode = trim($row[4]);
|
||||
$CustomerCode = trim($row[5]);
|
||||
$DocNo = trim($row[6]);
|
||||
$DocDate = trim($row[7]);
|
||||
$CusTradeName = trim($row[9]);
|
||||
$CusLocation = trim($row[10]);
|
||||
|
||||
// if (empty($plantCode)) $invalidPlantCode[] = "Row {$index}";
|
||||
if (empty($DisChaDesc)) $invalidDisChaDesc[] = "Row {$index}";
|
||||
if (empty($CustomerCode)) $invalidCustomerCode[] = "Row {$index}";
|
||||
if (empty($DocNo)) $invalidDocNo[] = "Row {$index}";
|
||||
if (empty($CusTradeName)) $invalidCusTradeName[] = "Row {$index}";
|
||||
if (empty($CusLocation)) $invalidCusLocation[] = "Row {$index}";
|
||||
// if (empty($createdBy)) $invalidUser[] = "Row {$index}";
|
||||
if (empty($CusTradeName)) $invalidCusTradeName[] = "Row {$index}";
|
||||
if (empty($CusLocation)) $invalidCusLocation[] = "Row {$index}";
|
||||
// if (empty($createdBy)) $invalidUser[] = "Row {$index}";
|
||||
|
||||
if (strlen($plantCode) < 4) {
|
||||
$invalidPlantCode[] = $plantCode;
|
||||
}
|
||||
if (!is_numeric($plantCode)) {
|
||||
$invalidPlantType[] = $plantCode;
|
||||
}
|
||||
else if(!Plant::where('code', $plantCode)->first())
|
||||
{
|
||||
$invalidPlaCoFound[] = $plantCode;
|
||||
@@ -241,7 +246,7 @@ class InvoiceDataValidationResource extends Resource
|
||||
|
||||
//!empty($invalidDisChaDesc) ||
|
||||
|
||||
if (!empty($invalidCustomerCode) || !empty($invalidDocNo) || !empty($invalidDocDate) || !empty($invalidCusTradeName) || !empty($invalidCusLocation) || !empty($invalidUser))
|
||||
if (!empty($invalidCustomerCode) || !empty($invalidDocNo) || !empty($invalidDocDate) || !empty($invalidCusTradeName) || !empty($invalidCusLocation))
|
||||
{
|
||||
$errorMsg = '';
|
||||
|
||||
@@ -251,7 +256,6 @@ class InvoiceDataValidationResource extends Resource
|
||||
if (!empty($invalidDocDate)) $errorMsg .= 'Missing Document Date in rows: ' . implode(', ', $invalidDocDate) . '<br>';
|
||||
if (!empty($invalidCusTradeName)) $errorMsg .= 'Missing Customer Trade Name in rows: ' . implode(', ', $invalidCusTradeName) . '<br>';
|
||||
if (!empty($invalidCusLocation)) $errorMsg .= 'Missing Customer Location in rows: ' . implode(', ', $invalidCusLocation) . '<br>';
|
||||
if (!empty($invalidUser)) $errorMsg .= 'Missing User in rows: ' . implode(', ', $invalidUser) . '<br>';
|
||||
|
||||
Notification::make()
|
||||
->title('Missing Mandatory Fields')
|
||||
@@ -265,6 +269,30 @@ class InvoiceDataValidationResource extends Resource
|
||||
return;
|
||||
}
|
||||
|
||||
// if (!empty($invalidDocNo) || !empty($invalidUser))
|
||||
// {
|
||||
// $errorMsg = '';
|
||||
|
||||
// //if (!empty($invalidDisChaDesc)) $errorMsg .= 'Missing Distribution Channel Description in rows: ' . implode(', ', $invalidDisChaDesc) . '<br>';
|
||||
// //if (!empty($invalidCustomerCode)) $errorMsg .= 'Missing Customer Code in rows: ' . implode(', ', $invalidCustomerCode) . '<br>';
|
||||
// if (!empty($invalidDocNo)) $errorMsg .= 'Missing Document Number in rows: ' . implode(', ', $invalidDocNo) . '<br>';
|
||||
// //if (!empty($invalidDocDate)) $errorMsg .= 'Missing Document Date in rows: ' . implode(', ', $invalidDocDate) . '<br>';
|
||||
// //if (!empty($invalidCusTradeName)) $errorMsg .= 'Missing Customer Trade Name in rows: ' . implode(', ', $invalidCusTradeName) . '<br>';
|
||||
// //if (!empty($invalidCusLocation)) $errorMsg .= 'Missing Customer Location in rows: ' . implode(', ', $invalidCusLocation) . '<br>';
|
||||
// //if (!empty($invalidUser)) $errorMsg .= 'Missing User in rows: ' . implode(', ', $invalidUser) . '<br>';
|
||||
|
||||
// Notification::make()
|
||||
// ->title('Missing Mandatory Fields')
|
||||
// ->body($errorMsg)
|
||||
// ->danger()
|
||||
// ->send();
|
||||
|
||||
// if ($disk->exists($path)) {
|
||||
// $disk->delete($path);
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (!empty($invalidPlantCode)) {
|
||||
$invalidPlantCode = array_unique($invalidPlantCode);
|
||||
Notification::make()
|
||||
@@ -277,6 +305,19 @@ class InvoiceDataValidationResource extends Resource
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if(!empty($invalidPlantType))
|
||||
{
|
||||
$invalidPlantType = array_unique($invalidPlantType);
|
||||
Notification::make()
|
||||
->title('Invalid Plant Codes')
|
||||
->body('The following plant codes should contain numeric values:<br>' . implode(', ', $invalidPlantType))
|
||||
->danger()
|
||||
->send();
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!empty($invalidPlaCoFound)) {
|
||||
$invalidPlaCoFound = array_unique($invalidPlaCoFound);
|
||||
Notification::make()
|
||||
@@ -308,13 +349,13 @@ class InvoiceDataValidationResource extends Resource
|
||||
foreach ($rows as $index => $row) {
|
||||
if ($index == 0) continue;
|
||||
|
||||
$plantCode = trim($row[0]);
|
||||
$DisChaDesc = trim($row[1]);
|
||||
$CustomerCode = trim($row[2]);
|
||||
$DocNo = trim($row[3]);
|
||||
$DocDate = trim($row[4]);
|
||||
$CusTradeName = trim($row[5]);
|
||||
$CusLocation = trim($row[6]);
|
||||
$DisChaDesc = trim($row[3]);
|
||||
$plantCode = trim($row[4]);
|
||||
$CustomerCode = trim($row[5]);
|
||||
$DocNo = trim($row[6]);
|
||||
$DocDate = trim($row[7]);
|
||||
$CusTradeName = trim($row[9]);
|
||||
$CusLocation = trim($row[10]);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -375,9 +416,9 @@ class InvoiceDataValidationResource extends Resource
|
||||
return Filament::auth()->user()->can('view import invoice data validation');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->exporter(InvoiceDataValidationExporter::class)
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view export invoice data validation');
|
||||
->exporter(InvoiceDataValidationExporter::class)
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view export invoice data validation');
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user