Added plant code instead of plant name on import and export
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 12s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 9s
Laravel Larastan / larastan (pull_request) Failing after 3m3s
Laravel Pint / pint (pull_request) Successful in 2m44s

This commit is contained in:
dhanabalan
2026-01-13 11:59:15 +05:30
parent 0cc969f065
commit 18fc1d25ac
2 changed files with 72 additions and 68 deletions

View File

@@ -24,8 +24,8 @@ class StickerMasterExporter 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 NAME'), ->label('PLANT CODE'),
ExportColumn::make('item.code') ExportColumn::make('item.code')
->label('ITEM CODE'), ->label('ITEM CODE'),
ExportColumn::make('serial_number_motor') ExportColumn::make('serial_number_motor')
@@ -88,10 +88,10 @@ class StickerMasterExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string public static function getCompletedNotificationBody(Export $export): string
{ {
$body = 'Your sticker master export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.'; $body = 'Your sticker master 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;

View File

@@ -151,10 +151,10 @@ class StickerMasterImporter extends Importer
->example(''), ->example(''),
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']),
]; ];
} }
@@ -162,80 +162,83 @@ class StickerMasterImporter extends Importer
public function resolveRecord(): ?StickerMaster public function resolveRecord(): ?StickerMaster
{ {
$warnMsg = []; $warnMsg = [];
$plantCod = $this->data['plant'];
$plant = null;
$item = null; $item = null;
$plant = Plant::where('name', $this->data['plant'])->first(); if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
if (!$plant) { $warnMsg[] = 'Invalid plant code found';
$warnMsg[] = "Plant not found"; } else {
$plant = Plant::where('code', $plantCod)->first();
} }
else
{ if (! $plant) {
$warnMsg[] = 'Plant not found';
} else {
$item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first(); $item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first();
if (!$item) { if (! $item) {
$warnMsg[] = "Item code not found"; $warnMsg[] = 'Item code not found';
} } else {
else
{
if (Str::length($this->data['serial_number_motor']) > 0 && $this->data['serial_number_motor'] != '1') { if (Str::length($this->data['serial_number_motor']) > 0 && $this->data['serial_number_motor'] != '1') {
$warnMsg[] = "Serial number motor must be 1 or empty"; $warnMsg[] = 'Serial number motor must be 1 or empty';
} }
if (Str::length($this->data['serial_number_pump']) > 0 && $this->data['serial_number_pump'] != '1') { if (Str::length($this->data['serial_number_pump']) > 0 && $this->data['serial_number_pump'] != '1') {
$warnMsg[] = "Serial number pump must be 1 or empty"; $warnMsg[] = 'Serial number pump must be 1 or empty';
} }
if (Str::length($this->data['serial_number_pumpset']) > 0 && $this->data['serial_number_pumpset'] != '1') { if (Str::length($this->data['serial_number_pumpset']) > 0 && $this->data['serial_number_pumpset'] != '1') {
$warnMsg[] = "Serial number pumpset must be 1 or empty"; $warnMsg[] = 'Serial number pumpset must be 1 or empty';
} }
if (Str::length($this->data['pack_slip_motor']) > 0 && $this->data['pack_slip_motor'] != '1') { if (Str::length($this->data['pack_slip_motor']) > 0 && $this->data['pack_slip_motor'] != '1') {
$warnMsg[] = "Pack slip motor must be 1 or empty"; $warnMsg[] = 'Pack slip motor must be 1 or empty';
} }
if (Str::length($this->data['pack_slip_pump']) > 0 && $this->data['pack_slip_pump'] != '1') { if (Str::length($this->data['pack_slip_pump']) > 0 && $this->data['pack_slip_pump'] != '1') {
$warnMsg[] = "Pack slip pump must be 1 or empty"; $warnMsg[] = 'Pack slip pump must be 1 or empty';
} }
if (Str::length($this->data['pack_slip_pumpset']) > 0 && $this->data['pack_slip_pumpset'] != '1') { if (Str::length($this->data['pack_slip_pumpset']) > 0 && $this->data['pack_slip_pumpset'] != '1') {
$warnMsg[] = "Pack slip pumpset must be 1 or empty"; $warnMsg[] = 'Pack slip pumpset must be 1 or empty';
} }
if (Str::length($this->data['name_plate_motor']) > 0 && $this->data['name_plate_motor'] != '1') { if (Str::length($this->data['name_plate_motor']) > 0 && $this->data['name_plate_motor'] != '1') {
$warnMsg[] = "Name plate motor must be 1 or empty"; $warnMsg[] = 'Name plate motor must be 1 or empty';
} }
if (Str::length($this->data['name_plate_pump']) > 0 && $this->data['name_plate_pump'] != '1') { if (Str::length($this->data['name_plate_pump']) > 0 && $this->data['name_plate_pump'] != '1') {
$warnMsg[] = "Name plate pump must be 1 or empty"; $warnMsg[] = 'Name plate pump must be 1 or empty';
} }
if (Str::length($this->data['name_plate_pumpset']) > 0 && $this->data['name_plate_pumpset'] != '1') { if (Str::length($this->data['name_plate_pumpset']) > 0 && $this->data['name_plate_pumpset'] != '1') {
$warnMsg[] = "Name plate pumpset must be 1 or empty"; $warnMsg[] = 'Name plate pumpset must be 1 or empty';
} }
if (Str::length($this->data['tube_sticker_motor']) > 0 && $this->data['tube_sticker_motor'] != '1') { if (Str::length($this->data['tube_sticker_motor']) > 0 && $this->data['tube_sticker_motor'] != '1') {
$warnMsg[] = "Tube sticker motor must be 1 or empty"; $warnMsg[] = 'Tube sticker motor must be 1 or empty';
} }
if (Str::length($this->data['tube_sticker_pump']) > 0 && $this->data['tube_sticker_pump'] != '1') { if (Str::length($this->data['tube_sticker_pump']) > 0 && $this->data['tube_sticker_pump'] != '1') {
$warnMsg[] = "Tube sticker pump must be 1 or empty"; $warnMsg[] = 'Tube sticker pump must be 1 or empty';
} }
if (Str::length($this->data['tube_sticker_pumpset']) > 0 && $this->data['tube_sticker_pumpset'] != '1') { if (Str::length($this->data['tube_sticker_pumpset']) > 0 && $this->data['tube_sticker_pumpset'] != '1') {
$warnMsg[] = "Tube sticker pumpset must be 1 or empty"; $warnMsg[] = 'Tube sticker pumpset must be 1 or empty';
} }
if (Str::length($this->data['warranty_card']) > 0 && $this->data['warranty_card'] != '1') { if (Str::length($this->data['warranty_card']) > 0 && $this->data['warranty_card'] != '1') {
$warnMsg[] = "Warranty card must be 1 or empty"; $warnMsg[] = 'Warranty card must be 1 or empty';
} }
if (Str::length($this->data['panel_box_code']) > 0 && (Str::length($this->data['panel_box_code']) < 6 || !ctype_alnum($this->data['panel_box_code']))) { if (Str::length($this->data['panel_box_code']) > 0 && (Str::length($this->data['panel_box_code']) < 6 || ! ctype_alnum($this->data['panel_box_code']))) {
$warnMsg[] = "Invalid panel box code found"; $warnMsg[] = 'Invalid panel box code found';
} }
if (Str::length($this->data['load_rate']) < 0 || !is_numeric($this->data['load_rate']) || $this->data['load_rate'] < 0) { if (Str::length($this->data['load_rate']) < 0 || ! is_numeric($this->data['load_rate']) || $this->data['load_rate'] < 0) {
$warnMsg[] = "Load rate must be greater than or equal to 0"; $warnMsg[] = 'Load rate must be greater than or equal to 0';
} }
if (Str::length($this->data['bundle_quantity']) > 0 && (!is_numeric($this->data['bundle_quantity']) || $this->data['bundle_quantity'] <= 1)) { if (Str::length($this->data['bundle_quantity']) > 0 && (! is_numeric($this->data['bundle_quantity']) || $this->data['bundle_quantity'] <= 1)) {
$warnMsg[] = "Bundle quantity must be greater than or equal to '2' or empty"; $warnMsg[] = "Bundle quantity must be greater than or equal to '2' or empty";
} }
if (Str::length($this->data['material_type']) > 0 && $this->data['material_type'] != '1' && $this->data['material_type'] != '2' && $this->data['material_type'] != '3') { //($this->data['material_type'] != null) && if (Str::length($this->data['material_type']) > 0 && $this->data['material_type'] != '1' && $this->data['material_type'] != '2' && $this->data['material_type'] != '3') { // ($this->data['material_type'] != null) &&
$warnMsg[] = "Material type must be 1 or 2 or 3 or empty"; $warnMsg[] = 'Material type must be 1 or 2 or 3 or empty';
} }
} }
} }
if (!empty($warnMsg)) { if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg)); throw new RowImportFailedException(implode(', ', $warnMsg));
} }
StickerMaster::updateOrCreate([ StickerMaster::updateOrCreate([
'item_id' => $item->id, 'item_id' => $item->id,
'plant_id' => $plant->id 'plant_id' => $plant->id,
], ],
[ [
'serial_number_motor' => $this->data['serial_number_motor'], 'serial_number_motor' => $this->data['serial_number_motor'],
@@ -261,8 +264,9 @@ class StickerMasterImporter extends Importer
'panel_box_code' => $this->data['panel_box_code'], 'panel_box_code' => $this->data['panel_box_code'],
'load_rate' => $this->data['load_rate'], 'load_rate' => $this->data['load_rate'],
'bundle_quantity' => $this->data['bundle_quantity'], 'bundle_quantity' => $this->data['bundle_quantity'],
'material_type' => $this->data['material_type'] 'material_type' => $this->data['material_type'],
]); ]);
return null; return null;
// return StickerMaster::firstOrNew([ // return StickerMaster::firstOrNew([
// // Update existing records, matching them by `$this->data['column_name']` // // Update existing records, matching them by `$this->data['column_name']`
@@ -274,10 +278,10 @@ class StickerMasterImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string public static function getCompletedNotificationBody(Import $import): string
{ {
$body = 'Your sticker master import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.'; $body = 'Your sticker master 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;