Changeset 668


Ignore:
Timestamp:
Oct 1, 2010, 3:22:05 PM (14 years ago)
Author:
gav
Message:

New report: Inventory Value.

Location:
trunk
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/ReportController.groovy

    r654 r668  
    196196    } // equipmentRegister
    197197
     198    def inventoryValueGsp = {
     199        render(view: 'inventoryValue')
     200    }
     201
     202    def inventoryValue = {
     203
     204        params.reportTitle = "Inventory Value"
     205        params.logoUrl = grailsApplication.mainContext.getResource('images/logo.png').getURL()
     206        params.currentUser = authService.currentUser
     207
     208        def dataModel = inventoryReportService.getInventoryValue(params, RCU.getLocale(request))
     209
     210        // Jasper plugin controller expects data to be a Collection.
     211        chain(controller:'jasper', action:'index', model:[data: [dataModel]], params:params)
     212
     213    }
     214
    198215} // end of class.
  • trunk/grails-app/i18n/messages.properties

    r652 r668  
    437437report.error.no.inventory.items.found=Error: no inventory items found, please run report again.
    438438report.error.too.many.inventory.items=Error: over {0} inventory items, please run report again.
     439report.error.multiple.currency.found=Error: multiple currency found.
    439440
    440441#
  • trunk/grails-app/services/InventoryReportService.groovy

    r649 r668  
     1
     2import net.kromhouts.HqlBuilder
    13
    24/**
     
    164166    } // getStockTakeOverview()
    165167
     168    /**
     169    * Get the data for the inventory value.
     170    * @param params The request params, may contain params to specify the search.
     171    * @param locale The locale to use when generating result.message.
     172    */
     173    def getInventoryValue(params, locale) {
     174        def result = [:]
     175
     176        result.inventoryItemList = []
     177        result.inventoryItemCount = 0
     178        result.inventoryItemTotalValue = new BigDecimal(0)
     179        result.currency = null
     180        result.errorMessage = null
     181        result.summaryOfCalculationMethod = "This report does not convert between different currency.\n"
     182        result.summaryOfCalculationMethod += "Therefore all item's are checked to ensure that currency is the same."
     183
     184        result.site = Site.get(params.site.id.toLong())
     185        result.inventoryTypes = params.inventoryTypes.collect { InventoryType.get(it.toInteger()) }
     186        result.inventoryGroups = params.inventoryGroups.collect { InventoryGroup.get(it.toInteger()) }
     187
     188        def fail = { Map m ->
     189            result.error = [ code: m.code, args: m.args ]
     190            result.errorMessage = g.message(result.error)
     191            result.currency = null
     192            result.inventoryItemTotalValue = new BigDecimal(0)
     193            return result
     194        }
     195
     196        def q = new HqlBuilder().query {
     197            select 'distinct inventoryItem'
     198            from 'InventoryItem as inventoryItem',
     199                    'left join fetch inventoryItem.inventoryLocation as inventoryLocation',
     200                    'left join fetch inventoryLocation.inventoryStore as inventoryStore',
     201                    'left join fetch inventoryItem.unitOfMeasure as unitOfMeasure',
     202                    'left join fetch inventoryItem.picture as picture',
     203                    'left join fetch picture.images as Image'
     204            where 'inventoryItem.isActive = true'
     205                namedParams.siteId = result.site.id
     206                and 'inventoryStore.site.id = :siteId'
     207                if(result.inventoryTypes) {
     208                    namedParams.inventoryTypeIds = result.inventoryTypes.collect {it.id}
     209                    and 'inventoryItem.inventoryType.id in(:inventoryTypeIds)'
     210                }
     211                if(result.inventoryGroups) {
     212                    namedParams.inventoryGroupIds = result.inventoryGroups.collect {it.id}
     213                    and 'inventoryItem.inventoryGroup.id in(:inventoryGroupIds)'
     214                }
     215            order 'by inventoryItem.name asc'
     216        }
     217
     218        result.inventoryItemList = InventoryItem.executeQuery(q.query, q.namedParams)
     219        result.inventoryItemCount = result.inventoryItemList.size()
     220        result.currency = result.inventoryItemList[0]?.estimatedUnitPriceCurrency
     221
     222        for(inventoryItem in result.inventoryItemList) {
     223            // Check all currency is the same.
     224            if(result.currency != inventoryItem.estimatedUnitPriceCurrency) {
     225                fail(code:'report.error.multiple.currency.found') // No return, populate errors but continue report.
     226                break
     227            }
     228            result.inventoryItemTotalValue += inventoryItem.estimatedUnitPriceAmount * inventoryItem.unitsInStock
     229        } // for
     230
     231        // Success.
     232        return result
     233
     234    } // getInventoryValueByGroupAndType()
     235
    166236} // end class
  • trunk/grails-app/views/appCore/start.gsp

    r654 r668  
    196196                                    </tr>
    197197
     198                                    <tr class="prop">
     199                                        <td valign="top" class="name">
     200                                            <label>Inventory:</label>
     201                                        </td>
     202                                        <td valign="top" class="value">
     203                                                <g:link controller="report" action="inventoryValueGsp">
     204                                                    Inventory Value
     205                                                </g:link>
     206                                        </td>
     207                                    </tr>
     208
    198209                                </tbody>
    199210                            </table>
Note: See TracChangeset for help on using the changeset viewer.