Index: trunk/grails-app/services/InventoryCsvService.groovy
===================================================================
--- trunk/grails-app/services/InventoryCsvService.groovy	(revision 427)
+++ trunk/grails-app/services/InventoryCsvService.groovy	(revision 436)
@@ -55,5 +55,5 @@
             def line = []
             def lineNumber = 0
-            def maxNumberOfColumns = 23
+            def maxNumberOfColumns = 25
             def inventoryParams = [:]
             def inventoryProperties = ["name", "description", "comment", "unitsInStock", "reorderPoint", "recommendedReorderPoint",
@@ -61,14 +61,17 @@
                                                         "enableReorder", "inventoryLocation", "inventoryStore", "site",
                                                         "inventoryGroup", "inventoryType", "averageDeliveryTime", "averageDeliveryPeriod",
-                                                        "suppliersPartNumber", "suppliers",
-                                                        "manufacturersPartNumber", "manufacturers", "alternateItems", "spareFor"]
+                                                        "suppliersPartNumber", "preferredSupplier", "alternateSuppliers",
+                                                        "manufacturersPartNumber", "preferredManufacturer", "alternateManufacturers",
+                                                        "alternateItems", "spareFor"]
 
             def siteInstance
-            def supplierInstance
+            def alternateSupplierInstance
+            def preferredSupplierInstance
             def supplierTypeInstance
             def supplierTypeUnknown = SupplierType.get(1)
             def spareForInstance
             def alternateItemInstance
-            def manufacturerInstance
+            def preferredManufacturerInstance
+            def alternateManufacturerInstance
             def manufacturerTypeInstance
             def manufacturerTypeUnknown = ManufacturerType.get(1)
@@ -81,9 +84,18 @@
             def averageDeliveryPeriodInstance
 
-            def tempSuppliers = []
+            def tempPreferredSupplierItemAndType = ''
+            def tempPreferredSupplierItem = ''
+            def tempPreferredSupplierType = ''
+
+            def tempAlternateSuppliers = []
             def tempSupplierItem = ''
             def tempSupplierType = ''
             def tempSupplierItemAndType = []
-            def tempManufacturers = []
+
+            def tempPreferredManufacturerItemAndType = ''
+            def tempPreferredManufacturerItem = ''
+            def tempPreferredManufacturerType = ''
+
+            def tempAlternateManufacturers = []
             def tempManufacturerItem = ''
             def tempManufacturerType = ''
@@ -258,9 +270,40 @@
                 }
 
-                // Manufacturers.
-                tempManufacturers = parseInputList(inventoryParams.manufacturers)
+                // Preferred Manufacturer
+                if(inventoryParams.preferredManufacturer) {
+                    tempPreferredManufacturerItemAndType = parseItemAndType(inventoryParams.preferredManufacturer)
+                    tempPreferredManufacturerItem = WordUtils.capitalize(tempPreferredManufacturerItemAndType[0])
+
+                    preferredManufacturerInstance = Manufacturer.findByName(tempPreferredManufacturerItem)
+                    if(!preferredManufacturerInstance) {
+
+                        // Manufacturer Type.
+                        if(tempPreferredManufacturerItemAndType.size == 2) {
+                            tempPreferredManufacturerType = WordUtils.capitalizeFully(tempPreferredManufacturerItemAndType[1])
+                            manufacturerTypeInstance = ManufacturerType.findByName(tempPreferredManufacturerType)
+                        }
+                        else
+                            manufacturerTypeInstance = manufacturerTypeUnknown
+                        if(!manufacturerTypeInstance) {
+                            log.error "Failed to find preferred manufacturer type on line: " + lineNumber
+                            return fail(code: "inventory.import.failure", args: [lineNumber, logFileLink])
+                        }
+
+                        preferredManufacturerInstance = new Manufacturer(name: tempPreferredManufacturerItem,
+                                                                                                            supplierType: manufacturerTypeInstance)
+                        if(!preferredManufacturerInstance.save()) {
+                            log.error "Failed to create preferred manufacturer on line: " + lineNumber
+                            return fail(code: "inventory.import.failure", args: [lineNumber, logFileLink])
+                        }
+                    }
+                }
+                else
+                    preferredManufacturerInstance = null
+
+                // Alternate Manufacturers.
+                tempAlternateManufacturers = parseInputList(inventoryParams.manufacturers)
                 inventoryParams.manufacturers = []
 
