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

$formname = 'Ticket Purchase Entry';
$maindb = 'tiktnewmain';
$trandb = 'tiktnewtran';
$accdb = "actran";
$printfile = "tiktnewreg.php";
$file = 'tiktnew.php';
$trandbexist = 1;
$keyfld = "vouchno";

$source = "PU";
$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"];
    $supplier = $_POST["supplier"];
    $gstno = $_POST["gstno"];
    $remark1 = $_POST["remark1"];
    $remark2 = $_POST["remark2"];
    $totamt = $_POST["totamt"];
    $subtot = $_POST["subtot"];
    $handchg = $_POST["handchg"];
    $perpax = $_POST["perpax"];
    $gstperc = $_POST["gstperc"];
    $gstamt = $_POST["gstamt"];
    $tiktinvno = $_POST["tiktinvno"];
    $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;
        }

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

        mysqli_query($conn, "DELETE FROM `$trandb` WHERE `$keyfld`='$mvouch'") 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"];
            $paxname = $_POST["paxname_$i"];
            $ppno = $_POST["ppno_$i"];
            $from = $_POST["from_$i"];
            $to = $_POST["to_$i"];
            $travdate = $_POST["travdate_$i"];
            $airline = $_POST["airline_$i"];
            $ticketno = $_POST["ticketno_$i"];
            $flightno = $_POST["flightno_$i"];
            $fileno = $_POST["fileno_$i"];
            $pnr = $_POST["pnr_$i"];
            $amount = $_POST["amount_$i"];

            $nigctr = $nonights;

            if (!empty($paxname)) {

                $getfrom = mysqli_query($conn, "SELECT `name` FROM `sector` WHERE `name`='$from'") or die(mysqli_error($conn));
                if (mysqli_num_rows($getfrom) > 0) {
                    $fcode = mysqli_fetch_array($getfrom);
                    $fromcode = $icode['code'];
                } else {
                    $genfrom = mysqli_query($conn, "SELECT MAX(code) AS maxcode FROM `sector` where code != '' LIMIT 0,1 ") or die(mysqli_error($conn));
                    if (mysqli_num_rows($genfrom) > 0) {
                        $gfrom = mysqli_fetch_assoc($genfrom);
                        $fromcode = $gfrom["maxcode"] + 1;
                    } else {
                        $fromcode = '1';
                    }
                    mysqli_query($conn, "INSERT INTO `sector`(`code`, `name`)
                                     VALUES('$fromcode',  '$from')") or die(mysqli_error($conn));
                }

                $getto = mysqli_query($conn, "SELECT `name` FROM `sector` WHERE `name`='$to'") or die(mysqli_error($conn));
                if (mysqli_num_rows($getto) > 0) {
                    $tcode = mysqli_fetch_array($getto);
                    $tocode = $tcode['code'];
                } else {
                    $gento = mysqli_query($conn, "SELECT MAX(code) AS maxcode FROM `sector` where code != '' LIMIT 0,1 ") or die(mysqli_error($conn));
                    if (mysqli_num_rows($gento) > 0) {
                        $gto = mysqli_fetch_assoc($gento);
                        $tocode = $gto["maxcode"] + 1;
                    } else {
                        $tocode = '1';
                    }
                    mysqli_query($conn, "INSERT INTO `sector`(`code`, `name`)
                                     VALUES('$tocode',  '$to')") or die(mysqli_error($conn));
                }

                $getair = mysqli_query($conn, "SELECT `name` FROM `airline` WHERE `name`='$airline'") or die(mysqli_error($conn));
                if (mysqli_num_rows($getair) > 0) {
                    $acode = mysqli_fetch_array($getair);
                    $aircode = $acode['code'];
                } else {
                    $genair = mysqli_query($conn, "SELECT MAX(code) AS maxcode FROM `sector` where code != '' LIMIT 0,1 ") or die(mysqli_error($conn));
                    if (mysqli_num_rows($genair) > 0) {
                        $gto = mysqli_fetch_assoc($genair);
                        $aircode = $gto["maxcode"] + 1;
                    } else {
                        $aircode = '1';
                    }
                    mysqli_query($conn, "INSERT INTO `airline`(`code`, `name`)
                                     VALUES('$aircode',  '$airline')") or die(mysqli_error($conn));
                }


                $srl++;
                mysqli_query($conn, "INSERT INTO `$trandb`(`vouchno`, `vouchdt`, `srno`, `paxname`, `ppno`, `from`, `to`, fileno,
                                                                         `airline`, `ticketno`, `flightno`, `travdate`, `pnr`, `amount`)
                                                                  VALUES('$mvouch', '$vouchdt', '$srl', '$paxname', '$ppno', '$from', '$to', '$fileno',
                                                                         '$airline', '$ticketno', '$flightno', '$travdate', '$pnr', '$amount' )") or die(mysqli_error($conn));
            }
        }



        mysqli_query($conn, "DELETE FROM `$accdb` WHERE `vouchno` = '$mvouch' AND `source` = '$source'") or die(mysqli_error($conn));

        if ($tiktpuramt > 0) {
            $samtmin = $tiktpuramt * -1;

            $purcode = 12;
            // // purchase part
            // mysqli_query($conn, "INSERT INTO `$accdb`(`date`, `vouchno`, `source`, `trnno`, `accode`, `grpcode`, `amount`)
            //                                                 VALUES ('$tiktinvdt', '$mvouch', 'PTKT', '001', '$purcode', '004', '$samtmin')") or die(mysqli_error($conn));
            // // party part
            // mysqli_query($conn, "INSERT INTO `$accdb`(`date`, `vouchno`, `source`, `trnno`, `accode`, `grpcode`, `amount`)
            //                                                 VALUES ('$tiktinvdt', '$mvouch', 'PTKT', '002', '$tiktsupp', '009', '$tiktpuramt')") or die(mysqli_error($conn));
            // purchase part
            mysqli_query($conn, "INSERT INTO `$accdb`(`date`, `vouchno`, `source`, `trnno`, `accode`, `grpcode`, `amount`)
                                                            VALUES ('$tiktinvdt', '$mvouch', '$source', '001', '$tiktsupp', '009', '$samtmin')") or die(mysqli_error($conn));
            // party part
            mysqli_query($conn, "INSERT INTO `$accdb`(`date`, `vouchno`, `source`, `trnno`, `accode`, `grpcode`, `amount`)
                                                            VALUES ('$tiktinvdt', '$mvouch', '$source', '002', '$purcode', '004', '$tiktpuramt')") or die(mysqli_error($conn));
        }

        mysqli_query($conn, "DELETE FROM `$accdb` WHERE `vouchno`='$mvouch' AND source = '$source' ") or die(mysqli_error($conn));

        if ($totamt > 0) {
            $minus_amt = ($totamt * -1);

            // sale part
            mysqli_query($conn, "INSERT INTO `$accdb`(`date`, `vouchno`, `source`, `trnno`, `accode`, `grpcode`, `amount`)
                                                            VALUES ('$vouchdt', '$mvouch', '$source', '001', '30','005', '$minus_amt')") or die(mysqli_error($conn));

            // party part
            mysqli_query($conn, "INSERT INTO `$accdb`(`date`, `vouchno`, `source`, `trnno`, `accode`, `grpcode`, `amount`)
                                                            VALUES ('$vouchdt', '$mvouch', '$source', '002', '$supplier','010', '$totamt')") or die(mysqli_error($conn));
        }

        #################################TRAN PART END #################################
        ############################## MAIN ######################################################
        if ($addflag == 1) {

            $uuid = $_SESSION["uuid"];

            mysqli_query($conn, "INSERT INTO `$maindb`(`vouchno`, `vouchdt`, `supplier`, `totamt`, `remark1`, `remark2`, `gstno`, `subtot`, `perpax`,
                                                                     `handchg`, `gstperc`, `gstamt`, `tiktsupp`, `tiktrate`, `tiktinvno`, `tiktinvdt`, `tiktpuramt`, uuid)
                                                             VALUES ('$qvouch', '$vouchdt',  '$supplier', '$totamt', '$remark1', '$remark2', '$gstno', '$subtot', '$perpax', 
                                                                     '$handchg', '$gstperc', '$gstamt', '$tiktsupp', '$tiktrate', '$tiktinvno', '$tiktinvdt', '$tiktpuramt', '$uuid' )") 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', `supplier`='$supplier', `totamt`='$totamt',`remark1`='$remark1',`remark2`='$remark2',
                                                                    `gstno`='$gstno', `subtot`='$subtot', `perpax`='$perpax', `handchg`='$handchg', `gstperc`='$gstperc', 
                                                                    `gstamt`='$gstamt', `tiktsupp`='$tiktsupp', `tiktrate`='$tiktrate', `tiktinvno`='$tiktinvno',
                                                                    `tiktinvdt`='$tiktinvdt', `tiktpuramt`='$tiktpuramt'  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[supplier]'") or die(mysqli_error($conn));
    $lagent = mysqli_fetch_array($magent);

    $gettksupp = mysqli_query($conn, "SELECT accode,name FROM `accmast` WHERE accode='$get[tiktsupp]'") or die(mysqli_error($conn));
    $fettksupp = mysqli_fetch_array($gettksupp);
}

$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 = 'PTKT' 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=<?= mt_rand() ?>" type="text/javascript"></script>
<script src="MyScript/tiktnew.js?c=<?= mt_rand() ?>" type="text/javascript"></script>
<script src="MyScript/tiktnew_search.js?b=<?= mt_rand() ?>" type="text/javascript"></script>
<style>
    .sknewbtn {
        background-image: linear-gradient(135deg, #09C6F9 10%, #045DE9 100%) !important;
        color: white !important;
    }
</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>
                    <div class="panel-body">
                        <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">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>

                        <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"> Supplier</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4 pad">
                                <select name="supplier" class="form-control form supplier select2" style="width: 100%;">
                                    <option value='<?php echo ($addflag != 1) ? $lagent['accode'] : '' ?>'>
                                        <?php echo ($addflag != 1) ? $lagent['name'] : '' ?></option>
                                    <?php
                                    $mhotl = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `grpcode`='009'") or die(mysqli_error($conn));
                                    while ($thotl = mysqli_fetch_array($mhotl)) {
                                        echo "<option value='$thotl[accode]'>$thotl[name]</option>";
                                    }
                                    ?>
                                </select>
                            </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">Invoice No.</label>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-4 col-xs-4  pad">
                                <input type="text" class="form-control text-size form tiktinvno" name="tiktinvno" maxlength="15"
                                       value="<?php echo ($addflag != 1) ? $get["tiktinvno"] : ""; ?>">
                            </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">GST No.</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4  pad">
                                <input type="text" class="form-control text-size form gstno" name="gstno"
                                       value="<?php echo ($addflag != 1) ? $get["gstno"] : ""; ?>">
                            </div>
                        </div>

                        <div class="table-responsive" style="padding: 1%;">
                            <table class="table table-striped table-condensed table-bordered " id="tabledata"
                                   width="100%">
                                <thead class="mySearchTr">
                                    <tr>
                                        <th style="width: 2%"></th>
                                        <th style="width: 3%" class='text-center'>Sr.</th>
                                        <th style="width: 7%">Passport</th>
                                        <th style="width: 10%;">File No</th>

                                        <th style="width: 20%">Pax Name</th>
                                        <th style="width: 6%">From</th>
                                        <th style="width: 6%;">To</th>
                                        <th style='width: 6%'>Date</th>
                                        <th style="width: 10%;">Airline</th>
                                        <th style="width: 8%;">Ticket No.</th>
                                        <th style='width: 7%'>Flight No.</th>
                                        <th style='width: 7%'>PNR</th>
                                        <th style="width: 10%" class='text-right'>Amount</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)) {

                                            $getho = mysqli_query($conn, "SELECT `code`,`name` FROM `airline` where code='$tran[airline]'") or die(mysqli_error($conn));
                                            $fetho = mysqli_fetch_array($getho);

                                            $mctr++;
                                            echo "<tr>";
                                            echo "<td style='text-align:center'><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><input type='text' class='form-control form ppno' maxlength='15'  name='ppno_$ctr'     value='$tran[ppno]' ></td>";
                                            echo "<td><input type='text' value='$tran[fileno]' name='fileno_$ctr' class='form-control form fileno'></td>";

                                            echo "<td><input type='text' class='form-control form paxname' maxlength='40' name='paxname_$ctr'  value='$tran[paxname]' required></td>";

                                            echo "<td>";
                                            echo "<input list='from' name='from_$ctr' class='lcheckin form-control form ' autocomplete='off' value='$tran[from]'> ";
                                            echo "<datalist id='from' char='#'>";
                                            echo "<option>";

                                            $mun = mysqli_query($conn, "SELECT `name` FROM `sector` group by `name`  order by `name`") or die(mysqli_error($conn));

                                            while ($tun = mysqli_fetch_array($mun)) {
                                                $unname = $tun['name'];
                                                echo "<option value='$unname'>";
                                            }
                                            echo "</datalist>";
                                            echo "</td>";
                                            // echo "<td>";
                                            // echo "<select class='form-control form lcheckin select2 fetchpart_$ctr' name='from_$ctr' style='width:100%'>";
                                            // echo "<option value='$tran[from]'>$tran[from]</option>";
                                            // $gfrm = mysqli_query($conn, "SELECT `code`,`name` FROM `sector` ORDER BY `name`") or die(mysqli_error($conn));
                                            // while ($ifrm = mysqli_fetch_array($gfrm)) {
                                            //     echo "<option value='$ifrm[name]'>$ifrm[name]</option>";
                                            // }
                                            // echo "</select>";
                                            // echo "</td>";
                                            echo "<td>";
                                            echo "<input list='to' name='to_$ctr' class='lcheckout form-control form ' autocomplete='off' value='$tran[to]'> ";
                                            echo "<datalist id='to' char='#'>";
                                            echo "<option>";

                                            $mto = mysqli_query($conn, "SELECT `name` FROM `sector` group by `name`  order by `name`") or die(mysqli_error($conn));

                                            while ($tto = mysqli_fetch_array($mto)) {
                                                $toname = $tto['name'];
                                                echo "<option value='$toname'>";
                                            }
                                            echo "</datalist>";
                                            echo "</td>";

                                            // echo "<td>";
                                            // echo "<select class='form-control form lcheckout select2 fetchpart_$ctr' name='to_$ctr' style='width:100%'>";
                                            // echo "<option value='$tran[to]'>$tran[to]</option>";
                                            // $gto = mysqli_query($conn, "SELECT `code`,`name` FROM `sector` ORDER BY `name`") or die(mysqli_error($conn));
                                            // while ($ito = mysqli_fetch_array($gto)) {
                                            //     echo "<option value='$ito[name]'>$ito[name]</option>";
                                            // }
                                            // echo "</select>";
                                            // echo "</td>";

                                            echo "<td><input type='date' class='form-control form travdate'  name='travdate_$ctr' value='$tran[travdate]'></td>";

                                            echo "<td>";
                                            echo "<input list='airline' name='airline_$ctr' class='lcheckout form-control form ' autocomplete='off' value='$tran[airline]'> ";
                                            echo "<datalist id='airline' char='#'>";
                                            echo "<option>";

                                            $mair = mysqli_query($conn, "SELECT `name` FROM `airline` group by `name`  order by `name`") or die(mysqli_error($conn));

                                            while ($tair = mysqli_fetch_array($mair)) {
                                                $airname = $tair['name'];
                                                echo "<option value='$airname'>";
                                            }
                                            echo "</datalist>";
                                            echo "</td>";
                                            // echo "<td>";
                                            // echo "<select class='form-control form airline select2' name='airline_$ctr' style='width:100%'  >";
                                            // echo "<option value='$fetho[code]'>$fetho[name]</option>";
                                            // $git = mysqli_query($conn, "SELECT `code`,`name` FROM `airline` 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><input type='text' class='form-control form ticketno'             name='ticketno_$ctr' value='$tran[ticketno]' ></td>";
                                            echo "<td><input type='text' class='form-control form flightno'             name='flightno_$ctr' value='$tran[flightno]' ></td>";
                                            echo "<td><input type='text' class='form-control form pnr'                  name='pnr_$ctr'      value='$tran[pnr]' ></td>";
                                            echo "<td><input type='text' class='form-control text-right form amount'    name='amount_$ctr'   value='$tran[amount]'></td>";
                                            echo "</tr>";
                                            $ctr++;
                                        }
                                    } else {
                                        $pctr = 0;
                                        echo "<tr>";
                                        echo "<td style='text-align:center'><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><input type='text' class='form-control form ppno' name='ppno_0' value='' required></td>";
                                        echo "<td><input type='text'   name='fileno_0' class='fileno form-control form' style='text-align:left;' value='' /></td>";

                                        echo "<td><input type='text' class='form-control form paxname' maxlength='40'  name='paxname_0' value=''></td>";

                                        echo "<td>";
                                        echo "<input list='from' name='from_0' class='form-control lcheckin form' value=''>";
                                        echo "<datalist id='from' char='#'>";
                                        echo "    <option value=''></option>";
                                        $mun = mysqli_query($conn, "SELECT `name` FROM `sector` group by `name`  order by `name`") or die(mysqli_error($conn));
                                        while ($tun = mysqli_fetch_array($mun)) {
                                            $unname = $tun['name'];
                                            echo "<option value='$unname'>";
                                        }
                                        echo "</datalist>";
                                        echo "</td>";

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

                                        echo "<td>";
                                        echo "<input list='to' name='to_0' class='form-control lcheckout form' value=''>";
                                        echo "<datalist id='to' char='#'>";
                                        echo "    <option value=''></option>";
                                        $mto = mysqli_query($conn, "SELECT `name` FROM `sector` group by `name`  order by `name`") or die(mysqli_error($conn));
                                        while ($tto = mysqli_fetch_array($mto)) {
                                            $toname = $tto['name'];
                                            echo "<option value='$toname'>";
                                        }
                                        echo "</datalist>";
                                        echo "</td>";

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

                                        echo "<td><input type='date' name='travdate_0' value='' class='form-control form travdate'></td>";

                                        echo "<td>";
                                        echo "<input list='airline' name='airline_0' class='form-control lcheckin form' value=''>";
                                        echo "<datalist id='airline' char='#'>";
                                        echo "    <option value=''></option>";
                                        $mair = mysqli_query($conn, "SELECT `name` FROM `airline` group by `name`  order by `name`") or die(mysqli_error($conn));
                                        while ($tair = mysqli_fetch_array($mair)) {
                                            $airname = $tair['name'];
                                            echo "<option value='$airname'>";
                                        }
                                        echo "</datalist>";
                                        echo "</td>";
                                        // echo "<td>";
                                        // echo "<select class='form-control form airline select2' name='airline_0' style='width:100%'>";
                                        // echo "<option value=''></option>";
                                        // $git = mysqli_query($conn, "SELECT `code`,`name` FROM `airline` 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><input type='text' name='ticketno_0' value='' class='form-control form ticketno' required></td>";
                                        echo "<td><input type='text' name='flightno_0' value='' class='form-control form flightno' required></td>";
                                        echo "<td><input type='text' name='pnr_0' value='' maxlength='15'  class='form-control form pnr' required></td>";
                                        echo "<td><input type='text' name='amount_0' value='0' class='form-control text-right form amount'></td>";

                                        echo "</tr>";
                                    }
                                    $pctr++;
                                    ?>
                                <input type="hidden" id="items" name="items"
                                       value="<?php echo ($addflag != 1) ? $ctr : 1; ?>" />
                                </tbody>
                            </table>

                            <div class="col-lg-12 " style="margin-top: 10px;">
                                <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>

                        <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">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-5 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Subtotal</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 subtot form" name="subtot"
                                       value="<?php echo ($addflag != 1) ? $get["subtot"] : "0"; ?>" readonly>
                            </div>
                        </div>

                        <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"></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" style="width: 30.933333%;">
                                <label class="label-control marg">Handling Charges</label>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-4 col-xs-4 pad" style="width: 6.333333%;">
                                <input type="text" class="form-control text-right perpax form" name="perpax"
                                       value="<?php echo ($addflag != 1) ? $get["perpax"] : "0"; ?>">
                            </div>
                            <div class="col-lg-1 col-md-2 col-sm-2 col-xs-2 text-right pad" style="width: 4.333333%;">
                                <label class="label-control marg">Per Pax</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 handchg form" name="handchg"
                                       value="<?php echo ($addflag != 1) ? $get["handchg"] : "0"; ?>">
                            </div>
                        </div>

                        <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"></label>
                            </div>
                            <div class="col-lg-4 col-md-3 col-sm-4 col-xs-4  pad">
                            </div>
                            <div class="col-lg-4 col-md-2 col-sm-2 col-xs-2 text-right pad" style="width: 37.333333%;">
                                <label class="label-control marg">GST %</label>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-4 col-xs-4  pad" style="width: 4.333333%;">
                                <input type="text" class="form-control text-right gstperc form" name="gstperc"
                                       value="<?php echo ($addflag != 1) ? $get["gstperc"] : "0"; ?>">
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-4 col-xs-4  pad">
                                <input type="text" class="form-control text-right gstamt form" name="gstamt"
                                       value="<?php echo ($addflag != 1) ? $get["gstamt"] : "0"; ?>" readonly>
                            </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">Final 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="totamt"
                                       value="<?php echo ($addflag != 1) ? $get["totamt"] : "0"; ?>" readonly>
                            </div>
                        </div>
                    </div>
                    <div class="panel-footer">

                        <?php include("includes/buttons.php"); ?>
                    </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">GST No</option>
                                <option value="5">Amount</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">GST No</option>
                                <option value="5">Amount</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:30%">Agent/Customer</th>
                                    <th style="width:35%">GST No</th>
                                    <th style="width:8%">Amount</th>
                                    <!-- <th style="width:8%">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>