<?php $connect = new PDO("mysql:host=localhost;dbname=shaftcrmco_crmsoftware", "shaftcrmco_user", "@1TesT1@123");
require_once('vendor/autoload.php');
use Dompdf\Dompdf;

//error_reporting(0);

$querydiscount ="select * from new_vendorpo_01 where vendor_id = '".$_REQUEST['vendor_id']."' AND vendorpo_id ='".$_REQUEST['vendorpo_id']."' ";

$statement2 = $connect->prepare($querydiscount);

$statement2->execute();

$resultdiscount1 = $statement2->fetchAll();

foreach($resultdiscount1 as $row2)

{

$vendorpo_id=$row2['vendorpo_id'];

$vendor_name = $row2['vendor_name'];
$GST_type=$row2['GST_type'];

$gst_type=$row2['GST_type'];

$term_of_payment=$row2['term_of_payment'];

$delivery_note=$row2['delivery_note'];

$vendorpo_date = date("d-m-Y", strtotime($row2['vendorpo_date']));

$vendorpo_no=$row2['vendorpo_no'];

$freight_charges=$row2['freight_charges'];

$frieght_terms=$row2['frieght_terms'];

$payment_mode=$row2['payment_mode'];

$sales_person_id=$row2['sales_person_id'];

$address=$row2['address'];


$contact_person=$row2['contact_person'];

$contact_no=$row2['contact_no'];

$contact_email=$row2['contact_email'];

$customer_name=$row2['customer_name'];


$frieght_terms = $row2['frieght_terms'];
$price_basis = $row2['price_basis'];
$pkg_fwdg = $row2['pkg_fwdg'];
$transit = $row2['transit'];
$insurance = $row2['insurance'];
$delivery_note = $row2['delivery_note'];
$payment_mode = $row2['payment_mode'];
$GST_type = $row2['GST_type'];
$currency = $row2['currency'];
}


if($GST_type=='DirectExports'){
$gst_title = "Dr No";
}else{
$gst_title = "HSN";

}




$query = "select * from vendorpo_more_product_02 where vendorpo_id = '".$_REQUEST['vendorpo_id']."' AND vendor_id = '".$_REQUEST['vendor_id']."' AND deleted !='YES' and pro_status='Save' ORDER BY  more_vproduct_id ASC";

 $i=1;



	$statement = $connect->prepare($query);

	$statement->execute();

	$result = $statement->fetchAll();


$html= '<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<style type="text/css">

<!--

body {

	margin-left: 0px;

	margin-top: 0px;

	margin-right: 0px;

	margin-bottom: 0px;

}

.style5 {font-family: Arial, Helvetica, sans-serif; font-size: 12px; padding:1px; }
.style5c {font-family: Arial, Helvetica, sans-serif; font-size: 13px; padding-left:3px; line-height:130%; }

.style5a {font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height:150%; padding-bottom:10px; padding-top:10px;; }

.style5b {font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height:150%; padding:2px; }

.style7 {font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; line-height:110%; }



.style8 {font-family: Arial, Helvetica, sans-serif; font-size: 13px; font-weight: bold; padding:2px; }

.style8b {font-family: Arial, Helvetica, sans-serif; font-size: 16px; font-weight: bold; }



.style8a {font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height:130%; }

</style></head>

<body><table width="100%" border="1" style="border-collapse:collapse">
<tr>
<td colspan="4"><div align="center" class="style8b">DINESH INDUSTRIES
</div></td>
</tr>
<tr>
<td colspan="4" class="style5"><div align="center">PLOT NO-W-251(a), TTC INDL. AREA, MIDC RABALE, THANE BELAPUR ROAD, NAVI MUMBAI-708
</div></td>
</tr>
<tr>
<td height="25" colspan="4"><div align="center" class="style8b">PURCHASE ORDER</div></td>
</tr>
<tr>
<td width="53" valign="top" colspan="2">

