<?php
$cot_id=$_GET['cot_id'];
$query=mysqli_query($con, "SELECT *  , DATE_FORMAT(cot_fecha, '%d-%m-%Y') AS nueva_fecha  from dis_cotizacion where cot_id='$cot_id' ");
$roww=mysqli_fetch_array($query);
$cliente_id=$roww['dis_cliente_clie_id'];
$ven_fecha=$roww['nueva_fecha'];
$ven_n_venta=$roww['cot_n_cotizacion'];
$cot_dias=$roww['cot_validez'];

$canc=mysqli_query($con,"SELECT * FROM dis_cliente where clie_id='$cliente_id' ") or die(mysqli_error($con)); 
$datoc=mysqli_fetch_array($canc);
$ven_cc=$datoc['clie_cc'];
$ven_nombre=$datoc['clie_nombre'];
$clie_direccion=$datoc['clie_direccion'] ?? '';
$clie_telefono=$datoc['$clie_telefono'] ?? '';
$clie_correo=$datoc['$clie_correo'] ?? '';

?>

<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: 48%; color: #444444;">
                <img style="width: 60%;" src="../../../img/<?php echo $distribuidor;?>.png" alt="Logo"><br>
            </td>
             <td style="width: 12%; color: #444444;">
            </td>
			<td style="width: 40%;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_regimen; ?> </strong><br> 
				<strong><?php echo $emp_direccion;?></strong><br>
				<strong><?php echo $emp_correo;?></strong><br>
				<strong>Tel: <?php echo $emp_telefono;?></strong><br>
				<!--<strong>Agente de retención en el impuesto sobre las ventas</strong>-->
			</td>
        </tr>
    </table>
	<hr style="display: block;height: 1px;border: 1px solid #bdc3c7;">
 	<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 $ven_nombre;?></p>
							<p style="padding:-10px;"><strong>DOCUMENTO: </strong><?php echo $ven_cc;?></p>
							<p style="padding:-10px;"><strong>DIRECCION: </strong><?php echo $clie_direccion;?> <?php //echo mb_strtoupper($clie_barrio);?> <?php // echo mb_strtoupper($name);?></p>
							<p style="padding:-10px;"><strong>TELEFONO: </strong><?php echo $clie_telefono;?></p>
							<p style="padding:-10px;"><strong>CORREO: </strong><?php echo $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">COTIZACION 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 $ven_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 $ven_fecha;?></p>
							<p style="padding:-10px;"><strong>VALIDEZ: </strong><?php echo $cot_dias;?></p>
							<p style="padding:-10px;"><strong>VENDEDOR: </strong><?php echo $clie_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: 61%; 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 IVA INCL</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

    $cot_id=$roww['cot_id'];


    $descuentof=0;
    $descuento=0;
    $neto=0;
    $sumador_total=0;
    $iva_total=0;

   


    $sql=mysqli_query($con, "SELECT * from  dis_cotizacion_detalle where dis_cotizacion_cot_id='$cot_id' ");
    while ($row=mysqli_fetch_array($sql))
    {
    $id=$row["cotd_id"];
    $cotd_id=$row["cotd_id"];
    $cotd_referencia=$row['cotd_referencia'];
    $cotd_nombre=$row['cotd_nombre'];
    $cotd_cantidad=$row['cotd_cantidad'];
    $cotd_precio=$row['cotd_precio'];
    $cotd_iva=$row['cotd_iva'];
    $cotd_descuento=$row['cotd_desc'];

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

    $precio_u_sin_iva=$cotd_precio/$iva1;
    $precio_unidad=$precio_u_sin_iva;

    $precio_t_sin_iva=$precio_unidad*$cotd_cantidad;

    $descuento=($cotd_descuento/100)*$precio_t_sin_iva;

    $precio_descuento_t=$precio_t_sin_iva-$descuento;

    $total_iva_u=$precio_descuento_t*$iva0;

    $iva_total+=$total_iva_u;

    $neto+=$precio_t_sin_iva;

    $descuentof+=$descuento;

    $sumador_total=($neto+$iva_total)-$descuentof;

    if (($id % 2) == 0) {
    //Es un número par
  	$color='#fff';
} else {
    //Es un número impar
    $color='#F3F2F2';
}
?>		
		<tr style="background:<?php echo $color;?>">
			<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: 61%;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($cotd_precio,0);?>
			</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_t_sin_iva,0);?>
			</td>
		</tr>
<?php } ?>		
<tr>
			<td colspan="2" style="padding:2px;text-align:right;border-left:solid 1px #bdc3c7;border-bottom:solid 1px #bdc3c7;font-size:7px">Total Unidades</td>
			<td  style="padding:2px;text-align:center;border-left:solid 1px #bdc3c7;border-bottom:solid 1px #bdc3c7;font-size:8px"><?php // echo $suma; ?></td>
			<td colspan="3"  style="padding:2px;text-align:left;border-left:solid 1px #bdc3c7;border-bottom:solid 1px #bdc3c7;border-right:solid 1px #bdc3c7;font-size:8px"></td>
		</tr>
    </table>


    <table cellspacing="0" style="width: 100%;padding-top: 5px;">
        <tr>
            <td style="width: 64%;">
            	<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  $roww['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: 35%;">
				<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($descuentof,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($iva_total,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:10px;text-align:right;"> 
							<?php echo number_format($sumador_total,0); ?>
						</td>
					</tr>
			    </table>
			</td>
		</tr>
    </table>
  
	
	<div style="font-size:8px; padding: 2px;text-align: center;">Impreso por | <?php // echo $emp_nombre;?> - VICPOS - www.vicpos.com</div>
	<div style="width:100%; border-top:dashed 1px;margin-top:1mm;"></div>
	
</page>	  