<?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
    FROM transaccion_mercadotecnia as a 
    INNER JOIN mercadotecnia as b ON a.codigo=b.codigo and a.tipo_transaccion='Salida'
    INNER JOIN usuarios as c on a.created_user = c.id_user 
    WHERE a.codigo_transaccion in(" . $cond . ")
    ORDER BY codigo_transaccion DESC")
        or die('Error '.mysqli_error($mysqli));

$count  = mysqli_num_rows($query);*/

$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
					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='Entrada'
					and a.created_user = c.id_user 
					and d.id = a.idenc 
					and a.idenc in(" . $cond . ")
					ORDER BY codigo_transaccion asc")
        or die('Error '.mysqli_error($mysqli));

$count  = mysqli_num_rows($query);





//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'];
$nombre_perfil = $data_perfil['nombre_empresa'];
$direccion_perfil = $data_perfil['direccion'];
$email_perfil = $data_perfil['email'];
$almacen_perfil = $data_perfil['almacen'];
$almacenista_perfil = $data_perfil['almacenista'];




?>
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>ENTRADA DE ALMACEN </title>
		
        <link rel="stylesheet" type="text/css" href="../../../assets/css/laporan.css" />
       
    </head>
    <body>
        <div id="myHeader">
          <?php echo $data_perfil['nombre_empresa'];?>	     
        </div>
        
        <hr><br>    
		 <?php
			 	/*	echo "<img src='http://".$_SERVER['HTTP_HOST']."/cdc/images/logo.png' border='0' width='250' height='110' align=\"center\"><br>";*/
			 
			 ?>
			 
		  <div id="title">
          ENTRADA DE ALMACEN <?php echo $data_perfil['almacen'];?> <br>
		  ( REIMPRESION )
      
        </div>
     
		
		                 

        <div id="myHeader">
              


               <?php
			   
			   $sql_folio=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.name_user,d.txtMotivo,d.txtCorreo,d.status,
					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
					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='Entrada'
					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);
			   $sta = $rw_folio['status'];
			  
               //echo "FOLIO:  ".$rw_folio['folio'];
			   
			   echo  "<div align=\"right\" style='color:#ff0000;font-size:100%;font-weight:bold;'>$folio_perfil - $cond</div><br>";  
			   echo  "<div align=\"right\" style='font-size:90%;font-weight:bold;'>$rw_folio[fecha]</div><br>"; 
			

               $sql_usuario=mysqli_query($mysqli,"select * from usuarios WHERE id_user='$_SESSION[id_user]' ");
               $rw_usuario=mysqli_fetch_array($sql_usuario);
             
				
				echo  "<div align=\"right\" style='color:#ff0000; style='font-size:100%;font-weight:bold;'>$rw_folio[fecha]</div><br>";			   
				echo  "INGRESO:  <br><div align=\"left\" style='color:#14A1F5;style='font-size:90%;font-weight:bold;'>$rw_usuario[name_user]</div>";
				echo  "SE ENVIO A:<br>   <div align=\"left\" style='color:#14A1F5; style='font-size:90%;font-weight:bold;'> $rw_folio[txtCorreo] EL DIA  $rw_folio[fecha]</div>"; 			   
				echo  "OBSERVACION GENERAL: <br> <div align=\"left\" style='color:#14A1F5; style='font-size:90%;font-weight:bold;'> $rw_folio[observacion_enc]</div>"; 
				
			   

              
			 
               
              ?>

        </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>#</small></th>
                        <th height="20" align="center" valign="middle" bgcolor="#005a6f" style="color: #ffffff;"><small>TRANS</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>PRODUCTOS</small></th>
                        <th height="20" align="center" valign="middle" bgcolor="#005a6f" style="color: #ffffff;"><small>CANT</small></th>
                       
                       
                        <th height="20" align="center" valign="middle"bgcolor="#005a6f" style="color: #ffffff;"><small>DETALLE</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='15' height='13' align='center' valign='middle' style='font-size:80%;'>$no</td>
                        <td width='100' height='13' align='center' valign='middle'style='font-size:80%;'>$data[codigo_transaccion]</td>
                        
                        <td width='60' height='13' align='center' valign='middle'style='font-size:80%;'>$data[codigo]</td>
                        <td style='padding-left:5px;' width='180' height='13' valign='middle'style='font-size:80%;'>$data[nombre]</td>
                        <td style='padding-right:10px;' width='30' height='13' align='center' valign='middle'style='font-size:80%;'>$data[numero]</td>
                     
            
						<td width='280' height='13' align='center' valign='middle'style='font-size:80%;'>$data[observaciones]</td>
						
                    
					</tr>";
            $no++;
        }
        ?>  
                </tbody>
            </table>

            
        </div>
<?php



echo "<br>";    
echo "<br>";
if($sta == 'C'){    
  /* echo "<div align='center'>
   <img src='http://".$_SERVER['HTTP_HOST']."/cdc/images/cancelado.png' border='0' width='150' height='180' align=\"center\">
   </div>";*/
}
if($sta == 'A'){    
  /* echo "<div align='center'>
   <img src='http://".$_SERVER['HTTP_HOST']."/cdc/images/entrada.png' border='0' width='450' height='310' align=\"center\">
   </div>";*/
}
/*echo "Recibe:  ".$rw_folio['nombre'];
echo  "<div align=\"center\">$rw_folio[recibe]</div><br>"; 

echo  "<div align=\"center\">_________________________</div><br>"; 
echo "<br>";
echo  "<div align=\"center\">Recibe</div><br>";*/
echo "<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; }
?>