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

$formname = 'Bank Reconciliation';
$maindb = 'actran';
$source = "";
$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";
$result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE chqret != 'Y' and clrdate = '0000-00-00' and 
                        `grpcode` = '$dcode' AND date >='$dfrmdate' and date <= '$dtodate' ") or die(mysqli_error($conn));
?>

<div id="sortableTable" class="body collapse in">
    <div class="toolbar">
        <ul class="nav">
            <li><input id="submit" type='submit' name='submit' id='save' value='Save' class="btn btn-primary"></li>
            <li><input class="btn btn-danger" type="button" onClick="window.location.href = '<?= $grid ?>'" value="Exit" /></li>
        </ul>
    </div>
    <table class="table table-bordered ">
        <thead>
            <tr>
                <th>Source
                    <i class="icon-sort"></i>
                    <i class="icon-sort-down"></i>
                    <i class="icon-sort-up"></i>
                </th>
                <th style="width: 370px;">Vouchno
                    <i class="icon-sort"></i>
                    <i class="icon-sort-down"></i>
                    <i class="icon-sort-up"></i>
                </th>
                <th>Date
                    <i class="icon-sort"></i>
                    <i class="icon-sort-down"></i>
                    <i class="icon-sort-up"></i>
                </th>
                <th>Cheque No.
                    <i class="icon-sort"></i>
                    <i class="icon-sort-down"></i>
                    <i class="icon-sort-up"></i>
                </th>
                <th>Chq. Date
                    <i class="icon-sort"></i>
                    <i class="icon-sort-down"></i>
                    <i class="icon-sort-up"></i>
                </th>
                <th>Amount
                    <i class="icon-sort"></i>
                    <i class="icon-sort-down"></i>
                    <i class="icon-sort-up"></i>
                </th>
                <th>Clear Date
                    <i class="icon-sort"></i>
                    <i class="icon-sort-down"></i>
                    <i class="icon-sort-up"></i>
                </th>
            </tr>
        </thead>
        <tbody>
            <?php
            $ctr = 0;
            $mctr = 1;

            if (mysqli_num_rows($result) > 0) {
                while ($row = mysqli_fetch_object($result)) {
                    $ctr++;
                    echo "<tr>";
                    echo "<td>";
                    echo "$row->source";
                    echo "</td>";
                    echo "<td>";
                    echo "$row->vouchno";
                    echo "</td>";
                    echo "<td>";
                    echo "$row->date";
                    echo "</td>";
                    echo "<td>";
                    echo "$row->chqno";
                    echo "</td>";
                    echo "<td>";
                    echo "$row->chqdt";
                    echo "</td>";
                    echo "<td>";
                    echo "$row->amount";
                    echo "</td>";
                    echo "<td>";
                    echo "$row->clrdate";
                    echo "</td>";
                    echo "</tr>";
                    $mctr++;
                }
                echo "<input type='hidden' name='count' value='$ctr'>";
            } else {

                echo "<tr>";
                echo "<td>";
                echo $ctr;
                echo "</td>";
                echo "<td>";
                echo "<input list='item' name='item_$ctr' class='item form-control' value='$row[item]' style='height:33px;'>";
                echo "<datalist id='item'>";
                echo "<option value=''></option>";
                $mitem = mysqli_query($conn, "SELECT `name` FROM `item`") or die(mysqli_error($conn));
                while ($trow = mysqli_fetch_array($mitem)) {
                    echo "<option value=$trow[name]>";
                }
                echo "</datalist>";

                echo "<input type='hidden' name='code_$mctr' value='' class='form-control' >";
                echo "</td>";
                echo "<td>";
                echo "<input type='text' name='s5_$mctr' value='' class='form-control' style='text-align:right'>";
                echo "</td>";
                echo "<td>";
                echo "<input type='text' name='s6_$mctr' value='' class='form-control' style='text-align:right'>";
                echo "</td>";
                echo "<td>";
                echo "<input type='text' name='s7_$mctr' value='' class='form-control' style='text-align:right'>";
                echo "</td>";
                echo "<td>";
                echo "<input type='text' name='s8_$mctr' value='' class='form-control' style='text-align:right'>";
                echo "</td>";
                echo "<td>";
                echo "<input type='text' name='s9_$mctr' value='' class='form-control' style='text-align:right'>";
                echo "</td>";
                echo "<td>";
                echo "<input type='text' name='s10_$mctr' value='' class='form-control' style='text-align:right'>";
                echo "</td>";
                echo "<td>";
                echo "<input type='text' name='s11_$mctr' value='' class='form-control' style='text-align:right'>";
                echo "</td>";
                echo "<td>";
                echo "<input type='text' name='s12_$mctr' value='' class='form-control' style='text-align:right'>";
                echo "</td>";
                echo "<td>";
                echo "<input type='text' name='soth_$mctr' value='' class='form-control' style='text-align:right'>";
                echo "</td>";
                echo "<td>";
                echo "<input type='text' name='qty_$mctr' value='' class='form-control' style='text-align:right'>";
                echo "</td>";
                echo "<td>";
                echo "<input type='text' name='rate_$mctr' value='' class='form-control' style='text-align:right'>";
                echo "</td>";
                echo "</tr>";
            }

            echo "</table>";
            ?>
