<?php $connect = new PDO("mysql:host=localhost;dbname=shaftcrmco_crmsoftware", "shaftcrmco", "shaft#$CRM%23");
require_once('vendor/autoload.php');
use Dompdf\Dompdf;

//error_reporting(0);

$querydiscount ="select * from quotation_make_table_1 where customer_id = '".$_REQUEST['customer_id']."' AND quotation_id ='".$_REQUEST['quotation_id']."' ";

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

$statement2->execute();

$resultdiscount1 = $statement2->fetchAll();

foreach($resultdiscount1 as $row2)

{

$quotation_id=$row2['quotation_id'];

$branch_id=$row2['branch_id'];

$GST_type=$row2['GST_type'];

$gst_type=$row2['GST_type'];

$term_of_payment=$row2['term_of_payment'];

$delivery_note=$row2['delivery_note'];

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

$final_quotation_no=$row2['final_quotation_no'];

$freight_charges=$row2['freight_charges'];

$frieght_terms=$row2['frieght_terms'];
$qtn_validity = $row2['qtn_validity'];

$payment_mode=$row2['payment_mode'];

$sales_person_id=$row2['sales_person_id'];

$billing_address=$row2['billing_address'];



$billing_GST_no=$row2['billing_GST_no'];

$bill_kind_atten_id=$row2['bill_kind_atten_id'];

$ship_kind_atten_id=$row2['ship_kind_atten_id'];

$qtn_validity = $row2['qtn_validity'];

$currency = $row2['currency'];


$bill_id=$row2['bill_id'];

$ship_id=$row2['ship_id'];





$delivery_address=$row2['delivery_address'];



$delivery_GST_no=$row2['delivery_GST_no'];

$our_company=$row2['our_company'];

$qtn_date=$row2['qtn_date'];

$reference_no = $row2['reference_no'];

$reference_date01= $row2['reference_date'];

if($reference_date01!=''){

$reference_date = date("d-m-Y", strtotime($reference_date01));

}



$customer_name=$row2['customer_name'];

}

$queryl2 = "select * from mst_customer where c_id='".$_REQUEST['customer_id']."'";

$statement42 = $connect->prepare($queryl2);

$statement42->execute();

$resultl2 = $statement42->fetchAll();

foreach($resultl2 as $customer)

{

$MSME=$customer['MSME'];

}





$queryl2ca = "select * from customer_address where add_id='$bill_id'";

$statement42ca = $connect->prepare($queryl2ca);

$statement42ca->execute();

$resultl2ca = $statement42ca->fetchAll();

foreach($resultl2ca as $customerca)

{

$location=$customerca['bill_city'];

$state=$customerca['bill_state'];

$pincode=$customerca['bill_pincode'];

}





$queryl2sa = "select * from customer_shipaddress where add_id='$ship_id'";

$statement42sa = $connect->prepare($queryl2sa);

$statement42sa->execute();

$resultl2sa = $statement42sa->fetchAll();

foreach($resultl2sa as $customersa)

{

$locations=$customersa['ship_city'];

$states=$customersa['ship_state'];

$pincodes=$customersa['ship_pincode'];

}





$querylship = "select * from customer_contact where contact_id ='$ship_kind_atten_id'";

$querylo573 = $connect->prepare($querylship);

$querylo573->execute();

$querylo573r = $querylo573->fetchAll();

foreach($querylo573r as $row5)

{

$del_kind_atten = $row5['contact_name'];

$del_contact_no = $row5['mobile_no'];

$del_email_id = $row5['email_id'];

}	



$querylo57 = "select * from customer_contact where contact_id ='$bill_kind_atten_id'";

$querylo574 = $connect->prepare($querylo57);

$querylo574->execute();

$querylo574r = $querylo574->fetchAll();

foreach($querylo574r as $row1)

{

$bill_kind_atten = $row1['contact_name'];

$bill_contact_no = $row1['mobile_no'];

$bill_email_id = $row1['email_id'];

}	



$query = "select * from quotation_more_product_02 where quotation_id = '".$_REQUEST['quotation_id']."' AND customer_id = '".$_REQUEST['customer_id']."' AND deleted !='YES' and qtn_status='Save' ORDER BY mandatory_accessories asc, recommended_spares asc, more_product_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; }

