Merge pull request 'Added validation in importer and exporter of sticker structure details' (#75) from ranjith-dev into master
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
Reviewed-on: #75
This commit was merged in pull request #75.
This commit is contained in:
@@ -13,21 +13,43 @@ class StickerStructureDetailExporter extends Exporter
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
static $rowNumber = 0;
|
||||
return [
|
||||
ExportColumn::make('id')
|
||||
->label('ID'),
|
||||
ExportColumn::make('sticker_id'),
|
||||
ExportColumn::make('sticker_width'),
|
||||
ExportColumn::make('sticker_height'),
|
||||
ExportColumn::make('sticker_lmargin'),
|
||||
ExportColumn::make('sticker_rmargin'),
|
||||
ExportColumn::make('sticker_tmargin'),
|
||||
ExportColumn::make('sticker_bmargin'),
|
||||
ExportColumn::make('created_at'),
|
||||
ExportColumn::make('updated_at'),
|
||||
ExportColumn::make('created_by'),
|
||||
ExportColumn::make('updated_by'),
|
||||
ExportColumn::make('deleted_at'),
|
||||
ExportColumn::make('no')
|
||||
->label('NO')
|
||||
->state(function ($record) use (&$rowNumber) {
|
||||
// Increment and return the row number
|
||||
return ++$rowNumber;
|
||||
}),
|
||||
ExportColumn::make('plant.code')
|
||||
->label('PLANT CODE'),
|
||||
ExportColumn::make('itemCharacteristic.item.code')
|
||||
->label('ITEM CODE'),
|
||||
ExportColumn::make('sticker_id')
|
||||
->label('STICKER ID'),
|
||||
ExportColumn::make('sticker_width')
|
||||
->label('STICKER WIDTH'),
|
||||
ExportColumn::make('sticker_height')
|
||||
->label('STICKER HEIGHT'),
|
||||
ExportColumn::make('sticker_lmargin')
|
||||
->label('STICKER LEFT MARGIN'),
|
||||
ExportColumn::make('sticker_rmargin')
|
||||
->label('STICKER RIGHT MARGIN'),
|
||||
ExportColumn::make('sticker_tmargin')
|
||||
->label('STICKER TOP MARGIN'),
|
||||
ExportColumn::make('sticker_bmargin')
|
||||
->label('STICKER BOTTOM MARGIN'),
|
||||
ExportColumn::make('created_at')
|
||||
->label('CREATED AT'),
|
||||
ExportColumn::make('updated_at')
|
||||
->label('UPDATED AT'),
|
||||
ExportColumn::make('created_by')
|
||||
->label('CREATED BY'),
|
||||
ExportColumn::make('updated_by')
|
||||
->label('UPDATED BY'),
|
||||
ExportColumn::make('deleted_at')
|
||||
->enabledByDefault(false)
|
||||
->label('DELETED AT'),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,15 @@
|
||||
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\Item;
|
||||
use App\Models\ItemCharacteristic;
|
||||
use App\Models\Plant;
|
||||
use App\Models\StickerStructureDetail;
|
||||
use App\Models\User;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
||||
|
||||
class StickerStructureDetailImporter extends Importer
|
||||
{
|
||||
@@ -14,26 +19,133 @@ class StickerStructureDetailImporter extends Importer
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
ImportColumn::make('sticker_id'),
|
||||
ImportColumn::make('sticker_width'),
|
||||
ImportColumn::make('sticker_height'),
|
||||
ImportColumn::make('sticker_lmargin'),
|
||||
ImportColumn::make('sticker_rmargin'),
|
||||
ImportColumn::make('sticker_tmargin'),
|
||||
ImportColumn::make('sticker_bmargin'),
|
||||
ImportColumn::make('created_by'),
|
||||
ImportColumn::make('updated_by'),
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Plant Code')
|
||||
->example('1000')
|
||||
->label('PLANT CODE')
|
||||
->relationship(resolveUsing: 'code')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('item_characteristic_id')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Item Code')
|
||||
->example('123456')
|
||||
->label('ITEM CODE')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('sticker_id')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Sticker ID')
|
||||
->example('123456')
|
||||
->label('STICKER ID')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('sticker_width')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Sticker Width')
|
||||
->example('90')
|
||||
->label('STICKER WIDTH')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('sticker_height')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Sticker Height')
|
||||
->example('90')
|
||||
->label('STICKER HEIGHT')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('sticker_lmargin')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Sticker Left Margin')
|
||||
->example('0')
|
||||
->label('STICKER LEFT MARGIN')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('sticker_rmargin')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Sticker Right Margin')
|
||||
->example('0')
|
||||
->label('STICKER RIGHT MARGIN')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('sticker_tmargin')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Sticker Top Margin')
|
||||
->example('0')
|
||||
->label('STICKER TOP MARGIN')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('sticker_bmargin')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Sticker Bottom Margin')
|
||||
->example('0')
|
||||
->label('STICKER BOTTOM MARGIN')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('created_by')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Created By')
|
||||
->example('RAW001234')
|
||||
->label('CREATED BY')
|
||||
->rules(['required']),
|
||||
];
|
||||
}
|
||||
|
||||
public function resolveRecord(): ?StickerStructureDetail
|
||||
{
|
||||
// return StickerStructureDetail::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
$warnMsg = [];
|
||||
|
||||
return new StickerStructureDetail();
|
||||
$plant = Plant::where('code', $this->data['plant'])->first();
|
||||
|
||||
if (!$plant) {
|
||||
$warnMsg[] = "Plant code not found";
|
||||
}
|
||||
|
||||
// $item = null;
|
||||
// if ($plant) {
|
||||
// $item = Item::where('code', $this->data['itemCharacteristic.item'])->where('plant_id', $plant->id)->first();
|
||||
// }
|
||||
// if (!$item) {
|
||||
// $warnMsg[] = "Item not found";
|
||||
// }
|
||||
|
||||
$itemCode = $this->data['item_characteristic_id'] ?? null;
|
||||
|
||||
$item = Item::where('code', $itemCode)->first();
|
||||
if (!$item) {
|
||||
$warnMsg[] = "Item not found";
|
||||
}
|
||||
|
||||
$itemChar = ItemCharacteristic::where('item_id', $item->id)->first();
|
||||
if (!$itemChar) {
|
||||
$warnMsg[] = "Item not found in item characteristic";
|
||||
}
|
||||
|
||||
$user = User::where('name', $this->data['created_by'])->first();
|
||||
if (!$user) {
|
||||
$warnMsg[] = "User not found";
|
||||
}
|
||||
|
||||
if (!empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
else { //if (empty($warnMsg))
|
||||
$stickerId = StickerStructureDetail::where('sticker_id', $this->data['sticker_id'])
|
||||
->first();
|
||||
|
||||
if ($stickerId) {
|
||||
throw new RowImportFailedException("Sticker ID already exist!");
|
||||
}
|
||||
}
|
||||
|
||||
StickerStructureDetail::Create([
|
||||
'plant_id' => $plant->id,
|
||||
'item_characteristic_id' => $itemChar->id,
|
||||
'sticker_id' => $this->data['sticker_id'],
|
||||
'sticker_width' => $this->data['sticker_width'],
|
||||
'sticker_height' => $this->data['sticker_height'],
|
||||
'sticker_lmargin' => $this->data['sticker_lmargin'],
|
||||
'sticker_rmargin' => $this->data['sticker_rmargin'],
|
||||
'sticker_tmargin' => $this->data['sticker_tmargin'],
|
||||
'sticker_bmargin' => $this->data['sticker_bmargin'],
|
||||
'created_by' => $this->data['created_by'],
|
||||
]);
|
||||
|
||||
return null;
|
||||
|
||||
//return new StickerStructureDetail();
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
|
||||
Reference in New Issue
Block a user