Added validation logic in sticker detail for importer and exporter #74
@@ -29,6 +29,8 @@ class StickerDetailExporter extends Exporter
|
|||||||
->label('ELEMENT ID'),
|
->label('ELEMENT ID'),
|
||||||
ExportColumn::make('element_type')
|
ExportColumn::make('element_type')
|
||||||
->label('ELEMENT TYPE'),
|
->label('ELEMENT TYPE'),
|
||||||
|
ExportColumn::make('characteristics_type')
|
||||||
|
->label('CHARACTERISTICS TYPE'),
|
||||||
ExportColumn::make('string_value')
|
ExportColumn::make('string_value')
|
||||||
->label('STRING VALUE'),
|
->label('STRING VALUE'),
|
||||||
ExportColumn::make('string_font')
|
ExportColumn::make('string_font')
|
||||||
@@ -47,6 +49,8 @@ class StickerDetailExporter extends Exporter
|
|||||||
->label('SHAPE NAME'),
|
->label('SHAPE NAME'),
|
||||||
ExportColumn::make('shape_pen_size')
|
ExportColumn::make('shape_pen_size')
|
||||||
->label('SHAPE PEN SIZE'),
|
->label('SHAPE PEN SIZE'),
|
||||||
|
ExportColumn::make('curve_radius')
|
||||||
|
->label('CURVE RADIUS'),
|
||||||
ExportColumn::make('shape_x1_value')
|
ExportColumn::make('shape_x1_value')
|
||||||
->label('SHAPE X1 VALUE'),
|
->label('SHAPE X1 VALUE'),
|
||||||
ExportColumn::make('shape_y1_value')
|
ExportColumn::make('shape_y1_value')
|
||||||
@@ -55,10 +59,6 @@ class StickerDetailExporter extends Exporter
|
|||||||
->label('SHAPE X2 VALUE'),
|
->label('SHAPE X2 VALUE'),
|
||||||
ExportColumn::make('shape_y2_value')
|
ExportColumn::make('shape_y2_value')
|
||||||
->label('SHAPE Y2 VALUE'),
|
->label('SHAPE Y2 VALUE'),
|
||||||
ExportColumn::make('image_path')
|
|
||||||
->label('IMAGE PATH'),
|
|
||||||
ExportColumn::make('image_type')
|
|
||||||
->label('IMAGE TYPE'),
|
|
||||||
ExportColumn::make('image_x')
|
ExportColumn::make('image_x')
|
||||||
->label('IMAGE X'),
|
->label('IMAGE X'),
|
||||||
ExportColumn::make('image_y')
|
ExportColumn::make('image_y')
|
||||||
|
|||||||
@@ -2,10 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Filament\Imports;
|
namespace App\Filament\Imports;
|
||||||
|
|
||||||
|
use App\Models\Plant;
|
||||||
use App\Models\StickerDetail;
|
use App\Models\StickerDetail;
|
||||||
|
use App\Models\StickerStructureDetail;
|
||||||
|
use App\Models\User;
|
||||||
use Filament\Actions\Imports\ImportColumn;
|
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\Actions\Imports\Exceptions\RowImportFailedException;
|
||||||
|
|
||||||
class StickerDetailImporter extends Importer
|
class StickerDetailImporter extends Importer
|
||||||
{
|
{
|
||||||
@@ -14,50 +18,295 @@ class StickerDetailImporter extends Importer
|
|||||||
public static function getColumns(): array
|
public static function getColumns(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
ImportColumn::make('stickerStructureDetail')
|
ImportColumn::make('sticker_structure_detail_id')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->relationship()
|
->exampleHeader('Sticker ID')
|
||||||
|
->example('123456')
|
||||||
|
->label('STICKER ID')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('design_element_type'),
|
ImportColumn::make('design_element_type')
|
||||||
ImportColumn::make('element_id'),
|
->requiredMapping()
|
||||||
ImportColumn::make('element_type'),
|
->exampleHeader('Design Element Type')
|
||||||
ImportColumn::make('string_value'),
|
->label('DESIGN ELEMENT TYPE')
|
||||||
ImportColumn::make('string_font'),
|
->example('Text/Shape/Image/QR'),
|
||||||
ImportColumn::make('string_size'),
|
ImportColumn::make('element_id')
|
||||||
ImportColumn::make('element_colour'),
|
->requiredMapping()
|
||||||
ImportColumn::make('string_align'),
|
->exampleHeader('Element ID')
|
||||||
ImportColumn::make('string_x_value'),
|
->label('ELEMENT ID')
|
||||||
ImportColumn::make('string_y_value'),
|
->example('001'),
|
||||||
ImportColumn::make('shape_name'),
|
ImportColumn::make('element_type')
|
||||||
ImportColumn::make('shape_pen_size'),
|
->requiredMapping()
|
||||||
ImportColumn::make('shape_x1_value'),
|
->exampleHeader('Element Type')
|
||||||
ImportColumn::make('shape_y1_value'),
|
->label('ELEMENT TYPE')
|
||||||
ImportColumn::make('shape_x2_value'),
|
->example('Static/Dynamic'),
|
||||||
ImportColumn::make('shape_y2_value'),
|
ImportColumn::make('characteristics_type')
|
||||||
ImportColumn::make('image_path'),
|
->requiredMapping()
|
||||||
ImportColumn::make('image_type'),
|
->exampleHeader('Characteristics Type')
|
||||||
ImportColumn::make('image_x'),
|
->label('CHARACTERISTICS TYPE')
|
||||||
ImportColumn::make('image_y'),
|
->example('ZMM values'),
|
||||||
ImportColumn::make('image_width'),
|
ImportColumn::make('string_value')
|
||||||
ImportColumn::make('image_height'),
|
->requiredMapping()
|
||||||
ImportColumn::make('qr_value'),
|
->exampleHeader('String Value')
|
||||||
ImportColumn::make('qr_align'),
|
->label('STRING VALUE')
|
||||||
ImportColumn::make('qr_size'),
|
->example('1'),
|
||||||
ImportColumn::make('qr_x_value'),
|
ImportColumn::make('string_font')
|
||||||
ImportColumn::make('qr_y_value'),
|
->requiredMapping()
|
||||||
ImportColumn::make('created_by'),
|
->exampleHeader('String Font')
|
||||||
ImportColumn::make('updated_by'),
|
->label('STRING FONT')
|
||||||
|
->example('Arial'),
|
||||||
|
ImportColumn::make('string_size')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('String Size')
|
||||||
|
->label('STRING SIZE')
|
||||||
|
->example('12'),
|
||||||
|
ImportColumn::make('element_colour')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Element Colour')
|
||||||
|
->label('ELEMENT COLOUR')
|
||||||
|
->example('Black'),
|
||||||
|
ImportColumn::make('string_align')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('String Align')
|
||||||
|
->label('STRING ALIGN')
|
||||||
|
->example('Left/Center/Right'),
|
||||||
|
ImportColumn::make('string_x_value')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('String X Value')
|
||||||
|
->label('STRING X VALUE')
|
||||||
|
->example('10'),
|
||||||
|
ImportColumn::make('string_y_value')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('String Y Value')
|
||||||
|
->label('STRING Y VALUE')
|
||||||
|
->example('20'),
|
||||||
|
ImportColumn::make('shape_name')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Shape Name')
|
||||||
|
->label('SHAPE NAME')
|
||||||
|
->example('Line/Rectangle/CurvedRectangle'),
|
||||||
|
ImportColumn::make('shape_pen_size')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Shape Pen Size')
|
||||||
|
->label('SHAPE PEN SIZE')
|
||||||
|
->example('0.3'),
|
||||||
|
ImportColumn::make('curve_radius')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Curve Radius')
|
||||||
|
->label('CURVE RADIUS')
|
||||||
|
->example('3'),
|
||||||
|
ImportColumn::make('shape_x1_value')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Shape X1 Value')
|
||||||
|
->label('SHAPE X1 VALUE')
|
||||||
|
->example('10'),
|
||||||
|
ImportColumn::make('shape_y1_value')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Shape Y1 Value')
|
||||||
|
->label('SHAPE Y1 VALUE')
|
||||||
|
->example('20'),
|
||||||
|
ImportColumn::make('shape_x2_value')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Shape X2 Value')
|
||||||
|
->label('SHAPE X2 VALUE')
|
||||||
|
->example('30'),
|
||||||
|
ImportColumn::make('shape_y2_value')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Shape Y2 Value')
|
||||||
|
->label('SHAPE Y2 VALUE')
|
||||||
|
->example('40'),
|
||||||
|
ImportColumn::make('image_x')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Image X')
|
||||||
|
->label('IMAGE X')
|
||||||
|
->example('15'),
|
||||||
|
ImportColumn::make('image_y')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Image Y')
|
||||||
|
->label('IMAGE Y')
|
||||||
|
->example('25'),
|
||||||
|
ImportColumn::make('image_width')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Image Width')
|
||||||
|
->label('IMAGE WIDTH')
|
||||||
|
->example('100'),
|
||||||
|
ImportColumn::make('image_height')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Image Height')
|
||||||
|
->label('IMAGE HEIGHT')
|
||||||
|
->example('100'),
|
||||||
|
ImportColumn::make('qr_value')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('QR Value')
|
||||||
|
->label('QR VALUE')
|
||||||
|
->example('246118|53246735267'),
|
||||||
|
ImportColumn::make('qr_align')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('QR Align')
|
||||||
|
->label('QR ALIGN')
|
||||||
|
->example('Left/Center/Right'),
|
||||||
|
ImportColumn::make('qr_size')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('QR Size')
|
||||||
|
->label('QR SIZE')
|
||||||
|
->example('10'),
|
||||||
|
ImportColumn::make('qr_x_value')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('QR X Value')
|
||||||
|
->label('QR X VALUE')
|
||||||
|
->example('30'),
|
||||||
|
ImportColumn::make('qr_y_value')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('QR Y Value')
|
||||||
|
->label('QR Y VALUE')
|
||||||
|
->example('40'),
|
||||||
|
ImportColumn::make('created_by')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Created By')
|
||||||
|
->label('CREATED BY')
|
||||||
|
->example('RAW001234'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resolveRecord(): ?StickerDetail
|
public function resolveRecord(): ?StickerDetail
|
||||||
{
|
{
|
||||||
// return StickerDetail::firstOrNew([
|
|
||||||
// // Update existing records, matching them by `$this->data['column_name']`
|
|
||||||
// 'email' => $this->data['email'],
|
|
||||||
// ]);
|
|
||||||
|
|
||||||
return new StickerDetail();
|
$warnMsg = [];
|
||||||
|
|
||||||
|
$sticker = $this->data['sticker_structure_detail_id'] ?? null;
|
||||||
|
|
||||||
|
$stickerCode = StickerStructureDetail::where('sticker_id', $sticker)->first();
|
||||||
|
if (!$stickerCode) {
|
||||||
|
$warnMsg[] = "Sticker Id not found in Sticker Structure Detail";
|
||||||
|
}
|
||||||
|
|
||||||
|
$stickerId = $stickerCode->id;
|
||||||
|
|
||||||
|
$user = User::where('name', $this->data['created_by'])->first();
|
||||||
|
if (!$user) {
|
||||||
|
$warnMsg[] = "User not found";
|
||||||
|
}
|
||||||
|
|
||||||
|
$designType = strtolower($this->data['design_element_type'] ?? '');
|
||||||
|
|
||||||
|
$rules = [
|
||||||
|
'text' => [
|
||||||
|
'required' => ['string_x_value', 'string_y_value'],
|
||||||
|
'allowed' => [
|
||||||
|
'string_value',
|
||||||
|
'string_font',
|
||||||
|
'string_size',
|
||||||
|
'string_align',
|
||||||
|
'string_colour',
|
||||||
|
'string_x_value',
|
||||||
|
'string_y_value',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
'image' => [
|
||||||
|
'required' => ['image_x', 'image_y', 'image_width', 'image_height'],
|
||||||
|
'allowed' => [
|
||||||
|
'image_x',
|
||||||
|
'image_y',
|
||||||
|
'image_width',
|
||||||
|
'image_height',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
'shape' => [
|
||||||
|
'required' => ['shape_name', 'shape_pen_size', 'shape_x1_value', 'shape_y1_value', 'shape_x2_value', 'shape_y2_value'],
|
||||||
|
'allowed' => [
|
||||||
|
'shape_name',
|
||||||
|
'shape_pen_size',
|
||||||
|
'curve_radius',
|
||||||
|
'shape_x1_value',
|
||||||
|
'shape_y1_value',
|
||||||
|
'shape_x2_value',
|
||||||
|
'shape_y2_value',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
'qr' => [
|
||||||
|
'required' => ['qr_value', 'qr_x_value', 'qr_y_value', 'qr_size'],
|
||||||
|
'allowed' => [
|
||||||
|
'qr_value',
|
||||||
|
'qr_align',
|
||||||
|
'qr_size',
|
||||||
|
'qr_x_value',
|
||||||
|
'qr_y_value',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!isset($rules[$designType])) {
|
||||||
|
$warnMsg[] = "Invalid Design Element Type: {$designType}";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($rules[$designType])) {
|
||||||
|
foreach ($rules[$designType]['required'] as $field) {
|
||||||
|
if (empty($this->data[$field])) {
|
||||||
|
$warnMsg[] = ucfirst($designType) . " requires {$field}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$allElementFields = [
|
||||||
|
'string_value','string_font','string_size','string_align','string_colour',
|
||||||
|
'string_x_value','string_y_value',
|
||||||
|
'image_x','image_y','image_width','image_height',
|
||||||
|
'shape_name','shape_pen_size','curve_radius',
|
||||||
|
'shape_x1_value','shape_y1_value','shape_x2_value','shape_y2_value',
|
||||||
|
'qr_value','qr_align','qr_size','qr_x_value','qr_y_value',
|
||||||
|
];
|
||||||
|
|
||||||
|
if (isset($rules[$designType])) {
|
||||||
|
$allowed = $rules[$designType]['allowed'];
|
||||||
|
|
||||||
|
foreach ($allElementFields as $field) {
|
||||||
|
if (!in_array($field, $allowed, true) && !empty($this->data[$field])) {
|
||||||
|
$warnMsg[] = "Field {$field} is not allowed for {$designType} element";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($warnMsg)) {
|
||||||
|
throw new RowImportFailedException(implode(' | ', $warnMsg));
|
||||||
|
}
|
||||||
|
|
||||||
|
StickerDetail::Create([
|
||||||
|
'sticker_structure_detail_id' => $stickerId,
|
||||||
|
'design_element_type' => $this->data['design_element_type'],
|
||||||
|
'element_id' => $this->data['element_id'],
|
||||||
|
'element_type' => $this->data['element_type'],
|
||||||
|
'characteristics_type' => $this->data['characteristics_type'],
|
||||||
|
'string_value' => $this->data['string_value'],
|
||||||
|
'string_font' => $this->data['string_font'],
|
||||||
|
'string_size' => $this->data['string_size'],
|
||||||
|
'element_colour' => $this->data['element_colour'],
|
||||||
|
'string_align' => $this->data['string_align'],
|
||||||
|
'string_x_value' => $this->data['string_x_value'],
|
||||||
|
'string_y_value' => $this->data['string_y_value'],
|
||||||
|
'shape_name' => $this->data['shape_name'],
|
||||||
|
'shape_pen_size' => $this->data['shape_pen_size'],
|
||||||
|
'curve_radius' => $this->data['curve_radius'],
|
||||||
|
'shape_x1_value' => $this->data['shape_x1_value'],
|
||||||
|
'shape_y1_value' => $this->data['shape_y1_value'],
|
||||||
|
'shape_x2_value' => $this->data['shape_x2_value'],
|
||||||
|
'shape_y2_value' => $this->data['shape_y2_value'],
|
||||||
|
'image_x' => $this->data['image_x'],
|
||||||
|
'image_y' => $this->data['image_y'],
|
||||||
|
'image_width' => $this->data['image_width'],
|
||||||
|
'image_height' => $this->data['image_height'],
|
||||||
|
'qr_value' => $this->data['qr_value'],
|
||||||
|
'qr_align' => $this->data['qr_align'],
|
||||||
|
'qr_size' => $this->data['qr_size'],
|
||||||
|
'qr_x_value' => $this->data['qr_x_value'],
|
||||||
|
'qr_y_value' => $this->data['qr_y_value'],
|
||||||
|
'created_by' => $this->data['created_by'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
//return new StickerDetail();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getCompletedNotificationBody(Import $import): string
|
public static function getCompletedNotificationBody(Import $import): string
|
||||||
|
|||||||
Reference in New Issue
Block a user