source: trunk/grails-app/services/InventoryItemService.groovy @ 225

Last change on this file since 225 was 225, checked in by gav, 10 years ago

Complete inventory movement implementation as per ticket #24.
Refactor showTab function in both Task and Inventory (which now has tabs).

File size: 1.8 KB
Line 
1/**
2* Provides a service class for the InventoryItem domain class.
3*/
4class 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
Note: See TracBrowser for help on using the repository browser.