<?php 
	session_start();
	if (!isset($_SESSION['user_login_status']) AND $_SESSION['user_login_status'] != 1) {
        header("location: ../../login.php");
		exit;
    }
	/* Connect To Database*/
	include("../../config/db.php");
	include("../../config/conexion.php");
	$id_proforma= intval($_GET['id_proforma']);
	$sql_count=mysqli_query($con,"select * from proformas where id_proforma='".$id_proforma."'");
	$count=mysqli_num_rows($sql_count);
	if ($count==0)
	{
	echo "<script>alert('Proforma no encontrada')</script>";
	echo "<script>window.close();</script>";
	exit;
	}
	$sql_proforma=mysqli_query($con,"select * from proformas where id_proforma='".$id_proforma."'");
	$rw_proforma=mysqli_fetch_array($sql_proforma);
	$numero_proforma=$rw_proforma['numero_proforma'];
	$id_cliente=$rw_proforma['id_cliente'];
	$id_vendedor=$rw_proforma['id_vendedor'];
	$fecha_proforma=$rw_proforma['fecha_proforma'];
	
	?>
	
<page backtop="10mm" backbottom="10mm" backleft="20mm" backright="20mm">
    <page_header>
        <table style="width: 100%; border: solid 1px black;">
            <tr>
                <td style="text-align: left;    width: 33%">FONTUR</td>
                <td style="text-align: center;    width: 34%">Proforma</td>
                <td style="text-align: right;    width: 33%"><?php echo date('d/m/Y'); ?></td>
            </tr>
        </table>
    </page_header>
    <page_footer>
        <table style="width: 100%; border: solid 1px black;">
            <tr>
                <td style="text-align: left;    width: 50%">FONTUR</td>
                <td style="text-align: right;    width: 50%">page [[page_cu]]/[[page_nb]]</td>
            </tr>
        </table>
    </page_footer>
    <table style="width:100%;">
        <tr>
            <td style="width: 100%; color: #444444;">
            <img style="width: 100%;" src="../../img/cintillo-cedil.png" alt="Logo">
            </td>
        </tr>
    </table>
    <br>
	<br>
    <table cellspacing="0" style="width: 100%;">
        <tr>
      <td style="width: 25%;">
      </td>
	  <td style="width: 50%;font-size:12px;text-align:center">
      </td>
	<td style="width: 25%; font-size:12px;text-align:right">RIF J-40296166-9
	</td>	
        </tr>
    </table>
    <br>
    
    <table cellspacing="0" style="width: 100%; border-color:transparent;">
        <tr>

            <td style="width: 25%;">
                <img style="width: 100%;" src="../../img/logofontur.png" alt="Logo"><br>
                
            </td>
			<td style="width: 50%; color: #34495e;font-size:12px;text-align:center">
                <span style="color: #34495e;font-size:14px;font-weight:bold"><?php echo NOMBRE_EMPRESA;?></span>
				<br><?php echo DIRECCION_EMPRESA;?><br> 
				Teléfono: <?php echo TELEFONO_EMPRESA;?><br>
				Email: <?php echo EMAIL_EMPRESA;?>
                
            </td>
			<td style="width: 25%;text-align:right">
			COTIZACION Nº <?php echo $numero_proforma;?>
			</td>
			
        </tr>
    </table>
    <br>
    
<table cellspacing="0" style="width: 50%; text-align: left; font-size: 11pt;">
        <tr style="border:#000;">
           <td style="width:35%; border:#000;" class='midnight-blue'>VENDEDOR</td>
		  <td style="width:25%; border:#000;" class='midnight-blue'>FECHA</td>
		   
        </tr>
		<tr>
           <td style="width:35%; border:#000;">
			<?php 
				$sql_user=mysqli_query($con,"select * from users where user_id='$id_vendedor'");
				$rw_user=mysqli_fetch_array($sql_user);
				echo $rw_user['firstname']." ".$rw_user['lastname'];
			?>
		   </td>
		  <td style="width:25%; border:#000;"><?php echo date("d/m/Y", strtotime($fecha_proforma));?></td>
		   		
		  
        </tr>
		
        
   
    </table>
    <br>
	
   <?php $sql_cliente=mysqli_query($con,"select * from clientes where id_cliente='$id_cliente'");
				$rw_cliente=mysqli_fetch_array($sql_cliente);
   ?> 
	<table cellspacing="0" style="width: 100%; text-align: left; font-size: 11pt;">
        <tr>
           <td style="width:25%; border:#000;" class='midnight-blue'>NOMBRE O RAZON SOCIAL</td>
           <td style="width:75%; border:#000;">
           <?php echo $rw_cliente['nombre_cliente'];?>
           </td>
        </tr>
        </table>
   <table cellspacing="0" style="width: 100%; text-align: left; font-size: 11pt;">     
		<tr>
           <td style="width:25%; border:#000;" class='midnight-blue'>RIF
          </td>
   <td style="width:25%; border:#000;">
           <?php echo $rw_cliente['rif_cliente'];?>
          </td>
    <td style="width:25%; border:#000;" class='midnight-blue'>TELEFONO
    </td>
    <td style="width:25%; border:#000;">
    <?php echo $rw_cliente['telefono_cliente'];?>
    </td>
    </tr>
    </table>
    <table height="36" cellspacing="0" style="width: 100%; text-align: left; font-size: 11pt;">
    <tr>
    <td style="width:25%; border:#000;" class='midnight-blue'>DIRECCION FISCAL
    </td>
    <td style="width:75%; border:#000;">
     <?php 	echo $rw_cliente['direccion_cliente'];?>
    </td>        
   </tr>
    </table>
	<br>
  
    <table cellspacing="0" style="width: 100%; border:#000; text-align: left; font-size: 10pt;">
        <tr>
            <th style="width: 5%; border:#000; text-align:center" class='midnight-blue'>NRO</th>
            <th style="width: 50%; border:#000;" class='midnight-blue'>ARTICULO</th>
            <th style="width: 18%; border:#000; text-align: right" class='midnight-blue'>PRECIO UNIT.</th>
            <th style="width: 7%; border:#000; text-align: right" class='midnight-blue'>CANT</th>
            <th style="width: 20%; border:#000; text-align: right" class='midnight-blue'>MONTO</th>
            
        </tr>

