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
|
||||
return ++$rowNumber;
|
||||
}),
|
||||
ExportColumn::make('plant.name')
|
||||
->label('PLANT'),
|
||||
ExportColumn::make('plant.code')
|
||||
->label('PLANT CODE'),
|
||||
ExportColumn::make('line.name')
|
||||
->label('LINE'),
|
||||
->label('LINE NAME'),
|
||||
ExportColumn::make('production_order')
|
||||
->label('PRODUCTION ORDER'),
|
||||
ExportColumn::make('serial_number')
|
||||
@@ -54,14 +54,14 @@ class QualityValidationExporter extends Exporter
|
||||
->label('NAME PLATE PUMP'),
|
||||
ExportColumn::make('name_plate_pumpset')
|
||||
->label('NAME PLATE PUMPSET'),
|
||||
ExportColumn::make('warranty_card')
|
||||
->label('WARRANTY CARD'),
|
||||
ExportColumn::make('tube_sticker_motor')
|
||||
->label('TUBE STICKER MOTOR'),
|
||||
ExportColumn::make('tube_sticker_pump')
|
||||
->label('TUBE STICKER PUMP'),
|
||||
ExportColumn::make('tube_sticker_pumpset')
|
||||
->label('TUBE STICKER PUMPSET'),
|
||||
ExportColumn::make('warranty_card')
|
||||
->label('WARRANTY CARD'),
|
||||
ExportColumn::make('part_validation1')
|
||||
->label('PART VALIDATION 1'),
|
||||
ExportColumn::make('part_validation2')
|
||||
@@ -90,10 +90,10 @@ class QualityValidationExporter extends Exporter
|
||||
|
||||
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()) {
|
||||
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
|
||||
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
|
||||
}
|
||||
|
||||
return $body;
|
||||
|
||||
@@ -14,7 +14,6 @@ use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Str;
|
||||
|
||||
class QualityValidationImporter extends Importer
|
||||
@@ -35,16 +34,16 @@ class QualityValidationImporter extends Importer
|
||||
->exampleHeader('Item Code')
|
||||
->example('123456')
|
||||
->label('Item Code'),
|
||||
// ->relationship(
|
||||
// name: 'stickerMaster',
|
||||
// resolveUsing: function ($state) {
|
||||
// $state = trim($state);
|
||||
// $item = Item::where('code', $state)->first();
|
||||
// return $item
|
||||
// ? StickerMaster::where('item_id', $item->id)->value('id')
|
||||
// : null;
|
||||
// }
|
||||
// ),
|
||||
// ->relationship(
|
||||
// name: 'stickerMaster',
|
||||
// resolveUsing: function ($state) {
|
||||
// $state = trim($state);
|
||||
// $item = Item::where('code', $state)->first();
|
||||
// return $item
|
||||
// ? StickerMaster::where('item_id', $item->id)->value('id')
|
||||
// : null;
|
||||
// }
|
||||
// ),
|
||||
ImportColumn::make('production_order')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Production Order')
|
||||
@@ -101,6 +100,11 @@ class QualityValidationImporter extends Importer
|
||||
->exampleHeader('Name Plate PumpSet')
|
||||
->example('1')
|
||||
->label('Name Plate PumpSet'),
|
||||
ImportColumn::make('warranty_card')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Warranty Card')
|
||||
->example('1')
|
||||
->label('Warranty Card'),
|
||||
ImportColumn::make('tube_sticker_motor')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Tube Sticker Motor')
|
||||
@@ -116,11 +120,6 @@ class QualityValidationImporter extends Importer
|
||||
->exampleHeader('Tube Sticker PumpSet')
|
||||
->example('1')
|
||||
->label('Tube Sticker PumpSet'),
|
||||
ImportColumn::make('warranty_card')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Warranty Card')
|
||||
->example('1')
|
||||
->label('Warranty Card'),
|
||||
ImportColumn::make('part_validation1')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Part Validation 1')
|
||||
@@ -156,14 +155,14 @@ class QualityValidationImporter extends Importer
|
||||
->exampleHeader('Line Name')
|
||||
->example('4 inch pump line')
|
||||
->label('Line Name')
|
||||
->relationship(resolveUsing:'name')
|
||||
->relationship(resolveUsing: 'name')
|
||||
->rules(['required']),
|
||||
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('updated_at')
|
||||
->requiredMapping()
|
||||
@@ -183,35 +182,41 @@ class QualityValidationImporter extends Importer
|
||||
public function resolveRecord(): ?QualityValidation
|
||||
{
|
||||
$warnMsg = [];
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
$line = null;
|
||||
$stickMaster = null;
|
||||
if (!$plant) {
|
||||
$warnMsg[] = "Plant not found";
|
||||
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();
|
||||
}
|
||||
else {
|
||||
|
||||
if (! $plant) {
|
||||
$warnMsg[] = 'Plant not found';
|
||||
} else {
|
||||
$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')
|
||||
->whereHas('item', function ($query) use ($uniqueCode, $plant) {
|
||||
$query->where('code', $uniqueCode)->where('plant_id', $plant->id);
|
||||
})->value('id');
|
||||
}
|
||||
|
||||
if (!$line) {
|
||||
$warnMsg[] = "Line not found";
|
||||
if (! $line) {
|
||||
$warnMsg[] = 'Line not found';
|
||||
}
|
||||
|
||||
if (!$stickMaster) {
|
||||
$warnMsg[] = "Sticker item code not found";
|
||||
if (! $stickMaster) {
|
||||
$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) {
|
||||
$warnMsg[] = "Invalid production order found";
|
||||
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';
|
||||
}
|
||||
|
||||
if (!ctype_alnum($this->data['serial_number']) || Str::length($this->data['serial_number']) < 9) {
|
||||
$warnMsg[] = "Invalid serial number found";
|
||||
if (! ctype_alnum($this->data['serial_number']) || Str::length($this->data['serial_number']) < 9) {
|
||||
$warnMsg[] = 'Invalid serial number found';
|
||||
}
|
||||
// dd($stickMaster);
|
||||
|
||||
@@ -220,13 +225,13 @@ class QualityValidationImporter extends Importer
|
||||
// }
|
||||
|
||||
$user = User::where('name', $this->data['operator_id'])->first();
|
||||
if (!$user) {
|
||||
$warnMsg[] = "Operator ID not found";
|
||||
if (! $user) {
|
||||
$warnMsg[] = 'Operator ID not found';
|
||||
}
|
||||
$fromDate = $this->data['created_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;
|
||||
$tdateTime = null;
|
||||
@@ -252,14 +257,14 @@ class QualityValidationImporter extends Importer
|
||||
}
|
||||
|
||||
// $fDateOnly = '';
|
||||
if (!isset($fdateTime)) {
|
||||
if (! isset($fdateTime)) {
|
||||
// throw new \Exception('Invalid date time format');
|
||||
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||
}
|
||||
// else {
|
||||
// $fDateOnly = $fdateTime->toDateString();
|
||||
// }
|
||||
if (!isset($tdateTime)) {
|
||||
if (! isset($tdateTime)) {
|
||||
$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";
|
||||
// }
|
||||
|
||||
if (!empty($warnMsg)) {
|
||||
if (! empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
|
||||
QualityValidation::updateOrCreate([
|
||||
'plant_id' => $plant->id,
|
||||
'sticker_master_id' => $stickMaster,//->id
|
||||
'serial_number' => $this->data['serial_number']
|
||||
'sticker_master_id' => $stickMaster, // ->id
|
||||
'serial_number' => $this->data['serial_number'],
|
||||
],
|
||||
[
|
||||
'line_id' => $line->id,
|
||||
'uom' => $this->data['uom'],
|
||||
'production_order' => $this->data['production_order'],
|
||||
'serial_number_motor' => $this->data['serial_number_motor'],
|
||||
'serial_number_pump' => $this->data['serial_number_pump'],
|
||||
'serial_number_pumpset' => $this->data['serial_number_pumpset'],
|
||||
'pack_slip_motor' => $this->data['pack_slip_motor'],
|
||||
'pack_slip_pump' => $this->data['pack_slip_pump'],
|
||||
'pack_slip_pumpset' => $this->data['pack_slip_pumpset'],
|
||||
'name_plate_motor' => $this->data['name_plate_motor'],
|
||||
'name_plate_pump' => $this->data['name_plate_pump'],
|
||||
'name_plate_pumpset' => $this->data['name_plate_pumpset'],
|
||||
'tube_sticker_motor' => $this->data['tube_sticker_motor'],
|
||||
'tube_sticker_pump' => $this->data['tube_sticker_pump'],
|
||||
'tube_sticker_pumpset' => $this->data['tube_sticker_pumpset'],
|
||||
'warranty_card' => $this->data['warranty_card'],
|
||||
'part_validation1' => $this->data['part_validation1'],
|
||||
'part_validation2' => $this->data['part_validation2'],
|
||||
'part_validation3' => $this->data['part_validation3'],
|
||||
'part_validation4' => $this->data['part_validation4'],
|
||||
'part_validation5' => $this->data['part_validation5'],
|
||||
'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'],
|
||||
'operator_id' => $this->data['operator_id'],
|
||||
]);
|
||||
[
|
||||
'line_id' => $line->id,
|
||||
'uom' => $this->data['uom'],
|
||||
'production_order' => $this->data['production_order'],
|
||||
'serial_number_motor' => $this->data['serial_number_motor'],
|
||||
'serial_number_pump' => $this->data['serial_number_pump'],
|
||||
'serial_number_pumpset' => $this->data['serial_number_pumpset'],
|
||||
'pack_slip_motor' => $this->data['pack_slip_motor'],
|
||||
'pack_slip_pump' => $this->data['pack_slip_pump'],
|
||||
'pack_slip_pumpset' => $this->data['pack_slip_pumpset'],
|
||||
'name_plate_motor' => $this->data['name_plate_motor'],
|
||||
'name_plate_pump' => $this->data['name_plate_pump'],
|
||||
'name_plate_pumpset' => $this->data['name_plate_pumpset'],
|
||||
'tube_sticker_motor' => $this->data['tube_sticker_motor'],
|
||||
'tube_sticker_pump' => $this->data['tube_sticker_pump'],
|
||||
'tube_sticker_pumpset' => $this->data['tube_sticker_pumpset'],
|
||||
'warranty_card' => $this->data['warranty_card'],
|
||||
'part_validation1' => $this->data['part_validation1'],
|
||||
'part_validation2' => $this->data['part_validation2'],
|
||||
'part_validation3' => $this->data['part_validation3'],
|
||||
'part_validation4' => $this->data['part_validation4'],
|
||||
'part_validation5' => $this->data['part_validation5'],
|
||||
'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'],
|
||||
'operator_id' => $this->data['operator_id'],
|
||||
]);
|
||||
|
||||
return null;
|
||||
// return QualityValidation::firstOrNew([
|
||||
@@ -322,10 +327,10 @@ class QualityValidationImporter extends Importer
|
||||
|
||||
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()) {
|
||||
$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