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

$formname = 'Hotel Entry';
$maindb = 'hotelslmain';
$trandb = 'hotelsltran';
$accdb = "actran";
// $printfile = "hotelsl_invprint.php";
$printfile = "hotelsl_invoice_print.php";
$file = 'hotelsl.php';
$trandbexist = 1;
$keyfld = "vouchno";

$source = "HTSL";
$tourcode = $_SESSION['tourcode'];

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
$compcd = $_SESSION["comp_" . $dbname];
$zroot = $_SESSION["zdir"];

mysqli_select_db($conn, $zdb);
include("includes/vouchno_generate.php");
include("includes/prev&next.php");

if (isset($_POST["submit"])) {
    $a = 1;
    $qvouch = $_POST["vouchno"];
    $vouchdt = $_POST["vouchdt"];
    $customer = trim($_POST["customer"]);
    $prname = trim($_POST["prname"]);
    $nationality = trim($_POST["nationality"]);
    $remark1 = $_POST["remark1"];
    $remark2 = $_POST["remark2"];
    $extchg = $_POST["extchg"];
    $totamt = $_POST["totamt"];
    $roe = $_POST["roe"];
    $type = $_POST["type"];
    $hotelamt = $_POST["hotelamt"];
    $hotelinramt = $_POST["hotelinramt"];

    $count = $_POST["items"];

    $mvouch = $qvouch;

    $salecode = 11;

    if ($a == 1) {
        // mysqli_query($conn, "LOCK TABLES `$maindb` WRITE, `$trandb` WRITE ");

        if ($addflag == 1) {
            $gen1 = mysqli_query($conn, "SELECT MAX(vouchno) AS maxcode FROM `$maindb` where vouchno != '' 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;
        }


        $chkagn = mysqli_query($conn, "SELECT accode FROM accmast WHERE name = '$customer'") or die(mysqli_error($conn));
        $mnoa = mysqli_num_rows($chkagn);
        if ($type == "A") {
            $agrp = '044';
            $init = 'BRK';
        } else {
            $agrp = '010';
            $init = 'SDR';
        }
        if ($mnoa > 0) {
            $feta = mysqli_fetch_array($chkagn);
            $agencode = $feta['accode'];
        } else {
            $gena = mysqli_query($conn, "SELECT MAX(accode) AS maxcode FROM `accmast` where accode != '' LIMIT 0,1 ") or die(mysqli_error($conn));
            if (mysqli_num_rows($gena) > 0) {
                $vvoucha = mysqli_fetch_assoc($gena);
                $qvoucha = $vvoucha["maxcode"] + 1;
            } else {
                $qvoucha = '51';
            }
            $agencode = $qvoucha;
            mysqli_query($conn, "INSERT INTO `accmast`(`accode`, `name`, `grpcode`, `init`) 
                    VALUES ('$agencode', '$customer', '$agrp', '$init')") or die(mysqli_error($conn));
        }

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

        mysqli_query($conn, "DELETE FROM `$trandb` WHERE `$keyfld`='$mvouch'") or die(mysqli_error($conn));
        mysqli_query($conn, "DELETE FROM `roomsacn` WHERE `$keyfld`='$mvouch' and source = '$source' ") or die(mysqli_error($conn));

        $srl = 0;
        $batch = date("Y-m-d") . $mvouch;
        $cnt = 0;
        for ($i = 0; $i <= $count; $i++) {

            $srno = $_POST["srno_$i"];
            $trcity = $_POST["city_$i"];
            $hotelnm = $_POST["hotelnm_$i"];
            $checkin = $_POST["checkin_$i"];
            $checkout = $_POST["checkout_$i"];
            $nonights = $_POST["nonights_$i"];
            $hotelpax = $_POST["hotelpax_$i"];
            $roomcatg = 4;
            if ($_POST["roomcatg_$i"]) {
                $roomcatg = $_POST["roomcatg_$i"];
            }
            $roomview = $_POST["roomview_$i"];
            $roomtype = $_POST["roomtype_$i"];
            $qty = $_POST["qty_$i"];
            $rate = $_POST["rate_$i"];
            $amount = $_POST["amount_$i"];
            $trmealtype = $_POST["mealtype_$i"];
            $cnfno = $_POST["cnfno_$i"];
            $prncomp = $_POST["prncomp_$i"];
            $remarks = mysqli_real_escape_string($conn, $_POST["remarks_$i"]);
            $bckdate = date('Y-m-d', strtotime($checkout . ' - 1 days'));

            $nigctr = $nonights;

            if (!empty($checkin)) {
                $srl++;
                mysqli_query($conn, "INSERT INTO `$trandb`(`vouchno`, `vouchdt`, `srno`, `checkin`, `checkout`, `nonights`, `roomcatg`, `roomtype`,  roomview, 
                                                            `qty`, `rate`, `amount`, `remarks`, `city`, `hotelnm`, `mealtype`, `cnfno`, prncomp, hotelpax) 
                                                    VALUES('$mvouch', '$vouchdt', '$srl', '$checkin', '$checkout', '$nonights', '$roomcatg', '$roomtype', '$roomview',
                                                           '$qty', '$rate', '$amount', '$remarks', '$trcity', '$hotelnm', '$trmealtype', '$cnfno','$prncomp', '$hotelpax' )") or die(mysqli_error($conn));
                $nopax = $nopax + 1;

                $bookdate = $checkin;
                $chk = '1';
                $chko = '';
                for ($r = 0; $r < $nigctr; $r++) {
                    $mhotcatg = mysqli_query($conn, "SELECT category FROM hotels where code='$hotelnm' ") or die(mysqli_error($conn));
                    $thotcatg = mysqli_fetch_array($mhotcatg);
                    $hotelcatg = $thotcatg['category'];

                    $mqty = $qty * -1;
                    if ($bookdate == $bckdate) {
                        $chko = '1';
                    }
                    mysqli_query($conn, "INSERT INTO `roomsacn`(`source`, `vouchno`, `bookdate`, `hotel`, `city`, roomview,
                                                                      `roomcatg`, `roomtype`, `qty`, `rate`, `hotelcatg`, `mealtype`,checkin, checkout)
                                                      VALUES('$source', '$mvouch', '$bookdate', '$hotelnm', '$trcity', '$roomview',
                                                                      '$roomcatg', '$roomtype', '$mqty', '$rate', '$hotelcatg', '$trmealtype','$chk','$chko' )") or die(mysqli_error($conn));
                    $chk = '';
                    $bookdate = date('Y-m-d', strtotime($bookdate . ' + 1 days'));

                    if ($bookdate > $checkout) {
                        break;
                    }
                }
            }
        }


        $rate = $_POST["rate"];
        $amount = $nopax * $rate;

        $purcode = 12;

        #################################TRAN PART END #################################

        mysqli_query($conn, "DELETE FROM `$accdb` WHERE `vouchno`='$mvouch' and source = '$source'") or die(mysqli_error($conn));
        if ($hotelamt > 0) {
            $minus_amt = ($hotelamt * -1);

            // sale part
            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount, regnno, tour, ord)
                    VALUES ('$vouchdt', '$mvouch', '$source', '001', '31','005', '$hotelamt', '$mvouch', '$tourcode', '19')") or die(mysqli_error($conn));

            // party part
            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount, regnno, tour, ord)
                     VALUES ('$vouchdt', '$mvouch', '$source', '002', '$agencode','010', '$minus_amt', '$mvouch', '$tourcode', '19')") or die(mysqli_error($conn));
        }

        ############################## MAIN ######################################################
        if ($addflag == 1) {

            $uuid = $_SESSION["uuid"];

            mysqli_query($conn, "INSERT INTO `$maindb`(`vouchno`, `vouchdt`, `customer`,  `roe`, `remark1`, `remark2`,prname,`nationality`,`extchg`, 
                                                       hotelamt, hotelinramt, uuid, type,`totamt`)
                                               VALUES ($qvouch, '$vouchdt',  '$agencode', '$roe', '$remark1', '$remark2','$prname','$nationality','$extchg',
                                                        '$hotelamt', '$hotelinramt', '$uuid', '$type','$totamt')") or die(mysqli_error($conn));
            insmess();
            $mvouch = $qvouch; //1
            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
        } else {
            $mvouch = $qvouch; //1
            mysqli_query($conn, "UPDATE `$maindb` SET `vouchdt`='$vouchdt', `customer`='$agencode', `roe`='$roe', `remark1`='$remark1', type='$type',`extchg`='$extchg',`totamt`='$totamt',
                                                    `remark2`='$remark2', `hotelamt`='$hotelamt', `hotelinramt`='$hotelinramt',prname='$prname',`nationality`='$nationality'
                                                       WHERE `vouchno`= '$mvouch' ") or die(mysqli_error($conn));
            updmess();
            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
        }

        ################################# MAIN PART END #################################
    }
}

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);

    $magent = mysqli_query($conn, "SELECT accode,name FROM accmast where accode='$get[customer]'") or die(mysqli_error($conn));
    $lagent = mysqli_fetch_array($magent);
}

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

