diff --git a/app/Importer/ConsumableImporter.php b/app/Importer/ConsumableImporter.php index 10ffaaedfb..40c597e896 100644 --- a/app/Importer/ConsumableImporter.php +++ b/app/Importer/ConsumableImporter.php @@ -28,9 +28,9 @@ class ConsumableImporter extends ItemImporter { $consumable = Consumable::where('name', trim($this->item['name']))->first(); if ($consumable) { + if (! $this->updating) { $this->log('A matching Consumable '.$this->item['name'].' already exists. '); - return; } $this->log('Updating Consumable'); @@ -39,12 +39,10 @@ class ConsumableImporter extends ItemImporter return; } + $this->log('No matching consumable, creating one'); $consumable = new Consumable(); $consumable->created_by = auth()->id(); - $this->item['model_number'] = trim($this->findCsvMatch($row, 'model_number')); - $this->item['item_no'] = trim($this->findCsvMatch($row, 'item_number')); - $this->item['min_amt'] = trim($this->findCsvMatch($row, "min_amt")); $consumable->fill($this->sanitizeItemForStoring($consumable)); // This sets an attribute on the Loggable trait for the action log diff --git a/app/Importer/ItemImporter.php b/app/Importer/ItemImporter.php index 435f081aba..b8f2494096 100644 --- a/app/Importer/ItemImporter.php +++ b/app/Importer/ItemImporter.php @@ -24,6 +24,12 @@ class ItemImporter extends Importer protected function handle($row) { + + /** + * This section adds the most common fields into the $item array so we don't have to manually add them to + * things like accessories, consumables, etc. + */ + // Need to reset this between iterations or we'll have stale data. $this->item = []; @@ -73,29 +79,20 @@ class ItemImporter extends Importer $this->item['notes'] = $this->findCsvMatch($row, 'notes'); $this->item['order_number'] = $this->findCsvMatch($row, 'order_number'); $this->item['purchase_cost'] = $this->findCsvMatch($row, 'purchase_cost'); + $this->item['model_number'] = trim($this->findCsvMatch($row, 'model_number')); + $this->item['min_amt'] = $this->findCsvMatch($row, 'min_amt'); + $this->item['qty'] = $this->findCsvMatch($row, 'quantity'); + $this->item['requestable'] = $this->findCsvMatch($row, 'requestable'); + $this->item['created_by'] = auth()->id(); + $this->item['serial'] = $this->findCsvMatch($row, 'serial'); + $this->item['item_no'] = trim($this->findCsvMatch($row, 'item_number')); + $this->item['purchase_date'] = null; if ($this->findCsvMatch($row, 'purchase_date') != '') { $this->item['purchase_date'] = date('Y-m-d', strtotime($this->findCsvMatch($row, 'purchase_date'))); } -// $this->item['asset_eol_date'] = null; -// if ($this->findCsvMatch($row, 'asset_eol_date') != '') { -// $csvMatch = $this->findCsvMatch($row, 'asset_eol_date'); -// \Log::warning('EOL Date for $csvMatch is '.$csvMatch); -// try { -// $this->item['asset_eol_date'] = CarbonImmutable::parse($csvMatch)->format('Y-m-d'); -// } catch (\Exception $e) { -// Log::info($e->getMessage()); -// $this->log('Unable to parse date: '.$csvMatch); -// } -// } - - - $this->item['qty'] = $this->findCsvMatch($row, 'quantity'); - $this->item['requestable'] = $this->findCsvMatch($row, 'requestable'); - $this->item['created_by'] = auth()->id(); - $this->item['serial'] = $this->findCsvMatch($row, 'serial'); // NO need to call this method if we're running the user import. // TODO: Merge these methods. $this->item['checkout_class'] = $this->findCsvMatch($row, 'checkout_class'); @@ -512,7 +509,6 @@ class ItemImporter extends Importer if ($supplier->save()) { $this->log('Supplier '.$item_supplier.' was created'); - return $supplier->id; } $this->logError($supplier, 'Supplier'); diff --git a/app/Models/Consumable.php b/app/Models/Consumable.php index 30161e8429..f8c8e83892 100644 --- a/app/Models/Consumable.php +++ b/app/Models/Consumable.php @@ -75,6 +75,7 @@ class Consumable extends SnipeModel 'item_no', 'location_id', 'manufacturer_id', + 'supplier_id', 'name', 'order_number', 'model_number', diff --git a/resources/views/livewire/importer.blade.php b/resources/views/livewire/importer.blade.php index 3511a81bb2..5bb63f9af1 100644 --- a/resources/views/livewire/importer.blade.php +++ b/resources/views/livewire/importer.blade.php @@ -191,7 +191,7 @@ - @if (($typeOfImport != 'location' && $typeOfImport!= 'assetModel') && ($typeOfImport!='')) + @if (($typeOfImport != 'location' && $typeOfImport!= 'assetModel' && $typeOfImport!= 'component') && ($typeOfImport!=''))