<?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'];
$final=$_REQUEST['final'];
$origen=$_REQUEST['origen'];
$entrega=$_REQUEST['entrega'];
$payment=$_REQUEST['payment'];
$packing=$_REQUEST['packing'];
$bancos=$_REQUEST['bancos'];

$query="SELECT `id_pedido`, `orden`, 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 `pedidos` 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; 
$fechaped =date("Y")."-".date("m")."-".date("d"); 


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


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


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

$html .=' 



<html>
<head>
<title>Proforma # '.$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>SALES CONTRACT</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. Seller </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>7. No & date of S/C</b><br>
<!-- QXC'.$ayo.''.$mes.''.$dia.' ( --> '. $orden.'    <br>
'. $fechaped.'  
</td>
</tr>
<tr>
<td valign=top align=left>
<b>8. No & date of L/C</b><br>
T/T BASE<br><br>
</td>
</tr>
<tr>
<td valign=top align=left colspan=2>
<b>2. Buyers</b><br>
'.$nombre.' <br>
NIT: '.$nit .'<br>
PHONE: '.$telefono .'<br>

ADDRESS: '.$direccion .'<br>
</td>
<td valign=top align=left>
<b>9. Notify party</b><br>
Same as Buyer
</td>
</tr>
<tr>
<td valign=top align=left >
<b>3. Port of loading</b><br>
'.$origen.'

</td>
<td valign=top align=left>
<b>4. Final destination</b><br>
'.$final.'
</td>
<td valign=top align=left rowspan=2>
<b>10. Manufactory</b><br>

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

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


';

 $costo_t=0;
$servicios="";
$i=0;
$pedido=$_GET['id'];
$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 `pedidos_items` inner join  referencias on id_ref=descripcion where orden_pedido ='$id_pedido'";
$resultado2=$conexion-> query ($consulta);


     while ($row1=$resultado2->fetch_assoc()){
      $i=$i+1;
      
      $provee1= $row1['supplier'];

      $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 style='font-size:12px' >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 style='font-size:12px'>".number_format($row1['quantity'],0,".",",")." " . strtoupper($imprimir) ."</td>
<td align=right valign=top height=25px style='font-size:12px'> U$ ".number_format($row1['price_usd'], 2, '.', ',')."/" . strtoupper($imprimir) ."</td>
<td align=right valign=top height=25px style='font-size:12px'> = USD$ ".number_format($costo, 2, '.', ',')."</td>
</tr>";
$costo_t=$costo_t+$costo;


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


   <table width='100%' border='0' style='font-style:italic, border-collapse: collapse;' class='table table-bordered table-condensed table-hover'>
<tr>
<td align=left width=60% height=30px style='font-style:italic;font-size:12px'><b>11. Description of goods</b></td>
<td align=center width=10% height=30px style='font-style:italic;font-size:12px'><b>12. Qty/unit</b></td>
<td align=center width=15% height=30px style='font-style:italic;font-size:12px'><b>13. Unit Price/FOB</b></td>
<td align=center width=15% height=30px style='font-style:italic;font-size:12px'><b>14. Amount</b></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;font-size:12px'>TOTAL AMOUNT</td>
<td align=right style='font-size:12px'>  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>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 : ".$entrega .". <br> 
7. 10% MORE OR LESS IN QUANTITY AND VALUE TO BE ACCEPTED. <br>
8. THE SELLERS SHALL NOT BE HELD RESPONSIBLE FOR THE DELAY IN SHIPMENT OR NON-DELIVERY OF THE GOODS DUE TO FORCE 
    MAJEURE, WHICH MIGHT OCCUR DURING THE PROCESS OF MANUFACTURING OR IN THE COURSE OF LOADING FOR TRANSIT.<br> 
9. CLAIMS: ALL CLAIMS MUST BE MADE IN WRITING WITHIN THIRTY DAYS  AFTER ARRIVAL OF GOODS AT THE PORT OF DESTINATION AND 
    NO CLAIMS WILL BE RECOGNIZED IF THE SAID GOODS ARE USED OR RESOLD A PART OR UNLESS THEY HAVE BEEN SET ASIDE INS-  
    PECTION BY THE SELLER.  <br><br>
  ";


$detalle="";
$query_b="SELECT `id_bancos`, `nombre_bancos`, `beneficiario_empre`, `direccion_empresa`, `beneficiario_bancos`, `direccion_bancos`, `swift_bic`, `num_cuenta`, `intermediario`, `swift_code` FROM `bancos` where id_bancos='$bancos'";
$result_b=$conexion-> query ($query_b);
$row_b=$result_b->fetch_assoc();



$beneficiario_empre=$row_b['beneficiario_empre'];
$direccion_empresa=$row_b['direccion_empresa'];
$beneficiario_bancos=$row_b['beneficiario_bancos'];
$direccion_bancos=$row_b['direccion_bancos'];
$swift_bic=$row_b['swift_bic'];
$num_cuenta=$row_b['num_cuenta'];
$intermediario=$row_b['intermediario'];
$swift_code=$row_b['swift_code'];



if ($beneficiario_empre!="") {
 $detalle.="BENEFICIARY:<b> ".$beneficiario_empre."</b><br> ";
}

if ($direccion_empresa!="") {
 $detalle.= "ADDRESS:<b> ".$direccion_empresa."</b><br>";
}


if ($beneficiario_bancos!="") {
 $detalle.= "BENEFICIARY BANK:<b> ".$beneficiario_bancos."  </b><br>";
}


if ($direccion_bancos!="") {
 $detalle.= "ADDRESS:<b> ".$direccion_bancos."  </b><br>";
}


if ($swift_bic!="") {
 $detalle.= "SWIFT BIC:<b> ".$swift_bic." </b><br>";
}



if ($num_cuenta!="") {
 $detalle.= "ACCOUNT NUMBER:<b> ".$num_cuenta."  </b><br>";
}



if ($intermediario!="") {
 $detalle.= "INTERMEDIARY INSTITUTION:<b> ".$intermediario." </b><br>";
}


if ($swift_code!="") {
 $detalle.= "SWIFT:<b> ".$swift_code." </b><br>";
}






 $html.= "

".$detalle."

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

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