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

$formname = "Bank Reconcillation";
$maindb = 'actran';
$zdb = $_SESSION["zdbyear_" . $dbname];
$zyear = right($zdb, 4);
$mfrdate = getzdates($zyear, 'S');
$mtodate = getzdates($zyear, 'E');
/////--------------------------------------------
$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
$compcd = $_SESSION["comp_" . $dbname];
mysqli_select_db($conn, $zdb);

$usertype = $_SESSION["usertype_" . $dbname];
$username = $_SESSION["username_" . $dbname];

if (isset($_POST["submit"])) {
    $a = 1;
    if ($a == 1) {


        $a = 1;
        $count = $_POST["count"];
//    browse($count);
        $mvouch = $qvouch;
        $cnt = 0;
        for ($i = 0; $i <= $count; $i++) {

            $code = $_POST["code_$i"];
            $vouchno = $_POST["vouchno_$i"];
            $source = $_POST["source_$i"];
            switch ($source) {
                case 'Bank Receipt':
                    $sourc = 'BR';
                    break;
                case 'Bank Payment':
                    $sourc = 'BP';
                    break;
                case 'Contra':
                    $sourc = 'TR';
                    break;

                default:
                    break;
            }
            $clrdate = $_POST["clrdate_$i"];
            $chqno = $_POST["chqno_$i"];

//            if (!empty($clrdate)) {
            mysqli_query($conn, "UPDATE `$maindb` SET `clrdate`='$clrdate' WHERE `accode`='$code' and `vouchno`='$vouchno' and `source`='$sourc'") or die(mysqli_error($conn));

//            }
        }

        updmess();
        header("Refresh: 1; bankrecon.php");
    }
}

$senable = "";
$cenable = "";

include("includes/linkshead.php");
?>

<script>
    $(document).ready(function () {
        $("body").on(" blur", ".clrdate", chkclrdate);


        $(".savetabl").hide();
        $("#data").hide();


        $("#proceed").click(function () {
            var acname1 = $('.acname').val();

            if (acname1 == "") {
                alert("Bank Cannot Be Empty");
            } else {



                var acname = $('.acname').val(),
                        frmdate = $('.frmdate').val(),
                        todate = $('.todate').val(),
                        dtype = $('.dtype').val(),
                        scope = $('.scope').val();

                $.ajax({
                    type: "POST",
                    url: "bankrecon_fr.php",
                    data: {acname: acname, frmdate: frmdate, todate: todate, dtype: dtype, scope: scope},
                    success: function (result) {
                        if (result != '') {
                            $(".savetabl").show();
                            $(".proctabl").hide();
                        } else {
                            $(".proctabl").show();
                        }
                        $("#data").html(result);
                        $("#data").show();
                    }
                });
            }
        });


        function  chkclrdate() {
            var tr = $(this).closest("tr");
            var clrdate = tr.find('.clrdate').val();
            var vouchdt = tr.find('.vouchdt').val();

            if (clrdate < vouchdt) {
                alert("Clear Date Cannot Be Less Than Voucher Date");
//                clrdate.focus();
                tr.find('.clrdate').val("");
            }


        }


//        $('#submit').click(function () {
//
//            $('#bill').submit();
//        });

    });

</script>

</head>
<body>
    <form method='POST' action="">
        <!-- Default box -->
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12  pad">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><?php Echo $formname; ?></h3>
                    <div class="actions pull-right">
                        <!--<i class="fa fa-chevron-down"></i>-->
                        <!--<i class="fa fa-times"></i>-->
                    </div>
                </div>
                <div class="panel-body">
                    <div class="row proctabl">
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right">
                            <label class="control-label marg">Bank</label>
                        </div>
                        <div class="col-lg-3 col-md-7 col-sm-7 col-xs-7 pad">
                            <select class="form-control select2 acname" name='acname' required>
                                <option value=""></option>
                                <?php
                                $mown1 = mysqli_query($conn, "SELECT accode, bankinit, name FROM `accmast` where grpcode = '001' ORDER BY `name`") or die(mysqli_error($conn));
                                while ($trow1 = mysqli_fetch_array($mown1)) {
                                    echo "<option value='$trow1[accode]'>$trow1[name]</option>";
                                }
                                ?>
                            </select>
                        </div>
                    </div>
                    <div class="row proctabl">
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right">
                            <label class="control-label marg">From Date</label>
                        </div>
                        <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                            <input type="date" size="" name="frmdate" value="<?php echo $mfrdate; ?>" required class="form-control frmdate"/>
                        </div>
                    </div>
                    <div class="row proctabl">
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right">
                            <label class="control-label marg">To Date</label>
                        </div>
                        <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                            <input type="date" size="" name="todate" value="<?php echo $mtodate; ?>" required class="form-control todate"/>
                        </div>
                    </div>
                    <div class="row proctabl">
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right">
                            <label class="control-label marg">Type</label>
                        </div>
                        <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 pad">
                            <select id="cmbtype" name="dtype" class="form-control select2 dtype">
                                <option value="">All</option>   
                                <option value="BR">Receipt</option>   
                                <option value="BP">Payment</option>   
                                <option value="TR">Contra</option>   
                            </select>
                        </div>
                    </div>
                    <div class="row proctabl">
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right">
                            <label class="control-label marg">Scope</label>
                        </div>
                        <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 pad">
                            <select id="prinnar" name="scope" class="form-control select2 scope">
                                <option value="A">All</option>   
                                <option value="C">Cleared</option>   
                                <option value="N">Not Cleared</option>   
                            </select>
                        </div>
                    </div>
                    <div class='col-lg-9'>
                        <div style="overflow: auto; ">
                            <table class="table-condensed proctabl" style="margin: 0 auto;">
                                <tr>
                                    <td>
                                        <input id="proceed" type='button' name='proceed'  value='Proceed' class="btn btn-success">
                                    </td>
                                    <td>
                                        <input class="btn " style="background-color:red" type="button" onClick="window.location.href = '<?= 'default.php' ?>'" value="Exit" >
                                    </td>
                                </tr>
                            </table>
                            <table class="table-condensed savetabl"  style="margin: 0 auto;">
                                <tr>
                                    <td>
                                        <input id="submit" type='submit' name='submit'  value='Save' class="btn btn-success">
                                    </td>
                                    <td>
                                        <input class="btn " style="background-color:red" type="button" onClick="window.location.href = '<?= $file ?>'" value="Exit" />
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div class="col-lg-10 table-responsive"  id="data"  style="overflow-y:scroll; height: 600px">

                    </div>
                </div>
            </div>
        </div>
    </form>


    <?php include("includes/linksfoot.php"); ?>
</body>
</html>


