<!DOCTYPE html>
<html>
   <head>
      <title>Comprar</title>      
	  <meta name = "viewport" content = "width = device-width, initial-scale = 1">
      <link rel = "stylesheet" href = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"> 
	  <link rel = "stylesheet" href = "css/flex.css">		 	  	  
      <script src = "https://code.jquery.com/jquery-1.11.3.min.js"></script>
      <script src = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
	  <script src = "js/navegar.js"></script>
	  <script src = "hpedido.js"></script>


   </head>

   <body>
      <div data-role = "page" id = "page1">
         <div data-role = "navbar" >
                <ul>
                    <li><a href="javascript:navegar_oferta  ()" class = "ui-btn ui-btn-inline ui-btn-a">Ofertas</a></li>
                    <li><a href="javascript:navegar_compra  ()" class = "ui-btn-active ui-state-persist">Fruta y Verdura</a></li>
                    <li><a href="javascript:navegar_obrador ()" class = "ui-btn ui-btn-inline ui-btn-a">Obrador</a></li>
					<li><a href="javascript:navegar_flor ()" class = "ui-btn ui-btn-inline ui-btn-a">Flor</a></li>
					<li><a href="javascript:navegar_historico ()" class = "ui-btn ui-btn-inline ui-btn-a">Historico</a></li>					
					<li><a href="logout.php" class = "ui-btn ui-btn-inline ui-btn-a ">Salir</a></li>						
                </ul>		 
         </div>
                 
         <div data-role = "header"  data-position="fixed">
            <h2>FRUTA Y VERDURA</h2>
         </div>
         
         <div data-role = "main" class = "ui-content" id="comprar">
<?php

include($_SERVER['DOCUMENT_ROOT'].'/_configs/conecta.php' );
include($_SERVER['DOCUMENT_ROOT'].'/_configs/conecta2.php' );
             