-                for(tempManufacturer in tempManufacturers) {
+                for(tempManufacturer in tempAlternateManufacturers) {
                     tempManufacturerItemAndType = parseItemAndType(tempManufacturer)
                     tempManufacturerItem = WordUtils.capitalizeFully(tempManufacturerItemAndType[0])
@@ -292,14 +335,45 @@
                 }
 
-                // Suppliers.
-                tempSuppliers = parseInputList(inventoryParams.suppliers)
-                inventoryParams.suppliers = []
-
-                for(tempSupplier in tempSuppliers) {
+                // Preferred Supplier
+                if(inventoryParams.preferredSupplier) {
+                    tempPreferredSupplierItemAndType = parseItemAndType(inventoryParams.preferredSupplier)
+                    tempPreferredSupplierItem = WordUtils.capitalize(tempPreferredSupplierItemAndType[0])
+
+                    preferredSupplierInstance = Supplier.findByName(tempPreferredSupplierItem)
+                    if(!preferredSupplierInstance) {
+
+                        // SupplierType.
+                        if(tempPreferredSupplierItemAndType.size == 2) {
+                            tempPreferredSupplierType = WordUtils.capitalizeFully(tempPreferredSupplierItemAndType[1])
+                            supplierTypeInstance = SupplierType.findByName(tempPreferredSupplierType)
+                        }
+                        else
+                            supplierTypeInstance = supplierTypeUnknown
+                        if(!supplierTypeInstance) {
+                            log.error "Failed to find preferred supplier type on line: " + lineNumber
+                            return fail(code: "inventory.import.failure", args: [lineNumber, logFileLink])
+                        }
+
+                        preferredSupplierInstance = new Supplier(name: tempPreferredSupplierItem,
+                                                                                            supplierType: supplierTypeInstance)
+                        if(!preferredSupplierInstance.save()) {
+                            log.error "Failed to create preferred supplier on line: " + lineNumber
+                            return fail(code: "inventory.import.failure", args: [lineNumber, logFileLink])
+                        }
+                    }
+                }
+                else
+                    preferredSupplierInstance = null
+
+                // Alternate Suppliers.
+                tempAlternateSuppliers = parseInputList(inventoryParams.alternateSuppliers)
+                inventoryParams.alternateSuppliers = []
+
+                for(tempSupplier in tempAlternateSuppliers) {
                     tempSupplierItemAndType = parseItemAndType(tempSupplier)
                     tempSupplierItem = WordUtils.capitalizeFully(tempSupplierItemAndType[0])
 
-                    supplierInstance = Supplier.findByName(tempSupplierItem)
-                    if(!supplierInstance) {
+                    alternateSupplierInstance = Supplier.findByName(tempSupplierItem)
+                    if(!alternateSupplierInstance) {
 
                         // SupplierType.
@@ -311,17 +385,17 @@
                             supplierTypeInstance = supplierTypeUnknown
                         if(!supplierTypeInstance) {
-                            log.error "Failed to find supplier type on line: " + lineNumber
-                            return fail(code: "inventory.import.failure", args: [lineNumber, logFileLink])
-                        }
-
-                        supplierInstance = new Supplier(name: tempSupplierItem,
+                            log.error "Failed to find alternate supplier type on line: " + lineNumber
+                            return fail(code: "inventory.import.failure", args: [lineNumber, logFileLink])
+                        }
+
+                        alternateSupplierInstance = new Supplier(name: tempSupplierItem,
                                                                             supplierType: supplierTypeInstance)
-                        if(!supplierInstance.save()) {
-                            log.error "Failed to create suppliers on line: " + lineNumber
-                            return fail(code: "inventory.import.failure", args: [lineNumber, logFileLink])
-                        }
-                    }
-
-                    inventoryParams.suppliers.add(supplierInstance)
+                        if(!alternateSupplierInstance.save()) {
+                            log.error "Failed to create alternate suppliers on line: " + lineNumber
+                            return fail(code: "inventory.import.failure", args: [lineNumber, logFileLink])
+                        }
+                    }
+
+                    inventoryParams.suppliers.add(alternateSupplierInstance)
                 }
 
@@ -373,4 +447,6 @@
                 inventoryParams.unitOfMeasure = unitOfMeasureInstance
                 inventoryParams.averageDeliveryPeriod = averageDeliveryPeriodInstance
+                inventoryParams.preferredSupplier = preferredSupplierInstance
+                inventoryParams.preferredManufacturer = preferredManufacturerInstance
 
                 // Name.
@@ -469,6 +545,8 @@
                                         "Consumable",
                                         "7", "Week(s)",
-                                        "123", "Multi Distributors1@OEM; Multi Distributors2@Local",
-                                        "321", "Mega Manufacturer1@OEM;Mega Manufacturer2@Alternate",
+                                        "123", "Multi Supplier@Local",
+                                        "Multi Distributors1@OEM; Multi Distributors2@Local",
+                                        "321", "Master Manufacturer@OEM",
+                                        "Mega Manufacturer1@OEM;Mega Manufacturer2@Alternate",
                                         "2204E-2RS", ""
                                         ] as String[])
