Index: trunk/grails-app/controllers/CostCodeDetailedController.groovy
===================================================================
--- trunk/grails-app/controllers/CostCodeDetailedController.groovy	(revision 632)
+++ trunk/grails-app/controllers/CostCodeDetailedController.groovy	(revision 633)
@@ -78,4 +78,6 @@
             }
             costCodeInstance.properties = params
+            // Trim name to avoid spaces.
+            costCodeInstance.name = costCodeInstance.name.trim()
             if(!costCodeInstance.hasErrors() && costCodeInstance.save(flush: true)) {
                 flash.message = "CostCode ${params.id} updated"
@@ -100,4 +102,6 @@
     def save = {
         def costCodeInstance = new CostCode(params)
+        // Trim name to avoid spaces.
+        costCodeInstance.name = costCodeInstance.name.trim()
         if(!costCodeInstance.hasErrors() && costCodeInstance.save(flush: true)) {
             flash.message = "CostCode ${costCodeInstance.id} created"
Index: trunk/grails-app/controllers/InventoryItemPurchaseDetailedController.groovy
===================================================================
--- trunk/grails-app/controllers/InventoryItemPurchaseDetailedController.groovy	(revision 632)
+++ trunk/grails-app/controllers/InventoryItemPurchaseDetailedController.groovy	(revision 633)
@@ -226,6 +226,13 @@
         params.returnTo = params.returnTo ?: 'inventoryItem'
 
-        if(!result.error)
-            return [ inventoryItemPurchaseInstance : result.inventoryItemPurchaseInstance ]
+        def costCodes = []
+
+        if(!result.error) {
+            if(inventoryPurchaseService.isPersonInPurchasingGroup(result.inventoryItemPurchaseInstance.costCode.purchasingGroup))
+                costCodes = inventoryPurchaseService.getCostCodesByPerson()
+
+            return [ inventoryItemPurchaseInstance : result.inventoryItemPurchaseInstance,
+                            'costCodes': costCodes ]
+        }
 
         flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
@@ -248,5 +255,14 @@
         }
 
-        render(view:'edit', model:[inventoryItemPurchaseInstance: result.inventoryItemPurchaseInstance.attach()])
+        result.inventoryItemPurchaseInstance.attach()
+        result.inventoryItemPurchaseInstance.costCode.attach()
+        result.inventoryItemPurchaseInstance.costCode.purchasingGroup.attach()
+
+        def costCodes = []
+        if(inventoryPurchaseService.isPersonInPurchasingGroup(result.inventoryItemPurchaseInstance.costCode.purchasingGroup))
+            costCodes = inventoryPurchaseService.getCostCodesByPerson()
+
+        render(view:'edit', model:[inventoryItemPurchaseInstance: result.inventoryItemPurchaseInstance,
+                                                'costCodes': costCodes])
     }
 
@@ -262,5 +278,8 @@
         }
 
-        return ['inventoryItemPurchaseInstance':inventoryItemPurchaseInstance]
+        def costCodes = inventoryPurchaseService.getCostCodesByPerson()
+
+        return ['inventoryItemPurchaseInstance': inventoryItemPurchaseInstance,
+                        'costCodes': costCodes]
     }
 
@@ -282,6 +301,9 @@
         }
 
+        def costCodes = inventoryPurchaseService.getCostCodesByPerson()
+
         params.errorMessage = g.message(code: result.error.code, args: result.error.args)
-        render(view:'create', model:['inventoryItemPurchaseInstance': result.inventoryItemPurchaseInstance])
+        render(view:'create', model:['inventoryItemPurchaseInstance': result.inventoryItemPurchaseInstance,
+                                                    'costCodes': costCodes])
     }
 
Index: trunk/grails-app/controllers/PersonController.groovy
===================================================================
--- trunk/grails-app/controllers/PersonController.groovy	(revision 632)
+++ trunk/grails-app/controllers/PersonController.groovy	(revision 633)
@@ -157,4 +157,5 @@
             person.properties = params
             person.setPersonGroupsFromCheckBoxList(params.personGroups)
