<?php include('../cfg/res.php');?>
<?php
$sql_vtas='select count(*)as ventas from vtas0 where codigo="'.$_SESSION['user_vcrx_id'].'"';

$sql_vtas='select count(*)as ventas from vtas1 where enti="'.$_SESSION['user_vcrx_id'].'"';
$res_vtas=mysql_query($sql_vtas,$link_vcrx);
$n_vtas=mysql_result($res_vtas,0,'ventas');
//echo $n_vtas;

$sql_drtr='select * from drtr0 where left(enti_codigo,10) = "'.$_SESSION['user_vcrx_id'].'"';
$res_drtr=mysql_query($sql_drtr,$link_vcrx);
$drtr=0;
if (mysql_num_rows($res_drtr)>0)
{
	$drtr=1;
}

$sql_dcto='select * from enti0 where enti_codigo="'.$_SESSION['user_vcrx_id'].'"';
$res_dcto=mysql_query($sql_dcto,$link_vcrx);
if(mysql_num_rows($res_dcto)==0)
{
	$dcto=0;
}
else
{
	$dcto=mysql_result($res_dcto,0,'enti_dcto');
	$referidox=mysql_result($res_dcto,0,'enti_referidox');
	if(empty($dcto))
		{
		$dcto=0;
		}
	if((empty($referidox) || !isset($referidox)) && $drtr=0)
		{
		$dcto=0;
		}
	
}




?>
<div align="left" id="frm_excel_pedido">
<table width="100%" cellpadding="2" cellspacing="0">


<tr valign="top">
<td width="53%">

<div style="width:555px;">
<table border="1" id="tabla_pedido_cabecera" cellpadding="0" cellspacing="0">
<tr style="font-size:12px;">
		<td align="center"><div class="talla_cab_cat">Cat</div></td>
	        <td align="center"><div class="talla_cab_pag">Pag</div></td>
		<td align="center"><div class="talla_cab_cod">Cod</div></td>
		<td align="center"><div class="talla_cab_pvp" style="width:50px;">PVP</div></td>

        	<td align="center"><div class="talla_vacio">U</div></td>
		<td align="center"><div class="talla_vacio">4</div></td>
		<td align="center"><div class="talla_vacio">6</div></td>
		<td align="center"><div class="talla_vacio">8</div></td>
		<td align="center"><div class="talla_vacio">10</div></td>
		<td align="center"><div class="talla_vacio">12</div></td>
		<td align="center"><div class="talla_vacio">XS</div></td>
		<td align="center"><div class="talla_vacio">S</div></td>
		<td align="center"><div class="talla_vacio">M</div></td>
		<td align="center"><div class="talla_vacio">L</div></td>
		<td align="center"><div class="talla_vacio">XL</div></td>
        
</tr>
</table>
</div>

<div style="width:555px;height:450px;overflow-y: scroll;">
<form name="frm_pedido" id="frm_pedido"  method="post" style="padding:0px; margin:0px;"  >
<input type="hidden" id="h_ped_dcto" value="<?php echo $dcto;?>" />
<table border="1" id="tabla_pedido" cellpadding="0" cellspacing="0">
<tr>
		<td><div class="talla_cab_cat"></div></td>
        	<td><div class="talla_cab_pag"></div></td>
		<td><div class="talla_cab_cod"></div></td>
		<td><div class="talla_cab_pvp"></div></td>

	        <td><div class="talla_vacio"></div></td>
		<td><div class="talla_vacio"></div></td>
		<td><div class="talla_vacio"></div></td>
		<td><div class="talla_vacio"></div></td>
		<td><div class="talla_vacio"></div></td>
		<td><div class="talla_vacio"></div></td>
		<td><div class="talla_vacio"></div></td>
		<td><div class="talla_vacio"></div></td>
		<td><div class="talla_vacio"></div></td>
		<td><div class="talla_vacio"></div></td>
		<td><div class="talla_vacio"></div></td>
        
</tr>
<?php
$sql_nctlg='SELECT item_nctlg
from invhoja
GROUP BY item_nctlg
ORDER BY item_nctlg desc LIMIT 2';

