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

$formname = 'User Creation';
$maindb = 'passmain';
$trandb = 'usercomp';
$printfile = "";
$file = 'user.php';
$trandbexist = 0;
$grid = '';
$keyfld = "code";
$keyfld2 = "username";
$zroot = $_SESSION["zdir"];

//browse($_SESSION["redirect"]);
//browse($zroot);
$keycond1 = "and usertype != 99";
$admin = $_SESSION["admin_" . $dbname];
$username = $_SESSION["username_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];

include("includes/vouchno_generate.php");
include("includes/prev&next.php");

if (isset($_POST["submit"])) {
    $a = 1;
    $user = $_POST["user"];
    $password = $_POST["password"];
    $usertype = $_POST["usertype"];
    $series = $_POST["series"];
    $count = $_POST["items"];
    ################## MASTERS ##################

    $customer = $_POST["customer"];
    $supplier = $_POST["supplier"];
    $godown = $_POST["godown"];
    $itemgrp = $_POST["itemgrp"];
    $item = $_POST["item"];
    $changeofrates = $_POST["changeofrates"];

    $transport = $_POST["transport"];
    $openbal = $_POST["openbal"];
    $chcustdtl = $_POST["chcustdtl"];
    $bank = $_POST["bank"];
    $cash = $_POST["cash"];
    $expense = $_POST["expense"];
    $group = $_POST["group"];
    $otherac = $_POST["otherac"];
    $paytype = $_POST["paytype"];
    $narration = $_POST["narration"];
    $drawbank = $_POST["drawbank"];

    ################## TRANSACTIONS ##################

    $purchase = $_POST["purchase"];
    $sale = $_POST["sale"];
    $architecture = $_POST["architecture"];
    $staff = $_POST["staff"];
    $saleret = $_POST["saleret"];
    $purret = $_POST["purret"];
    $ticredoth = $_POST["ticredoth"];
    $tideboth = $_POST["tideboth"];
    $crednote = $_POST["crednote"];
    $inward = $_POST["inward"];
    $outward = $_POST["outward"];
    $tidamage = $_POST["tidamage"];
    //    $transfer = $_POST["transfer"];
    $transfer = $_POST["transfer"];
    $bankrecp = $_POST["bankrecp"];
    $bankpay = $_POST["bankpay"];
    $cashrecp = $_POST["cashrecp"];
    $cashpay = $_POST["cashpay"];
    $journal = $_POST["journal"];
    $contra = $_POST["contra"];

    ################## REPORTS ##################


    $stock = $_POST["stock"];
    $stockall = $_POST["stockall"];
    $inwout = $_POST["inwout"];
    $receivablerep = $_POST["receivablerep"];
    $inouthist = $_POST["inouthist"];
    $vat = $_POST["vat"];
    $ledger = $_POST["ledger"];
    $itemwise = $_POST["itemwise"];
    $ospay = $_POST["ospay"];
    $itemwisepl = $_POST["itemwisepl"];
    $itemwise_sl = $_POST["itemwise_sl"];
    $bankrecon = $_POST["bankrecon"];
    $itemwisegrpsl = $_POST["itemwisegrpsl"];
    $tipartysl = $_POST["tipartysl"];
    $leadparty = $_POST["leadparty"];
    $dailyrep = $_POST["dailyrep"];
    $dailycash = $_POST["dailycash"];
    $bankbook = $_POST["bankbook"];
    $jvbook = $_POST["jvbook"];
    $contreg = $_POST["contreg"];
    $amtrep = $_POST["amtrep"];
    $expenserep = $_POST["expenserep"];
    $pendpurchase = $_POST["pendpurchase"];
    $chqrep = $_POST["chqrep"];
    $cashbook = $_POST["cashbook"];
    $exprep = $_POST["exprep"];
    $dailyreport = $_POST["dailyreport"];
    $itemgrpwisesale = $_POST["itemgrpwisesale"];
    $itemwisesale = $_POST["itemwisesale"];
    $bankrecorep = $_POST["bankrecorep"];


    ################## REGISTERS ##################1

    $purreg = $_POST["purreg"];
    $salereg = $_POST["salereg"];
    $inwreg = $_POST["inwreg"];
    $outreg = $_POST["outreg"];
    $debreg = $_POST["debreg"];
    $debregoth = $_POST["debregoth"];
    $credreg = $_POST["credreg"];
    $damreg = $_POST["damreg"];
    $excreg = $_POST["excreg"];
    $tranreg = $_POST["tranreg"];
    $payablerep = $_POST["payablerep"];
    $bankrecon = $_POST["bankrecon"];
    $ticredothregoth = $_POST["ticredothregoth"];


    ################## TOOLS ##################

    $tlcompany = $_POST["tlcompany"];
    $tlbackup = $_POST["tlbackup"];
    $tlprofile = $_POST["tlprofile"];

    ################## DASHBOARD ##################

    $pendlv = $_POST["pendlv"];
    $pendcp = $_POST["pendcp"];

    ################## FINALIZATION ##################
    $closestk = $_POST["closestk"];
    $trbal = $_POST["trbal"];
    $profit = $_POST["profit"];
    $profloss = $_POST["profloss"];
    $profshar = $_POST["profshar"];
    $balsheet = $_POST["balsheet"];

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

    if ($a == 1) {
        if ($addflag == 1) {
            $gen1 = mysqli_query($conn, "SELECT MAX($keyfld) AS maxcode FROM `$maindb` LIMIT 0,1 ") or die(mysqli_error($conn));

            if (mysqli_num_rows($gen1) > 0) {
                $vvouch = mysqli_fetch_assoc($gen1);
                $qvouch = $vvouch["maxcode"] + 1;
            } else {
                $qvouch = '1';
            }
            $mvouch = $qvouch;
        }

        #################################TRAN PART #################################

        mysqli_query($conn, "DELETE FROM `$trandb` WHERE `username`='$qvouch'") or die(mysqli_error($conn));

        for ($i = 0; $i < $count; $i++) {
            //            $cono = $_POST["cono_$i"];
            $finyear = $_POST["finyear_$i"];
            $yearname = $_POST["yearname_$i"];
            $startdate = $_POST["startdate_$i"];
            $lastdate = $_POST["lastdate_$i"];

            if (!empty($finyear)) {
                mysqli_query($conn, "INSERT INTO `$trandb`(`username`,`cono`, `finyear`, `yearname`, `startdate`, `lastdate`) 
                    VALUES ('$qvouch', '1', '$finyear', '$yearname', '$startdate', '$lastdate')") or die(mysqli_error($conn));
            }
        }
        ############################## MAIN  ######################################################



        $usecode = mysqli_query($conn, "SELECT accode, name FROM $zdb.`accmast` WHERE name='$user'") or die(mysqli_error($conn));
        if (mysqli_num_rows($usecode) > 0) {
            $getuser = mysqli_fetch_object($usecode);
            $saleexec = $getuser->accode;
        } else {
            $genex = mysqli_query($conn, "SELECT MAX(accode) AS maxcode FROM $zdb.`accmast`  LIMIT 0,1 ") or die(mysqli_error($conn));

            if (mysqli_num_rows($genex) > 0) {
                $vvouchex = mysqli_fetch_assoc($genex);
                $saleexec = $vvouchex["maxcode"] + 1;
            } else {
                $saleexec = '51';
            }


            mysqli_query($conn, "INSERT INTO  $zdb.`accmast`(accode, `grpcode`, `name`,usercode)
                                        VALUES($saleexec, '040', '$user', '$mvouch')") or die(mysqli_error($conn));
        }
        $redirect = $_SESSION["redirect"];
        $zheadroot = $_SESSION['zheadroot'];
        if ($addflag == 1) {


            mysqli_query($conn, "INSERT INTO `$maindb`(code, `user`, `password`, `usertype`, `customer`, `supplier`,`godown`, `itemgrp`, `item`,`changeofrates`,`openbal`, `chcustdtl`,
                                                        `bank`, `cash`, `expense`, `group`, `otherac`,`transport`,`narration`,
                                                        `purchase`, `sale`,`saleret`,`purret`,`ticredoth`,`tideboth`,   `inward`, `outward`, `tidamage`, 
                                                        `bankrecp`, `bankpay`, `cashrecp`, `cashpay`, `journal`,`contra`,
                                                        `stock`, `stockall`,`inwout`, `receivablerep`, `itemwise`, `ospay`, `itemwise_sl`, `bankrecon`, `ledger`, `dailyreport`,
                                                        `leadparty`, `bankbook`,`jvbook`, `contreg`,`amtrep`,`expenserep`,`chqrep`,`cashbook`,
                                                         `transfer`,`itemwisesale`, `bankrecorep`,`itemgrpwisesale`,`purreg`, `salereg`,
                                                          `inwreg`, `outreg`, `debreg`, `debregoth`, `credreg`, `damreg`, `tranreg`,`ticredothregoth`,`payablerep`,
                                                        `trbal`, `architecture`,`staff`, `profshar`,`profit`, `balsheet`,`drawbank`, `pendpurchase`, `saleexec`, `pendlv`, `pendcp`)
                                        VALUES($qvouch, '$user', '$password', '$usertype', '$customer', '$supplier','$godown', '$itemgrp', '$item','$changeofrates','$openbal', '$chcustdtl',
                                                         '$bank', '$cash', '$expense', '$group', '$otherac','$transport','$narration',
                                                         '$purchase', '$sale','$saleret','$purret','$ticredoth','$tideboth',  '$inward','$outward', '$tidamage', 
                                                         '$bankrecp', '$bankpay', '$cashrecp', '$cashpay', '$journal','$contra',
                                                         '$stock', '$stockall','$inwout', '$receivablerep', '$itemwise', '$ospay' ,'$itemwise_sl', '$bankrecon','$ledger', '$dailyreport',
                                                         '$leadparty',
                                                         '$bankbook','$jvbook','$contreg','$amtrep','$expenserep', '$chqrep','$cashbook',  '$transfer','$itemwisesale', '$bankrecorep','$itemgrpwisesale',
                                                         '$purreg', '$salereg', '$inwreg', '$outreg', '$debreg', '$debregoth', '$credreg', '$damreg','$tranreg' ,'$ticredothregoth','$payablerep',
                                                         '$trbal', '$architecture', '$staff','$profshar','$profit', '$balsheet' ,'$drawbank', '$pendpurchase', '$saleexec', '$pendlv','$pendcp')") or die(mysqli_error($conn));


            mysqli_query($conn, "INSERT INTO  $zheadroot.usermain(`code`, `user`, `password`, `usertype`,`dbroot`, `redirect`)
                                        VALUES('$saleexec', '$user', '$password', '$usertype', '$zroot', '$redirect')") or die(mysqli_error($conn));

            insmess();
            $mvouch = $qvouch;
            header("refresh: 1;$file?$keyfld=$mvouch&mode=edit");
        } else {
            $mvouch = $qvouch;

            //            $usecode = mysqli_query($conn, "SELECT code FROM `passmain` WHERE user = '$username'") or die(mysqli_error($conn));
            //            $getuser = mysqli_fetch_object($usecode);
            //            $code = $getuser->code;



            mysqli_query($conn, "UPDATE `$maindb` SET `user` = '$user', `password` = '$password', `usertype` = '$usertype', `customer` = '$customer',saleexec='$saleexec',
                                                 `supplier` = '$supplier',`godown`='$godown', `itemgrp` = '$itemgrp', `item`='$item',`changeofrates`='$changeofrates',`openbal`='$openbal', `chcustdtl`='$chcustdtl',
                                                 `bank` = '$bank', `cash` = '$cash', `expense` = '$expense', `group`='$group', `otherac`='$otherac',`transport`='$transport',`narration`='$narration',
                                                 `purchase` = '$purchase', `sale` = '$sale',`saleret`='$saleret',`purret`='$purret',`ticredoth`='$ticredoth',`tideboth`='$tideboth',  `inward`='$inward', `outward`='$outward', `tidamage`='$tidamage',
                                                 `bankrecp` = '$bankrecp', `bankpay` = '$bankpay', `cashrecp` = '$cashrecp',  `cashpay`='$cashpay', `journal`='$journal', `contra`='$contra',
                                                 `stock` = '$stock',`stockall`= '$stockall' ,`inwout` = '$inwout', `receivablerep`='$receivablerep', `itemwise`='$itemwise', `ospay`='$ospay', `itemwise_sl`='$itemwise_sl',`ledger`='$ledger', 
                                                 `leadparty` = '$leadparty',   `bankbook`='$bankbook',`jvbook`='$jvbook',`contreg`='$contreg',`amtrep`='$amtrep' ,`expenserep`='$expenserep',`chqrep`='$chqrep',`cashbook`='$cashbook', `transfer`='$transfer',
                                                 `purreg` = '$purreg',`salereg`='$salereg',`inwreg` = '$inwreg',  `outreg`='$outreg', `debreg`='$debreg', `debregoth`='$debregoth',  `credreg`='$credreg', `damreg`='$damreg',`tranreg`='$tranreg' ,`ticredothregoth`='$ticredothregoth',
                                                 `payablerep`='$payablerep', `bankrecorep`='$bankrecorep', `bankrecon`='$bankrecon',`dailyreport`='$dailyreport',`itemgrpwisesale`='$itemgrpwisesale',    
                                                 `trbal`='$trbal', `architecture`='$architecture', `staff` ='$staff',`profshar`='$profshar', `profit`='$profit',`balsheet`='$balsheet',
                                                 `drawbank`='$drawbank', `pendpurchase`= '$pendpurchase',`itemwisesale`= '$itemwisesale',`pendcp`= '$pendcp',`pendlv`= '$pendlv'  WHERE code = '$mvouch'") or die(mysqli_error($conn));

            mysqli_query($conn, "UPDATE $zheadroot.`usermain` SET `user` = '$user', `password` = '$password', `usertype` = '$usertype' WHERE code = '$saleexec'") or die(mysqli_error($conn));
            updmess();
            header("refresh: 1;$file?$keyfld=$mvouch&mode=edit");
        }
    }
}

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);
    $nm = $get['user'];
    $rd = "readonly";
}

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

/* DELETE */
if (isset($_GET["delete"])) {

    $chkresult = mysqli_query($conn, "SELECT username FROM $zdb.`salemain` WHERE username='$nm'") or die(mysqli_error($conn));
    $fetget = mysqli_num_rows($chkresult);
    if ($fetget > 0) {
        browse('User Exist in Transaction');
    } else {
        delete("$zroot", "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
        delete("$zroot", "$trandb", "$keyfld2", $_GET[$keyfld], "$file?mode=last");
    }
}
?>
<?php include("includes/linkshead.php"); ?>
<style>
    input[type=checkbox] {
        width: 20px;
        height: 20px;
    }
</style>
<script src="MyScript/user.js" type="text/javascript"></script>

<body>
    <!-- Default box -->
    <form action='' method='POST'>
        <!-- Default box -->
        <div class="">
            <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">
                            <label class="col-sm-3 control-label marg">User Name</label>
                            <div class="col-sm-6">
                                <input type="text" class="form-control form" name="user" placeholder="User Name" autocomplete="off" value='<? echo ($addflag != 1) ? $get['user'] : ''; ?>' required="" autofocus <?= $rd ?>>
                            </div>
                        </div>
                        <div class="row">
                            <label class="col-sm-3 control-label marg">Password</label>
                            <div class="col-sm-6">
                                <input type="password" class="form-control form" name="password" id="password" autocomplete="off" placeholder="Password" value='<? echo ($addflag != 1) ? $get['password'] : ''; ?>' required="">
                            </div>
                        </div>
                        <div class="row">
                            <label class="col-sm-3 control-label marg">Confirm Password</label>
                            <div class="col-sm-6">
                                <input type="password" name="confpass" id="confpass" class="form-control form" placeholder="Confirm Password" required="" value='<? echo ($addflag != 1) ? $get['password'] : ''; ?>'>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-6">
                                <p id="alert"></p>
                            </div>
                        </div>
                        <div class="row">
                            <label class="col-sm-3 control-label marg">User Type</label>
                            <div class="col-sm-6">

                                <select class='form-control select2 form' name="usertype" id="usertype" required>
                                    <?php
                                    if ($addflag != 1) {
                                        $usertype = "";
                                        if ($get['usertype'] == 1) {
                                            $ucode = "1";
                                            $usertype = "Supervisor";
                                        }
                                        if ($get['usertype'] == 2) {
                                            $ucode = "2";
                                            $usertype = "Admin";
                                        }
                                        if ($get['usertype'] == 3) {
                                            $ucode = "3";
                                            $usertype = "Sales Executive";
                                        }
                                        echo "<option value='$ucode'>$usertype</option>";
                                    }
                                    ?>
                                    <option value="1">Supervisor</option>
                                    <option value="2">Admin</option>
                                    <option value="3">Sales Executive</option>
                                </select>
                            </div>
                        </div>
                        <div class="nav-tabs-custom">
                            <ul class="nav nav-tabs">
                                <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true">Master</a></li>
                                <li class=""><a href="#tab_2" data-toggle="tab" aria-expanded="false">Transaction</a></li>
                                <li class=""><a href="#tab_3" data-toggle="tab" aria-expanded="false">Report</a></li>
                                <li class=""><a href="#tab_4" data-toggle="tab" aria-expanded="false">Register</a></li>
                                <li class=""><a href="#tab_5" data-toggle="tab" aria-expanded="false">Dashboard</a></li>
                                <!--<li class=""><a href="#tab_5" data-toggle="tab" aria-expanded="false">Finalization</a></li>-->
                            </ul>
                            <div class="tab-content">
                                <div class="tab-pane active" id="tab_1">
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg selectall">Select All/UnSelect All</label>
                                        <div class="col-sm-4" style="margin-top:6px">
                                            <input type="checkbox" class="form " id="Smasters" value="1">
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Customer</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  masters" id="customer" name="customer" value="1" <?
                                                                                                                                    if ($get['customer'] == 1) {
                                                                                                                                        echo "checked";
                                                                                                                                    }
                                                                                                                                    ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Cash</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  masters" id="cash" name="cash" value="1" <?
                                                                                                                            if ($get['cash'] == 1) {
                                                                                                                                echo "checked";
                                                                                                                            }
                                                                                                                            ?>>
                                        </div>

                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Supplier</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  masters" id="supplier" name="supplier" value="1" <?
                                                                                                                                    if ($get['supplier'] == 1) {
                                                                                                                                        echo "checked";
                                                                                                                                    }
                                                                                                                                    ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Opening Balance</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  masters" id="openbal" name="openbal" value="1" <?
                                                                                                                                if ($get['openbal'] == 1) {
                                                                                                                                    echo "checked";
                                                                                                                                }
                                                                                                                                ?>>
                                        </div>

                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Architect</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  masters" id="architecture" name="architecture" value="1" <?
                                                                                                                                            if ($get["architecture"] == 1) {
                                                                                                                                                echo "checked";
                                                                                                                                            }
                                                                                                                                            ?>>
                                        </div>

                                        <label class="col-sm-4 control-label marg">Group</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  masters" id="group" name="group" value="1" <?
                                                                                                                            if ($get["group"] == 1) {
                                                                                                                                echo "checked";
                                                                                                                            }
                                                                                                                            ?>>
                                        </div>


                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Product</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  masters" id="item" name="item" value="1" <?
                                                                                                                            if ($get["item"] == 1) {
                                                                                                                                echo "checked";
                                                                                                                            }
                                                                                                                            ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Other A/c.</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  masters" id="otherac" name="otherac" value="1" <?
                                                                                                                                if ($get["otherac"] == 1) {
                                                                                                                                    echo "checked";
                                                                                                                                }
                                                                                                                                ?>>
                                        </div>
                                    </div>
                                    <div class="row">

                                        <label class="col-sm-4 control-label marg">Sales Executive</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  masters" id="staff" name="staff" value="1" <?
                                                                                                                            if ($get["staff"] == 1) {
                                                                                                                                echo "checked";
                                                                                                                            }
                                                                                                                            ?>>
                                        </div>
                                    </div>


                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Expense</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  masters" id="expense" name="expense" value="1" <?
                                                                                                                                if ($get['expense'] == 1) {
                                                                                                                                    echo "checked";
                                                                                                                                }
                                                                                                                                ?>>
                                        </div>
                                    </div>

                                    <!-- ###################### TRANSACTIONS ############################# -->

                                </div><!-- /.tab-pane -->
                                <div class="tab-pane" id="tab_2">
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg selectall">Select All/UnSelect All</label>
                                        <div class="col-sm-4" style="margin-top:6px">
                                            <input type="checkbox" class="form transactions" id="Stransactions" value="1">
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Purchase</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  transactions" id="purchase" name="purchase" value="1" <?
                                                                                                                                        if ($get["purchase"] == 1) {
                                                                                                                                            echo "checked";
                                                                                                                                        }
                                                                                                                                        ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Cash Receipt</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  transactions" id="cashrecp" name="cashrecp" value="1" <?
                                                                                                                                        if ($get['cashrecp'] == 1) {
                                                                                                                                            echo "checked";
                                                                                                                                        }
                                                                                                                                        ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Sale</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  transactions" id="sale" name="sale" value="1" <?
                                                                                                                                if ($get['sale'] == 1) {
                                                                                                                                    echo "checked";
                                                                                                                                }
                                                                                                                                ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Cash Payment</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  transactions" id="cashpay" name="cashpay" value="1" <?
                                                                                                                                    if ($get['cashpay'] == 1) {
                                                                                                                                        echo "checked";
                                                                                                                                    }
                                                                                                                                    ?>>
                                        </div>


                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Purchase Return - GR</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  transactions" id="purret" name="purret" value="1" <?
                                                                                                                                    if ($get["purret"] == 1) {
                                                                                                                                        echo "checked";
                                                                                                                                    }
                                                                                                                                    ?>>
                                        </div>
                                    </div>
                                    <div class="row">

                                        <label class="col-sm-4 control-label marg">Purchase Return - Others</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  transactions" id="tideboth" name="tideboth" value="1" <?
                                                                                                                                        if ($get['tideboth'] == 1) {
                                                                                                                                            echo "checked";
                                                                                                                                        }
                                                                                                                                        ?>>
                                        </div>

                                    </div>

                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Sale Return - GR</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  transactions" id="saleret" name="saleret" value="1" <?
                                                                                                                                    if ($get['saleret'] == 1) {
                                                                                                                                        echo "checked";
                                                                                                                                    }
                                                                                                                                    ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Sale Return - Others</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  transactions" id="ticredoth" name="ticredoth" value="1" <?
                                                                                                                                        if ($get['ticredoth'] == 1) {
                                                                                                                                            echo "checked";
                                                                                                                                        }
                                                                                                                                        ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Inward</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  transactions" id="inward" name="inward" value="1" <?
                                                                                                                                    if ($get['inward'] == 1) {
                                                                                                                                        echo "checked";
                                                                                                                                    }
                                                                                                                                    ?>>
                                        </div>

                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Outward</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  transactions" id="outward" name="outward" value="1" <?
                                                                                                                                    if ($get['outward'] == 1) {
                                                                                                                                        echo "checked";
                                                                                                                                    }
                                                                                                                                    ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Damage</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  transactions" id="tidamage" name="tidamage" value="1" <?
                                                                                                                                        if ($get['tidamage'] == 1) {
                                                                                                                                            echo "checked";
                                                                                                                                        }
                                                                                                                                        ?>>
                                        </div>
                                    </div>

                                    <!-- ###################### REPORTS ############################# -->


                                </div><!-- /.tab-pane -->

                                <div class="tab-pane" id="tab_3">
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg selectall">Select All/UnSelect All</label>
                                        <div class="col-sm-4" style="margin-top:6px">
                                            <input type="checkbox" class="form " id="Sreports" value="1">
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Stock</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="stock" name="stock" value="1" <?
                                                                                                                            if ($get['stock'] == 1) {
                                                                                                                                echo "checked";
                                                                                                                            }
                                                                                                                            ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Ledger</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="ledger" name="ledger" value="1" <?
                                                                                                                                if ($get['ledger'] == 1) {
                                                                                                                                    echo "checked";
                                                                                                                                }
                                                                                                                                ?>>
                                        </div>

                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Item History</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="inwout" name="inwout" value="1" <?
                                                                                                                                if ($get['inwout'] == 1) {
                                                                                                                                    echo "checked";
                                                                                                                                }
                                                                                                                                ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Outstanding Receivable</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="receivablerep" name="receivablerep" value="1" <?
                                                                                                                                            if ($get['receivablerep'] == 1) {
                                                                                                                                                echo "checked";
                                                                                                                                            }
                                                                                                                                            ?>>
                                        </div>

                                    </div>
                                    <div class="row">
                                        <label class="  col-sm-4 control-label marg">Itemwise P/L</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="itemwise" name="itemwise" value="1" <?
                                                                                                                                    if ($get['itemwise'] == 1) {
                                                                                                                                        echo "checked";
                                                                                                                                    }
                                                                                                                                    ?>>
                                        </div>
                                        <label class="  col-sm-4 control-label marg">Outstanding Payable</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="ospay" name="ospay" value="1" <?
                                                                                                                            if ($get['ospay'] == 1) {
                                                                                                                                echo "checked";
                                                                                                                            }
                                                                                                                            ?>>
                                        </div>

                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Itemwise P/L - Sales Eecutive</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="itemwise_sl" name="itemwise_sl" value="1" <?
                                                                                                                                        if ($get['itemwise_sl'] == 1) {
                                                                                                                                            echo "checked";
                                                                                                                                        }
                                                                                                                                        ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Cash Book</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="cashbook" name="cashbook" value="1" <?
                                                                                                                                    if ($get['cashbook'] == 1) {
                                                                                                                                        echo "checked";
                                                                                                                                    }
                                                                                                                                    ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Itemwise Sale</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="itemwisesale" name="itemwisesale" value="1" <?
                                                                                                                                            if ($get['itemwisesale'] == 1) {
                                                                                                                                                echo "checked";
                                                                                                                                            }
                                                                                                                                            ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Expense Report</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="expenserep" name="expenserep" value="1" <?
                                                                                                                                        if ($get['expenserep'] == 1) {
                                                                                                                                            echo "checked";
                                                                                                                                        }
                                                                                                                                        ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Daily Report</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="dailyreport" name="dailyreport" value="1" <?
                                                                                                                                        if ($get['dailyreport'] == 1) {
                                                                                                                                            echo "checked";
                                                                                                                                        }
                                                                                                                                        ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Pending Purchase</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="pendpurchase" name="pendpurchase" value="1" <?
                                                                                                                                            if ($get['pendpurchase'] == 1) {
                                                                                                                                                echo "checked";
                                                                                                                                            }
                                                                                                                                            ?>>
                                        </div>
                                    </div>

                                    <!-- ###################### REGISTERS ############################# -->


                                </div><!-- /.tab-pane-->
                                <div class="tab-pane" id="tab_4">
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg selectall">Select All/UnSelect All</label>
                                        <div class="col-sm-4" style="margin-top:6px">
                                            <input type="checkbox" class="form " id="Sregisters" value="1">
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Purchase</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  registers" id="purreg" name="purreg" value="1" <?
                                                                                                                                if ($get['purreg'] == 1) {
                                                                                                                                    echo "checked";
                                                                                                                                }
                                                                                                                                ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Inward</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  registers" id="inwreg" name="inwreg" value="1" <?
                                                                                                                                if ($get['inwreg'] == 1) {
                                                                                                                                    echo "checked";
                                                                                                                                }
                                                                                                                                ?>>
                                        </div>

                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Sale</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  registers" id="salereg" name="salereg" value="1" <?
                                                                                                                                    if ($get['salereg'] == 1) {
                                                                                                                                        echo "checked";
                                                                                                                                    }
                                                                                                                                    ?>>
                                        </div>

                                        <label class="col-sm-4 control-label marg">Outward</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  registers" id="outreg" name="outreg" value="1" <?
                                                                                                                                if ($get['outreg'] == 1) {
                                                                                                                                    echo "checked";
                                                                                                                                }
                                                                                                                                ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Purchase Return </label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  registers" id="debreg" name="debreg" value="1" <?
                                                                                                                                if ($get["debreg"] == 1) {
                                                                                                                                    echo "checked";
                                                                                                                                }
                                                                                                                                ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Damaged</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  registers" id="damreg" name="damreg" value="1" <?
                                                                                                                                if ($get["damreg"] == 1) {
                                                                                                                                    echo "checked";
                                                                                                                                }
                                                                                                                                ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Purchase Return - Others</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  registers" id="debregoth" name="debregoth" value="1" <?
                                                                                                                                        if ($get["debregoth"] == 1) {
                                                                                                                                            echo "checked";
                                                                                                                                        }
                                                                                                                                        ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Sale Return</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  registers" id="credreg" name="credreg" value="1" <?
                                                                                                                                    if ($get['credreg'] == 1) {
                                                                                                                                        echo "checked";
                                                                                                                                    }
                                                                                                                                    ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Sale Return - Others</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  registers" id="ticredothregoth" name="ticredothregoth" value="1" <?
                                                                                                                                                    if ($get['ticredothregoth'] == 1) {
                                                                                                                                                        echo "checked";
                                                                                                                                                    }
                                                                                                                                                    ?>>
                                        </div>
                                    </div>
                                </div>
                                <div class="tab-pane" id="tab_5">
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg selectall">Select All/UnSelect All</label>
                                        <div class="col-sm-4" style="margin-top:6px">
                                            <input type="checkbox" class="form " id="Sdashboard" value="1">
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Pending CP</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form dashboard" id="pendcp" name="pendcp" value="1" <?
                                                                                                                                if ($get['pendcp'] == 1) {
                                                                                                                                    echo "checked";
                                                                                                                                }
                                                                                                                                ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Pending Delivery</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form dashboard" id="pendlv" name="pendlv" value="1" <?
                                                                                                                                if ($get['pendlv'] == 1) {
                                                                                                                                    echo "checked";
                                                                                                                                }
                                                                                                                                ?>>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div><!-- /.tab-content -->
                    </div>
                </div>
                <div class="panel-footer">
                    <?php include("includes/buttons.php"); ?>
                </div>
            </div>
        </div>
        <div class="col-lg-6 col-md-12 col-sm-12 col-xs-12 pad">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">Year Details</h3>

                </div>
                <div class="panel-body">
                    <div class="table-responsive">
                        <table class="table table-striped table-condensed table-bordered" width="100%">
                            <thead class="mySearchTr">
                                <tr>
                                    <th width="3%"></th>
                                    <th width="10%">Year</th>
                                    <th width="10%">Name</th>
                                    <th width="10%">From</th>
                                    <th width="10%">To</th>
                                </tr>
                            </thead>
                            <tbody class="tbody">
                                <?php
                                if ($addflag != 1) {
                                    $ctr = 0;
                                    $gettran = mysqli_query($conn, "SELECT `cono`,`finyear`,date_format(`startdate`, '%d-%m-%Y') as startdate,date_format(`lastdate`, '%d-%m-%Y') as lastdate,`yearname` FROM `usercomp` WHERE `username`='$get[code]' ORDER BY `cono`") or die(mysqli_error($conn));
                                    while ($tran = mysqli_fetch_array($gettran)) {

                                        $fetyear = mysqli_query($conn, "SELECT `finyear`,`yearname` FROM `compyear` WHERE `finyear`='$tran[finyear]'") or die(mysqli_error($conn));
                                        $fyear = mysqli_fetch_array($fetyear);

                                        echo "<tr>";
                                        echo "<td><i class='fa fa-close remove' style='display:none;'></i></td>";
                                        echo "<td>";
                                        echo "<select class='form-control form finyear select2' name='finyear_$ctr' style='width:100%'>";
                                        echo "<option value='$fyear[finyear]'>$fyear[yearname]</option>";
                                        $gyear = mysqli_query($conn, "SELECT `finyear`,`yearname` FROM `compyear`") or die(mysqli_error($conn));
                                        while ($year = mysqli_fetch_array($gyear)) {
                                            echo "<option value='$year[finyear]'>$year[yearname]</option>";
                                        }
                                        echo "</select>";
                                        echo "</td>";
                                        echo "<td><input type='text' class='form-control form yearname' name='yearname_$ctr' value='$tran[yearname]' readonly></td>";
                                        echo "<td><input type='text' class='form-control form startdate' name='startdate_$ctr' value='$tran[startdate]' readonly></td>";
                                        echo "<td><input type='text' class='form-control form lastdate' name='lastdate_$ctr' value='$tran[lastdate]' readonly></td>";
                                        echo "</tr >";
                                        $ctr++;
                                    }
                                } else {
                                ?>
                                    <tr>
                                        <td><i class='fa fa-close remove'></i></td>
                                        <td>
                                            <select class="form-control form finyear select2" name="finyear_0" style='width:100%' required>
                                                <option value=""></option>
                                                <?php
                                                $gyear = mysqli_query($conn, "SELECT `finyear`,`yearname` FROM `compyear`") or die(mysqli_error($conn));
                                                while ($year = mysqli_fetch_array($gyear)) {
                                                    echo "<option value='$year[finyear]'>$year[yearname]</option>";
                                                }
                                                ?>
                                            </select>
                                        </td>
                                        <td><input type="text" class="form-control form yearname" name="yearname_0" value="" readonly></td>
                                        <td><input type="text" class="form-control form startdate" name="startdate_0" value="" readonly></td>
                                        <td><input type="text" class="form-control form lastdate" name="lastdate_0" value="" readonly></td>
                                    </tr>
                                <?
                                }
                                ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="col-lg-12 pad">
                        <button type="button" class="btn btn-primary btn-square form" 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>
    </form>
    <div class="modal fade bs-example-modal-lg" 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=" table-responsive">
                        <table id="example1" class="table table-striped">
                            <thead>
                                <tr class="mySearchTr">
                                    <th>Code</th>
                                    <th>Name</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                if ($addflag != 1) {
                                    $srchresult = mysqli_query($conn, "SELECT * FROM `$maindb` where usertype != '99'") or die(mysqli_error($conn));
                                    while ($row = mysqli_fetch_array($srchresult)) {
                                        echo "<tr>";
                                        echo "<td align='left'>$row[code]</td>";
                                        echo "<td align='left'>$row[user]</td>";
                                        echo "<td align='left'><a href=\"$file?mode=edit&$keyfld=$row[$keyfld]\"><i class='fa fa-pencil' style='font-size:1.3em;color:#00C0EF;cursor:pointer;'></i></a></td>";
                                        echo "</tr>";
                                    }
                                }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="modal-footer"></div>
            </div>
        </div>
    </div>
</body>

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