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

$maindb = 'salemain';
$trandb = 'saletran';
$accdb = 'actran';
$stkdb = 'transacn';
$printfile = "sale_print.php";
$file = 'sale.php';
$trandbexist = 1;
$source = "SL";

$keycond = '';
$keyfld = "vouchno";
$myyear = $_SESSION["tit_" . $dbname];

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

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

//browse($username);
$formname = 'Sale';

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

    $vouchdt = trim($_POST["vouchdt"]);
    $voucher = trim($_POST["voucher"]);

    $qvouch = $_POST["vouchno"];

    $mono = $_POST["monno"];
    $invno = $_POST["invno"];
    $godown = $_POST["godown"];
    $addgst = $_POST["addgst"];
    $addpack = $_POST["addpack"];
    //    $debitac = $_POST["debitac"];
    $paidby = trim($_POST["paidby"]);
    $party = trim($_POST["party"]);
    $taxableamt = trim($_POST["taxableamt"]);
    $totbillamt = trim($_POST["totbillamt"]);
    $grossamt = trim($_POST["grossamt"]);
    $gstno = trim($_POST["gstno"]);
    $totdisc = trim($_POST["totdisc"]);
    $totvat = trim($_POST["totvat"]);
    $totalqty = trim($_POST["totalqty"]);
    $packby = trim($_POST["packby"]);
    $mobile = trim($_POST["mobile"]);
    $rem1 = trim($_POST["remark1"]);
    $rem2 = trim($_POST["remark2"]);
    $tvatperc = trim($_POST["tvatperc"]);
    $ldiscperc = trim($_POST["ldiscperc"]);

    $nocart = $_POST["nocart"];
    $lrno = $_POST["lrno"];
    $lrdate = $_POST["lrdate"];
    $transporter = $_POST["transporter"];
    $area = $_POST["area"];

    $totadv = $_POST["totadv"];
    $totbal = $_POST["totbal"];

    date_default_timezone_set("Asia/Dubai");
    $usertime = date("Y-m-d H:i:sa");

    //    $taxableamt = $grossamt - $totdiscamt + $postamt;