$result_nctlg=mysql_query($sql_nctlg,$link_vcrx);
while($row_nctlg=mysql_fetch_assoc($result_nctlg))
{
	$sql_item='select 
	left(item_codigo,6)as codigo,
	item_pctlg,
	item_modelo,
	ROUND(item_pvp1, 2),
	item_puni
	from invhoja 
	where item_nctlg="'.$row_nctlg['item_nctlg'].'"
	group by left(item_codigo,6) order by item_pctlg asc';
	$result_item=mysql_query($sql_item,$link_vcrx);
	while($row_item=mysql_fetch_row($result_item))
	{
?>
	<tr>
    	<td align="right"><?php echo $row_nctlg['item_nctlg'];?></td>
        <td align="center"><?php echo $row_item[1];?></td>	
        <td align="left"><?php echo $row_item[2];?></td>
        <td align="right"><?php echo $row_item[3];?></td>
	<input type="hidden"   value="<?php echo $row_item[3];?>" readonly="readonly" style="width:50px; border:none; margin:0px; padding:0px; text-align:right;" />
        <input type="hidden"  id="<?php echo $row_item[2];?>" value="<?php echo $row_item[4];?>" readonly="readonly" />
        </td>
        
<?php
$sql_talla='select item_codigo,RIGHT(item_codigo,2) as talla from invhoja where item_codigo like "'.$row_item[0].'%"
and  item_nctlg="'.$row_nctlg['item_nctlg'].'" order by talla asc ';
//echo $sql_talla;
	$res_talla=mysql_query($sql_talla,$link_vcrx);
	$arreglo[0]='<td class="talla_vacio">&nbsp;</td>';
	$arreglo[1]='<td class="talla_vacio">&nbsp;</td>';
	$arreglo[2]='<td class="talla_vacio">&nbsp;</td>';
	$arreglo[3]='<td class="talla_vacio">&nbsp;</td>';
	$arreglo[4]='<td class="talla_vacio">&nbsp;</td>';
	$arreglo[5]='<td class="talla_vacio">&nbsp;</td>';
	$arreglo[6]='<td class="talla_vacio">&nbsp;</td>';
	$arreglo[7]='<td class="talla_vacio">&nbsp;</td>';
	$arreglo[8]='<td class="talla_vacio">&nbsp;</td>';
	$arreglo[9]='<td class="talla_vacio">&nbsp;</td>';
	$arreglo[10]='<td class="talla_vacio">&nbsp;</td>';
	
	while($row_talla=mysql_fetch_row($res_talla))
	{
 		if($row_talla[1]=='00')
		{
			$arreglo[0]='<td align="center" class="celda"><div class="talla_div"><input type="text" name="'.$row_talla[0].'" id="'.$row_talla[0].'" class="talla_txt" onkeydown="mover(event,this.id);" onblur="recalc_ped();"  /></div></td>';
		}
		if($row_talla[1]=='04')
		{
			$arreglo[1]='<td align="center" class="celda"><div class="talla_div"><input type="text" name="'.$row_talla[0].'" id="'.$row_talla[0].'" class="talla_txt"  onkeydown="mover(event,this.id);" onblur="recalc_ped();"  /></div></td>';
		}
		if($row_talla[1]=='06')
		{
			$arreglo[2]='<td align="center" class="celda"><div class="talla_div"><input type="text" name="'.$row_talla[0].'" id="'.$row_talla[0].'" class="talla_txt"  onkeydown="mover(event,this.id);" onblur="recalc_ped();"  /></div></td>';
		}
		if($row_talla[1]=='08')
		{
			$arreglo[3]='<td align="center" class="celda"><div class="talla_div"><input type="text" name="'.$row_talla[0].'" id="'.$row_talla[0].'" class="talla_txt"  onkeydown="mover(event,this.id);" onblur="recalc_ped();"  /></div></td>';
		}
		if($row_talla[1]=='10')
		{
			$arreglo[4]='<td align="center" class="celda"><div class="talla_div"><input type="text" name="'.$row_talla[0].'" id="'.$row_talla[0].'" class="talla_txt"  onkeydown="mover(event,this.id);" onblur="recalc_ped();"  /></div></td>';
		}
		if($row_talla[1]=='12')
		{
			$arreglo[5]='<td align="center" class="celda"><div class="talla_div"><input type="text" name="'.$row_talla[0].'" id="'.$row_talla[0].'" class="talla_txt"  onkeydown="mover(event,this.id);" onblur="recalc_ped();"  /></div></td>';
		}
		if($row_talla[1]=='90')
		{
			$arreglo[6]='<td align="center" class="celda"><div class="talla_div"><input type="text" name="'.$row_talla[0].'" id="'.$row_talla[0].'" class="talla_txt"  onkeydown="mover(event,this.id);"  onblur="recalc_ped();" /></div></td>';
		}
		if($row_talla[1]=='91')
		{
			$arreglo[7]='<td align="center" class="celda"><div class="talla_div"><input type="text" name="'.$row_talla[0].'" id="'.$row_talla[0].'" class="talla_txt"  onkeydown="mover(event,this.id);"  onblur="recalc_ped();" /></div></td>';
		}
		if($row_talla[1]=='92')
		{
			$arreglo[8]='<td align="center" class="celda"><div class="talla_div"><input type="text" name="'.$row_talla[0].'" id="'.$row_talla[0].'" class="talla_txt"  onkeydown="mover(event,this.id);"  onblur="recalc_ped();" /></div></td>';
		}
		if($row_talla[1]=='93')
		{
			$arreglo[9]='<td align="center" class="celda"><div class="talla_div"><input type="text" name="'.$row_talla[0].'" id="'.$row_talla[0].'" class="talla_txt"  onkeydown="mover(event,this.id);"  onblur="recalc_ped();" /></div></td>';
		}
		if($row_talla[1]=='94')
		{
			$arreglo[10]='<td align="center" class="celda"><div class="talla_div"><input type="text" name="'.$row_talla[0].'" id="'.$row_talla[0].'" class="talla_txt"  onkeydown="mover(event,this.id);"  onblur="recalc_ped();" /></div></td>';
		}
				

	}
	foreach($arreglo as $valor){echo $valor;}
 ?> 
 </tr>    
<?php		
	}
}
?>
</table>

