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

$formname = 'Finishing And Packing';

$maindb = 'packmain';
$trandb = 'packtran';
$stkdb = 'packsacn';

$printfile = "finandpack_print.php"; //print not done
$file = 'finandpack.php';
$trandbexist = 1;
$keyfld = "vouchno";
$source = "PACK";

$fseries = $_SESSION["series_" . $dbname];
$keycond = " and `series`='$fseries'";
$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
$compcd = $_SESSION["comp_" . $dbname];
$username = $_SESSION["username_" . $dbname];

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

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

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

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

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

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

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

    $staff = $_POST["staff"];

    $subtotal = $_POST["subtotal"];


    $packkg = $_POST["packkg"];
    $packrate = $_POST["packrate"];
    $packamt = $_POST["packamt"];

    $paidrate = $_POST["paidrate"];
    $paidamt = $_POST["paidamt"];

    $gstrate = $_POST["gstrate"];
    $gstamt = $_POST["gstamt"];

    $netamt = $_POST["netamt"];
    $oldamt = $_POST["oldamt"];
    $cashamt = $_POST["cashamt"];
    $ccamt = $_POST["ccamt"];
    $credamt = $_POST["credamt"];
    $lessperc = $_POST["lessperc"];
    $lesother = $_POST["lesother"];
    $remark1 = $_POST["remark1"];
    $remark2 = $_POST["remark2"];
    $transname = $_POST["transname"];
    $disctotp = $_POST["disctotp"];
    $bankname = $_POST["bankname"];

    $oms = $_POST["oms"];


    $totqty = $_POST['totqty'];

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

    $lrno = $_POST["lrno"];
    $lrdate = $_POST["lrdate"];
    $nopkgs = $_POST["nopkgs"];


    $count = $_POST["items"];

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

    $mvouch = $qvouch;

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


    if ($a == 1) {

        mysqli_query($conn, "LOCK TABLES `$maindb` WRITE,  $trandb WRITE, sordsacn WRITE, accmast WRITE , packsacn WRITE") or die(mysqli_error($conn));

        if ($addflag == 1) {
            $gen1 = mysqli_query($conn, "SELECT MAX(vouchno+0) 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;
        }

        $mccamt = $ccamt;


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

        mysqli_query($conn, "DELETE FROM `$trandb` WHERE `$keyfld`='$mvouch' $keycond") or die(mysqli_error($conn));
        mysqli_query($conn, "DELETE FROM `$stkdb` WHERE `$keyfld`='$mvouch' AND `source`='$source' $keycond")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"];
            $mitem = $_POST["item_$i"];
            $unit = $_POST["unit_$i"];
            $qty = $_POST["qty_$i"];
            $mrp = $_POST["mrp_$i"];
            $msp = $_POST["msp_$i"];
            $rate = $_POST["rate_$i"];
            $ratebfdisc = $_POST["ratebfdisc_$i"];
            $amount = $_POST["amount_$i"];
            $color = $_POST["color_$i"];

//            $discperc = $_POST["discperc_$i"];
//            $discamt = $_POST["discamt_$i"];
//            $discount2 = $_POST["discount2_$i"];
//            $cgstrate = $_POST["cgstrate_$i"];
//            $cgstamt = $_POST["cgstamt_$i"];
//            $sgstrate = $_POST["sgstrate_$i"];
//            $sgstamt = $_POST["sgstamt_$i"];
//            $igstrate = $_POST["igstrate_$i"];
//            $igstamt = $_POST["igstamt_$i"];
            $total = $_POST["total_$i"];
            $subtot = $_POST["subtot_$i"];

            $otprowsucs = $_POST["otprowsucs_$i"];
            $otpvalue = $_POST["otpvalue_$i"];
            $hsncode = $_POST["hsncode_$i"];

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

//            $gstperc = $cgstperc + $sgstperc + $igstperc;



            if (!empty($mitem)) {
                $srl = $srl + 1;
                $stkqty = $qty * -1;


                mysqli_query($conn, "INSERT INTO `$trandb`(series, `vouchno`, `vouchdt`, `srno`, `barcode`, `item`, `qty`, `unit`, 
                                            `mrp`, `msp`, `rate`, `amount`, `discperc`, `discount`, `discount2`, `otprowsucs`, `otpvalue`,`hsncode`,
                                            `cgstrate` , `cgstamt`, `sgstrate`, `ratebfdisc`,
                                            `sgstamt`, `igstrate`, `igstamt`,`total`, `subtot`, `gstperc`,color) 
                    VALUES ('$fseries', '$mvouch', '$vouchdt', '$srl', '$barcode', '$mitem', '$qty', '$unit', 
                                        '$mrp', '$msp', '$rate', '$amount', '$discperc', '$discamt', '$discount2', '$otprowsucs', '$otpvalue','$hsncode',
                                         '$cgstrate', '$cgstamt', '$sgstrate', '$ratebfdisc',
                                          '$sgstamt', '$igstrate', '$igstamt', '$total', '$subtot', '$gstperc','$color')") or die(mysqli_error($conn));

                ###########Stock Part############

                mysqli_query($conn, "INSERT INTO `packsacn` (`vouchno`, `compcode`, `yearno`, `vouchdt`, `srno`,`staff`, `barcode`, `itemcode`, `qty`,  
                                                          `source`,  color, series) 
                                                  VALUES ('$mvouch', '$compcd', '$myyear', '$vouchdt', '$srl', '$staff', '$mitem', '$mitem', '$stkqty',  
                                                          '$source', '$color','$fseries')") or die(mysqli_error($conn));


                mysqli_query($conn, "INSERT INTO `sordsacn`(`vouchno`, `compcode`, `yearno`, `vouchdt`, `srno`,`accode`, `barcode`, `itemcode`, `qty`,  
                                                          `source`,   color, series, ordno) 
                                                  VALUES ('$mvouch', '$compcd', '$myyear', '$vouchdt', '$srl', '$party', '$mitem', '$mitem', '$stkqty',  
                                                          '$source', '$color','$fseries', '$ordno' )") or die(mysqli_error($conn));
            }
        }

        ############################### Accounts Part ######################################################
//        mysqli_query($conn, "DELETE FROM `$accdb` WHERE `vouchno` = '$mvouch' AND `source`='$source' $keycond") OR die(mysqli_error($conn));
//
//        if ($netamt > 0) {
//
//            if ($autoamtsale > 0) {
//                $minus_amt = ($autoamtsale * -1);
//                $autoamtsale = $autoamtsale;
//            } else {
//                $minus_amt = ($netamt * -1);
//                $autoamtsale = $netamt;
//            }
//
//// sale part
//            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount, prodtype, actamt, series)
//                    VALUES ('$vouchdt','$mvouch', '$source', '001', '$salecode','005', '$autoamtsale', '$prodtype', '$actamt', '$fseries')") OR die(mysqli_error($conn));
//// party part
//            mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, source, trnno, accode, grpcode, amount, prodtype, actamt, series)
//                     VALUES ('$vouchdt','$mvouch', '$source', '002', '$party', '010', '$minus_amt', '$prodtype', '$actminus','$fseries')") or die(mysqli_error($conn));
//        }
        ############################## MAIN ######################################################
        if ($addflag == 1) {
            mysqli_query($conn, "INSERT INTO `$maindb`(series, `vouchno`, `invno`, `invdt`, `vouchdt`, `staff`, `transporter`, `lrno`, 
                        `lrdate`, `cashcred`, `prodtype`, `salesman`, `packby`, `driver`, `dcperc`, `dcbperc`, `dcamt`, `totqty`, `subtotal`, `litemdisc`, 
                        `cdiscperc`, `cdiscamt`, `packkg`, `packrate`, `packamt`, `paidrate`, `paidamt`, `gstrate`, `gstamt`, `discperc`, `discount`, `netamt`, `cashamt`,`ccamt`,`credamt`, `lesother`, `lessperc`,
                        `remark1`, `remark2`,transname,`cashvouch`,`disctotp`,`purcono`,`purvouch`,`bankvouch`,`bankname`, `oms`, `cgstperc`, `sgstperc`, `igstperc`, 
                        `totcgst`, `totsgst`, `totigst`, `tottaxamt`,`gstperc`,`cgst5`,`sgst5`,`igst5`,`cgst12`,`sgst12`,`igst12`,`cgst18`,`sgst18`,`igst18`,`cgst28`,
                                               `sgst28`,`igst28`,`totgst5`,`totgst12`,`totgst18`,`totgst28`,`nameprint`,`printmobile`,`totalamount`,`roundoff`,autoamtsale, cartqty,`ordno`, `nopkgs`, `adduser`, `adddate`, `addtime`) 
                        VALUES ('$fseries', '$qvouch', '$invno', '$vouchdt', '$vouchdt', '$staff', '$transporter', '$lrno', 
                        '$lrdate', '$type', '$prodtype', '$salesman', '$packby', '$driver', '$dcperc', '$dcbperc', '$dcamt', '$totqty', '$subtotal', '$litemdisc', 
                        '$cdiscperc', '$cdiscamt', '$packkg', '$packrate', '$packamt', '$paidrate', '$paidamt', '$gstrate', '$gstamt', '$discperc', '$discount', '$netamt', '$cashamt','$ccamt','$credamt', '$lesother', '$lessperc', 
                        '$remark1', '$remark2','$transname','$mcashvouch', '$disctotp','$purcono','$mpurvouch','$mbankvouch','$bankname', '$oms', '$cgstperc', '$sgstperc', '$igstperc',
                        '$totcgst', '$totsgst', '$totigst', '$taxamt','$gstperc','$cgst5','$sgst5','$igst5', '$cgst12','$sgst12','$igst12', '$cgst18', '$sgst18','$igst18','$cgst28',
                        '$sgst28','$igst28','$totgst5','$totgst12','$totgst18','$totgst28','$nameprint','$printmobile','$totalamount','$roundoff','$autoamtsale', '$packkg', '$ordno', '$nopkgs','$adduser','$adddate','$addtime')") or die(mysqli_error($conn));
//            insmess();


            $mvouch = $qvouch; //1
//            $_SESSION['print_voucher'] = $mvouch;
//            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit&series=$fseries");
        } else {
            $mvouch = $qvouch; //1
            $editdate = date("Y-m-d");
            $edittime = date("h:i:sa");

            mysqli_query($conn, "UPDATE `$maindb` SET `invno`='$invno',`invdt`='$vouchdt',`vouchdt`='$vouchdt',`nameprint`='$nameprint', `printmobile`='$printmobile',
                    `staff`='$staff',`transporter`='$transporter',`lrno`='$lrno',`lrdate`='$lrdate',`cashcred`='$type',`prodtype`='$prodtype',`salesman`='$salesman', `packby`='$packby',
                    `driver`='$driver',`dcperc`='$dcperc',`dcbperc`='$dcbperc',`dcamt`='$dcamt',`totqty`='$totqty',`subtotal`='$subtotal',
                    `litemdisc`='$litemdisc',`cdiscperc`='$cdiscperc',`cdiscamt`='$cdiscamt',`packkg`='$packkg',`packrate`='$packrate',`packamt`='$packamt',
                    `paidrate`='$paidrate',`paidamt`='$paidamt', `gstrate`='$gstrate',`gstamt`='$gstamt', `discperc`='$discperc',`discount`='$discount',`netamt`='$netamt',`credamt`='$credamt',`ccamt`='$ccamt',`cashamt`='$cashamt', `lesother`='$lesother',`remark1`='$remark1',
                    `lessperc`='$lessperc', `remark2`='$remark2', transname='$transname', `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',
                    `cgst5`='$cgst5',`sgst5`='$sgst5', `igst5`='$igst5',`cgst12`='$cgst12',`sgst12`='$sgst12',`igst12`='$igst12',
                    `cgst18`='$cgst18', `sgst18`='$sgst18',`igst18`='$igst18',autoamtsale='$autoamtsale',
                    `cgst28`='$cgst28', `sgst28`='$sgst28',`igst28`='$igst28',`oms`='$oms', `totalamount`='$totalamount',`roundoff`='$roundoff',
                    `totgst5`='$totgst5',`totgst12`='$totgst12', `totgst18`='$totgst18',`totgst28`='$totgst28', `cartqty`='$packkg',`ordno`='$ordno', `nopkgs`='$nopkgs', 
                    `edituser`='$adduser',`edittime`='$edittime',`editdate`='$editdate' WHERE `vouchno`='$mvouch' $keycond") or die(mysqli_error($conn));

            updmess();
//            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
        }
        if ($addflag == 1) {
//            browse($fseries);
//            insmess();
            header("refresh: 1; $file?mode=edit&$keyfld=$mvouch&form=$form&series=$fseries");
        } else {
//            updmess();
            header("refresh: 1; $file?mode=edit&$keyfld=$mvouch&form=$form&series=$fseries");
        }

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

if ($addflag != 1) {

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

    $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE $keyfld='$getvouch' $keycond") or die(mysqli_error($conn));
    $get = mysqli_fetch_array($result);
    $delcsh = $get['cashvouch'];
    $delbnk = $get['bankvouch'];
    $delpurcono = $get['purcono'];
    $delpurvch = $get['purvouch'];


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

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


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

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

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

    $getbank = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode` = '$get[bankname]'");
    $banknm = mysqli_fetch_array($getbank);

    $getcomp2 = mysqli_query($conn, "SELECT * FROM $zroot.`company` WHERE code='$get[tocomp]'") or die(mysqli_error($conn));
    $fetcomp2 = mysqli_fetch_array($getcomp2);

    $getgst = mysqli_query($conn, "SELECT * FROM `saletype` WHERE code='$get[gstperc]'") or die(mysqli_error($conn));
    $fetgst = mysqli_fetch_array($getgst);
}

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

if (isset($_GET["delete"])) {
//    delete($zdb, "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
//    delete($zdb, "$trandb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
    $delcondn = " vouchno = '$_GET[vouchno]' $keycond";
    $delcond = " source = '$source' and vouchno = '$_GET[vouchno]' $keycond";
    $delcond2 = " source = '$source' and vouchno = '$_GET[vouchno]' and `compcode` = '$compcd' $keycond";
    $delcond1 = " source = 'CR' and vouchno = '$delcsh' $keycond";
    $delcond3 = " source = 'BR' and vouchno = '$delbnk' $keycond";

    delnew($zdb, "$maindb", "$delcondn", "$file?mode=last&series=$fseries");
    delnew($zdb, "$trandb", "$delcondn", "$file?mode=last&series=$fseries");
//    delnew($zdb, "$accdb", "$delcond1", "$file?mode=last&series=$fseries");
//    delnew($zdb, "$accdb", "$delcond3", "$file?mode=last&series=$fseries");
//    delete($zdb, "$cashdb", "$keyfld", $delcsh, "$file?mode=last&series=$fseries");
//    delete($zdb, "$bankdb", "$keyfld", $delbnk, "$file?mode=last&series=$fseries");
//    delnew($zdb, "$stkdb", "$delcond", "$file?mode=last&series=$fseries");
//    delnew($zdb, "$accdb", "$delcond", "$file?mode=last&series=$fseries");
}


include("includes/linkshead.php");
?>
<style type="text/css">

</style>
<!--<script src="MyScript/shortkeys.js" type="text/javascript"></script>-->
<script src="MyScript/finandpack.js?A=2" type="text/javascript"></script>
<script src="MyScript/finandpack_search.js?" type="text/javascript"></script>
<script src="MyScript/checkdate.js" type="text/javascript"></script>
</head>
<body >
    <form action='' method='POST'>
        <div class="col-lg-5 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>
            <button type="button" id="close_form1" style="float: right;font-weight: bold;font-size: 18px;color:red;" ><i class="fa fa-close"></i></button>
            <div class="normotp">
                <div style='width:100%;' id='browdata'>
                    MSP
                </div>
                <div class="ratemspless">
                    <label class="label-control">Rate Cannot Be Less Than Msp</label>
                    <!--                    <label class="label-control">To Sell Below MSP Generate OTP</label>
                    
                                        <input type="button" name="genotp" class="form-control genotp" style="color:red;border: none" value="Click here to Generate OTP">
                                        <input type="hidden" name="rowsrno" id="rowsrno" class="form-control rowsrno">
                                        <input type="hidden" name="rowitm" id="rowitm" class="form-control rowitm">
                                        <input type="hidden" name="rowqty" id="rowqty" class="form-control rowqty">
                                        <input type="hidden" name="rowrate" id="rowrate" class="form-control rowrate">
                                        <input type="hidden" name="rowmrp" id="rowmrp" class="form-control rowmrp">
                                        <input type="hidden" name="rowmsp" id="rowmsp" class="form-control rowmsp">
                                        <input type="hidden" name="idget" id="idget" class="form-control idget">
                                        <div class="row">
                                            <div class="col-lg-4 text-right"><label class="label-control">Enter OTP</label></div>
                                            <div class="col-lg-4">
                                                <input type="text" name="otprecv" id="otprecv" class="form-control otprecv" style="background-color: white;color: green;">
                                            </div>
                                        </div>
                                        <input type="hidden" name="otpsend" id="otpsend" class="form-control otpsend">
                                        <a id="genotp" name="genotp" class="form-control genotp" style="color:red;"><u>Generate OTP</u></a>
                                        <div class="row">
                                            <div class="col-lg-4 text-right"></div>
                                            <div class="col-lg-4 ">
                                                <input type="button" name="subotp" id="subotp" class="form-control form subotp" style="color: blue;background-color: whitesmoke" value="Submit OTP">
                                            </div>
                                        </div>
                                        <input type="hidden" name="otpsucs" id="otpsucs" class="form-control otpsucs">-->
                </div>
            </div>
            <div class="lesdsotp">

                <!--<a id="genotp" name="genotp" class="form-control genotp" style="color:red;"><u>Generate OTP</u></a>-->
                <div class="row">
                    <label class="label-control">Total Amount of Bill is Less Than Msp Total</label>
                    <label class="label-control">To Sell Below MSP Total Generate OTP</label>
                </div>
                <div class="row">
                    <div class="col-lg-12">    
                        <input type="button" name="gendsotp" class="form-control gendsotp form" style="color:red;border: none;" value="Click to Generate Discount OTP">
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-4 text-right"><label class="label-control">Discount OTP</label></div>
                    <div class="col-lg-4">
                        <input type="text" name="otpdsrecv" id="otpdsrecv" class="form-control otpdsrecv" style="background-color: white;color: green;">
                        <input type="hidden" name="otpdssend" id="otpdssend" class="form-control otpdssend">
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-4 text-right"></div>
                    <div class="col-lg-4 ">
                        <input type="button" name="subdsotp" id="subdsotp" class="form-control form subdsotp" style="color: blue;background-color: whitesmoke" value="Submit Discount OTP">
                    </div>
                </div>
                <input type="hidden" name="otpdssucs" id="otpdssucs" class="form-control otpdssucs">

            </div>
        </div>

        <!-- Default box -->
        <div>
            <div class="col-lg-8 col-md-8 col-sm-12 col-xs-12  pad">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <?php include("includes/usermention.php");
                        ?>
                        <div class="actions pull-right">
                            <i class="fa fa-chevron-down"></i>
                            <i class="fa fa-times"></i>
                        </div>
                    </div>

                    <!--                    <div class="panel-heading">
                                            <h3 class="panel-title" style="color:#78909C"><a class="myPrint"><?php Echo $formname; ?></a></h3>
                                            <div class="actions pull-right">
                                                <i class="fa fa-chevron-down"></i>
                                                <i class="fa fa-times"></i>
                                            </div>
                                        </div>-->
                    <div class="panel-body">
                        <div class="row" >
                            <!--                            <div class="col-lg-3 col-md-3 col-sm-2 col-xs-2 text-right pad">
                                                                <a id='print' class="btn btn-pad" style="background-color:grey;display:;margin-top:17px; <? Echo $printdisabled ?>" href="quot_pdf.php?vouchno=<?= $qvouch; ?>"  target="_blank" >
                                                                    <button type="button" >PDF</button>
                                                                </a>
                                                        </div>-->
                            <div class="col-lg-10 col-md-5 col-sm-9 col-xs-9 pad" >
                                <?php include("includes/buttons.php"); ?>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-1 col-md-1 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Voucher No</label>
                            </div>
                            <div class="col-lg-1 col-md-1 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"; ?>" readonly required>
                                <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-1 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Date</label>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-8 col-xs-8 pad">
                                <input type="date" class="form-control form focusfield vouchdt" name="vouchdt" value="<?php Echo ($addflag != 1) ? $get["vouchdt"] : date("Y-m-d"); ?>" required style="padding:0px;" autofocus>
                                <input type="hidden" value="<?= $zStartDate ?>" class="zstdate">
                                <input type="hidden" value="<?= $zEndDate ?>" class="zenddate">

                            </div>


                            <div class="col-lg-1 col-md-1 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Staff</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-6 col-xs-8 pad">
                                <select class="form-control form staff select2" name="staff" style="width: 96%" >
                                    <option value="<?php Echo ($addflag != 1) ? $get["staff"] : ""; ?>"><?php Echo ($addflag != 1) ? $fstaff["name"] : ""; ?></option>
                                    <?php
                                    $gstaff = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `grpcode`='039' ORDER by name")or die(mysqli_error($conn));
                                    while ($staff = mysqli_fetch_array($gstaff)) {
                                        Echo "<option value='$staff[accode]'>$staff[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-3 col-xs-3 text-right pad">
                                <label class="label-control marg" style="color: red;">Sale Order</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form ordno" name="ordno" value="<?php Echo ($addflag != 1) ? $get["ordno"] : ""; ?>"  required>
                            </div>
                        </div>
                        <div class="table-responsive" style="overflow-y:scroll;height: 350px;">
                            <table class="table table-striped table-condensed table-bordered tab" width="100%">


                                <thead  class="mySearchTr">
                                    <tr>
                                        <th style='width: 1%' class="stick"></th>
                                        <th style='width: 5%' class='text-right stick'>Sr.</th>
                                        <th style='width: 10%' class='text-left stick'>Barcode</th>
                                        <th style='width: 30%' class="stick">Item</th>
                                        <th style='width: 10%' class="stick">Color</th>
                                        <th style='width: 10%' class='text-right stick'>Qty.</th>
<!--                                        <th style='width: 4%' class='text-right stick'>Rate</th>
                                        <th style='width: 6%' class='text-right stick'>Amount</th>-->
                                    </tr>
                                </thead>
                                <tbody class="tbody" id="saledtltab">
                                    <?php
                                    if ($addflag != 1) {
                                        $ctr = 0;
                                        $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$get[vouchno]' $keycond ORDER BY `srno`")or die(mysqli_error($conn));
                                        while ($tran = mysqli_fetch_array($gettran)) {
                                            $finditem = mysqli_query($conn, "SELECT `code`,`name` FROM `item` WHERE `code`='$tran[item]'") or die(mysqli_error($conn));
                                            $fitem = mysqli_fetch_array($finditem);

                                            $findcolor = mysqli_query($conn, "SELECT `code`,`name` FROM `color` WHERE `code`='$tran[color]'") or die(mysqli_error($conn));
                                            $fcolor = mysqli_fetch_array($findcolor);

                                            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 barcode' name='barcode_$ctr' value='$tran[barcode]'>";
                                            Echo "</td>";
                                            Echo "<td>";
                                            Echo "<select class='form-control form item select2' name='item_$ctr' style='width:100%'>";
                                            Echo "<option value='$fitem[code]'>$fitem[name]</option>";
                                            $gitem = mysqli_query($conn, "SELECT `code`,`name` FROM `item` WHERE `prodtype`='$get[prodtype]'")or die(mysqli_error($conn));
                                            while ($item = mysqli_fetch_array($gitem)) {
                                                Echo "<option value='$item[code]'>$item[name]</option>";
                                            }
                                            Echo "</select>";
                                            Echo "<input type='hidden' class='msp' name='msp_$ctr' value='$tran[msp]' >";
                                            Echo "<input type='hidden' class='otprowsucs' name='otprowsucs_$ctr' value='$tran[otprowsucs]' >";
                                            Echo "</td>";
                                            Echo "<td>";
                                            Echo "<select class='form-control form color select2' name='color_$ctr' style='width:100%'>";
                                            Echo "<option value='$fcolor[code]'>$fcolor[name]</option>";
                                            $gcolor = mysqli_query($conn, 'SELECT `code`,`name` FROM `color` order by name')or die(mysqli_error($conn));
                                            while ($color = mysqli_fetch_array($gcolor)) {
                                                Echo "<option value='$color[code]'>$color[name]</option>";
                                            }
                                            Echo "</select>";
                                            echo "</td>";
                                            Echo "<td><input type='text' class='form-control form text-right qty'      name='qty_$ctr'      value='$tran[qty]'></td>";
                                            Echo "<input type='hidden' class='msp' name='msp_$ctr' >";
                                            Echo "<input type='hidden' class='otpvalue' id='otpvalue_$ctr' name='otpvalue_$ctr' value='$tran[otpvalue]'>";
//                                            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">
                                                <input type="hidden" class="form-control form text-right purvouch" name="purvouch_0" value="">
                                                <input type="hidden" class="form-control form text-right pursrno" name="pursrno_0" value=""></td>
                                            <td><input type="text" class="form-control form barcode" name="barcode_0" name="barcode"></td>
                                            <td>
                                                <select class="form-control form item select2" name="item_0" style='width:100%'>
                                                    <option value=""></option>
                                                    <?php
                                                    $gitem = mysqli_query($conn, "SELECT * FROM `item`")or die(mysqli_error($conn));
                                                    while ($item = mysqli_fetch_array($gitem)) {
                                                        Echo "<option value='$item[code]'>$item[name]</option>";
                                                    }
                                                    ?>
                                                </select>
                                                <input type='hidden' class='msp' name='msp_0' >
                                                <input type='hidden' class='otprowsucs' name='otprowsucs_0' >
                                                <input type='hidden' class='otpvalue' name='otpvalue_0' >
                                            </td>
                                            <td>
                                                <select class="form-control form color select2" name="color_0" style='width:100%'>
                                                    <option value=""></option>
                                                    <?php
                                                    $gcolor = mysqli_query($conn, "SELECT `code`,`name` FROM `color` order by name")or die(mysqli_error($conn));
                                                    while ($color = mysqli_fetch_array($gcolor)) {
                                                        Echo "<option value='$color[code]'>$color[name]</option>";
                                                    }
                                                    ?>
                                                </select>
                                            </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>  
                                        <?
                                        $pctr++;
                                    }
                                    ?>
                                <input type="hidden" id="items" name="items" value="<?php echo ($addflag != 1) ? $ctr : 1; ?>" />  

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

                                </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="<? Echo ($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="<? Echo ($addflag != 1) ? $get["remark2"] : ""; ?>">
                                    </div>
                                </div>
                                <!--                                <div class="col-lg-12 col-xs-12 pad">
                                                                    <div class="col-lg-3 pad text-right">Transporter</div>
                                                                    <div class="col-lg-9 pad">
                                                                        <input type="text" name="transname" class="form-control form transname" value="<? Echo ($addflag != 1) ? $get["transname"] : ""; ?>">
                                                                    </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-8 pad text-right">
                                        <label class="label-control marg" style='color:#337AB7'>Total Qty. </label>
                                    </div>
                                    <div class="col-lg-3 pad">
                                        <input type="text" name="totqty" class="form-control form text-right totqty"  value="<?php echo ($addflag != 1) ? $get['totqty'] : "0.00"; ?>" readonly>
                                    </div>
                                    <!--                                    <div class="col-lg-2 pad text-right">
                                                                            <label class="label-control marg" style='color:#337AB7'>Total</label>
                                                                        </div>
                                                                        <div class="col-lg-3 pad">
                                                                            <input type="text" class="form-control form subtotal text-right" value="<? Echo ($addflag != 1) ? $get['subtotal'] : "0"; ?>" name="subtotal" readonly>
                                                                            <input type="hidden" class="form-control form msptotal text-right" value="<? Echo ($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-2 col-md-2 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-2 col-md-2 text-right pad">
                                                                        <input type="text" class="form-control form lessperc text-right" value="<? Echo ($addflag != 1) ? $get['lessperc'] : "0.00"; ?>" name="lessperc" step="any">
                                                                    </div>
                                                                    <div class="col-lg-2 col-md-2 text-center pad">
                                                                        <label class="label-control">%</label>
                                                                    </div>
                                                                    <div class="col-lg-3 col-md-3 pad">
                                                                        <input type="text" class="form-control form lesother text-right" value="<? Echo ($addflag != 1) ? $get['lesother'] : "0"; ?>" name="lesother">
                                                                        <input type="hidden" class="form-control form disctotp text-right" value="<? Echo ($addflag != 1) ? $get['disctotp'] : ""; ?>" name="disctotp" >
                                                                    </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 numeric" value="<? Echo ($addflag != 1) ? $get['totalamount'] : "0"; ?>" name="totalamount" readonly>
                                                                    </div>
                                                                </div>
                                                                <div class="col-lg-12 col-xs-12 pad">
                                                                    <div class="col-lg-5 pad text-right">
                                                                        <label class="label-control marg">Add Packing</label>
                                                                    </div>
                                                                    <div class="col-lg-1 pad text-right">
                                                                        <input type="text" class="form-control form packkg text-right" value="<? Echo ($addflag != 1) ? $get['packkg'] : "1"; ?>" name="packkg" >
                                                                    </div>
                                                                    <div class="col-lg-1 pad text-center">
                                                                        <label class="label-control marg">x</label>
                                                                    </div>
                                                                    <div class="col-lg-2 pad">
                                                                        <input type="text" class="form-control form packrate text-right" value="<? Echo ($addflag != 1) ? $get['packrate'] : "0"; ?>" name="packrate">
                                                                    </div>
                                                                    <div class="col-lg-3 pad">
                                                                        <input type="text" class="form-control form packamt text-right" value="<? Echo ($addflag != 1) ? $get['packamt'] : "0"; ?>" name="packamt" readonly>
                                                                    </div>
                                                                </div>
                                                                <div class="col-lg-12 col-xs-12 pad">
                                                                    <div class="col-lg-5 pad text-right">
                                                                        <label class="label-control marg">TR Paid</label>
                                                                    </div>
                                                                    <div class="col-lg-1 pad text-right">
                                                                    </div>
                                                                    <div class="col-lg-1 pad text-center">
                                                                        <label class="label-control marg">x</label>
                                                                    </div>
                                                                    <div class="col-lg-2 pad">
                                                                        <input type="text" class="form-control form paidrate text-right" value="<? Echo ($addflag != 1) ? $get['paidrate'] : "0"; ?>" name="paidrate">
                                                                    </div>
                                                                    <div class="col-lg-3 pad">
                                                                        <input type="text" class="form-control form paidamt text-right" value="<? Echo ($addflag != 1) ? $get['paidamt'] : "0"; ?>" name="paidamt" readonly>
                                                                    </div>
                                                                </div>
                                                                
                                                                <div class="col-lg-12 col-xs-12 pad">
                                                                    <div class="col-lg-5 pad text-right">
                                                                        <label class="label-control marg">Add GST</label>
                                                                    </div>
                                                                    <div class="col-lg-1 pad text-right">
                                                                    </div>
                                                                    <div class="col-lg-1 pad text-center">
                                                                        <label class="label-control marg">x</label>
                                                                    </div>
                                                                    <div class="col-lg-2 pad">
                                                                        <input type="text" class="form-control form gstrate text-right" value="<? // Echo ($addflag != 1) ? $get['gstrate'] : "0";  ?>" name="gstrate">
                                                                    </div>
                                                                    <div class="col-lg-3 pad">
                                                                        <input type="text" class="form-control form gstamt text-right" value="<? // Echo ($addflag != 1) ? $get['gstamt'] : "0";  ?>" name="gstamt" 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="<? Echo ($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 totbillamt" value="<? Echo ($addflag != 1) ? $get['netamt'] : "0"; ?>" name="netamt" readonly>
                                                                        <input type="hidden" class="form-control form oldamt text-right" value="<? Echo ($addflag != 1) ? $get['netamt'] : "0"; ?>" name="oldamt" readonly>
                                                                    </div>
                                                                </div>-->

                            </div>
                        </div>
                        <!--                    </div>
                                        </div>-->
                        <!--</div>-->
                        <!--<div class="row">-->
                        <!--            <div class="panel panel-default">
                                        <div class="panel-body">
                        -->

                        <div class="col-lg-3 pad">
                            <input type="button" id="finishTab" class="btn btn-primary pull-right form mySearchTr" style="color: #fff;" value="Check & Finish">
                        </div>

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


    <div class="modal fade bs-example-modal-lg searchModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span>&times;</span></button>
                    <h4 class="modal-title" id="myLargeModalLabel">Search <? Echo $formname; ?></h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-lg-2">
                            <select class="form-control sfield">
                                <option value="1">Voucher</option>
                                <option value="2">Date</option>
                                <option value="3">Staff</option>
                                <option value="4">Total Qty</option>
                                <option value="5">Subtotal</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control soperator">
                                <option value="">Type of Search</option>
                                <option value="%">Like</option>
                                <option value="=">Exactly</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control sortBy">
                                <option value="">Sort By</option>
                                <option value="1">Voucher</option>
                                <option value="2">Date</option>
                                <option value="3">Staff</option>
                                <option value="4">Total Qty</option>
                                <option value="5">Subtotal</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="6%">Quotation</th>
                                    <th width="10%">Date</th>
                                    <th width="30%">Party</th>
                                    <th width="10%">Total Qty</th>
                                    <th width="10%">Subtotal</th>
                                    <th width="1%">Action</th>
                                </tr>
                            </thead>
                            <tbody class="sTbody">
                            </tbody>
                        </table>
                    </div>
                    <div class="row">
                        <div class="col-xs-12 text-right search-action-bar">
                            <input type="button"  class="btn btn-primary sprev" value="Previous">
                            <input type="button"  class="btn btn-primary snext" value="Next">
                        </div>
                    </div>
                </div>
                <div class="modal-footer"></div>
            </div>
        </div>
    </div>
    <?php include("includes/linksfoot.php"); ?>
</body>
</html>
