Added view rights against plant on import and export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s

This commit is contained in:
dhanabalan
2026-01-13 16:05:25 +05:30
parent 4705b3aebb
commit ae954e2d7d
2 changed files with 55 additions and 51 deletions

View File

@@ -14,6 +14,7 @@ class GrMasterExporter extends Exporter
public static function getColumns(): array
{
static $rowNumber = 0;
return [
ExportColumn::make('no')
->label('NO')
@@ -21,10 +22,10 @@ class GrMasterExporter extends Exporter
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.name')
->label('PLANT'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('item.code')
->label('ITEM'),
->label('ITEM CODE'),
ExportColumn::make('serial_number')
->label('SERIAL NUMBER'),
ExportColumn::make('gr_number')

View File

@@ -3,14 +3,14 @@
namespace App\Filament\Imports;
use App\Models\GrMaster;
use App\Models\Item;
use App\Models\Plant;
use App\Models\User;
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;
use App\Models\Plant;
use App\Models\Item;
use Str;
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
use App\Models\User;
class GrMasterImporter extends Importer
{
@@ -21,10 +21,10 @@ class GrMasterImporter extends Importer
return [
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example('Ransar Industries-I')
->label('Plant Name')
->relationship(resolveUsing:'name')
->exampleHeader('Plant Code')
->example('1000')
->label('Plant Code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('item')
->requiredMapping()
@@ -63,44 +63,47 @@ class GrMasterImporter extends Importer
// ]);
$warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first();
if (!$plant) {
$warnMsg[] = "Plant not found";
}
$plantCod = $this->data['plant'];
$plant = null;
$item = null;
if ($plant) {
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found';
} else {
$item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first();
}
if (! $item) {
$warnMsg[] = "Item not found";
$warnMsg[] = 'Item not found';
}
}
if (Str::length($this->data['serial_number']) < 9 || ! ctype_alnum($this->data['serial_number'])) {
$warnMsg[] = "Invalid serial number found";
$warnMsg[] = 'Invalid serial number found';
}
if (empty($this->data['gr_number'])) {
$warnMsg[] = "GR Number cannot be empty.";
$warnMsg[] = 'GR Number cannot be empty.';
}
$user = User::where('name', $this->data['created_by'])->first();
if (! $user) {
$warnMsg[] = "User not found";
$warnMsg[] = 'User not found';
}
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
else { //if (empty($warnMsg))
} else { // if (empty($warnMsg))
$grMaster = GrMaster::where('plant_id', $plant->id)
->where('serial_number', $this->data['serial_number'])
->latest()
->first();
if ($grMaster) {
throw new RowImportFailedException("Serial number already exist!");
throw new RowImportFailedException('Serial number already exist!');
}
}