<?php 
include 'load.php';
$qid = $_GET['qid'];
$quotationinfo = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM tbl_quotations WHERE quotations_id='$qid'"));

$quotations_no = $quotationinfo['quotations_no'];
$logo = $quotationinfo['Logo'];
$date = $quotationinfo['date'];
$formattedDate = date("M d, Y", strtotime($date));
$duedDate = date("M d, Y", strtotime($quotationinfo['due_date']));
$from_compay_name = $quotationinfo['from_compay_name'];
$from_compay_address = $quotationinfo['from_compay_address'];
$from_compay_phone = $quotationinfo['from_compay_phone'];
$for_company_name = $quotationinfo['for_company_name'];
$for_compny_address = $quotationinfo['for_compny_address'];
$bank_name = $quotationinfo['bank_name'];
$account_number = $quotationinfo['account_number'];
$bank = $quotationinfo['bank'];
$branch = $quotationinfo['branch'];
$discount = $quotationinfo['discount'];
$terms_and_condition = $quotationinfo['terms_and_condition'];
$quotations_total = $quotationinfo['quotations_total'];
$total = $quotationinfo['total'];
$fromcompanyemail = $quotationinfo['fromcompanyemail'];
$emailfor = $quotationinfo['emailfor'];
$cpersonfor = $quotationinfo['cpersonfor'];
$for_compay_phone = $quotationinfo['for_compny_phone'];
$advance_payment = $quotationinfo['advance_payment'];
$description = $quotationinfo['description'];

$validity_period = $quotationinfo['validity_period'];
$no_of_days = $quotationinfo['no_of_days'];
$pdf_title = $quotationinfo['pdf_title'];

if(empty($logo)){
	$binfo = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM branch WHERE branch_id ='1'"));
	
	$logo = $binfo['logo'];
}





$tc = explode(",",$terms_and_condition);
$tcon = "";
$c=1;
foreach ($tc as $key => $x) {
	$tcon .='<div>'.$c.'. '.$x.'</div>';
	$c++;
}


$quotationiteminfo = mysqli_query($conn, "SELECT * FROM tbl_quotations_items WHERE quotations_id='$qid'");
$c= 1;
$tbody="";
while($row = mysqli_fetch_assoc($quotationiteminfo)) {
	$prid = $row['product_id'];
	$productinfo = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM mobileproducts WHERE prid='$prid'"));
    $tbody.='<tr class="tb">
                <td>'.$c.'</td>
                <td class="pname" style="font-family:iskoola_pota;">'.$productinfo['proname'].'<br>'.$description.'</td>		
                <td>'.$row['qty'].'</td>
                <td>LKR '.number_format($row['price'], 2).'</td>
                <td>LKR '.number_format($row['price']*$row['qty'], 2).'</td>';
               
$c++;
}

$header = '<div class="header">
	<div class="headerleft">
	<img src="'.$logo.'" width="170" height="auto">
		
	</div>
	<div class="headerright">
		<div class="wrap">
			<div class="qtitle">'.$pdf_title.'</div>
			<div class="qtydate">'.$pdf_title.' No  #  <span><strong>'.' '.$quotations_no.'</strong></span></div>
			<div class="qtydate">'.$pdf_title.' Date  <span><strong>'.' '.$formattedDate.'</span></strong></div>
			<div class="qtydate">Due Date  <span><strong>'.' '.$duedDate.'</span></strong></div>
			
		</div>
	</div>
</div>';
?>