<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Detail</title>
    </head>
    <body>
        <%@include file="header.jsp" %>

        <form name="detail" method="POST">
            <c:choose>
                <c:when test="${type == 'customer'}">
                    <p>
                        <label for="customerId">ID</label>
                        <input type="text" name="customerId" value="${result.customerId}" size="30" id="customerId" />
                    </p>
                    <p>
                        <label for="name">Nom</label>
                        <input type="text" name="name" value="${result.name}" size="30" id="name" />
                    </p>
                    <p>
                        <label for="addressline1">Adresse</label>
                        <input type="text" name="addressline1" value="${result.addressline1}" size="30" id="addressline1" />
                    </p>
                    <p>
                        <label for="addressline2">Adresse 2</label>
                        <input type="text" name="addressline2" value="${result.addressline2}" size="30" id="addressline2" />
                    </p>
                    <p>
                        <label for="city">City</label>
                        <input type="text" name="city" value="${result.city}" size="25" id="city" />
                    </p>
                    <p>
                        <label for="zip">Code Postal</label>
                        <select name="zip" id="zip">
                            <c:forEach items="${cpostaux}" var="cp">
                                <option <c:if test="${cp==result.zip}"> selected </c:if>>${cp}</option>
                            </c:forEach>
                        </select>
                    </p>
                    <p>
                        <label for="state">State</label>
                        <input type="text" name="state" value="${result.state}" size="2" id="state" />
                    </p>
                    <p>
                        <label for="phone">Phone</label>
                        <input type="text" name="phone" value="${result.phone}" size="12" id="phone" />
                    </p>
                    <p>
                        <label for="fax">Fax</label>
                        <input type="text" name="fax" value="${result.fax}" size="12" id="fax" />
                    </p>
                    <p>
                        <label for="email">E-mail</label>
                        <input type="text" name="email" value="${result.email}" size="40" id="email"/>
                    </p>
                    <p>
                        <label for="discountCode">Remise</label>
                        <select name="discountCode" id="discountCode">
                            <c:forEach items="${code}" var="dc">
                                <option <c:if test="${dc.discountCode==result.discountCode}"> selected </c:if> value="${dc.discountCode}">${dc.discountCode} - ${dc.rate}%</option>
                            </c:forEach>
                        </select>
                    </p>
                    <p>
                        <label for="creditLimit">Credit limit</label>
                        <input type="number" name="creditLimit" value="${result.creditLimit}" id="creditLimit"/>
                    </p>
                </c:when>
                <c:when test="${type == 'product'}">
                    <p>
                        <label for="productId">ID</label>
                        <input type="number" name="productId" value="${result.productId}" size="30" id="productId" />
                    </p>
                    <p>
                        <label for="manufacturerId">Manufacturer</label>
                        <select name="manufacturerId" id="manufacturerId">
                            <c:forEach items="${manufacturers}" var="manufacturer">
                                <option <c:if test="${manufacturer.manufacturerId == result.manufacturerId}">selected </c:if>value="${manufacturer.manufacturerId}">${manufacturer.name}</option>
                            </c:forEach>
                        </select>
                    </p>
                    <p>
                        <label for="productCode">Product Code</label>
                        <select name="productCode" id="productCode">
                            <c:forEach items="${productCodes}" var="productCode">
                                <option <c:if test="${productCode.prodCode == result.productCode}">selected </c:if>value="${productCode.prodCode}">${productCode.prodCode} - ${productCode.description}</option>
                            </c:forEach>
                        </select>
                    </p>
                    <p>
                        <label for="purchaseCost">Purchase cost</label>
                        <input type="number" step="0.000000000001" name="purchaseCost" value="${result.purchaseCost}" id="purchaseCost" />
                    </p>
                    <p>
                        <label for="quantityOnHand">Quantity on hand</label>
                        <input type="number" name="quantityOnHand" value="${result.quantityOnHand}" id="quantityOnHand" />
                    </p>
                    <p>
                        <label for="markup">Markup</label>
                        <input type="number" step="0.0001" name="markup" value="${result.markup}" id="markup" />
                    </p>
                    <p>
                        <label for="available">Available</label>
                        <label for="isavailable">TRUE:</label>
                        <input type="radio" name="available" value="TRUE" <c:if test="${result.available == 'TRUE'}">checked</c:if> id="isavailable" />
                            <label for="notavailable">FALSE:</label>
                            <input type="radio" name="available" value="FALSE" <c:if test="${result.available == 'FALSE'}">checked</c:if> id="notavailable" />
                        </p>
                        <p>
                            <label for="description">Description</label>
                            <input type="text" name="description" value="${result.description}" id="description" size="50" />
                    </p>
                </c:when>
                <c:when test="${type == 'purchase'}">
                    <p>
                        <label for="orderNum">Order number</label>
                        <input type="number" name="orderNum" value="${result.orderNum}" id="orderNum" />
                    </p>
                    <p>
                        <label for="customerId">Customer</label>
                        <select name="customerId" id="customerId">
                            <c:forEach items="${customers}" var="customer">
                                <option <c:if test="${customer.customerId == result.customerId}">selected </c:if>value="${customer.customerId}">${customer.name}</option>
                            </c:forEach>
                        </select>
                    </p>
                    <p>
                        <label for="productId">Product</label>
                        <select name="productId" id="productId">
                            <c:forEach items="${products}" var="product">
                                <option <c:if test="${product.productId == result.productId}">selected </c:if>value="${product.productId}">${product.description}</option>
                            </c:forEach>
                        </select>
                    </p>
                    <p>
                        <label for="quantity">Quantity</label>
                        <input type="number" name="quantity" value="${result.quantity}" id="quantity" />
                    </p>
                    <p>
                        <label for="shippingCost">Shipping cost</label>
                        <input type="number" name="shippingCost" value="${result.shippingCost}" id="shippingCost" />
                    </p>
                    <p>
                        <label for="salesDate">Sales date</label>
                        <input type="date" name="salesDate" value="${result.salesDate}" id="salesDate" />
                    </p>
                    <p>
                        <label for="shippingDate">Shipping date</label>
                        <input type="date" name="shippingDate" value="${result.shippingDate}" id="shippingDate" />
                    </p>
                    <p>
                        <label for="freightCompany">Freight company</label>
                        <input type="text" name="freightCompany" value="${result.freightCompany}" id="freightCompany" />
                    </p>
                </c:when>
                <c:when test="${type == 'discount'}">
                    <p>
                        <label for="discountCode">Discount code</label>
                        <input type="text" name="discountCode" value="${result.discountCode}" id="discountCode" size="1" />
                    </p>
                    <p>
                        <label for="rate">Rate</label>
                        <input type="number" name="rate" value="${result.rate}" id="rate" />
                    </p>
                </c:when>
                <c:when test="${type == 'prodCode'}">
                    <p>
                        <label for="prodCode">Product Code</label>
                        <input type="text" name="prodCode" value="${result.prodCode}" id="prodCode" size="2" />
                    </p>
                    <p>
                        <label for="discountCode">Remise</label>
                        <select name="discountCode" id="discountCode">
                            <c:forEach items="${code}" var="dc">
                                <option <c:if test="${dc.discountCode==result.discountCode}"> selected </c:if> value="${dc.discountCode}">${dc.discountCode} - ${dc.rate}%</option>
                            </c:forEach>
                        </select>
                    </p>
                    <p>
                        <label for="description">Description</label>
                        <input type="text" name="description" value="${result.description}" id="description" size="10" />
                    </p>
                </c:when>
            </c:choose>

            <input hidden type="text" name="type"  value="${type}" />
            <c:choose>
                <c:when test="${save != null}">
                    <input type="submit" value="Add" formaction="save.htm" />
                </c:when>
                <c:otherwise>
                    <input type="submit" value="Edit" formaction="update.htm" />
                    <input type="submit" value="Delete" formaction="delete.htm" />
                    <c:if test="${type == 'customer'}">
                        <input type="submit" value="Afficher les achats" formaction="achats.htm" />
                    </c:if>
                </c:otherwise>
            </c:choose>
        </form>
    </body>
</html>