$idEmpresa = ("1");
$idData = 1;
$idDataParent = 1;

			$queryFamilia = ("SELECT DISTINCT familia.codfamilia,desfamilia FROM DBA.familia,DBA.articulo where familia.codfamilia=articulo.codfamilia and familia.codfamilia <> 'AL' and familia.codfamilia <> 'XX'  and prod_in_fam > 0 ORDER BY desfamilia;");
			$resultado = odbc_exec($conexion_mercafruit,$queryFamilia );

			echo "<div id='productgridcontainer' class='product-grid-container container-center'>
			";
			// comienza un bucle que leera todos los registros y ejecutara las ordenes que siguen

			while ($productosFamilia = odbc_fetch_array($resultado)) { 
//  			    $queryFamStock = ("SELECT  _por_ven_com  (\"1\",\"".$productosFamilia['codfamilia']."\") as cantidad from fsfamili where cod_famili = \"".$productosFamilia['codfamilia']."\";");
//				$resFamStock = odbc_exec($conexion_resdis,$queryFamStock );
//				$stockFam = odbc_fetch_array($resFamStock);
			
				$productosFamilia['codfamilia'] = str_replace ('\xef\xbf\xbd','&Ntilde;', $productosFamilia['codfamilia']);
                echo "<div class='product-list--row'> ";

					$idDataParent= $idData ;
					$idData++;
					$contengan=chr(209);
					//DETALLE
					$queryArtFam = ("SELECT DISTINCT catalogo.codart codart,catalogo.desccatalogo descart,catalogo.codref codref, catalogo.codcatalogo FROM DBA.articulo,DBA.catalogo where 
							CATALOGO.CODART  NOT LIKE '%".$contengan."%'  AND 
							catalogo.activo='S' AND articulo.codart = catalogo.codart AND codsubfam <> 'DE' AND  codfamilia='".$productosFamilia['codfamilia']."'  ORDER BY desccatalogo ;");
					$resArtFam = odbc_exec($conexion_mercafruit,$queryArtFam );
					while ($productosArtFam = odbc_fetch_array($resArtFam)) { 
						
						$queryArtFamStock = ("SELECT  _stock_art  (\"1\",\"".$productosArtFam['codart']."\") as cantidad from fsarticu where emp_articu = \"1\" and cod_articu = \"".$productosArtFam['codart']."\";");
						$resArtFamStock = odbc_exec($conexion_resdis,$queryArtFamStock );
						$stockArt = odbc_fetch_array($resArtFamStock);
						
//						$queryPesoMArt = ("select max( fslincom.bru_lincom/fslincom.bul_lincom) as pmedio  from fsexiste,fslincom where fsexiste.emp_existe = fslincom.emp_lincom and fsexiste.lot_lincom = fslincom.lot_lincom and fsexiste.art_existe = fslincom.art_lincom and fsexiste.art_existe = '".$productosArtFam['codart']."' and fsexiste.fec_lincom in (select max(fec_lincom) from   fslincom where art_lincom = '".$productosArtFam['codart']."' );");
//echo $queryPesoMArt;						
//						$resPesoMArt = odbc_exec($conexion_resdis,$queryPesoMArt );
//						$pesoMedioArt = odbc_fetch_array($resPesoMArt);						


						echo "<div class='product-list__item'> ";
							echo "<div class='prod_grid' data-productcode='".$productosArtFam['codart']."'> ";				
								echo "<ul class='product-grid-icons'></ul>";
									echo "<a href='infoart.php?articulo=".trim($productosArtFam['codart'])."' title='' class='productMainLink'  data-rel='dialog' data-transition='pop' style='background-color:#e7416d;color:WHITE'  >";
									echo "<div class='column-left'>";
									echo "<div class='thumb'>";
										echo "<img class='crispImage' intemprop='image' src='img\\".trim($productosArtFam['codart']).".jpg' alt='".$productosArtFam['descart']."' onerror='missingImage(this);' width='100' height='100'>";
									echo "</div>";
									echo "<div class='column-right'>";
										echo "<span class='details'>".$productosArtFam['descart']."</span>";
										echo "<div class='price-container'>";								
											echo "<p class='price'></p>";
											echo "<p class='pricePerKilogram'>Stock: ".$stockArt['cantidad']."</p>";
										echo "</div>";
										echo "<ul class ='product-grid-labels'></ul>";
										echo "<div class ='cart'>";
											echo "<form id='updateCartFormByProduct_".trim($productosArtFam['codart'])."' name='UpdateQuantityForm' data-productdescription='DescripciondeProduccion' class='UpdateQuantityForm' action='' method='post' data-productcode='".$productosArtFam['codart']."' >";
												echo "<input type='hidden' class='productCode' name='productCodePost' value='".trim($productosArtFam['codart'])."'";
												echo "<input type='hidden' class='initialQuantity' name='initialQuantity' value='1'";
												echo "<input type='hidden' class='quantity' name='quantity' value='1'";										
												echo "<input type='hidden' class='soldByType' name='soldByType' value='QUANTITY'";																				
												echo "<input type='hidden' class='price' name='priceBr' value='2,05'";																														
											echo "</form>";									
											echo "<div class='product-initialAddToCart productGrid-product-initialialAddToCart' data-productcode='".trim($productosArtFam['codart'])."'>";
												echo "<button>Añadir</button>";
											echo "</div>";									
										echo "</div>";
									echo "</div>";
									echo "</div>";
									echo "</a>";
							echo "</div>";
						echo "</div>";
                    }
					odbc_free_result ($resArtFam);
				echo "</div>";
//F DETALLE 
			} // fin del bucle de ordenes
            odbc_free_result($resultado); 
							
			//cerramos la etiqueta tabla
echo "</div>";


?>
         </div>
         
         <div data-role = "footer" data-position="fixed">
						<a href="info_venta.php" DATA-ICON="user"  class = "ui-icon-user" data-rel="dialog" data-transition="pop" style='background-color:#e7416d;color:WHITE'>i</a>
						<a href='javascript:limpiaPedido()' data-role='button' data-theme='a' title='Borrar' class='ui-btn' style='width:130px;margin-left:10px;background-color:#E7BB41;color: WHITE;text-shadow: 0 1px 0 #C39619;' >Limpiar</a>
						<a href='javascript:confirmaPedido2()' data-role='button' data-theme='c' title='Comprar' class='ui-btn' style='width:130px;background-color:TEAL;color: WHITE;text-shadow: 0 1px 0 #13520C;'>Comprar</a>           
						
         </div>
			<section id="info" data-role="dialog" >
				<header data-role="header">
					<h1>Informacion</h1>
				</header>
				<article data-role="content">
					<p>Usuario o contraseña no valida</p>
					<a href="#" data-role="button" data-rel="back">Aceptar</a>
				</article>
			</section>		 
      </div>

   </body>
</html>