<?php
session_start();
ob_start();





require_once "../../../config/database.php";

include "../../../config/fungsi_tanggal.php";

include "../../../config/fungsi_rupiah.php";

if (!isset($_GET['id'])){
    echo "Favor seleccionar una remision";
    return;  
}
$cond = $_GET['id'];
$created_user = $_SESSION['id_user'];

$hari_ini = date("d-m-Y");

$no = 1;


$query = mysqli_query($mysqli, "
     SELECT a.tipo_transaccion, a.codigo_transaccion,a.fecha,a.codigo,a.numero,
					b.codigo,b.nombre,b.unidad,a.observaciones,a.created_user,c.username, 
					a.idenc,CONCAT(d.serie,d.id) as 'folio',(select nombre_entrega from  transaccion_medicamentos where idenc = (" . $cond . ") limit 1) as 'recibe',d.observacion_enc,d.txtMotivo
					FROM transaccion_medicamentos as a, 
					medicamentos as b,
					usuarios as c,
					transaccion_medicamentos_enc as d
					Where
						a.codigo=b.codigo
					and a.tipo_transaccion='Salida'
					and a.created_user = c.id_user 
					and d.id = a.idenc 
					and a.idenc in(" . $cond . ")
					ORDER BY codigo_transaccion DESC")
        or die('Error '.mysqli_error($mysqli));

$count  = mysqli_num_rows($query);

$sql_folio=mysqli_query($mysqli,"SELECT a.tipo_transaccion,a.status, a.codigo_transaccion,a.fecha,a.codigo,a.numero,
					b.codigo,b.nombre,b.unidad,a.observaciones,a.created_user,c.name_user, 
					a.idenc,CONCAT(d.serie,d.id) as 'folio', e.id as remision ,
                    (select nombre_entrega from  transaccion_medicamentos where idenc = (" . $cond . ") limit 1) as 'recibe',
					d.observacion_enc,d.txtMotivo,d.txtCancel
					FROM transaccion_medicamentos as a, 
					medicamentos as b,
					usuarios as c,
					transaccion_medicamentos_enc as d,
                    remision_encabezado as e
					Where
						a.codigo=b.codigo
                    and e.idSalida = d.folio
					and a.tipo_transaccion='Salida'
					and a.created_user = c.id_user 
					and d.id = a.idenc 
					and a.idenc in(" . $cond . ")
					ORDER BY codigo_transaccion DESC ");
               $rw_folio=mysqli_fetch_array($sql_folio);
               $status= $rw_folio['status'];


               $sql_usuario=mysqli_query($mysqli,"select * from usuarios WHERE id_user='$_SESSION[id_user]' ");
               $rw_usuario=mysqli_fetch_array($sql_usuario);

			   		//Query Encabezado
$queryEnc = mysqli_query($mysqli, "
    SELECT e.* FROM remision_encabezado as e WHERE e.idSalida = '$idenc'")
        or die('Error '.mysqli_error($mysqli));
$rw_encabezado_rem=mysqli_fetch_array($queryEnc);   
$foliorem = $rw_encabezado_rem['folio']; 

//Query parametros perfil
$queryperfil = mysqli_query($mysqli, "SELECT * FROM perfil")
                                or die('error'.mysqli_error($mysqli));
$rows  = mysqli_num_rows($queryperfil);
$data_perfil  = mysqli_fetch_assoc($queryperfil);
$folio_perfil = $data_perfil['folio'];
$folio_rem_perfil = $data_perfil['folio2'];
$nombre_perfil = $data_perfil['nombre_empresa'];
$direccion_perfil = $data_perfil['direccion'];
$direccion_perfil = $data_perfil['direccion'];
$email_perfil = $data_perfil['email'];
$almacen_perfil = $data_perfil['almacen'];
$almacenista_perfil = $data_perfil['almacenista'];

//insertar nombre de quien recibe
$queryrecibe = mysqli_query($mysqli, "
SELECT b.nombre FROM transaccion_medicamentos_enc as a,correos as b WHERE a.txtCorreo = b.tipo and a.id = '$cond' ")
or die('Error '.mysqli_error($mysqli));
$rows  = mysqli_num_rows($queryrecibe);
$data  = mysqli_fetch_assoc($queryrecibe);
/*print_r($data);
die();*/
$recibe = $data['nombre'];

?>
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head>
	 
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title></title>
        <link rel="stylesheet" type="text/css" href="../../../assets/css/laporan.css" />       
    </head>
    <body>
	 
     
			   
		
			<?php
		/*	echo "<img src='http://".$_SERVER['HTTP_HOST']."/images/logo.png' border='0' width='150' height='70' align=\"left\"><br>";	*/				 
			 ?>
			 
			  

		<br>
        <br>
		<br>
        <br>
		<br>
        <br>
		   
       
		
	
		<table width="500px" cellpadding="5px" cellspacing="5px" border="1" style="color: #ffffff;">
    <tr bgcolor="#005a6f">
        <td>RAZON SOCIAL </td>
        <td>DEPARTAMENTO</td>
		<td>ALMACENISTA</td>
        <td>DOCUMENTO</td>
        <td>FECHA</td>
		 <td>FOLIO</td>
    </tr>
    <tr style="color: #ffffff;" style="color: #000000 ;">
              <td align='center'> <?php echo $data_perfil['nombre_empresa'];?> <br><br></td>
		 <td align='center' > <?php echo $data_perfil['almacen'];?> </td>
		 <td align='center'> <?php echo $data_perfil['almacenista'];?> </td>
        <td align='center'>SALIDA</td>
        <td align='center'><?php echo $rw_folio['fecha']?></td>
        <td align='center'style='color:#ff0000;font-size:100%;font-weight:bold;'> <?php echo $folio_perfil;?> - <?php echo$rw_folio['idenc'];?>	</td>
    </tr>
 
</table><br/>


<table width="500px" cellpadding="5px" cellspacing="5px" border="1" style="color: #ffffff;">
    <tr bgcolor="#005a6f">
        <td>AUTORIZA</td>
        <td>MOTIVO DE SALIDA</td>
		<td>ESTATUS</td>
	
    </tr>
    <tr style="color: #ffffff;" style="color: #000000 ;">
        <td align='center'> <?php echo $rw_folio['name_user'];?> <br><br></td>
		 <td align='center' > <?php echo $rw_folio['txtMotivo'];?></td>
		 <td align='center' > <?php 
		 if($status == 'C'){  
			   
				echo "<font style='color:#ff0000;style='font-size:90%;font-weight:bold;'>CANCELADO</font>";
               }
			   
			    if($status == 'A'){  
			   
				echo "<font style='color:#14A1F5;style='font-size:90%;font-weight:bold;'>SALIDA SURTIDA </font>";
               }
		 ?></td>
	
    </tr>
 
</table><br/>

		<table width="500px" cellpadding="5px" cellspacing="5px" border="1" style="color: #ffffff;">  '
    <tr bgcolor="#005a6f">
        <td>DETALLE DE LA SALIDA <?php echo $rw_folio['folio'];?> RELACIONADO CON LA REMISION <?php echo $folio_rem_perfil;?>-<?php echo $rw_folio['remision'];?> </td>
  
    </tr>

 
</table><br/>	
		                 

        <div id="myHeader">
              


               <?php
			   
			   
			  
           
			   
			   //echo  "<div align=\"right\" style='color:#ff0000;font-size:100%;font-weight:bold;'>$rw_folio[folio]</div><br>";  #
			   //echo  "<div align=\"right\" style='font-size:90%;font-weight:bold;'>$rw_folio[fecha]</div><br>"; 
			

            
			   
			   
               
			   //echo  "<div align=\"left\" style='font-size:90%;font-weight:bold;'>ENTREGA: $rw_usuario[name_user]</div><br>"; 
			   
			   //echo  "<div align=\"left\" style='font-size:90%;font-weight:bold;'>AUTORIZA: $rw_folio[name_user]</div>";
			  
              
			   //echo "<br>";
              
			    //echo  "<div align=\"left\" style='font-size:90%;font-weight:bold;'>OBSERVACION GENERAL: $rw_folio[observacion_enc]</div>";
			
			    //echo "<br>";
                //echo "<br>";
				
			   

              
			 
               
              ?>
			  
			 

        </div>


        <div id="myHeader">
		
            <table width="100%" border="0.3" cellpadding="0" cellspacing="0"  >
                <thead style="background:#e8ecee">
                    <tr class="tr-title">
                      <th height="15" align="center" valign="middle" bgcolor="#005a6f" style="color: #ffffff;"><small>PARTIDA</small></th>
					  <th height="20" align="center" valign="middle" bgcolor="#005a6f" style="color: #ffffff;"><small>CANTIDAD</small></th>
					  <th height="20" align="center" valign="middle" bgcolor="#005a6f" style="color: #ffffff;"><small>ARTICULO</small></th>
					  <th height="20" align="center" valign="middle" bgcolor="#005a6f" style="color: #ffffff;"><small>CODIGO</small></th>
                        <th height="20" align="center" valign="middle" bgcolor="#005a6f" style="color: #ffffff;"><small>TRANS</small></th>
                       
                       
                      
						
                    </tr>
                </thead>
                <tbody>

                    <br>  
             <br>
             <br>


        <?php


      
        while ($data = mysqli_fetch_assoc($query)) {
        #    $precio_compra = format_rupiah($data['precio_compra']);
         #   $precio_venta = format_rupiah($data['precio_venta']);
          
            echo "  <tr> 
                      <td width='20' height='13' align='center' valign='middle' style='font-size:80%;'>$no</td>
						 <td style='padding-right:10px;' width='30' height='13' align='center' valign='middle'style='font-size:80%;'>$data[numero]</td>
						    <td style='padding-left:5px;' width='380' height='13' valign='middle'style='font-size:80%;'>$data[nombre]</td>
							 <td width='145' height='13' align='center' valign='middle'style='font-size:80%;'>$data[codigo]</td>
                        <td width='100' height='13' align='center' valign='middle'style='font-size:80%;'>$data[codigo_transaccion]</td>
						
                    
					</tr>";
            $no++;
        }
        ?>  
                </tbody>
            </table>
             <?php
			  /*if($status == 'C'){    
				   echo "<div align='center'>
				  <!-- <img src='http://".$_SERVER['HTTP_HOST']."/cdc/images/cancelado.png' border='0' width='150' height='170' align=\'center\'>  -->
				   </div>
				   <br>
					<br>
				   <table>
					<tr >
					
					<td align='center'style='color:#ff0000;font-size:100%;font-weight:bold;'>MOTIVO DE CANCELACION:</td>
					</tr>
					<tr >
					<td align='center'style='color:#ff0000;font-size:100%;font-weight:bold;'>$rw_folio[txtCancel]</td>
					</tr>
				   </table><br/>
				   ";
				}*/
				
			  ?>

            
        </div>
<?php

echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";



?>


	<table width="500px" cellpadding="5px" cellspacing="5px" border="1" style="color: #ffffff;">
    <tr bgcolor="#005a6f">
        <td>OBSERVACIONES___________________________________________________________</td>
        <td>FIRMA DE RECIBIDO</td>
    </tr>
    <tr style="color: #ffffff;" style="color: #000000 ;">
     
        <td><?php echo $rw_folio['observacion_enc'];?>
		<br><br><br><br><br><br>
		</td>
		<td><br><br><br>   <?php echo $recibe ?><br><br><br>
		
		</td>
       
    </tr>
 
</table><br/>

    </body>
</html>



<?php
$filename="$folio_perfil-$cond.pdf"; 


//==========================================================================================================
$content = ob_get_clean();
$content = '<page style="font-family: freeserif">'.($content).'</page>';

require_once('../../../assets/plugins/html2pdf_v4.03/html2pdf.class.php');
try
{
    $html2pdf = new HTML2PDF('P','F4','en', false, 'ISO-8859-15',array(10, 10, 10, 10));
    $html2pdf->setDefaultFont('Arial');
    $html2pdf->writeHTML($content, isset($_GET['vuehtml']));
    $html2pdf->Output($filename);
}
catch(HTML2PDF_exception $e) { echo $e; }
?>