source: trunk/grails-app/controllers/InventoryItemPurchaseDetailedController.groovy @ 441

Last change on this file since 441 was 441, checked in by gav, 14 years ago

Add CostCode and InventoryItemPurchase domain classes with import features.
Includes some fixes to inventory imports, where manufacturer and supplier were crossed.

File size: 6.9 KB
Line 
1import org.codehaus.groovy.grails.plugins.springsecurity.Secured
2
3@Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager'])
4class InventoryItemPurchaseDetailedController extends BaseController {
5
6    def authService
7    def inventoryPurchaseService
8
9    def index = {
10        redirect(controller: 'inventoryItemDetailed', action:'search', params:params)
11    }
12
13    // the delete, save and update actions only accept POST requests
14    static allowedMethods = [delete:'POST', save:'POST', update:'POST']
15
16    def show = {
17        def inventoryItemPurchaseInstance = InventoryItemPurchase.read( params.id )
18
19        if(!inventoryItemPurchaseInstance) {
20            flash.message = "InventoryItemPurchase not found with id ${params.id}"
21            redirect(controller: 'inventoryItemDetailed', action:'search')
22        }
23        else { return [ inventoryItemPurchaseInstance : inventoryItemPurchaseInstance ] }
24    }
25
26    def delete = {
27        def result = inventoryPurchaseService.delete(params)
28
29        if(!result.error) {
30            flash.message = g.message(code: "default.delete.success", args: ["InventoryItemPurchase", params.id])
31            redirect(controller: 'inventoryItemDetailed',
32                            action: 'show',
33                            id: result.inventoryItemId,
34                            params: [showTab: "showPurchasingTab"])
35            return
36        }
37
38        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
39
40        if(result.error.code == "default.not.found") {
41            redirect(controller: 'inventoryItemDetailed', action: 'search')
42            return
43        }
44
45        redirect(action:show, id: params.id)
46    }
47
48    def edit = {
49        def result = inventoryPurchaseService.edit(params)
50
51        if(!result.error)
52            return [ inventoryItemPurchaseInstance : result.inventoryItemPurchaseInstance ]
53
54        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
55        redirect(controller: 'inventoryItemDetailed', action:'search', params:params)
56    }
57
58    def update = {
59        def result = inventoryPurchaseService.update(params)
60
61        if(!result.error) {
62            flash.message = g.message(code: "default.update.success", args: ["Inventory Purchase", params.id])
63            redirect(action:show, id: params.id)
64            return
65        }
66
67        if(result.error.code == "default.not.found") {
68            flash.message = g.message(code: result.error.code, args: result.error.args)
69            redirect(controller: 'inventoryItemDetailed', action:'search', params:params)
70            return
71        }
72
73        render(view:'edit', model:[inventoryItemPurchaseInstance: result.inventoryItemPurchaseInstance.attach()])
74    }
75
76    def create = {
77        def inventoryItemPurchaseInstance = new InventoryItemPurchase()
78        inventoryItemPurchaseInstance.properties = params
79
80        if(!inventoryItemPurchaseInstance.inventoryItem) {
81            flash.message = "Please select an inventory item then the 'purchasing' tab."
82            redirect(controller: 'inventoryItemDetailed', action: 'search')
83            return
84        }
85
86        return ['inventoryItemPurchaseInstance':inventoryItemPurchaseInstance]
87    }
88
89    def save = {
90        def result = inventoryPurchaseService.save(params)
91
92        if(!result.error) {
93            flash.message = g.message(code: "default.create.success", args: ["Inventory Purchase", ''])
94            redirect(controller: 'inventoryItemDetailed',
95                            action: 'show',
96                            id: result.inventoryItemId,
97                            params: [showTab: "showPurchasingTab"])
98            return
99        }
100
101        render(view:'create', model:['inventoryItemPurchaseInstance': result.inventoryItemPurchaseInstance])
102    }
103
104    def receive = {
105        def inventoryItemPurchaseInstance = InventoryItemPurchase.read( params.id )
106
107        if(!inventoryItemPurchaseInstance) {
108            flash.message = "InventoryItemPurchase not found with id ${params.id}"
109            redirect(controller: 'inventoryItemDetailed', action:'search')
110            return
111        }
112
113        inventoryItemPurchaseInstance.properties = params
114        def calcQuantities = inventoryPurchaseService.calcQuantities(inventoryItemPurchaseInstance)
115        inventoryItemPurchaseInstance.quantity = calcQuantities.thisOrderRemaining
116        return ['inventoryItemPurchaseInstance':inventoryItemPurchaseInstance,
117                        'orderId': inventoryItemPurchaseInstance.id]
118    }
119
120    def receiveSave = {
121        def result = inventoryPurchaseService.receiveSave(params)
122
123        if(!result.error) {
124            flash.message = g.message(code: "default.create.success", args: ["Inventory Purchase", ''])
125            redirect(controller: 'inventoryItemDetailed',
126                            action: 'show',
127                            id: result.inventoryItemId,
128                            params: [showTab: "showPurchasingTab"])
129            return
130        }
131
132        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
133
134        if(result.error.code == "default.not.found") {
135            redirect(controller: 'inventoryItemDetailed', action: 'search')
136            return
137        }
138
139        render(view:'receive',
140                        model:['inventoryItemPurchaseInstance': result.inventoryItemPurchaseInstance,
141                                    'orderId': result.orderId])
142    }
143
144    def approveInvoicePayment = {
145        def inventoryItemPurchaseInstance = InventoryItemPurchase.read( params.id )
146
147        if(!inventoryItemPurchaseInstance) {
148            flash.message = "InventoryItemPurchase not found with id ${params.id}"
149            redirect(controller: 'inventoryItemDetailed', action:'search')
150            return
151        }
152
153        inventoryItemPurchaseInstance.properties = params
154        return ['inventoryItemPurchaseInstance':inventoryItemPurchaseInstance,
155                        'orderId': inventoryItemPurchaseInstance.id]
156    }
157
158    def approveInvoicePaymentSave = {
159        def result = inventoryPurchaseService.approveInvoicePaymentSave(params)
160
161        if(!result.error) {
162            flash.message = g.message(code: "default.create.success", args: ["Inventory Purchase", ''])
163            redirect(controller: 'inventoryItemDetailed',
164                            action: 'show',
165                            id: result.inventoryItemId,
166                            params: [showTab: "showPurchasingTab"])
167            return
168        }
169
170        if(result.error.code == "default.not.found") {
171            flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
172            redirect(controller: 'inventoryItemDetailed', action: 'search')
173            return
174        }
175
176        render(view:'approveInvoicePayment',
177                    model:['inventoryItemPurchaseInstance': result.inventoryItemPurchaseInstance,
178                                    'orderId': result.orderId])
179    }
180}
Note: See TracBrowser for help on using the repository browser.