<?php
$query=mysqli_query($con,"SELECT * , DATE_FORMAT(`vena_fecha`,'%d-%m-%Y') as vena_fecha FROM ventas_apartadas where vena_id='$vena_id' and empresa='$empresa' ");
$roww=mysqli_fetch_array($query);
$vena_fecha=$roww['vena_fecha'];
$vena_n_venta=$roww['vena_n_venta'];
$Cliente_clie_id=$roww['Cliente_clie_id'];
$vena_cc=$roww['vena_cc'];
$vena_nombre=$roww['vena_nombre'];
$vena_telefono=$roww['vena_telefono'];


$dir=mysqli_query($con,"SELECT * FROM cliente where clie_id='$Cliente_clie_id'") or die(mysqli_error($con)); 
$dire=mysqli_fetch_array($dir);
$clie_direccion=$dire['clie_direccion'];
$clie_correo=$dire['clie_correo'];
$clie_ciudad=$dire['clie_ciudad'];

$ciu=mysqli_query($api,"SELECT * from municipalities where id='$clie_ciudad'");
$ciud=mysqli_fetch_array($ciu);
$name=$ciud['name'];


$usuario=$roww['usuario'];
$sql3=mysqli_query($con,"SELECT * from usuario where usu_id='$usuario'");
$usu=mysqli_fetch_array($sql3);
$usu_nombre=$usu['usu_nombre'];

?>
<page backtop="1mm" backbottom="5mm" backleft="5mm" backright="5mm" style="font-size: 11pt; font-family: arial" >


    <table cellspacing="0" style="width: 100%;" >
        <tr>
            <td style="width: 33%; color: #444444;">
                <img style="width: 80%;" src="../../../img/<?php echo $empresa;?>.png" alt="Logo"><br>
            </td>
			<td style="width: 34%; font-size:12px;text-align:center;">
				<strong style="font-size:15px"><?php echo $emp_nombre;?></strong><br>
				<strong>Nit: <?php echo $emp_nit;?></strong> <br>
				<strong><?php echo $emp_direccion;?></strong><br>
				<strong><?php echo $emp_correo;?></strong><br>
				<strong>Tel: <?php echo $emp_cel;?> / <?php echo $emp_telefono;?></strong><br>
				<!--<strong>Responsable de IVA </strong><br> 
				<strong>Agente de retención en el impuesto sobre las ventas</strong>-->
			</td>
			<td style="width: 21%;"></td>
        </tr>
    </table>
	
 	<table cellspacing="0" style="width: 100%;" >
        <tr>
             <td style="width: 70%;">
                <table cellspacing="0">
                    <tr>
                        <td  style="background-color:#bdc3c7;padding:2px;text-align:center;"> 
                            <strong style="font-size:10px;color: #000" >DATOS DEL CLIENTE</strong>
                        </td>
                    </tr>
					<tr>
						<td style="width: 100%;text-align:left;border:solid 1px #bdc3c7;font-size:10px ;padding-left: 15px"> 
							<p style="padding:-10px;"><strong>NOMBRE: </strong><?php echo $vena_nombre;?></p>
							<p style="padding:-10px;"><strong>DOCUMENTO: </strong><?php echo $vena_cc;?></p>
							<p style="padding:-10px;"><strong>DIRECCION: </strong><?php echo $clie_direccion;?> <?php echo mb_strtoupper($name);?></p>
							<p style="padding:-10px;"><strong>TELEFONO: </strong><?php echo $vena_telefono;?></p>
							<p style="padding:-10px;"><strong>CORREO: </strong><?php echo mb_strtoupper($clie_correo);?></p>
						</td>
					</tr>
			    </table>
            </td>
			<td style="width: 30%;">
				<table cellspacing="0" style="width: 100%; padding-left:5px">
			        <tr>
						<td style="width: 100%;color:white;background-color:#bdc3c7;padding:2px;text-align:center"> 
							<strong style="font-size:10px;color: #000" >APARTADO N°</strong>
						</td>
					</tr>
					<tr>
						<td style="width: 100%;padding:2px;text-align:center;border:solid 1px #bdc3c7;font-size:12px"> 
							<strong style="color: red"><?php echo $vena_n_venta;?></strong>
						</td>
					</tr>
			    </table>
			    <table cellspacing="0" style="width: 100%;padding-left: 5px; padding-top: 5px;">
					<tr>
						<td style="width: 100%;text-align:left;border:solid 1px #bdc3c7;font-size:10px ;padding-left: 15px;"> 
							<p style="padding:-10px;"><strong>FECHA : </strong><?php echo $vena_fecha;?></p>
							<p style="padding:-10px;"><strong>VENDEDOR: </strong><?php echo $usu_nombre;?></p>
							<p style="padding:-10px;"><strong> </strong><?php //echo $usu_nombre;?></p>
						</td>
					</tr>
			    </table>
			</td>
		</tr>
    </table>



	<table cellspacing="0" style="width: 100%; padding-top: 5px;">
        <tr>
			<td style="width: 10%;color:white;background-color:#bdc3c7;padding:2px;text-align:center"> 
				<strong style="font-size:10px;color: #000">REF</strong>
			</td>
			<td style="width: 5%; color:white;background-color:#bdc3c7;padding:2px;text-align:center"> 
				<strong style="font-size:10px;color: #000">GTIA</strong>
			</td>
			<td style="width: 50%; color:white;background-color:#bdc3c7;padding:2px;text-align:center"> 
				<strong style="font-size:10px;color: #000">DESCRIPCIÓN</strong>
			</td>
			<td style="width: 5%; color:white;background-color:#bdc3c7;padding:2px;text-align:center"> 
				<strong style="font-size:10px;color: #000">CANT</strong>
			</td>
			<td style="width: 8%; color:white;background-color:#bdc3c7;padding:2px;text-align:center"> 
				<strong style="font-size:10px;color: #000">PRECIO U</strong>
			</td>
			<td style="width: 6%; color:white;background-color:#bdc3c7;padding:2px;text-align:center"> 
				<strong style="font-size:10px;color: #000">IVA %</strong>
			</td>
			<td style="width: 7%; color:white;background-color:#bdc3c7;padding:2px;text-align:center"> 
				<strong style="font-size:10px;color: #000">DESC %</strong>
			</td>
			<td style="width:9%; color:white;background-color:#bdc3c7;padding:2px;text-align:center"> 
				<strong style="font-size:10px;color: #000">TOTAL</strong>
			</td>
		</tr>
