[175] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
| 2 | |
---|
| 3 | class 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 | |
---|
| 27 | def delete = { |
---|
[177] | 28 | def result = inventoryMovementService.reverseMove(params) |
---|
| 29 | |
---|
| 30 | if(!result.error) { |
---|
| 31 | flash.message = "InventoryMovement ${params.id} deleted" |
---|
| 32 | redirect(controller:"taskDetailed", action:"show", id:result.taskId) |
---|
| 33 | } |
---|
| 34 | else { |
---|
| 35 | if(result.inventoryMovementInstance) { |
---|
| 36 | render(view:'show',model:[inventoryMovementInstance:result.inventoryMovementInstance]) |
---|
[175] | 37 | } |
---|
[177] | 38 | else { |
---|
| 39 | flash.message = "Could not delete inventory movement." |
---|
| 40 | redirect(controller:"taskDetailed", action:"search", id:result.taskId) |
---|
[175] | 41 | } |
---|
| 42 | } |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | def create = { |
---|
| 46 | if(!params.task?.id) { |
---|
| 47 | flash.message = "Please select a task, then the Inventory tab." |
---|
| 48 | redirect(controller:"taskDetailed", action:"search") |
---|
| 49 | } |
---|
| 50 | def inventoryMovementInstance = new InventoryMovement() |
---|
| 51 | inventoryMovementInstance.properties = params |
---|
| 52 | return ['inventoryMovementInstance':inventoryMovementInstance] |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | def save = { |
---|
[177] | 56 | def result = inventoryMovementService.move(params) |
---|
| 57 | |
---|
| 58 | if(!result.error) { |
---|
| 59 | flash.message = "Inventory Movement for ${result.inventoryMovementInstance.inventoryItem.name} created." |
---|
| 60 | redirect(controller:"taskDetailed", action:"show", id: result.taskId) |
---|
[175] | 61 | } |
---|
| 62 | else { |
---|
[177] | 63 | if(result.inventoryMovementInstance) { |
---|
| 64 | render(view:'create',model:[inventoryMovementInstance:result.inventoryMovementInstance]) |
---|
| 65 | } |
---|
| 66 | else { |
---|
| 67 | flash.message = "Could not create inventory movement." |
---|
| 68 | redirect(controller:"taskDetailed", action:"search", id:result.taskId) |
---|
| 69 | } |
---|
| 70 | |
---|
[175] | 71 | } |
---|
| 72 | } |
---|
[177] | 73 | |
---|
[175] | 74 | } |
---|