Ignore:
Timestamp:
Mar 16, 2010, 12:00:04 PM (10 years ago)
Author:
gav
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/InventoryItemService.groovy

    r425 r441  
    2828    def show(params) {
    2929        def result = [:]
     30
    3031        def fail = { Map m ->
    3132            result.error = [ code: m.code, args: ["InventoryItem", params.id] ]
     
    3738        if(!result.inventoryItemInstance)
    3839            return fail(code:"default.not.found")
     40
     41        def p = [:]
     42
     43        if(params.paginate == "purchases") {
     44            params.showTab = "showPurchasingTab"
     45            p.max = Math.min(params.max?.toInteger() ?: 10, 100)
     46            p.offset = params.offset?.toInteger() ?: 0
     47            p.sort = params.sort ?: null
     48            p.order = params.order ?: null
     49        }
     50        else {
     51            p.max = 10
     52            p.offset = 0
     53        }
     54
     55        result.inventoryItemPurchasesTotal = InventoryItemPurchase.countByInventoryItem(result.inventoryItemInstance)
     56
     57        result.inventoryItemPurchases = InventoryItemPurchase.withCriteria {
     58                eq("inventoryItem", result.inventoryItemInstance)
     59                maxResults(p.max)
     60                firstResult(p.offset)
     61                // Sorting:
     62                // Default is to sort by order number then id.
     63                // When a sortable column is clicked then we sort by that.
     64                // If the sortable column clicked is order number then we add id as the second sort.
     65                if(p.sort && p.order) {
     66                    order(p.sort, p.order)
     67                    if(p.sort == "purchaseOrderNumber") order('id', 'asc')
     68                }
     69                else {
     70                    order('purchaseOrderNumber', 'desc')
     71                    order('id', 'asc')
     72                }
     73            }
    3974
    4075        result.showTab = [:]
     
    4681                result.showTab.movement =  new String("true")
    4782                break
     83            case "showPurchasingTab":
     84                result.showTab.purchasing =  new String("true")
     85                break
    4886            default:
    4987                result.showTab.inventory = new String("true")
    5088        }
    5189
    52         def p = [:]
    5390        p.max = result.inventoryMovementListMax = 10
     91        p.offset = 0
    5492        p.order = "desc"
    5593        p.sort = "id"
    5694        result.inventoryMovementList = InventoryMovement.findAllByInventoryItem(result.inventoryItemInstance, p)
    5795        result.inventoryMovementListTotal = InventoryMovement.countByInventoryItem(result.inventoryItemInstance)
     96
    5897
    5998        // Success.
Note: See TracChangeset for help on using the changeset viewer.