<%@ page contentType="text/html; charset=iso-8859-1" language="java" errorPage="" %>
<%@ page import="com.fenalco.utilities.lists.ListView"%>
<%@ page import="com.fenalco.entities.User"%>
<%@ page import="com.fenalco.entities.DataAccess"%>
<%@ page import="com.fenalco.entities.Supplier"%>
<%
    ListView cart = ( ListView )request.getAttribute( "cartView" );
    
    String message = null;
    message = ( String )request.getAttribute( "message" );
    if( message == null )
    {
        message = "";
    }
    double total = 0.0;
    
    int prods = 0;
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel='stylesheet' style='text/css' href='../css/tablas.css'>
<title>Mi carrito de compras</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<script type='text/javascript' language='javascript' src='../js/library.js'></script>
<script language='javascript'>
    function removeProduct( supp, id )
    {
        var name = "producto_" + supp + "_" + id;
        document.getElementById( name ).value = "0";
        document.getElementById( 'carrito' ).submit();
    }
    
    function validateForm(){
        var flag = true;
        var message = "Han ocurrido los siguientes errores:\n";

        if(isEmpty(document.list.name)){
                message = message + "- El nombre de la lista es vacío.\n";
                flag = false;
        }
         if(!flag){
                    window.alert(message);
        }
        return flag;
    }
</script>
<body bgcolor="#ffffff" background="../images/shopkeeper/general/fondo.jpg" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- 
-->
<%
	String helpId = "45";
%>
<table border="0" cellpadding="0" cellspacing="0" width="780">
    <%@ include file="encabezado.jsp" %>
</table>
<table width="760" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td width="155" valign="top">
			<%@ include file="menuminorista.jsp" %>
	</td>
        <td width='603' valign="top">
                    <%
                        String tittle = "Carrito de Compras";
                    %>
                    <%@ include file="/titulo.jsp" %>
                    
            <table>
                <tr>
                    <td align='left'>
                        <font color='#FF0000'><%=message%></font>
                    </td>
                </tr>
                <tr>
                    <td>
                        <table>
                            <form name="carrito" id="carrito" action="/minorista/actualizarcarrito" method="post">
                            <%
                                while( cart.move() )
                                {
                                        int supplierId = ( ( Integer )cart.nextElement() ).intValue();
                                        String supplierName = Supplier.getName( supplierId );
                                        ListView products = ( ListView )cart.nextElement();

                             %>
                        
                            <tr>
                                <td>
                                    <b>Proveedor: <%=supplierName%></b>
                                </td>
                            </tr>
                            
                            <tr>
                                <td>
                                         <table width="100%" border="0">
                                            <tr class='tableheader'> 
                                              <td><div align="center"><strong>C&oacute;digo de Barras</strong></div></td>
                                              <td><div align="center"><strong>Nombre</strong></div></td>
                                              <td><div align="center"><strong>Categor&iacute;a</strong></div></td>
                                              <td><div align="center"><strong>Marca</strong></div></td>
                                              <td><div align="center"><strong>Precio Unit.</strong></div></td>
                                              <td colspan='2'><div align="center"><strong>Cant.</strong></div></td>
                                              <td><div align="center"><strong>Precio Total</strong></div></td>
                                            </tr>
                                            <%
                                                    double sub = 0;
                                                    while( products.move() )
                                                    {
                                                            int id = Integer.parseInt( ( String )products.nextElement() );
                                                            prods++;
                                            %>
                                            <tr> 
                                              <td><%=products.nextElement()%></td>
                                              <td><%=products.nextElement()%></td>
                                              <td><%=products.nextElement()%></td>
                                              <td><%=products.nextElement()%></td>
                                              <td align="right"><%=DataAccess.getCurrency( Double.parseDouble( ( String )products.nextElement() ) )%></td>
                                              <td><input name="producto_<%=supplierId%>_<%=id%>" id="producto_<%=supplierId%>_<%=id%>" type="text" value="<%=products.nextElement()%>" size="2" maxlength="10"></td>
                                              <td><a href='javascript:removeProduct(<%=supplierId%>, <%=id%>)'><img src='/images/buttons/shopkeeper/desactivar.gif' border='0' alt='Eliminar del Carrito'></a></td>
                                              <%
                                                    double subTotal = Double.parseDouble( ( String )products.nextElement() );
                                                    total += subTotal;
                                                    sub += subTotal;
                                                %>
                                              <td align="right"><%=DataAccess.getCurrency( subTotal )%></td>
                                            </tr>
                                            <%
                                                    }
                                            %>
                                      </table>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                
                                    <table align="right" width='505'>

                                            <tr>

                                                <td><strong>SUBTOTAL</strong></td>
                                                <td><strong><%=DataAccess.getCurrency( sub )%></strong></td>
                                            </tr>
                                            <tr>
                                                <td colspan='2'>
                                                    <hr>
                                                </td>

                                            </tr>
                                    </table>
                                </td>
                            </tr>
                           <%
                            }
                    %>
                    <%
                        if( prods > 0 )
                        {
                    %>      
                    </table>
                    
                    </td>
            </tr>
            <tr>
                <td>
                    <table  align="center">
                        <tr>
                            <td><strong>TOTAL</strong></td>
                            <td><strong><%=DataAccess.getCurrency( total )%></strong></td>
                        
                            <td colspan='2'><input type="submit" value="Modificar Cantidades"></td>
                        </tr>

                    </table>

                    <input type="hidden" name="event" value="modificar_cantidad">
                </form>
                </td>
            </tr>
            <tr>
                <td>
                    <%
                                  tittle = "Opciones";
                                %>
                                <%@ include file="/titulo.jsp" %>
                </td>
            </tr>
            <tr align='center'>
                <td>
                    <table cellpadding='0' cellspacing='0'>
                        
                        <tr>
                            <td valign='top' align='left'><b>1. Pedido</b></td>
                            <td align='right'>
 
                                <form action="/minorista/actualizarcarrito" method="post">
                                    <input type="hidden" name="event" value="pedido">
                                    <input type="submit" value="Generar">
                                </form>
                            </td>
                           
                        </tr>
                        <tr>
                            <td valign='top' align='left'><b>
                                2. Cotizaci&oacute;n</b>
                            </td>    
                            
                            <td align='right'>
                                <form action="/minorista/actualizarcarrito" method="post">
                                    <input type="hidden" name="event" value="cotizacion">
                                    <input type="submit" value="Generar">
                                </form>
                            </td>
                            
                            
                        </tr>
                        <tr>
                            <td colspan='2' valign='top' align='left'>
                                <b>3. Lista de compra</b>
                            </td>
                        </tr>
                        <tr>
                            <form name='list' action="/minorista/actualizarcarrito" method="post" onSubmit="return validateForm();">
                            <td>
                                <input type="text" name='name'>
                            </td>
                            <td align='right'>
                                <input type="hidden" name="event" value="lista">
                                <input type="submit" value="Guardar">
                            </td>
                            
                            </form>
                        </tr>
                        
                        <tr>
                            <td align="center" colspan="3">
                                <p>
                                <br>
                                <br>
                                <a href="/minorista/catalogo">Volver al Cat&aacute;logo</a>
                                </p>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            
             <%
            }
            else
            {
                %>
                <p align="center">
                    <font color="#FF0000">
                        El carrito de compras no contiene ning&uacute;n producto.<br>
                        Para agregar productos vaya al <a href="/minorista/catalogo">Cat&aacute;logo</a>.
                    </font>
                <p>
                <%
            }
        %>
      
      <p>&nbsp; </p>                       
        
        </table>
 
</td>
</tr>
</table>




</body>
</html>
