Added item code duplicate validation in production plan resource page
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 16s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 16s
This commit is contained in:
@@ -826,6 +826,39 @@ class ProductionPlanResource extends Resource
|
||||
->label('Import Production Plans')
|
||||
->color('warning')
|
||||
->importer(ProductionPlanImporter::class)
|
||||
->fileRules([
|
||||
fn (): \Closure => function ($attribute, $value, $fail) {
|
||||
|
||||
$csv = \League\Csv\Reader::createFromPath(
|
||||
$value->getRealPath(),
|
||||
'r'
|
||||
);
|
||||
|
||||
$csv->setHeaderOffset(0);
|
||||
|
||||
$itemCodes = [];
|
||||
|
||||
foreach ($csv->getRecords() as $record) {
|
||||
$itemCode = trim((string) ($record['Item Code'] ?? ''));
|
||||
|
||||
if ($itemCode !== '') {
|
||||
$itemCodes[] = $itemCode;
|
||||
}
|
||||
}
|
||||
|
||||
$duplicates = collect($itemCodes)
|
||||
->duplicates()
|
||||
->unique()
|
||||
->values();
|
||||
|
||||
if ($duplicates->isNotEmpty()) {
|
||||
$fail(
|
||||
'Duplicate Item Codes found: ' .
|
||||
$duplicates->implode(', ')
|
||||
);
|
||||
}
|
||||
},
|
||||
])
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view import production plan');
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user