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

$formname = 'Attendance Entry';
$maindb = 'attend';
$printfile = "";
$file = 'attendance.php';
$trandbexist = 0;
$keycond = " ";
$focusfield = "name";

$zroot = $_SESSION["zdir"];

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


$usertype = $_SESSION["usertype"];
$user = $_SESSION['username_' . $dbname];

mysqli_select_db($conn,$zdb);


//browse($addflag);
if (isset($_POST["submit"])) {
    mysqli_select_db($conn,$zdb);
    $a = 1;
    $vouchno = $_POST["vouchno"];
    $vouchdt = $_POST["vouchdt"];
    $mark = $_POST["mark"];
    $delv = $_POST["delv"];
    $delvdate = $_POST["delvdate"];
    $party = $_POST["party"];
    $nag = $_POST["nag"];
    $sizemm = $_POST["sizemm"];
    $guagemm = $_POST["guagemm"];
    $makemm = $_POST["makemm"];
    $dia = $_POST["dia"];
    $ap = $_POST["ap"];
    $weld = $_POST["weld"];
    $straight = $_POST["straight"];
    $foot = $_POST["foot"];
    $totfeet = $_POST["totfeet"];
    $weight = $_POST["weight"];
    $rate = $_POST["rate"];
    $amount = $_POST["amount"];
    $cashcred = $_POST["cashcred"];
    $descrip = $_POST["descrip"];
    $cashvouch = $_POST["cashvouch"];



    $count = $_POST["items"];
    $mvouch = $qvouch;
    $salecode = 15;



    if ($a == 1) {


        $genv = mysqli_query($conn,"SELECT MAX(vouchno) AS maxcode FROM `$maindb` where vouchno != ''  LIMIT 0,1 ") or die(mysqli_error($conn));
        if (mysqli_num_rows($genv) > 0) {
            $vouchn = mysqli_fetch_assoc($genv);
            $qvouch = $vouchn["maxcode"] + 1;
        } else {
            $qvouch = '1';
        }



        $mvouch = $qvouch;

        #############AUto Cash Receipt Start####################
        $mcashamt = $cashamt;







#################################TRAN PART END #################################
############################### Accounts Part ##################################
//        mysqli_query($conn,"DELETE FROM $zroot.`$accdb` WHERE `vouchno` = '$mvouch' AND `source`='$source' and `company`='$cmbcomp' and `brancode`='$brancode'") OR die(mysqli_error($conn));
//
//        if ($netamt > 0) {
//            $minus_amt = ($netamt * -1);
//
//// sale part
//            mysqli_query($conn,"INSERT INTO $zroot.`$accdb`( `company`, date, vouchno, source, trnno, accode, grpcode, amount, `brancode`)
//                    VALUES ('$cmbcomp', '$vouchdt','$mvouch', '$source', '001', '$salecode','005', '$netamt', '$brancode')") OR die(mysqli_error($conn));
//// party part
//            mysqli_query($conn,"INSERT INTO $zroot.`$accdb`(`company`, date, vouchno, source, trnno, accode, grpcode, amount, `brancode`)
//                     VALUES ('$cmbcomp', '$vouchdt','$mvouch', '$source', '002', '$name', '010', '$minus_amt', '$brancode')") or die(mysqli_error($conn));
//        }
############################## MAIN ######################################################
        mysqli_query($conn,"INSERT INTO `$maindb`(`vouchno`, `vouchdt`, `mark`, `delv`, `delvdate`, `party`, `nag`, `sizemm`,
                        `guagemm`,`makemm`, `dia`,`ap`, `weld`, `straight`, `foot`, `totfeet`, `weight`, `rate`,
                        `amount`, `cashcred`, `descrip`, `cashvouch`)
                 VALUES ('$qvouch', '$vouchdt', '$mark', '$delv', '$delvdate','$party', '$nag', '$sizemm',
                        '$guagemm', '$makemm', '$dia', '$ap', '$weld', '$straight', '$foot', '$totfeet', '$weight', '$rate',
                        '$amount', '$cashcred', '$descrip', '$cashvouch')") or die(mysqli_error($conn));


        insmess();
        $mvouch = $qvouch; //1
        header("refresh: 1; $grid?mode=last");
    }
}

mysqli_select_db($conn,$zdb);

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

<script src="MyScript/attendance.js" type="text/javascript"></script>

<style>
    .button {
        padding: 15px 25px;
        font-size: 15px;
        text-align: center;
        cursor: pointer;
        outline: none;
        color: #fff;
        background-color: #4CAF50;
        border: none;
        border-radius: 15px;
        box-shadow: 0 9px #999;
    }

    .button:hover {background-color: #3e8e41}

    .button:active {
        background-color: #3e8e41;
        box-shadow: 0 5px #666;
        transform: translateY(4px);
    }
    /* Sortable tables */
    table.sortable thead {
        /*background-color:#eee;*/
        /*color:#666666;*/
        font-weight: bold;
        cursor: default;
    }
    .table>tbody>tr>td {
        padding: 1px;
    }
    .form-control{
        padding: 0px 0px; 
    }
</style>

</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-6">
                <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</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" value="<?php Echo date(); ?>" /><br>
                        </div>                      
                    </div>

                    <div class="row">
                        <div class="col-lg-7 col-md-8 col-sm-8 col-xs-8 text-right pad">
                            <input id='addnew' value="Attendance Details" type="button"  class="btn btn-success mySearchTr btn btn-labeled btn-success">
                        </div>
                    </div>

                    <div class="row">
                        <div class="panel-footer">
                            <div style="overflow: auto; ">
                                <table class="table-condensed" style="margin: 0 auto;">
                                    <tr>
                                        <td class=" buttonform tooltip-bottom" id="ssubmit" style="" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Save Record">
                                            <button id='submit' type='submit' name='submit' value='<?php echo ($addflag == 0) ? "Update" : "Save"; ?>' class="btn btn-pad btn-square " style="background-color:#008D4C;display: inline; ">
                                                <i class="fa fa-check" style="color:#ffffff"></i>
                                            </button>
                                        </td>
                                        <td class=" buttonform tooltip-bottom" id="scancel" style="" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Cancel Record">
                                            <button id='cancel' type="button" class="btn btn-pad btn-square " style="background-color:#39CCCC; "  onClick="window.location.href = 'chalmain.php?mode=last'">
                                                <i class="fa fa-times" style="color:#ffffff"></i>
                                            </button>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="panel-body tohide" >
                    <div class="col-lg-11 table responsive ssload" style="overflow-y: scroll;height: 480px;">
                        <table class="table table-striped  table-bordered" width="100%" style="font-size: 11px;padding:0px;">
                            <thead>
                                <tr class="mySearchTr" style="background-color: #77BCFF;">
                                    
                                    <th style="width:7%;">Date</th>
                                    <th style="width: 10%">Description</th>
                                    <th style="width: 2%">C/R</th>
                                    <th style="width: 6%">Cashvouch</th>
                                </tr>
                            </thead>
                            <tbody class="sTbody">

                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <script type="text/javascript">
<?php if ($addflag == 0) { ?>
            $(".ndata").show();
            $("#submit").show();
            $(".mark").focus();
            $(".tohide").hide();
<?php } ?>
    </script>
    <?php include("includes/linksfoot.php"); ?>

</body>
</html>
