Merge pull request 'ranjith-dev' (#1405) from ranjith-dev into master
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
Reviewed-on: #1405
This commit was merged in pull request #1405.
This commit is contained in:
@@ -826,6 +826,49 @@ class ProductionPlanResource extends Resource
|
|||||||
->label('Import Production Plans')
|
->label('Import Production Plans')
|
||||||
->color('warning')
|
->color('warning')
|
||||||
->importer(ProductionPlanImporter::class)
|
->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) {
|
||||||
|
|
||||||
|
$values = array_values($record);
|
||||||
|
|
||||||
|
$plantCode = trim((string) ($values[0] ?? ''));
|
||||||
|
$itemCode = trim((string) ($values[1] ?? ''));
|
||||||
|
|
||||||
|
if ($plantCode === '' || $itemCode === '') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$key = $plantCode . '|' . $itemCode;
|
||||||
|
|
||||||
|
$itemCodes[] = $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
$duplicates = collect($itemCodes)
|
||||||
|
->duplicates()
|
||||||
|
->unique()
|
||||||
|
->values()
|
||||||
|
->map(fn ($duplicate) => explode('|', $duplicate)[1])
|
||||||
|
->unique()
|
||||||
|
->values();
|
||||||
|
|
||||||
|
if ($duplicates->isNotEmpty()) {
|
||||||
|
$fail(
|
||||||
|
'Duplicate Item Codes found: ' . $duplicates->implode(', ')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
])
|
||||||
->visible(function () {
|
->visible(function () {
|
||||||
return Filament::auth()->user()->can('view import production plan');
|
return Filament::auth()->user()->can('view import production plan');
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user