<?php $connect = new PDO("mysql:host=localhost;dbname=instrume_crm", "instrumexcrm", "Instru#crm@2022");
require_once 'vendor/autoload.php';
use Dompdf\Dompdf;

$qrycon = "select * from quotation_order_01 where quotation_id = '".$_REQUEST['quotation_id']."'";
$statement2 = $connect->prepare($qrycon);
$statement2->execute();
$resultdiscount1 = $statement2->fetchAll();
foreach($resultdiscount1 as $list)
{
$bank_details=$list['bank_details'];
$quotation_id= $list['quotation_id'];
$company_name= $list['company_name'];
$c_id= $list['c_id'];
$type_products= $list['type_products'];
$address= $list['address'];
$email_id= $list['email_id'];
$contact= $list['contact'];
$currency= $list['currency'];
$unique_id= $list['unique_id'];
$entry_date= $list['entry_date'];
$entry_by= $list['entry_by'];
$po_number= $list['po_number'];
$po_date= $list['po_date'];
$delivery_name= $list['delivery_name'];
$warranty_name= $list['warranty_name'];
$payment_mode= $list['payment_mode'];
$tax_name= $list['tax_name'];

$final_quotation_no= $list['final_quotation_no'];
$f_year= $list['f_year'];
$quotation_date= $list['quotation_date'];
$quotation_type= $list['quotation_type'];
$validity= $list['validity'];
$installation_charge= $list['installation_charge'];
$installation_charge_text= $list['installation_charge_text'];
$jurisdiction= $list['jurisdiction'];
$pf_and_delivery_charge= $list['pf_and_delivery_charge'];
$pf_and_delivery_charge_text= $list['pf_and_delivery_charge_text'];

$delivery_charges=$list['delivery_charges'];
$delivery_charges_text=$list['delivery_charges_text'];

$mobile_no= $list['mobile_no']; 
$subject=$list['subject'];
$bank_charges=$list['bank_charges'];
$bank_charges_text=$list['bank_charges_text'];

$enquiry_from=$list['enquiry_from'];
$enquiry_date=$list['enquiry_date'];
}   

$image ="header_bar.png";

$image1 ="footer_new.jpg";
if($quotation_date!='') { $quotation_date01=  date("d-m-Y", strtotime($quotation_date)); }
if($enquiry_date!='') { $enquiry_date01=  date("d-m-Y", strtotime($enquiry_date)); }	
$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: 14px; padding:3px;}
.style5b {font-family: Arial, Helvetica, sans-serif; font-size: 13px; padding-left:3px; padding-right:3px; padding-top:1px;  padding-bottom:1px;}
.style5a {font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height:150%; padding-bottom:10px; padding-top:10px;; }

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

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

.style8a {font-family: Arial, Helvetica, sans-serif; font-size: 13px; }
</style></head>

<body>
<img src="https://instrumexcrm.in/crm_software/dompdf/'.$image.'">
<table width="100%" border="1" style="border-collapse:collapse">

<tr>
<td colspan="3" valign="top"><div align="left" class="style5">To,<br>'.$company_name.'<br>'.$address.'';

