ranjith-dev #1405

Merged
jothi merged 2 commits from ranjith-dev into master 2026-11-10 08:46:24 +00:00
Showing only changes of commit 558f0a39bd - Show all commits

View File

@@ -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');
}),