- Timestamp:
- Sep 6, 2010, 2:40:39 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.