source: trunk/grails-app/controllers/InventoryMovementDetailedController.groovy @ 298

Last change on this file since 298 was 298, checked in by gav, 10 years ago

Set base authorisations on all controllers.

File size: 4.3 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3@Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager'])
4class InventoryMovementDetailedController extends BaseController {
5
6    def inventoryMovementService
7
8    // the delete, save and update actions only accept POST requests
9    static allowedMethods = [delete:'POST', save:'POST']
10
11    def index = { redirect(action:list,params:params) }
12
13    def list = {
14        flash.message = flash.message
15        redirect(controller:"taskDetailed", action:"search")
16    }
17
18    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager', 'ROLE_InventoryUser'])
19    def show = {
20        def inventoryMovementInstance = InventoryMovement.get( params.id )
21
22        if(!inventoryMovementInstance) {
23            flash.message = "InventoryMovement not found with id ${params.id}"
24            redirect(action:list)
25        }
26        else { return [ inventoryMovementInstance : inventoryMovementInstance ] }
27    }
28
29    /**
30    * List the inventory movements for an InventoryItem.
31    * @param params.inventoryItem.id The id of an existing inventory item.
32    */
33    @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager', 'ROLE_InventoryUser'])
34    def listInventoryMovements = {
35        def inventoryItemInstance = InventoryItem.get(params.inventoryItem.id)
36
37        if(!inventoryItemInstance) {
38            flash.message = "Inventory item not found with id ${params.id}"
39            redirect(controller:'inventoryItemDetailed', action: 'search')
40        }
41
42        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
43        def inventoryMovementList = InventoryMovement.findAllByInventoryItem(inventoryItemInstance, params)
44        def inventoryMovementListTotal = InventoryMovement.countByInventoryItem(inventoryItemInstance)
45
46        [ inventoryMovementList: inventoryMovementList,
47            inventoryMovementListTotal:  inventoryMovementListTotal,
48            inventoryItemInstance: inventoryItemInstance]
49    }
50
51    def delete = {
52        def result = inventoryMovementService.reverseMove(params)
53
54        if(!result.error) {
55            flash.message = "InventoryMovement ${params.id} deleted"
56            redirect(controller:"taskDetailed", action:"show", id:result.taskId)
57        }
58        else {
59            if(result.inventoryMovementInstance) {
60                render(view:'show',model:[inventoryMovementInstance:result.inventoryMovementInstance.attach()])
61            }
62            else {
63                flash.message = "Could not delete inventory movement."
64                redirect(controller:"taskDetailed", action:"search")
65            }
66        }
67    }
68
69    def create = {
70        def inventoryMovementInstance = new InventoryMovement()
71        inventoryMovementInstance.properties = params
72        def inventoryMovementTypeList = InventoryMovementType.withCriteria { gt("id", 1L) } // Don't include "Used".
73
74        return ['inventoryMovementInstance': inventoryMovementInstance,
75                        inventoryMovementTypeList: inventoryMovementTypeList]
76    }
77
78    /**
79    * Handles all inventory movements except those of type "Used".
80     * The "Used" type is handled directly by InventoryItemDetailedController and useInventoryItem.
81    */
82    def save = {
83        def result = inventoryMovementService.move(params)
84
85        if(!result.error) {
86            flash.message = "Inventory Movement for ${result.inventoryMovementInstance.inventoryItem.name} created."
87            if(result.taskId) {
88                redirect(controller:"taskDetailed", action:"show", id: result.taskId)
89                return
90            }
91            redirect(controller:"inventoryItemDetailed", action:"show", id: result.inventoryMovementInstance.inventoryItem.id)
92        }
93        else {
94            if(result.inventoryMovementInstance) {
95                def inventoryMovementTypeList = InventoryMovementType.withCriteria { gt("id", 1L) } // Don't include "Used".
96                render(view:'create', model:[inventoryMovementInstance: result.inventoryMovementInstance,
97                                                            inventoryMovementTypeList: inventoryMovementTypeList])
98            }
99            else {
100                flash.message = "Could not create inventory movement."
101                redirect(controller:"taskDetailed", action:"search", id:result.taskId)
102            }
103
104        }
105    }
106
107}
Note: See TracBrowser for help on using the repository browser.