<?php
   		
   		$suma=0;
        $neto=0;
	    $total_descuento=0;
	    $total_iva=0;
	    $total_retencion=0;
	    $sumador_articulos=0;


        $sql=mysqli_query($con, "SELECT * from  venta_apartadas_detalle where ventas_apartadas_vena_id='$vena_id'");
        while ($row=mysqli_fetch_array($sql))
          {
            $venad_art_id=$row['venad_art_id'];
		    $cotd_referencia=$row['venad_referencia'];
		    $cotd_nombre=$row['venad_nombre'];
		    $cotd_cantidad=$row['venad_cantidad'];
		    $cotd_precio=$row['venad_precio'];
		    $cotd_iva=$row['venad_iva'];
		    $cotd_descuento=$row['venad_desc'];

		    $suma+=$row['venad_cantidad'];

		    $iva0=$cotd_iva/100; //0.19
		    $iva1=1+$iva0; //1.19

			$precio_total_item=$cotd_precio*$cotd_cantidad;//precio normal 1.000.000
			$precio_total_sin_iva_item=($cotd_precio/$iva1)*$cotd_cantidad; //precio sin iva  840.336
			$descuento_item=($cotd_descuento/100)*$precio_total_sin_iva_item; //descuento_item 84.033
			$total_iva_item=$precio_total_sin_iva_item*$iva0; // total iva  159.336

		    $neto+=$precio_total_sin_iva_item;
		    $total_descuento+=$descuento_item;
		    $total_iva+=$total_iva_item;
		    $sumador_articulos=($neto+$total_iva)-$total_descuento;

    		$gar=mysqli_query($con,"SELECT * FROM articulos where art_id='$venad_art_id' and empresa='$empresa'") ;
    		$gar=mysqli_fetch_array($gar);


?>		
		<tr>
			<td style="width:10%;padding:2px;text-align:center;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
				<?php echo $cotd_referencia;?>
			</td>
			
			<td style="width:5%;padding:2px;text-align:center;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
				<?php echo $gar['art_garantia'];?>
			</td>
			<td style="width: 50%;padding:2px;text-align:left;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
				<?php echo $cotd_nombre;?>
			</td>
			<td style="width:5%;padding:2px;text-align:center;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
				<?php echo $cotd_cantidad;?>
			</td>
			<td style="width:8%;padding:2px;text-align:right;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
				<?php echo number_format($precio_total_sin_iva_item,0);?>
			</td>
			<td style="width:6%;padding:2px;text-align:center;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
				<?php echo $cotd_iva;?>
			</td>
			<td style="width:7%;padding:2px;text-align:center;border-left:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
				<?php echo $cotd_descuento;?>
			</td>
			<td style="width: 9%;padding:2px;text-align:right;border-left:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:9px"> 
				<?php echo number_format($precio_total_item,0);?>
			</td>
		</tr>
<?php } 
$sumador_total=$sumador_articulos;