if($mobile_no!=''){$html.= 'Phone : '.$mobile_no.'
<br>';}
if($email_id!=''){$html.= 'Email : '.$email_id.'
<br>';}
$html.= '</div>
</td>
<td colspan="3"><div align="left" class="style5b">Quotation No:&nbsp;'.$final_quotation_no.'</div>
<div align="left" class="style5b">Quotation Date: '.$quotation_date01.'</div>
<div align="left" class="style5b">Enquiry : '.$enquiry_from.'</div>
<div align="left" class="style5b">Enquiry Date: '.$enquiry_date01.'</div></td>
</tr>';
if($contact!='') {
$html.= '
<tr>
<td colspan="6"><div align="left" class="style5">Kind Attn : '.$contact.'</div></td>
</tr>';}
$html.= '
<tr>
<td colspan="6"><div align="left" class="style5"><strong>Subject&nbsp;</strong>:&nbsp;'.$subject.'</div></td>
</tr>
<tr>
<td width="10%"  bgcolor="#CEF0FE"><div align="center" class="style5"><strong>Sr. No.</strong></div></td>
<td colspan="2" width="58%" bgcolor="#CEF0FE"><div align="left" class="style5"><strong>Description</strong></div></td>
<td width="15%" bgcolor="#CEF0FE"><div align="left" class="style5"><strong>Unit Rate</strong></div></td>
<td width="8%" bgcolor="#CEF0FE"><div align="center" class="style5"><strong>Qty</strong></div></td>
<td width="15%" bgcolor="#CEF0FE"><div align="right" class="style5"><strong>Amount</strong></div></td>

</tr>';
$k=1;

$qry97 = "select * from quotation_more_product02 where quotation_id='$quotation_id' and c_id='$c_id' order by more_product_id ASC ";
$statement11 = $connect->prepare($qry97);
$statement11->execute();
$result3s = $statement11->fetchAll();
foreach($result3s as $row4)
{
$item_name= $row4['item_name'];

$item_details= $row4['item_details'];

$HSN_code= $row4['HSN_code'];
$discount_price= $row4['discount_price'];
$sensor= $row4['sensor'];

$count_sensor01 = str_word_count("$sensor");
$count_sensor+=$count_sensor01;

$item_name= $row4['item_name'];
$item_type= $row4['item_type'];

$item_qty= $row4['item_qty'];
$main_product_id= $row4['main_product_id'];

$item_id01= $row4['item_id'];
$i++;
$qry97item = "select * from product_details where product_id='$item_id01'";
$statement41 = $connect->prepare($qry97item);
$statement41->execute();
$resultls5 = $statement41->fetchAll();
foreach($resultls5 as $user_data)
{
$sepreate_page=$user_data['sepreate_page'];
$name = $user_data['name'];
$product_description01 = $user_data['product_description'];

$countword1 = str_word_count("$product_description01");
 $countword+=$countword1;
}


$m=0;
$j=0;

$qry97= "select * from quotation_more_product02 where quotation_id='".$_REQUEST['quotation_id']."' and c_id='".$_REQUEST['c_id']."'  ORDER BY  more_product_id ASC ";
$statement9a = $connect->prepare($qry97);
$statement9a->execute();
$result9a = $statement9a->fetchAll();
$rowcount = $statement9a->rowCount();

foreach($result9a as $row4a)
{
$item_name= $row4a['item_name'];


if($item_name=='NEW PRODUCT'){
$item_name=''; 
}
$item_details= $row4a['item_details'];

$HSN_code= $row4a['HSN_code'];
$discount_price= $row4a['discount_price'];

$item_name= $row4a['item_name'];
$item_type= $row4a['item_type'];

$item_qty= $row4a['item_qty'];
$main_product_id= $row4a['main_product_id'];

$item_id= $row4a['item_id'];

if($item_type=='machine') {$j='';}


if($item_type=='accessories') { $j++; }

$html .= '<tr>
<td><div align="center" class="style5">'.$i.'.'.$j.'</div></td>
<td  colspan="2><div align="left" class="style5b">'.$item_name.'  <br>
         '.$item_details.'</div></td>
<td><div align="left" class="style5b">'.number_format($discount_price,2).'</td>
<td><div align="center" class="style5b">'.$item_qty.'</div></td>
<td><div align="right" class="style5b">'.number_format($discount_price*$item_qty,2).'</div></td>
</tr>';
  $k++; } }
  
  
if($j<='10')

{
$space ='150';
}
$html .= '
 <tr>
<td colspan="6"> <div style="height:'.$space.'px">'.$j.'</div></td>
</tr>

  
 <tr>
<td colspan="6" bgcolor="#F9D1D2"><div class="style5" align="center"><strong>Commercial Terms & Conditions</strong>   </div></td>
</tr> 
  
<tr>
<td colspan="2"><div align="left" class="style5b">Tax</div></td>
<td colspan="4"><div align="left" class="style5b">'.$tax_name.'</div></td>
</tr>';
if($pf_and_delivery_charge!='' or $pf_and_delivery_charge_text!='') {

$html .= '<tr>
<td colspan="2"><div align="left" class="style5b">Package Forwarding</div></td>
<td colspan="4"><div align="left" class="style5b">'.$pf_and_delivery_charge.''.$pf_and_delivery_charge_text.'</div></td>
</tr>';} if($installation_charge!='' or $installation_charge_text!='') {
$html .= '
<tr>
<td colspan="2"><div align="left" class="style5b">Installation charges</div></td>
<td colspan="4"><div align="left" class="style5b">'.$installation_charge.''.$installation_charge_text.'</div></td>
</tr>';} 
$html .= '
<tr>
<td colspan="2"><div align="left" class="style5b">Payment</div></td>
<td colspan="4"><div align="left" class="style5b">'.$payment_mode.'</div></td>
</tr>
<tr>
<td colspan="2"><div align="left" class="style5b">Delivery Period</div></td>
<td colspan="4"><div align="left" class="style5b">'.$delivery_name.'</div></td>
</tr>
<tr>
<td colspan="2"><div align="left" class="style5b">Validity</div></td>
<td colspan="4"><div align="left" class="style5b">'.$validity.'</div></td>
</tr>';
if($bank_charges!='' or $bank_charges_text!='') {
$html .= '<tr>
<td colspan="2"><div align="left" class="style5b">Validity</div></td>
<td colspan="4"><div align="left" class="style5b">'.$bank_charges.''.$bank_charges_text.'</div></td>
</tr>';}
if($delivery_charges!='' or $delivery_charges_text!='') {
$html .= '<tr>
<td colspan="2"><div align="left" class="style5b">Delivery Charges</div></td>
<td colspan="4"><div align="left" class="style5b">'.$delivery_charges.''.$delivery_charges_text.'</div></td>
</tr>';}
$html .= '<tr>
<td colspan="2"><div align="left" class="style5b">Warranty</div></td>
<td colspan="4"><div align="left" class="style5b">'.$warranty_name.'</div></td>
</tr>
<tr>
<td colspan="2"  valign="top"><div align="left" class="style5b">Jurisdiction Mumbai<br>'.$bank_details.'</div></td>
<td colspan="4"><div align="right" class="style7">For Instrumex<br>
            <img src="https://instrumexcrm.in/crm_software/dompdf/sign.jpg" alt="logo"><br>
        Authorised Signatory</div></td>
</tr>

</table><img src="https://instrumexcrm.in/crm_software/dompdf/'.$image1.'">
</body>
</html>

</body>
</html>';
$quotation_id=$_REQUEST['quotation_id'];
$customer_id=$_REQUEST['customer_id'];


$file_name = $final_quotation_no . '.pdf';
$dompdf = new Dompdf;
$dompdf->loadHtml($html);
$dompdf->setPaper('A4','portrait');
$dompdf->render();
$dompdf->stream('demo.pdf',array("Attachment"=>0));
$file = $dompdf->output();
file_put_contents($file_name, $file);
?>
