<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border-collapse:collapse;">
  <tr>
    <td class="tabledata">Branch/Unit</td>
    <td class="tabledata">Total Sale</td>
    <td class="tabledata">Net Sale</td>
   <!-- <td class="tabledata">Total Excise</td>
    <td class="tabledata">Tax Value</td>-->
  </tr>
  <?php
 $NetSale=0;
 if($_SESSION['UserID']==10){
  $invoice=DB_query("select basicAmount AS Total from salesorder inner join salesorder_details on salesorder.id=salesorder_details.masterId where branch='".$_SESSION['AssignedBranch']."' and (ApprovalStatus='2' || ApprovalStatus='3') GROUP BY salesorder.id",$db);
  }
  else
  {
   $invoice=DB_query("select basicAmount AS Total from salesorder inner join salesorder_details on salesorder.id=salesorder_details.masterId where branch='".$_SESSION['AssignedBranch']."' and (ApprovalStatus='2' || ApprovalStatus='3') and createdBy='".$_SESSION['UserID']."' GROUP BY salesorder.id",$db);
  }
  while($invoice_data=DB_fetch_array($invoice)){
  $NetSale=$NetSale+$invoice_data['Total'];
  } 
  ?>
   <tr>
    <td class="tabledata_fist"><?php echo $s->getField('locations','loccode',$_SESSION['AssignedBranch'],'locationname'); ?></td>
    <td class="tabledata1"><?php  $TotalSale=0;
	if($_SESSION['UserID']==10){
		 $inv=DB_query("SELECT grandTotal AS grand FROM salesorder INNER JOIN salesorder_details ON salesorder.id=salesorder_details.masterId WHERE branch='".$_SESSION['AssignedBranch']."' AND (ApprovalStatus='2' || ApprovalStatus='3') GROUP BY salesorder.id 	",$db);
		 }
		 else
		 {
		 $inv=DB_query("SELECT grandTotal AS grand FROM salesorder INNER JOIN salesorder_details ON salesorder.id=salesorder_details.masterId WHERE branch='".$_SESSION['AssignedBranch']."' AND (ApprovalStatus='2' || ApprovalStatus='3') and createdBy='".$_SESSION['UserID']."' GROUP BY salesorder.id 	",$db);
		 }
	                       while($invdata=DB_fetch_array($inv)){
						    $TotalSale=$TotalSale+$invdata['grand']; 
						   }
						   echo $TotalSale;
						   ?>  	
    	</td>
    <td class="tabledata1"><?php echo $NetSale; ?></td>
    
  </tr>
  
  

</table>