- Timestamp:
- Sep 6, 2010, 2:40:39 AM (14 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/conf/Config.groovy
r637 r646 209 209 [order:20, controller:'inventoryItemDetailed', title:'Create', action:'create', isVisible: { true }], 210 210 [order:90, controller:'inventoryItemDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }], 211 [order:91, controller:'inventoryItemDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }] 211 [order:91, controller:'inventoryItemDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }], 212 [order:91, controller:'inventoryItemDetailed', title:'Reorder', action:'reorder', isVisible: { params.action == 'reorder' }] 212 213 ] 213 214 ], -
trunk/grails-app/controllers/InventoryItemDetailedController.groovy
r635 r646 34 34 } 35 35 forward(action: 'search', params: params) 36 } 37 38 /** 39 * Set session.inventoryItemReorderSearchParamsMax 40 */ 41 @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager', 'ROLE_InventoryUser']) 42 def setReorderSearchParamsMax = { 43 def max = 1000 44 if(params.newMax?.isInteger()) { 45 def i = params.newMax.toInteger() 46 if(i > 0 && i <= max) 47 session.inventoryItemReorderSearchParamsMax = params.newMax 48 if(i > max) 49 session.inventoryItemReorderSearchParamsMax = max 50 } 51 forward(action: 'reorder', params: params) 36 52 } 37 53 … … 542 558 } 543 559 560 /** 561 * Search for Inventory items that require reorder. 562 */ 563 @Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager']) 564 def reorder = { 565 566 // In the case of an actionSubmit button, rewrite action name from 'index'. 567 if(params._action_reorder) 568 params.action='reorder' 569 570 if(session.inventoryItemReorderSearchParamsMax) 571 params.max = session.inventoryItemReorderSearchParamsMax 572 573 def inventoryItemInstanceList = [] 574 def inventoryItemInstanceTotal 575 def filterParams = params 576 def suppliers = Supplier.findAllByIsActive(true).sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) } 577 def inventoryGroups = InventoryGroup.findAllByIsActive(true) 578 if(!params.selectedGroups) 579 params.selectedGroups = inventoryGroups.collect{it.id} 580 else 581 params.selectedGroups = params.selectedGroups.collect { it.toLong() } 582 583 // Restore search unless a new search is being requested. 584 if(!params.newSearch && !params.quickSearch) { 585 if(session.reorderSearchSelectedGroups) { 586 params.selectedGroups = session.reorderSearchSelectedGroups 587 params.selectedSupplier = session.reorderSearchSelectedSupplier 588 params.includeAlternateSuppliers = session.reorderSearchIncludeAlternateSuppliers 589 params.includeReorderListingDisabled = session.reorderSearchIncludeReorderListingDisabled 590 params.includeOnBackOrder = session.reorderSearchIncludeOnBackOrder 591 } 592 else if(session.inventoryItemReorderQuickSearch) { 593 params.quickSearch = session.inventoryItemReorderQuickSearch 594 if(session.inventoryItemReorderQuickSearchDaysBack) 595 params.daysBack = session.inventoryItemReorderQuickSearchDaysBack.toString() 596 } 597 } 598 599 // Remember sort if supplied, otherwise try to restore. 600 if(params.sort && params.order) { 601 session.inventoryItemReorderSearchSort = params.sort 602 session.inventoryItemReorderSearchOrder = params.order 603 } 604 else if(session.inventoryItemReorderSearchSort && session.inventoryItemReorderSearchOrder) { 605 params.sort = session.inventoryItemReorderSearchSort 606 params.order = session.inventoryItemReorderSearchOrder 607 } 608 609 if(params.quickSearch) { 610 // Quick Search Links: 611 if(!params.quickSearch) params.quickSearch = "inventoryBelowReorder" 612 def result = inventoryItemSearchService.getQuickSearch(params, RCU.getLocale(request)) 613 inventoryItemInstanceList = result.inventoryItemList 614 inventoryItemInstanceTotal = result.inventoryItemList.totalCount 615 params.message = result.message 616 filterParams.quickSearch = result.quickSearch 617 // Remember search. 618 session.inventoryItemReorderQuickSearch = result.quickSearch 619 if(result.daysBack) 620 session.inventoryItemReorderQuickSearchDaysBack = result.daysBack 621 // Clear any previous search. 622 session.removeAttribute("reorderSearchSelectedGroups") 623 session.removeAttribute("reorderSearchSelectedSupplier") 624 session.removeAttribute("reorderSearchIncludeAlternateSuppliers") 625 session.removeAttribute("reorderSearchIncludeReorderListingDisabled") 626 session.removeAttribute("reorderSearchIncludeOnBackOrder") 627 } 628 else { 629 // Reorder Search: 630 def result = inventoryItemSearchService.getReorderSearch(params, RCU.getLocale(request)) 631 inventoryItemInstanceList = result.inventoryItemList 632 inventoryItemInstanceTotal = result.inventoryItemList.totalCount 633 params.message = result.message 634 // Place limit search selects in filterParams for pagination. 635 if(params.selectedGroups) { 636 filterParams.selectedGroups = params.selectedGroups 637 filterParams.selectedSupplier = params.selectedSupplier 638 filterParams.includeAlternateSuppliers = params.includeAlternateSuppliers 639 filterParams.includeReorderListingDisabled = params.includeReorderListingDisabled 640 filterParams.includeOnBackOrder = params.includeOnBackOrder 641 } 642 // Remember search. 643 session.reorderSearchSelectedGroups = params.selectedGroups 644 session.reorderSearchSelectedSupplier = params.selectedSupplier 645 session.reorderSearchIncludeAlternateSuppliers = params.includeAlternateSuppliers 646 session.reorderSearchIncludeReorderListingDisabled = params.includeReorderListingDisabled 647 session.reorderSearchIncludeOnBackOrder = params.includeOnBackOrder 648 // Clear any previous search. 649 session.removeAttribute("inventoryItemReorderQuickSearch") 650 session.removeAttribute("inventoryItemReorderQuickSearchDaysBack") 651 } 652 653 // export plugin: 654 if(params?.format && params.format != "html") { 655 656 def dateFmt = { date -> 657 formatDate(format: "EEE, dd-MMM-yyyy", date: date) 658 } 659 660 String title 661 if(params.quickSearch) 662 title = params.message 663 else 664 title = "Filtered Inventory List." 665 666 response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] 667 response.setHeader("Content-disposition", "attachment; filename=Inventory.${params.extension}") 668 List fields = ["name", 669 "description", 670 "inventoryGroup", 671 "unitsInStock", 672 "reorderPoint", 673 "unitOfMeasure", 674 "inventoryLocation", 675 "inventoryLocation.inventoryStore"] 676 Map labels = ["name": "Name", 677 "description": "Description", 678 "inventoryGroup": "Group", 679 "unitsInStock":"In Stock", 680 "reorderPoint":"Reorder Point", 681 "unitOfMeasure": "UOM", 682 "inventoryLocation": "Location", 683 "inventoryLocation.inventoryStore": "Store"] 684 685 Map formatters = [:] 686 Map parameters = [title: title, separator: ","] 687 688 exportService.export(params.format, 689 response.outputStream, 690 inventoryItemInstanceList.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }, 691 fields, 692 labels, 693 formatters, 694 parameters) 695 } 696 697 // Add some basic params to filterParams. 698 filterParams.max = params.max 699 filterParams.offset = params.offset?.toInteger() ?: 0 700 filterParams.sort = params.sort ?: "name" 701 filterParams.order = params.order ?: "asc" 702 703 return[ inventoryItemInstanceList: inventoryItemInstanceList, 704 inventoryItemInstanceTotal: inventoryItemInstanceTotal, 705 filterParams: filterParams, 706 params: params, 707 inventoryGroups: inventoryGroups, 708 suppliers: suppliers] 709 } // end reorder() 710 544 711 } // end of class -
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.