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

$formname = 'Transfer Alert';
$maindb = 'transacn';
$trandb = '';
$printfile = "";
$file = 'autotran.php';
//$fileadd = 'visaedit.php';
$trandbexist = 1;
$grid = '';
$keyfld = "vouchno";
$keycond = " ";
$focusfield = "name";
//$mgrpcode = '009';
$bseries = $_SESSION["user_series"];
$zroot = $_SESSION["zdir"];

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];

$compcd = $_SESSION["comp_" . $dbname];

$usertype = $_SESSION["usertype"];
$user = $_SESSION['username_' . $dbname];
//browse($user);

mysqli_select_db($conn, $zdb);
//include("includes/vouchno_generate.php");
//include("includes/prev&next.php");
$count = $_POST["items"];
if (isset($_POST["submit"])) {
    $date = date("Y-m-d");

    for ($i = 0; $i < $count; $i++) {


        $vouchno = $_POST["vouchno_$i"];
        $complete = $_POST["complete_$i"];

        if ($complete == 1) {
            mysqli_query($conn, "UPDATE `$maindb` SET `complete` = '$date' WHERE `vouchno`='$vouchno' and `source`='TR' and `compcode`!='$compcd'")or die(mysqli_error($conn));
        }
    }
}

if ($addflag != 1) {
    $getvouch = '';
    if ($addflag == 0) {
        $getvouch = $_GET[$keyfld];
    } else {
        $getvouch = $qvouch;
    }

//    $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE $keyfld='$getvouch'") or die(mysqli_error($conn));
//    $get = mysqli_fetch_array($result);
}

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


if (isset($_GET["delete"])) {
    delete($zdb, "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
}

include("includes/linkshead.php");
?>
<!--<script src="MyScript/leadenq.js" type="text/javascript"></script>-->
<script type="text/javascript">

</script>
<script type="text/javascript">
//    $(document).keydown(function (event) {
//        if (!(String.fromCharCode(event.which).toLowerCase() == 'a' && event.altKey) && !(event.which == 19))
//            return true;
//        $("#add").click();
//        event.preventDefault();
//        return false;
//    });
//
//    $(document).keydown(function (event) {
//        //19 for Mac Command+S
//        if (!(String.fromCharCode(event.which).toLowerCase() == 's' && event.altKey) && !(event.which == 19))
//            return true;
//        //alert("Ctrl-s pressed");
//        $("#update").click();
//        event.preventDefault();
//        return false;
//    });
//
//    $(document).keydown(function (event) {
//        //19 for Mac Command+S
//        if (!(String.fromCharCode(event.which).toLowerCase() == 'f' && event.altKey) && !(event.which == 19))
//            return true;
//        //alert("Ctrl-s pressed");
//        $("#btsearch").click();
//        event.preventDefault();
//        return false;
//    });
</script>

</head>
<body>
    <!--    <div id="preloader" class="col-lg-12 text-center">
            <h3 class="text-center">Loading</h3>
            <div id="status">&nbsp;</div>
        </div>-->
    <form action='' method='POST'>
        <!-- Default box -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-body table-responsive" style="width:100%">
                        <div class="container" style="float:right;">
                            <input style="padding-right: 15px;float:right;width:17%;"  type='submit' id="update" name='submit' value='SAVE' class="btn btn-success">
                        </div>
                        <table id="example1" class="table-bordered" width="100%">
                            <thead>
                                <tr style="background-color: #78909C">
                                    <th style="width: 5%;">Sr.</th>
                                    <th style="width: 5%;">Voucher</th>
                                    <th style="width: 15%;">Date</th>
                                    <th style="width: 25%;">From</th>
                                    <th style="width: 5%;">Action</th>
                                    <th style="width: 5%;">Close</th>
                                </tr>
                            </thead>
                            <tbody class="mytable table-bordered">
                                <?php
                                $srchresult = mysqli_query($conn, "SELECT vouchno, DATE_FORMAT(`vouchdt`, '%d-%m-%Y')as vouchdt, compcode, source, qty
                                                            FROM `transacn` where `complete`= '0000-00-00' and `source`='TR' and `compcode`!='$compcd' group by vouchno order by vouchdt DESC") or die(mysqli_error($conn));
                                $ctr = 0;
                                $mctr = 0;
                                while ($row = mysqli_fetch_array($srchresult)) {
                                    $mctr++;

                                    $gettech = mysqli_query($conn, "SELECT * FROM $zroot.`company` WHERE `code` ='$row[compcode]' ") or die(mysqli_error($conn));
                                    $tech = mysqli_fetch_array($gettech);

                                    echo "<tr>";
                                    Echo "<td style='align:center;' class=''>$mctr</td>";
                                    Echo "<td style='align:center;' class=''><input type='text' style='border:none;background-color:white' name= 'vouchno_$ctr' value='$row[vouchno]' class='vouchno form-control' readonly></a></td>";
                                    Echo "<td  class=''>$row[vouchdt]</td>";
                                    Echo "<td class=''>$tech[name]</td>";
                                    echo "<td align=center><a href=\"autotran_edit.php?mode=edit&vouchno=$row[vouchno]\"><img class='' src='images/edit.png'></a></td>";
                                    Echo "<td style='align:center;padding-left:25px;' class=''><input type='checkbox' style='border:none;height:25px;width:25px;' align='center' name= 'complete_$ctr' value='1' class='commplete form-control'></a></td>";
                                    echo "</tr>";
                                    $ctr++;
                                }
                                ?>
                            <input type = "text" style="display: none;" name = "items" value = "<? Echo $ctr; ?>">
                            </tbody> 
                        </table>

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

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

</body>
</html>
