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

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

Complete functionality for inventory movement types other than "Used".

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