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
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
This commit is contained in:
@@ -14,6 +14,7 @@ class GrMasterExporter extends Exporter
|
||||
public static function getColumns(): array
|
||||
{
|
||||
static $rowNumber = 0;
|
||||
|
||||
return [
|
||||
ExportColumn::make('no')
|
||||
->label('NO')
|
||||
@@ -21,36 +22,36 @@ 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'),
|
||||
->label('SERIAL NUMBER'),
|
||||
ExportColumn::make('gr_number')
|
||||
->label('GR NUMBER'),
|
||||
->label('GR NUMBER'),
|
||||
ExportColumn::make('status')
|
||||
->label('STATUS'),
|
||||
->label('STATUS'),
|
||||
ExportColumn::make('created_at')
|
||||
->label('CREATED AT'),
|
||||
->label('CREATED AT'),
|
||||
ExportColumn::make('updated_at')
|
||||
->label('UPDATED AT'),
|
||||
->label('UPDATED AT'),
|
||||
ExportColumn::make('created_by')
|
||||
->label('CREATED BY'),
|
||||
->label('CREATED BY'),
|
||||
ExportColumn::make('updated_by')
|
||||
->label('UPDATED BY'),
|
||||
->label('UPDATED BY'),
|
||||
ExportColumn::make('deleted_at')
|
||||
->label('DELETED AT')
|
||||
->enabledByDefault(false),
|
||||
->label('DELETED AT')
|
||||
->enabledByDefault(false),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Export $export): string
|
||||
{
|
||||
$body = 'Your gr master export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
|
||||
$body = 'Your gr master export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
|
||||
|
||||
if ($failedRowsCount = $export->getFailedRowsCount()) {
|
||||
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
|
||||
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
|
||||
}
|
||||
|
||||
return $body;
|
||||
|
||||
@@ -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,17 +21,17 @@ 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()
|
||||
->exampleHeader('Item Code')
|
||||
->example('630214')
|
||||
->label('Item Code')
|
||||
->relationship(resolveUsing:'code')
|
||||
->relationship(resolveUsing: 'code')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('serial_number')
|
||||
->requiredMapping()
|
||||
@@ -51,7 +51,7 @@ class GrMasterImporter extends Importer
|
||||
->example('Admin')
|
||||
->label('Created By')
|
||||
->rules(['required']),
|
||||
//ImportColumn::make('updated_by'),
|
||||
// ImportColumn::make('updated_by'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
$item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first();
|
||||
|
||||
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';
|
||||
}
|
||||
}
|
||||
if (!$item) {
|
||||
$warnMsg[] = "Item not found";
|
||||
}
|
||||
if (Str::length($this->data['serial_number']) < 9 || !ctype_alnum($this->data['serial_number'])) {
|
||||
$warnMsg[] = "Invalid serial number found";
|
||||
|
||||
if (Str::length($this->data['serial_number']) < 9 || ! ctype_alnum($this->data['serial_number'])) {
|
||||
$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";
|
||||
if (! $user) {
|
||||
$warnMsg[] = 'User not found';
|
||||
}
|
||||
|
||||
if (!empty($warnMsg)) {
|
||||
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();
|
||||
->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!');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,15 +116,15 @@ class GrMasterImporter extends Importer
|
||||
]);
|
||||
|
||||
return null;
|
||||
//return new GrMaster();
|
||||
// return new GrMaster();
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
{
|
||||
$body = 'Your gr master import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
|
||||
$body = 'Your gr master import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
|
||||
|
||||
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
||||
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
|
||||
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
|
||||
}
|
||||
|
||||
return $body;
|
||||
|
||||
Reference in New Issue
Block a user