<?php
ob_start();
// ini_set('display_errors', 1);
// error_reporting(E_ERROR);
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');

$formname = 'Sale TB';
$maindb = 'saletbmain';
$trandb = 'saletbtran';
$printfile = "saletb_pdf.php";
$file = 'saletb.php';
$trandbexist = 1;
$keyfld = "vouchno";

// browse("WORK IN PROGRESS");
$adduser = $_SESSION['username_' . $dbname];
date_default_timezone_set("Asia/Kolkata");
$adddate = date("Y-m-d");
$addtime = date("h:i:sa");

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
$compcd = $_SESSION["comp_" . $dbname];
$usertype = $_SESSION["usertype_" . $dbname];
$username = $_SESSION["username_" . $dbname];

$zroot1 = substr($zroot, 0, -4);

$currcono = $compcd;
$curryear = $myyear;

$zyear = right($zdb, 4);

$zStartDate = getzdates($zyear, 'S');
$zEndDate = getzdates($zyear, 'E');

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

if (isset($_POST["submit"])) {
    $a = 1;
    $qvouch = $_POST["vouchno"];
    $invno = $_POST["invno"];
    $vouchdt = $_POST["vouchdt"];

    $party = $_POST["party"];
    $mobileno = $_POST["mobileno"];
    $transporter = $_POST["transporter"];
    $cartno = $_POST["cartno"];
    $subtotal = $_POST["subtotal"];
    $totqty = $_POST['totqty'];

    $netamt = $_POST["netamt"];

    $remark1 = $_POST["remark1"];
    $remark2 = $_POST["remark2"];

    $oms = $_POST["oms"];
    $cgstperc = $_POST["cgstperc"];
    $sgstperc = $_POST["sgstperc"];
    $igstperc = $_POST["igstperc"];

    $cgstamt = $_POST["cgstamt"];
    $sgstamt = $_POST["sgstamt"];
    $igstamt = $_POST["igstamt"];


    $count = $_POST["items"];

    if ($igstperc > 0) {
        $gstp = $igstperc;
    } else {
        $gstp = $cgstperc + $sgstperc;
    }

    $mvouch = $qvouch;

    if ($type == 'C') {
        $salecode = 14;
    } else {
        $salecode = 15;
    }


    if ($a == 1) {

        mysqli_query($conn, "LOCK TABLES `$maindb` WRITE,  $trandb WRITE, accmast WRITE, `transport` WRITE") or die(mysqli_error($conn));
        try {
            mysqli_query($conn, "START TRANSACTION");
            if ($addflag == 1) {
                $gen1 = mysqli_query($conn, "SELECT MAX(vouchno+0) 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));
            $group = $source . $mvouch;

            $srl = 0;
            //        browse($count);
            for ($i = 0; $i <= $count; $i++) {
                $msrno = $_POST["srno_$i"];
                $mitem = $_POST["item_$i"];
                $qty = $_POST["qty_$i"];
                $rate = $_POST["rate_$i"];
                $amount = $_POST["amount_$i"];

                if (!empty($mitem)) {
                    $srl = $srl + 1;

                    mysqli_query($conn, "INSERT INTO `$trandb`(`vouchno`, `vouchdt`, `srno`, `item`, `qty`, `rate`, `amount`) 
                                                       VALUES ('$qvouch', '$vouchdt', '$srl', '$mitem', '$qty', '$rate', '$amount')") or die(mysqli_error($conn));
                }
            }

            ############################## MAIN ######################################################

            if ($addflag == 1) {
                mysqli_query($conn, "INSERT INTO `$maindb`(`vouchno`, `invno`, `invdt`, `vouchdt`, `party`, `totqty`, `subtotal`, `netamt`,
                                                           `remark1`, `remark2`, `oms`, `cgstperc`, `sgstperc`, `igstperc`, 
                                                           `cgstamt`, `sgstamt`, `igstamt`, `mobileno`, `transporter`, `cartno`,`adduser`,`adddate`,`addtime`) 
                                                   VALUES ('$qvouch', '$invno', '$vouchdt', '$vouchdt', '$party', '$totqty', '$subtotal', '$netamt',  
                                                           '$remark1', '$remark2', '$oms', '$cgstperc', '$sgstperc', '$igstperc',
                                                           '$cgstamt', '$sgstamt', '$igstamt', '$mobileno', '$transporter', '$cartno','$adduser','$adddate','$addtime')") or die(mysqli_error($conn));
                //            insmess();

                mysqli_query($conn, "COMMIT");

                // Unlock tables
                mysqli_query($conn, "UNLOCK TABLES");
                $mvouch = $qvouch; //1
                //            $_SESSION['print_voucher'] = $mvouch;
                header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
            } else {
                $mvouch = $qvouch; //1
                $editdate = date("Y-m-d");
                $edittime = date("h:i:sa");
                mysqli_query($conn, "UPDATE `$maindb` SET `invno`='$invno',`invdt`='$vouchdt',`vouchdt`='$vouchdt', `party`='$party', `oms`='$oms',
                                                          `totqty`='$totqty', `subtotal`='$subtotal', `remark1`='$remark1',`remark2`='$remark2',
                                                          `cgstperc`='$cgstperc', `sgstperc`='$sgstperc', `igstperc`='$igstperc', 
                                                          `cgstamt`='$cgstamt', `sgstamt`='$sgstamt', `igstamt`='$igstamt', `netamt`='$netamt',
                                                          `mobileno`='$mobileno', `transporter`='$transporter', `cartno`='$cartno',`edituser`='$adduser', `editdate`='$editdate', `edittime`='$edittime' 
                                                          WHERE `vouchno`='$qvouch'") or die(mysqli_error($conn));
                mysqli_query($conn, "COMMIT");

                // Unlock tables
                mysqli_query($conn, "UNLOCK TABLES");
                updmess();
                header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
            }
        } catch (Exception $e) {
            // Rollback the transaction if anything goes wrong
            mysqli_query($conn, "ROLLBACK");
            mysqli_query($conn, "UNLOCK TABLES");
            // Optionally, log the error
            browse("Transaction failed: " . $e->getMessage());
            // You can redirect or show an error message here
        }
    }
}

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

    $findparty = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `accode`='$get[party]'") or die(mysqli_error($conn));
    $lparty = mysqli_fetch_array($findparty);

    $gettransp = mysqli_query($conn, "SELECT `code`,`name` FROM `transport` WHERE `code`= '$get[transporter]'") or die(mysqli_error($conn));
    $ltrans = mysqli_fetch_array($gettransp);

    $rd = "readonly";
}

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

if (isset($_GET["delete"])) {

    delete($zdb, "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
    delete($zdb, "$trandb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
}


include("includes/linkshead.php");
?>
<style type="text/css">
    /* .bolden {
        font-family: "Arial Black"
    } */

    .label-right {
        display: block;
        text-align: right;
    }

    .row {
        width: 100%;
        margin-right: 0px;
        margin-left: 0px;
    }

    .party-flex {
        display: flex;
        align-items: center;
    }

    .party-flex .select2-container {
        flex: 1 1 auto !important;
        /* �? TAKE ALL REMAINING WIDTH */
        min-width: 0 !important;
    }

    .create-party-btn {
        white-space: nowrap !important;
        margin-left: 6px !important;
        height: 28px !important;
        border-radius: 7px;
    }

    /* ===== Create Party Modal ===== */

    #partyModal .modal-dialog {
        max-width: 420px;
        /* margin-top: 10vh; */
    }

    #partyModal .modal-content {
        border-radius: 10px;
        border: none;
        box-shadow: 0 12px 35px rgba(0, 0, 0, 0.18);
    }

    /* Header */
    #partyModal .modal-header {
        background: #f6f8fa;
        border-bottom: 1px solid #e3e6ea;
        padding: 15px 18px;
    }

    #partyModal .modal-title {
        font-weight: 600;
        font-size: 16px;
        color: #2c3e50;
    }

    #partyModal .close {
        font-size: 22px;
        opacity: 0.5;
    }

    /* Body */
    #partyModal .modal-body {
        padding: 18px;
    }

    #partyModal label {
        font-size: 13px;
        font-weight: 600;
        color: #555;
        margin-bottom: 6px;
    }

    #partyModal input[type="text"] {
        height: 38px;
        border-radius: 6px;
        border: 1px solid #ced4da;
        font-size: 14px;
    }

    #partyModal input[type="text"]:focus {
        border-color: #5cb85c;
        box-shadow: 0 0 0 2px rgba(92, 184, 92, 0.15);
    }

    /* Footer */
    #partyModal .modal-footer {
        border-top: 1px solid #e3e6ea;
        padding: 12px 18px;
    }

    #partyModal .btn-primary {
        background-color: #5cb85c;
        border-color: #4cae4c;
        border-radius: 6px;
        font-weight: 600;
        padding: 7px 18px;
    }

    #partyModal .btn-primary:hover {
        background-color: #4cae4c;
    }

    /* Small helper text (optional) */
    #partyModal .help-text {
        font-size: 12px;
        color: #888;
        margin-top: 5px;
    }

    /* Select2 same height as input */

    #partyModal .select2-container .select2-selection--single {
        height: 38px !important;
        border: 1px solid #ced4da !important;
        border-radius: 6px !important;
    }

    #partyModal .select2-container--default .select2-selection--single .select2-selection__rendered {
        line-height: 38px !important;
        padding-left: 12px !important;
        font-size: 14px;
    }

    #partyModal .select2-container--default .select2-selection--single .select2-selection__arrow {
        height: 38px !important;
        right: 6px;
    }

    #partyModal .select2-container {
        width: 100% !important;
    }

    /* ===== Create Transporter Modal ===== */

    #transporterModal .modal-dialog {
        max-width: 420px;
        /* margin-top: 10vh; */
    }

    #transporterModal .modal-content {
        border-radius: 10px;
        border: none;
        box-shadow: 0 12px 35px rgba(0, 0, 0, 0.18);
    }

    /* Header */
    #transporterModal .modal-header {
        background: #f6f8fa;
        border-bottom: 1px solid #e3e6ea;
        padding: 15px 18px;
    }

    #transporterModal .modal-title {
        font-weight: 600;
        font-size: 16px;
        color: #2c3e50;
    }

    #transporterModal .close {
        font-size: 22px;
        opacity: 0.5;
    }

    /* Body */
    #transporterModal .modal-body {
        padding: 18px;
    }

    #transporterModal label {
        font-size: 13px;
        font-weight: 600;
        color: #555;
        margin-bottom: 6px;
    }

    #transporterModal input[type="text"] {
        height: 38px;
        border-radius: 6px;
        border: 1px solid #ced4da;
        font-size: 14px;
    }

    #transporterModal input[type="text"]:focus {
        border-color: #5cb85c;
        box-shadow: 0 0 0 2px rgba(92, 184, 92, 0.15);
    }

    /* Footer */
    #transporterModal .modal-footer {
        border-top: 1px solid #e3e6ea;
        padding: 12px 18px;
    }

    #transporterModal .btn-primary {
        background-color: #5cb85c;
        border-color: #4cae4c;
        border-radius: 6px;
        font-weight: 600;
        padding: 7px 18px;
    }

    #transporterModal .btn-primary:hover {
        background-color: #4cae4c;
    }

    /* Small helper text (optional) */
    #transporterModal .help-text {
        font-size: 12px;
        color: #888;
        margin-top: 5px;
    }

    /* Select2 same height as input */

    #transporterModal .select2-container .select2-selection--single {
        height: 38px !important;
        border: 1px solid #ced4da !important;
        border-radius: 6px !important;
    }

    #transporterModal .select2-container--default .select2-selection--single .select2-selection__rendered {
        line-height: 38px !important;
        padding-left: 12px !important;
        font-size: 14px;
    }

    #transporterModal .select2-container--default .select2-selection--single .select2-selection__arrow {
        height: 38px !important;
        right: 6px;
    }

    #transporterModal .select2-container {
        width: 100% !important;
    }



    @media (max-width:1200px) {

        .label-control {
            font-size: 11px;
        }

        .form-control {
            font-size: 12px;
            padding: 4px 6px;
        }

        .btn {
            font-size: 12px;
            padding: 4px 8px;
        }

        .party-flex {
            display: flex;
            align-items: center;
            gap: 3px;
        }

        .create-party-btn {
            padding: 4px 8px;
            white-space: nowrap;
        }
    }

    @media (max-width:991px) {

        .label-control {
            font-size: 10px;
        }

        .form-control {
            font-size: 11px;
            padding: 3px 4px;
        }

        .btn {
            font-size: 11px;
            padding: 3px 6px;
        }

        .party-flex {
            display: flex;
            gap: 2px;
        }

        .create-party-btn {
            font-size: 11px;
        }

        .marg {
            margin-top: 8px;
        }
    }

    @media (max-width:768px) {

        .label-control {
            font-size: 9px;
        }

        .form-control {
            font-size: 10px;
            height: 28px;
            padding: 2px 4px;
        }

        .btn {
            font-size: 10px;
            padding: 2px 5px;
            height: 28px;
        }

        .create-party-btn {
            font-size: 10px;
            padding: 2px 5px;
        }

        .select2-container--default .select2-selection--single {
            height: 28px !important;
        }

        .select2-container--default .select2-selection--single .select2-selection__rendered {
            line-height: 28px !important;
            font-size: 10px;
        }

        .select2-container--default .select2-selection--single .select2-selection__arrow {
            height: 28px !important;
        }
    }