@@ -483,6 +561,8 @@
                                         "Consumable",
                                         "2", "Month(s)",
-                                        "456KL", "Multi Distributors1; Multi Distributors2",
-                                        "654OP", "Mega Manufacturer1;Mega Manufacturer2",
+                                        "456KL", "Multi Supplier",
+                                        "Multi Distributors1; Multi Distributors2",
+                                        "654OP", "Master Manufacturer",
+                                        "Mega Manufacturer1;Mega Manufacturer2",
                                         "", ""
                                         ] as String[])
@@ -494,5 +574,5 @@
     /**
     * Build complete inventory for export.
-    * @param inventoryItemList The list of inventory items to build..
+    * @param inventoryItemList The list of inventory items to build.
     * @returns The inventory as a String in csv format.
     */
@@ -528,5 +608,10 @@
             row.add(inventoryItem.suppliersPartNumber)
 
-            row.add( inventoryItem.suppliers.sort { p1, p2 ->
+            if(inventoryItem.preferredSupplier)
+                row.add( inventoryItem.preferredSupplier.name + "@" + inventoryItem.preferredSupplier.supplierType )
+            else
+                row.add('')
+
+            row.add( inventoryItem.alternateSuppliers.sort { p1, p2 ->
                 p1.name.compareToIgnoreCase(p2.name)
             }.collect { it.name + "@" + it.supplierType }.join(';') )
@@ -534,5 +619,10 @@
             row.add(inventoryItem.manufacturersPartNumber)
 
-            row.add(inventoryItem.manufacturers.sort { p1, p2 ->
+            if(inventoryItem.preferredManufacturer)
+                row.add( inventoryItem.preferredManufacturer.name + "@" + inventoryItem.preferredManufacturer.manufacturerType )
+            else
+                row.add('')
+
+            row.add(inventoryItem.alternateManufacturers.sort { p1, p2 ->
                 p1.name.compareToIgnoreCase(p2.name)
             }.collect { it.name + "@" + it.manufacturerType }.join(';'))
@@ -556,6 +646,6 @@
             ["Name*", "Description", "Comment", "Units In Stock", "Reorder Point*", "Recommended Reorder Point", "Unit Of Measure*",
             "Estimated Unit Price", "Currency", "Enable Reorder", "Location*", "Store*", "Site*", "Group*", "Type*",
-            "averageDeliveryTime", "averageDeliveryPeriod", "Supplier's Part Number", "Supplier",
-            "Manufacturer's Part Number", "Manufacturer", "Alternate Item", "Spare For"]
+            "Average Delivery Time", "Average Delivery Period", "Supplier's Part Number", "Preferred Supplier", "Alternate Suppliers",
+            "Manufacturer's Part Number", "Preferred Manufacturer", "Alternate Manufacturers", "Alternate Item", "Spare For"]
     }
 
