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

ini_set('display_errors', 1);
error_reporting(E_ERROR);

$formname = 'Employee';
$maindb = 'accmast';
$imagedb = 'kariimg';
$file = 'karigar.php';
$grid = '';
$keyfld = "accode";
$keycond = "";
$keycond1 = " AND `grpcode`='040'";
$trandbexist = 0;
$focusfld = "name";
$printfile = 'karigar_print.php';
$type = 'K';
$myyear = $_SESSION[$myyear];
$compcode2 = $_SESSION["comp_" . $dbname];
if ($compcode2 == "") {
    $compcode = 1;
} else {
    $compcode = $_SESSION["comp_" . $dbname];
}


//$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
include("includes/vouchno_generate.php");
include("includes/prev&next.php");

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

    $a = 1;

    $mgrpcode = '040';
    $name = mysqli_real_escape_string($conn, $_POST["name"]);
    $karigcode = $_POST["karigcode"];
    $refcode = $_POST["refcode"];
    $refname = $_POST["refname"];
    $refcodenew = $_POST["refcodenew"];
    $gender = $_POST["gender"];
    $add1 = mysqli_real_escape_string($conn, $_POST["add1"]);
    $add2 = mysqli_real_escape_string($conn, $_POST["add2"]);
    $add3 = mysqli_real_escape_string($conn, $_POST["add3"]);
    $city = $_POST["city"];
    $pin = $_POST["pin"];
    $coun = $_POST["country"];
    $station = $_POST["station"];
    $mob = $_POST["mobile"];
    $tel = $_POST["tel"];
    $cpers1 = $_POST["contpers"];
    $emgcontpers = $_POST["emgcontpers"];
    $emgcontno = $_POST["emgcontno"];
    $email = $_POST["email"];
    $openbal = $_POST["openbal"];
    $opendc = $_POST["dc"];
    $process = $_POST["process"];
    $acdate = $_POST["acdate"];
    $acno = $_POST["acno"];
    $bankname = $_POST["bankname"];
    $ifsc = $_POST["ifsc"];
    $mode = $_POST["mode"];
    $state = $_POST["state"];
    $statecode = $_POST["statecode"];

    $active = $_POST["active"];
    $autoinactive = $_POST["autoinactive"];
    $pancard = $_POST["pancard"];
    $aadhar = $_POST["aadhar"];
    $nickname = $_POST["nickname"];
    $starttime = $_POST["starttime"];
    $endtime = $_POST["endtime"];
    $dept = $_POST["dept"];
    $pfund = $_POST["pfund"];
    $esic = $_POST["esic"];
    $ptax = $_POST["p_tax"];
    $basic = $_POST["basic"];
    $da = $_POST["da"];
    $hra = $_POST["hra"];
    $ta = $_POST["ta"];
    $oa = $_POST["oa"];
    $total = $_POST["total"];
    $pfpercent = $_POST["pfpercent"];
    $esicperct = $_POST["esicperct"];
    $location = $_POST["location"];
    $designation = $_POST["designation"];

    if ($name == "") {
        $a = 0;
        browse("Name Cannot Be Empty");
        if ($addflag == 1) {
            header("location:javascript://history.go(-1)");
        } else {
            header("refresh: ; $file?mode=last");
        }
    }

    // if ($process == "") {
    //     $a = 0;
    //     browse("Process Cannot Be Empty");
    //     if ($addflag == 1) {
    //         header("location:javascript://history.go(-1)");
    //     } else {
    //         header("refresh: ; $file?mode=last");
    //     }
    // }

    if (isset($_POST["name"])) {
        $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE `name`= '$name' AND accode != '$qvouch'") or die(mysqli_error($conn));
        if (mysqli_num_rows($result) > 0) {
            $a = 0;
            browse("Name Already Exist");
            header("refresh: 1; $file?mode=last");
        }
    }


    if ($a == 1) {
        if ($addflag == 1) {
            mysqli_query($conn, "INSERT INTO `$maindb`(accode,`custcode`, `name`, `nickname`, `add1`, `add2`, `add3`, `city`, `pin`, `station`, `country`, mobile ,tel,mode,
                                                 deptcode ,`email`, `contpers`, `emgcontpers`, `emgcontno`, `pancard`, `aadhar`, openbal, `dc`, grpcode, `process`,bankname,ifsc,refcodenew,
                                                 `acdate`, `active`, autoinactive, `type`,`starttime`, endtime, `pfund`, `esic`, `p_tax`, `basic`, `da`, `hra`, `ta`, `oa`, `total`,acno,
                                                 gender,refcode,`location`,`state`,`statecode`, refname, designation)
                                        VALUES($qvouch,'$karigcode','$name', '$nickname', '$add1', '$add2', '$add3', '$city', '$pin', '$station', '$coun', '$mob' , '$tel', '$mode',
                                              '$dept','$email', '$cpers1', '$emgcontpers', '$emgcontno', '$pancard', '$aadhar', '$openbal', '$opendc', '$mgrpcode', '$process','$bankname','$ifsc','$refcodenew',
                                              '$acdate', '$active','$autoinactive','K','$starttime', '$endtime','$pfund', '$esic', '$ptax','$basic', '$da', '$hra', '$ta', '$oa', '$total','$acno',
                                              '$gender','$refcode', '$location','$state','$statecode', '$refname', '$designation')") or die(mysqli_error($conn));
            insmess();
            $mvouch = $_GET["vouchno"];
            $mvouch = $qvouch;
            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
            //            header("refresh: 1; $file?mode=true");
        } else {
            $mvouch = $qvouch;
            mysqli_query($conn, "UPDATE `$maindb` SET `custcode`='$karigcode', `name`='$name', `nickname`='$nickname',`add1`='$add1', `add2`='$add2', `add3`='$add3', `city`='$city', 
                                              `pin`='$pin', `station`='$station', `country`='$coun', mobile= '$mob',tel='$tel',starttime='$starttime', endtime='$endtime', 
                                               fax='$fax', mobile='$mob', deptcode='$dept', `email`='$email', `contpers`='$cpers1', `emgcontpers`='$emgcontpers',gender='$gender',refcode='$refcode', 
                                              `emgcontno`='$emgcontno', `pancard`='$pancard', `aadhar`='$aadhar',  openbal='$openbal', `dc`='$opendc', `process`='$process',refcodenew='$refcodenew',
                                              `acdate`='$acdate', `active`='$active', autoinactive='$autoinactive', `pfund`='$pfund',acno='$acno',bankname='$bankname',ifsc='$ifsc',
                                              `esic`='$esic',`p_tax`='$ptax',`basic`='$basic', `da`='$da', `hra`='$hra', `ta`='$ta', mode='$mode',
                                              `oa`='$oa', `total`='$total', `location`='$location',`state`='$state',`statecode`='$statecode', `refname`='$refname',
                                              `designation`='$designation'  where accode = '$mvouch' AND `type` = 'K'") or die(mysqli_error($conn));

            updmess();
            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
            //            header("refresh: 1; $grid");
        }

        //karigar image
        $fileNameold = $qvouch . ".jpg";
        $imgp = mysqli_query($conn, "SELECT * FROM `$imagedb` WHERE `code`='$qvouch'") or die(mysqli_error($conn));
        $gimg = mysqli_fetch_array($imgp);
        $path1 = $gimg['path'];
        if (file_exists($path1 . $fileNameold)) {
            unlink($path1 . $fileNameold);
        }

        $path = "admin/" . $compcode . "karigar_image/";
        $fileName = $qvouch . ".jpg";
        //        browse($fileName);
        $img_file = $path . ($fileName);
        //        browse($img_file);

        $fileTmpLoc = $_FILES["file3"]["tmp_name"]; // File in the PHP tmp folder
        $fileType = $_FILES["file3"]["type"]; // The type of file it is
        $fileSize = $_FILES["file3"]["size"]; // File size in bytes
        $fileErrorMsg = $_FILES["file3"]["error"]; // 0 for false... and 1 for true
        //        aadhar front image


        $apath = "admin/" . $compcode . "/aadhfront/";
        $fileName = $qvouch . ".jpg";
        //        browse($fileName);
        $aimg_file = $apath . ($fileName);
        //        browse($img_file);

        $afileTmpLoc = $_FILES["filea"]["tmp_name"]; // File in the PHP tmp folder
        $afileType = $_FILES["filea"]["type"]; // The type of file it is
        $afileSize = $_FILES["filea"]["size"]; // File size in bytes
        $afileErrorMsg = $_FILES["filea"]["error"]; // 0 for false... and 1 for true

        if ($afileSize < 50000) {
            move_uploaded_file($afileTmpLoc, "$aimg_file");
        } else {
            browse("Aadhar Front Image Size is Greater than 20KB");
        }

        //        aadhar back image


        $bpath = "admin/" . $compcode . "/aadhback/";
        $fileName = $qvouch . ".jpg";
        //        browse($fileName);
        $bimg_file = $bpath . ($fileName);
        //        browse($img_file);

        $bfileTmpLoc = $_FILES["fileb"]["tmp_name"]; // File in the PHP tmp folder
        $bfileType = $_FILES["fileb"]["type"]; // The type of file it is
        $bfileSize = $_FILES["fileb"]["size"]; // File size in bytes
        $bfileErrorMsg = $_FILES["fileb"]["error"]; // 0 for false... and 1 for true

        if ($bfileSize < 50000) {
            move_uploaded_file($bfileTmpLoc, "$bimg_file");
        } else {
            browse("Aadhar Back Image Size is Greater than 20KB");
        }

        //        aadhar front image 


        $ppath = "admin/" . $compcode . "/pancard/";
        $fileName = $qvouch . ".jpg";
        //        browse($fileName);
        $pimg_file = $ppath . ($fileName);
        //        browse($img_file);

        $pfileTmpLoc = $_FILES["filep"]["tmp_name"]; // File in the PHP tmp folder
        $pfileType = $_FILES["filep"]["type"]; // The type of file it is
        $pfileSize = $_FILES["filep"]["size"]; // File size in bytes
        $pfileErrorMsg = $_FILES["filep"]["error"]; // 0 for false... and 1 for true

        if ($pfileSize < 50000) {
            move_uploaded_file($pfileTmpLoc, "$pimg_file");
        } else {
            browse("Pan Card Image Size is Greater than 20KB");
        }

        if ($fileSize < 50000) {
            move_uploaded_file($fileTmpLoc, "$img_file");
        } else {
            browse("Karigar Image Size is Greater than 20KB");
        }
        // browse("$fileName upload is complete");


        $imgp1 = mysqli_query($conn, "SELECT * FROM `$imagedb` where code = '$mvouch'") or die(mysqli_error($conn));
        $gimg1 = mysqli_fetch_array($imgp1);
        if (mysqli_num_rows($imgp1) > 0) {
            mysqli_query($conn, "UPDATE `$imagedb` SET `imgpath`='$img_file', aadharfront='$aimg_file', aadharback='$bimg_file', panimg='$pimg_file' WHERE `code`='$qvouch' ") or die(mysqli_error($conn));
        } else {
            mysqli_query($conn, "INSERT INTO `$imagedb`(`code`,`imgpath`,`aadharfront`, `aadharback`, `panimg`)
                                            VALUES('$qvouch', '$img_file','$aimg_file', '$bimg_file', '$pimg_file')") or die(mysqli_error($conn));
        }



        //        if (!empty($fileTmpLoc)) {
        //            if (move_uploaded_file($fileTmpLoc, "$img_file")) {
        //
        //                ###########################SAVE PART################################################   
        //                $imgp = mysqli_query($conn, "SELECT * FROM `$imagedb`")or die(mysqli_error($conn));
        //                $gimg = mysqli_fetch_array($imgp);
        //
        //                mysqli_query($conn, "DELETE FROM `$imagedb` WHERE code='$qvouch' ") or die(mysqli_error($conn));
        //
        //                if ($gimg['vouchno'] == $qvouch) {
        //
        ////        print " UPDATE `itemimage` SET `vouchno`='$qvouch', `imgpath`='$img_file' WHERE `vouchno`='$qvouch' ";
        //                    mysqli_query($conn, "UPDATE `$imagedb` SET `code`='$qvouch', `imgpath`='$img_file' WHERE `code`='$qvouch' ") or die(mysqli_error($conn));
        //                }
        //
        //                mysqli_query($conn, "INSERT INTO `$imagedb`(`code`,`imgpath`)
        //                                            VALUES('$qvouch', '$img_file')") or die(mysqli_error($conn));
        //            } else {
        //
        //                browse("move_uploaded_file function failed");
        //            }
        //        }
    }
}



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

    $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE $keyfld='$getvouch' $keycond ") or die(mysqli_error($conn));
    $get = mysqli_fetch_array($result);
    $karigcode = $get['custcode'];

    $result2 = mysqli_query($conn, "SELECT * FROM `$imagedb` WHERE code ='$getvouch' ") or die(mysqli_error($conn));
    $get2 = mysqli_fetch_array($result2);


    $getdept = mysqli_query($conn, "SELECT * FROM `dept` WHERE `code`='$get[deptcode]'") or die(mysqli_error($conn));
    $fdept = mysqli_fetch_array($getdept);
}