</form>






</div>

</td>

<td width="47%">

	<div align="center" style="margin-bottom:5px;">
    	<a href="../lib/pedidos_formato.php" target="new" style="text-decoration:none;color:#ffffff;font-size:14px; font-weight:bolder; background:#09c;">
        &nbsp; IMPRIMIR HOJA DE FORMATO &nbsp;
        </a>
    </div>
    <div align="center">Envio</div>
  	<div><input type="radio" name="radio_car" id="radio" value="0" checked="checked" onclick="recalc_ped();" />Retiro oficina</div>
  	<div><input type="radio" name="radio_car" id="radio1" value="1" onclick="recalc_ped();" />Envio a Director</div>
  	<div><input type="radio" name="radio_car" id="radio2" value="4" onclick="recalc_ped();" />Envio a Domicilio</div>
	<table width="100%" border="0" cellpadding="2" cellspacing="0" style="background: #EAEAFF ; border-collapse:collapse;">
	<tr>
	<td  align="left" width="50%"><strong>UNIDADES:</strong></td>
	<td align="right"><span id="sub_uni_car"></span></td>
	</tr>

	<tr>
	<td  align="left" width="50%"><strong>SUBTOTAL:</strong></td>
	<td align="right"><span id="sub_tot_car"></span></td>
	</tr>

	<tr>
	<td  align="left"><strong>DCTO:</strong></td>
	<td align="right"><span id="dcto_tot_car"></span></td>
	</tr>

	<tr>
	<td  align="left"><strong>IVA:</strong></td>
	<td align="right"><span id="iva_car"></span></td>
	</tr>

	<tr>
	<td  align="left"><strong>ENVIO:</strong></td>
	<td align="right"><span id="envio_car"></span></td>
	</tr>

	<tr>
	<td  align="left"><strong>TOTAL:</strong></td>
	<td align="right"><span id="total_car"></span></td>
	</tr>


	</table>
 <?php if($_GET['opt']=='hped')
 {?>
<div align="center">
	<?php					
		require('../../lib/valdatenti.php');
		$valdatentix=new valdatenti('../cfg/res.php',$_SESSION['user_vcrx_id']);
		if($valdatentix->existe==1)
		{
		?>
		
<div></div>
<div>c.i. Empresario</div>

		<input type="text" class="est_txt" id="enti" onKeyDown="busca_maes(event,this.id,'enti100');" />
        <div id="enti100"></div>
        <div id="lista_maes" align="left"></div>
<div></div>
	   <input type="image" src="../img/carrito.jpg"  onclick="carrito('<?php if($n_vtas!=0){echo 1;}else{echo 4;};?>');" id="carrito_ico"/>
        
      <?php  
		}
		else
		{
		?>
      
	  	<a href="?opt=dper" style="color:#F00; text-decoration:none;">Complete su Informacion Aqui.!</a>
	  <?php
	    
		}
		
		if($_SESSION['user_vcrx_tipo']=='admi' || $drtr=1)
		{
?>
<?php
		}
	?>
   
</div>
<div align="center" id="carrito_error"></div>
<?php }?>



</td>



</tr>
</table>
</div>