<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Expense Purchase Report</title>
 <?php require 'header.php' ?>
</head>

<body onload="window.print()">
<div class="container col-sm-12">
<div id="a">
<h3 align="center">GST Purchase Report </h3>
<table id="stockExpenseDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
        <thead>
            <tr>
            
            <th>Expense Type </th>
            <th>Expense Qty</th>
            <th>Expenser</th>
            <th>Mode Of Pay</th>
            <th>Amount</th>
            <th>Rermark</th>
                <!-- <th>Action</th> -->
            </tr>
        </thead>
        
        <?php
		require_once("config/configDB.php");
				$fromDate=$_GET['fromdate'];
				$toDate=$_GET['todate'];
			
				$expensetype=$_GET['expensetype'];
				$expenser ='';
				
					
				$sql = "SELECT ee.cashno,ee.mode,ee.remark, ee.expensedate, ee.expense,ee.expensetype,ee.expensetype,ee.expenser,ee.amount,ee.id,em.expense as expensename FROM expense_entry as ee LEFT JOIN expense_master as em ON em.id=ee.expensetype WHERE ee.flag=1 ";
				
				if($fromDate !=''  && $toDate !='' && $expensetype ==''  && $expenser ==''  ) {
	 	$sql.=" and expensedate BETWEEN '".$fromDate."' AND '".$toDate."' ORDER BY ee.expensedate ASC ";

	 }
	 
	else if($fromDate !=''  && $toDate !='' && $expensetype !=''  && $expenser ==''  ) {
		
		$sql.=" and expensetype='".$expensetype."' and expensedate BETWEEN '".$fromDate."' AND '".$toDate."' ORDER BY ee.expensedate ASC ";
	}
	
	else if($fromDate !=''  && $toDate !='' && $expensetype !=''  && $expenser !=''  ) {
		
		$sql.=" and expenser='".$expenser."' and expensetype='".$expensetype."' and expensedate BETWEEN '".$fromDate."' AND '".$toDate."' ORDER BY ee.expensedate ASC ";
	}
	
	
	else if($fromDate !=''  && $toDate !='' && $expensetype ==''  && $expenser !=''  ) {
		
		$sql.=" and expenser='".$expenser."' and expensedate BETWEEN '".$fromDate."' AND '".$toDate."' ORDER BY ee.expensedate ASC ";
	}
	
	else if($fromDate ==''  && $toDate =='' && $expensetype !=''  && $expenser !=''  ) {
		
		$sql.=" and expensetype='".$expensetype."' and expenser='".$expenser."'  ORDER BY ee.expensedate ASC ";
	}
	
	else if($fromDate ==''  && $toDate =='' && $expensetype !=''  && $expenser ==''  ) {
		
		$sql.=" and expensetype='".$expensetype."'   ORDER BY ee.expensedate ASC ";
	}
	
	else if($fromDate ==''  && $toDate =='' && $expensetype ==''  && $expenser !=''  ) {
		
		$sql.=" and expenser='".$expenser."'  ORDER BY ee.expensedate ASC ";
	}
	
				?>
	 
				
        
        <tbody>
             <?php
			$query=mysqli_query($conn, $sql) or die("brandgriddata.php: get brand Data step 1".$sql);
			$amount=0;
			while($row=mysqli_fetch_array($query))
			{
			?>
            <tr>
           
            <td><?php echo $row['expensename'];?></td>
            <td><?php echo $row['expense'];?></td>
            <td><?php echo $row['expenser'];?></td>
            <td><?php echo $row['mode'];?></td>
            <td align="right"><?php echo number_format($row['amount'],2,'.','');?></td>
            <td><?php echo $row['remark'];?></td>
            </tr>
            <?php
			$amount=$amount+$row['amount'];
			}
			?>
            <tr>
            <td align="right" colspan="4"><b>Total</b></td>
            <td align="right"><strong><?php echo number_format($amount,2,'.','');?></strong></td>
            </tr>
        </tbody>
       
    </table>
    </div>
</div>
 <?php require 'footer.php' ?>

    <script type="text/javascript">var base_url = "<?= $base_url ?>";</script>
  
    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/jquery-ui.min.js"></script>
</body>
</html>
