<?
include("../../conex.php");
$cant = "1";
$flag=0;

if( $radiobutton=="r2")
	{
	$txtdescuento=($txtdescuento/100);
	$txtdescuento=(int)($txtsubtotal*$txtdescuento);
	}
	
	$sql_dcto = "SELECT id FROM tipo_dcto WHERE descripcion = 'BOLETA'";
	$res_dcto = mysql_query($sql_dcto,$enlace);
	$row=0;
	while (mysql_fetch_object ($res_dcto))
		{
		$id_tipo_dcto=mysql_result($res_dcto, $row, "id");
		$row=$row+1;
		}
	$sql_pago = "SELECT id FROM tipo_pago WHERE descripcion = 'CHEQUE'";
	$res_pago = mysql_query($sql_pago,$enlace);
	$row=0;
	while (mysql_fetch_object ($res_pago))
		{
		$id_tipo_pago=mysql_result($res_pago, $row, "id");
		$row=$row+1;
		}
	$sql_par = "SELECT valor FROM parametros WHERE descripcion = 'IVA'";
	$res_par = mysql_query($sql_par,$enlace);
	$row=0;
	while (mysql_fetch_object ($res_par))
		{
		$par_iva=mysql_result($res_par, $row, "valor");
		$row=$row+1;
		}
	/************************************************** calculo neto e iva ***********************************************/	
	$sql_total=$txttotal/(1+$par_iva);
	$sql_neto = number_format($sql_total,0,',','');
	$sql_iva=$txttotal-$sql_neto;
	$sql_total=$txttotal;
	/************************************************** sacar numero boleta *********************************************/		
	$sql_ultima_bol = "SELECT num_dcto FROM salida WHERE tipo_dcto = $id_tipo_dcto ORDER BY num_dcto DESC";
	$res_ultima_bol = mysql_query($sql_ultima_bol,$enlace);
	$sql_num_bol=0;
	if(mysql_fetch_object($res_ultima_bol))	$sql_num_bol = mysql_result($res_ultima_bol,0 ,"num_dcto");
	$sql_num_bol = $sql_num_bol + 1;
	/************************************************** insertar salida ***********************************************/	
	$dia = substr ($fecha, 0, 2);
	$mes = substr ($fecha, 3, 2);
	$aņo = substr ($fecha, 6, 4); 
	$fecha_em = "$aņo-$mes-$dia";
	$wsql = "INSERT INTO salida (num_dcto, tipo_dcto, fecha_emision, tipo_pago, neto, iva, total, productos) 
	VALUES ($sql_num_bol, $id_tipo_dcto, $fecha_em, $id_tipo_pago, $sql_neto, $sql_iva, $sql_total, 1)";
	$consulta = mysql_query($wsql,$enlace);
?>


<table width="90%" align="center" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="25%"><div align="center"><img src="../Images/logo.gif" width="60px" height="60px"></div></td>
	<td width="50%"><div align="center"><strong><font size="6">BOLETA NUMERO <?=$sql_num_bol?></font></strong></div></td>
    <td width="25%">&nbsp;</td>
  </tr>
</table>

<table width="90%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000">
	<tr bgcolor="#000000"> 
		<td width="10%"><div align="center"><strong><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Cant.</font></strong></div></td>
		<td width="20%"><div align="center"><strong><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">C&oacute;digo</font></strong></div></td>
		<td width="45%"><div align="center"><strong><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Detalle</font></strong></div></td>
		<td width="10%"><div align="center"><strong><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Precio</font></strong></div></td>
		<td width="15%"><div align="center"><strong><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Total $</font></strong></div></td>
    </tr>
<? 
$cant = "1";
while ($cant<=$cnt)
	{
	if ($total[$cant]>0)
		{
		$psql = "INSERT INTO movimiento (entrada_salida_traspaso, fecha, cod_producto, cantidad, precio_unitario,numero_dcto, tipo_dcto) 
		VALUES ('S', $fecha_em, $codigo[$cant], $cantidad[$cant], $precio[$cant], $sql_num_bol, $id_tipo_dcto)";
		$sql_productos = mysql_query($psql,$enlace);
		
		?>
		<tr> 
			<td width="10%"><div align="left"><font color="#333333" face="Arial, Helvetica, sans-serif">
			<? echo "$cantidad[$cant]";?>&nbsp;
			  </font></div></td>
			  
			<td width="20%"><div align="left"><font color="#333333" face="Arial, Helvetica, sans-serif">
				<? echo "$codigo[$cant]";?>&nbsp;
			</font></div></td>
			
			<td width="45%"><div align="left"><font color="#333333" face="Arial, Helvetica, sans-serif">
				<? echo "$detalle[$cant]";?>&nbsp;
			</font></div></td>
			
			<td width="10%"><div align="right"><font color="#333333" face="Arial, Helvetica, sans-serif">
				<? echo "$precio[$cant]";?>&nbsp;
			</font></div></td>
				
			<td width="15%"><div align="right"><font color="#333333" face="Arial, Helvetica, sans-serif">
				<? echo "$total[$cant]";?>&nbsp;
			</font></div></td>
		</tr>
		<? 
		}
	$cant=$cant+1;
	}
	?>
</table>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr>
	  	<td width="10%">&nbsp;</td>
		<td width="5%">&nbsp;</td>
		<td width="20%">&nbsp;</td>
		<td width="50%"><div align="right"><strong><font color="#333333" face="Arial, Helvetica, sans-serif">NETO</font></strong></div></td>
		<td width="15%"><div align="right"><font color="#333333" face="Arial, Helvetica, sans-serif">
        $
        <?=$sql_neto?>
        </font></div></td>
    </tr>
	<tr>
		<td width="10%">&nbsp;</td>
		<td width="5%">&nbsp;</td>
		<td width="20%">&nbsp;</td>
		<td width="50%"><div align="right"><strong><font color="#333333" face="Arial, Helvetica, sans-serif">IVA</font></strong></div></td>
		<td width="15%"><div align="right"><font color="#333333" face="Arial, Helvetica, sans-serif">
		  $
		  <?=$sql_iva?>
	    </font></div></td>
    </tr>
	<tr>
		<td width="10%">&nbsp;</td>
		<td width="5%">&nbsp;</td>
		<td width="20%">&nbsp;</td>
	  	<td width="50%"><div align="right"><strong><font color="#333333" face="Arial, Helvetica, sans-serif">TOTAL </font></strong></div></td>
	  	<td width="15%"><div align="right"><font color="#333333" face="Arial, Helvetica, sans-serif">
	    $<? if ($txttotal=='')$txttotal=0;?>
	    <?=$sql_total?>
      </font></div></td>
    </tr>
</table>