</style>
<script src="MyScript/saletb.js?a=<?= mt_rand() ?>" type="text/javascript"></script>
<script src="MyScript/saletb_search.js?b=<?= mt_rand() ?>" type="text/javascript"></script>
<script src="MyScript/checkdate.js" type="text/javascript"></script>

</head>

<body>
    <form action='' method='POST'>

        <!-- Default box -->
        <div>
            <div class="col-lg-10 col-md-12 col-sm-12 col-xs-12 pad">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <?php include('includes/usermention.php'); ?>
                    </div>
                    
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 text-right pad">
                                <label class="label-control marg">Voucher</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="text" class="form-control form vouchno" name="vouchno" value="<?php echo ($addflag != 1) ? $get["vouchno"] : " $qvouch"; ?>" readonly required>
                                <input type="hidden" value="<?= $zStartDate ?>" style="width: 1px;border: none" class="zstdate">
                                <input type="hidden" value="<?= $zEndDate ?>" style="width: 1px;border: none" class="zenddate">
                                <input type="hidden" class="addflg" name="addflg" value="<?php echo $addflag; ?>">
                                <input type="hidden" class="oms" name="oms"
                                    value="<?php echo ($addflag != 1) ? $get["oms"] : ""; ?>">
                            </div>


                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 text-right pad">
                                <label class="label-control marg">Date</label>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                                <input type="date" id="vouchdt" class="form-control form focusfield vouchdt"
                                    name="vouchdt"
                                    value="<?php echo ($addflag != 1) ? $get["vouchdt"] : date("Y-m-d"); ?>" required
                                    autofocus />
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 text-right pad">
                                <label class="label-control marg">Invoice No.</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="text" class="form-control form invno" name="invno"
                                    value="<?php echo ($addflag != 1) ? $get["invno"] : "$qvouch"; ?>" required>
                            </div>

                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 text-right pad">
                                <label class="label-control marg">Customer</label>
                            </div>

                            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 pad">

                                <div class="party-flex">

                                    <select class="form-control form party select2"
                                        id="party"
                                        name="party"
                                        style="width:100%">
                                        <option value="<?= ($addflag != 1) ? $lparty['accode'] : '' ?>">
                                            <?= ($addflag != 1) ? $lparty['name'] : '' ?>
                                        </option>

                                        <?php
                                        $gparty = mysqli_query($conn, "SELECT accode,name FROM accmast WHERE grpcode='010' ORDER BY name");

                                        while ($party = mysqli_fetch_array($gparty)) {
                                            echo "<option value='$party[accode]'>$party[name]</option>";
                                        }
                                        ?>
                                    </select>

                                    <button type="button"
                                        class="btn btn-success create-party-btn form"
                                        id="createPartyBtn">
                                        + Create
                                    </button>

                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 text-right pad">
                                <label class="label-control marg">No. Cartons</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="text" class="form-control form cartno" name="cartno"
                                    value="<?php echo ($addflag != 1) ? $get["cartno"] : ""; ?>">
                            </div>

                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 text-right pad">
                                <label class="label-control marg">Mobile No.</label>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                                <input type="text" class="form-control form mobileno" maxlength="10" name="mobileno"
                                    value="<?php echo ($addflag != 1) ? $get["mobileno"] : ""; ?>">
                            </div>

                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Transporter</label>
                            </div>
                            <div class="col-lg-4 col-md-5 col-sm-4 col-xs-4 pad">

                                <div class="party-flex">

                                    <select class="form-control form transporter select2"
                                        name="transporter"
                                        style="width:100%">

                                        <option value="<?= ($addflag != 1) ? $ltrans['code'] : '' ?>">
                                            <?= ($addflag != 1) ? $ltrans['name'] : '' ?>
                                        </option>

                                        <?php
                                        $gtrans = mysqli_query($conn, "SELECT code,name FROM transport ORDER BY name");
                                        while ($ftrans = mysqli_fetch_array($gtrans)) {
                                            echo "<option value='$ftrans[code]'>$ftrans[name]</option>";
                                        }
                                        ?>
                                    </select>

                                    <button type="button"
                                        class="btn btn-success create-party-btn form"
                                        id="createTransporterBtn">
                                        + Create
                                    </button>

                                </div>
                            </div>



                        </div>

                        <div class="table-responsive" style="overflow-y:scroll;height: 500px;">
                            <table class="table table-striped table-condensed table-bordered tab" width="100%">
                                <thead class="mySearchTr">
                                    <tr>
                                        <th style='width: 1%' class="stick"></th>
                                        <th style='width: 3%' class='text-right stick'>Sr.</th>
                                        <th style='width: 15%' class="stick">Description</th>
                                        <!--<th style='width: 10%' class="stick">Color</th>-->
                                        <th style='width: 4%' class='text-right stick'>Qty.</th>
                                        <th style='width: 4%' class='text-right stick'>Rate</th>
                                        <th style='width: 6%' class='text-right stick'>Amount</th>
                                    </tr>
                                </thead>
                                <tbody class="tbody" id="saledtltab">
                                    <?php
                                    if ($addflag != 1) {
                                        $ctr = 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)) {

                                            echo "<tr>";
                                            echo "<td class='text-center'><i class='fa fa-close remove' style='display:none;'></i></td>";
                                            echo "<td><input type='text' class='form-control form text-right srno' name='srno_$ctr' value='$tran[srno]'></td>";
                                            echo "<td><input type='text' class='form-control form item' maxlength='50' name='item_$ctr'      value='$tran[item]'></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 amount' name='amount_$ctr'    value='$tran[amount]' readonly></td>";
                                            echo "</tr>";
                                            $ctr++;
                                        }
                                    } else {
                                        $pctr = 0;
                                    ?>
                                        <tr>
                                            <td class="text-center"><i class="fa fa-close remove"></i></td>
                                            <td><input type="text" class="form-control form text-right srno" name="srno_0"
                                                    value="1"></td>
                                            <td><input type="text" class="form-control form item" maxlength="50"
                                                    name="item_0" value=""></td>
                                            <td><input type="text" class="form-control form text-right qty" name="qty_0"
                                                    value="0"></td>
                                            <td><input type="text" class="form-control form text-right rate"
                                                    id="rate_<?= $pctr ?>" name="rate_0" value="0"></td>
                                            <td><input type="text" class="form-control form text-right amount"
                                                    name="amount_0" value="0" readonly></td>
                                        </tr>
                                    <?php
                                        $pctr++;
                                    }
                                    ?>
                                    <input type="hidden" id="items" name="items"
                                        value="<?php echo ($addflag != 1) ? $ctr : 1; ?>" />

                                </tbody>
                            </table>
                        </div>

                        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 pad">
                            <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 pad">

                                <div>
                                    <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="col-lg-10 col-md-10 col-sm-10 col-xs-10 pad">
                                    <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad text-right">

                                        <label class="label-control marg">Remarks</label>
                                    </div>
                                    <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9 pad">
                                        <input type="text" name="remark1" class="form-control form remark1"
                                            value="<? echo ($addflag != 1) ? $get["remark1"] : ""; ?>">
                                    </div>
                                </div>
                                <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10 pad">
                                    <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad text-right"></div>
                                    <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9 pad">
                                        <input type="text" name="remark2" class="form-control form remark2"
                                            value="<? echo ($addflag != 1) ? $get["remark2"] : ""; ?>">
                                    </div>
                                </div>
                            </div>


                            <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 pad">
                                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 pad">
                                    <div class="col-lg-5 col-md-5 col-sm-5 col-xs-5 pad text-right">
                                        <label class="label-control marg" style='color:#337AB7'>Total Qty. </label>
                                    </div>
                                    <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                                        <input type="text" name="totqty"
                                            class="form-control form text-right totqty bolden"
                                            value="<?php echo ($addflag != 1) ? $get['totqty'] : "0.00"; ?>" readonly>
                                    </div>
                                    <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad text-right">
                                        <label class="label-control marg" style='color:#337AB7'>SubTotal</label>
                                    </div>
                                    <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                        <input type="text" class="form-control form subtotal text-right bolden"
                                            value="<? echo ($addflag != 1) ? $get['subtotal'] : "0"; ?>" name="subtotal"
                                            readonly>
                                    </div>
                                </div>

                                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 pad">
                                    <div class="col-lg-7 col-md-7 col-sm-7 col-xs-7 pad text-right">
                                        <label class="label-control marg">CGST</label>
                                    </div>

                                    <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                                        <input type="text" class="form-control form cgstperc text-right bolden"
                                            value="<? echo ($addflag != 1) ? $get['cgstperc'] : "0"; ?>"
                                            name="cgstperc">
                                    </div>
                                    <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                        <input type="text" class="form-control form cgstamt text-right bolden"
                                            value="<? echo ($addflag != 1) ? $get['cgstamt'] : "0"; ?>" name="cgstamt"
                                            readonly>
                                    </div>
                                </div>

                                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 pad">
                                    <div class="col-lg-7 col-md-7 col-sm-7 col-xs-7 pad text-right">
                                        <label class="label-control marg">SGST</label>
                                    </div>

                                    <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                                        <input type="text" class="form-control form sgstperc text-right bolden"
                                            value="<? echo ($addflag != 1) ? $get['sgstperc'] : "0"; ?>"
                                            name="sgstperc">
                                    </div>
                                    <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                        <input type="text" class="form-control form sgstamt text-right bolden"
                                            value="<? echo ($addflag != 1) ? $get['sgstamt'] : "0"; ?>" name="sgstamt"
                                            readonly>
                                    </div>
                                </div>

                                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 pad">
                                    <div class="col-lg-7 col-md-7 col-sm-7 col-xs-7 pad text-right">
                                        <label class="label-control marg">IGST</label>
                                    </div>

                                    <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                                        <input type="text" class="form-control form igstperc text-right bolden"
                                            value="<? echo ($addflag != 1) ? $get['igstperc'] : "0"; ?>"
                                            name="igstperc">
                                    </div>
                                    <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                        <input type="text" class="form-control form igstamt text-right bolden"
                                            value="<? echo ($addflag != 1) ? $get['igstamt'] : "0"; ?>" name="igstamt"
                                            readonly>
                                    </div>
                                </div>


                                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 pad">
                                    <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad"></div>
                                    <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad"></div>
                                    <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad text-right">
                                        <label class="label-control marg">Netamt (Rs.)</label>
                                    </div>
                                    <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                        <input type="text" class="form-control form netamt text-right totbillamt bolden"
                                            value="<? echo ($addflag != 1) ? $get['netamt'] : "0"; ?>" name="netamt"
                                            readonly>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad text-right"></div>

                        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 pad">
                            <?php include("includes/buttons.php"); ?>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                            <input type="button" id="finishTab" class="btn btn-primary pull-right form mySearchTr"
                                style="color: #fff;" value="Check & Finish">
                        </div>
                    </div>
                </div>
            </div>
    </form>
    <?php include("includes/linksfoot.php"); ?>



    <div class="modal fade" id="partyModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content" style="width: 550px;border-radius:10px;">

                <div class="modal-header">
                    <button class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title">Create Party</h4>
                </div>

                <div class="modal-body">
                    <!-- <div class="form-group">
                        <label>Party Name</label>
                        <input type="text" id="party_name" class="form-control" maxlength="50">
                    </div>
                    <div class="form-group">
                        <label>Party Name</label>
                        <input type="text" id="party_name" class="form-control" maxlength="50">
                    </div> -->

                    <div class="row" style="margin-bottom:10px;">

                        <div class="col-md-3 text-right pad">
                            <label class="label-control" style="margin-top:7px;">Name</label>
                        </div>

                        <div class="col-md-8">
                            <input type="text" class="form-control party_name" id="party_name" name="party_name"
                                maxlength="40" style="border-radius:4px;">
                        </div>

                    </div>

                    <div class="row" style="margin-bottom:10px;">

                        <div class="col-md-3 text-right pad">
                            <label class="label-control" style="margin-top:7px;">GST No.</label>
                        </div>

                        <div class="col-md-8">
                            <input type="text" class="form-control party_gstno" id="party_gstno" name="party_gstno"
                                maxlength="15" style="border-radius:4px;">
                        </div>

                    </div>

                    <div class="row" style="margin-bottom:10px;">

                        <div class="col-md-3 text-right pad">
                            <label class="label-control" style="margin-top:7px;">State</label>
                        </div>

                        <div class="col-md-4">
                            <select name="mstate" class="form-control mstate select2" style="width:100%;">

                                <option value=""></option>

                                <?php
                                $mown4 = mysqli_query($conn, "SELECT `code`, `name` FROM `state` ORDER BY name") or die(mysqli_error($conn));
                                while ($trow4 = mysqli_fetch_array($mown4)) {
                                    echo "<option value='$trow4[name]'>$trow4[name]</option>";
                                }
                                ?>

                            </select>
                        </div>

                        <div class="col-md-2 text-right pad">
                            <label class="label-control" style="margin-top:7px;">Code</label>
                        </div>

                        <div class="col-md-2">
                            <input type="text" class="form-control mstatecode" name="mstatecode" readonly>
                        </div>

                    </div>

                    <div class="row">

                        <div class="col-md-3 text-right pad">
                            <label class="label-control" style="margin-top:7px;">Mobile</label>
                        </div>

                        <div class="col-md-4">
                            <input type="text" class="form-control mmobile" name="mmobile" maxlength="10"
                                style="border-radius:4px;">
                        </div>

                    </div>
                </div>

                <div class="modal-footer">
                    <button class="btn btn-primary" id="saveParty">Save</button>
                </div>

            </div>
        </div>
    </div>

    <div class="modal fade" id="transporterModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content" style="width: 550px;border-radius:10px;">

                <div class="modal-header">
                    <button class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title">Create Transporter</h4>
                </div>

                <div class="modal-body">

                    <div class="row" style="margin-bottom:10px;">

                        <div class="col-md-3 text-right pad">
                            <label class="label-control" style="margin-top:7px;">Name</label>
                        </div>

                        <div class="col-md-8">
                            <input type="text" class="form-control transporter_name" id="transporter_name" name="transporter_name" maxlength="40" style="border-radius:4px;">
                        </div>

                    </div>

                    <div class="row">

                        <div class="col-md-3 text-right pad">
                            <label class="label-control" style="margin-top:7px;">Mobile</label>
                        </div>

                        <div class="col-md-4">
                            <input type="text" class="form-control tmobile" name="tmobile" maxlength="10"
                                style="border-radius:4px;">
                        </div>

                    </div>
                </div>

                <div class="modal-footer">
                    <button class="btn btn-primary" id="saveTransporter">Save</button>
                </div>

            </div>
        </div>
    </div>

    <div class="modal fade searchModal bs-example-modal-lg" tabindex="-1" role="dialog"
        aria-labelledby="myLargeModalLabel">
        <div class="modal-dialog modal-lg" style="margin-top: 15%">
            <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">
                    <input type="hidden" value="<?php echo $fseries ?>" class="form-control series">
                    <input type="hidden" value="<?php echo $get['vouchno']; ?>" class="form-control vouchno">
                    <input type="hidden" value="<?php echo $file ?>" class="form-control file">
                    <input type="hidden" value="S" class="form-control parasrch">
                    <div class="row">
                        <div class="col-lg-2">
                            <select class="form-control sfield">
                                <option value="1">Voucher</option>
                                <option value="2">Customer</option>
                                <option value="3">Date</option>
                                <option value="4">Net 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="1">Voucher</option>
                                <option value="2">Customer</option>
                                <option value="3">Date</option>
                                <option value="4">Net 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">
                        <img src="images/search.gif" alt="loading">
                    </div>
                    <div class="col-lg-12 snoRecord text-center">
                        <h3>NO RECORDS FOUND</h3>
                    </div>
                    <div class="table-responsive" style="max-height: 400px;overflow: auto;">
                        <table id="" class="table table-striped table-condensed table-bordered" width="100%">
                            <thead>
                                <tr class="mySearchTr">
                                    <th width="5%">Voucher</th>
                                    <th width="10%">Invoice No.</th>
                                    <th width="15%">Date</th>
                                    <th width="20%">Customer</th>
                                    <th width="15%">Amount</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>
</body>

</html>