Changeset 468


Ignore:
Timestamp:
Mar 30, 2010, 10:01:10 PM (14 years ago)
Author:
gav
Message:

Add inventory item purchase search view and logic.

Location:
trunk/grails-app
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/InventoryItemPurchaseDetailedController.groovy

    r441 r468  
    11import org.codehaus.groovy.grails.plugins.springsecurity.Secured
     2import org.codehaus.groovy.grails.commons.ConfigurationHolder
     3import com.zeddware.grails.plugins.filterpane.FilterUtils
    24
    35@Secured(['ROLE_AppAdmin', 'ROLE_Manager', 'ROLE_InventoryManager'])
     
    57
    68    def authService
     9    def filterService
     10    def exportService
     11    def dateUtilService
    712    def inventoryPurchaseService
    813
    914    def index = {
    10         redirect(controller: 'inventoryItemDetailed', action:'search', params:params)
     15        redirect(action:'search', params:params)
    1116    }
    1217
    1318    // the delete, save and update actions only accept POST requests
    1419    static allowedMethods = [delete:'POST', save:'POST', update:'POST']
     20
     21    def setSearchParamsMax = {
     22        def max = 1000
     23        if(params.newMax.isInteger()) {
     24            def i = params.newMax.toInteger()
     25            if(i > 0 && i <= max)
     26                session.inventoryItemPurchaseSearchParamsMax = params.newMax
     27            if(i > max)
     28                session.inventoryItemPurchaseSearchParamsMax = max
     29        }
     30        forward(action: 'search', params: params)
     31    }
     32
     33    def search = {
     34
     35        if(session.inventoryItemPurchaseSearchParamsMax)
     36            params.max = session.inventoryItemPurchaseSearchParamsMax
     37
     38        // Protect filterPane.
     39        params.max = Math.min( params.max ? params.max.toInteger() : 10,  1000 )
     40        params.offset = params.offset?.toInteger() ?: 0
     41        params.sort = params.sort ?: "purchaseOrderNumber"
     42        params.order = params.order ?: "desc"
     43
     44        def inventoryItemPurchaseList = []
     45        def inventoryItemPurchaseTotal
     46        def filterParams = [:]
     47
     48        // Quick Search:
     49        if(!FilterUtils.isFilterApplied(params)) {
     50
     51            if(params.quickSearch == "searchAllOrders") {
     52                inventoryItemPurchaseList = InventoryItemPurchase.findAllByInventoryItemPurchaseType(InventoryItemPurchaseType.read(1),
     53                                                                                                                                                                        [max:params.max,
     54                                                                                                                                                                        offset:params.offset,
     55                                                                                                                                                                        sort:params.sort,
     56                                                                                                                                                                        order:params.order])
     57                if(inventoryItemPurchaseList.size() > 0) { params.message = "All Orders." }
     58                else { params.message = "No orders found." }
     59            }
     60            else if(params.quickSearch == "searchAllReceived") {
     61                inventoryItemPurchaseList = InventoryItemPurchase.findAllByInventoryItemPurchaseTypeOrInventoryItemPurchaseType(InventoryItemPurchaseType.read(2),
     62                                                                                                                                                                                                                            InventoryItemPurchaseType.read(3),
     63                                                                                                                                                                                                                            [max:params.max,
     64                                                                                                                                                                                                                            offset:params.offset,
     65                                                                                                                                                                                                                            sort:params.sort,
     66                                                                                                                                                                                                                            order:params.order])
     67                if(inventoryItemPurchaseList.size() > 0) { params.message = "All Received Complete." }
     68                else { params.message = "No orders found." }
     69            }
     70            else {
     71                //Default:
     72                inventoryItemPurchaseList = InventoryItemPurchase.list(max:params.max,
     73                                                                                                                offset:params.offset,
     74                                                                                                                sort:params.sort,
     75                                                                                                                order:params.order)
     76                if(inventoryItemPurchaseList.size() > 0) { params.message = "All Purchases." }
     77                else { params.message = "No orders found." }
     78            }
     79
     80            inventoryItemPurchaseTotal = inventoryItemPurchaseList.size()
     81            filterParams.quickSearch = params.quickSearch
     82        }
     83        else {
     84            // filterPane:
     85            inventoryItemPurchaseList = filterService.filter( params, InventoryItemPurchase )
     86            inventoryItemPurchaseTotal = filterService.count( params, InventoryItemPurchase )
     87            filterParams = com.zeddware.grails.plugins.filterpane.FilterUtils.extractFilterParams(params)
     88        }
     89
     90        // export plugin:
     91        if(params?.format && params.format != "html") {
     92
     93            def dateFmt = { date ->
     94                formatDate(format: "EEE, dd-MMM-yyyy", date: date)
     95            }
     96
     97            String title
     98            if(params.quickSearch)
     99                title = "${params.quickSearch} inventory purchases."
     100            else
     101                title = "Filtered inventory purchases."
     102
     103            response.contentType = ConfigurationHolder.config.grails.mime.types[params.format]
     104            response.setHeader("Content-disposition", "attachment; filename=Purchases.${params.extension}")
     105            List fields = ["purchaseOrderNumber", "dateEntered", "costCode", "quantity", "orderValueAmount", "invoiceNumber",
     106                                    "inventoryItemPurchaseType"]
     107            Map labels = ["purchaseOrderNumber": "Order Number", "dateEntered": "Date", "costCode": "Cost Code",
     108                                    "quantity": "Quantity", "orderValueAmount": "Order \$", "invoiceNumber": "Invoice Number",
     109                                    "inventoryItemPurchaseType": "Type"]
     110            Map formatters = [ dateEntered: dateFmt]
     111            Map parameters = [title: title, separator: ","]
     112
     113            exportService.export(params.format, response.outputStream, inventoryItemPurchaseList, fields, labels, formatters, parameters)
     114        }
     115
     116        // Add some basic params to filterParams.
     117        filterParams.max = params.max
     118        filterParams.offset = params.offset?.toInteger() ?: 0
     119        filterParams.sort = params.sort ?: "purchaseOrderNumber"
     120        filterParams.order = params.order ?: "desc"
     121
     122        return[ inventoryItemPurchaseList: inventoryItemPurchaseList,
     123                inventoryItemPurchaseTotal: inventoryItemPurchaseTotal,
     124                filterParams: filterParams ]
     125
     126    } // end search()
    15127
    16128    def show = {
  • trunk/grails-app/controllers/TaskDetailedController.groovy

    r465 r468  
    4040            params.max = session.taskSearchParamsMax
    4141
    42         // TaskSearchService protects itself but filterPane does not.
     42        // Protect filterPane.
    4343        params.max = Math.min( params.max ? params.max.toInteger() : 10,  1000 )
    4444
  • trunk/grails-app/i18n/messages.properties

    r464 r468  
    257257fp.property.text.manufacturer.name=Manufacturer
    258258fp.property.text.estimatedUnitPriceAmount=Estimated Unit Price
     259
     260fp.property.text.inventoryItemPurchaseType.name=Type
  • trunk/grails-app/views/inventoryItemDetailed/search.gsp

    r450 r468  
    2525
    2626            <div class="paginateButtons">
     27                <span class="searchButtons">
     28                    <a href='' onclick="showElement('searchPane'); return false;">Quick</a>
     29                </span>
    2730                Results: ${inventoryItemInstanceList.size()} / ${inventoryItemInstanceTotal}
    2831                <span class="searchButtons">
     
    102105            </g:if>
    103106
    104             <div class="list">
    105                 <table>
    106                     <thead>
    107                         <tr>
    108 
    109                             <th>Picture</th>
    110                        
    111                                 <g:sortableColumn property="name" title="Name" params="${filterParams}" />
    112                        
    113                                 <g:sortableColumn property="description" title="Description" params="${filterParams}" />
    114                        
    115                             <g:sortableColumn property="unitsInStock" title="Units In Stock" params="${filterParams}" />
    116                            
    117                             <th>Unit Of Measure</th>
    118 
    119                             <th></th>
    120                        
    121                         </tr>
    122                     </thead>
    123                     <tbody>
    124                     <g:each in="${inventoryItemInstanceList}" status="i" var="inventoryItemInstance">
    125                         <tr class="${(i % 2) == 0 ? 'clickableOdd' : 'clickableEven'}" />
    126 
    127                             <td class='gallery'>
    128                                 <g:if test="${inventoryItemInstance.picture}" >
    129                                     <wa:pictureLightboxAnchor picture="${inventoryItemInstance.picture}"
    130                                                                                         size="${Image.Small}"
    131                                                                                         lightboxSize="${Image.Large}"
    132                                                                                         target="_blank"
    133                                                                                         title="Show Original" />
    134                                 </g:if>
    135                             </td>
    136                        
    137                             <td onclick='window.location = "${request.getContextPath()}/inventoryItemDetailed/show/${inventoryItemInstance.id}"' >
    138                                 ${fieldValue(bean:inventoryItemInstance, field:'name')}
    139                             </td>
    140                        
    141                             <td onclick='window.location = "${request.getContextPath()}/inventoryItemDetailed/show/${inventoryItemInstance.id}"' >
    142                                 ${fieldValue(bean:inventoryItemInstance, field:'description')}
    143                             </td>
    144                        
    145                             <td onclick='window.location = "${request.getContextPath()}/inventoryItemDetailed/show/${inventoryItemInstance.id}"' >
    146                                 ${fieldValue(bean:inventoryItemInstance, field:'unitsInStock')}
    147                             </td>
    148                        
    149                             <td onclick='window.location = "${request.getContextPath()}/inventoryItemDetailed/show/${inventoryItemInstance.id}"' >
    150                                 ${fieldValue(bean:inventoryItemInstance, field:'unitOfMeasure')}
    151                             </td>
    152 
    153                             <td>
    154                                 <g:link action="show" id="${inventoryItemInstance.id}">
    155                                     <img  src="${resource(dir:'images/skin',file:'database_go.png')}" alt="Show" />
    156                                 </g:link>
    157                             </td>
    158                        
    159                         </tr>
    160                     </g:each>
    161                     </tbody>
    162                 </table>
    163             </div>
     107            <g:if test="${inventoryItemInstanceList.size() > 0}">
     108                <div class="list">
     109                    <table>
     110                        <thead>
     111                            <tr>
     112
     113                                <th>Picture</th>
     114                           
     115                                <g:sortableColumn property="name" title="Name" params="${filterParams}" />
     116                           
     117                                <g:sortableColumn property="description" title="Description" params="${filterParams}" />
     118                           
     119                                <g:sortableColumn property="unitsInStock" title="Units In Stock" params="${filterParams}" />
     120                               
     121                                <th>Unit Of Measure</th>
     122
     123                                <th></th>
     124                           
     125                            </tr>
     126                        </thead>
     127                        <tbody>
     128                        <g:each in="${inventoryItemInstanceList}" status="i" var="inventoryItemInstance">
     129                            <tr class="${(i % 2) == 0 ? 'clickableOdd' : 'clickableEven'}" />
     130
     131                                <td class='gallery'>
     132                                    <g:if test="${inventoryItemInstance.picture}" >
     133                                        <wa:pictureLightboxAnchor picture="${inventoryItemInstance.picture}"
     134                                                                                            size="${Image.Small}"
     135                                                                                            lightboxSize="${Image.Large}"
     136                                                                                            target="_blank"
     137                                                                                            title="Show Original" />
     138                                    </g:if>
     139                                </td>
     140                           
     141                                <td onclick='window.location = "${request.getContextPath()}/inventoryItemDetailed/show/${inventoryItemInstance.id}"' >
     142                                    ${fieldValue(bean:inventoryItemInstance, field:'name')}
     143                                </td>
     144                           
     145                                <td onclick='window.location = "${request.getContextPath()}/inventoryItemDetailed/show/${inventoryItemInstance.id}"' >
     146                                    ${fieldValue(bean:inventoryItemInstance, field:'description')}
     147                                </td>
     148                           
     149                                <td onclick='window.location = "${request.getContextPath()}/inventoryItemDetailed/show/${inventoryItemInstance.id}"' >
     150                                    ${fieldValue(bean:inventoryItemInstance, field:'unitsInStock')}
     151                                </td>
     152                           
     153                                <td onclick='window.location = "${request.getContextPath()}/inventoryItemDetailed/show/${inventoryItemInstance.id}"' >
     154                                    ${fieldValue(bean:inventoryItemInstance, field:'unitOfMeasure')}
     155                                </td>
     156
     157                                <td>
     158                                    <g:link action="show" id="${inventoryItemInstance.id}">
     159                                        <img  src="${resource(dir:'images/skin',file:'database_go.png')}" alt="Show" />
     160                                    </g:link>
     161                                </td>
     162                           
     163                            </tr>
     164                        </g:each>
     165                        </tbody>
     166                    </table>
     167                </div>
     168            </g:if>
    164169            <div class="paginateButtons">
    165170                <g:paginate total="${inventoryItemInstanceTotal}" params="${filterParams}" />
     
    182187                                                                                ]}"/>
    183188        </div> <!-- end body div -->
     189
     190        <!-- Start Search Pane -->
     191        <div class="overlayPane" id="searchPane" style="display:none;">
     192            <h2>Quick Search</h2>
     193            <g:form method="post" id="searchForm" name="searchForm" >
     194                <table>
     195                    <tbody>
     196
     197                        <tr class="prop">
     198                            <td valign="top" class="name">
     199                                <label>Links:</label>
     200                            </td>
     201                            <td valign="top" class="value">
     202                                <g:link controller="inventoryItemPurchaseDetailed"
     203                                                action="search">
     204                                                Purchases
     205                                </g:link>
     206                                <br />
     207                            </td>
     208                        </tr>
     209
     210                    </tbody>
     211                </table>
     212                <div class="buttons">
     213                    <span class="button">
     214                        <input type="button" value="${g.message(code:'fp.tag.filterPane.button.cancel.text', default:'Cancel')}" onclick="return hideElement('searchPane');" />
     215                    </span>
     216                </div>
     217            </g:form>
     218        </div> <!-- end search pane -->
     219
    184220    </body>
    185221</html>
Note: See TracChangeset for help on using the changeset viewer.