<div align="left"  class="style5c">To,	</div>				
<div align="left"  class="style5c">Kind Attn: '.$contact_person.'</div>	
<div align="left"  class="style5c">M/s: '.$vendor_name.' </div>	
<div align="left"  class="style5c">Address: '.$address.'</div>	
<div align="left"  class="style5c">Mobile: '.$contact_no.'</div>	
<div align="left"  class="style5c">Email: '.$contact_email.'</div></td>
<td width="47%" valign="top" colspan="2">
<table width="100%" border="0" style="border-collapse:collapse">
<tr>
<td width="30%"><div align="left"  class="style5c">Our Offer No.:</div></td>
<td width="70%"><div align="left"  class="style5c">'.$vendorpo_no.'</div></td>
</tr>
<tr>
<td><div align="left"  class="style5c">Offer Date:</div></td>
<td><div align="left"  class="style5c">'.$vendorpo_date.'</div></td>
</tr>
</table></td>
</tr>
<tr>
<td height="10" colspan="4"><div align="center" class="style8">OUR REGISTRATION</div></td>
</tr>
<tr>
<td colspan="2"><div align="center"  class="style5">PAN NO: AGGPP3822R </div></td>
<td colspan="2"><div align="center"  class="style5"  >GST/UIN:27AGGPP3822R1ZR
 </div></td>
</tr>';
$query = "select * from vendorpo_more_product_02 where vendorpo_id = '".$_REQUEST['vendorpo_id']."' AND vendor_id = '".$_REQUEST['vendor_id']."' AND deleted !='YES' and pro_status='Save' ORDER BY  more_vproduct_id ASC";

 $i=1;



	$statement = $connect->prepare($query);

	$statement->execute();

	$result = $statement->fetchAll();

	
$html.= '
<tr>
<td colspan="4"><div align="left" class="style5" style="padding-bottom:10px;">Dear Sir,<br />
With reference to your enquiry, please find our offer for the following.</div>
<table width="100%" border="1" style="border-collapse:collapse">
<tr>
<td><div align="center"  class="style8">Item No.</div></td>
<td><div align="left"  class="style8" style="padding-left:3px;">Material Description</div></td>
<td><div align="center"  class="style8">'.$gst_title.'</div></td>
<td><div align="center"  class="style8">Qty</div></td>
<td><div align="center"  class="style8">Unit</div></td>
<td><div align="center"  class="style8">Rate<br>'.$currency.' </div></td>
<td><div align="right"  class="style8" style="padding-right:3px;">Total</div></td>
</tr>';
$k=1;


foreach($result as $row)
{
$product_name = $row['product_name'];

$product_id = $row['product_id'];

$more_vproduct_id = $row['more_vproduct_id'];

$unit=$row['unit'];

$pro_status = $row['pro_status'];

$itemdesc = $row['itemdesc'];

$qty = $row['qty'];

$due_date = $row['due_date'];

$lead_time = $row['lead_time'];

$pro_photo01 = $row['pro_photo'];

if($pro_photo01==''){
$pro_photo = "no_image.jpg";
}else{
$pro_photo = $pro_photo01;
}


$unit =  $row['unit']; 

$qty =  $row['qty']; 

$more_vproduct_id =  $row['more_vproduct_id']; 

$price =  round($row['po_price'],0); 

$packing_charges01 = $row['packing_charges'];

$insurance_charges01 = $row['insurance_charges'];


$HSN_code = $row['HSN_code'];

if (is_numeric($qty)) {

$qtysum += $qty;

}

$total_amount=$price*$qty;

$sumofamount +=$total_amount;
$gstvalue = $sumofamount*18/100;

if($itemdesc!=''){  $itemdesc01 =  "<br>".$itemdesc;}


$no = floor($sumofamount);

   $point = round($sumofamount - $no, 0) * 100;

   $hundred = null;

   $digits_1 = strlen($no);

   $i = 0;

   $str = array();

   $words = array('0' => '', '1' => 'one', '2' => 'two',

    '3' => 'three', '4' => 'four', '5' => 'five', '6' => 'six',

    '7' => 'seven', '8' => 'eight', '9' => 'nine',

    '10' => 'ten', '11' => 'eleven', '12' => 'twelve',

    '13' => 'thirteen', '14' => 'fourteen',

    '15' => 'fifteen', '16' => 'sixteen', '17' => 'seventeen',

    '18' => 'eighteen', '19' =>'nineteen', '20' => 'twenty',

    '30' => 'thirty', '40' => 'forty', '50' => 'fifty',

    '60' => 'sixty', '70' => 'seventy',

    '80' => 'eighty', '90' => 'ninety');

   $digits = array('', 'hundred', 'thousand', 'lakh', 'crore');

   while ($i < $digits_1) {

     $divider = ($i == 2) ? 10 : 100;

     $number = floor($no % $divider);

     $no = floor($no / $divider);

     $i += ($divider == 10) ? 1 : 2;

     if ($number) {

        $plural = (($counter = count($str)) && $number > 9) ? 's' : null;

        $hundred = ($counter == 1 && $str[0]) ? ' and ' : null;

        $str [] = ($number < 21) ? $words[$number] .

            " " . $digits[$counter] . $plural . " " . $hundred

            :

            $words[floor($number / 10) * 10]

            . " " . $words[$number % 10] . " "

            . $digits[$counter] . $plural . " " . $hundred;

     } else $str[] = null;

  }

  $str = array_reverse($str);

  $result = implode('', $str);

  $points = ($point) ?

    "." . $words[$point / 10] . " " . 

          $words[$point = $point % 10] : '';

$html .= '
<tr>
<td><div align="center"  class="style8a">'.$k.'</div></td>
<td valign="top"><div align="left"  class="style8a"  style="padding-left:3px;">'.$product_name.' '.$itemdesc01.'</div></td>
<td valign="top"><div align="center"  class="style8a">'.$HSN_code.'</div></td>
<td valign="top"><div align="center"  class="style8a">'.$qty.'</div></td>
<td valign="top"><div align="center"  class="style8a">'.$unit.'</div></td>
<td valign="top"><div align="center"  class="style8a">'.$price.'</div></td>
<td valign="top"><div align="right"  class="style8a"  style="padding-right:3px;">'.$total_amount.'</div></td>
</tr>';
$k++; }
$html .= '
<tr>
<td  colspan="6"><div align="right" class="style5">GRAND TOTAL IN '.$currency.'</div></td>
<td><div align="right" class="style5"  style="padding-right:3px;">'.preg_replace("/(\d+?)(?=(\d\d)+(\d)(?!\d))(\.\d+)?/i", "$1,", $sumofamount).'</div></td>
</tr>
<tr>
<td  colspan="7"><div align="left" class="style5">Basic Amount in words: '.$currency.' '.$result.'</div></td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="4"><div align="center" class="style5b">We hope you will find our offer competative, hence waiting for your valued Purchase Order.</div></td>
</tr>
<tr>
<td colspan="4"><div align="center" class="style8">TERMS AND CONDITIONS</div></td>
</tr>
<tr>
<td colspan="2"> <div align="left" class="style5" style="padding:3px;">
1. PRICE BASIS :  '.$price_basis.'<br>
2. FREIGHT : '.$frieght_terms.'<br>
3. P&F: '.$pkg_fwdg.'</div></td>
<td colspan="2"><div align="left" class="style5" style="padding:3px;">
GST: Extra At Actual  18%</br>
TRANSIT: '.$transit.'</br>
INSURANCE : '.$insurance.'

