<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 Orders (History) </a> </li>
          <li> <a href="#">Sales Orders Datagrid</a> </li>
        </ul>
      </div>
    </nav>
    <div class="row-fluid">
      <div class="span12">
        <h3 class="heading">Sales Orders (History)</h3>
        <table class="table table-striped table-bordered dTableR" id="dt_a">
          <thead>
            <tr>
              <!--<th> Order #</th>-->
             <th> Order Ref</th>
              <th> Order Date </th>
              <th> Customer </th>
              <th> Phone </th>
              <th> Required By </th>
              <th> Order Total(BDT)</th>
              <th> Advance</th>
              <th> Paid</th>
              <th> Status</th>
              <th width="15%" align="center">Action</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]));
				
				$dateval=explode("-",$mydata['delivery_date']);
			    $deliverydate=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($getTotal==$paid || $getTotal < $paid){
			  
				 
			  ?>
            <tr  class="bar<?php echo $mydata['order_no']?>">
              <!--<td><?php echo $mydata['order_no'];?></td>-->
              <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 $deliverydate;?></td>
              <td><?php echo number_format($mydata['total'],2)?></td>
              <td><?php echo number_format($getdata[0] - $mydata['total'],2);?></td>
              <td><?php echo number_format($getdata[0],2);?></td>
              <td class="center"><?php if($paid=="" && $paid < $mydata['total']) echo '<div class="span3"><p><button class="btn btn-danger">Pending</button></p</div>';elseif($paid < $mydata['total']) echo '<div class="span3"><p><button class="btn btn-warning">Partially</button></p</div>';elseif($paid > $mydata['total']) echo '<div class="span3"><p><button class="btn btn-primary">Advance</button></p</div>'; else if($paid == $mydata['total']) echo '<div class="span3"><p><button class="btn btn-success">Paid</button></p</div>'; ?></td>
              <td><table width="100%" border="0" align="center">
                  <tr>
                  <td><a href="sales_order.php?orderno=<?php echo $mydata['order_no'];?>" target="_blank"  title="Print Order"><i class="icon-print"></i></a></td>
                  </tr>
                </table></td>
            </tr>
            <?php 
			      }
				 }
				} 
?>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