//    $totbillamt1 = $taxableamt + $totgst5 + $totgst12 + $totgst18 + $totgst28 + $tcsamt;
//    $gstamount = $pretcs - $taxableamt;
//
//    $totbillamt = round($totbillamt1);
//    if ($totgst1 > 0) {
//        $oms = 1;
//    } else {
    $oms = $_POST['oms'];
    //    }

    $count = $_POST["items"];
    $mvouch = $qvouch;

    if ($paidby == "R") {
        $purcode = '15';
    } else {
        $purcode = '14';
    }

    $accode = $party;
    $grpcode = '010';

    if ($vouchdt == '0000-00-00') {
        browse("Voucher Date Cannot Be Empty");
        $a = 0;
    }

    if ($accode == "") {
        browse("Party Cannot Be Empty");
        $a = 0;
    }

    if ($a == 1) {
        mysqli_query($conn, "LOCK TABLES `$maindb` WRITE, `$trandb` WRITE, `product` WRITE, `$stkdb` WRITE, `$accdb` WRITE, `cashrecp` WRITE, `accmast` WRITE ");

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

            $time = strtotime($vouchdt);
            $month = date("m", $time);
            $intmonth = intval($month);
            if ($intmonth < 10) {
                $intmonth = '0' . $intmonth;
            }
            $voucher = $intmonth . $mvouch;
        }

        //**************************************************        auto cash Entry Start  ***************************************
        $mcashvouch = $_POST["cashvouch"];

        if ($paidby == 'C' || $totadv > 0) {
            if ($mcashvouch == '0' || $mcashvouch == '') {
                $gen1 = mysqli_query($conn, "SELECT MAX(vouchno+0) AS maxcode FROM `cashrecp` where vouchno!=''  LIMIT 0,1 ") or die(mysqli_error($conn));
                if (mysqli_num_rows($gen1) > 0) {
                    $vvouch = mysqli_fetch_assoc($gen1);
                    $tcashvouch = $vvouch["maxcode"] + 1;
                } else {
                    $tcashvouch = '1';
                }
                $mcashvouch = $tcashvouch;
            }

            $genrecp = mysqli_query($conn, "SELECT * FROM `cashrecp` where `vouchno` = '$mcashvouch' ") or die(mysqli_error($conn));
            if (mysqli_num_rows($genrecp) > 0) {
                $fetrecp = mysqli_fetch_array($genrecp);
                $mrecpno = $fetrecp['recpno'];
                $mcashvouch = $fetrecp['vouchno'];
            } else {
                $gen2 = mysqli_query($conn, "SELECT MAX(recpno+0) AS maxcode FROM `cashrecp` where bankname = '3' LIMIT 0,1 ") or die(mysqli_error($conn));
                if (mysqli_num_rows($gen2) > 0) {
                    $gvouch = mysqli_fetch_assoc($gen2);
                    $mrecpno1 = $gvouch["maxcode"] + 1;
                } else {
                    $mrecpno1 = '1';
                }
                $mrecpno = $mrecpno1;
            }
            if ($totadv > 0) {
                $recpamt = $totadv;
            } else {
                $recpamt = $totbillamt;
            }

            mysqli_query($conn, "DELETE FROM `cashrecp` WHERE `$keyfld`='$mcashvouch' ") or die(mysqli_error($conn));

            mysqli_query($conn, "INSERT INTO `cashrecp`( vouchno ,`vouchdt`, `bankname`, `bankinit`, `recpno`, `party`,`amount`,`remark1`,`remark2`,`trnflag`)
                                       Values ('$mcashvouch', '$vouchdt', '3', 'COH', '$mrecpno','$accode','$recpamt','Cash Recd. For','Sale No.$mvouch','S')") or die(mysqli_error($conn));

            // cash part  

            $minus_amt = ($recpamt * -1);

            mysqli_query($conn, "DELETE FROM `$accdb` WHERE `$keyfld`='$mcashvouch' and `source` = 'CR' $keycond") or die(mysqli_error($conn));

            mysqli_query($conn, "INSERT INTO `$accdb`(date,godown, vouchno, recpno, source, trnno, bankinit, accode, grpcode, amount, trnflag, monno)
                    VALUES ('$vouchdt','$godown','$mcashvouch', '$mrecpno', 'CR', '001', 'COH', '3','002', '$minus_amt','S','$mono')") or die(mysqli_error($conn));

            // party part
            mysqli_query($conn, "INSERT INTO `$accdb`(date, godown, vouchno, recpno, source, trnno, bankinit, accode, grpcode, amount, trnflag, monno)
                    VALUES ('$vouchdt','$godown','$mcashvouch', '$mrecpno', 'CR', '002', 'COH', '$accode', '010', '$recpamt','S','$mono')") or die(mysqli_error($conn));
        } else {
            mysqli_query($conn, "DELETE FROM `cashrecp` WHERE `$keyfld`='$mcashvouch' $keycond") or die(mysqli_error($conn));
            mysqli_query($conn, "DELETE FROM `actran` WHERE `$keyfld`='$mcashvouch' AND `source`='CR' $keycond") or die(mysqli_error($conn));
            $mcashvouch = "";
        }


        //**************************************************        auto cash Entry End    *************************************** 

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

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

        $cnt = 0;
        $cntamt = 0;

        for ($i = 0; $i < $count; $i++) {
            $msrno = $_POST["srno_$i"];
            $barcode = $_POST["barcode_$i"];
            $mitem = mysqli_real_escape_string($conn, $_POST["itemname_$i"]);
            $cartqty = $_POST["cartqty_$i"];
            $qty = $_POST["qty_$i"];
            $totqty = $_POST["totqty_$i"];
            $rate = $_POST["cost_$i"];
            $amt = $_POST["amount_$i"];
            $discperc = $_POST["discperc_$i"];
            $discamt = $_POST["discamt_$i"];
            $vatperc = $_POST["vatperc_$i"];
            $vat = $_POST["vat_$i"];
            $total = $_POST["total_$i"];
            $subtot = $_POST["subtot_$i"];
            $stk = $_POST["stk_$i"];

            $gstperc = $cgstrate + $sgstrate + $igstrate;

            $mitemcode = mysqli_query($conn, "SELECT code,cost FROM `product` WHERE `code`='$mitem'") or die(mysqli_error($conn));

            $icode = mysqli_fetch_array($mitemcode);
            $itcode = $icode['code'];

            $cost = $icode['cost'];
            $group = $source . $mvouch;

            if (!empty($mitem)) {
                $cnt++;
                $tcartqty = $cartqty * -1;
                $tqty = $qty * -1;
                $ttotqty = $totqty * -1;

                mysqli_query($conn, "INSERT INTO `$trandb`(vouchno, vouchdt, srno, itemcode, itemname, cartqty, qty, totqty, cost, amount, `discperc`, `discamt`, 
                                                          `total`,`barcode`,`subtot`,vatperc, vat,rate,stk)
                                                  VALUES('$mvouch', '$vouchdt', '$cnt', '$itcode', '$mitem', '$cartqty', '$qty', '$totqty', '$cost', '$amt',
                                   '$discperc', '$discamt', '$total','$barcode','$subtot','$vatperc', '$vat','$rate','$stk')") or die(mysqli_error($conn));

                mysqli_query($conn, "INSERT INTO `$stkdb`(`srno`, `yearno`, `vouchno`, `vouchdt`, `itemcode`,  `cartqty`,rate,barcode,godown,
                                                  `qty`, `source`, amount, accode, `group` , `totqty`, `cost`, `itemgrp`, `ordno`, `monno`)
                            VALUES('$cnt', '$myyear', '$mvouch', '$vouchdt', '$itcode',  '$tcartqty','$rate','$barcode','$godown',
                                   '$tqty', '$source', '$amt', '$party', '$group', '$ttotqty', '$cost', '$itemgrp', '1', '$mono')") or die(mysqli_error($conn));
            }
        }
        //        browse(1);
############################### Accounts Part ######################################################
//        IF ($chkledg == 1) {

        mysqli_query($conn, "DELETE FROM `$accdb` WHERE `vouchno` = '$mvouch' AND `source` = '$source' ") OR die(mysqli_error($conn));
        if ($totbillamt > 0) {
            $minus_amt = ($totbillamt * -1);
            $saleamt = $totbillamt - $addgst;

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

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

            if ($addgst > 0) {
                //            gt part    - gst
                mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,`godown`, source, trnno, accode, grpcode, amount, monno)
                            VALUES ('$vouchdt','$mvouch','$godown', '$source', '003', '8','020', '$addgst','$mono')") or die(mysqli_error($conn));
            }
        }

        if ($addflag == 1) {
            $newvoucher = $mono . $mvouch;

            mysqli_query($conn, "INSERT INTO `$maindb`(vouchno, `vouchdt`, `voucher`, `invno`, `mono`, `party`, `paidby`, `debitac`, 
                                              `rem1`, `rem2`, `cashvouch`, `totdisc`,`grossamt`, totvat, packby, mobile, ldiscperc, 
                                               `tvatperc`, nocart, `lrno`, `lrdate`, `transporter`, `area`,  `totalqty`,`godown`,`addpack`,`addgst`,
                                               `purcode`,`billamt`,username, usertime, `totadv`, `totbal`)
                                      VALUES('$mvouch', '$vouchdt', '$newvoucher', '$mvouch', '$mono', '$party', '$paidby', '$purcode',
                                             '$rem1', '$rem2', '$mcashvouch', '$totdisc','$grossamt', '$totvat','$packby','$mobile','$ldiscperc',
                                             '$tvatperc', '$nocart', '$lrno', '$lrdate', '$transporter', '$area', '$totalqty','$godown','$addpack','$addgst',
                                             '$purcode','$totbillamt','$username', '$usertime', '$totadv', '$totbal')") or die(mysqli_error($conn));

            //            $_SESSION['print_voucher'] = $mvouch;
        } else {

            mysqli_query($conn, "UPDATE `$maindb` SET  `vouchdt`='$vouchdt',  `mono`='$mono', `party`='$party', `paidby`='$paidby', 
                                         packby='$packby', `rem1`='$rem1', `rem2`='$rem2', `totdisc`='$totdisc',`grossamt`='$grossamt', 
                                         `debitac`='$purcode',`purcode`='$purcode', mobile='$mobile',`cashvouch`='$mcashvouch',totvat='$totvat',`godown`='$godown', 
                                         `billamt`='$totbillamt', ldiscperc='$ldiscperc',nocart='$nocart', lrno = '$lrno', lrdate = '$lrdate', transporter = '$transporter', 
                                          area = '$area', tvatperc='$tvatperc', `totadv`='$totadv', `totbal`='$totbal',  `username`='$username',`addpack`='$addpack',`addgst`='$addgst', 
                                         `totalqty`='$totalqty', `usertime`='$usertime'  WHERE `vouchno` = '$mvouch' ") or die(mysqli_error($conn));
        }

        //        if (!empty($mobile)) {
//            mysqli_query($conn, "UPDATE `accmast` SET  `mobile`='$mobile'   WHERE `accode` = '$party' ") or die(mysqli_error($conn));
//        }

        mysqli_query($conn, "UNLOCK TABLES");
        if ($addflag == 1) {
            insmess();
            header("refresh: 1; $file?mode=edit&$keyfld=$mvouch&form=$form");
        } else {
            updmess();
            header("refresh: 1; $file?mode=edit&$keyfld=$mvouch&form=$form");
        }
    }
}

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, `$stkdb` WRITE, `$accdb` WRITE, `cashrecp` 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-btn i {
        font-size: 20px;
        color: #FF3B30;

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

    <style>

    @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-1 col-sm-1 col-xs-1 pad">
                                <input type="text" name="vouchno" class="form-control form vouchno" id="vouchno" value="<?php echo ($addflag != 1) ? $get['vouchno'] : $qvouch ?>">
                                <input type="hidden" name="voucher" class="form-control form voucher" value="<?php echo ($addflag != 1) ? $get['voucher'] : '' ?>" tabindex="-1" readonly required>
                                <input type="hidden" name="monno" class="form-control form monno" value="<?php echo ($addflag != 1) ? $get['monno'] : '' ?>">
                                <input type="hidden" class="form-control addflag" value="<?php echo $addflag ?>">
                                <input type="hidden" name="source" class="form-control form source" value="<?= $source; ?>" id="source">
                                <input type="hidden" class="form-control form" name="cashvouch" value="<?php echo ($addflag != 1) ? $get[" cashvouch "] : " "; ?>">
                                <input type="hidden" class="form-control form canc_flag" name="" value="<?php echo ($addflag != 1) ? $get[" canc_flag "] : " "; ?>">
                                <input type="hidden" class="form-control form edpara" name="" value="<?php echo ($addflag != 1) ? $edpara : " "; ?>"> </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-1 col-md-1 col-sm-1 col-xs-8 pad">
                                <input type="date" class="form-control form vouchdt focusfield" name="vouchdt" value="<?php echo ($addflag != 1) ? $get[" vouchdt "] : date("Y-m-d "); ?>" autofocus required> </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Invoice</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="text" name="invno" class="form-control form invno" value="<?php echo ($addflag != 1) ? $get['invno'] : " $qvouch "; ?>" readonly> </div>
                            <div class="col-lg-1 pad text-right">
                                <label class="label-control marg">Party</label>
                            </div>
                            <div class="col-lg-3 pad">
                                <div class="party-flex">
                                    <select class="form-control form cmbparty party select2" id="party" name="party" style="width: 100%">
                                        <option value="<?php echo ($addflag != 1) ? $lparty[" accode "] : " "; ?>">
                                            <?php echo ($addflag != 1) ? $lparty["name"] : ""; ?>
                                        </option>
                                        <?php // do not remove this condition.Talk to Fairoz Sir first. // if ($addflag == 1) { $gparty = mysqli_query($conn, "SELECT accode,name FROM accmast WHERE grpcode='010' order by name") or die(mysqli_error($conn)); 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 pad text-right">
                                <label class="label-control marg">Paid By</label>
                            </div>
                            <div class="col-lg-1 pad">
                                <select id="paidby" name="paidby" class="form-control form select2 paidby">
                                    <option value="C" <?= ( $get['paidby'] == 'C' ) ? 'selected' : '' ?>>Cash</option>
                                    <option value="R" <?= ( $get['paidby'] == 'R' ) ? 'selected' : '' ?>>Credit</option>
                                </select>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Godown</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad ">
                                <select name="godown" class="form-control form select2 godown">
                                    <option value="<?php echo ($addflag != 1) ? $getgd['code'] : " "; ?>">
                                        <?php echo ($addflag != 1) ? $getgd['gcode'] : ""; ?>
                                    </option>
                                    <?php $mown = mysqli_query($conn, "SELECT * FROM godown") or die(mysqli_error($conn));
                                    while ($trow = mysqli_fetch_array($mown)) { // browse($trow[code]); echo "<option value='$trow[code]'>$trow[gcode]</option>"; }  ?>
                                    </select>
                                </div>
                                <div class="col-lg-1 pad text-right">
                                    <label class="label-control marg">No. Cartons</label>
                                </div>
                                <div class="col-lg-1 pad">
                                    <input type="text" class="form-control form nocart" name="nocart" value="<?php echo ($addflag != 1) ? $get[" nocart "] : " "; ?>"> </div>
                                <div class="col-lg-1 pad text-right">
                                    <label class="label-control marg">Transporter</label>
                                </div>
                                <div class="col-lg-3 col-md-4 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="<?php echo ($addflag != 1) ? $ltrans[" code "] : " "; ?>">
                                            <?php echo ($addflag != 1) ? $ltrans["name"] : ""; ?>
                                            </option>
    <?php $gtrans = mysqli_query($conn, "SELECT code,name FROM transport order by name") or die(mysqli_error($conn));
    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 class='col-lg-1 col-md-1 col-sm-1 col-xs-1'> </div>-->
                                <!-- <div class='col-lg-1 col-md-1 col-sm-1 col-xs-1'> <button type='button' class='btn btn-primary lrtab form btn-square' style="color: white"> LR. Detail </button> </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">LR 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 lrno" name="lrno" value="<?php echo ($addflag != 1) ? $get[" lrno "] : " "; ?>"> </div>
                                <!-- <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad"> &nbsp; </div>-->
                                <div class="col-lg-1 col-md-1 col-sm-3 col-xs-3 text-right pad">
                                    <label class="label-control marg">LR Date</label>
                                </div>
                                <div class="col-lg-1 col-md-2 col-sm-1 col-xs-1 pad">
                                    <input type="date" class="form-control form lrdate" name="lrdate" value="<?php echo ($addflag != 1) ? $get[" lrdate "] : " "; ?>"> </div>
                                <div class="col-lg-1 pad text-right">
                                    <label class="label-control marg">Area</label>
                                </div>
                                <div class="col-lg-2 pad">
                                    <input type="text" name="area" class="form-control form area" value="<?php echo ($addflag != 1) ? $get['area'] : ''; ?>" tabindex=""> </div>
                                <div class="col-lg-1">
                                    <button type='button' class='btn btn-primary form showUploader btn-square' style="color: white"> LR Image Upload </button>
                                </div>
                                <!-- <div class="col-lg-1"> <button type='button' class='btn btn-primary btn-square' onclick="window.open('lrprint.php?vouchno=<?= $get['vouchno'] ?>')" target="_blank" style="color: white"> LR Print </button> </div>-->
    <?php if ($get['imgpath'] != '') { ?>
                                    <div class="col-lg-1"> <a id='print' class="btn btn-pad btn-square" style="background-color:#5BC0DE;" href="<?= $get['imgpath']; ?>" target="_blank"> View Image </a> </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 style="width: 3%"></th>
                                            <th style="width: 5%">Sr.</th>
                                            <!-- <th style='width: 6%'>Code</th> -->
                                            <th style="width: 25%;">Item Name</th>
                                            <!--<th style='width: 5%' class="text-right">Qty. in Ctn.</th>-->
                                            <th style='width: 10%' class="text-right">Stk.</th>
                                            <th style='width: 10%' class="text-right">Qty.</th>
                                            <!--<th style='width: 5%' class="text-right">Total Qty.</th>-->
                                            <th style='width: 10%' class="text-right">Rate</th>
                                            <th style='width: 15%' class="text-right">Amount</th>
                                            <!--                                        <th style='width: 4%' class="text-right">Disc. %</th>
                                            <th style='width: 8%' class="text-right">Discount</th>
                                            <th style='width: 4%' class="text-right">VAT. %</th>
                                            <th style='width: 8%' class="text-right">VAT</th>
                                            <th style='width: 10%' class="text-right">Total</th>-->
                                        </tr>
                                    </thead>
                                    <tbody class="tbody">
                                        <?php
                                        if ($addflag != 1) {
                                            $qry = mysqli_query($conn, "SELECT t.*,p.code,p.name FROM `$trandb` t LEFT JOIN product p ON t.itemcode = p.code 
                                                                     WHERE t.vouchno='$getvouch' ORDER BY t.srno") or die(mysqli_error($conn));
                                            $ctr = 0;
                                            while ($row = mysqli_fetch_array($qry)) {
                                                // $getitem = mysqli_query($conn, "SELECT code, name FROM `product` WHERE code = '$row[itemcode]'") or die(mysqli_error($conn));
                                                // $geti = mysqli_fetch_array($getitem);

                                                echo "<tr>";
                                                echo "<td><i class='fa fa-close remove' style='display:none;'></i></td>";
                                                echo "<td><input type='text' name='srno_$ctr' class='srno form-control  form'  value='$row[srno]' readonly></td>";
                                                // echo "<td><input type='text' name='barcode_$ctr' class='barcode form-control  form' value='$row[barcode]' ></td>";
                                                echo "<td>";
                                                echo "<select class='form-control form itemname select2' name='itemname_$ctr' style='width:100%' required>";
                                                echo "<option value='$row[code]'>$row[name]</option>";
                                                $gitem = mysqli_query($conn, "SELECT `code`,`name` FROM `product`  order by name") or die(mysqli_error($conn));
                                                while ($item = mysqli_fetch_array($gitem)) {
                                                    echo "<option value='$item[code]'>$item[name]</option>";
                                                }
                                                echo "</select>";
                                                echo "</td>";
                                                //                                            Echo "<td><input type='number' name='cartqty_$ctr' class='cartqty form-control text-right  form' value='$row[cartqty]' ></td>";
                                                echo "<td><input type='text' step='any' name='stk_$ctr' class='stk form-control  text-right form' value='$row[stk]' tabindex='-1' style='background-color:lightgrey;color:blue'></td>";
                                                echo "<td class='p1'><input type='text' step='any' name='qty_$ctr' id='qty_$ctr' class='qty form-control  text-right form' value='$row[qty]'></td>";
                                                //                                            Echo "<td><input type='number' step='any' name='totqty_$ctr' class='totqty form-control text-right  form' value='$row[totqty]' readonly tabindex='-1'></td>";
                                                echo "<td class='p2'><input type='text' step='any' name='cost_$ctr' id='rate_$ctr' class='cost rate  form-control text-right  form' value='$row[rate]' ></td>";
                                                echo "<td><input type='number' step='any' name='amount_$ctr' id='amount_$ctr' class='amount form-control text-right  form'  value='$row[amount]' tabindex='-1' readonly></td>";
                                                //                                            Echo "<td><input type='text' name='discperc_$ctr' class='discperc form-control text-right  form' value='$row[discperc]' ></td>";
//                                            Echo "<td><input type='text' name='discamt_$ctr' class='discamt form-control text-right  form' value='$row[discamt]' ></td>";
//                                            Echo "<td><input type='text' name='vatperc_$ctr' class='vatperc form-control text-right  form' value='$row[vatperc]'></td>";
//                                            Echo "<td><input type='text' name='vat_$ctr' class='vat form-control text-right  form' tabindex='-1' value='$row[vat]'readonly></td>";
//                                            Echo "<td><input type='text' name='total_$ctr' class='total form-control text-right  form' tabindex='-1' value='$row[total]' readonly></td>";
                                                echo "</tr>";
                                                $ctr++;
                                            }
                                        } else {
                                            ?>
                                            <tr>
                                                <td><i class='fa fa-close remove'></i></td>
                                                <td><input type='text' name='srno_0' class='srno form-control form' value='1' readonly></td>
                                                <!-- <td><input type='text' name='barcode_0' class='barcode form-control form' value='' required></td> -->


                                                <td>
                                                    <select class="form-control form itemname select2" id="itemname" name="itemname_0"  style='width:100%'>
                                                        <option value=""></option>
                                                        <?php
                                                        $gitem = mysqli_query($conn, "SELECT * FROM `product` order by name") or die(mysqli_error($conn));
                                                        while ($item = mysqli_fetch_array($gitem)) {
                                                            echo "<option value='$item[code]'>$item[name]</option>";
                                                        }
                                                        ?>
                                                    </select>
                                                    <!-- <input type='text' name='itemname_0' class='itemname form-control form' value='' required readonly> -->
                                                </td>
                                                <td><input type='text' step='any' name='stk_0'
                                                           class='stk form-control  text-right form' value='0' tabindex='-1'
                                                           style='background-color:lightgrey;color:blue'></td>
                                                <td class='p1'><input type="text" step="any" name='qty_0'
                                                                      class='qty form-control text-right form zero' value='0'></td>
                                                              <!--<td><input type="number" step="any" name='totqty_0' class='totqty form-control text-right form zero' tabindex='-1' value='0' readonly></td>-->
                                                <td class='p2'><input type="text" step="any" name='cost_0'
                                                                      class='cost rate form-control text-right form zero' value='0'></td>
                                                <td><input type="number" step="any" name='amount_0' id="amount_0"
                                                           class='amount text-right form-control form zero' value='0' tabindex='-1'
                                                           readonly></td>
                                                   <!--                                            <td><input type='text' name='discperc_0' class='discperc text-right form-control form '  value='0.00' ></td> 
                                                   <td><input type='text' name='discamt_0' class='discamt text-right form-control form  ' value='0.00' ></td> 
                                                   <td><input type='text' name='vatperc_0' class='vatperc text-right form-control form  ' value='0.00' ></td> 
                                                   <td><input type='text' name='vat_0' class='vat text-right form-control form  ' tabindex='-1' value='0.00' readonly> </td> 
                                                   <td><input type='text' name='total_0' class='total text-right form-control form  ' tabindex='-1' value='0.00' readonly></td> -->
                                            </tr>
        <?php
    }
    ?>
                                    </tbody>
                                </table>
                            </div>
                            <div class="col-lg-12 pad">
                                <button type="button" class="btn btn-primary btn-square form" id="addnew">
                                    <i class="fa fa-plus" data-toggle='tooltip' title='Add Row'></i>
                                </button>
                                <input type="hidden" id="items" name="items"
                                       value="<?php echo ($addflag != 1) ? $ctr : 1; ?>">
                                   <!--<input type="hidden" class="mandatoryId" name="manId" value="">-->
                            </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">
                                        <div class="col-lg-3 pad text-right">
                                            <label class="label-control marg">Packed By</label>
                                        </div>
                                        <div class="col-lg-4 pad">
                                            <input type="text" name="packby" class="form-control form packby"
                                                   value="<? echo ($addflag != 1) ? $get["packby"] : ""; ?>" tabindex="-1">
                                        </div>
                                    </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 "
                                                   value="<? echo ($addflag != 1) ? $get["rem1"] : ""; ?>">
                                        </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 "
                                                   value="<? echo ($addflag != 1) ? $get["rem2"] : ""; ?>">
                                        </div>
                                    </div>
                                    <div class="col-lg-12 col-xs-12 pad">
                                        <div class="col-lg-9 pad">

    <?php
//                                        browse($get['canc_flag']);
    if ($get['canc_flag'] != '') {
        ?>
                                                <img src="images/cancel.jpg" alt="Cancelled Bill"
                                                     style="width:100%;height:100%">
    <?php } ?>

                                        </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-2 label-control marg text-rigt pad">Total Qty.</div>
                                        <div class="col-lg-2 pad">
                                            <input type="number" step="any" name="totalqty"
                                                   class="form-control form text-right totalqty"
                                                   value="<?php echo ($addflag != 1) ? $get['totalqty'] : "0"; ?>">
                                        </div>
                                        <div class="col-lg-2 pad text-right">
                                            <label class="label-control marg">Subtotal</label>
                                        </div>
                                        <div class="col-lg-3 pad">
                                            <input type="number" step="any" name="grossamt"
                                                   class="form-control form text-right totamt grossamt"
                                                   value="<?php echo ($addflag != 1) ? $get['grossamt'] : "0"; ?>" readonly
                                                   tabindex="-1">
                                        </div>
                                    </div>
                                    <div class="col-lg-12 col-xs-12 pad">
                                        <div class="col-lg-4 pad"></div>
                                        <div class="col-lg-3 pad text-right">
                                            <label class="label-control marg">Less Discount</label>
                                        </div>
                                        <div class="col-lg-1 pad">
                                            <input type="number" step="any" name="ldiscperc"
                                                   class="form-control form text-right ldiscperc"
                                                   value="<?php echo ($addflag != 1) ? $get['ldiscperc'] : "0"; ?>">

                                        </div>
                                        <div class="col-lg-1 pad text-center">
                                            <label class="label-control marg">%</label>
                                        </div>
                                        <div class="col-lg-3 pad">
                                            <input type="number" step="any" name="totdisc"
                                                   class="form-control form text-right totdisc"
                                                   value="<?php echo ($addflag != 1) ? $get['totdisc'] : "0"; ?>">
                                            <input type="hidden" step="any" name="tvatperc"
                                                   class="form-control form text-right tvatperc"
                                                   value="<?php echo ($addflag != 1) ? $get['tvatperc'] : "0"; ?>">
                                            <input type="hidden" step="any" name="totvat"
                                                   class="form-control form text-right totvat"
                                                   value="<?php echo ($addflag != 1) ? $get['totvat'] : "0"; ?>" readonly
                                                   tabindex="-1">
                                        </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">Add Transport</label>
                                        </div>
                                        <div class="col-lg-3 pad">
                                            <input type="number" step="any" name="addpack" required="true"
                                                   class="form-control form text-right  addpack"
                                                   value="<?php echo ($addflag != 1) ? $get['addpack'] : "0"; ?>">
                                        </div>
                                    </div><!-- comment -->
                                    <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">Add GT</label>
                                        </div>
                                        <div class="col-lg-3 pad">
                                            <input type="number" step="any" name="addgst" required="true"
                                                   class="form-control form text-right addgst "
                                                   value="<?php echo ($addflag != 1) ? $get['addgst'] : "0"; ?>">
                                        </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">Net Amount</label>
                                        </div>
                                        <div class="col-lg-3 pad">
                                            <input type="number" step="any" name="totbillamt" required="true"
                                                   class="form-control form text-right tottotal totbillamt"
                                                   value="<?php echo ($addflag != 1) ? $get['billamt'] : "0"; ?>" readonly
                                                   tabindex="-1">
                                        </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">Advance</label>
                                        </div>

                                        <div class="col-lg-3 pad">
                                            <input type="number" step="any" name="totadv"
                                                   class="form-control  text-right totadv form"
                                                   value="<?php echo ($addflag != 1) ? $get['totadv'] : "0"; ?>" tabindex="-1">
                                        </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">Balance</label>
                                        </div>
                                        <div class="col-lg-3 pad">
                                            <input type="number" step="any" name="totbal" required="true"
                                                   class="form-control form text-right totbal"
                                                   value="<?php echo ($addflag != 1) ? $get['totbal'] : "0"; ?>" readonly
                                                   tabindex="-1">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">

                        <div class="col-lg-1 pad"></div>
                        <div class="col-lg-1 pad">
                            <a id='whats' href="sale_pdf.php?vouchno=<?= $qvouch; ?>&para=whatsapp"
                               class="partywhatsapp-btn" target="_blank">
                                PARTY <i class="fa fa-whatsapp"></i>
                            </a>
                        </div>
                        <div class="col-lg-1 pad">
                            <a href="sale_pdf.php?vouchno=<?= $qvouch; ?>" class="partypdf-btn" target="_blank">
                                PDF <i class="fa fa-file-pdf-o"></i>
                            </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">
                                            </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="" alt="your image" />
                                    </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>