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

$formname = 'Bank Reconciliation';
$maindb = 'actran';
$file = 'bankreco.php';
$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);



$dcode = mysqli_real_escape_string($conn, $_GET["code"]);
$dfrmdate = mysqli_real_escape_string($conn, $_GET["frmdate"]);
$dtodate = mysqli_real_escape_string($conn, $_GET["todt"]);

$colorcode = "#FF8C00";
if (!empty($dcode)) {
    $result = mysqli_query($conn, "SELECT * FROM `actran` where grpcode='$dcode' and chqret != 'Y' and clrdate = '0000-00-00' and chqno != '' and
                        `grpcode` = '$dcode' AND date >='$dfrmdate' and date <= '$dtodate'") or die(mysqli_error($conn));
    $flag = "";
} else {
    $result = mysqli_query($conn, "SELECT * FROM `actran` where chqret != 'Y' and clrdate = '0000-00-00' and chqno != '' 
                            AND date >='$dfrmdate' and date <= '$dtodate'") or die(mysqli_error($conn));
    $flag = "";
}
$ctr = 0;

//echo '<table id="detail" border="1" width="40%" align="right">';
//echo "<tr>";
//echo '<th>
//    </th>';
//echo '<th align="right"><font color="Green" size="3px">Debit  </font><input type="text" size="10" id="totdebit" name="totdebit" class="form-control" readonly></th>';
//echo '<th align="right"><font color="red" size="3px">Credit  </font><input type="text" size="10" id="totcredit" name="totcredit" class="form-control" readonly></th>';
//echo '</tr>';
//echo '</table>';

echo '<table id="openstock" border="1" width="100%" align="center">';
?>
    <input id="submit" type='submit' name='submit' id='save' value='Save' class="btn btn-primary">
    <input class="btn btn-danger" type="button" onClick="window.location.href = '<?= $grid ?>'" value="Exit" />
<?php             
echo "<tr>";
echo "<th style='font-family: arial-regular;'>Type $flag</label></th>";
echo "<th align=''  style='font-family: arial-regular;text-align:left;'><b>Vouchno</b></th>";
echo "<th align='' style='font-family: arial-regular;text-align:left;'><b>Date</b></th>";
echo "<th align='' style='font-family: arial-regular;text-align:left;'><b>Cheque No.</b></th>";
echo "<th align='' style='font-family: arial-regular;text-align:left;'><b>Chq. Date</b></th>";
echo "<th align='' style='font-family: arial-regular;text-align:right;'><b>Amount</b></th>";
echo "<th align='' style='font-family: arial-regular;text-align:left;'><b>Clear Date</b></th>";

echo '</tr>';
while ($row = mysqli_fetch_array($result)) {
    $amount = $row["amount"];
    if ($amount < 0){
        $amt = $amount * -1;
    }
    else{
        $amt = $amount;
    }
    echo "<tr>";
    echo '<td align="center"><input type="hidden" name="accode_' . $ctr . '" value="' . $row["accode"] . '">
             <input type="text" size="5"  maxlength=""  name="source_' . $ctr . '"  value="' . $row["source"] . '" class="form-control" readonly/></td>';
    echo '<td align="center">
              <input type="text" size="5" maxlength="" style="text-align: left;" name="vouchno_' . $ctr . '" value="' . $row["vouchno"] . '" class="form-control" readonly></td>';
    echo '<td align="left"><input type="date" size="8"  maxlength="" name="date_' . $ctr . '" value="' . $row["date"] . '" class="form-control" style="text-align:left; padding-left: 5px;"  readonly ></td>';
    echo '<td align="center "><input type="text" size="5" maxlength="" name="chqno_' . $ctr . '" value="'.$row["chqno"].'" style="text-align:left;" class="form-control" readonly></td>';
    echo '<td align="center "><input type="text" size="8" maxlength="" name="chqdate_' . $ctr . '" value="'.$row["chqdate"].'" style="text-align:left;" class="form-control" readonly></td>';
    echo '<td align="center "><input type="text" size="10" maxlength="" name="amount_' . $ctr . '" value="'.$amt.'" style="text-align:right;" class="form-control" readonly ></td>';
    echo '<td align="center "><input type="date" size="8" maxlength="" name="clrdate_' . $ctr . '" value="'.$row["clrdate"].'" style="text-align:left;" class="form-control" ></td>';
    echo '</tr>';
    $ctr++;
}
echo "<input type='hidden' name='count' value='$ctr'>";
echo "</table>";
?>
