Changeset 668 for trunk/grails-app
- Timestamp:
- Oct 1, 2010, 3:22:05 PM (14 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/ReportController.groovy
r654 r668 196 196 } // equipmentRegister 197 197 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 198 215 } // end of class. -
trunk/grails-app/i18n/messages.properties
r652 r668 437 437 report.error.no.inventory.items.found=Error: no inventory items found, please run report again. 438 438 report.error.too.many.inventory.items=Error: over {0} inventory items, please run report again. 439 report.error.multiple.currency.found=Error: multiple currency found. 439 440 440 441 # -
trunk/grails-app/services/InventoryReportService.groovy
r649 r668 1 2 import net.kromhouts.HqlBuilder 1 3 2 4 /** … … 164 166 } // getStockTakeOverview() 165 167 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 166 236 } // end class -
trunk/grails-app/views/appCore/start.gsp
r654 r668 196 196 </tr> 197 197 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 198 209 </tbody> 199 210 </table>
Note: See TracChangeset
for help on using the changeset viewer.