</div></td>
</tr>
<tr>
<td colspan="4"><div align="center" class="style8">PAYMENT & DELIVERY</div></td>
</tr>
<tr>
<td colspan="4"><div align="left" class="style5" style="padding:3px;">
PAYMENT : '.$payment_mode.'<br>
DELIVERY : '.$delivery_note.'
</div></td>
</tr>
<tr>
<td colspan=4"><div align="center" class="style8">NOTES</div></td>
</tr>
<tr>
<td colspan="4"><div align="left" class="style5">
<ol>
<li>Material Should be Supplied Strictly as per the Purchase Order</li>
<li>Acceptance of This Order Should be expressed in the form of Signed &amp; Stamped Copy of This Order</li>
<li>Delivery Period mentioned in this Order Should be Strictly Considered from the Date of Confirmation of Purchase Order</
</ol>
</div></td>
</tr>
<tr>
<td colspan="2" valign="top"><div align="left" class="style8" style="padding:3px;">ACCEPTANCE CONFIRMATION</div>
<div align="left" class="style5"  style="padding:3px;">Accepted By :</div>
<div align="left" class="style5"  style="padding:3px;">Designation : </div>
<div align="left" class="style5"  style="padding:3px;">Date :</div>


</td>
<td colspan="2" valign="top"><div align="right" class="style8"style="padding:3px;"> FOR DINESH INDUSTRIES
</div>
<div align="right" class="style5"><br><br></div>
<div align="right" class="style5" style="padding:15px;">Signature</div></td>
</tr>

</table>

</body>
</html>
';

$vendorpo_id=$_REQUEST['vendorpo_id'];

$vendor_id=$_REQUEST['vendor_id'];



include 'connection.php';



$file_name = $vendorpo_no . '.pdf';

$dompdf = new Dompdf;

$dompdf->loadHtml($html);

$dompdf->setPaper('A4','portrait');

$dompdf->render();

$dompdf->stream($file_name,array("Attachment"=>0));

$file = $dompdf->output();

file_put_contents($file_name, $file);
?>
