<?php
session_start();
if (!isset($_SESSION['reusername'])) { echo 'Sorry You Dont Have permissions to View this Page!'; exit();}
require_once 'includes/database.php';
require_once 'includes/display.php';
require_once 'includes/funcs.php';
echo $htmlheaders;  echo '<head>';
echo $js;
echo '<script type="text/javascript" src="js/jquery.tools.min.js"></script>';
echo $recss;

echo '</head><body>';
$user = $_SESSION['reusername'];
$db=new MySQLDatabase();
$db->open_connection();
$sd = substr($_REQUEST['s'],6,4)."-".substr($_REQUEST['s'],3,2)."-".substr($_REQUEST['s'],0,2);
$ed = substr($_REQUEST['e'],6,4)."-".substr($_REQUEST['e'],3,2)."-".substr($_REQUEST['e'],0,2);       
$i=1;

echo '<p><a href="#" id="printnow" class="printnow" onclick="myprint();" style="float:left;">Print</a>';
echo '<a href="#" id="closenow" class="closenow" onclick="window.close();">Close</a></p>';
echo '<div id="printblk">';	
echo '<table id="treport" style="width:95%;margin-left:20px;font-size:10px;font-family:Trebuchet MS, Arial;font-size:12px;">
<tr><td colspan="8"><center><span style="font-size:22px;font-weight:bold"> QOOLPOINT LTD</span></center></td></tr>
<tr><td colspan="8"><span style="font-size:16px;font-weight:bold;"><center>RECEIPTS LIST -  From: '.$_REQUEST['s'].'&nbsp;&nbsp; To: '.$_REQUEST['e'].'</center></span></td></tr>';
echo'<tr><u><th>S/no</th> <th>Receipt No.</th><th>Date</th> <th>Customer</th> <th>Type</th> <th>Bank</th> <th>Naration</th> <th>Amount</th>  </u></tr>';
echo '<tr><td colspan="8"><hr/></td></tr>'; 
$sql = mysqli_query($db->connection, "SELECT cname, rdate, rtype, recpno, amount, CONCAT(pmode, ' - ', IFNULL(chqno,' '),' - ', IFNULL(chqdet,' ')) as nar, bacc FROM recptrans WHERE rdate >= '$sd' AND rdate <= '$ed' ORDER BY bacc, rdate, recpno") or die (mysqli_error($db->connection) );
$tot = 0; $bacc = '*'; 	$gtot = 0;
while ($row = mysqli_fetch_array($sql, MYSQLI_ASSOC)){
    $nbacc = $row['bacc'];
    if(( $nbacc !== $bacc) && ($bacc !== '*') ){ 
      echo '<tr><td colspan="8"><hr/></td></tr>'; 
      echo '<tr><td colspan="7">'.$bacc.'</td><td align="right">' . number_format($tot, 0). '</td></tr>';  
      echo '<tr><td colspan="8"><hr/></td></tr>';  $tot = 0;   
    }
    $bacc = $row['bacc'];
    echo "<tr>";
    echo "<td>" . $i . "</td>";
    echo "<td>" . $row['recpno'] . "</td>";
    echo "<td style='width:110px;'>" . substr($row['rdate'],8,2)."-".substr($row['rdate'],5,2)."-".substr($row['rdate'],0,4)."</td>";
    echo "<td>" . $row['cname'] . "</td>";
    echo "<td>" . $row['rtype'] . "</td>";
    echo "<td>" . $row['bacc'] . "</td>";
    echo "<td>" . $row['nar'] . "</td>";
    echo "<td align='right'>" . number_format($row['amount'],0). "</td>";
    echo "</tr>";
    $i++; $tot = $tot + floatval($row['amount']);	$gtot = $gtot + floatval($row['amount']);
    }
echo '<tr><td colspan="8"><hr/></td></tr>'; 
echo '<tr><td colspan="7">'.$bacc.'</td><td align="right">' . number_format($tot, 0). '</td></tr>';  
echo '<tr><td colspan="8"><hr/></td></tr>';  
echo '<tr><td colspan="7">GRAND TOTAL</td><td align="right">' . number_format($gtot, 0). '</td></tr>'; 
echo '<tr><td colspan="8"><hr/></td></tr>';
echo '</table>';
echo '<span style="font-size:14px;font-weight:normal;float:left;font-family:Arial;margin-left:30px;">'; 
echo '<i>Printed by:</i> '.$user.'&nbsp;&nbsp;&nbsp;&nbsp;'.date("d-m-Y  H:i:s").'<br/><br/>';
echo '<i>Checked by:</i> _____________________<br/><br/></span>';
echo '</div>';
echo '</body></html>';
?> 

<script type="text/javascript">
function myprint(){
	var w = window.open('', '', 'width=800,height=600,resizeable,scrollbars');
	 w.document.write($("#printblk").html());

	 w.document.close(); 										// needed for chrome and safari
	 javascript:w.print();
	 w.close();
};	
</script>