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

$formname = 'Sale GST';
$maindb = 'salemain';
$trandb = 'saletran';
$stkdb = 'transacn';
$accdb = 'actran';
$cashdb = 'cashrecp';
$bankdb = 'bankrecp';
$printfile = "salegst_fin_print.php";
$file = 'sale.php';
$trandbexist = 1;
$keyfld = "vouchno";
$source = "SL";

$compcd = $_SESSION["comp_" . $dbname];

$stkdb1 = 'tran';
$zroot = $_SESSION["zdir"];
$combstkdb = $stkdb1 . $myyear;

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

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

date_default_timezone_set('Asia/Kolkata');
$time = date('H:i:s');

$usertype = $_SESSION["usertype"];
$username = $_SESSION["username_" . $dbname];
$edpara = $_GET["edpara"];

//browse($username);

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$zyear = right($zdb, 4);
$comp = $_SESSION["comp_" . $dbname];
$zStartDate = getzdates($zyear, 'S', $comp);
$zEndDate = getzdates($zyear, 'E', $comp);
mysqli_select_db($conn, $zdb);

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

//if (isset($_POST["cancbtn"])) {
//    $mcancvouch = $_POST['cancvouch'];
//    $mcashvouch2 = $_POST['cashvouch2'];
//    $cancdate = $_POST['cancdate'];
//
//    //    browse($cancdate);
//    if ($cancdate != '' || $cancdate != '0000-00-00') {
//        //    browse($mcancvouch);
////    browse($mcashvouch2);
//        mysqli_query($conn, "DELETE FROM `$accdb` WHERE `vouchno` = '$mcancvouch' AND `source` = '$source' ") OR die(mysqli_error($conn));
//        mysqli_query($conn, "DELETE FROM `cashrecp` WHERE `$keyfld`='$mcashvouch2' ") or die(mysqli_error($conn));
//        mysqli_query($conn, "DELETE FROM `$accdb` WHERE `$keyfld`='$mcashvouch2' and `source` = 'CR' $keycond") or die(mysqli_error($conn));
//        mysqli_query($conn, "DELETE FROM `$stkdb` WHERE vouchno='$mcancvouch'  AND `source`='$source'") or die(mysqli_error($conn));
//
//        mysqli_query($conn, "Update `$maindb` set `cancdate`='$cancdate', cancuser='$username', canc_flag='C' where vouchno = '$mcancvouch'") or die(mysqli_error($conn));
//        mysqli_query($conn, "Update `$trandb` set cancdate='C' where vouchno = '$mcancvouch'") or die(mysqli_error($conn));
//        browse('Bill Cancelled');
//    }
//    header("refresh: 1; $file?mode=edit&$keyfld=$mcancvouch");
//}
if (isset($_POST["submit"])) {
    $a = 1;
    $invno = $_POST["invno"];
    $vouchdt = $_POST["vouchdt"];
    $invdt = $_POST["invdt"];
    $party = $_POST["party"];
    $type = $_POST["type"];
    $prodtype = $_POST["prodtype"];
    $salesman = $_POST["salesman"];
    $driver = $_POST["driver"];
    $dcperc = $_POST["dcperc"];
    $dcbperc = $_POST["dcbperc"];
    $dcamt = $_POST["dcamt"];
    $subtotal = $_POST["subtotal"];
    $litemdisc = $_POST["litemdisc"];
    $cdiscperc = $_POST["cdiscperc"];
    $cdiscamt = $_POST["cdiscamt"];
    $coukg = $_POST["coukg"];
    $courate = $_POST["courate"];
    $couamt = $_POST["couamt"];
    $netamt = $_POST["netamt"];
    $oldamt = $_POST["oldamt"];
    $cashamt = $_POST["cashamt"];
    $ccamt = $_POST["ccamt"];
    $credamt = $_POST["credamt"];
    $lesother = $_POST["lesother"];
    $remark1 = $_POST["remark1"];
    $remark2 = $_POST["remark2"];
    $disctotp = $_POST["disctotp"];
    $bankname = $_POST["bankname"];

    $ordno = $_POST["ordno"];
    $orddt = $_POST["orddt"];
    $orderby = $_POST["orderby"];
    $chalno = $_POST["chalno"];
    $chaldt = $_POST["chaldt"];
    $gatepass = $_POST["gatepass"];

    $oms = $_POST["oms"];
    $taxamt = $_POST["taxamt"];
    $totcgst = $_POST["totcgst"];
    $totsgst = $_POST["totsgst"];
    $totigst = $_POST["totigst"];
    $sgstperc = $_POST["sgstperc"];
    $cgstperc = $_POST["cgstperc"];
    $igstperc = $_POST["igstperc"];
    $gstperc = $_POST["gstperc"];

    $nameprint = $_POST['nameprint'];
    $printmobile = $_POST['printmobile'];
    $totalamount = $_POST['totalamount'];
    $roundoff = $_POST['roundoff'];

    $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) {
        #############AUto Cash Receipt Start####################
        if ($addflag == 1) {
            $gen1 = mysqli_query($conn, "SELECT MAX(vouchno) AS maxcode FROM `$maindb`  LIMIT 0,1 ") or die(mysqli_error($conn));
            if (mysqli_num_rows($gen1) > 0) {
                $vvouch = mysqli_fetch_assoc($gen1);
                $mvouch = $vvouch["maxcode"] + 1;
            } else {
                $mvouch = '1';
            }
        }
        #################################TRAN PART #################################

        mysqli_query($conn, "DELETE FROM `$trandb` WHERE `$keyfld`='$mvouch'") or die(mysqli_error($conn));
        mysqli_query($conn, "DELETE FROM `$stkdb` WHERE `$keyfld`='$mvouch' AND `source`='$source'") or die(mysqli_error($conn));
        //        mysqli_query($conn, "DELETE FROM `pursacn` WHERE `$keyfld`='$mvouch' AND `source`='$source' ")or die(mysqli_error($conn));
//        mysqli_query($conn, "DELETE FROM $zroot.$combstkdb WHERE `$keyfld`='$mvouch' AND `source`='$source' and `compcode`='$compcd'")or die(mysqli_error($conn));
        $group = $source . $mvouch;

        $srl = 0;
        //        browse($count);
        for ($i = 0; $i <= $count; $i++) {
            $msrno = $_POST["srno_$i"];
            $barcode = $_POST["barcode_$i"];
            $descrip = $_POST["descrip_$i"];
            $color = $_POST["color_$i"];
            $mitem = $_POST["item_$i"];
            $unit = $_POST["unit_$i"];
            $macqty = $_POST["macqty_$i"];
            $qty = $_POST["qty_$i"];
            $mrp = $_POST["mrp_$i"];
            $msp = $_POST["msp_$i"];
            $rate = $_POST["rate_$i"];
            $amount = $_POST["amount_$i"];
            $discperc = $_POST["discperc_$i"];
            $discount = $_POST["discount_$i"];
            $total = $_POST["total_$i"];
            $otprowsucs = $_POST["otprowsucs_$i"];
            $otpvalue = $_POST["otpvalue_$i"];
            $hsncode = $_POST["hsncode_$i"];

            $purvouch = $_POST["purvouch_$i"];
            $pursrno = $_POST["pursrno_$i"];

            $getunit = mysqli_query($conn, "SELECT * FROM `unit` WHERE `name` = '$unit'");
            $fetunit = mysqli_fetch_array($getunit);
            $unitcode = $fetunit['code'];

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

                mysqli_query($conn, "INSERT INTO `$trandb`(`vouchno`, `vouchdt`, `srno`, `barcode`, `item`, `qty`, `unit`, color, descrip, macqty,
                                `mrp`, `msp`, `rate`, `amount`, `discperc`, `discount`, `total`, `otprowsucs`, `otpvalue`,`hsncode`) 
                    VALUES ('$qvouch', '$vouchdt', '$srl', '$barcode', '$mitem', '$qty', '$unitcode', '$color','$descrip', '$macqty',
                                '$mrp', '$msp', '$rate', '$amount', '$discperc', '$discount', '$total', '$otprowsucs', '$otpvalue','$hsncode')") or die(mysqli_error($conn));
            }
        }

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

        if ($netamt > 0) {


            $minus_amt = ($netamt * -1);

            if ($prodtype == 'P') {
                $actamt = $netamt * 10;
                $actminus = $minus_amt * 10;
            } else {
                $actamt = $netamt;
                $actminus = $minus_amt;
            }

            // sale part
            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount, prodtype, actamt)
                    VALUES ('$vouchdt','$mvouch', '$source', '001', '$salecode','005', '$netamt', '$prodtype', '$actamt')") OR die(mysqli_error($conn));
            // party part
            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount, prodtype, actamt)
                     VALUES ('$vouchdt','$mvouch', '$source', '002', '$party', '010', '$minus_amt', '$prodtype', '$actminus')") or die(mysqli_error($conn));
        }
        ############################## MAIN ######################################################
        if ($addflag == 1) {
            mysqli_query($conn, "INSERT INTO `salemain`(`vouchno`, `invno`, `invdt`, `vouchdt`, `party`, `transporter`, `lrno`, 
                        `lrdate`, `cashcred`, `prodtype`, `salesman`, `driver`, `dcperc`, `dcbperc`, `dcamt`, `totqty`, `subtotal`, `litemdisc`, 
                        `cdiscperc`, `cdiscamt`,`discperc`, `discount`, `netamt`, `cashamt`,`ccamt`,`credamt`, `lesother`, 
                        `remark1`, `remark2`,`cashvouch`,`disctotp`,`purcono`,`purvouch`,`bankvouch`,`bankname`, `oms`, `cgstperc`, `sgstperc`, `igstperc`, 
                        `totcgst`, `totsgst`, `totigst`, `tottaxamt`,`gstperc`,`nameprint`,`totalamount`,`roundoff`,
                        `ordno`,`orddt`,`orderby`,`chalno`,`chaldt`,`gatepass`) 
                        VALUES ('$qvouch', '$invno', '$vouchdt', '$vouchdt', '$party', '$transporter', '$lrno', 
                        '$lrdate', '$type', '$prodtype', '$salesman', '$driver', '$dcperc', '$dcbperc', '$dcamt', '$totqty', '$subtotal', '$litemdisc', 
                        '$cdiscperc', '$cdiscamt', '$discperc', '$discount', '$netamt', '$cashamt','$ccamt','$credamt', '$lesother', 
                        '$remark1', '$remark2','$mcashvouch', '$disctotp','$purcono','$mpurvouch','$mbankvouch','$bankname', '$oms', '$cgstperc', '$sgstperc', '$igstperc',
                        '$totcgst', '$totsgst', '$totigst', '$taxamt','$gstperc','$nameprint','$totalamount','$roundoff',
                        '$ordno','$orddt','$orderby','$chalno','$chaldt','$gatepass')") 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 `salemain` SET `invno`='$invno',`invdt`='$vouchdt',`vouchdt`='$vouchdt',`nameprint`='$nameprint', `totalamount`='$totalamount',`roundoff`='$roundoff',
                    `party`='$party',`transporter`='$transporter',`lrno`='$lrno',`lrdate`='$lrdate',`cashcred`='$type',`prodtype`='$prodtype',`salesman`='$salesman',
                    `driver`='$driver',`dcperc`='$dcperc',`dcbperc`='$dcbperc',`dcamt`='$dcamt',`totqty`='$totqty',`subtotal`='$subtotal',
                    `litemdisc`='$litemdisc',`cdiscperc`='$cdiscperc',`cdiscamt`='$cdiscamt',
                    `discperc`='$discperc',`discount`='$discount',`netamt`='$netamt',`credamt`='$credamt',`ccamt`='$ccamt',`cashamt`='$cashamt', `lesother`='$lesother',`remark1`='$remark1',
                    `remark2`='$remark2', `cashvouch`='$mcashvouch',`disctotp`='$disctotp',`purcono`='$purcono',`purvouch`='$mpurvouch',
                    `bankvouch`='$mbankvouch',`bankname`='$bankname', `oms`='$oms',`cgstperc`='$cgstperc',`gstperc`='$gstperc',
                     `sgstperc`='$sgstperc', `igstperc`='$igstperc', `totcgst`='$totcgst', `totsgst`='$totsgst', `totigst`='$totigst', `tottaxamt`='$taxamt',
                    `ordno`='$ordno', `orddt`='$orddt', `orderby`='$orderby', `chalno`='$chalno', `chaldt`='$chaldt', `gatepass`='$gatepass'
                    WHERE `vouchno`='$qvouch'") or die(mysqli_error($conn));

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

if ($addflag != 1) {

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

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

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

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

    $delcsh = $get['cashvouch'];
}

if (isset($_GET["delete"])) {
    mysqli_query($conn, "LOCK TABLES `$maindb` WRITE, `$trandb` WRITE,`$accdb` WRITE") or die(mysqli_error($conn));

    $delcond = " source = '$source' and vouchno = '$_GET[vouchno]'";
//    $delcond1 = " source = 'CR' and vouchno = '$delcsh'";
//    $delcond3 = " vouchno = '$delcsh'  ";
    $delcond2 = " vouchno = '$_GET[vouchno]'";

    delnew($zdb, "$maindb", "$delcond2", "$file?mode=last");
    delnew($zdb, "$trandb", "$delcond2", "$file?mode=last");
//    delnew($zdb, "$stkdb", "$delcond", "$file?mode=last");
    delnew($zdb, "$accdb", "$delcond", "$file?mode=last");
//    delnew($zdb, "$accdb", "$delcond1", "$file?mode=last");
//    delnew($zdb, "cashrecp", "$delcond3", "$file?mode=last");

    mysqli_query($conn, "UNLOCK TABLES");
}

include("includes/linkshead.php");
?>
<script src="MyScript/sale.js?a=<?= mt_rand(); ?>" type="text/javascript"></script>
<!-- <script src="MyScript/search_item_sale.js?A=<?= mt_rand(); ?>" type="text/javascript"></script> -->
<script src="MyScript/sale_search.js?b=<?= mt_rand(); ?>" type="text/javascript"></script>
<script src="MyScript/checkdate.js" type="text/javascript"></script>
<style>
    .partypdf-btn {
        position: relative;
        overflow: hidden;

        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 10px;

        padding: 10px 16px;

        border: 1.5px solid rgba(255, 59, 48, 0.40);
        border-radius: 14px;

        background: rgba(255, 255, 255, 0.88);
        backdrop-filter: blur(10px);

        color: #D32F2F;
        font-size: 15px;
        font-weight: 600;
        text-decoration: none !important;

        cursor: pointer;

        transition: all .28s cubic-bezier(.4, 0, .2, 1);

        box-shadow:
            0 4px 14px rgba(255, 59, 48, 0.10),
            0 1px 3px rgba(0, 0, 0, 0.06);
    }
    .partypdf-prof {
        position: relative;
        overflow: hidden;

        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 10px;

        padding: 10px 16px;

        border: 1.5px blue;
        border-radius: 14px;

        background: rgba(255, 255, 255, 0.88);
        backdrop-filter: blur(10px);

        color: blue;
        font-size: 15px;
        font-weight: 600;
        text-decoration: none !important;

        cursor: pointer;

        transition: all .28s cubic-bezier(.4, 0, .2, 1);

        box-shadow:
            0 4px 14px rgba(255, 59, 48, 0.10),
            0 1px 3px rgba(0, 0, 0, 0.06);
    }

    .partypdf-btn i {
        font-size: 20px;
        color: #FF3B30;

        transition: all .28s ease;
    }

    .partypdf-prof i {
        font-size: 20px;
        color: blue;

        transition: all .28s ease;
    }

    .partypdf-btn:hover {
        transform: translateY(-3px);

        border-color: rgba(255, 59, 48, 0.95);

        background: #fff;

        color: #B71C1C;

        box-shadow:
            0 12px 30px rgba(255, 59, 48, 0.25),
            0 4px 12px rgba(255, 59, 48, 0.12);
    }

    .partypdf-btn:hover i {
        transform: scale(1.12) rotate(-4deg);
    }

    .partypdf-btn:active {
        transform: scale(0.97);

        box-shadow:
            0 6px 16px rgba(255, 59, 48, 0.20);
    }

    .partywhatsapp-btn {
        position: relative;
        overflow: hidden;

        display: inline-flex;
        align-items: center;
        gap: 10px;

        padding: 10px 16px;

        border: 1.5px solid rgba(37, 211, 102, 0.45);
        border-radius: 14px;

        background: rgba(255, 255, 255, 0.88);
        backdrop-filter: blur(10px);

        color: #25D366;
        font-size: 15px;
        font-weight: 600;
        text-decoration: none !important;

        cursor: pointer;

        transition: all .28s cubic-bezier(.4, 0, .2, 1);

        box-shadow:
            0 4px 14px rgba(37, 211, 102, 0.10),
            0 1px 3px rgba(0, 0, 0, 0.06);
    }

    .partywhatsapp-btn i {
        font-size: 22px;
        color: #25D366;

        transition: all .28s ease;
    }

    .partywhatsapp-btn:hover {
        transform: translateY(-3px);

        border-color: rgba(37, 211, 102, 0.9);

        background: #fff;

        box-shadow:
            0 12px 30px rgba(37, 211, 102, 0.28),
            0 4px 12px rgba(37, 211, 102, 0.12);
    }

    .partywhatsapp-btn:hover i {
        transform: scale(1.12) rotate(-6deg);
    }

    .partywhatsapp-btn:active {
        transform: scale(0.97);

        box-shadow:
            0 6px 16px rgba(37, 211, 102, 0.20);
    }

    a:not(.partypdf-btn):not(.partywhatsapp-btn) {
        text-decoration: none;
        color: inherit;
    }

    .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>

</style>
</head>

<body>
    <form action='' method='POST'>
        <div class="col-lg-3 pad text-center" id="overlay_form" style="display:none;z-index:999;">
            <button type="button" id="close_form" style="float: right;font-weight: bold;font-size: 18px;color:red;"><i
                    class="fa fa-close"></i></button>
            <div style='width:100%;' id='browdata'>
            </div>
        </div>
        <!-- Default box -->
        <div>
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12  pad">
                <div class="panel panel-default">
                    <div class="panel-heading" style="height:40px">
                        <div class="col-lg-10 col-md-10 col-sm-10  col-xs-10">
                            <h3 class="panel-title" style="color:black"><a class="myPrint"><?php echo $formname; ?></a>
                            </h3>
                        </div>
                        <div class="col-lg-2 col-md-2 col-sm-2  col-xs-2">
                            <input type="date" value="<?= $zStartDate ?>" style="width: 1px;border: none"
                                   class="zstdate">
                            <input type="date" value="<?= $zEndDate ?>" style="width: 1px;border: none"
                                   class="zenddate">
                            <h4 class="panel-title" style="float:right"><b><?php echo $get['username'] ?></b></h4>
                        </div>

                    </div>
                    <div class="panel-body">
                        <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">Voucher</label>
                            </div>
                            <div class="col-lg-1 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form vouchno" name="vouchno"
                                       value="<?php echo ($addflag != 1) ? $get["vouchno"] : "$qvouch"; ?>" required
                                       readonly>
                                <input type="hidden" class="form-control form" name="cashvouch"
                                       value="<?php echo ($addflag != 1) ? $get["cashvouch"] : ""; ?>" readonly>
                                <input type="hidden" class="form-control form" name="bankvouch"
                                       value="<?php echo ($addflag != 1) ? $get["bankvouch"] : ""; ?>" readonly>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Date</label>
                            </div>
                            <div class="col-lg-2 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="date" class="form-control form  focusfield" name="vouchdt"
                                       value="<?php echo ($addflag != 1) ? $get["vouchdt"] : date("Y-m-d"); ?>"
                                       autofocus="autofocus">
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Invoice No.</label>
                            </div>
                            <div class="col-lg-1 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form" name="invno"
                                       value="<?php echo ($addflag != 1) ? $get["invno"] : "$qvouch"; ?>">
                            </div>

                            <div class="col-lg-1 col-md-1 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Out Of State</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="checkbox" class="form-control form oms" <?php
// if ($get['oms'] == "1") {
//     Echo "checked";
// }
                                ?> value="1" name="oms">
                            </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">Party</label>
                            </div>
                            <div class="col-lg-4 col-md-8 col-sm-8 col-xs-8 pad">
                                <select class="form-control form select2 party" name="party" style="width: 100%"
                                        required>
                                    <option value="<?php echo ($addflag != 1) ? $get["party"] : ""; ?>"><?php echo ($addflag != 1) ? $lparty["name"] : ""; ?></option> 
                                    <?php
                                    $gparty = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `grpcode`='010' ORDER BY `name`") or die(mysqli_error($conn));

                                    while ($fparty = mysqli_fetch_array($gparty)) {

                                        Echo "<option value='$fparty[accode]'>$fparty[name]</option>";
                                    }
                                    ?>
                                </select>
                                <input type="hidden" class="form-control form prodtype " name="prodtype" value="O"
                                       style="width: 100%" required>
                            </div>


                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-2 text-right pad">
                                <label class="label-control marg" style="color: #78909C">GST %</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-2 pad">
                                <select name="gstperc" class="form-control form gstperc ">
                                    <option value="<?php echo ($addflag != 1) ? $get["gstperc"] : ""; ?>">


                                        <?php echo ($addflag != 1) ? $get["gstperc"] : ""; ?>
                                    </option>
                                    <?php
                                    $getgst = mysqli_query($conn, "SELECT * FROM `saletype` where `code`!='' ORDER BY per") or die(mysqli_error($conn));
                                    while ($fetgst = mysqli_fetch_array($getgst)) {
                                        Echo "<option value='$fetgst[per]'>$fetgst[name]</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-4 text-right pad">
                                <label class="label-control marg">Work Order No.</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-8 pad">
                                <input type="text" class="form-control form ordno" name="ordno"
                                       value="<?= ($addflag != 1) ? $get['ordno'] : ''; ?>">
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-4 text-right pad">
                                <label class="label-control marg">Work Order Date</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-8 pad">
                                <input type="date" class="form-control form orddt" name="orddt"
                                       value="<?= ($addflag != 1) ? $get['orddt'] : date('Y-m-d'); ?>">
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-4 text-right pad">
                                <label class="label-control marg">Order By</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-8 pad">
                                <input type="text" class="form-control form orderby" name="orderby"
                                       value="<?= ($addflag != 1) ? $get['orderby'] : ''; ?>">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-4 text-right pad">
                                <label class="label-control marg">Our Challan No.</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-8 pad">
                                <input type="text" class="form-control form chalno" name="chalno"
                                       value="<?= ($addflag != 1) ? $get['chalno'] : ''; ?>">
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-4 text-right pad">
                                <label class="label-control marg">Date</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-8 pad">
                                <input type="date" class="form-control form chaldt" name="chaldt"
                                       value="<?= ($addflag != 1) ? $get['chaldt'] : date('Y-m-d'); ?>">
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-4 text-right pad">
                                <label class="label-control marg">Your Challan No.</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-8 pad">
                                <input type="text" class="form-control form gatepass" name="gatepass"
                                       value="<?= ($addflag != 1) ? $get['gatepass'] : ''; ?>">
                            </div>
                        </div>

                        <div class="table-responsive" style="overflow-y:scroll; height: 350px">
                            <table class="table-striped table-condensed table-bordered tab" width="100%">
                                <thead class="mySearchTr">
                                    <tr>
                                        <th width="1%"></th>
                                        <th width="3%" class='text-right'>Sr.</th>
                                        <th width="15%">Description</th>
                                        <th width="5%">Hsn Code</th>
                                        <th width="5%" class='text-right'>Qty.</th>
                                        <th width="5%" class='text-right'>Shift/Hrs.</th>
                                        <th width="5%" class='text-right'>Rate</th>
                                        <th width="9%" class='text-right'>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><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]'>
                                                      <input type='hidden' class='form-control form text-right purvouch' name='purvouch_$sctr' value='$fetquery[purvouch]'>
                                                      <input type='hidden' class='form-control form text-right pursrno' name='pursrno_$sctr' value='$fetquery[pursrno]'></td>";
                                            echo "<td>";
                                            echo "<input type='text' class='form-control form descrip' name='descrip_$ctr' value='$tran[descrip]' maxlength='50'>";
                                            echo "</td>";
                                            echo "<td><input type='text' class='form-control form hsncode'                name='hsncode_$ctr'       value='$tran[hsncode]'></td>";
                                            echo "<td><input type='text' class='form-control form text-right macqty'      name='macqty_$ctr'      value='$tran[macqty]'></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>
                                            <input type='hidden' class='form-control form text-right mspamount'   name='mspamount_$ctr'   value='$tran[mspamount]' readonly></td>";
                                            echo "</tr >";
                                            $ctr++;
                                        }
                                    } else {
                                        $pctr = 0;
                                        ?>
                                        <tr>
                                            <td><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 descrip"           name="descrip_0" name="descrip"  maxlength='50'></td>
                                            <td><input type="text" class="form-control form text-left hsncode" name="hsncode_0"      value=""></td>
                                            <td><input type="text" class="form-control form text-right macqty" name="macqty_0"         value="0"></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>
                                                <input type="hidden" class="form-control form text-right mspamount"   name="mspamount_0"      value="0" readonly></td>
                                        </tr>   
                                        <?php
                                        $pctr++;
                                    }
                                    ?>


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

                        <div class="col-lg-12 col-xs-12 pad">
                            <div class="col-lg-6 col-xs-12 pad">
                                <div class="col-lg-12 col-xs-12 pad">
                                    <button type="button" class="btn btn-primary btn-square form" id="addnew">
                                        <i class="fa fa-plus" data-toggle='tooltip' title='Add Row'></i>
                                    </button>
                                    <input type="hidden" id="items" name="items"
                                           value="<?php echo ($addflag != 1) ? $ctr : 1; ?>" />
                                </div>
                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-3 pad text-right">
                                        <label class="label-control marg">Remarks</label>
                                    </div>
                                    <div class="col-lg-9 pad">
                                        <input type="text" name="remark1" class="form-control form remark1"
                                               value="<?= ($addflag != 1) ? $get["remark1"] : ""; ?>">
                                    </div>
                                </div>
                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-3 pad text-right"></div>
                                    <div class="col-lg-9 pad">
                                        <input type="text" name="remark2" class="form-control form remark2"
                                               value="<?= ($addflag != 1) ? $get["remark2"] : ""; ?>">
                                    </div>
                                </div>

                            </div>

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

                                    </div>
                                    <div class="col-lg-3 pad"></div>
                                    <div class="col-lg-3 pad text-right">
                                        <label class="label-control marg">SubTotal</label>
                                    </div>
                                    <div class="col-lg-3 pad">
                                        <input type="text" class="form-control form subtotal text-right"
                                               value="<?= ($addflag != 1) ? $get['subtotal'] : "0"; ?>" name="subtotal"
                                               readonly>
                                        <input type="hidden" class="form-control form msptotal text-right"
                                               value="<?= ($addflag != 1) ? $get['msptotal'] : "0"; ?>" name="msptotal"
                                               readonly>
                                    </div>
                                </div>


                                <!--                                <div class="col-lg-12 col-md-12 col-xs-12 pad">
                                                                    <div class="col-lg-3 col-md-3 pad"></div>
                                                                    <div class="col-lg-3 col-md-3 text-right pad">
                                                                        <label class="label-control marg">Advance</label>
                                                                        <label class="label-control marg">Less Other</label>
                                                                    </div>
                                                                    <div class="col-lg-3 col-md-3 pad"></div>
                                                                    <div class="col-lg-3 col-md-3 pad">
                                                                        <input type="text" class="form-control form lesother text-right"
                                                                               value="<?= ($addflag != 1) ? $get['lesother'] : "0"; ?>" name="lesother">
                                                                    </div>
                                                                </div>-->

                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-3 pad">
                                        <!--<input type="button" name="gendsotp" class="form-control gendsotp form" style="color:red;border: none;" value="Generate Discount OTP">-->
                                    </div>
                                    <div class="col-lg-3 pad text-right">
                                        <label class="label-control marg">Advance</label>
                                    </div>
                                    <div class="col-lg-2 pad">
                                        <input type="text" class="form-control form  cdiscperc text-right"
                                               value="<?= ($addflag != 1) ? $get['cdiscperc'] : "0"; ?>"
                                               name="cdiscperc" >
                                    </div>
                                    <div class="col-lg-1 pad">
                                        <label class="label-control marg">%</label>
                                    </div>
                                    <div class="col-lg-3 pad">
                                        <input type="text" class="form-control form lesother text-right"
                                               value="<?= ($addflag != 1) ? $get['lesother'] : "0"; ?>" name="lesother"
                                               readonly>
                                    </div>
                                </div>

                                <div class="col-lg-12 col-md-12 col-xs-12 pad">
                                    <div class="col-lg-3 col-md-3 pad"></div>
                                    <div class="col-lg-3 col-md-3 text-right pad">
                                        <label class="label-control marg">Taxable Value</label>
                                        <!--<label class="label-control marg">Less Other</label>-->
                                    </div>
                                    <div class="col-lg-3 col-md-3 pad"></div>
                                    <div class="col-lg-3 col-md-3 pad">
                                        <input type="text" class="form-control form taxamt text-right"
                                               value="<?= ($addflag != 1) ? $get['tottaxamt'] : "0"; ?>" name="taxamt"
                                               readonly>
                                    </div>
                                </div>
                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-3 pad">
                                        <!--<input type="button" name="gendsotp" class="form-control gendsotp form" style="color:red;border: none;" value="Generate Discount OTP">-->
                                    </div>
                                    <div class="col-lg-3 pad text-right">
                                        <label class="label-control marg">Add CGST</label>
                                    </div>
                                    <div class="col-lg-2 pad">
                                        <input type="text" class="form-control form  cgstperc text-right"
                                               value="<?= ($addflag != 1) ? $get['cgstperc'] : "$gstperc"; ?>"
                                               name="cgstperc" readonly>
                                    </div>
                                    <div class="col-lg-1 pad">
                                        <label class="label-control marg">%</label>
                                    </div>
                                    <div class="col-lg-3 pad">
                                        <input type="text" class="form-control form cgstamt text-right"
                                               value="<?= ($addflag != 1) ? $get['totcgst'] : "0"; ?>" name="totcgst"
                                               readonly>
                                    </div>
                                </div>
                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-3 pad">
                                        <!--<input type="button" name="gendsotp" class="form-control gendsotp form" style="color:red;border: none;" value="Generate Discount OTP">-->
                                    </div>
                                    <div class="col-lg-3 pad text-right">
                                        <label class="label-control marg">Add SGST</label>
                                    </div>
                                    <div class="col-lg-2 pad">
                                        <input type="text" class="form-control form sgstperc text-right"
                                               value="<?= ($addflag != 1) ? $get['sgstperc'] : "$gstperc"; ?>"
                                               name="sgstperc" readonly>
                                    </div>
                                    <div class="col-lg-1 pad">
                                        <label class="label-control marg">%</label>
                                    </div>
                                    <div class="col-lg-3 pad">
                                        <input type="text" class="form-control form sgstamt text-right"
                                               value="<?= ($addflag != 1) ? $get['totsgst'] : "0"; ?>" name="totsgst"
                                               readonly>
                                    </div>
                                </div>
                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-3 pad">
                                        <!--<input type="button" name="gendsotp" class="form-control gendsotp form" style="color:red;border: none;" value="Generate Discount OTP">-->
                                    </div>
                                    <div class="col-lg-3 pad text-right">
                                        <label class="label-control marg">Add IGST</label>
                                    </div>
                                    <div class="col-lg-2 pad">
                                        <input type="text" class="form-control form igstperc text-right"
                                               value="<?= ($addflag != 1) ? $get['igstperc'] : "$gstperc"; ?>"
                                               name="igstperc" readonly>
                                    </div>
                                    <div class="col-lg-1 pad">
                                        <label class="label-control marg">%</label>
                                    </div>
                                    <div class="col-lg-3 pad">
                                        <input type="text" class="form-control form igstamt text-right"
                                               value="<?= ($addflag != 1) ? $get['totigst'] : "0"; ?>" name="totigst"
                                               readonly>
                                    </div>
                                </div>
                                <div class="col-lg-12 col-md-12 col-xs-12 pad">
                                    <div class="col-lg-3 col-md-3 pad"></div>
                                    <div class="col-lg-3 col-md-3 text-right pad">
                                        <!--<label class="label-control marg">Less Other</label>-->
                                    </div>
                                    <div class="col-lg-3 col-md-3 pad text-right">
                                        <label class="label-control marg">Total Amount</label>

                                    </div>
                                    <div class="col-lg-3 col-md-3 pad">
                                        <input type="text" class="form-control form totalamount text-right"
                                               value="<?= ($addflag != 1) ? $get['totalamount'] : "0"; ?>"
                                               name="totalamount" readonly>
                                    </div>
                                </div>
                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-3 pad"></div>
                                    <div class="col-lg-3 pad"></div>
                                    <div class="col-lg-3 pad text-right">
                                        <label class="label-control marg">Round Off</label>
                                    </div>
                                    <div class="col-lg-3 pad">
                                        <input type="text" class="form-control form roundoff text-right "
                                               value="<?= ($addflag != 1) ? $get['roundoff'] : "0"; ?>" name="roundoff">
                                    </div>
                                </div>

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

                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">

                    <div class="col-lg-1 pad"></div>

                    <div class="col-lg-1 pad">
                        <a href="salegst_fin_pdf.php?vouchno=<?= $qvouch; ?>" class="partypdf-btn" target="_blank">
                            PDF <i class="fa fa-file-pdf-o"></i>
                        </a>
                    </div>
                    <div class="col-lg-1 pad">
                        <a href="salegst_fin_pdf.php?vouchno=<?= $qvouch; ?>&proforma=1" class="partypdf-prof" target="_blank">
                            PROFORMA
                        </a>
                    </div>

                </div>
                <div class="col-lg-1 pad"></div>
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 pad">
                    <div class="panel panel-default">
                        <div class="panel-body">


                            <div class="col-lg-12 col-md-10 col-sm-10 col-xs-10 text-center pad">
                                <?php include("includes/buttons.php"); ?>
                            </div>



                        </div>

                        <script>
                            $(document).ready(function () {

                                var usertype = <?= $usertype ?>;
                                if (usertype == 3) {
                                    $("#hedit").hide();
                                }
                            });
                        </script>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade" id="imageUpload" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="col-lg-11">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">LR Upload</h4>
                        </div>
                        <div class="modal-body">
                            <div class="row">
                                <div class="col-lg-12 upload">
                                    <form id="upload_form" enctype="multipart/form-data" method="post">

                                        <div class="col-lg-3 pad">
                                            <span class="btn btn-default btn-file btn-square btn-warning">
                                                Choose File <input type="file" name="file1" id="file1">
                                            </span>
                                            <input type="hidden" name="code" id="vouchno" value='<?php echo ($addflag != 1) ? $get['vouchno'] : "$qvouch"; ?>'>
                                            <input type="button" value="Upload File" id="uploadbtn" class="btn btn-square" style="background-color: #C0CA33; color: white">
                                            <?php if ($get['imgpath']) { ?>
                                                <input type="button" value="Delete File" id="dellrbtn" class="btn btn-square" style="background-color: red; color: white">
                                            <?php } ?>
                                        </div>
                                        <div class="col-lg-6">
                                            <div class="progress">
                                                <progress id="progressBar" class="progress-bar" role="progressbar" value="0" max="100" style="width:100%;color: red;"></progress>
                                            </div>
                                            <h3 id="status"></h3>
                                            <p id="loaded_n_total"></p>
                                        </div>
                                    </form>
                                </div>
                                <div class="col-lg-10 upload">
                                    <img id="preview" src="<?= $get['imgpath'] ?>?a=2" alt="your image"  style="width:100%"/>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>

    <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;" required>
                        </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;" required>
                        </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%;" required>

                                <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 required>
                        </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;" required>
                        </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" id="cancmodel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">
        <div class="modal-dialog">
            <div class="col-lg-11">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel">Cancel Bill</h4>
                    </div>
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-lg-12 upload">
                                <form id="upload_form" method="post">

                                    <div class="row pad">
                                        <input type="hidden" name="cancvouch" id="cancvouch"
                                               value='<?php echo ($addflag != 1) ? $get['vouchno'] : "$qvouch"; ?>'>
                                        <input type="hidden" name="cashvouch2" id="cashvouch2"
                                               value='<?php echo ($addflag != 1) ? $get['cashvouch'] : ""; ?>'>
                                        <div class="col-lg-4 col-md-4 col-sm-4 col-xs-5 text-right">
                                            <label class="label-control marg">Cancel Date</label>
                                        </div>
                                        <div class="col-lg-4 col-md-4 col-sm-6 col-xs-7">

                                            <input type="date" name="cancdate"
                                                   value="<?php echo ($addflag != 1) ? $get['cancdate'] : ""; ?>"
                                                   class="form-control cancdate">
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-lg-6 col-md-6 col-sm-7 col-xs-8 text-right">
                                            <input type="submit" value="Cancel" name="cancbtn" class="btn btn-square"
                                                   style="background-color: #C0CA33; color: white">
                                        </div>
                                    </div>

                                </form>
                            </div>

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

    <div class="modal fade itemModal" 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">
                    <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="<?php echo $para ?>" class="form-control para">-->
                    <div class="row">
                        <div class="col-lg-3">
                            <select class="form-control ifield">
                                <option value="1">Name</option>
                                <option value="2">Barcode</option>
                                <option value="3">Itemcode</option>
                                <!--                            <option value="4">Gram</option>
                                                            <option value="5">Unit</option>-->
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control ioperator">
                                <option value=""></option>
                                <option value="%">Like</option>
                                <option value="=">Exactly</option>
                            </select>
                        </div>
                        <div class="col-lg-4">
                            <input type="text" value="" class="form-control isearch">
                        </div>
                        <div class="col-lg-3">
                            <input type="button" class="btn btn-primary iload" value="Search">
                        </div>
                    </div>

                    <div class="col-lg-12 iloader text-center">
                        <img src="images/search.gif" alt="loading">
                    </div>
                    <div class="col-lg-12 inoRecord 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="15%">Itemcode</th>
                                    <th width="49%">Name</th>
                                    <th width="8%">Stock</th>
                                    <!--                                <th width="17%">Barcode</th>
                                    <th width="8%">Gram</th>
                                    <th width="8%">Unit</th>-->
                                    <th width="8%">Rate</th>
                                </tr>
                            </thead>
                            <tbody class="iTbody">
                            </tbody>
                        </table>
                    </div>
                    <div class="row">
                        <div class="col-xs-12 text-right search-action-bar">
                            <input type="button" class="btn btn-primary iprevious" value="Previous">
                            <input type="button" class="btn btn-primary inext" value="Next">
                        </div>
                    </div>
                </div>
                <div class="modal-footer"></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"> Party Name</option>
                                <option value="4">Voucher</option>
                                <option value="2">Invoice No.</option>
                                <option value="3">Date</option>
                                <!--<option value="5">Mobile</option>-->
                                <option value="6">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="4"> Party Name</option>
                                <option value="1">Voucher</option>
                                <option value="2">Invoice No.</option>
                                <option value="3">Date</option>
                                <!--<option value="5">Mobile</option>-->
                                <option value="6">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%">Party Name</th>
                                    <!--<th width="10%">Mobile</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>
    <?php include("includes/linksfoot.php"); ?>
</body>

</html>