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

$formname = 'Bank Reconciliation';
$maindb = 'bankrecp';
$trandb = 'accmast';
$file = 'bankreco.php';
$source = "BR";

$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);

if (isset($_GET["mode"]) == "true") {
    $addflag = 1;
} else {
    $addflag = 0;
}

if (isset($_POST['submit'])) {


    $count = $_POST["count"];
    for ($i = 0; $i < $count; $i++) {

        $mtype = $_POST["type_$i"];
        $mvouch = $_POST["vouchno_$i"];
        $mdate = $_POST["date_$i"];
        $mchqno = $_POST["chqno_$i"];
        $mchqdate = $_POST["chqdate_$i"];
        $mamount = $_POST["amount_$i"];
        $mclrdate = $_POST["clrdate_$i"];

        $cnt = $cnt + 1;

        ################################ CHECK EXISTING ITEMS #################################################
        mysqli_query($conn, "UPDATE `actran` SET `source`='$mtype', `vouchno`='$mvouchno', date ='$mdate', chqno = '$mchqno', chqdate = '$mchqdate',"
                . "         amount='$mamount', clrdate='$mclrdate' WHERE `source`='$mtype'")or die(mysqli_error($conn));
        if($mtype == 'BR'){
            mysqli_query($conn, "UPDATE `bankrecp` SET clrdate='$mclrdate' WHERE `vouchno`='$mvouchno' and `source`='$mtype'")or die(mysqli_error($conn));
        }
        
        if($mtype == 'BP'){
            mysqli_query($conn, "UPDATE `bankpay` SET clrdate='$mclrdate' WHERE `vouchno`='$mvouchno' and `source`='$mtype'")or die(mysqli_error($conn));
        }
        
        if($mtype == 'TR'){
            mysqli_query($conn, "UPDATE `contra` SET clrdate='$mclrdate' WHERE `vouchno`='$mvouchno' and `source`='$mtype'")or die(mysqli_error($conn));
        }
        
    }
    updmess();
//        header("refresh: 1; $file");
}
include('includes/files.php');
include('includes/combo2.php');
?> 
<script>
    $(document).ready(function () {

        $("#proceed").click(function () {
            alert('1');
            var group = $('#cmbgrp').val();
            var fromdate = $('#fromdt').val();
            var todate = $('#todt').val();

            $.ajax({
                type: "GET",
                url: "bankrecosrch.php",
                data: {code: group , fromdt : fromdate, todt : todate },
                success: function (result) {
                    $("#data").html(result);
                }
            });
        });
        $('#submit').click(function () {

            $('#bill').submit();
        });

    });


    $(document).keydown(function (event) {
        //19 for Mac Command+S
        if (!(String.fromCharCode(event.which).toLowerCase() == 's' && event.ctrlKey) && !(event.which == 19))
            return true;
        //alert("Ctrl-s pressed");
        $("#submit").click();
        event.preventDefault();
        return false;
    });

</script>
</head>
<body>
    <!--BEGIN INPUT TEXT FIELDS-->
    <form action=''  name="openstock" method="POST">

        <div class="row">
            <div class="col-lg-12" style='width:100%;float:left;'>
                <div class="box dark">
                    <header>
                        <div class="icons"><i class="fa fa-edit"></i></div>
                        <h5><?= $formname ?></h5>
                        <!-- .toolbar -->
                        <div class="toolbar">
                            <ul class="nav">
                                <!--  <li><a href="#">Link</a></li>
                                  <li class="dropdown">
                                      <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                                          <i class="fa fa-th-large"></i>
                                      </a>
                                      <ul class="dropdown-menu">
                                          <li><a href="">q</a></li>
                                          <li><a href="">a</a></li>
                                          <li><a href="">b</a></li>
                                      </ul>
                                  </li>-->
                                <li>
                                    <a class="accordion-toggle minimize-box" data-toggle="collapse" href="#div-1">
                                        <i class="fa fa-chevron-up"></i>
                                    </a>
                                </li>

                            </ul>
                        </div>
                        <!-- /.toolbar -->
                    </header>
                    <div id="div-1" class="accordion-body collapse in body">
                        <div class="form-horizontal">

                            <div class="form-group">
                                <label class="control-label col-lg-1">A/C. Group</label>

                                <div class="col-lg-5">
                                    <select id="cmbgrp" name="cmbgrp" style="height:35px;"  class="godown form-control">
                                        <option></option>
                                        <?php
                                        $mown = mysqli_query($conn, "SELECT * FROM `accmast` where `grpcode` = '001'") or die(mysqli_error($conn));
                                        while ($trow = mysqli_fetch_array($mown)) {
                                            echo "<option value=$trow[grpcode]>$trow[name]</option>";
                                        }
                                        ?>

                                    </select>
                                    <input type="text" id="custhidden" hidden>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-lg-1">From Date</label>
                                <div class="col-lg-2">
                                    <input type="date" class="form-control" size='80' name="fromdt" id="fromdt" value="<?php echo date('Y-m-d'); ?>">
                                </div>
                                <label class="control-label col-lg-1">To Date</label>
                                <div class="col-lg-2">
                                    <input type="date" class="form-control" size='80' name="todt" id="todt" value="<?php echo date('Y-m-d'); ?>">
                                </div>
                            </div>
                            <br>
                            <div class="form-group" style="padding-left: 22%;">
                                <input id="proceed" type='button' name='proceed'  value='Proceed' class="btn btn-success">
                                <input class="btn btn-danger" type="button" onClick="window.location.href = '<?= $grid ?>'" value="Exit   " />
                            </div>
                                
                            <!--<h4><b>Item List</b></h4>-->
                            <br/>
                        </div>
                    <!--</div>-->
<!--                </div>
            </div>-->
<!--            <div class="col-lg-6" style='width:100%;float:left;'>
                <div class="box dark">
                    <header>
                        <div class="icons"><i class="fa fa-edit"></i></div>
                        <h5>Item List</h5>
                         .toolbar 
                        <div class="toolbar">
                            <ul class="nav">


                                <li>
                                    <a class="accordion-toggle minimize-box" data-toggle="collapse" href="#div-2">
                                        <i class="fa fa-chevron-up"></i>
                                    </a>
                                </li>
                            </ul>
                        </div>
                         /.toolbar 
                    </header>-->
                    <!--<div id="div-2" class="accordion-body collapse in body">-->
                        <div style="overflow: auto; border: 0px solid;">
                            <div style="float:left;">
                                <div id='data'></div>                  
                            </div> 
                        </div> 

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

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