Changeset 547 for trunk/grails-app


Ignore:
Timestamp:
May 26, 2010, 3:50:50 AM (14 years ago)
Author:
gav
Message:

Improvements to Inventory Stock Take reports, MSSQL does not like using distinct the way it was, also improved protection against too many results.

Location:
trunk/grails-app
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/i18n/messages.properties

    r546 r547  
    315315
    316316# Reports
     317report.too.many.results.warning=Warning over {0} results, please run report again.
    317318report.stock.take.overview=Stock Take (Overview)
    318319report.stock.take.overview.help=Use this report to manage inventory stock take. Use in conjunction with the Stock Take (By Location) report.
  • trunk/grails-app/services/InventoryReportService.groovy

    r546 r547  
    1313    def g = new org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib()
    1414
    15 //     def paramsMax = 100000
     15    def paramsMax = 250
    1616
    1717    /**
     
    6161        result.locations = result.locations.collect {it.trim()}
    6262
     63        def paginateParams = [:]
     64        paginateParams.max = Math.min(params?.max?.toInteger() ?: paramsMax, paramsMax)
     65
    6366        def namedParams = [:]
    6467        namedParams.locationList = [null] // null protects against HQL unexpected end of subtree exception with an empty list.
     
    7174        }
    7275
     76        // Return the actual locations as a string.
     77        if(namedParams.locationList.size() > 1)
     78            result.locations = namedParams.locationList[1..-1].toString()[1..-2]
     79        else
     80            result.locations = g.message(code: 'default.none.text')
     81
     82        // Inventory List.
     83        result.inventoryListQuery = "from InventoryItem as inventoryItem \
     84                                                        left join inventoryItem.inventoryLocation as inventoryLocation \
     85                                                        where (inventoryItem.isActive = true \
     86                                                                    and  inventoryItem.inventoryLocation in (:locationList) \
     87                                                                    ) "
     88
     89        result.inventoryCountQuery = "select count(distinct inventoryItem) " + result.inventoryListQuery
     90        result.inventoryItemCount = InventoryItem.executeQuery(result.inventoryCountQuery, namedParams)[0]
     91
     92        // Exit if too many results.
     93        result.countWarning = null
     94        if(result.inventoryItemCount > paramsMax) {
     95            result.countWarning = g.message(code: 'report.too.many.results.warning',
     96                                                                    args: [paramsMax],
     97                                                                    default: "Warning over ${paramsMax} results, please run report again!")
     98            result.inventoryItemList = []
     99            return result
     100        }
     101
     102        result.inventoryListQuery = "select distinct inventoryItem " + result.inventoryListQuery
     103        def inventoryList = InventoryItem.executeQuery(result.inventoryListQuery, namedParams, paginateParams)
     104
     105        // Reset namedParams for next query.
     106        namedParams = [:]
     107        namedParams.inventoryList = inventoryList
     108
    73109        // Note: HQL docs advise not using fetch aliases in where clause (or any other clause).
    74110        // Access is via the parent object, however that does not work for the order by clause in this case.
     
    79115                                        left join fetch inventoryItem.picture as picture \
    80116                                        left join fetch picture.images as Image \
    81                                         where (inventoryItem.isActive = true \
    82                                                     and  inventoryItem.inventoryLocation in (:locationList) \
     117                                        where (inventoryItem in (:inventoryList) \
    83118                                                    ) \
    84119                                        order by inventoryStore.name, inventoryLocation.name"
    85120
    86         result.query = "select distinct inventoryItem " + result.query
    87         result.queryResult = InventoryLocation.executeQuery(result.query, namedParams)
    88         result.inventoryItemCount = result.queryResult.size()
    89 
    90         // Return the actual locations as a string.
    91         if(namedParams.locationList.size() > 1)
    92             result.locations = namedParams.locationList[1..-1].toString()[1..-2]
    93         else
    94             result.locations = g.message(code: 'default.none.text')
    95 
    96         result.inventoryItemList = result.queryResult
     121        result.query = "select inventoryItem " + result.query
     122        result.inventoryItemList = InventoryItem.executeQuery(result.query, namedParams, paginateParams)
    97123
    98124        // Success.
  • trunk/grails-app/views/inventoryItemPurchaseDetailed/edit.gsp

    r518 r547  
    4040                       
    4141                            <tr class="prop">
    42                                 <td valign="top" class="name">Purchase Order Number:</td>
    43                                
    44                                 <td valign="top" class="value">${fieldValue(bean:inventoryItemPurchaseInstance, field:'purchaseOrderNumber')}</td>
    45                                
     42                                <td valign="top" class="name">
     43                                    <label for="invoiceNumber">Purchase Order Number:</label>
     44                                </td>
     45                                <td valign="top" class="value ${hasErrors(bean:inventoryItemPurchaseInstance,field:'purchaseOrderNumber','errors')}">
     46                                    <input type="text" maxlength="50" id="purchaseOrderNumber" name="purchaseOrderNumber" value="${fieldValue(bean:inventoryItemPurchaseInstance,field:'purchaseOrderNumber')}"/>
     47                                </td>
    4648                            </tr>
    4749                       
     
    139141                            </tr>
    140142                       
     143                            <tr class="prop">
     144                                <td valign="top" class="name">
     145                                    <label for="comment">Comment:</label>
     146                                </td>
     147                                <td valign="top" class="value ${hasErrors(bean:inventoryItemPurchaseInstance,field:'comment','errors')}">
     148                                    <textarea rows="5" cols="40" name="comment">${fieldValue(bean:inventoryItemPurchaseInstance, field:'comment')}</textarea>
     149                                </td>
     150                            </tr>
     151                       
    141152                        </tbody>
    142153                    </table>
Note: See TracChangeset for help on using the changeset viewer.