From 5b5874499d2eabd8088c23dfee4e82c2d3f86f87 Mon Sep 17 00:00:00 2001
From: Oskar Stenberg <01ste02@gmail.com>
Date: Mon, 12 Jul 2021 11:46:19 +0200
Subject: [PATCH] Added import for min_amt for consumables

---
 app/Importer/ConsumableImporter.php                       | 3 +++
 app/Importer/Importer.php                                 | 5 +++--
 app/Importer/import_mappings.md                           | 1 +
 app/Models/Consumable.php                                 | 1 +
 resources/assets/js/components/importer/importer-file.vue | 4 +++-
 5 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/app/Importer/ConsumableImporter.php b/app/Importer/ConsumableImporter.php
index e7972bb2c..69964a8f3 100644
--- a/app/Importer/ConsumableImporter.php
+++ b/app/Importer/ConsumableImporter.php
@@ -41,9 +41,12 @@ class ConsumableImporter extends ItemImporter
         $consumable = new Consumable();
         $this->item['model_number'] = $this->findCsvMatch($row, "model_number");;
         $this->item['item_no'] = $this->findCsvMatch($row, "item_number");
+        $this->item['min_amt'] = $this->findCsvMatch($row, "minimum quantity");
+        $this->log("min_amt " . $this->item["min_amt"]);
         $consumable->fill($this->sanitizeItemForStoring($consumable));
         //FIXME: this disables model validation.  Need to find a way to avoid double-logs without breaking everything.
         $consumable->unsetEventDispatcher();
+        $this->log(implode(",", $this->item));
         if ($consumable->save()) {
             $consumable->logCreate('Imported using CSV Importer');
             $this->log("Consumable " . $this->item["name"] . ' was created');
diff --git a/app/Importer/Importer.php b/app/Importer/Importer.php
index 6466c3b2d..352caf849 100644
--- a/app/Importer/Importer.php
+++ b/app/Importer/Importer.php
@@ -75,6 +75,7 @@ abstract class Importer
         'department' => 'department',
         'manager_first_name' => 'manager first name',
         'manager_last_name' => 'manager last name',
+        'min_amt' => 'minimum quantity',
     ];
     /**
      * Map of item fields->csv names
@@ -195,11 +196,11 @@ abstract class Importer
         $val = $default;
         $key = $this->lookupCustomKey($key);
 
-        // $this->log("Custom Key: ${key}");
+        $this->log("Custom Key: ${key}");
         if (array_key_exists($key, $array)) {
             $val = Encoding::toUTF8(trim($array[ $key ]));
         }
-        // $this->log("${key}: ${val}");
+        $this->log("${key}: ${val}");
         return $val;
     }
 
diff --git a/app/Importer/import_mappings.md b/app/Importer/import_mappings.md
index 7899cf679..211a68bc9 100644
--- a/app/Importer/import_mappings.md
+++ b/app/Importer/import_mappings.md
@@ -29,6 +29,7 @@
 | serial number       | serial           | Asset, license                            |
 | status              | status           | Asset ? All                               |
 | supplier            | supplier         | Asset ? All                               |
+| minimum quantity    | min_amt          | Consumable                                |
 | termination date    | termination_date | License                                   |
 | warranty months     | warranty_months  | Asset                                     |
 | User Related Fields | assigned_to      | Asset                                     |
diff --git a/app/Models/Consumable.php b/app/Models/Consumable.php
index 14de8c6eb..fa0a64a36 100644
--- a/app/Models/Consumable.php
+++ b/app/Models/Consumable.php
@@ -68,6 +68,7 @@ class Consumable extends SnipeModel
         'purchase_cost',
         'purchase_date',
         'qty',
+        'min_amt',
         'requestable'
     ];
 
diff --git a/resources/assets/js/components/importer/importer-file.vue b/resources/assets/js/components/importer/importer-file.vue
index f4fddcd84..9ad0d6f52 100644
--- a/resources/assets/js/components/importer/importer-file.vue
+++ b/resources/assets/js/components/importer/importer-file.vue
@@ -155,6 +155,7 @@
                     consumables: [
                         {id: 'item_no', text: "Item Number"},
                         {id: 'model_number', text: "Model Number"},
+                        {id: 'min_amt', text: "Minimum Quantity"},
                     ],
                     licenses: [
                         {id: 'asset_tag', text: 'Assigned To Asset'},
@@ -210,6 +211,7 @@
                             .sort(sorter);
 
                     case 'consumable':
+                    	console.log('Returned consumable');
                         return this.columnOptions.general
                             .concat(this.columnOptions.consumables)
                             .sort(sorter);
@@ -303,4 +305,4 @@
             select2: require('../select2.vue').default
         }
     }
-</script>
\ No newline at end of file
+</script>
-- 
GitLab