//$total_retencion+=($neto+$sumador_combo-$total_descuento)*($ret_porcentaje/100);
//$sumador_total=$sumador_articulos+$sumador_combo-$total_retencion;

?>		
		<tr>
			<td style="width: 10%;padding:2px;text-align:center;border-left:solid 1px #bdc3c7;border-bottom:solid 1px #bdc3c7;font-size:8px">Total Items</td>
			<td style="width: 5%;padding:2px;text-align:center;border-left:solid 1px #bdc3c7;border-bottom:solid 1px #bdc3c7;font-size:8px"><?php echo $suma; ?></td>
			<td colspan="6" style="width: 10%;padding:2px;text-align:center;border-left:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7; border-bottom:solid 1px #bdc3c7;font-size:8px"></td>
		</tr>
    </table>


    <table cellspacing="0" style="width: 100%;padding-top: 5px;">
        <tr>
            <td style="width: 69%;">
            	<table cellspacing="0" style="width: 100%;">
			        <tr>
						<td style="width: 100%;color:white;background-color:#bdc3c7;padding:2px;text-align:center;"> 
							<strong style="font-size:10px;color: #000" >OBSERVACIONES</strong>
						</td>
					</tr>
				
					<tr>
						<td style="width: 100%;border-left:solid 1px #bdc3c7;border-bottom:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7;">
							<strong style="font-size:8px;"><?php //echo $observaciones;?> </strong>
						</td>
					</tr>
					<tr>
						<td>
							<table cellspacing="0" style="width: 100%;" >
								<tr>
									<td colspan="3" style="width: 100%;padding-bottom: 36px"></td>
								</tr>
								<tr>
									<td style="width: 45%;">_______________________________</td>
									<td style="width: 5%;"></td>
									<td style="width: 45%;">_____________________________</td>	
								</tr>
								<tr>
									<td style="width: 45%;font-size:8px;">Cliente C.C</td>
									<td style="width: 5%;"></td>
									<td style="width: 45%;font-size:8px;">Vendedor C.C</td>		
								</tr>
						    </table>
						</td>
					</tr>
			    </table>
            </td>
            <td style="width: 1%;"></td>
			<td style="width: 30%;">
				<table cellspacing="0" style="width: 100%;">
			        <tr>
						<td colspan="2" style="width: 100%;color:white;background-color:#bdc3c7;text-align:center;padding:2px;"> 
							<strong style="font-size:10px;color: #000" >TOTALES</strong>
						</td>
					</tr>
					<tr>
						<td style="width: 50%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
							NETO
						</td>
						<td style="width: 50%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
							<?php echo number_format($neto,0); ?>
						</td>
					</tr>
					<tr>
						<td style="width: 50%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
							DESCUENTO
						</td>
						<td style="width: 50%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
							<?php echo number_format($total_descuento,0); ?>
						</td>
					</tr>
					<tr>
						<td style="width: 50%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
							IVA
						</td>
						<td style="width: 50%;padding:2px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
							<?php echo number_format($total_iva,0); ?>
						</td>
					</tr>
					<tr>
						<td style="width: 50%;padding:4px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;font-size:10px;text-align:right;"> 
							TOTAL
						</td>
						<td style="width: 50%;padding:4px;text-align:center;border-bottom:solid 1px #bdc3c7;border-left:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7;font-size:11px;text-align:right; color: red;"> 
							<strong><?php echo number_format($sumador_total,0); ?></strong>
						</td>
					</tr>
			    </table>
			</td>
		</tr>
    </table>

   	
    <div style="font-size:8px; padding: 2px;text-align: center;">Impreso por | <?php echo $emp_nombre;?> - VICPOS - <?php echo $emp_url;?></div>
	<div style="width:100%; border-top:dashed 1px;margin-top:1mm;"></div>
	

	
</page>	  