

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta name="layout" content="main" />
        <title>Edit InventoryItem</title>
        <nav:resources override="true"/>
        <g:render template="/shared/pictureHead" />
    </head>
    <body>
        <div class="nav">
            <nav:renderSubItems group="nav"/>
        </div>
        <div class="body">
            <g:render template="/shared/messages" />
            <g:hasErrors bean="${inventoryItemInstance}">
            <div class="errors">
                <g:renderErrors bean="${inventoryItemInstance}" as="list" />
            </div>
            </g:hasErrors>
            <g:form method="post" >
                <input type="hidden" name="id" value="${inventoryItemInstance?.id}" />
                <input type="hidden" name="version" value="${inventoryItemInstance?.version}" />
                <div class="dialog">
                    <table>
                        <tbody>

                            <tr class="prop">
                                <td valign="top" class="groupHeader">
                                    <label>Inventory Item</label>
                                </td>
                                <td valign="top" class="value">
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="groupName">
                                    <label for="name">Name:</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean:inventoryItemInstance,field:'name','errors')}">
                                    <input type="text"
                                                class="description"
                                                maxlength="50"
                                                id="name"
                                                name="name"
                                                value="${fieldValue(bean:inventoryItemInstance,field:'name')}"/>
                                    <g:helpBalloon class="helpballoon" code="inventory.item.name" />
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="groupName">Picture:</td>
                                <td valign="top" class="value">
                                    <g:if test="${inventoryItemInstance.picture}" >
                                        <span class='gallery'>
                                            <wa:pictureLightboxAnchor picture="${inventoryItemInstance.picture}" size="${Image.Small}" lightboxSize="${Image.Large}" target="_blank" title="Show Original" />
                                        </span>
                                        <br />
                                        <g:link controller="pictureDetailed" action="edit" id="${inventoryItemInstance.picture.id}" >
                                            Edit Picture
                                        </g:link>
                                    </g:if>
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="groupName">
                                    <label for="description">Description:</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean:inventoryItemInstance,field:'description','errors')}">
                                    <textarea rows="5" cols="40" name="description">${fieldValue(bean:inventoryItemInstance, field:'description')}</textarea>
                                    <g:helpBalloon class="helpballoon" code="inventory.item.description" />
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="groupName">
                                    <label for="comment">Comment:</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean:inventoryItemInstance,field:'comment','errors')}">
                                    <textarea rows="5" cols="40" name="comment">${fieldValue(bean:inventoryItemInstance, field:'comment')}</textarea>
                                    <g:helpBalloon class="helpballoon" code="inventory.item.comment" />
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="groupName">
                                    <label for="unitsInStock">In Stock:</label>
                                </td>
                                <td valign="top" class="value">
                                    ${inventoryItemInstance.unitsInStock} ${inventoryItemInstance.unitOfMeasure.encodeAsHTML()}
                                    <g:helpBalloon class="helpballoon" code="inventory.item.units.in.stock" />
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="groupName">
                                    <label for="inventoryLocation">Location:</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean:inventoryItemInstance,field:'inventoryLocation','errors')}">
                                    <g:select optionKey="id"
                                                        from="${ InventoryLocation.findAllByIsActive(true).sort { p1, p2 -> p1.toString().compareToIgnoreCase(p2.toString()) } }"
                                                        name="inventoryLocation.id"
                                                        value="${inventoryItemInstance?.inventoryLocation?.id}"
                                                        optionValue="${{it.name+ ' in ' + it.inventoryStore}}">
                                    </g:select>
                                    <g:helpBalloon class="helpballoon" code="inventory.item.inventory.location" />
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="groupName">
                                    <label for="inventoryGroup">Inventory Group:</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean:inventoryItemInstance,field:'inventoryGroup','errors')}">
                                    <g:select optionKey="id"
                                                        from="${InventoryGroup.findAllByIsActive(true).sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }}"
                                                        name="inventoryGroup.id"
                                                        value="${inventoryItemInstance?.inventoryGroup?.id}" >
                                    </g:select>
                                    <g:helpBalloon class="helpballoon" code="inventory.item.inventory.group" />
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="groupName">
                                    <label for="inventoryType">Inventory Type:</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean:inventoryItemInstance,field:'inventoryType','errors')}">
                                    <g:select optionKey="id"
                                                        from="${InventoryType.findAllByIsActive(true).sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }}"
                                                        name="inventoryType.id"
                                                        value="${inventoryItemInstance?.inventoryType?.id}" >
                                    </g:select>
                                    <g:helpBalloon class="helpballoon" code="inventory.item.inventory.type" />
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="groupHeader">
                                    <label for="name">Reorder Details</label>
                                </td>
                                <td valign="top" class="value">
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="groupName">
                                    <label for="isActive">Active:</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean:inventoryItemInstance,field:'isActive','errors')}">
                                    <g:checkBox name="isActive" value="${inventoryItemInstance?.isActive}" ></g:checkBox>
                                    <g:helpBalloon class="helpballoon" code="inventory.item.is.active" />
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="groupName">
                                    <label for="isObsolete">Obsolete:</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean:inventoryItemInstance,field:'isObsolete','errors')}">
                                    <g:checkBox name="isObsolete" value="${inventoryItemInstance?.isObsolete}" ></g:checkBox>
                                    <g:helpBalloon class="helpballoon" code="inventory.item.is.obsolete" />
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="groupName">
                                    <label for="enableReorderListing">Enable Reorder Listing:</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean:inventoryItemInstance,field:'enableReorderListing','errors')}">
                                    <g:checkBox name="enableReorderListing" value="${inventoryItemInstance?.enableReorderListing}" ></g:checkBox>
                                    <g:helpBalloon class="helpballoon" code="inventory.item.enable.reorder.listing" />
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="groupName">
                                    <label for="reorderPoint">Reorder Point:</label>
                                </td>
                                <td valign="top">
                                    <input  class="medium ${hasErrors(bean:inventoryItemInstance,field:'reorderPoint','errors')}"
                                                    type="text" id="reorderPoint" name="reorderPoint"
                                                    value="${fieldValue(bean:inventoryItemInstance,field:'reorderPoint')}" />
                                    ${inventoryItemInstance.unitOfMeasure.encodeAsHTML()}
                                    <g:helpBalloon class="helpballoon" code="inventory.item.reorder.point" />
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="groupName">
                                    <label for="reorderQuantity">Reorder Quantity:</label>
                                </td>
                                <td valign="top">
                                    <input class="medium ${hasErrors(bean:inventoryItemInstance,field:'reorderQuantity','errors')}"
                                                type="text" id="reorderQuantity" name="reorderQuantity"
                                                value="${fieldValue(bean:inventoryItemInstance,field:'reorderQuantity')}" />
                                     ${inventoryItemInstance.unitOfMeasure.encodeAsHTML()}
                                    <g:helpBalloon class="helpballoon" code="inventory.item.reorder.quantity" />
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="groupName">
                                    <label for="estimatedUnitPriceAmount">Estimated Unit Price:</label>
                                </td>
                                <td valign="top" class="value">
                                    <input  class="medium ${hasErrors(bean:inventoryItemInstance,field:'estimatedUnitPriceAmount','errors')}"
                                                    type="text" id="estimatedUnitPriceAmount" name="estimatedUnitPriceAmount"
                                                    value="${inventoryItemInstance.estimatedUnitPriceAmount}" />
                                    <g:currencySelect name="estimatedUnitPriceCurrency"
                                                                        value="${inventoryItemInstance?.estimatedUnitPriceCurrency}"
                                                                        from="${grailsApplication.config.currencyList}">
                                    </g:currencySelect>
                                    <g:helpBalloon class="helpballoon" code="inventory.item.estimated.unit.price.amount" />
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="groupName">
                                    <label for="suppliersPartNumber">Suppliers Part Number:</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean:inventoryItemInstance,field:'suppliersPartNumber','errors')}">
                                    <input type="text" id="suppliersPartNumber" maxlength="50" name="suppliersPartNumber" value="${fieldValue(bean:inventoryItemInstance,field:'suppliersPartNumber')}"/>
                                    <g:helpBalloon class="helpballoon" code="inventory.item.suppliers.part.number" />
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="groupName">
                                    <label for="preferredSupplier">Preferred Supplier:</label>
                                </td>
                                <td valign="top">
                                    <g:select optionKey="id"
                                                    from="${suppliers}"
                                                    name="preferredSupplier.id"
                                                    value="${inventoryItemInstance.preferredSupplier?.id}"
                                                    noSelection="['null':'--None--']">
                                    </g:select>
                                    <g:helpBalloon class="helpballoon" code="inventory.item.preferred.supplier" />
                                    <p><g:link controller="supplierDetailed" action="create">+Add Supplier</g:link></p>
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="groupName">
                                    <label for="alternateSuppliers">Alternate Suppliers:</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean:inventoryItemInstance,field:'alternateSuppliers','errors')}">
                                    <g:helpBalloon class="helpballoon" code="inventory.item.alternate.suppliers" />
                                    <custom:checkBoxList name="alternateSuppliers"
                                                                    from="${suppliers}"
                                                                    value="${inventoryItemInstance?.alternateSuppliers?.collect{it.id}}"
                                                                    optionKey="id"
                                                                    linkController="supplierDetailed"
                                                                    linkAction="show"/>
                                    <g:link controller="supplierDetailed" action="create">+Add Supplier</g:link>
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="groupHeader">
                                    <label for="name">Spare For</label>
                                </td>
                                <td valign="top" class="value">
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="groupName">
                                    <label for="spareFor">Assets:</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean:inventoryItemInstance,field:'spareFor','errors')}">
                                    <g:helpBalloon class="helpballoon" code="inventory.item.spare.for" />
                                    <custom:checkBoxList name="spareFor"
                                                                    from="${Asset.findAllByIsActive(true).sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }}"
                                                                    value="${inventoryItemInstance?.spareFor?.collect{it.id}}"
                                                                    optionKey="id"
                                                                    sortBy="name"
                                                                    linkController="assetDetailed"
                                                                    linkAction="show"/>
                                    <g:link controller="assetDetailed" action="create">+Add Asset</g:link>
                                </td>
                            </tr>

                        </tbody>
                    </table>
                </div>
                <div class="buttons">
                    <span class="button"><g:actionSubmit class="save" value="Update" /></span>
                    <span class="button"><g:actionSubmit class="cancel" value="Cancel" action="Show"/></span>
                    <span class="button"><g:actionSubmit class="delete" onclick="return confirm('Are you sure?');" value="Delete" /></span>
                </div>
            </g:form>
        </div>
    </body>
</html>
