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

$formname = 'Attendance Entry';
$maindb = 'attend';
$printfile = "cash_print_fr.php";
$file = 'attendance.php';
$trandbexist = 0;
$grid = '';

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn,$zdb);
$keyfld = 'vouchdt';

include("includes/attnvouchno_generate.php");
include("includes/attnpv&nx.php");

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

    $vouchdt = $_POST["vouchdt"];
    $count = $_POST["items"];


    $a = 1;

    mysqli_query($conn,"DELETE FROM `$maindb` WHERE `$keyfld`='$vouchdt'") or die(mysqli_error($conn));

    $srl = 0;
    for ($i = 0; $i < $count; $i++) {
        $msrno = $_POST["srno_$i"];
        $staff = $_POST["staff_$i"];
        $salhrs = $_POST["salhrs_$i"];
        $hours = $_POST["hours_$i"];
        $advance = $_POST["advance_$i"];
        $remarks = $_POST["remarks_$i"];

        if (!empty($staff)) {
            $srl = $srl + 1;

            mysqli_query($conn,"INSERT INTO $maindb(`vouchdt`, `srno`, `staff`, `hours`, `advance`,`remark`) 
                    VALUES ('$vouchdt', '$srl', '$staff', '$hours', '$advance', '$remarks')") or die(mysqli_error($conn));
        }
    }
    insmess();
    header("refresh: 1; $file?$keyfld=$qvouch&mode=edit");
}
//browse($prevvouch);

if ($addflag != 1) {

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

    $result = mysqli_query($conn,"SELECT * FROM `$maindb` WHERE vouchdt = '$qvouch' ORDER BY vouchdt DESC LIMIT 0,1") or die(mysqli_error($conn));
    $get = mysqli_fetch_array($result);
        

}

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

if (isset($_GET["delete"])) {
    $vouchdt = $_GET["vouchdt"];
    $delcond2 = " vouchdt = '$vouchdt'  ";

//    delete($zdb, "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
    delnew($zdb, "$maindb", "$delcond2", "$file?mode=last");
}

include("includes/linkshead.php");
?>
<script src="MyScript/attendance.js" type="text/javascript"></script>
<script src="MyScript/attendance_search.js" type="text/javascript"></script>
</head>
<body>
    <form action='' method='POST'>
        <!-- Default box -->
        <div class="row">
            <div class="col-lg-8">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title" style="color:inherit"><?php Echo $formname; ?></h3>
                        <div class="actions pull-right">
                            <i class="fa fa-chevron-down"></i>
                            <i class="fa fa-times"></i>
                        </div>
                    </div>
                    <br>
                    <div class="row">
                        <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 text-right pad">
                            <label class="label-control marg date">Date</label>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                            <input type="date" id="vouchdt" name="vouchdt" class="form-control form date focusfield" value="<?php Echo ($addflag != 1) ? $get["vouchdt"] : date("Y-m-d"); ?>" autofocus/><br>
                        </div>
                    </div>
                    <div class="panel-body tohide" >
                        <!--<div class="col-lg-12 table responsive  ssload" style="overflow-y: scroll;">-->
                        <table class="table table-striped  table-bordered" width="100%" style="font-size: 14px;padding:0px;">
                            <thead>
                                <tr class="mySearchTr" style="background-color: #77BCFF;">
                                    <th style="width: 3%;"></th>
                                    <th style="width: 5%;">Sr.</th>
                                    <th style="width: 27%">Staff Name</th>
                                    <th style="width: 10%">Salhrs</th>
                                    <th style="width: 10%">Hours</th>
                                    <th style="width: 15%">Advance</th>
                                    <th style="width: 30%">Remarks</th>
                                </tr>
                            </thead>
                            <tbody class="data">

                            </tbody>

                        </table>
                        <div class="col-lg-12 pad">
<!--                            <input type="button" style="height: 30px; width: 30px; padding: 0px" id="addnew" class="btn btn-success btn-lg form" accode="addnew2" value="+" />-->
                            <button type="button" class="btn btn-primary btn-square "  id="addnew">
                                <i class="fa fa-plus" data-toggle='tooltip' title='Add Row'></i>    
                            </button>
                            <input type="hidden" id="items" name="items" value="<?php echo ($addflag != 1) ? $ctr : 1; ?>" />  
                        </div>
                    </div>
                    <!--</div>-->
                    <div class="row">
                        <div class="panel-footer">
                            <?php include('includes/buttons.php'); ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <script type="text/javascript">
        $(window).load(function () {
            $(".tohide").hide();
        });
        $(document).ready(function () {
            $(".tohide").hide();
        });
    </script>
    <div class="modal fade bs-example-modal-lg searchModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="myLargeModalLabel">Search <? Echo $formname; ?></h4>
                    <button class="close" data-dismiss="modal"><span>&times;</span></button>
                </div>
                <div class="modal-body">

                    <div class="row">
                        <div class="col-lg-2">
                            <select class="form-control sfield" style="color:#000000;">
                                <option value="1">Date</option>
<!--                                <option value="2">Staff</option>
                                <option value="3">Hours</option>
                                <option value="4">Advance</option>
                                <option value="5">Remark</option>-->
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control soperator" style="color:#000000;">
                                <option value="">Type of Search</option>
                                <option value="%">Like</option>
                                <option value="=">Exactly</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control sortBy" style="color:#000000;">
                                <option value="">Sort By</option>
                                <option value="1">Date</option>
<!--                                <option value="2">Staff</option>
                                <option value="3">Hours</option>
                                <option value="4">Advance</option>
                                <option value="5">Remark</option>-->
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control orderAs" style="color:#000000;">
                                <option value="desc">Desc</option>
                                <option value="asc">Asc</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <input type="text" value="" class="form-control ssearch" placeholder="Search Here">
                        </div>
                        <div class="col-lg-2">
                            <input type="button" class="btn btn-primary sload" value="Search" >
                        </div>
                    </div>
                    <div class="col-lg-12 sloader text-center">
                    </div>
                    <div class="col-lg-12 snoRecord text-center">
                        <h3>NO RECORDS FOUND</h3>
                    </div>
                    <div class="table-responsive" style="max-height: 400px;overflow: auto;">
                        <table id="" class="table table-striped table-condensed table-bordered" width="100%" style="margin-bottom:10px;">
                            <thead style="background-color:#39ADE1">
                                <tr class="mySearchTr">
                                    <th width="50%">Date</th>
<!--                                    <th width="30%">Staff</th>
                                    <th width="10%" style="text-align: right">Hours</th>
                                    <th width="10%" style="text-align: right">Advance</th>
                                    <th width="35%">Remark</th>-->
                                    <th width="50%">Action</th>
                                </tr>
                            </thead>
                            <tbody class="sTbody">
                            </tbody>
                        </table>
                    </div>
                    <div class="row">
                        <div class="col-xs-12 text-right search-action-bar">
                            <input type="button"  class="btn btn-primary sprev" value="Previous">
                            <input type="button"  class="btn btn-primary snext" value="Next">
                        </div>
                    </div>
                </div>
                <div class="modal-footer"></div>
            </div>
        </div>
    </div>
    <?php include("includes/linksfoot.php"); ?>
</body>
</html>
