1 | /** |
---|
2 | * Provides a service class for the InventoryItem domain class. |
---|
3 | */ |
---|
4 | class InventoryItemService { |
---|
5 | |
---|
6 | boolean transactional = false |
---|
7 | |
---|
8 | /** |
---|
9 | * Prepare the data for the show view. |
---|
10 | * The result can be used to easily construct the model for the show view. |
---|
11 | * @param params The incoming params as normally passed to the show view |
---|
12 | * primarily including the id of the inventoryItem. |
---|
13 | * @returns A map containing result.error=true (if any error) and result.inventoryItemInstance (if available) |
---|
14 | * and |
---|
15 | */ |
---|
16 | def prepareShowData(params) { |
---|
17 | def result = [:] |
---|
18 | |
---|
19 | def fail = { Object[] args -> |
---|
20 | if(args.size() == 2) result.errors = [args[0], args[1]] |
---|
21 | log.debug result.errors |
---|
22 | result.error = true |
---|
23 | return result |
---|
24 | } |
---|
25 | |
---|
26 | result.showTab = [:] |
---|
27 | switch (params.showTab) { |
---|
28 | case "showDetailTab": |
---|
29 | result.showTab.detail = new String("true") |
---|
30 | break |
---|
31 | case "showMovementTab": |
---|
32 | result.showTab.movement = new String("true") |
---|
33 | break |
---|
34 | default: |
---|
35 | result.showTab.inventory = new String("true") |
---|
36 | } |
---|
37 | |
---|
38 | result.inventoryItemInstance = InventoryItem.get( params.id ) |
---|
39 | |
---|
40 | if(!result.inventoryItemInstance) |
---|
41 | return fail("inventoryItem", "inventoryItem.notFound") |
---|
42 | |
---|
43 | log.debug "WTF are we doing here" |
---|
44 | |
---|
45 | def p = [:] |
---|
46 | p.max = result.inventoryMovementListMax = 10 |
---|
47 | p.order = "desc" |
---|
48 | p.sort = "id" |
---|
49 | result.inventoryMovementList = InventoryMovement.findAllByInventoryItem(result.inventoryItemInstance, p) |
---|
50 | result.inventoryMovementListTotal = InventoryMovement.countByInventoryItem(result.inventoryItemInstance) |
---|
51 | |
---|
52 | // Success |
---|
53 | return result |
---|
54 | |
---|
55 | } // end prepareShowData() |
---|
56 | |
---|
57 | } // end class |
---|