Ignore:
Timestamp:
Jun 11, 2010, 2:00:04 PM (14 years ago)
Author:
gav
Message:

Improvements to purchasing, calculate remaining value amounts.

File:
1 edited

Legend:

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

    r441 r596  
    1010    * Calulates the quantities for an inventoryItem and purchaseOrderNumber.
    1111    * @param order An inventory puchase that was the source of the order.
    12     * @returns A result map contianing the totalOrdered, totalReceived, totalRemaining, thisOrderRemaining.
     12    * @returns A result map containing the totalOrdered, totalReceived, totalRemaining, thisOrderRemaining,
     13    *                 totalOrderedAmount, totalReceivedAmount, totalRemainingAmount, thisOrderRemainingAmount.
    1314    */
    1415    def calcQuantities(order) {
     
    1718
    1819        result.totalOrdered = 0
     20        result.totalOrderedAmount = 0
    1921        InventoryItemPurchase.withCriteria {
    2022            eq("inventoryItem", order.inventoryItem)
     
    2527        }.each() {
    2628            result.totalOrdered += it.quantity
     29            result.totalOrderedAmount += it.orderValueAmount
    2730        }
    2831
    2932        result.totalReceived = 0
     33        result.totalReceivedAmount = 0
    3034        InventoryItemPurchase.withCriteria {
    3135            eq("inventoryItem", order.inventoryItem)
     
    3943        }.each() {
    4044            result.totalReceived += it.quantity
     45            result.totalReceivedAmount += it.orderValueAmount
    4146        }
    4247
     
    4752            result.totalRemaining = 0
    4853
     54        result.totalRemainingAmount
     55        if(result.totalOrderedAmount > result.totalReceivedAmount)
     56            result.totalRemainingAmount = result.totalOrderedAmount - result.totalReceivedAmount
     57        else
     58            result.totalRemainingAmount = 0
     59
    4960        result.thisOrderRemaining
    5061        if(result.totalRemaining > order.quantity)
     
    5263        else
    5364            result.thisOrderRemaining = result.totalRemaining
     65
     66        result.thisOrderRemainingAmount
     67        if(result.totalRemainingAmount > order.orderValueAmount)
     68            result.thisOrderRemainingAmount = order.orderValueAmount
     69        else
     70            result.thisOrderRemainingAmount = result.totalRemainingAmount
    5471
    5572        return result
     
    254271            if(result.inventoryItemPurchaseInstance.quantity)
    255272                calcQuantities.totalReceived += result.inventoryItemPurchaseInstance.quantity
     273            if(result.inventoryItemPurchaseInstance.orderValueAmount)
     274                calcQuantities.totalReceivedAmount += result.inventoryItemPurchaseInstance.orderValueAmount
    256275
    257276            if(calcQuantities.totalReceived >= calcQuantities.totalOrdered) {
Note: See TracChangeset for help on using the changeset viewer.