- Timestamp:
- May 28, 2010, 1:29:19 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/InventoryReportService.groovy
r547 r550 13 13 def g = new org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib() 14 14 15 // Protect java heap memory. 16 // Most likely want to set paramsMax and inClauseMax to the same values. 15 17 def paramsMax = 250 18 19 // At least with Oracle and MSSQL db limits are 1000 (in list) and 2000 (nodes) respectively. 20 // But 255 has also been mentioned on the internet as a possible limit for some databases. 21 def inClauseMax = 250 16 22 17 23 /** … … 52 58 def result = [:] 53 59 60 result.inventoryItemList = [] 61 result.inventoryItemCount = 0 62 result.locationCount = 0 63 result.errorMessage = null 54 64 result.summaryOfCalculationMethod = 'This report should be used in conjunction with the `Stock Take (Overview)` Report.' 55 65 56 // Sanitise the locations string and convert to a list. 66 def fail = { Map m -> 67 result.error = [ code: m.code, args: m.args ] 68 result.errorMessage = g.message(result.error) 69 result.locations = '' 70 return result 71 } 72 73 def paginateParams = [:] 74 paginateParams.max = Math.min(params?.max?.toInteger() ?: paramsMax, paramsMax) 75 76 def namedParams = [:] 77 namedParams.locationList = [] 78 79 // Sanitise the user supplied locations string and convert to a list. 57 80 result.locations = params.locationString.trim() 58 81 if(result.locations.startsWith('e.g:')) … … 61 84 result.locations = result.locations.collect {it.trim()} 62 85 63 def paginateParams = [:] 64 paginateParams.max = Math.min(params?.max?.toInteger() ?: paramsMax, paramsMax) 65 66 def namedParams = [:] 67 namedParams.locationList = [null] // null protects against HQL unexpected end of subtree exception with an empty list. 68 69 // Fill namedParams.locationList 70 result.locations.each() { 71 InventoryLocation.findAllByNameIlike(it).each() { 72 namedParams.locationList << it 86 // Fill namedParams.locationList. 87 result.locations.each() { location -> 88 if(namedParams.locationList.size() < paramsMax) { 89 // paramsMax+1 to ensure the too many locations check bellow is triggered. 90 namedParams.locationList += InventoryLocation.findAllByNameIlike(location, [max: paramsMax+1]) 73 91 } 92 namedParams.locationList.unique() 74 93 } 75 94 76 // Return the actual locations as a string. 77 if(namedParams.locationList.size() > 1) 78 result.locations = namedParams.locationList[1..-1].toString()[1..-2] 95 // Return the actual locations as a string, along with a count. 96 result.locationCount = namedParams.locationList.size() 97 if(result.locationCount > 0) { 98 result.locations = namedParams.locationList.toString()[1..-2] 99 } 79 100 else 80 101 result.locations = g.message(code: 'default.none.text') 102 103 // Exit if empty location list. 104 // Protects against HQL unexpected end of subtree exception with an empty list. 105 if(namedParams.locationList.isEmpty()) 106 return fail(code:'report.error.no.locations.found') 107 108 // Exit if IN clause list too big. 109 if(namedParams.locationList.size() > inClauseMax) 110 return fail(code:'report.error.too.many.locations', args: [inClauseMax]) 81 111 82 112 // Inventory List. … … 91 121 92 122 // 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 } 123 if(result.inventoryItemCount > paramsMax) 124 return fail(code:'report.error.too.many.results', args: [paramsMax]) 101 125 102 126 result.inventoryListQuery = "select distinct inventoryItem " + result.inventoryListQuery … … 107 131 namedParams.inventoryList = inventoryList 108 132 109 // Note: HQL docs advise not using fetch aliases in where clause (or any other clause). 133 // Exit if empty inventory list. 134 // Protects against HQL unexpected end of subtree exception with an empty list. 135 if(namedParams.inventoryList.isEmpty()) 136 return fail(code:'report.error.no.inventory.items.found') 137 138 // Exit if inventory list too big. 139 if(namedParams.inventoryList.size() > inClauseMax) 140 return fail(code:'report.error.too.many.inventory.items', args: [inClauseMax]) 141 142 // Note: HQL docs advise 'not using fetch aliases in where clause (or any other clause)'. 110 143 // Access is via the parent object, however that does not work for the order by clause in this case. 111 144 result.query = "from InventoryItem as inventoryItem \ … … 119 152 order by inventoryStore.name, inventoryLocation.name" 120 153 121 result.query = "select inventoryItem " + result.query154 result.query = "select distinct inventoryItem " + result.query 122 155 result.inventoryItemList = InventoryItem.executeQuery(result.query, namedParams, paginateParams) 123 156 -
trunk/web-app/reports/stockTakeByLocation.jrxml
r547 r550 5 5 <property name="ireport.zoom" value="1.0"/> 6 6 <property name="ireport.x" value="0"/> 7 <property name="ireport.y" value="0"/> 7 <property name="ireport.y" value="144"/> 8 <import value="java.util.*"/> 8 9 <import value="net.sf.jasperreports.engine.*"/> 9 <import value="java.util.*"/>10 10 <import value="net.sf.jasperreports.engine.data.*"/> 11 11 <style name="Crosstab Data Text" isDefault="false" hAlign="Center"/> … … 73 73 <parameter name="currentUser" class="java.lang.String"/> 74 74 <parameter name="logoUrl" class="java.lang.String"/> 75 <parameter name="startDateString" class="java.lang.String"/> 76 <parameter name="endDateString" class="java.lang.String"/> 77 <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false"> 78 <defaultValueExpression><![CDATA["C:\\Documents and Settings\\kromhoutg\\My Documents\\reports\\"]]></defaultValueExpression> 79 </parameter> 75 <parameter name="locationString" class="java.lang.String"/> 80 76 <queryString language="SQL"> 81 77 <![CDATA[]]> … … 85 81 <field name="inventoryItemCount" class="java.lang.Integer"/> 86 82 <field name="locations" class="java.lang.String"/> 87 <field name="countWarning" class="java.lang.String"/> 83 <field name="errorMessage" class="java.lang.String"/> 84 <field name="locationCount" class="java.lang.Integer"/> 88 85 <background> 89 86 <band splitType="Stretch"/> … … 105 102 <reportElement x="0" y="75" width="340" height="17"/> 106 103 <textElement textAlignment="Center" verticalAlignment="Middle" markup="none"/> 107 <textFieldExpression class="java.lang.String"><![CDATA[" Inventory Items: "+$F{inventoryItemCount}+", Locations: "+$F{locations}+"."]]></textFieldExpression>104 <textFieldExpression class="java.lang.String"><![CDATA["Total - Items: "+$F{inventoryItemCount}+", Locations: "+$F{locationCount}]]></textFieldExpression> 108 105 </textField> 109 106 <textField> 110 107 <reportElement mode="Opaque" x="400" y="4" width="382" height="46" isPrintWhenDetailOverflows="true" forecolor="#FF0000" backcolor="#FFCCCC"> 111 <printWhenExpression><![CDATA[$F{ countWarning} != null ? true:false]]></printWhenExpression>108 <printWhenExpression><![CDATA[$F{errorMessage} != null ? true:false]]></printWhenExpression> 112 109 </reportElement> 113 110 <textElement textAlignment="Center" verticalAlignment="Middle"> 114 111 <font size="12" isBold="true"/> 115 112 </textElement> 116 <textFieldExpression class="java.lang.String"><![CDATA[$F{ countWarning}]]></textFieldExpression>113 <textFieldExpression class="java.lang.String"><![CDATA[$F{errorMessage}]]></textFieldExpression> 117 114 </textField> 118 115 </band> … … 132 129 <jr:groupHeader groupName="group1"> 133 130 <jr:cell height="20" rowSpan="1"> 134 <textField >135 <reportElement x="0" y="0" width="1 27" height="20"/>131 <textField isStretchWithOverflow="true"> 132 <reportElement x="0" y="0" width="117" height="20"/> 136 133 <textElement verticalAlignment="Middle"> 137 134 <font size="12" isBold="true"/> … … 141 138 </jr:cell> 142 139 </jr:groupHeader> 143 <jr:columnHeader style="table_CH" height="20" rowSpan="1"/> 144 <jr:detailCell style="table_TD" height="51" rowSpan="1"> 145 <image> 146 <reportElement x="39" y="0" width="88" height="51"/> 140 <jr:columnHeader style="table_CH" height="20" rowSpan="1"> 141 <textField isStretchWithOverflow="true"> 142 <reportElement x="0" y="0" width="117" height="20"/> 143 <textElement verticalAlignment="Middle"> 144 <font isBold="true"/> 145 </textElement> 146 <textFieldExpression class="java.lang.String"><![CDATA[$F{inventoryLocation}.name]]></textFieldExpression> 147 </textField> 148 </jr:columnHeader> 149 <jr:detailCell style="table_TD" height="51" rowSpan="1"> 150 <image hAlign="Center" vAlign="Middle"> 151 <reportElement x="29" y="0" width="88" height="51"/> 147 152 <imageExpression class="java.awt.Image"><![CDATA[net.sf.jasperreports.engine.util.JRImageLoader.loadImage($F{picture}.images.first().data)]]></imageExpression> 148 153 </image> … … 151 156 <jr:column width="237"> 152 157 <jr:columnHeader style="table_CH" height="20" rowSpan="1"> 153 <textField >158 <textField isStretchWithOverflow="true"> 154 159 <reportElement x="0" y="0" width="237" height="20"/> 155 160 <textElement verticalAlignment="Middle"> … … 174 179 <jr:column width="104"> 175 180 <jr:columnHeader style="table_CH" height="20" rowSpan="1"> 176 <textField >181 <textField isStretchWithOverflow="true"> 177 182 <reportElement x="0" y="0" width="104" height="20"/> 178 183 <textElement textAlignment="Center" verticalAlignment="Middle"> … … 196 201 <jr:column width="90"> 197 202 <jr:columnHeader style="table_CH" height="20" rowSpan="1"> 198 <textField >203 <textField isStretchWithOverflow="true"> 199 204 <reportElement x="0" y="0" width="90" height="20"/> 200 205 <textElement textAlignment="Center" verticalAlignment="Middle"> … … 206 211 <jr:detailCell style="table_TD" height="51" rowSpan="1"> 207 212 <rectangle> 208 <reportElement x="5" y=" 8" width="80" height="35"/>213 <reportElement x="5" y="11" width="80" height="30"/> 209 214 </rectangle> 210 215 </jr:detailCell> … … 232 237 <jr:column width="139"> 233 238 <jr:columnHeader style="table_CH" height="20" rowSpan="1"> 234 <textField >239 <textField isStretchWithOverflow="true"> 235 240 <reportElement x="0" y="0" width="139" height="20"/> 236 241 <textElement verticalAlignment="Middle"> … … 326 331 <textFieldExpression class="java.lang.String"><![CDATA["Summary"]]></textFieldExpression> 327 332 </textField> 328 <textField >329 <reportElement x="0" y="60" width="782" height=" 309"/>333 <textField isStretchWithOverflow="true"> 334 <reportElement x="0" y="60" width="782" height="18"/> 330 335 <textElement/> 331 336 <textFieldExpression class="java.lang.String"><![CDATA[$F{summaryOfCalculationMethod}]]></textFieldExpression> 337 </textField> 338 <textField isStretchWithOverflow="true" pattern="dd-MMM-yyyy" isBlankWhenNull="true"> 339 <reportElement x="0" y="125" width="782" height="17"/> 340 <textElement verticalAlignment="Middle" markup="none"/> 341 <textFieldExpression class="java.lang.String"><![CDATA["Locations found: "]]></textFieldExpression> 342 </textField> 343 <textField isStretchWithOverflow="true" pattern="dd-MMM-yyyy" isBlankWhenNull="true"> 344 <reportElement x="14" y="143" width="768" height="17"/> 345 <textElement verticalAlignment="Middle" markup="none"/> 346 <textFieldExpression class="java.lang.String"><![CDATA[$F{locations}+"."]]></textFieldExpression> 347 </textField> 348 <textField isStretchWithOverflow="true" pattern="dd-MMM-yyyy" isBlankWhenNull="true"> 349 <reportElement x="14" y="101" width="768" height="17"/> 350 <textElement verticalAlignment="Middle" markup="none"/> 351 <textFieldExpression class="java.lang.String"><![CDATA[$P{locationString}]]></textFieldExpression> 352 </textField> 353 <textField isStretchWithOverflow="true" pattern="dd-MMM-yyyy" isBlankWhenNull="true"> 354 <reportElement x="0" y="84" width="782" height="17"/> 355 <textElement verticalAlignment="Middle" markup="none"/> 356 <textFieldExpression class="java.lang.String"><![CDATA["Locations requested ('e.g:' is ignored and '%' is a wild card): "]]></textFieldExpression> 332 357 </textField> 333 358 </band>
Note: See TracChangeset
for help on using the changeset viewer.