<?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=$_POST['id_pedido_proforma'];
$port=$_POST['port'];
$destination=$_POST['destination'];
$fob_china=$_POST['fob_china'];
$payment=$_POST['payment'];
$packing=$_POST['packing'];






$query="SELECT `id_pedido`, `orden`, `fecha_pedido`, left(`fecha_pedido`, 4) ayo, SUBSTRING(`fecha_pedido`, 6, 2) mes, SUBSTRING(`fecha_pedido`, 9, 2) dia, `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"];
$forma_pago=$row["forma_pago"];
$embalaje=$row["embalaje"];
$ciudad=$row["ciudad"];
$telefono=$row["telefono"];
$id_pedido2=$row["id_pedido"];
$nit=$row["nit"];
$direccion=$row["direccion"];
$ayo=$row["ayo"];
$mes=$row["mes"];
$dia=$row["dia"];

$fechaped =$ayo."-".$mes."-".$dia; 


$date = new DateTime($fechaped);
$fechaped= $date->format('M d, Y');


$date = new DateTime($fechaped);
$ayo= $date->format('y');



$fechaped=date("d-M-y");
//style=" Background-color:#ECEAEA; border-width: 3px;border-right: solid; border-color:#FFFFFF;font-size:18px "

$html .=' 



<html>
<head>
<title>Comercial Invoice # '.$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>COMERCIAL INVOICE</b>
</span>
</td>
</tr>
<tr>
<td align=center>
<span style="font-size:12px;width:100%; text-align:center">
<b>  This contract is made by and between the Buyers and the Sellers; whereby the Buyers agree to buy and the Sellers agree to sell the under-mentioned goods subject to the terms and conditions as stipulated hereinafter:</b>
</span>
</td>
</tr>
</table>
</div>


 <div style="position: absolute; right: 2.5em; top:8em; left: 2.5em; ">

<table width=100% border=1 style="font-style:italic; border-collapse: collapse;border-width: thin; border-style:solid; font-size:13px;">
<tr>

<td valign=top align=left rowspan=2 colspan=2>
<b>1. Shipper/exporter </b><br>
QINGDAO QIXIANG INTERNATIONAL TRADING CO., LIMITED  <br>
#19128, B BUILDING, WONDER PLAZA,KEQIAO  <br>
SHAOXING,ZHEJIANG,CHINA <br>
Tel: +86-575-81101766          <br>       FAX: 86-575-88322672 <br> 

</td>

<td valign=top align=left>
<b>8. No & date of invoice</b><br>
('. $orden.')   - 
'. $fechaped.'
</td>
</tr>
<tr>

<td valign=top align=left>
<b>9. No & date of L/C</b><br>
T/T BASE<br><br>
</td>


</tr>

<tr>
<td valign=top align=left colspan=2>
<b>2. Consignee</b><br>
'.$nombre.' <br>
NIT: '.$nit .'<br>
PHONE: '.$telefono .'<br>

ADDRESS: '.$direccion .'<br>
</td>
<td valign=top align=left>
<b>10. Manufactory</b><br>
QINGDAO QIXIANG INTERNATIONAL TRADING CO.,LIMITED<br>
#19128, B BUILDING ,WONDER PLAZA,KEQIAO, SHAOXING<br>
ZHEJIANG ,CHINA

</td>
</tr>
<tr>
<td valign=top align=left colspan=2>
<b>3. Notify party</b><br>
'.$nombre.' <br>
NIT: '.$nit .'<br>
PHONE: '.$telefono .'<br>

ADDRESS: '.$direccion .'<br>
</td>
<td valign=top align=left rowspan=3>
<b>11. Remarks</b><br>
1. COUNTRY OF ORIGIN : CHINA  <br>
2. PAYMENT : '.$payment.'<br>
3. INSURANCE : TO BE COVERED BY BUYER <br>  
4. PACKING: '. $packing.'<br>
5. PARTIAL SHIPMENT : NOT ALLOWED  <br> 
6. DELIVERY : ABOUT 30 DAYS AFTER ADVANCE PAYMENT & L/DIP CFM. <br> 
7. 10% MORE OR LESS IN QUANTITY AND VALUE TO BE ACCEPTED. <br>
</td>


</tr>

<tr>
<td valign=top align=left >
<b>4. Port of loading</b><br>
'.$port .'

</td>
<td valign=top align=left>
<b>5. Final destination</b><br>
'.$destination .'
</td>

</tr>
<tr>
<td valign=top align=left >
<b>6. Carrier</b><br>
BY BOAT (SEA)
</td>
<td valign=top align=left>
<b>7. Salling on or about</b><br>

</td>
</tr>
</table>
</div>


';

