<?php
$query="SELECT order_no,reference,ord_date,contact_email,deliver_to,total,b.debtor_no,b.debtor_ref AS phone,b.name,b.address FROM ".$prefix."sales_orders AS a,".$prefix."debtors_master AS b WHERE a.debtor_no=b.debtor_no AND a.trans_type='32'  AND reference LIKE 'SQ-%';";
//echo $query;
$resultType=mysqli_query($linkid,$query);
?>

<div id="contentwrapper">
  <div class="main_content">
    <nav>
      <div id="jCrumbs" class="breadCrumb module">
        <ul>
          <li> <a href="#"><i class="icon-home"></i></a> </li>
          <li> <a href="#">Sales Quotation </a> </li>
          <li> <a href="#">Sales Quotation Datagrid</a> </li>
        </ul>
      </div>
    </nav>
    <div class="row-fluid">
      <div class="span12">
        <h3 class="heading">Sales Quotation</h3>
        <table class="table table-striped table-bordered dTableR" id="dt_a">
          <thead>
            <tr>
              <th> quotation Ref</th>
              <th> Order Date </th>
              <th> Customer </th>
              <th> Phone </th>
              <th> Order Total(BDT)</th>
              <th> Status</th>
            </tr>
          </thead>
          <tbody>
            <?php 

			  if($resultType)

				{

				while($mydata = mysqli_fetch_assoc($resultType))
				{
				$dateval=explode("-",$mydata['ord_date']);
			    $monthval=date("d-m-Y",mktime(0,0,0,$dateval[1],$dateval[2],$dateval[0]));
				
				
				$orderid=$mydata['order_no'];
				$query="SELECT SUM(paid),SUM(sap) FROM ".$prefix2."order_payment WHERE order_no=$orderid";
				//echo $query;
				$result=mysqli_query($linkid,$query);
				$getdata=mysqli_fetch_row($result);
				$paid=$getdata[0]+$getdata[1];;

 				$getTotal=$mydata['total'];

			  //  if($paid < $getTotal){
			 
			
			  ?>
            <tr  class="bar<?php echo $mydata['order_no']?>">
              <td><?php echo $mydata['reference']?></td>
              <td><?php echo $monthval;?></td>
              <td><?php echo $mydata['name']?></td>
              <td><img src="img/phn.png" width="16" />&nbsp;<?php echo $mydata['phone'];?></td>
              <td><?php echo number_format($mydata['total'],2)?></td>
              <td><a href="sales_quotation.php?orderno=<?php echo $mydata['order_no'];?>" target="_blank"  title="Print Order"><i class="icon-print"></i></a></td>
           </tr>
            <?php 

				// }

				 } 
}
?>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