if ($addflag == 1) {
    $result = mysqli_query($conn, "SELECT max(cast(custcode as decimal(10))) as maxcustcode FROM `$maindb` WHERE `grpcode`='009'") or die(mysqli_error($conn));
    $get = mysqli_fetch_array($result);
    $addkarigcode = $get['maxcustcode'] + 1;
}

/* DELETE */
if (isset($_GET["delete"])) {
    $chkdel = mysqli_query($conn, "SELECT accode FROM `payproc` WHERE `accode`='$_GET[$keyfld]'") or die(mysqli_error($conn));
    $cntdel1 = mysqli_num_rows($chkdel);
    $chkdel2 = mysqli_query($conn, "SELECT accode FROM `attdtran` WHERE `accode`='$_GET[$keyfld]'") or die(mysqli_error($conn));
    $cntdel2 = mysqli_num_rows($chkdel2);
    $cntdel = $cntdel1 + $cntdel2;
    if ($cntdel > 0) {
        browse("Employee Exists in Transactions");
        header("refresh: 1; $file?$keyfld=$_GET[$keyfld]&mode=edit");
    } else {

        delete($zdb, "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
    }
}
include("includes/linkshead.php");
?>

<script type="text/javascript">
    $(document).ready(function() {
        $("body").on("blur", ".karigcode", ExistKarig);
        $("body").on("change", ".dept", Department);

        function ExistKarig() {
            var karigar = $(".karigcode").val();
            if (karigar == '') {
                alert('Karigar Code Cannot Be Empty');
                $(".karigcode").focus();
            }
            $.post("get_existkarig.php", {
                karigar: karigar
            }, function(data) {
                if (data > 0) {
                    $(".karigcode").val('');
                    $(".karigcode").focus();
                }
            });

        }

        function Department() {
            var dept = $("#dept").val();

            $.post("get_dept.php", {
                dept: dept
            }, function(data) {
                $(".process").html(data);
            });

        }

    });
</script>
<script type="text/javascript">
    function keyPressed() {
        var key = event.keyCode || event.charCode || event.which;
        return key;
    }
</script>
<style>
    .padd {
        padding-top: 5px;
    }
</style>

<script src="MyScript/karigar.js?a=<?= mt_rand() ?>" type="text/javascript"></script>
<script src="MyScript/karigar_search.js?b=<?= mt_rand() ?>" type="text/javascript"></script>
</head>

<body>
    <form action='' method='POST' enctype="multipart/form-data">

        <!-- Default box -->

        <div class="row">
            <div class="col-lg-6">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><?php echo $formname; ?></h3>
                    </div>

                    <div class="panel-body">
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-2 col-xs-2 text-right pad">
                                <label class="control-label"> Code</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="text" name="karigcode" value="<?php echo ($addflag != 1) ? $karigcode : $addkarigcode; ?>" maxlength="3" class="form-control form karigcode" required readonly tabindex="-1" />
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 text-right pad" style="width: 80px;">
                                <label class="control-label text-right pad">Ref Code</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="text" name="refcode" oninput='this.value = this.value.replace(/[,]/g, "")' value="<?php echo ($addflag != 1) ? $get['refcode'] : ""; ?>" maxlength="10" class="form-control form refcode" />
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-1 col-xs-1 text-right pad" style="width: 110px;">
                                <label class="control-label text-right pad">Ref Name</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-2 col-xs-2 pad">
                                <input type="text" name="refname" value="<?php echo ($addflag != 1) ? $get['refname'] : ""; ?>" class="form-control form refname" readonly tabindex="-1" />
                            </div>
                        </div>

                        <div class="row">
                            <label class="control-label col-lg-3 col-md-3 col-sm-2 col-xs-2 text-right pad">Name</label>
                            <div class="col-lg-8 col-md-9 col-sm-9 col-xs-9 pad">
                                <input type="hidden" size="40" value="<?php echo ($addflag != 1) ? $get['accode'] : "$qvouch"; ?>" class="form-control form accode" required />
                                <input type="text" size="40" oninput='this.value = this.value.replace(/[,]/g, "")' name="name" value="<?php echo ($addflag != 1) ? $get['name'] : ""; ?>" class="form-control form name focusfield" required />
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="control-label  " style="color: #a7c957;">Name (Govt. Id.)</label>
                            </div>
                            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" size="40" oninput='this.value = this.value.replace(/[,]/g, "")' name="nickname" value="<?php echo ($addflag != 1) ? $get['nickname'] : ""; ?>" class="form-control form" />
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-2 col-xs-2 text-right pad">
                                <label class="control-label">Gender</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 pad">
                                <select class="form-control form gender select2" name="gender">
                                    <option value="M" <?= ($addflag != 1 && $get["gender"] == "M") ? "selected" : "" ?>>Male</option>
                                    <option value="F" <?= ($addflag != 1 && $get["gender"] == "F") ? "selected" : "" ?>>Female</option>
                                </select>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-2 col-xs-2 text-right pad">
                                <label class="control-label">Address</label>
                            </div>
                            <div class="col-lg-8 col-md-9 col-sm-9 col-xs-9 pad">
                                <input type="text" size="80" oninput='this.value = this.value.replace(/[,]/g, "")' name="add1" value="<?php echo ($addflag != 1) ? $get['add1'] : ""; ?>" class="form-control form" />
                                <input type="text" size="80" oninput='this.value = this.value.replace(/[,]/g, "")' name="add2" value="<?php echo ($addflag != 1) ? $get['add2'] : ""; ?>" class="form-control form" />
                                <input type="text" size="80" oninput='this.value = this.value.replace(/[,]/g, "")' name="add3" value="<?php echo ($addflag != 1) ? $get['add3'] : ""; ?>" class="form-control form" />
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">City</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="text" class="form-control form" oninput='this.value = this.value.replace(/[,]/g, "")' name="city" autocomplete="off" value="<?php echo ($addflag != 1) ? $get["city"] : ""; ?>">
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Pin</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="text" maxlenght="8" oninput='this.value = this.value.replace(/[,]/g, "")' size="8" name="pin" class="form-control form" value="<?php echo ($addflag != 1) ? $get['pin'] : ""; ?>" />
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-3 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="control-label">Mobile</label>
                            </div>
                            <div class="col-lg-8 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="number" name="mobile" oninput='this.value = this.value.replace(/[,]/g, "")' class="form-control form" value="<?php echo ($addflag != 1) ? $get['mobile'] : ""; ?>" />
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-3 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">State</label>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 pad">
                                <select name="state" class="form-control form state select2" required>
                                    <option value="<?php echo ($addflag != 1) ? $get['state'] : ""; ?>"><?php echo ($addflag != 1) ? $get['state'] : " "; ?></option>
                                    <?php
                                    $mown4 = mysqli_query($conn, "SELECT `code`, `name` FROM `state` ORDER BY name") or die(mysqli_error($conn));
                                    while ($trow4 = mysqli_fetch_array($mown4)) {
                                        echo "<option value='$trow4[name]'>$trow4[name]</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">State Code</label>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                                <input type="text" class="form-control form number numeric statecode" required name="statecode" value="<?php echo ($addflag != 1) ? $get["statecode"] : ""; ?>" readonly>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4 text-right pad">
                                <label class="control-label" style="color:red;">Emergency Contact Person</label>
                            </div>
                            <div class="col-lg-8 col-md-7 col-sm-7 col-xs-7 pad">
                                <input type="text" size="40" oninput='this.value = this.value.replace(/[,]/g, "")' name="emgcontpers" class="form-control form" value="<?php echo ($addflag != 1) ? $get['emgcontpers'] : ""; ?>" />
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4 text-right pad">
                                <label class="control-label" style="color:red;">Emergency Contact Mobile</label>
                            </div>
                            <div class="col-lg-2 col-md-7 col-sm-7 col-xs-7 pad">
                                <input type="text" size="40" name="emgcontno" oninput='this.value = this.value.replace(/[,]/g, "")' class="form-control form" value="<?php echo ($addflag != 1) ? $get['emgcontno'] : ""; ?>" />
                            </div>
                            <div class="col-lg-3 text-right pad">
                                <!-- <label class="control-label">Opening Balance</label> -->
                            </div>
                            <div class="col-lg-2 pad">
                                <!-- <input type="text" size="40" oninput='this.value = this.value.replace(/[,]/g, "")' name="openbal" class="form-control form text-right" value="<?php echo ($addflag != 1) ? $get['openbal'] : ""; ?>" /> -->
                            </div>
                            <div class="col-lg-1 pad">

                            </div>
                        </div>

                        <script language="javascript" type="text/javascript">
                            function removeSpaces(string) {
                                return string.split(' ').join('');
                            }
                        </script>

                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="control-label ">Pan Card No.</label>
                            </div>
                            <div class="col-lg-3 col-md-4 col-sm-4 col-xs-4 pad">
                                <input type="text" oninput='this.value = this.value.replace(/[,]/g, "")' onblur="this.value = removeSpaces(this.value);" size="40" name="pancard" maxlength="10" pattern="[A-Z]{5}[0-9]{4}[A-Z]{1}" class="form-control form pancard" value="<?php echo ($addflag != 1) ? $get['pancard'] : ""; ?>"
                                    onKeyDown="javascript: var keycode = keyPressed(event);
                                        if (keycode == 32) {
                                            return false;
                                        }" />
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="control-label marg" style="color: red;">Active</label>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                                <input type="checkbox" name="active" value="1" class="form form-control" style="width: 30px" <?
                                                                                                                                if ($get['active'] == "") {
                                                                                                                                    echo "unchecked";
                                                                                                                                } else {
                                                                                                                                    echo "checked";
                                                                                                                                }
                                                                                                                                ?>>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="control-label ">Aadhar Card No.</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4 pad">
                                <input type="text" onblur="this.value = removeSpaces(this.value);" oninput='this.value = this.value.replace(/[,]/g, "")' size="40" name="aadhar" maxlength="12" class="form-control form aadhar" value="<?php echo ($addflag != 1) ? $get['aadhar'] : ""; ?>" onKeyDown="javascript: var keycode = keyPressed(event);
                                        if (keycode == 32) {
                                            return false;
                                        }" />
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="control-label">Department</label>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 pad">
                                <select id="dept" name="dept" class="form-control dept form select2" required>
                                    <option value="<?php echo ($addflag != 1) ? $fdept['code'] : ""; ?>"><?php echo ($addflag != 1) ? $fdept['name'] : ""; ?></option>
                                    <?php
                                    $mdept = mysqli_query($conn, "SELECT `code`, `name` FROM `dept` ORDER BY name") or die(mysqli_error($conn));
                                    while ($tdept = mysqli_fetch_array($mdept)) {
                                        echo "<option value=$tdept[code]>$tdept[name]</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-lg-6">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">Details</h3>

                        <div class="row" style="background-color: aqua">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Bank Name</label>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 pad">
                                <input type="text" oninput='this.value = this.value.replace(/[,]/g, "")' class="form-control form" name="bankname" value="<?php echo ($addflag != 1) ? $get["bankname"] : ""; ?>">
                            </div>
                        </div>
                        
                        <div class="row" style="background-color: aqua">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">IFSC Code</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="text" oninput='this.value = this.value.replace(/[,]/g, "")' class="form-control form" name="ifsc" value="<?php echo ($addflag != 1) ? $get["ifsc"] : ""; ?>">
                            </div>
                        </div>
                        
                        <div class="row" style="background-color: aqua">
                            <label class="control-label col-lg-3 text-right pad">A/c No.</label>
                            <div class="col-lg-3 pad">
                                <input type="text" oninput='this.value = this.value.replace(/[,]/g, "")' maxlength="20" id="acno" name="acno" value="<?php echo ($addflag != 1) ? $get['acno'] : ""; ?>" class="form-control form" />
                            </div>
                        </div>

                        <div class="row" style="background-color: aqua">
                            <label class="control-label col-lg-3 text-right pad">Designation</label>
                            <div class="col-lg-3 pad">
                                <input type="text" name="designation" value="<?php echo ($addflag != 1) ? $get['designation'] : ""; ?>" class="form-control form designation" />
                            </div>
                        </div>

                        <!-- <div class="row" style="background-color: aqua">
                            <label class="control-label col-lg-3 text-right pad">Mode</label>
                            <div class="col-lg-2 col-md-1 col-sm-8 col-xs-8 pad">
                                <select class="form-control form inspacdelv selct2 pfund" name="mode">
                                    <option value=''></option>
                                    <option value='C' <?php
                                                        if ($addflag != 1) {
                                                            if ($get["mode"] == "C") {
                                                                echo "selected='selected'";
                                                            }
                                                        }
                                                        ?>>Cash</option>
                                    <option value='B' <?php
                                                        if ($addflag != 1) {
                                                            if ($get["mode"] == "B") {
                                                                echo "selected='selected'";
                                                            }
                                                        }
                                                        ?>>Bank</option>
                                </select>
                            </div>
                        </div> -->
                        <!--
                        <div class="row"  style="background-color: yellow">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">A/c. No.</label>
                            </div>
                            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form" name="acnum" value="<?php echo ($addflag != 1) ? $get["acnum"] : ""; ?>" >
                            </div>
                        </div> -->
                        <!-- 
                        <div class="row">
                            <label class="control-label col-lg-3 text-right pad">Last A/c Date </label>
                            <div class="col-lg-8 pad">
                                <input type="date" style="width:189px; height:33px" id="acdate" name="acdate" value="<?php echo ($addflag != 1) ? $get['acdate'] : date("Y-m-d"); ?>" class="form-control form" required />
                            </div>
                        </div> -->

                        <!-- <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">P.Fund</label>
                            </div>
                            <div class="col-lg-2 col-md-1 col-sm-8 col-xs-8 pad">
                                <select class="form-control form inspacdelv selct2 pfund" name="pfund">
                                    <option value=''></option>
                                    <option value='Y' <?php
                                                        if ($addflag != 1) {
                                                            if ($get["pfund"] == "Y") {
                                                                echo "selected='selected'";
                                                            }
                                                        }
                                                        ?>>Yes</option>
                                    <option value='N' <?php
                                                        if ($addflag != 1) {
                                                            if ($get["pfund"] == "N") {
                                                                echo "selected='selected'";
                                                            }
                                                        }
                                                        ?>>No</option>
                                </select>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">ESIC</label>
                            </div>
                            <div class="col-lg-2 col-md-1 col-sm-8 col-xs-8 pad">
                                <select name="esic" class="form-control form esic selct2">
                                    <option value=""></option>
                                    <option value="Y" <?php
                                                        if ($addflag != 1) {
                                                            if ($get["esic"] == "Y") {
                                                                echo "Selected='selected'";
                                                            }
                                                        }
                                                        ?>>Yes</option>
                                    <option value="N" <?php
                                                        if ($addflag != 1) {
                                                            if ($get["esic"] == "N") {
                                                                echo "Selected='selected'";
                                                            }
                                                        }
                                                        ?>>No</option>
                                </select>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">P.T</label>
                            </div>
                            <div class="col-lg-2 col-md-1 col-sm-8 col-xs-8 pad">
                                <select name="p_tax" class="form-control form  selct2">
                                    <option value=""></option>
                                    <option value="Y" <?php
                                                        if ($addflag != 1) {
                                                            if ($get["p_tax"] == "Y") {
                                                                echo "Selected='selected'";
                                                            }
                                                        }
                                                        ?>>Yes</option>
                                    <option value="N" <?php
                                                        if ($addflag != 1) {
                                                            if ($get["p_tax"] == "N") {
                                                                echo "Selected='selected'";
                                                            }
                                                        }
                                                        ?>>No</option>
                                </select>
                            </div>
                        </div> -->

                        <!-- <div class="row" style="background-color: yellow">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Basic</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <input type="text" oninput='this.value = this.value.replace(/[,]/g, "")' class="form-control form text-right basic" name="basic" value="<?php echo ($addflag != 1) ? $get["basic"] : "0"; ?>">
                            </div>

                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">HRA</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <input type="text" oninput='this.value = this.value.replace(/[,]/g, "")' class="form-control form text-right hra" name="hra" value="<?php echo ($addflag != 1) ? $get["hra"] : "0"; ?>">
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">DA/MA</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <input type="text" oninput='this.value = this.value.replace(/[,]/g, "")' class="form-control form text-right da ma" name="da" value="<?php echo ($addflag != 1) ? $get["da"] : "0"; ?>">
                            </div>
                        </div>
                        <div class="row" style="background-color: yellow">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">TA/CA</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <input type="text" oninput='this.value = this.value.replace(/[,]/g, "")' class="form-control form text-right ta ca" name="ta" value="<?php echo ($addflag != 1) ? $get["ta"] : "0"; ?>">
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">OA</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <input type="text" oninput='this.value = this.value.replace(/[,]/g, "")' class="form-control form text-right oa" name="oa" value="<?php echo ($addflag != 1) ? $get["oa"] : "0"; ?>">
                            </div>
                        </div> -->

                        <div class="row" style="background-color: yellow">
                            <!-- <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Salary</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <input type="text" oninput='this.value = this.value.replace(/[,]/g, "")' class="form-control form text-right total" name="total" value="<?php echo ($addflag != 1) ? $get["total"] : "0"; ?>">
                            </div> -->
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Salary</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <input type="text" oninput='this.value = this.value.replace(/[,]/g, "")' class="form-control form text-right basic" name="basic" value="<?php echo ($addflag != 1) ? $get["basic"] : "0"; ?>">
                            </div>
                        </div>

                        <div class="row">
                            <!-- <label class="control-label col-lg-3 text-right pad" style="color:red">Auto In Active</label>
                            <div class="col-lg-2 pad">
                                <input type="checkbox" name="autoinactive" value="1" class="form form-control" style="width: 30px" <?
                                                                                                                                    if ($get['autoinactive'] == 1) {
                                                                                                                                        echo "checked";
                                                                                                                                    } else {
                                                                                                                                        echo "unchecked";
                                                                                                                                    }
                                                                                                                                    ?>>
                            </div> -->
                        </div>

                        <div class="row">
                            <label class="control-label col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">Start Time</label>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="time" name="starttime" value="<?php echo ($addflag != 1) ? $get['starttime'] : ""; ?>" class="form form-control starttime">
                            </div>
                            <label class="control-label col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">End Time</label>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="time" name="endtime" value="<?php echo ($addflag != 1) ? $get['endtime'] : ""; ?>" class="form form-control endtime">
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Karigar Image</label>
                            </div>
                            <div class="col-lg-1 col-md-2 col-sm-2 col-xs-2 pad">
                                <input type="file" name="file3" id="file3" class="form btn btn-primary" accept="image/*">
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="float:right">
                                <img id="preview" width="300px" height="150px" src="<?php echo $get2['imgpath'] . "?a=" . mt_rand(); ?>" alt="your image" />
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Aadhar Front</label>
                            </div>
                            <div class="col-lg-1 col-md-2 col-sm-2 col-xs-2 pad">
                                <input type="file" name="filea" id="filea" class="form btn btn-primary" accept="image/*">
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="float:right">
                                <img id="preview" width="300px" height="150px" src="<?php echo $get2['aadharfront'] . "?a=" . mt_rand(); ?>" alt="your image" />
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Aadhar Back</label>
                            </div>
                            <div class="col-lg-1 col-md-2 col-sm-2 col-xs-2 pad">
                                <input type="file" name="fileb" id="fileb" class="form btn btn-primary" accept="image/*">
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="float:right">
                                <img id="preview" width="300px" height="150px" src="<?php echo $get2['aadharback'] . "?a=" . mt_rand(); ?>" alt="your image" />
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Pan Card</label>
                            </div>
                            <div class="col-lg-1 col-md-2 col-sm-2 col-xs-2 pad">
                                <input type="file" name="filep" id="filep" class="form btn btn-primary" accept="image/*">
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="float:right">
                                <img id="preview" width="300px" height="150px" src="<?php echo $get2['panimg'] . "?a=" . mt_rand(); ?>" alt="your image" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        </div>

        <div class="panel-footer col-lg-12">

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


        <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">
                        <button class="close" data-dismiss="modal"><span>&times;</span></button>
                        <h4 class="modal-title" id="myLargeModalLabel">Search <? echo $formname; ?></h4>
                    </div>
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-lg-2">
                                <select class="form-control sfield">
                                    <option value="5">Code</option>
                                    <option value="1">Name</option>
                                    <option value="2">Department</option>
                                    <option value="3">City</option>
                                    <option value="4">Mobile</option>
                                </select>
                            </div>
                            <div class="col-lg-2">
                                <select class="form-control soperator">
                                    <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">
                                    <option value="5">Code</option>
                                    <option value="1">Name</option>
                                    <option value="2">Department</option>
                                    <option value="3">City</option>
                                    <option value="4">Mobile</option>
                                </select>
                            </div>
                            <div class="col-lg-2">
                                <select class="form-control orderAs">
                                    <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">
                            <!--<img src="images/search.gif" alt="loading">-->
                        </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%">
                                <thead>
                                    <tr class="mySearchTr">
                                        <th style="color: white;">Code</th>
                                        <th style="color: white;">Name</th>
                                        <th style="color: white;">Department</th>
                                        <th style="color: white;">City</th>
                                        <th style="color: white;">Mobile</th>
                                        <th style="color: white;">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"); ?>

    </form>
</body>

</html>