Changeset 668 for trunk/grails-app/services/InventoryReportService.groovy
- Timestamp:
- Oct 1, 2010, 3:22:05 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.