<?php 
date_default_timezone_set("America/Caracas" );
 require_once('mpdf/mpdf2.php');

$mpdf = new mPDF('es');
$mpdf = new mPDF('win-1252', 'letter','','',5,5,5,5,5,5,'P');
$mpdf -> useOnlyCoreFonts=true;
$mpdf -> watermark_font = 'Arial';
$mpdf=new mPDF();


//$fecha=date("d/m/Y");

                                             include("conexion.php");

$id_pedido=$_REQUEST['id'];
$id_supplier=$_REQUEST['id_supplier'];



$query="SELECT `id_pedido`, `orden`, `fecha_pedido`, `fecha_final`, `cliente`, `forma_pago`, `embalaje`, nombre, ciudad, telefono, nit, direccion FROM `importado` inner join  clientes on id=cliente WHERE id_pedido='$id_pedido'";
$result=$conexion-> query ($query);
$row=$result->fetch_assoc();

  $fecha_pedido=$row["fecha_pedido"];
$nombre=strtoupper($row["nombre"]);
$orden=$row["orden"];



//style=" Background-color:#ECEAEA; border-width: 3px;border-right: solid; border-color:#FFFFFF;font-size:18px "

$html .=' 



<html>
<head>
<title>Purchase No '.$orden.'</title>
<style type="text/css">
.table-striped > tbody > tr:nth-of-type(odd) {
  background-color: #f9f9f9;
}
</style>
</head>

<body>
 <div style="position: absolute; right: 2.5em; top:2em; left: 2.5em; font-size:10px;">
<table width=100%>
<tr align=center>
<td align=center>
<span style="font-size:18px;width:100%; text-align:center">
<b>QINGDAO QIXIANG INTERNATIONAL TRADING CO., LIMITED </b>
</span>
</td>
</tr>
<tr>
<td align=center>
<span style="font-size:18px;width:100%; text-align:center">
<b>Purshase Orders # '. $orden.' </b>
</span>
</td>
</tr>
<tr>
<td align=center>
<span style="font-size:12px;width:100%; text-align:center">
<b>  <!-- espacio para texto --></b>
</span>
</td>
</tr>
</table>
</div>




';

 $cant_color=0;
$servicios="";
$i=0;
$pedido=$_GET['id'];
$ref2="";
$ref="";
$consulta="SELECT `id_pedidos_color`, `id_pedidos_items`, `color`, importado_items_color.`quantity` quantity, nombre_ref, descripcion, q_real FROM `importado_items_color` inner join importado_items on id_item=id_pedidos_items inner join referencias on descripcion=id_ref where supplier='$id_supplier' and orden_pedido ='$id_pedido' order by descripcion";


