Added update or create record on import
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Models\Block;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
use Notification;
|
||||
|
||||
class BlockImporter extends Importer
|
||||
{
|
||||
@@ -32,12 +33,18 @@ class BlockImporter extends Importer
|
||||
|
||||
public function resolveRecord(): ?Block
|
||||
{
|
||||
$plant = \App\Models\Plant::where('name', $this->data['plant'])->first();
|
||||
return Block::updateOrCreate([
|
||||
'name' => $this->data['name'],
|
||||
'plant_id' => $plant->id
|
||||
]
|
||||
);
|
||||
// return Block::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
|
||||
return new Block();
|
||||
// return new Block();
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
|
||||
@@ -25,12 +25,16 @@ class CompanyImporter extends Importer
|
||||
|
||||
public function resolveRecord(): ?Company
|
||||
{
|
||||
return Company::updateOrCreate([
|
||||
'name' => $this->data['name']
|
||||
]
|
||||
);
|
||||
// return Company::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
|
||||
return new Company();
|
||||
// return new Company();
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
|
||||
@@ -45,12 +45,17 @@ class ItemImporter extends Importer
|
||||
|
||||
public function resolveRecord(): ?Item
|
||||
{
|
||||
// return Item::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
|
||||
return new Item;
|
||||
$plant = \App\Models\Plant::where('name', $this->data['plant'])->first();
|
||||
return Item::updateOrCreate([
|
||||
'code' => $this->data['code'],
|
||||
'plant_id' => $plant->id
|
||||
],
|
||||
[
|
||||
'description' => $this->data['description'],
|
||||
'hourly_quantity' => $this->data['hourly_quantity']
|
||||
]
|
||||
);
|
||||
// return new Item;
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
|
||||
@@ -38,12 +38,21 @@ class LineImporter extends Importer
|
||||
|
||||
public function resolveRecord(): ?Line
|
||||
{
|
||||
$plant = \App\Models\Plant::where('name', $this->data['plant'])->first();
|
||||
return Line::updateOrCreate([
|
||||
'name' => $this->data['name'],
|
||||
'plant_id' => $plant->id
|
||||
],
|
||||
[
|
||||
'type' => $this->data['type']
|
||||
]
|
||||
);
|
||||
// return Line::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
|
||||
return new Line();
|
||||
// return new Line();
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
|
||||
@@ -31,12 +31,19 @@ class LineStopImporter extends Importer
|
||||
|
||||
public function resolveRecord(): ?LineStop
|
||||
{
|
||||
return LineStop::updateOrCreate([
|
||||
'code' => $this->data['code']
|
||||
],
|
||||
[
|
||||
'reason' => $this->data['reason']
|
||||
]
|
||||
);
|
||||
// return LineStop::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
|
||||
return new LineStop();
|
||||
// return new LineStop();
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
|
||||
@@ -26,7 +26,7 @@ class StickerMasterImporter extends Importer
|
||||
->requiredMapping()
|
||||
->exampleHeader('Plant Name')
|
||||
->example('Ransar Industries-I')
|
||||
->label('PLANT')
|
||||
->label('PLANT NAME')
|
||||
->relationship(resolveUsing: 'name')
|
||||
->rules(['required']),
|
||||
|
||||
@@ -178,6 +178,41 @@ class StickerMasterImporter extends Importer
|
||||
|
||||
public function resolveRecord(): ?StickerMaster
|
||||
{
|
||||
$item = \App\Models\Item::where('code', $this->data['item'])->first();
|
||||
$plant = \App\Models\Plant::where('name', $this->data['plant'])->first();
|
||||
if (!$plant || !$item) {
|
||||
// Optionally handle missing plant/block
|
||||
return null;
|
||||
}
|
||||
return StickerMaster::updateOrCreate([
|
||||
'item_id' => $item->id,
|
||||
'plant_id' => $plant->id
|
||||
],
|
||||
[
|
||||
'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'],
|
||||
'panel_box_code' => $this->data['panel_box_code'],
|
||||
'load_rate' => $this->data['load_rate'],
|
||||
'bundle_quantity' => $this->data['bundle_quantity'],
|
||||
'material_type' => $this->data['material_type']
|
||||
]
|
||||
);
|
||||
// return StickerMaster::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
|
||||
Reference in New Issue
Block a user