Added view rights against plant on import and export and Validation logic updated
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:
@@ -24,10 +24,10 @@ class QualityValidationExporter extends Exporter
|
|||||||
// Increment and return the row number
|
// Increment and return the row number
|
||||||
return ++$rowNumber;
|
return ++$rowNumber;
|
||||||
}),
|
}),
|
||||||
ExportColumn::make('plant.name')
|
ExportColumn::make('plant.code')
|
||||||
->label('PLANT'),
|
->label('PLANT CODE'),
|
||||||
ExportColumn::make('line.name')
|
ExportColumn::make('line.name')
|
||||||
->label('LINE'),
|
->label('LINE NAME'),
|
||||||
ExportColumn::make('production_order')
|
ExportColumn::make('production_order')
|
||||||
->label('PRODUCTION ORDER'),
|
->label('PRODUCTION ORDER'),
|
||||||
ExportColumn::make('serial_number')
|
ExportColumn::make('serial_number')
|
||||||
@@ -54,14 +54,14 @@ class QualityValidationExporter extends Exporter
|
|||||||
->label('NAME PLATE PUMP'),
|
->label('NAME PLATE PUMP'),
|
||||||
ExportColumn::make('name_plate_pumpset')
|
ExportColumn::make('name_plate_pumpset')
|
||||||
->label('NAME PLATE PUMPSET'),
|
->label('NAME PLATE PUMPSET'),
|
||||||
|
ExportColumn::make('warranty_card')
|
||||||
|
->label('WARRANTY CARD'),
|
||||||
ExportColumn::make('tube_sticker_motor')
|
ExportColumn::make('tube_sticker_motor')
|
||||||
->label('TUBE STICKER MOTOR'),
|
->label('TUBE STICKER MOTOR'),
|
||||||
ExportColumn::make('tube_sticker_pump')
|
ExportColumn::make('tube_sticker_pump')
|
||||||
->label('TUBE STICKER PUMP'),
|
->label('TUBE STICKER PUMP'),
|
||||||
ExportColumn::make('tube_sticker_pumpset')
|
ExportColumn::make('tube_sticker_pumpset')
|
||||||
->label('TUBE STICKER PUMPSET'),
|
->label('TUBE STICKER PUMPSET'),
|
||||||
ExportColumn::make('warranty_card')
|
|
||||||
->label('WARRANTY CARD'),
|
|
||||||
ExportColumn::make('part_validation1')
|
ExportColumn::make('part_validation1')
|
||||||
->label('PART VALIDATION 1'),
|
->label('PART VALIDATION 1'),
|
||||||
ExportColumn::make('part_validation2')
|
ExportColumn::make('part_validation2')
|
||||||
@@ -90,10 +90,10 @@ class QualityValidationExporter extends Exporter
|
|||||||
|
|
||||||
public static function getCompletedNotificationBody(Export $export): string
|
public static function getCompletedNotificationBody(Export $export): string
|
||||||
{
|
{
|
||||||
$body = 'Your quality validation export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
|
$body = 'Your quality validation export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
|
||||||
|
|
||||||
if ($failedRowsCount = $export->getFailedRowsCount()) {
|
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;
|
return $body;
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ use Filament\Actions\Imports\ImportColumn;
|
|||||||
use Filament\Actions\Imports\Importer;
|
use Filament\Actions\Imports\Importer;
|
||||||
use Filament\Actions\Imports\Models\Import;
|
use Filament\Actions\Imports\Models\Import;
|
||||||
use Filament\Facades\Filament;
|
use Filament\Facades\Filament;
|
||||||
use Illuminate\Validation\Rule;
|
|
||||||
use Str;
|
use Str;
|
||||||
|
|
||||||
class QualityValidationImporter extends Importer
|
class QualityValidationImporter extends Importer
|
||||||
@@ -35,16 +34,16 @@ class QualityValidationImporter extends Importer
|
|||||||
->exampleHeader('Item Code')
|
->exampleHeader('Item Code')
|
||||||
->example('123456')
|
->example('123456')
|
||||||
->label('Item Code'),
|
->label('Item Code'),
|
||||||
// ->relationship(
|
// ->relationship(
|
||||||
// name: 'stickerMaster',
|
// name: 'stickerMaster',
|
||||||
// resolveUsing: function ($state) {
|
// resolveUsing: function ($state) {
|
||||||
// $state = trim($state);
|
// $state = trim($state);
|
||||||
// $item = Item::where('code', $state)->first();
|
// $item = Item::where('code', $state)->first();
|
||||||
// return $item
|
// return $item
|
||||||
// ? StickerMaster::where('item_id', $item->id)->value('id')
|
// ? StickerMaster::where('item_id', $item->id)->value('id')
|
||||||
// : null;
|
// : null;
|
||||||
// }
|
// }
|
||||||
// ),
|
// ),
|
||||||
ImportColumn::make('production_order')
|
ImportColumn::make('production_order')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('Production Order')
|
->exampleHeader('Production Order')
|
||||||
@@ -101,6 +100,11 @@ class QualityValidationImporter extends Importer
|
|||||||
->exampleHeader('Name Plate PumpSet')
|
->exampleHeader('Name Plate PumpSet')
|
||||||
->example('1')
|
->example('1')
|
||||||
->label('Name Plate PumpSet'),
|
->label('Name Plate PumpSet'),
|
||||||
|
ImportColumn::make('warranty_card')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Warranty Card')
|
||||||
|
->example('1')
|
||||||
|
->label('Warranty Card'),
|
||||||
ImportColumn::make('tube_sticker_motor')
|
ImportColumn::make('tube_sticker_motor')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('Tube Sticker Motor')
|
->exampleHeader('Tube Sticker Motor')
|
||||||
@@ -116,11 +120,6 @@ class QualityValidationImporter extends Importer
|
|||||||
->exampleHeader('Tube Sticker PumpSet')
|
->exampleHeader('Tube Sticker PumpSet')
|
||||||
->example('1')
|
->example('1')
|
||||||
->label('Tube Sticker PumpSet'),
|
->label('Tube Sticker PumpSet'),
|
||||||
ImportColumn::make('warranty_card')
|
|
||||||
->requiredMapping()
|
|
||||||
->exampleHeader('Warranty Card')
|
|
||||||
->example('1')
|
|
||||||
->label('Warranty Card'),
|
|
||||||
ImportColumn::make('part_validation1')
|
ImportColumn::make('part_validation1')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('Part Validation 1')
|
->exampleHeader('Part Validation 1')
|
||||||
@@ -156,14 +155,14 @@ class QualityValidationImporter extends Importer
|
|||||||
->exampleHeader('Line Name')
|
->exampleHeader('Line Name')
|
||||||
->example('4 inch pump line')
|
->example('4 inch pump line')
|
||||||
->label('Line Name')
|
->label('Line Name')
|
||||||
->relationship(resolveUsing:'name')
|
->relationship(resolveUsing: 'name')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('plant')
|
ImportColumn::make('plant')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('Plant Name')
|
->exampleHeader('Plant Code')
|
||||||
->example('Ransar Industries-I')
|
->example('1000')
|
||||||
->label('Plant Name')
|
->label('Plant Code')
|
||||||
->relationship(resolveUsing:'name')
|
->relationship(resolveUsing: 'code')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('updated_at')
|
ImportColumn::make('updated_at')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
@@ -183,35 +182,41 @@ class QualityValidationImporter extends Importer
|
|||||||
public function resolveRecord(): ?QualityValidation
|
public function resolveRecord(): ?QualityValidation
|
||||||
{
|
{
|
||||||
$warnMsg = [];
|
$warnMsg = [];
|
||||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
$plantCod = $this->data['plant'];
|
||||||
|
$plant = null;
|
||||||
$line = null;
|
$line = null;
|
||||||
$stickMaster = null;
|
$stickMaster = null;
|
||||||
if (!$plant) {
|
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||||
$warnMsg[] = "Plant not found";
|
$warnMsg[] = 'Invalid plant code found';
|
||||||
|
} else {
|
||||||
|
$plant = Plant::where('code', $plantCod)->first();
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
|
if (! $plant) {
|
||||||
|
$warnMsg[] = 'Plant not found';
|
||||||
|
} else {
|
||||||
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
|
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
|
||||||
$uniqueCode = trim($this->data['sticker_master_id_code']);// stickerMaster.item
|
$uniqueCode = trim($this->data['sticker_master_id_code']); // stickerMaster.item
|
||||||
$stickMaster = StickerMaster::select('id')->with('item')
|
$stickMaster = StickerMaster::select('id')->with('item')
|
||||||
->whereHas('item', function ($query) use ($uniqueCode, $plant) {
|
->whereHas('item', function ($query) use ($uniqueCode, $plant) {
|
||||||
$query->where('code', $uniqueCode)->where('plant_id', $plant->id);
|
$query->where('code', $uniqueCode)->where('plant_id', $plant->id);
|
||||||
})->value('id');
|
})->value('id');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$line) {
|
if (! $line) {
|
||||||
$warnMsg[] = "Line not found";
|
$warnMsg[] = 'Line not found';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$stickMaster) {
|
if (! $stickMaster) {
|
||||||
$warnMsg[] = "Sticker item code not found";
|
$warnMsg[] = 'Sticker item code not found';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_numeric($this->data['production_order']) || Str::length($this->data['production_order']) < 7 || Str::length($this->data['production_order']) > 14) {
|
if (! is_numeric($this->data['production_order']) || Str::length($this->data['production_order']) < 7 || Str::length($this->data['production_order']) > 14) {
|
||||||
$warnMsg[] = "Invalid production order found";
|
$warnMsg[] = 'Invalid production order found';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctype_alnum($this->data['serial_number']) || Str::length($this->data['serial_number']) < 9) {
|
if (! ctype_alnum($this->data['serial_number']) || Str::length($this->data['serial_number']) < 9) {
|
||||||
$warnMsg[] = "Invalid serial number found";
|
$warnMsg[] = 'Invalid serial number found';
|
||||||
}
|
}
|
||||||
// dd($stickMaster);
|
// dd($stickMaster);
|
||||||
|
|
||||||
@@ -220,13 +225,13 @@ class QualityValidationImporter extends Importer
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
$user = User::where('name', $this->data['operator_id'])->first();
|
$user = User::where('name', $this->data['operator_id'])->first();
|
||||||
if (!$user) {
|
if (! $user) {
|
||||||
$warnMsg[] = "Operator ID not found";
|
$warnMsg[] = 'Operator ID not found';
|
||||||
}
|
}
|
||||||
$fromDate = $this->data['created_at'];
|
$fromDate = $this->data['created_at'];
|
||||||
$toDate = $this->data['updated_at'];
|
$toDate = $this->data['updated_at'];
|
||||||
|
|
||||||
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; //'07-05-2025 08:00' or '07-05-2025 08:00:00'
|
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; // '07-05-2025 08:00' or '07-05-2025 08:00:00'
|
||||||
|
|
||||||
$fdateTime = null;
|
$fdateTime = null;
|
||||||
$tdateTime = null;
|
$tdateTime = null;
|
||||||
@@ -252,14 +257,14 @@ class QualityValidationImporter extends Importer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// $fDateOnly = '';
|
// $fDateOnly = '';
|
||||||
if (!isset($fdateTime)) {
|
if (! isset($fdateTime)) {
|
||||||
// throw new \Exception('Invalid date time format');
|
// throw new \Exception('Invalid date time format');
|
||||||
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||||
}
|
}
|
||||||
// else {
|
// else {
|
||||||
// $fDateOnly = $fdateTime->toDateString();
|
// $fDateOnly = $fdateTime->toDateString();
|
||||||
// }
|
// }
|
||||||
if (!isset($tdateTime)) {
|
if (! isset($tdateTime)) {
|
||||||
$warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
$warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,41 +280,41 @@ class QualityValidationImporter extends Importer
|
|||||||
// $warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
// $warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (!empty($warnMsg)) {
|
if (! empty($warnMsg)) {
|
||||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
QualityValidation::updateOrCreate([
|
QualityValidation::updateOrCreate([
|
||||||
'plant_id' => $plant->id,
|
'plant_id' => $plant->id,
|
||||||
'sticker_master_id' => $stickMaster,//->id
|
'sticker_master_id' => $stickMaster, // ->id
|
||||||
'serial_number' => $this->data['serial_number']
|
'serial_number' => $this->data['serial_number'],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'line_id' => $line->id,
|
'line_id' => $line->id,
|
||||||
'uom' => $this->data['uom'],
|
'uom' => $this->data['uom'],
|
||||||
'production_order' => $this->data['production_order'],
|
'production_order' => $this->data['production_order'],
|
||||||
'serial_number_motor' => $this->data['serial_number_motor'],
|
'serial_number_motor' => $this->data['serial_number_motor'],
|
||||||
'serial_number_pump' => $this->data['serial_number_pump'],
|
'serial_number_pump' => $this->data['serial_number_pump'],
|
||||||
'serial_number_pumpset' => $this->data['serial_number_pumpset'],
|
'serial_number_pumpset' => $this->data['serial_number_pumpset'],
|
||||||
'pack_slip_motor' => $this->data['pack_slip_motor'],
|
'pack_slip_motor' => $this->data['pack_slip_motor'],
|
||||||
'pack_slip_pump' => $this->data['pack_slip_pump'],
|
'pack_slip_pump' => $this->data['pack_slip_pump'],
|
||||||
'pack_slip_pumpset' => $this->data['pack_slip_pumpset'],
|
'pack_slip_pumpset' => $this->data['pack_slip_pumpset'],
|
||||||
'name_plate_motor' => $this->data['name_plate_motor'],
|
'name_plate_motor' => $this->data['name_plate_motor'],
|
||||||
'name_plate_pump' => $this->data['name_plate_pump'],
|
'name_plate_pump' => $this->data['name_plate_pump'],
|
||||||
'name_plate_pumpset' => $this->data['name_plate_pumpset'],
|
'name_plate_pumpset' => $this->data['name_plate_pumpset'],
|
||||||
'tube_sticker_motor' => $this->data['tube_sticker_motor'],
|
'tube_sticker_motor' => $this->data['tube_sticker_motor'],
|
||||||
'tube_sticker_pump' => $this->data['tube_sticker_pump'],
|
'tube_sticker_pump' => $this->data['tube_sticker_pump'],
|
||||||
'tube_sticker_pumpset' => $this->data['tube_sticker_pumpset'],
|
'tube_sticker_pumpset' => $this->data['tube_sticker_pumpset'],
|
||||||
'warranty_card' => $this->data['warranty_card'],
|
'warranty_card' => $this->data['warranty_card'],
|
||||||
'part_validation1' => $this->data['part_validation1'],
|
'part_validation1' => $this->data['part_validation1'],
|
||||||
'part_validation2' => $this->data['part_validation2'],
|
'part_validation2' => $this->data['part_validation2'],
|
||||||
'part_validation3' => $this->data['part_validation3'],
|
'part_validation3' => $this->data['part_validation3'],
|
||||||
'part_validation4' => $this->data['part_validation4'],
|
'part_validation4' => $this->data['part_validation4'],
|
||||||
'part_validation5' => $this->data['part_validation5'],
|
'part_validation5' => $this->data['part_validation5'],
|
||||||
'created_at' => $fdateTime->format('Y-m-d H:i:s'),//$this->data['created_at'],
|
'created_at' => $fdateTime->format('Y-m-d H:i:s'), // $this->data['created_at'],
|
||||||
'updated_at' => $tdateTime->format('Y-m-d H:i:s'),//$this->data['updated_at'],
|
'updated_at' => $tdateTime->format('Y-m-d H:i:s'), // $this->data['updated_at'],
|
||||||
'operator_id' => $this->data['operator_id'],
|
'operator_id' => $this->data['operator_id'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
// return QualityValidation::firstOrNew([
|
// return QualityValidation::firstOrNew([
|
||||||
@@ -322,10 +327,10 @@ class QualityValidationImporter extends Importer
|
|||||||
|
|
||||||
public static function getCompletedNotificationBody(Import $import): string
|
public static function getCompletedNotificationBody(Import $import): string
|
||||||
{
|
{
|
||||||
$body = 'Your quality validation import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
|
$body = 'Your quality validation import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
|
||||||
|
|
||||||
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
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;
|
return $body;
|
||||||
|
|||||||
Reference in New Issue
Block a user