$resultado2=$conexion-> query ($consulta);


     while ($row1=$resultado2->fetch_assoc()){


$ref2=$row1['descripcion'];
$items2=$row1['id_pedidos_items'];

 


if ($ref2!=$ref)
{
  $i=0;


        $query_item="SELECT `id_item`, `orden_pedido`, `descripcion`, `supplier`, `um`, `width`, `weight`, `meter`, `quantity`, `precio_compra`, `price_usd`, `fob`, `cap_hq`, `porc_ocup`, `seis_ocho`, `cent`, `cent_usd`, `com_colim`, `total_com`, `bon_fab`, `total_bon_fab`, `total_ganac`, `fecha_prod`, `remark`, nombre FROM `importado_items` inner join clientes on id=supplier where orden_pedido='$id_pedido' and descripcion='$ref2' and id_item='$items2'";
        //$html .="ver".$query_item;
$result_item=$conexion-> query ($query_item);
$row_item=$result_item->fetch_assoc();

  $quantity=$row_item["quantity"];
$supplier=strtoupper($row_item["nombre"]);
$um=$row_item["um"];
$width=$row_item["width"];
$weight=$row_item["weight"];
$meter=$row_item["meter"];
$price_usd=$row_item["precio_compra"];
$total=$row_item["precio_compra"]*$row_item["quantity"];
$fecha_prod=$row_item["fecha_prod"];
$total_ganac=$row_item["total_ganac"];
$remark=$row_item["remark"];



  $servicios.="
  <tr>
<td style='color:white; font-weight: bold; font-size:22px' >,</td>
</tr>
<tr>
<td colspan=3 style='background: rgba(226, 226, 226, 0.15); font-weight: bold;' ><b> ITEM DESCRIPTION: ".$row1['nombre_ref']." </b></td>
</tr>
</table>

<table width=100%>
<tr>
<td align=center style='background: rgba(145, 140, 142, 0.15); font-weight: bold;' ><b>Quantity</b></td>
<td align=center style='background: rgba(145, 140, 142, 0.15); font-weight: bold;' ><b>Supplier</b></td>
<td align=center style='background: rgba(145, 140, 142, 0.15); font-weight: bold;' ><b>U.M.</b></td>
<td align=center style='background: rgba(145, 140, 142, 0.15); font-weight: bold;' ><b>Width</b></td>
<td align=center style='background: rgba(145, 140, 142, 0.15); font-weight: bold;' ><b>Weight</b></td>
</tr>
<tr>
<td align=center  >".$quantity." </td>
<td align=center  >".$supplier." </td>
<td align=center  >".$um." </td>
<td align=center  >".$width." </td>
<td align=center  >".$weight." </td>
</tr>

<tr>
<td align=center style='background: rgba(145, 140, 142, 0.15); font-weight: bold;' ><b>Meter per Kilo</b></td>
<td align=center style='background: rgba(145, 140, 142, 0.15); font-weight: bold;' ><b>Price USD</b></td>
<td align=center style='background: rgba(145, 140, 142, 0.15); font-weight: bold;' ><b>Total FOB (USD)</b></td>
<td align=center style='background: rgba(145, 140, 142, 0.15); font-weight: bold;' ><b>Final Production Date</b></td>
<td align=center style='background: rgba(145, 140, 142, 0.15); font-weight: bold;' ><b>Remark</b></td>
</tr>

<tr>
<td align=center  >".number_format($meter,2,".",",")." </td>
<td align=center  >".number_format($price_usd,2,".",",")." </td>
<td align=center  >".number_format($total,2,".",",")." </td>
<td align=center  >".$fecha_prod." </td>
<td align=center  >".$remark." </td>
</tr>
</table>
<br>
<br>
<table width=100%>
<tr>
<td align=center width=15%  style='background: rgba(145, 140, 142, 0.15); font-weight: bold;'>#</td>
<td align=center width=60%  style='background: rgba(145, 140, 142, 0.15); font-weight: bold;'>NAME OF COLOR</td>
<td align=center width=25%  style='background: rgba(145, 140, 142, 0.15); font-weight: bold;'>QUANTITY</td>
</tr>

";
 
}

  $i=$i+1;


$ref=$row1['descripcion'];



    
      $servicios.="<tr>

<td align=center height=25px> COLOR ".$i."</td>
<td align=left height=25px >".$row1['color']."</td>
<td align=right height=25px>".number_format($row1['q_real'],0,".",",")."</td>

</tr>";
$cant_color=$cant_color+$row1['q_real'];


     }
   $html.= "
 <div style='position: absolute; right: 2.5em; top:8em; left: 2.5em; '>


   <table width='100%' border='0' style='font-style:italic, border-collapse: collapse;' class='table table-bordered table-condensed table-hover'>

 ".$servicios."
</table>


<table width=100%>
 <tr><td align=right colspan=2 height=30px style='background: rgba(226, 226, 226, 0.15); font-weight: bold; '>TOTAL QTY</td>
<td align=right width=25%  style='background: rgba(226, 226, 226, 0.15); font-weight: bold;' >  ". number_format($cant_color,0,".",",")."</td>
</tr>
</table>
</div>
";

 $html.= "
 <div style='position: absolute; right: 2.5em; bottom:1em; left: 2.5em; font-size:10px;'>


 <div style='Background-color:white; width:100%'>_______________________________________________________________________________________________________________________________________________________________________________</div>

<table width=100% style='font-size:12px'>
<tr>
<td>
<b> QINGDAO QIXIANG INTERNATIONAL TRADING CO., LIMITED</b><br> 
<b> #19128, B BUILDING ,WONDER PLAZA,KEQIAO,, SHAOXING, ZHEJIANG, CHINA  </b><br>


</td>
</tr>
</table>
</div>
</div>
 </body>
 </html>
";

 $mpdf->WriteHTML($html);
 /// D descargar, I ver en linea
 $nombre="Purchase No ".$orden.".pdf";
$mpdf->Output($nombre,'I');
exit;
 ?>