if (isset($_GET["delete"])) {
    delete($zdb, "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
    delete($zdb, "$trandb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
    $delcond = " source = '$source' and vouchno = '$_GET[vouchno]' ";
    $delcond2 = " source = 'PUVN' and vouchno = '$_GET[vouchno]' ";
    delnew($zdb, "actran", "$delcond", "$file?mode=last");
    delnew($zdb, "actran", "$delcond2", "$file?mode=last");
}

include("includes/linkshead.php");
?>
<script src="MyScript/shortkeys.js?a=2" type="text/javascript"></script>
<script src="MyScript/hotelsl.js?a=3" type="text/javascript"></script>
<script src="MyScript/hotelsl_search.js?a=2" type="text/javascript"></script>
<script>
    $(document).ready(function () {
        $('.visavouch').click(function () {
            $('.visaprint').toggle("");
        });
    });
</script>
<style>
    .sknewbtn {
        background-image: linear-gradient(135deg, #09C6F9 10%, #045DE9 100%) !important;
        color: white !important;
    }

    .skbtn {
        background-image: linear-gradient(135deg, #FFFEFF 10%, #D7FFFE 100%) !important;
        border: 1px solid #09C6F9 !important;
        /* background-color: white; */
        border: 2px solid #2FBFFE;
        color: #2A2A72;
        font-weight: bold;
        border-radius: 10px;
    }
</style>
</head>

<body>
    <form action='' method='POST'>
        <!-- Default box -->
        <div>
            <div class="col-lg-12 col-md-10 col-sm-12 col-xs-12  pad">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title" style="color:inherit"><?php echo $formname; ?></h3>
                        <!-- <div class="actions pull-right">
                            <i class="fa fa-chevron-down"></i>
                            <i class="fa fa-times"></i>
                        </div> -->
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-lg-1  col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Voucher</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-3 col-xs-3 pad">
                                <input type="text" class="form-control text-size form" name="vouchno" value="<?php echo ($addflag != 1) ? $get["vouchno"] : "$qvouch"; ?>" required readonly>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Date</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-4 col-xs-4 pad">
                                <input type="date" class="form-control form focusfield" name="vouchdt" value="<?php echo ($addflag != 1) ? $get["vouchdt"] : date('Y-m-d'); ?>" autofocus>
                            </div>
                            <div class="col-lg-1 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Agent / Customer</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4 pad">
                                <input list="customer" name="customer" class="customer form-control form" value="<?php echo ($addflag != 1) ? $lagent["name"] : ""; ?>" autocomplete="off">
                                <datalist id="customer">

                                    <option value=""></option>
                                    <?php
                                    $mitem = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE (`grpcode`='044' OR `grpcode`='010')  order by `name`") or die(mysqli_error($conn));
                                    while ($trow = mysqli_fetch_array($mitem)) {
                                        $hajiname = $trow['name'];
                                        echo "<option value='$hajiname'>";
                                    }
                                    ?>
                                </datalist>
                            </div>

                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Type</label>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 pad">
                                <select name="type" class="form-control form type" style="width: 100%;">
                                    <?php
                                    if ($get['type'] == 'A') {
                                        $agtype = 'Agent';
                                    } else {
                                        $agtype = 'Customer';
                                    }

                                    if ($addflag != 1) {
                                        echo "<option value='$get[type]'>$agtype</option>";
                                    } else {
                                        ?>
                                        <option value="A">Agent</option>
                                        <option value="C">Customer</option>
                                    <?php } ?>

                                </select>
                            </div>


                        </div>
                        <div class="row">
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg" style="color:red">ROE</label>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad adjcol">
                                <input type="number" class="form-control form text-right roe" name="roe" value="<?php echo ($addflag != 1) ? $get["roe"] : "1"; ?>" step='any'>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad" >
                                <label class="label-control marg">Guest Name</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad adjcol">
                                <input type="text" class="form-control form prname" name="prname" value="<?php echo ($addflag != 1) ? $get["prname"] : ""; ?>"  >
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad" >
                                <label class="label-control marg">Nationality</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 text-right pad adjcol">
                                <input list="nationality" name="nationality" class="nationality form-control form" value="<?php echo ($addflag != 1) ? $get["nationality"] : ""; ?>" tabindex="3" autocomplete="off">
                                <datalist id="nationality">
                                    <option value=""></option>
                                    <?php
                                    $mitem = mysqli_query($conn, "SELECT DISTINCT(`nationality`) as nationality FROM $maindb group by `nationality` order by `nationality`") or die(mysqli_error($conn));
                                    while ($trow = mysqli_fetch_array($mitem)) {
                                        $nationality = $trow['nationality'];
                                        echo "<option value='$nationality'>";
                                    }
                                    ?>
                                </datalist>
                            </div>
                        </div>
                        <br>
                        <div class="table-responsive">
                            <table class="table table-striped table-condensed table-bordered table-padd" width="100%">
                                <thead class="mySearchTr">
                                    <tr>
                                        <th width="2%"></th>
                                        <th width="2%"></th>
                                        <th width="3%" class='text-center'>Sr.</th>
                                        <th width="8%">City</th>
                                        <th width="10%">Hotel Name</th>
                                        <th width="5%">Check In</th>
                                        <th width="5%">Check Out</th>
                                        <th width="5%" class="text-center">No. Nights</th>
                                        <th width="4%" class="text-center">No. Pax</th>
                                        <!-- <th width="15%">Room Category</th> -->
                                        <th width="10%">Room View</th>
                                        <th width="7%">Type</th>
                                        <th width="5%" class='text-right'>Qty.</th>
                                        <th width="5%" class='text-right'>Rate</th>
                                        <th width="5%" class='text-right'>Amount</th>
                                        <th width="15%">Meal Type</th>
                                        <th width="10%">CNF No.</th>
                                        <th width="15%">Remarks</th>
                                    </tr>
                                </thead>

                                <tbody class="tbody">
                                    <?php
                                    if ($addflag != 1) {
                                        $ctr = 0;
                                        $mctr = 0;
                                        $tqty = 0;
                                        $tamt = 0;
                                        $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$get[vouchno]' ORDER BY `srno`") or die(mysqli_error($conn));
                                        while ($tran = mysqli_fetch_array($gettran)) {
                                            // $mhotcatg = mysqli_query($conn, "SELECT code,name FROM roomcatg WHERE code='$tran[roomcatg]'") or die(mysqli_error($conn));
                                            // $thotcatg = mysqli_fetch_array($mhotcatg);

                                            $mroomview = mysqli_query($conn, "SELECT code,name FROM roomview WHERE code='$tran[roomview]'") or die(mysqli_error($conn));
                                            $troomview = mysqli_fetch_array($mroomview);

                                            $mrtype = mysqli_query($conn, "SELECT code,name FROM roomtype WHERE code='$tran[roomtype]'") or die(mysqli_error($conn));
                                            $trtype = mysqli_fetch_array($mrtype);

                                            $mhotcity = mysqli_query($conn, "SELECT code,name FROM city WHERE code='$tran[city]'") or die(mysqli_error($conn));
                                            $thotcity = mysqli_fetch_array($mhotcity);

                                            $mhotel = mysqli_query($conn, "SELECT code,hotelnm FROM hotels WHERE code ='$tran[hotelnm]'") or die(mysqli_error($conn));
                                            $thotel = mysqli_fetch_array($mhotel);

                                            $mmeal = mysqli_query($conn, "SELECT code,name FROM $zroot.mealtype WHERE code ='$tran[mealtype]'") or die(mysqli_error($conn));
                                            $tmeal = mysqli_fetch_array($mmeal);
                                            $checked = "";
                                            if ($tran['prncomp'] == "1") {
                                                $checked = "checked";
                                            }

                                            $mctr++;
                                            echo "<tr>";
                                            echo "<td><input type='checkbox' style='border:none;position: inherit;height:25px;width:25px;' align='center' name= 'prncomp_$ctr' value='1' class='form-control form' $checked></td>";
                                            echo "<td><i class='fa fa-close remove' style='display:none'></i></td>";
                                            echo "<td><input type='text' class='form-control form text-center srno'    name='srno_$ctr'     value='$mctr'></td>";

                                            echo "<td>";
                                            echo "<select class='form-control form city select2' name='city_$ctr' style='width:100%'  >";
                                            echo "<option value='$thotcity[code]'>$thotcity[name]</option>";
                                            $gcity = mysqli_query($conn, "SELECT `code`,`name` FROM `city` ORDER BY `name`") or die(mysqli_error($conn));
                                            while ($icity = mysqli_fetch_array($gcity)) {
                                                echo "<option value='$icity[code]'>$icity[name]</option>";
                                            }
                                            echo "</select>";
                                            echo "</td>";

                                            echo "<td>";
                                            echo "<select class='form-control form hotelnm select2' name='hotelnm_$ctr' style='width:100%'>";
                                            echo "<option value='$thotel[code]'>$thotel[hotelnm]</option>";
                                            $mhotl = mysqli_query($conn, "SELECT code,hotelnm FROM hotels  order by hotelnm ") or die(mysqli_error($conn));
                                            while ($thotl = mysqli_fetch_array($mhotl)) {
                                                echo "<option value='$thotl[code]'>$thotl[hotelnm]</option>";
                                            }
                                            echo "</select>";
                                            echo "</td>";

                                            echo "<td><input type='date' class='form-control form checkin'        name='checkin_$ctr' value='$tran[checkin]'></td>";
                                            echo "<td><input type='date' class='form-control form checkout'        name='checkout_$ctr' value='$tran[checkout]'></td>";
                                            echo "<td><input type='number' class='form-control text-center form nonights'        name='nonights_$ctr' value='$tran[nonights]'></td>";
                                            echo "<td><input type='number' class='form-control text-center form hotelpax'        name='hotelpax_$ctr' value='$tran[hotelpax]'></td>";

                                            // echo "<td>";
                                            // echo "<select class='form-control form roomcatg select2' name='roomcatg_$ctr' style='width:100%'  >";
                                            // echo "<option value='$thotcatg[code]'>$thotcatg[name]</option>";
                                            // $git = mysqli_query($conn, "SELECT `code`,`name` FROM `roomcatg` ORDER BY `name`") or die(mysqli_error($conn));
                                            // while ($itm = mysqli_fetch_array($git)) {
                                            //     echo "<option value='$itm[code]'>$itm[name]</option>";
                                            // }
                                            // echo "</select>";
                                            // echo "</td>";

                                            echo "<td>";
                                            echo "<select class='form-control form roomview select2' name='roomview_$ctr' style='width:100%'  >";
                                            echo "<option value='$troomview[code]'>$troomview[name]</option>";
                                            $gitr = mysqli_query($conn, "SELECT `code`,`name` FROM `roomview` ORDER BY `name`") or die(mysqli_error($conn));
                                            while ($itr = mysqli_fetch_array($gitr)) {
                                                echo "<option value='$itr[code]'>$itr[name]</option>";
                                            }
                                            echo "</select>";
                                            echo "</td>";

                                            echo "<td>";
                                            echo "<select class='form-control form roomtype select2' name='roomtype_$ctr' style='width:100%'  >";
                                            echo "<option value='$tran[roomtype]'>$trtype[name]</option>";
                                            $git2 = mysqli_query($conn, "SELECT `code`,`name` FROM `roomtype` ORDER BY `name`") or die(mysqli_error($conn));
                                            while ($itm2 = mysqli_fetch_array($git2)) {
                                                echo "<option value='$itm2[code]'>$itm2[name]</option>";
                                            }
                                            echo "</select>";
                                            echo "</td>";

                                            echo "<td><input type='text' class='form-control form text-right qty'    name='qty_$ctr'  value='$tran[qty]'></td>";
                                            echo "<td><input type='text' class='form-control form text-right rate'    name='rate_$ctr'  value='$tran[rate]'></td>";
                                            echo "<td><input type='text' class='form-control form text-right hamount'  name='amount_$ctr'  value='$tran[amount]'readonly ></td>";

                                            echo "<td>";
                                            echo "<select class='form-control form mealtype select2' name='mealtype_$ctr' style='width:100%'  >";
                                            echo "<option value='$tran[mealtype]'>$tmeal[name]</option>";
                                            $gmeal2 = mysqli_query($conn, "SELECT `code`,`name` FROM $zroot.`mealtype` ORDER BY `name`") or die(mysqli_error($conn));
                                            while ($imeal2 = mysqli_fetch_array($gmeal2)) {
                                                echo "<option value='$imeal2[code]'>$imeal2[name]</option>";
                                            }
                                            echo "</select>";
                                            echo "</td>";

                                            echo "<td><input type='text' class='form-control form cnfno'  name='cnfno_$ctr'  value='$tran[cnfno]' ></td>";
                                            echo "<td><input type='text' class='form-control form remarks'  name='remarks_$ctr'  value='$tran[remarks]' ></td>";
                                            echo "</tr>";
                                            $ctr++;
                                        }
                                    } else {
                                        echo "<tr>";
                                        echo "<td><input type='checkbox' style='border:none;position: inherit;height:25px;width:25px;' align='center' name= 'prncomp_0' value='1' class='prncomp form-control form'></td>";
                                        echo "<td><i class='fa fa-close remove' style=''></i></td>";
                                        echo "<td><input type='text' class='form-control form text-center' srno'    name='srno_0'     value='1'></td>";

                                        echo "<td>";
                                        echo "<select class='form-control form city select2' name='city_0' style='width:100%'  >";
                                        echo "<option value=''></option>";
                                        $gcity = mysqli_query($conn, "SELECT `code`,`name` FROM `city` ORDER BY `name`") or die(mysqli_error($conn));
                                        while ($icity = mysqli_fetch_array($gcity)) {
                                            echo "<option value='$icity[code]'>$icity[name]</option>";
                                        }
                                        echo "</select>";
                                        echo "</td>";

                                        echo "<td>";
                                        echo "<select class='form-control form hotelnm select2' name='hotelnm_0' style='width:100%'  >";
                                        echo "<option value=''></option>";
                                        $mhotl = mysqli_query($conn, "SELECT code,hotelnm FROM hotels  order by hotelnm ") or die(mysqli_error($conn));
                                        while ($thotl = mysqli_fetch_array($mhotl)) {
                                            echo "<option value='$thotl[code]'>$thotl[hotelnm]</option>";
                                        }
                                        echo "</select>";
                                        echo "</td>";

                                        echo "<td><input type='date' class='form-control form checkin'        name='checkin_0' value='$tran[checkin]'></td>";
                                        echo "<td><input type='date' class='form-control form checkout'        name='checkout_0' value='$tran[checkout]'></td>";
                                        echo "<td><input type='number' class='form-control text-center form nonights'        name='nonights_0' value='$tran[nonights]'></td>";
                                        echo "<td><input type='number' class='form-control text-center form hotelpax'        name='hotelpax_0' value='$tran[hotelpax]'></td>";

                                        // echo "<td>";
                                        // echo "<select class='form-control form roomcatg select2' name='roomcatg_0' style='width:100%'  >";
                                        // echo "<option value=''></option>";
                                        // $git = mysqli_query($conn, "SELECT `code`,`name` FROM `roomcatg` ORDER BY `name`") or die(mysqli_error($conn));
                                        // while ($itm = mysqli_fetch_array($git)) {
                                        //     echo "<option value='$itm[code]'>$itm[name]</option>";
                                        // }
                                        // echo "</select>";
                                        // echo "</td>";
                                        echo "<td>";
                                        echo "<select class='form-control form roomview select2' name='roomview_0' style='width:100%'  >";
                                        echo "<option value=''></option>";
                                        $gitr = mysqli_query($conn, "SELECT `code`,`name` FROM `roomview` ORDER BY `name`") or die(mysqli_error($conn));
                                        while ($itr = mysqli_fetch_array($gitr)) {
                                            echo "<option value='$itr[code]'>$itr[name]</option>";
                                        }
                                        echo "</select>";
                                        echo "</td>";
                                        echo "<td>";
                                        echo "<select class='form-control form roomtype select2' name='roomtype_0' style='width:100%'  >";
                                        echo "<option value=''></option>";
                                        $git2 = mysqli_query($conn, "SELECT `code`,`name` FROM `roomtype` ORDER BY `name`") or die(mysqli_error($conn));
                                        while ($itm2 = mysqli_fetch_array($git2)) {
                                            echo "<option value='$itm2[code]'>$itm2[name]</option>";
                                        }

                                        echo "</select>";
                                        echo "</td>";

                                        echo "<td><input type='text' class='form-control form text-right qty'    name='qty_0'  value='0'></td>";
                                        echo "<td><input type='text' class='form-control form text-right rate'    name='rate_0'  value='0'></td>";
                                        echo "<td><input type='text' class='form-control form text-right hamount'  name='amount_0'  value='0' readonly ></td>";
                                        echo "<td>";
                                        echo "<select class='form-control form mealtype select2' name='mealtype_0' style='width:100%'  >";
                                        echo "<option value=''></option>";
                                        $gmeal2 = mysqli_query($conn, "SELECT `code`,`name` FROM $zroot.`mealtype` ORDER BY `name`") or die(mysqli_error($conn));
                                        while ($imeal2 = mysqli_fetch_array($gmeal2)) {
                                            echo "<option value='$imeal2[code]'>$imeal2[name]</option>";
                                        }
                                        echo "</select>";
                                        echo "</td>";
                                        echo "<td><input type='text' class='form-control form cnfno'  name='cnfno_0'  value='' ></td>";
                                        echo "<td><input type='text' class='form-control form remarks'  name='remarks_0'  value='' ></td>";

                                        echo "</tr>";
                                    }
                                    $pctr++;
                                    ?>
                                <input type="hidden" id="items" name="items" value="<?php echo ($addflag != 1) ? $ctr : 1; ?>" />
                                </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>
                        </div>

                        <div class="row">
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Remarks</label>
                            </div>
                            <div class="col-lg-4 col-md-3 col-sm-4 col-xs-4  pad">
                                <input type="text" class="form-control remark1 form" name="remark1" value="<?php echo ($addflag != 1) ? $get["remark1"] : ""; ?>">
                            </div>
                            <div class="col-lg-4 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg"><b>FE</b></label>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-4 col-xs-4  pad">
                                <input type="text" class="form-control text-right text-size hotelamt form" name="hotelamt" value="<?php echo ($addflag != 1) ? $get["hotelamt"] : ""; ?>" required readonly tabindex="-1">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg"></label>
                            </div>
                            <div class="col-lg-4 col-md-3 col-sm-4 col-xs-4  pad">
                                <input type="text" class="form-control remark2 form" name="remark2" value="<?php echo ($addflag != 1) ? $get["remark2"] : ""; ?>">
                            </div>
                            <div class="col-lg-4 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg"><b>Extra Charges</b></label>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-4 col-xs-4  pad">
                                <input type="text" class="form-control text-right text-size extchg form" name="extchg" value="<?php echo ($addflag != 1) ? $get["extchg"] : ""; ?>" required>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-10 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg"><b>Total Amount</b></label>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-4 col-xs-4  pad">
                                <input type="text" class="form-control text-right text-size totamt form" name="totamt" value="<?php echo ($addflag != 1) ? $get["totamt"] : ""; ?>" required readonly tabindex="-1">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-10 col-md-2 col-sm-2 col-xs-2 text-right pad" style='color: blue'>
                                <label class="label-control marg"><b>INR</b></label>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-4 col-xs-4  pad">
                                <input type="text" class="form-control text-right text-size hotelinramt form" name="hotelinramt" value="<?php echo ($addflag != 1) ? $get["hotelinramt"] : ""; ?>" required readonly tabindex="-1">
                            </div>
                        </div>
                        <!-- <div style="background-color:#E3F2E1;width: 50%;display: none;" class="pvisa">

                            <div class="row">
                                <div class="col-lg-3 text-right pad">
                                    <label class="label-control marg" style="color:red">Supplier</label>
                                </div>
                                <div class="col-lg-6 adjcolj pad">
                                    <select name="visasupp" class="form-control form pad visasupp" style="color:red;background-color:white;">
                                        <option value="<?php echo ($addflag != 1) ? $get["visasupp"] : ""; ?>"> <?php echo ($addflag != 1) ? $fetvsupp["name"] : ""; ?></option>
                        <?php
                        $gnm = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` where grpcode = '009' ORDER BY `name`") or die(mysqli_error($conn));
                        while ($fnm = mysqli_fetch_array($gnm)) {
                            echo "<option value='$fnm[accode]'>$fnm[name]</option>";
                        }
                        ?>

                                    </select>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-lg-3 text-right pad">
                                    <label class="label-control marg" style="color:red">Invoice No.</label>
                                </div>
                                <div class="col-lg-2 adjcolj pad">
                                    <input type="text" class="form-control form text-right  visainvno" style="color:red;background-color:white" name="visainvno" value="<?php echo ($addflag != 1) ? $get["visainvno"] : ""; ?>">
                                </div>
                                <div class="col-lg-2 text-right pad">
                                    <label class="label-control marg" style="color:red">Invoice Date</label>

                                </div>
                                <div class="col-lg-2 text-right pad">
                                    <input type="date" class="form-control form text-right  visainvdt" style="color:red;background-color:white" name="visainvdt" value="<?php echo ($addflag != 1) ? $get["visainvdt"] : ""; ?>">
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-lg-3 text-right pad">
                                    <label class="label-control marg" style="color:red">Rate</label>
                                </div>
                                <div class="col-lg-2 adjcolj pad">
                                    <input type="text" class="form-control form text-right  visarate" style="color:red;background-color:white" name="visarate" value="<?php echo ($addflag != 1) ? $get["visarate"] : ""; ?>">
                                </div>
                                <div class="col-lg-2 text-right pad">
                                    <label class="label-control marg" style="color:red">Amount</label>
                                </div>
                                <div class="col-lg-2 text-right pad">
                                    <input type="text" class="form-control form text-right  visapuramt" style="color:red;background-color:white" name="visapuramt" value="<?php echo ($addflag != 1) ? $get["visapuramt"] : ""; ?>">
                                </div>
                            </div>
                        </div> -->
                        <!-- <div class="row">
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <button type="button" id='print' class="btn btn-pad btn-square sknewbtn visapurch">
                                    Visa Purchase
                                </button>
                            </div>
                            <div class="col-lg-8 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Amount</label>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-4 col-xs-4  pad">
                                <input type="text" class="form-control text-right text-size totamt form" name="amount" value="<?php echo ($addflag != 1) ? $get["totamt"] : ""; ?>" readonly>
                            </div>
                        </div> -->

                    </div>
                    <div class="panel-footer">
                        <div class="col-lg-3 col-md-2 col-sm-2 col-xs-2 text-right pad">
                            <a align="right" id='print' class="btn btn-pad btn-square skbtn visavouch" href="#">
                                Hotel Voucher
                            </a>
                            <a align="right" id='print' class="btn btn-pad btn-square skbtn visaprint" href="hotelsl_print.php?vouchno=<?= $qvouch; ?>&para=<?= $para ?>&image=Yes&sale=Y" target="_blank" style="display: none;background-image: linear-gradient(135deg, #3C8CE7 10%, #00EAFF 100%) !important;color:white !important;">
                                <i class="fa fa-image"></i>
                            </a>
                            <a align="right" id='print' class="btn btn-pad btn-square skbtn visaprint" href="hotelsl_print.php?vouchno=<?= $qvouch; ?>&para=<?= $para ?>&image=No&sale=Y" target="_blank" style="display: none;background-image: linear-gradient(135deg, #3C8CE7 10%, #00EAFF 100%) !important;color:white !important;">
                                <i class="fa fa-print"></i>
                            </a>
                        </div>
                        <div class="col-lg-6 col-md-2 col-sm-2 col-xs-2 text-right pad">
                            <?php include("includes/buttons.php"); ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <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="1">Voucher</option>
                                <option value="2">Date</option>
                                <option value="3">Agent / Customer</option>
                                <option value="4">Guest Name</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="">Sort By</option>
                                <option value="1">Voucher</option>
                                <option value="2">Date</option>
                                <option value="3">Agent / Customer</option>
                                <option value="4">Guest Name</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">
                    </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-striped table-condensed table-bordered" width="100%">
                            <thead>
                                <tr class="mySearchTr">
                                    <th style="width:8%">Voucher</th>
                                    <th style="width:10%">Date</th>
                                    <th style="width:25%">Agent / Customer</th>
                                    <th style="width:17%">Guest Name</th>
                                    <th style="width:5%">Action</th>
                                </tr>
                            </thead>
                            <tbody class="sTbody">
                            </tbody>
                        </table>
                    </div>
                    <div class="row">
                        <div class="col-xs-12 text-right search-action-bar">
                            <input type="button" class="btn btn-primary sprev" value="Previous">
                            <input type="button" class="btn btn-primary snext" value="Next">
                        </div>
                    </div>
                </div>
                <div class="modal-footer"></div>
            </div>
        </div>
    </div>
    <?php include("includes/linksfoot.php"); ?>
</body>

</html>