<?php
require('validate.php');
$startdate = $_POST["startdate"];
$enddate   = $_POST["enddate"];
$invoice   = $_POST["invoice"];
$mobile   = $_POST["mobile"];

//echo $mode;exit;


?>

<?php 

if($mobile!="" or !empty($mobile))
{

$query="SELECT tran_date,reference,ov_amount,order_,b.name,b.address,b.debtor_ref FROM ".$prefix."debtor_trans AS a,".$prefix."debtors_master AS b WHERE a.debtor_no=b.debtor_no AND order_  > 0 AND  debtor_ref='$mobile' AND tran_date between '$startdate' AND '$enddate'";

//echo $query; 
}
else if($invoice!="" or !empty($invoice))
{

$query="SELECT tran_date,reference,ov_amount,order_,b.name,b.address,b.debtor_ref FROM ".$prefix."debtor_trans AS a,".$prefix."debtors_master AS b WHERE a.debtor_no=b.debtor_no AND order_  > 0 AND  reference='$invoice' AND tran_date between '$startdate' AND '$enddate'";

//echo $query; 
}
else
$query="SELECT tran_date,reference,ov_amount,order_,b.name,b.address,b.debtor_ref FROM ".$prefix."debtor_trans AS a,".$prefix."debtors_master AS b WHERE a.debtor_no=b.debtor_no AND order_  > 0 AND tran_date between '$startdate' AND '$enddate'";
//echo $query; 

$resultType=mysqli_query($linkid,$query);



?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Invoice  Search</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- Bootstrap framework -->
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="bootstrap/css/bootstrap-responsive.min.css" />
<link rel="shortcut icon" href="img/favicon.ico" />
</head>
<body>
<table width="90%" border="0" align="center">
  <tr>
    <td>
      <table width="100%" border="0">
        <tr>
          <td align="center"><?php //include "templates/letterHeader.php"?>
		  <?php include "templates/logoHeader.php"?>
			   <h4 class="heading">Current Invoices & Deliveries</h4>
			<p align="center" style="font-family:'Times New Roman', Times, serif; font-size:14px; font-style:italic">(<?php echo $startdate.' - '. $enddate;?>) </p>
           <!-- <table  border="1" align="center" cellpadding="4" cellspacing="4" bordercolor="#E6E6E6" bordercolorlight="#CCCCCC" bordercolordark="#ffffff" bgcolor="#FFFFFF" style="FONT-SIZE:12px; border-collapse:collapse; border:1px #CCCCCC solid; FONT-FAMILY: Arial, Helvetica, sans-serif; TEXT-DECORATION: none; FONT-WEIGHT: normal;">-->
              

        <table class="table table-striped table-bordered dTableR" id="dt_a">

          <thead>

            <tr>

              <th> Order No</th>

              <th> Reference</th>

              <th> Trans Date </th>

              <th> Customer </th>

              <th> Phone </th>

              <th> Amount(BDT)</th>
			  <th align="center"> Action</th>

            </tr>

          </thead>

          <tbody>

            <?php 



			  if($resultType)



				{



				while($mydata = mysqli_fetch_assoc($resultType))

				{

				

				$myref=explode("-",$mydata['reference']);

				//if($myref[0]=='DN'){

				

			  ?>

            <tr  class="bar<?php echo $mydata['order_']?>">

              <td><?php echo $mydata['order_'];?></td>

              <td><?php 

			  if($myref[0]=='DN'){

			   ?>

			    <a href="delivery_notes.php?id=<?php echo $mydata['reference'];?>" target="_blank"><?php echo $mydata['reference'];?>

				<?php

			    }

				else if($myref[0]=='INV'){

			   ?>

			    <a href="invoice_report.php?id=<?php echo $mydata['reference'];?>" target="_blank"><?php echo $mydata['reference'];?>

				<?php

			    }

			   ?></a></td>

              <td><?php echo $mydata['tran_date']?></td>

              <td><?php echo $mydata['name'];?></td>

              <td><img src="img/phn.png" width="16" />&nbsp;<?php echo $mydata['debtor_ref'];?></td>

              <td><?php echo number_format($mydata['ov_amount'],2)?></td>

               <td class="center">
		
				  <div class="row-fluid">
                        <div class="span10"> 
						<?php
						if($myref[0]=='INV'){
					   ?>
						<a href="index.php?tab=add-vat-challan?invid=<?php echo $mydata['reference'];?>" target="_blank"> <button class="btn btn-gebo">VAT C</button></a>
						<?php
						}
						?>
						</div>
                      </div>
				
                  </td>

            </tr>

            <?php 

					//}

				 	}



				 } 



?>

          </tbody>

        </table>

      </div>

           </td>
        </tr>
      </table></td>
  </tr>
</table>
<div>&nbsp;</div>
</body>
</html>
