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

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

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

File size: 4.1 KB
RevLine 
[175]1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3class InventoryMovementDetailedController extends BaseController {
4
[177]5    def inventoryMovementService
6
[175]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
[224]27    /**
28    * List the inventory movements for an InventoryItem.
[226]29    * @param params.inventoryItem.id The id of an existing inventory item.
[224]30    */
31    def listInventoryMovements = {
[226]32        def inventoryItemInstance = InventoryItem.get(params.inventoryItem.id)
[224]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
[175]48    def delete = {
[177]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) {
[205]57                render(view:'show',model:[inventoryMovementInstance:result.inventoryMovementInstance.attach()])
[175]58            }
[177]59            else {
60                flash.message = "Could not delete inventory movement."
[191]61                redirect(controller:"taskDetailed", action:"search")
[175]62            }
63        }
64    }
65
66    def create = {
67        def inventoryMovementInstance = new InventoryMovement()
68        inventoryMovementInstance.properties = params
[226]69        def inventoryMovementTypeList = InventoryMovementType.withCriteria { gt("id", 1L) } // Don't include "Used".
70
71        return ['inventoryMovementInstance': inventoryMovementInstance,
72                        inventoryMovementTypeList: inventoryMovementTypeList]
[175]73    }
74
[226]75    /**
76    * Handles all inventory movements except those of type "Used".
77     * The "Used" type is handled directly by InventoryItemDetailedController and useInventoryItem.
78    */
[175]79    def save = {
[177]80        def result = inventoryMovementService.move(params)
81
82        if(!result.error) {
83            flash.message = "Inventory Movement for ${result.inventoryMovementInstance.inventoryItem.name} created."
[226]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)
[175]89        }
90        else {
[177]91            if(result.inventoryMovementInstance) {
[226]92                def inventoryMovementTypeList = InventoryMovementType.withCriteria { gt("id", 1L) } // Don't include "Used".
93                render(view:'create', model:[inventoryMovementInstance: result.inventoryMovementInstance,
94                                                            inventoryMovementTypeList: inventoryMovementTypeList])
[177]95            }
96            else {
97                flash.message = "Could not create inventory movement."
98                redirect(controller:"taskDetailed", action:"search", id:result.taskId)
99            }
100
[175]101        }
102    }
[177]103
[175]104}
Note: See TracBrowser for help on using the repository browser.