.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"><img src="https://shaftcrmco.in/CRM_Software/dompdf/header_bar.png"  /></div></td>
</tr>
<tr>
<td colspan="4" class="style5"><div align="center">Regd Office: 141 Shamla Bhuvan, 1st Floor , Office No.2, Dr.Deshmukh Lane, Mumbai -400004. Tel: +91-22-6636 3146</div></td>
</tr>
<tr>
<td colspan="4" class="style5"><div align="center">Email : export@pearloverseas.co.in | pearloverseas7@gmail.com</div></td>
</tr>
<tr>
<td height="25" colspan="4"><div align="center" class="style8b">TECHNO COMMERCIAL QUOTATION</div></td>
</tr>
<tr>
<td colspan="2" width="53" valign="top">

<div align="left"  class="style5c">To,	</div>				
<div align="left"  class="style5c">Kind Attn: '.$bill_kind_atten.'</div>	
<div align="left"  class="style5c">M/s: '.$customer_name.' </div>	
<div align="left"  class="style5c">Address: '.$billing_address.'</div>	
<div align="left"  class="style5c">Mobile: '.$bill_contact_no.'</div>	
<div align="left"  class="style5c">Email: '.$bill_email_id.'</div>	



</td>
<td width="47%" colspan="2" valign="top">
<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">'.$final_quotation_no.'</div></td>
</tr>
<tr>
<td><div align="left"  class="style5c">Offer Date:</div></td>
<td><div align="left"  class="style5c">'.$date.'</div></td>
</tr>
<tr>
<td><div align="left"  class="style5c">Your Ref. No.:</div></td>
<td><div align="left"  class="style5c">'.$reference_no.'</div></td>
</tr>
<tr>
<td><div align="left"  class="style5c">Ref. Date:</div></td>
<td><div align="left"  class="style5c">'.$reference_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: BFRPS1879C </div></td>
<td colspan="2" class="style5"><div align="center">GST NO.: 27BFRPS1879C1ZW</div></td>
</tr>
<tr>
<td colspan="2"><div align="center" class="style5">ISO: 9001-2015</div></td>
<td colspan="2"><div align="center" class="style5">IEC: 0315010096</div></td>
</tr>';
$query = "select * from quotation_more_product_02 where quotation_id = '".$_REQUEST['quotation_id']."' AND customer_id = '".$_REQUEST['customer_id']."' AND deleted !='YES' and qtn_status='Save' ORDER BY  more_product_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">Sr. No.</div></td>
<td><div align="left"  class="style8" style="padding-left:3px;">ITEM DESCRIPTION</div></td>
<td><div align="center"  class="style8">HSN CODE</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">UNIT RATE IN '.$currency.' </div></td>
<td><div align="right"  class="style8" style="padding-right:3px;">TOTAL AMOUNT IN</div></td>
</tr>';
$k=1;


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

$product_id = $row['product_id'];

$more_product_id = $row['more_product_id'];

$unit=$row['unit'];

$pro_status = $row['pro_status'];

$itemdesc = $row['itemdesc'];

$product_type = $row['product_type'];

$qty = $row['qty'];

$due_date = $row['due_date'];

$lead_time = $row['lead_time'];





$unit =  $row['unit']; 

$qty =  $row['qty']; 

$more_product_id =  $row['more_product_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;

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

$html .= '
<tr>
<td><div align="center"  class="style8a">'.$k.'</div></td>
<td><div align="left"  class="style8a"  style="padding-left:3px;">'.$product_name.' '.$itemdesc01.'</div></td>
<td><div align="center"  class="style8a">'.$HSN_code.'</div></td>
<td><div align="center"  class="style8a">'.$qty.'</div></td>
<td><div align="center"  class="style8a">'.$unit.'</div></td>
<td><div align="center"  class="style8a">'.$price.'</div></td>
<td><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;">'.$sumofamount.'</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="2"> <div align="left" class="style5" style="padding-left:10px; line-height:150%;">TERMS AND CONDITIONS :<br />
1. Price Basis :  Free Delivery at your Transport Mumbai<br />
2. Freight : '.$frieght_terms.'<br />
3. Delivery: '.$delivery_note.'<br />
4. Payment: '.$payment_mode.'<br />
5. Taxes : 18% Gst Extra<br />
6. Validity : '.$qtn_validity.'</div></td>
<td  colspan="2"><div align="right" class="style5"> FOR PEARL OVERSEAS</div><br /><br />
<div align="right" class="style5"></div><br /><br />
<div align="right" class="style5">MITUL SHAH +91-91723 33437</div></td>
</tr>

</table>

</body>
</html>
';

$quotation_id=$_REQUEST['quotation_id'];

$customer_id=$_REQUEST['customer_id'];



include 'connection.php';



$file_name = $final_quotation_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);
?>
