<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');

$formname = "BANK RECONCILLATION";
$file = "bankrecon_fr.php";

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
$zroot = $_SESSION["zdbroot"];
mysqli_select_db($conn,$zdb);

$acname = $_POST["acname"];
$mfrmdate = $_POST['frmdate'];
$mtodate = $_POST['todate'];
$dtype = $_POST['dtype'];
$scope = $_POST['scope'];

$dtypecond = '';
$scopecond = "";

if (!empty($acname)) {
    $acnamecond = " AND `accode`='$acname'";
}
if (!empty($dtype)) {
    $dtypecond = " AND `source`='$dtype' ";
}
if (!empty($scope)) {
    switch ($scope) {
        case 'A':
            $scopecond = "";
            break;
        case 'C':
            $scopecond = " AND `clrdate`!='0000-00-00' ";
            break;
        case 'N':
            $scopecond = " AND `clrdate`='0000-00-00' ";
            break;
        default:
            "";
    }
}

$result = mysqli_query($conn,"SELECT vouchno,accode, source, date, chqno, chqdate, clrdate, amount FROM `actran` where `date` >= '$mfrmdate'
               and `date` <= '$mtodate'  $acnamecond $dtypecond $scopecond group by source,vouchno order by source,vouchno ") or die(mysqli_error($conn));
//PRINT "SELECT * FROM `item` where `code`!='' $itemgrpcond $subgrpcond  ORDER BY name";
$ont = mysqli_num_rows($result);

$flag = "";

$ctr = 0;

echo '<table id="bankrecon" border="1" width="100%" align="center">';

echo '<tr style="height:10px;background-color: #64CCFC">';
echo '<th style="width:5%">SR.NO.</th>';
echo '<th style="width:10%">TYPE</th>';
echo '<th style="width:10%">VOUCHER</th>';
echo '<th style="width:15%">CHEQUE NO.</th>';
echo '<th style="width:15%">CHEQUE DATE</th>';
echo '<th style="width:15%">CLEAR DATE</th>';
echo '<th class="text-right" style="width:20%">AMOUNT</th>';
echo "</tr>";

$mctr = 0;
while ($row = mysqli_fetch_array($result)) {
$amount = $row[amount];
$amt = abs($amount);
    $mctr++;
    echo "<tr>";
    echo "<td>$mctr</td>";
    echo "<td><input type='text' style='border: none;' name='source_$ctr' value='$row[source]' readonly></td>";
    echo "<td><input type='text' style='border: none;' name='vouchno_$ctr' value='$row[vouchno]' readonly><input type='hidden' name='code_$ctr' value='$row[accode]' readonly></td>";
    echo "<td><input type='text' style='border: none;' name='chqno_$ctr' value='$row[chqno]' readonly></td>";
    echo "<td><input type='date' style='border: none;' name='chqdate' value='$row[chqdate]' readonly></td>";
    echo "<td><input type='date' style='border: none;' name='clrdate_$ctr' value='$row[clrdate]'></td>";
    echo "<td class='text-right'><input type='text' class='text-right' style='border: none;' name='amount' value='$amt' readonly></td>";
    echo "</tr>";

    $ctr++;
}
echo "<input type='hidden' name='count' value='$ctr'>";
echo "</table>";
?>