<?php
$nums=1;
$sumador_total=0;
$sql=mysqli_query($con, "select * from products, detalle_proforma, proformas where products.id_producto=detalle_proforma.id_producto and detalle_proforma.numero_proforma=proformas.numero_proforma and proformas.id_proforma='".$id_proforma."'");

while ($row=mysqli_fetch_array($sql))
	{
	$id_producto=$row["id_producto"];
	$codigo_producto=$row['codigo_producto'];
	$cantidad=$row['cantidad'];
	$nombre_producto=$row['nombre_producto'];
	
	$precio_venta=$row['precio_venta'];
	$precio_venta_f=number_format($precio_venta,1);//Formateo variables
	$precio_venta_r=str_replace(",","",$precio_venta_f);//Reemplazo las comas
	$precio_total=$precio_venta_r*$cantidad;
	$precio_total_f=number_format($precio_total,1);//Precio total formateado
	$precio_total_r=str_replace(",","",$precio_total_f);//Reemplazo las comas
	$sumador_total+=$precio_total_r;//Sumador
	if ($nums%2==0){
		$clase="clouds";
	} else {
		$clase="silver";
	}
	?>

        <tr>
            <td class='<?php echo $clase;?>' style="width: 5%; border:#000;  text-align: center"><?php echo $nums; ?></td>
            <td class='<?php echo $clase;?>' style="width: 50%; border:#000; text-align: left"><?php echo $nombre_producto;?></td>
            <td class='<?php echo $clase;?>' style="width: 18%; border:#000; text-align: right">$ <?php echo $precio_venta_f;?></td>
            <td class='<?php echo $clase;?>' style="width: 7%; border:#000; text-align: right"><?php echo $cantidad;?></td>
            <td class='<?php echo $clase;?>' style="width: 20%; border:#000; text-align: right">$ <?php echo $precio_total_f;?></td>
            
        </tr>

	<?php 

	
	$nums++;
	}
	$subtotal=number_format($sumador_total,1,'.','');
	//$total_iva=($subtotal * TAX )/100;
	//$total_iva=number_format($total_iva,1,'.','');
	//$total_proforma=$subtotal+$total_iva;
	$total_proforma=$subtotal;
?>
	  
        <tr>
        <td style="widtd: 15%; text-align: right;">
            
            </td>
       <td colspan="3" style="widtd: 85%; text-align: right;">SUBTOTAL $ </td>
            <td style="widtd: 15%; text-align: right;">
            <?php echo number_format($subtotal,2);?>
            </td>
        </tr>
		<tr><td style="widtd: 15%; text-align: right;"></td>
            <td colspan="3" style="widtd: 85%; text-align: right;">IVA (<?php //echo TAX; ?>)0% $ </td>
            <td style="widtd: 15%; text-align: right;"> 0<?php //echo number_format($total_iva,2);?></td>
        </tr><tr>
        <td style="widtd: 15%; text-align: right;"></td>
            <td colspan="3" style="widtd: 85%; text-align: right;">TOTAL A PAGAR $ </td>
            <td style="widtd: 15%; text-align: right;"> <?php echo number_format($total_proforma,1);?></td>
        </tr>
    </table>
	
	
	
	<br>
	<div style="font-size:11pt;text-align:center;font-weight:bold">
    Esta Cotizacion Vence a las 24 horas desde su momento de expedición</div>
	
	
	  

</page>

