Merge pull request 'Refactor: Clean up imports and enhance form/table structure in InvoiceDataValidation and InvoiceOutValidation resources' (#15) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s

Reviewed-on: #15
This commit was merged in pull request #15.
This commit is contained in:
2025-11-27 05:29:19 +00:00
2 changed files with 237 additions and 205 deletions

View File

@@ -4,27 +4,23 @@ namespace App\Filament\Resources;
use App\Filament\Exports\InvoiceDataValidationExporter; use App\Filament\Exports\InvoiceDataValidationExporter;
use App\Filament\Resources\InvoiceDataValidationResource\Pages; use App\Filament\Resources\InvoiceDataValidationResource\Pages;
use App\Filament\Resources\InvoiceDataValidationResource\RelationManagers;
use App\Models\InvoiceDataValidation; use App\Models\InvoiceDataValidation;
use App\Models\Plant;
use DB;
use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Notifications\Notification;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Table; use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Facades\Filament;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Select;
use Filament\Notifications\Notification;
use App\Models\Plant;
use Filament\Forms\Get;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Maatwebsite\Excel\Facades\Excel; use Maatwebsite\Excel\Facades\Excel;
use App\Models\StickerMaster;
use App\Models\User;
use DB;
use Filament\Tables\Actions\ExportAction;
class InvoiceDataValidationResource extends Resource class InvoiceDataValidationResource extends Resource
{ {
@@ -67,6 +63,7 @@ class InvoiceDataValidationResource extends Resource
->label('Created By') ->label('Created By')
->default(Filament::auth()->user()?->name), ->default(Filament::auth()->user()?->name),
Forms\Components\Hidden::make('updated_by') Forms\Components\Hidden::make('updated_by')
->label('Updated By')
->default(Filament::auth()->user()?->name), ->default(Filament::auth()->user()?->name),
]); ]);
} }
@@ -77,10 +74,12 @@ class InvoiceDataValidationResource extends Resource
->columns([ ->columns([
Tables\Columns\TextColumn::make('No.') Tables\Columns\TextColumn::make('No.')
->label('No.') ->label('No.')
->alignCenter()
->getStateUsing(function ($record, $livewire, $column, $rowLoop) { ->getStateUsing(function ($record, $livewire, $column, $rowLoop) {
$paginator = $livewire->getTableRecords(); $paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10; $perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1; $currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration; return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}), }),
Tables\Columns\TextColumn::make('plant.code') Tables\Columns\TextColumn::make('plant.code')
@@ -100,8 +99,8 @@ class InvoiceDataValidationResource extends Resource
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('document_number') Tables\Columns\TextColumn::make('document_number')
->label('Document Number') ->label('Document Number')
->searchable()
->alignCenter() ->alignCenter()
->searchable()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('document_date') Tables\Columns\TextColumn::make('document_date')
->label('Document Date') ->label('Document Date')
@@ -127,15 +126,27 @@ class InvoiceDataValidationResource extends Resource
Tables\Columns\TextColumn::make('created_at') Tables\Columns\TextColumn::make('created_at')
->label('Created At') ->label('Created At')
->alignCenter() ->alignCenter()
->searchable()
->dateTime() ->dateTime()
->sortable() ->sortable(),
->toggleable(isToggledHiddenByDefault: true), // ->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('created_by')
->label('Created By')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('updated_at') Tables\Columns\TextColumn::make('updated_at')
->label('Updated At') ->label('Updated At')
->alignCenter() ->alignCenter()
->searchable()
->dateTime() ->dateTime()
->sortable() ->sortable(),
->toggleable(isToggledHiddenByDefault: true), // ->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_by')
->label('Updated By')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('deleted_at') Tables\Columns\TextColumn::make('deleted_at')
->label('Deleted At') ->label('Deleted At')
->alignCenter() ->alignCenter()
@@ -191,12 +202,10 @@ class InvoiceDataValidationResource extends Resource
$fullPath = Storage::disk('local')->path($path); $fullPath = Storage::disk('local')->path($path);
if ($fullPath && file_exists($fullPath)) if ($fullPath && file_exists($fullPath)) {
{
$rows = Excel::toArray(null, $fullPath)[0]; $rows = Excel::toArray(null, $fullPath)[0];
if ((count($rows) - 1) <= 0) if ((count($rows) - 1) <= 0) {
{
Notification::make() Notification::make()
->title('Records Not Found') ->title('Records Not Found')
->body("Import the valid 'Invoice Data' file to proceed..!") ->body("Import the valid 'Invoice Data' file to proceed..!")
@@ -206,6 +215,7 @@ class InvoiceDataValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} }
@@ -226,9 +236,10 @@ class InvoiceDataValidationResource extends Resource
// $duplicateEntries = []; // $duplicateEntries = [];
$duplicateEntriesExcel = []; $duplicateEntriesExcel = [];
foreach ($rows as $index => $row) foreach ($rows as $index => $row) {
{ if ($index == 0) {
if ($index == 0) continue; // Skip header continue;
} // Skip header
$DisChaDesc = trim($row[3]); $DisChaDesc = trim($row[3]);
$plantCode = trim($row[4]); $plantCode = trim($row[4]);
@@ -246,20 +257,16 @@ class InvoiceDataValidationResource extends Resource
if (empty($CustomerCode)) { if (empty($CustomerCode)) {
$invalidCustomerCode[] = "Row {$index}"; $invalidCustomerCode[] = "Row {$index}";
} }
if (empty($DocNo)) if (empty($DocNo)) {
{
$invalidDocNo[] = "Row {$index}"; $invalidDocNo[] = "Row {$index}";
} }
if (empty($CusTradeName)) if (empty($CusTradeName)) {
{
$invalidCusTradeName[] = "Row {$index}"; $invalidCusTradeName[] = "Row {$index}";
} }
if (empty($CusLocation)) if (empty($CusLocation)) {
{
$invalidCusLocation[] = "Row {$index}"; $invalidCusLocation[] = "Row {$index}";
} }
if (empty($Location)) if (empty($Location)) {
{
$invalidLocation[] = "Row {$index}"; $invalidLocation[] = "Row {$index}";
} }
// if (empty($createdBy)) $invalidUser[] = "Row {$index}"; // if (empty($createdBy)) $invalidUser[] = "Row {$index}";
@@ -269,9 +276,7 @@ class InvoiceDataValidationResource extends Resource
} }
if (! is_numeric($plantCode)) { if (! is_numeric($plantCode)) {
$invalidPlantType[] = $plantCode; $invalidPlantType[] = $plantCode;
} } elseif (! Plant::where('code', $plantCode)->first()) {
else if (!Plant::where('code', $plantCode)->first())
{
$invalidPlaCoFound[] = $plantCode; $invalidPlaCoFound[] = $plantCode;
} }
@@ -296,17 +301,28 @@ class InvoiceDataValidationResource extends Resource
$seenPlantDoc[] = $uniqueKey; $seenPlantDoc[] = $uniqueKey;
} }
if (!empty($invalidCustomerCode) || !empty($invalidDocNo) || !empty($invalidDocDate) || !empty($invalidCusTradeName) || !empty($invalidCusLocation)) if (! empty($invalidCustomerCode) || ! empty($invalidDocNo) || ! empty($invalidDocDate) || ! empty($invalidCusTradeName) || ! empty($invalidCusLocation)) {
{
$errorMsg = ''; $errorMsg = '';
// if (!empty($invalidDisChaDesc)) $errorMsg .= 'Missing Distribution Channel Description in rows: ' . implode(', ', $invalidDisChaDesc) . '<br>'; // 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($invalidCustomerCode)) {
if (!empty($invalidDocNo)) $errorMsg .= 'Missing Document Number in rows: ' . implode(', ', $invalidDocNo) . '<br>'; $errorMsg .= 'Missing Customer Code in rows: '.implode(', ', $invalidCustomerCode).'<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($invalidDocNo)) {
if (!empty($invalidCusLocation)) $errorMsg .= 'Missing Customer Location in rows: ' . implode(', ', $invalidCusLocation) . '<br>'; $errorMsg .= 'Missing Document Number in rows: '.implode(', ', $invalidDocNo).'<br>';
if (!empty($invalidLocation)) $errorMsg .= 'Missing Location in rows: ' . implode(', ', $invalidLocation) . '<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($invalidLocation)) {
$errorMsg .= 'Missing Location in rows: '.implode(', ', $invalidLocation).'<br>';
}
Notification::make() Notification::make()
->title('Missing Mandatory Fields') ->title('Missing Mandatory Fields')
@@ -317,10 +333,9 @@ class InvoiceDataValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} } elseif (! empty($invalidPlantCode)) {
else if (!empty($invalidPlantCode))
{
$invalidPlantCode = array_unique($invalidPlantCode); $invalidPlantCode = array_unique($invalidPlantCode);
Notification::make() Notification::make()
->title('Invalid Plant Codes') ->title('Invalid Plant Codes')
@@ -330,10 +345,9 @@ class InvoiceDataValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} } elseif (! empty($invalidPlantType)) {
else if (!empty($invalidPlantType))
{
$invalidPlantType = array_unique($invalidPlantType); $invalidPlantType = array_unique($invalidPlantType);
Notification::make() Notification::make()
->title('Invalid Plant Codes') ->title('Invalid Plant Codes')
@@ -343,10 +357,9 @@ class InvoiceDataValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} } elseif (! empty($invalidPlaCoFound)) {
else if (!empty($invalidPlaCoFound))
{
$invalidPlaCoFound = array_unique($invalidPlaCoFound); $invalidPlaCoFound = array_unique($invalidPlaCoFound);
Notification::make() Notification::make()
->title('Invalid Plant Codes') ->title('Invalid Plant Codes')
@@ -356,6 +369,7 @@ class InvoiceDataValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} }
@@ -401,8 +415,7 @@ class InvoiceDataValidationResource extends Resource
// return; // return;
// } // }
if (!empty($duplicateEntriesExcel)) if (! empty($duplicateEntriesExcel)) {
{
$duplicateGroupedByPlantExcel = []; $duplicateGroupedByPlantExcel = [];
foreach ($duplicateEntriesExcel as $message) {// "/Document Number '([^']+)' already exist(?:s)?(?: for Plant (.+))?/" foreach ($duplicateEntriesExcel as $message) {// "/Document Number '([^']+)' already exist(?:s)?(?: for Plant (.+))?/"
@@ -415,8 +428,7 @@ class InvoiceDataValidationResource extends Resource
$errorMsg = 'Duplicate Document Number found in Uploaded File :<br>'; $errorMsg = 'Duplicate Document Number found in Uploaded File :<br>';
foreach ($duplicateGroupedByPlantExcel as $plant => $docNumbers) foreach ($duplicateGroupedByPlantExcel as $plant => $docNumbers) {
{
// Remove duplicate document numbers for each plant // Remove duplicate document numbers for each plant
$uniqueDocNumbers = array_unique($docNumbers); $uniqueDocNumbers = array_unique($docNumbers);
$count = count($uniqueDocNumbers); $count = count($uniqueDocNumbers);
@@ -439,6 +451,7 @@ class InvoiceDataValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} }
@@ -455,10 +468,11 @@ class InvoiceDataValidationResource extends Resource
DB::beginTransaction(); DB::beginTransaction();
try try {
{
foreach ($rows as $index => $row) { foreach ($rows as $index => $row) {
if ($index == 0) continue; if ($index == 0) {
continue;
}
$rowNumber = $index + 1; $rowNumber = $index + 1;
@@ -508,7 +522,7 @@ class InvoiceDataValidationResource extends Resource
'customer_trade_name' => $CusTradeName, 'customer_trade_name' => $CusTradeName,
'customer_location' => $CusLocation, 'customer_location' => $CusLocation,
'location' => $Location, 'location' => $Location,
'updated_by' => $operatorName 'updated_by' => $operatorName,
]); ]);
$inserted = $record; $inserted = $record;
} else { } else {
@@ -522,7 +536,7 @@ class InvoiceDataValidationResource extends Resource
'customer_trade_name' => $CusTradeName, 'customer_trade_name' => $CusTradeName,
'customer_location' => $CusLocation, 'customer_location' => $CusLocation,
'location' => $Location, 'location' => $Location,
'created_by' => $operatorName 'created_by' => $operatorName,
]); ]);
} }
// $inserted = InvoiceDataValidation::create([ // $inserted = InvoiceDataValidation::create([
@@ -545,7 +559,7 @@ class InvoiceDataValidationResource extends Resource
$failedRecords[] = [ $failedRecords[] = [
'row' => $rowNumber, 'row' => $rowNumber,
'document_number' => $DocNo ?? null, 'document_number' => $DocNo ?? null,
'error' => $e->getMessage() 'error' => $e->getMessage(),
]; ];
} }
} }
@@ -570,9 +584,7 @@ class InvoiceDataValidationResource extends Resource
->success() ->success()
->send(); ->send();
} }
} } catch (\Exception $e) {
catch (\Exception $e)
{
DB::rollBack(); DB::rollBack();
Notification::make() Notification::make()
->title('Import Failed') ->title('Import Failed')

View File

@@ -4,27 +4,25 @@ namespace App\Filament\Resources;
use App\Filament\Exports\InvoiceOutValidationExporter; use App\Filament\Exports\InvoiceOutValidationExporter;
use App\Filament\Resources\InvoiceOutValidationResource\Pages; use App\Filament\Resources\InvoiceOutValidationResource\Pages;
use App\Filament\Resources\InvoiceOutValidationResource\RelationManagers;
use App\Models\InvoiceOutValidation; use App\Models\InvoiceOutValidation;
use App\Models\Plant; use App\Models\Plant;
use App\Models\User;
use Carbon\Carbon; use Carbon\Carbon;
use DB; use DB;
use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Section;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Table; use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Facades\Filament;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Section;
use Filament\Notifications\Notification;
use Maatwebsite\Excel\Facades\Excel; use Maatwebsite\Excel\Facades\Excel;
use Storage;
use Filament\Tables\Actions\ExportAction;
use PhpOffice\PhpSpreadsheet\Shared\Date as ExcelDate; use PhpOffice\PhpSpreadsheet\Shared\Date as ExcelDate;
use Storage;
class InvoiceOutValidationResource extends Resource class InvoiceOutValidationResource extends Resource
{ {
@@ -54,6 +52,7 @@ class InvoiceOutValidationResource extends Resource
->label('Created By') ->label('Created By')
->default(Filament::auth()->user()?->name), ->default(Filament::auth()->user()?->name),
Forms\Components\Hidden::make('updated_by') Forms\Components\Hidden::make('updated_by')
->label('Updated By')
->default(Filament::auth()->user()?->name), ->default(Filament::auth()->user()?->name),
]) ])
->columns(4), ->columns(4),
@@ -66,15 +65,18 @@ class InvoiceOutValidationResource extends Resource
->columns([ ->columns([
Tables\Columns\TextColumn::make('No.') Tables\Columns\TextColumn::make('No.')
->label('No.') ->label('No.')
->alignCenter()
->getStateUsing(function ($record, $livewire, $column, $rowLoop) { ->getStateUsing(function ($record, $livewire, $column, $rowLoop) {
$paginator = $livewire->getTableRecords(); $paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10; $perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1; $currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration; return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}), }),
Tables\Columns\TextColumn::make('plant.code') Tables\Columns\TextColumn::make('plant.code')
->label('Plant') ->label('Plant')
->alignCenter() ->alignCenter()
->searchable()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('qr_code') Tables\Columns\TextColumn::make('qr_code')
->label('QR Code') ->label('QR Code')
@@ -93,8 +95,10 @@ class InvoiceOutValidationResource extends Resource
->alignCenter() ->alignCenter()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('created_at') Tables\Columns\TextColumn::make('created_at')
->searchable() ->label('Created At')
->dateTime() ->dateTime()
->searchable()
->alignCenter()
->sortable(), ->sortable(),
// ->toggleable(isToggledHiddenByDefault: true), // ->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('created_by') Tables\Columns\TextColumn::make('created_by')
@@ -103,8 +107,10 @@ class InvoiceOutValidationResource extends Resource
->alignCenter() ->alignCenter()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('updated_at') Tables\Columns\TextColumn::make('updated_at')
->label('Updated At')
->dateTime() ->dateTime()
->searchable() ->searchable()
->alignCenter()
->sortable(), ->sortable(),
// ->toggleable(isToggledHiddenByDefault: true), // ->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_by') Tables\Columns\TextColumn::make('updated_by')
@@ -114,6 +120,7 @@ class InvoiceOutValidationResource extends Resource
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('deleted_at') Tables\Columns\TextColumn::make('deleted_at')
->dateTime() ->dateTime()
->alignCenter()
->sortable() ->sortable()
->toggleable(isToggledHiddenByDefault: true), ->toggleable(isToggledHiddenByDefault: true),
]) ])
@@ -165,12 +172,10 @@ class InvoiceOutValidationResource extends Resource
$fullPath = Storage::disk('local')->path($path); $fullPath = Storage::disk('local')->path($path);
if ($fullPath && file_exists($fullPath)) if ($fullPath && file_exists($fullPath)) {
{
$rows = Excel::toArray(null, $fullPath)[0]; $rows = Excel::toArray(null, $fullPath)[0];
if ((count($rows) - 1) <= 0) if ((count($rows) - 1) <= 0) {
{
Notification::make() Notification::make()
->title('Records Not Found') ->title('Records Not Found')
->body("Import the valid 'Invoice Data' file to proceed..!") ->body("Import the valid 'Invoice Data' file to proceed..!")
@@ -180,6 +185,7 @@ class InvoiceOutValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} }
@@ -194,25 +200,32 @@ class InvoiceOutValidationResource extends Resource
$duplicateQrExcel = []; $duplicateQrExcel = [];
// $duplicateQrDb = []; // $duplicateQrDb = [];
foreach ($rows as $index => $row) foreach ($rows as $index => $row) {
{ if ($index == 0) {
if ($index == 0) continue; continue;
}
$qrCode = trim($row[1]); $qrCode = trim($row[1]);
$plantCode = trim($row[2]); $plantCode = trim($row[2]);
$scannedAt = trim($row[3]); $scannedAt = trim($row[3]);
$scannedby = trim($row[4]); $scannedby = trim($row[4]);
if (empty($plantCode)) $invalidPlantCode[] = "Row {$index}"; if (empty($plantCode)) {
if (empty($qrCode)) $invalidqrCode[] = "Row {$index}"; $invalidPlantCode[] = "Row {$index}";
if (empty($scannedAt)) $invalidScannedAt[] = "Row {$index}"; }
if (empty($scannedby)) $invalidScannedBy[] = "Row {$index}"; if (empty($qrCode)) {
$invalidqrCode[] = "Row {$index}";
}
if (empty($scannedAt)) {
$invalidScannedAt[] = "Row {$index}";
}
if (empty($scannedby)) {
$invalidScannedBy[] = "Row {$index}";
}
if (strlen($plantCode) < 4) { if (strlen($plantCode) < 4) {
$invalidPlantCode[] = $plantCode; $invalidPlantCode[] = $plantCode;
} } elseif (! Plant::where('code', $plantCode)->first()) {
else if(!Plant::where('code', $plantCode)->first())
{
$invalidPlaCoFound[] = $plantCode; $invalidPlaCoFound[] = $plantCode;
} }
@@ -237,13 +250,18 @@ class InvoiceOutValidationResource extends Resource
// } // }
} }
if (!empty($invalidqrCode) || !empty($invalidScannedAt) || !empty($invalidScannedBy) || !empty($invalidUser)) if (! empty($invalidqrCode) || ! empty($invalidScannedAt) || ! empty($invalidScannedBy) || ! empty($invalidUser)) {
{
$errorMsg = ''; $errorMsg = '';
if (!empty($invalidqrCode)) $errorMsg .= 'Missing Qr code in rows: '.implode(', ', $invalidqrCode) . '<br>'; if (! empty($invalidqrCode)) {
if (!empty($invalidScannedAt)) $errorMsg .= 'Missing Scanned At in rows: '.implode(', ', $invalidScannedAt) . '<br>'; $errorMsg .= 'Missing Qr code in rows: '.implode(', ', $invalidqrCode).'<br>';
if (!empty($invalidScannedBy)) $errorMsg .= 'Missing Scanned By in rows: '.implode(', ', $invalidScannedBy) . '<br>'; }
if (! empty($invalidScannedAt)) {
$errorMsg .= 'Missing Scanned At in rows: '.implode(', ', $invalidScannedAt).'<br>';
}
if (! empty($invalidScannedBy)) {
$errorMsg .= 'Missing Scanned By in rows: '.implode(', ', $invalidScannedBy).'<br>';
}
Notification::make() Notification::make()
->title('Missing Mandatory Fields') ->title('Missing Mandatory Fields')
@@ -254,6 +272,7 @@ class InvoiceOutValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} }
@@ -267,6 +286,7 @@ class InvoiceOutValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} }
@@ -280,6 +300,7 @@ class InvoiceOutValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} }
@@ -293,11 +314,11 @@ class InvoiceOutValidationResource extends Resource
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} }
if (!empty($duplicateQrExcel)) if (! empty($duplicateQrExcel)) {
{
$duplicateGroupedByPlantQr = []; $duplicateGroupedByPlantQr = [];
foreach ($duplicateQrExcel as $message) {// "/Document Numbers '([^']+)' already exists for Plant Code (\S+)/" foreach ($duplicateQrExcel as $message) {// "/Document Numbers '([^']+)' already exists for Plant Code (\S+)/"
@@ -380,10 +401,11 @@ class InvoiceOutValidationResource extends Resource
DB::beginTransaction(); DB::beginTransaction();
try try {
{
foreach ($rows as $index => $row) { foreach ($rows as $index => $row) {
if ($index == 0) continue; if ($index == 0) {
continue;
}
$rowNumber = $index + 1; $rowNumber = $index + 1;
@@ -430,7 +452,7 @@ class InvoiceOutValidationResource extends Resource
$record->update([ $record->update([
'scanned_at' => $formattedDate, 'scanned_at' => $formattedDate,
'scanned_by' => $scannedBy, 'scanned_by' => $scannedBy,
'updated_by' => $operatorName 'updated_by' => $operatorName,
]); ]);
$inserted = $record; $inserted = $record;
} else { } else {
@@ -440,7 +462,7 @@ class InvoiceOutValidationResource extends Resource
'qr_code' => $qrcode, 'qr_code' => $qrcode,
'scanned_at' => $formattedDate, 'scanned_at' => $formattedDate,
'scanned_by' => $scannedBy, 'scanned_by' => $scannedBy,
'created_by' => $operatorName 'created_by' => $operatorName,
]); ]);
} }
// $inserted = InvoiceOutValidation::create([ // $inserted = InvoiceOutValidation::create([
@@ -460,7 +482,7 @@ class InvoiceOutValidationResource extends Resource
$failedRecords[] = [ $failedRecords[] = [
'row' => $rowNumber, 'row' => $rowNumber,
'qrcode' => $qrcode ?? null, 'qrcode' => $qrcode ?? null,
'error' => $e->getMessage() 'error' => $e->getMessage(),
]; ];
} }
} }
@@ -485,9 +507,7 @@ class InvoiceOutValidationResource extends Resource
->success() ->success()
->send(); ->send();
} }
} } catch (\Exception $e) {
catch (\Exception $e)
{
DB::rollBack(); DB::rollBack();
Notification::make() Notification::make()
->title('Import Failed') ->title('Import Failed')