[175] | 1 | import org.codehaus.groovy.grails.plugins.springsecurity.Secured |
---|
| 2 | |
---|
[298] | 3 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager']) |
---|
[175] | 4 | class InventoryMovementDetailedController extends BaseController { |
---|
| 5 | |
---|
[177] | 6 | def inventoryMovementService |
---|
| 7 | |
---|
[175] | 8 | // the delete, save and update actions only accept POST requests |
---|
| 9 | static allowedMethods = [delete:'POST', save:'POST'] |
---|
| 10 | |
---|
[298] | 11 | def index = { redirect(action:list,params:params) } |
---|
| 12 | |
---|
[175] | 13 | def list = { |
---|
| 14 | flash.message = flash.message |
---|
| 15 | redirect(controller:"taskDetailed", action:"search") |
---|
| 16 | } |
---|
| 17 | |
---|
[298] | 18 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager', 'ROLE_InventoryUser']) |
---|
[175] | 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 | |
---|
[224] | 29 | /** |
---|
| 30 | * List the inventory movements for an InventoryItem. |
---|
[226] | 31 | * @param params.inventoryItem.id The id of an existing inventory item. |
---|
[224] | 32 | */ |
---|
[298] | 33 | @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager', 'ROLE_InventoryUser']) |
---|
[224] | 34 | def listInventoryMovements = { |
---|
[226] | 35 | def inventoryItemInstance = InventoryItem.get(params.inventoryItem.id) |
---|
[224] | 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 | |
---|
[175] | 51 | def delete = { |
---|
[177] | 52 | def result = inventoryMovementService.reverseMove(params) |
---|
| 53 | |
---|
| 54 | if(!result.error) { |
---|
| 55 | flash.message = "InventoryMovement ${params.id} deleted" |
---|
[406] | 56 | if(result.taskId) |
---|
| 57 | redirect(controller:"taskDetailed", action:"show", id:result.taskId) |
---|
| 58 | redirect(controller:"inventoryItemDetailed", action:"show", id:result.inventoryItemInstance?.id) |
---|
[177] | 59 | } |
---|
| 60 | else { |
---|
| 61 | if(result.inventoryMovementInstance) { |
---|
[205] | 62 | render(view:'show',model:[inventoryMovementInstance:result.inventoryMovementInstance.attach()]) |
---|
[175] | 63 | } |
---|
[177] | 64 | else { |
---|
| 65 | flash.message = "Could not delete inventory movement." |
---|
[191] | 66 | redirect(controller:"taskDetailed", action:"search") |
---|
[175] | 67 | } |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | def create = { |
---|
| 72 | def inventoryMovementInstance = new InventoryMovement() |
---|
| 73 | inventoryMovementInstance.properties = params |
---|
[226] | 74 | def inventoryMovementTypeList = InventoryMovementType.withCriteria { gt("id", 1L) } // Don't include "Used". |
---|
| 75 | |
---|
| 76 | return ['inventoryMovementInstance': inventoryMovementInstance, |
---|
| 77 | inventoryMovementTypeList: inventoryMovementTypeList] |
---|
[175] | 78 | } |
---|
| 79 | |
---|
[226] | 80 | /** |
---|
| 81 | * Handles all inventory movements except those of type "Used". |
---|
| 82 | * The "Used" type is handled directly by InventoryItemDetailedController and useInventoryItem. |
---|
| 83 | */ |
---|
[175] | 84 | def save = { |
---|
[177] | 85 | def result = inventoryMovementService.move(params) |
---|
| 86 | |
---|
| 87 | if(!result.error) { |
---|
| 88 | flash.message = "Inventory Movement for ${result.inventoryMovementInstance.inventoryItem.name} created." |
---|
[226] | 89 | if(result.taskId) { |
---|
| 90 | redirect(controller:"taskDetailed", action:"show", id: result.taskId) |
---|
| 91 | return |
---|
| 92 | } |
---|
| 93 | redirect(controller:"inventoryItemDetailed", action:"show", id: result.inventoryMovementInstance.inventoryItem.id) |
---|
[175] | 94 | } |
---|
| 95 | else { |
---|
[177] | 96 | if(result.inventoryMovementInstance) { |
---|
[226] | 97 | def inventoryMovementTypeList = InventoryMovementType.withCriteria { gt("id", 1L) } // Don't include "Used". |
---|
| 98 | render(view:'create', model:[inventoryMovementInstance: result.inventoryMovementInstance, |
---|
| 99 | inventoryMovementTypeList: inventoryMovementTypeList]) |
---|
[177] | 100 | } |
---|
| 101 | else { |
---|
| 102 | flash.message = "Could not create inventory movement." |
---|
| 103 | redirect(controller:"taskDetailed", action:"search", id:result.taskId) |
---|
| 104 | } |
---|
| 105 | |
---|
[175] | 106 | } |
---|
| 107 | } |
---|
[177] | 108 | |
---|
[175] | 109 | } |
---|