Changeset 646 for trunk/grails-app/services
- Timestamp:
- Sep 6, 2010, 2:40:39 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/InventoryItemSearchService.groovy
r629 r646 1 import net.kromhouts.HqlBuilder 1 2 import grails.orm.PagedResultList 2 3 import org.compass.core.engine.SearchEngineQueryParseException … … 104 105 } // createCriteria 105 106 } // getInventoryBelowReorder 107 108 /** 109 * Search for inventory items that are below reorder point. 110 * @param params The request params. 111 * @param locale The locale to use when generating result.message. 112 */ 113 def getReorderSearch(params, locale) { 114 def result = [:] 115 116 def getMessage = { Map m -> 117 messageSource.getMessage(m.code, m.args == null ? null : m.args.toArray(), locale) 118 } 119 120 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 121 params.offset = params?.offset?.toInteger() ?: 0 122 123 def sort = "inventoryItem." + (params?.sort ?: "name") 124 def order = params?.order == "desc" ? "desc" : "asc" 125 126 def q = new HqlBuilder(max: params.max, offset: params.offset).query { 127 select 'count(distinct inventoryItem) as inventoryItemCount' 128 from 'InventoryItem as inventoryItem', 129 'left join inventoryItem.alternateSuppliers as alternateSupplier' 130 where 'inventoryItem.unitsInStock <= inventoryItem.reorderPoint' 131 and 'inventoryItem.isActive = true' 132 and 'inventoryItem.isObsolete = false' 133 134 if(!params.includeReorderListingDisabled) 135 and "inventoryItem.enableReorderListing = true" 136 137 if(params.selectedSupplier?.isLong()) { 138 namedParams.supplier = Supplier.get(params.selectedSupplier.toLong()) 139 if(params.includeAlternateSuppliers) 140 and "(inventoryItem.preferredSupplier = :supplier or alternateSupplier = :supplier)" 141 else 142 and "inventoryItem.preferredSupplier = :supplier" 143 } // if selectedSupplier 144 145 if(params.selectedGroups) { 146 namedParams.selectedGroupIds = params.selectedGroups 147 and "inventoryItem.inventoryGroup.id in(:selectedGroupIds)" 148 } 149 150 if(!params.includeOnBackOrder) { 151 // Sub query! 152 def onBackOrder = new HqlBuilder().query { 153 from "InventoryItemPurchase p" 154 where "p.inventoryItem = inventoryItem" 155 and "p.inventoryItem = inventoryItem" 156 and "p.inventoryItemPurchaseType.id = 1" // Order Placed. 157 and "p.receivedComplete = false" 158 } 159 160 and "not exists ($onBackOrder.query)" 161 } 162 163 } // query 164 165 def totalCount = InventoryItem.executeQuery(q.query, q.namedParams)[0].toInteger() 166 167 q.select = 'distinct inventoryItem' 168 q.order = "by $sort $order, inventoryItem.id asc" 169 def list = InventoryItem.executeQuery(q.query, q.namedParams, q.paginateParams) 170 171 result.inventoryItemList = new PagedResultList(list, totalCount) 172 173 // Get the result message. 174 if(result.inventoryItemList.totalCount > 0) 175 result.message = getMessage(code:"inventoryItem.search.text.below.reorder.description") 176 else 177 result.message = getMessage(code:"inventoryItem.search.text.below.reorder.none.found") 178 179 // Success. 180 return result 181 182 } // getReorderSearch 106 183 107 184 /**
Note: See TracChangeset
for help on using the changeset viewer.