$costo_t=0;
$servicios="";
$i=0;
$pedido=$_GET['id'];

    if {
    $consulta="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_ref FROM `importado_items` inner join  referencias on id_ref=descripcion where orden_pedido ='$id_pedido' order by id_item asc";

    $resultado2=$conexion-> query ($consulta);
    while ($row1=$resultado2->fetch_assoc()){
      $i=$i+1;
      
    $provee1= $row1['supplier'];
  $id_item=$row1['id_item'];
      
///buscando cantidad en item color
$consulta_color="SELECT sum(q_real) q_real FROM `importado_items_color` where id_pedidos_items='$id_item'";
$resultado_color=$conexion-> query ($consulta_color);
$row_color=$resultado_color->fetch_assoc();
$total_qty_real=$row_color['q_real'];

       }
    }  
    else
        {
  $consulta="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_ref FROM `importado_items` inner join referencias on id_ref=descripcion WHERE NOT EXISTS ( SELECT NULL FROM importado WHERE orden_pedido ='$id_pedido') order by id_item asc";

  $resultado2=$conexion-> query ($consulta);
    while ($row1=$resultado2->fetch_assoc()){
      $i=$i+1;
      
    $provee1= $row1['supplier'];
  $id_item=$row1['id_item'];
      
///buscando cantidad en item color
$consulta_color="SELECT sum(q_real) q_real FROM `importado_items_color` where id_pedidos_items='$id_item'";
$resultado_color=$conexion-> query ($consulta_color);
$row_color=$resultado_color->fetch_assoc();
$total_qty_real=$row_color['q_real'];

       }
    }


////buscando



      $costo= ($row1['quantity']  * $row1['price_usd']);




if (strtoupper($row1["um"]=='KILOS') ||  strtoupper($row1["um"]=='KILO'))  {

$imprimir="KL";
}
else
{
  $imprimir="MT";
}
    

    
    
      $servicios.="<tr>

<td align=left valign=top height=25px >ITEM: ".$i. " " . strtoupper($row1['nombre_ref']). " WEIGHT: ". $row1['weight']. " GSM WIDTH: ". $row1['width'] ." CM<br>".strtoupper($row1['remark'])."</td>
<td align=right valign=top height=25px>".number_format($row1['quantity'],0,".",",")." " . strtoupper($imprimir) ."</td>
<td align=right valign=top height=25px> U$ ".number_format($row1['price_usd'], 2, '.', ',')."/" . strtoupper($imprimir) ."</td>
<td align=right valign=top height=25px> = USD$ ".number_format($costo, 2, '.', ',')."</td>
</tr>";
$costo_t=$costo_t+$costo;


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


   <table width='100%' border='0' style='font-style:italic, border-collapse: collapse; font-size:12px' class='table table-bordered table-condensed table-hover'>
<tr>
<td align=left width=45% height=30px style='font-style:italic'><b>12.  Marks & no.of pkgs     </b> <span style='margin-left:120px' ><b>           13. Description of goods</b></span></td>
<td align=center width=10% height=30px style='font-style:italic'><b>14.   Q'ty/unit</b></td>
<td align=center width=15% height=30px style='font-style:italic'><b>15. Unit Price/FOB</b></td>
<td align=center width=15% height=30px style='font-style:italic'><b>16. Amount (USD)</b></td>
</tr>
<tr>
<td align=left width=45% height=30px style='font-style:italic'></td>
<td align=center width=10% height=30px style='font-style:italic'><b>".$fob_china."</b></td>
<td align=center width=15% height=30px style='font-style:italic'></td>
<td align=center width=15% height=30px style='font-style:italic'></td>
</tr>


 ".$servicios."
<tr>
<td colspan=2 rowspan=3 align=left valign=top ></td>
<td align=center height=30px style='background: rgba(226, 226, 226, 0.15); font-weight: bold;'>TOTAL AMOUNT</td>
<td align=right>  USD $ ". number_format($costo_t, 2, ',', '.')."</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>BANK DETAILS:</b> <br> 

  
BENEFICIARY:<b> QINGDAO QIXIANG INTERNATIONAL TRADING CO., LIMITED</b><br> 
ADDRESS:<b> #19128, B BUILDING ,WONDER PLAZA,KEQIAO,, SHAOXING, ZHEJIANG, CHINA  </b><br>
BENEFICIARY BANK:<b> CHINA ZHESHANG BANK, SHAOXING BRANCH  </b><br>
ADDRESS:<b> NO. 1418 JINKEQIAO AVENUE KEQIAO DISTRICT SHAOXING,ZHEJIANG PROVINCE ,P.R.CHINA  </b><br>
SWIFT BIC:<b> ZJCBCN2N </b><br>
ACCOUNT NUMBER:<b> 3371020011420100059665  </b><br>
INTERMEDIARY INSTITUTION:<b> JPMORGAN CHASE BANK, NEW YORK </b><br>
SWIFT:<b> CHASUS33 </b><br>

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

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