<?php
require('validate.php');
$startdate = $_POST["startdate"];
$enddate   = $_POST["enddate"];
$mode   = $_POST["mode"];
//echo $mode;exit;

$myvalstart=explode("-",$startdate);
$startdateval=date("j-M-y",mktime(0,0,0,$myvalstart[1],$myvalstart[2],$myvalstart[0]));	
	
$myvalend=explode("-",$enddate);
$enddateVal=date("j-M-y",mktime(0,0,0,$myvalend[1],$myvalend[2],$myvalend[0]));
//echo $enddate;


$query="SELECT SUM((b.ov_amount *.05)/1.05),SUM(b.ov_amount) FROM ".$prefix2."order_vat_challan AS a,".$prefix."debtor_trans AS b WHERE a.invoiceid=b.reference AND challan_date BETWEEN '$startdate' AND '$enddate' AND status=1";
$result=mysqli_query($linkid,$query);
$gettotal=mysqli_fetch_row($result);
$getcount=mysqli_num_rows($result);

$query="SELECT a.reference,a.order_no,a.invoiceid,b.ov_amount FROM ".$prefix2."order_vat_challan AS a,".$prefix."debtor_trans AS b WHERE a.invoiceid=b.reference AND challan_date BETWEEN '$startdate' AND '$enddate' AND status=1  ORDER BY a.reference ASC";
$resultType=mysqli_query($linkid,$query);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>VAT Challan Summary Report</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><?php include "templates/logoHeader.php"?>
      <table width="100%" border="0">
        <tr>
          <td align="center"><?php include "templates/letterHeader.php"?>
            <h3 class="heading" align="center" style="font-family:'Times New Roman', Times, serif; font-size:30px; font-style:italic">VAT Challan Summary Report</h3>
            <h5 class="heading"><?php if($mode=='all') echo "Mode of Payment: ALL";elseif($mode==1) echo "Mode of Payment: CASH";if($mode==2) echo "Mode of Payment: CHEQUE";if($mode==3) echo "Mode of Payment: CARD";?> </h5>
			<p align="center" style="font-family:'Times New Roman', Times, serif; font-size:14px; font-style:italic">(<?php echo $startdateval.' - '. $enddateVal;?>) </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-condensed table-striped" data-provides="rowlink" >
              <tr style="background-color:#F2F2F2; padding:5px;">
                  <th> Ref.</th>
				  <th> Order#</th>
				  <th> Invoice No</th>
				  <th> Invoice Amount</th>
				  <th> VAT Amount(BDT)</th>
              </tr>
              <?php 
		 if($resultType)

				{

				while($mydata = mysqli_fetch_assoc($resultType))
				{
		  ?>
              <tr>
           		  <td><?php echo $mydata['reference']?></td>
				  <td><?php echo $mydata['order_no']?></td>
				  <td><?php echo $mydata['invoiceid']?></td>
				  <td><?php echo number_format($mydata['ov_amount'],2)?></td>
				  <td><?php echo number_format(($mydata['ov_amount'] *.05)/1.05,2)?></td>
              </tr>
              <?php 
				  }
				 } 
	      if($getcount=="")
		  echo "<tr><td colspan=5>There is no order record for this month.</tr></td>";
		 	?>
              <tr style="background-color:#F2F2F2; padding:5px;">
                <td colspan="2">&nbsp;</td>
				<td align="right"><strong>Grand Total : </strong></td>
                <td  align="left"><strong><?php echo number_format($gettotal[1],2);?></strong></td>
                <td  align="left"><strong><?php echo number_format($gettotal[0],2);?></strong></td>
              </tr>
			   <tr style="background-color:#F2F2F2; padding:5px;">
                <td colspan="5" align="left"> <div style="padding-left:0px;">Issue Date: <?php echo date('j-M-y');?></div></td>
              </tr>
            </table>
           </td>
        </tr>
      </table></td>
  </tr>
</table>
<div>&nbsp;</div>
</body>
</html>