+            person.setPurchasingGroupsFromCheckBoxList(params.purchasingGroups)
 
             if(params.pass == "") {
@@ -194,4 +195,5 @@
             person.password = authenticateService.encodePassword(params.pass)
             person.setPersonGroupsFromCheckBoxList(params.personGroups)
+            person.setPurchasingGroupsFromCheckBoxList(params.purchasingGroups)
             if (person.save(flush: true)) {
                 addRemoveAuthorities(person)
Index: trunk/grails-app/controllers/PurchasingGroupDetailedController.groovy
===================================================================
--- trunk/grails-app/controllers/PurchasingGroupDetailedController.groovy	(revision 633)
+++ trunk/grails-app/controllers/PurchasingGroupDetailedController.groovy	(revision 633)
@@ -0,0 +1,110 @@
+import org.codehaus.groovy.grails.plugins.springsecurity.Secured
+
+@Secured(['ROLE_AppAdmin', 'ROLE_Manager'])
+class PurchasingGroupDetailedController extends BaseController {
+    
+    def index = { redirect(action:list,params:params) }
+
+    // the delete, save and update actions only accept POST requests
+    static allowedMethods = [delete:'POST', save:'POST', update:'POST']
+
+    def list = {
+        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
+        [ purchasingGroupInstanceList: PurchasingGroup.list( params ), purchasingGroupInstanceTotal: PurchasingGroup.count() ]
+    }
+
+    def show = {
+
+        // In the case of an actionSubmit button, rewrite action name from 'index'.
+        if(params._action_Show)
+            params.action='show'
+
+        def purchasingGroupInstance = PurchasingGroup.get( params.id )
+
+        if(!purchasingGroupInstance) {
+            flash.message = "PurchasingGroup not found with id ${params.id}"
+            redirect(action:list)
+        }
+        else { return [ purchasingGroupInstance : purchasingGroupInstance ] }
+    }
+
+    def delete = {
+        def purchasingGroupInstance = PurchasingGroup.get( params.id )
+        if(purchasingGroupInstance) {
+            try {
+                purchasingGroupInstance.delete(flush:true)
+                flash.message = "PurchasingGroup ${params.id} deleted"
+                redirect(action:list)
+            }
+            catch(org.springframework.dao.DataIntegrityViolationException e) {
+                flash.message = "PurchasingGroup ${params.id} could not be deleted"
+                redirect(action:show,id:params.id)
+            }
+        }
+        else {
+            flash.message = "PurchasingGroup not found with id ${params.id}"
+            redirect(action:list)
+        }
+    }
+
+    def edit = {
+
+        // In the case of an actionSubmit button, rewrite action name from 'index'.
+        if(params._action_Edit)
+            params.action='edit'
+
+        def purchasingGroupInstance = PurchasingGroup.get( params.id )
+
+        if(!purchasingGroupInstance) {
+            flash.message = "PurchasingGroup not found with id ${params.id}"
+            redirect(action:list)
+        }
+        else {
+            return [ purchasingGroupInstance : purchasingGroupInstance ]
+        }
+    }
+
+    def update = {
+        def purchasingGroupInstance = PurchasingGroup.get( params.id )
+        if(purchasingGroupInstance) {
+            if(params.version) {
+                def version = params.version.toLong()
+                if(purchasingGroupInstance.version > version) {
+                    
+                    purchasingGroupInstance.errors.rejectValue("version", "default.optimistic.locking.failure")
+                    render(view:'edit',model:[purchasingGroupInstance:purchasingGroupInstance])
+                    return
+                }
+            }
+            purchasingGroupInstance.properties = params
+            if(!purchasingGroupInstance.hasErrors() && purchasingGroupInstance.save(flush: true)) {
+                flash.message = "PurchasingGroup ${params.id} updated"
+                redirect(action:show,id:purchasingGroupInstance.id)
+            }
+            else {
+                render(view:'edit',model:[purchasingGroupInstance:purchasingGroupInstance])
+            }
+        }
+        else {
+            flash.message = "PurchasingGroup not found with id ${params.id}"
+            redirect(action:list)
+        }
+    }
+
+    def create = {
+        def purchasingGroupInstance = new PurchasingGroup()
+        purchasingGroupInstance.properties = params
+        return ['purchasingGroupInstance':purchasingGroupInstance]
+    }
+
+    def save = {
+        def purchasingGroupInstance = new PurchasingGroup(params)
+        if(!purchasingGroupInstance.hasErrors() && purchasingGroupInstance.save(flush: true)) {
+            flash.message = "PurchasingGroup ${purchasingGroupInstance.id} created"
+            redirect(action:show,id:purchasingGroupInstance.id)
+        }
+        else {
+            render(view:'create',model:[purchasingGroupInstance:purchasingGroupInstance])
+        }
+    }
+}
