<?php
ob_start();
//echo "1";
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');
//browse(1);
$maindb = 'salemain';
$trandb = 'saletran';
$trandb2 = 'saleexp';
$trandb3 = 'saledesc';
$accdb = 'actran';
$stkdb = 'transacn';

$printfile = "sale_print.php";
$file = 'sale.php';
$trandbexist = 1;
$source = "SL";
$keyfld = "vouchno";

$myyear = $_SESSION["tit_" . $dbname];

//browse($myyear) ;

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

$saleexec = $_SESSION["saleexec"];
$usertype = $_SESSION["usertype"];
$username = strtoupper($_SESSION["username_" . $dbname]);
if ($usertype != 1) {
    $keycond1 = " and `salesman`='$saleexec'";
} else {
    $keycond1 = "";
}

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

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

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 = $_POST["vouchdt"];
    $qvouch = $_POST["vouchno"];
    $voucher = trim($_POST["voucher"]);

    $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"]);
    $salesman = trim($_POST["salesman"]);
    $taxableamt = trim($_POST["taxableamt"]);
    $totbillamt = trim($_POST["totbillamt"]);
    $paycompdt = trim($_POST["paycompdt"]);
    $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"]);
    $architect = trim($_POST["architect"]);
    $rem1 = trim($_POST["remark1"]);
    $rem2 = trim($_POST["remark2"]);

    $tvatperc = trim($_POST["tvatperc"]);
    $ldiscperc = trim($_POST["ldiscperc"]);
    $ntprint = trim($_POST["ntprint"]);
    $cartpaid = trim($_POST["cartpaid"]);

    $lrno = $_POST["lrno"];
    $archno = $_POST["archno"];
    $add1 = $_POST["add1"];
    $add2 = $_POST["add2"];
    $add3 = $_POST["add3"];
    $lrdate = $_POST["lrdate"];
    $duedt = $_POST["duedt"];
    $transporter = $_POST["transporter"];
    $area = $_POST["area"];

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

    $mcashvouch = $_POST["cashvouch"];
    $cartvouch = $_POST["cartvouch"];
    $commby = $_POST["commby"];
    $commperc = $_POST["commperc"];
    $commsqft = $_POST["commsqft"];

    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;

    $addflg = $_POST["addflg"];

    if ($addflg == 3) {
        for ($i = 0; $i <= $count; $i++) {
            $msrno = $_POST["srno_$i"];
            $delchaln = $_POST["delchal_$i"];
            $mancpn = $_POST["mancp_$i"];
            $delvdaten = $_POST["delivery_date_$i"];

            if (!empty($msrno)) {
                mysqli_query($conn, "Update `$trandb` set `delchal`='$delchaln', `mancp`='$mancpn', `delvdate`='$delvdaten' where srno = '$msrno' and vouchno ='$mvouch'") or die(mysqli_error($conn));
            }
        }
    } else {
        //        browse('out');
        //browse($count);
        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 ($vouchdt == '') {
            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,size WRITE, `product` WRITE, `$stkdb` WRITE, $trandb2 WRITE, $trandb3 WRITE, `$accdb` WRITE, `cashrecp` WRITE, `accmast` WRITE,cashpay WRITE");

            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;
                //            browse($mvouch) ;\

                $getpty = mysqli_query($conn, "SELECT accode,name FROM `accmast` WHERE `name`='$party'") or die(mysqli_error($conn));
                if (mysqli_num_rows($getpty) > 0) {
                    $fetpty = mysqli_fetch_array($getpty);
                    $partycode = $fetpty['accode'];
                } else {
                    $genbr = mysqli_query($conn, "SELECT MAX(accode) AS maxcode FROM `accmast` where accode != '' LIMIT 0,1 ") or die(mysqli_error($conn));
                    if (mysqli_num_rows($genbr) > 0) {
                        $gbr = mysqli_fetch_assoc($genbr);
                        $brcode = $gbr["maxcode"] + 1;
                    } else {
                        $brcode = '1';
                    }
                    mysqli_query($conn, "INSERT INTO `accmast`(`accode`, `name`, grpcode)
                           VALUES('$brcode', '$party', '010')") or die(mysqli_error($conn));
                }

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

            //**************************************************        auto cash Entry for cartage paid Start  ***************************************

            if ($cartpaid > 0) {
                if ($cartvouch == '0' || $cartvouch == '') {
                    $gen1 = mysqli_query($conn, "SELECT MAX(vouchno) AS maxcode FROM `cashpay` where vouchno!=''  LIMIT 0,1 ") or die(mysqli_error($conn));
                    if (mysqli_num_rows($gen1) > 0) {
                        $vvouch = mysqli_fetch_assoc($gen1);
                        $tcartvouch = $vvouch["maxcode"] + 1;
                    } else {
                        $tcartvouch = '1';
                    }
                    $cartvouch = $tcartvouch;
                }

                $genrecp = mysqli_query($conn, "SELECT * FROM `cashpay` where `vouchno` = '$cartvouch' ") or die(mysqli_error($conn));
                if (mysqli_num_rows($genrecp) > 0) {
                    $fetrecp = mysqli_fetch_array($genrecp);
                    $mrecpno = $fetrecp['recpno'];
                    $cartvouch = $fetrecp['vouchno'];
                } else {
                    $gen2 = mysqli_query($conn, "SELECT MAX(recpno+0) AS maxcode FROM `cashpay` 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 `cashpay` WHERE `$keyfld`='$cartvouch' ") or die(mysqli_error($conn));

                mysqli_query($conn, "INSERT INTO `cashpay`( vouchno ,`vouchdt`, `bankname`, `bankinit`, `recpno`, `party`,`amount`,`remark1`,`remark2`,`trnflag`, saleexec)
                                       Values ('$cartvouch', '$vouchdt', '3', 'COH', '$mrecpno','30','$cartpaid','Cartage Paid. For','Sale No.$mvouch','S', '$salesman')") or die(mysqli_error($conn));

                // cash part  

                $minus_amt = ($cartpaid * -1);

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

                mysqli_query($conn, "INSERT INTO `$accdb`(date,godown, vouchno, recpno, source, trnno, bankinit, accode, grpcode, amount, trnflag, monno,saleexec)
                    VALUES ('$vouchdt','$godown','$cartvouch', '$mrecpno', 'CP', '001', 'COH', '3','002', '$cartpaid','S','$mono', '$salesman')") 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, saleexec)
                    VALUES ('$vouchdt','$godown','$cartvouch', '$mrecpno', 'CP', '002', 'COH', '30', '012', '$minus_amt','S','$mono', '$salesman')") or die(mysqli_error($conn));
            } else {
                mysqli_query($conn, "DELETE FROM `cashpay` WHERE `$keyfld`='$cartvouch' $keycond") or die(mysqli_error($conn));
                mysqli_query($conn, "DELETE FROM `actran` WHERE `$keyfld`='$cartvouch' AND `source`='CP' $keycond") or die(mysqli_error($conn));
                $cartvouch = "";
            }


            //**************************************************        auto cash Entry Start  ***************************************

            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`,saleexec)
                                       Values ('$mcashvouch', '$vouchdt', '3', 'COH', '$mrecpno','$accode','$recpamt','Cash Recd. For','Sale No.$mvouch','S','$salesman')") 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,saleexec)
                    VALUES ('$vouchdt','$godown','$mcashvouch', '$mrecpno', 'CR', '001', 'COH', '3','002', '$minus_amt','S','$mono','$salesman')") 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,saleexec)
                    VALUES ('$vouchdt','$godown','$mcashvouch', '$mrecpno', 'CR', '002', 'COH', '$accode', '010', '$recpamt','S','$mono', '$salesman')") 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 `$trandb2` WHERE vouchno='$mvouch' ") or die(mysqli_error($conn));
            mysqli_query($conn, "DELETE FROM `$trandb3` 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;

            //            browse($count);

            for ($i = 0; $i <= $count; $i++) {
                $msrno = $_POST["srno_$i"];
                $barcode = $_POST["barcode_$i"];
                $mitem1 = mysqli_real_escape_string($conn, $_POST["itemname_$i"]);
                $mitem = trim($mitem1);
                $cartqty = $_POST["cartqty_$i"];
                $qty = $_POST["qty_$i"];
                $unit = $_POST["unit_$i"];
                $calby = $_POST["calby_$i"];
                $sqft = $_POST["sqft_$i"];
                $size1 = mysqli_real_escape_string($conn, $_POST["size_$i"]);
                $size = trim($size1);

                $rate = $_POST["rate_$i"];
                $amt = $_POST["amount_$i"];
                $delivery_date = $_POST["delivery_date_$i"];
                $delchal = $_POST["delchal_$i"];
                $mancp = $_POST["mancp_$i"];

                $mansupp = $_POST["mansupp_$i"];
                $sldesign = $_POST["sldesign_$i"];
                $suppamt = $_POST["suppamt_$i"];

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

                if (!empty($mitem)) {

                    $getit = mysqli_query($conn, "SELECT code,cost FROM `product` WHERE `name`='$mitem'") or die(mysqli_error($conn));
                    if (mysqli_num_rows($getit) > 0) {
                        $icode = mysqli_fetch_array($getit);
                        $itcode = $icode['code'];
                        $cost = $icode['cost'];
                    } else {
                        $genit = mysqli_query($conn, "SELECT MAX(code) AS maxcode FROM `product` where code != '' LIMIT 0,1 ") or die(mysqli_error($conn));
                        if (mysqli_num_rows($genit) > 0) {
                            $git = mysqli_fetch_assoc($genit);
                            $itcode = $git["maxcode"] + 1;
                        } else {
                            $itcode = '1';
                        }
                        mysqli_query($conn, "INSERT INTO `product`(`code`, `name`, `cost`, rate, `adduser`,`unit`)
                           VALUES('$itcode',  '$mitem', '$cost', '$rate', '$username','$unit')") or die(mysqli_error($conn));
                    }

                    $getsz = mysqli_query($conn, "SELECT code,name FROM `size` WHERE `name`='$size'") or die(mysqli_error($conn));
                    if (mysqli_num_rows($getsz) > 0) {
                        $scode = mysqli_fetch_array($getsz);
                        $szcode = $scode['code'];
                    } else {
                        $gensz = mysqli_query($conn, "SELECT MAX(code) AS maxcode FROM `size` where code != '' LIMIT 0,1 ") or die(mysqli_error($conn));
                        if (mysqli_num_rows($gensz) > 0) {
                            $gsz = mysqli_fetch_assoc($gensz);
                            $szcode = $gsz["maxcode"] + 1;
                        } else {
                            $szcode = '1';
                        }
                        mysqli_query($conn, "INSERT INTO `size`(`code`, `name`)
                           VALUES('$szcode',  '$size')") or die(mysqli_error($conn));
                    }


                    $cnt++;
                    $group = $source . $mvouch;
                    $tcartqty = $cartqty * -1;
                    $tqty = $qty * -1;

                    if ($architect != '' && $commby != '') {
                        if ($commby == 'P') {
                            $suppamt = $amt * ($commperc / 100);
                        } else {
                            $suppamt = $sqft * $commsqft;
                        }
                        $tsuppamt = $tsuppamt + $suppamt;
                    }

                    mysqli_query($conn, "INSERT INTO `$trandb`(vouchno, vouchdt, srno, itemcode, itemname, qty, cost, amount, 
                                                           rate,unit,size,delvdate,sqft,calby,delchal,mancp,mansupp,sldesign,suppamt)
                                                    VALUES('$mvouch', '$vouchdt', '$cnt', '$itcode', '$mitem', '$qty', '$cost', '$amt',
                                                           '$rate','$unit','$size','$delivery_date','$sqft', '$calby','$delchal','$mancp','$mansupp','$sldesign', '$suppamt')") or die(mysqli_error($conn));

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


            $cnt2 = 0;
            $cntamt2 = 0;
            $count2 = $_POST["items2"];
            for ($j = 0; $j <= $count2; $j++) {
                $msrno = $_POST["srno_$j"];
                $descrip = $_POST["descrip_$j"];
                $mamt = $_POST["tamount_$j"];
                $msamt = $_POST["samount_$j"];

                if (!empty($descrip) || $mamt > 0 || $msamt > 0) {
                    $cnt2++;
                    mysqli_query($conn, "INSERT INTO `$trandb2`(vouchno, vouchdt, srno, descrip, paid,  amount)
                                                    VALUES('$mvouch', '$vouchdt', '$cnt2', '$descrip', '$mamt', '$msamt' )") or die(mysqli_error($conn));
                }
            }


            $cnt3 = 0;
            $cntamt3 = 0;
            $count3 = $_POST["items3"];
            for ($k = 0; $k <= $count3; $k++) {
                //            $msrno = $_POST["srno_$k"];
                $descrip3 = $_POST["descrip3_$k"];
                $qty3 = $_POST["qty3_$k"];
                $size3 = $_POST["size3_$k"];
                $sqft3 = $_POST["sqft3_$k"];
                $remarks3 = $_POST["remarks3_$k"];

                if (!empty($descrip3)) {
                    $cnt3++;
                    mysqli_query($conn, "INSERT INTO `$trandb3`(vouchno, vouchdt, srno, descrip , qty ,size , sqft , remarks)
                                                    VALUES('$mvouch', '$vouchdt', '$cnt3', '$descrip3', '$qty3', '$size3' , '$sqft3', '$remarks3' )") 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);

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

                // party part
                mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, `godown`, source, trnno, accode, grpcode, amount, monno, saleexec)
                                VALUES ('$vouchdt','$mvouch','$godown', '$source', '002', '$accode','010', '$minus_amt','$mono','$salesman')") or die(mysqli_error($conn));
            }
            if ($tsuppamt > 0) {
                $minus_tsupp = ($tsuppamt * -1);

                // architech
                mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno,`godown`, source, trnno, accode, grpcode, amount, monno,saleexec)
                            VALUES ('$vouchdt','$mvouch','$godown', '$source', '003', '$architect','021', '$tsuppamt','$mono','$salesman')") or die(mysqli_error($conn));

                // party part
                mysqli_query($conn, "INSERT INTO `$accdb`(date, vouchno, `godown`, source, trnno, accode, grpcode, amount, monno, saleexec)
                                VALUES ('$vouchdt','$mvouch','$godown', '$source', '004', '33','012', '$minus_tsupp','$mono','$salesman')") 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`, cartvouch,cartpaid, `totdisc`,`grossamt`, totvat, packby, mobile, ldiscperc, 
                                               `tvatperc`,`lrno`, `lrdate`, `transporter`, `area`,  `totalqty`,`godown`,`addpack`,`addgst`,paycompdt,
                                               `purcode`,`billamt`,username, usertime, `totadv`, `totbal`,architect,salesman,ntprint,duedt,`archno`,`add1`,`add2`,`add3`,
                                                `commby`, `commperc`, `commsqft`, `archit_amt`)
                                      VALUES('$mvouch', '$vouchdt', '$newvoucher', '$mvouch', '$mono', '$party', '$paidby', '$purcode',
                                             '$rem1', '$rem2', '$mcashvouch', '$cartvouch', '$cartpaid', '$totdisc','$grossamt', '$totvat','$packby','$mobile','$ldiscperc',
                                             '$tvatperc', '$lrno', '$lrdate', '$transporter', '$area', '$totalqty','$godown','$addpack','$addgst','$paycompdt',
                                             '$purcode','$totbillamt','$username', '$usertime', '$totadv', '$totbal','$architect','$salesman','$ntprint','$duedt',
                                             '$archno', '$add1', '$add2', '$add3', '$commby', '$commperc', '$commsqft', '$tsuppamt') ") or die(mysqli_error($conn));

                //            $_SESSION['print_voucher'] = $mvouch;
            } else {
                mysqli_query($conn, "UPDATE `$maindb` SET  `vouchdt`='$vouchdt',  `invno`='$mvouch', `mono`='$mono', `party`='$party', `paidby`='$paidby', paycompdt='$paycompdt',
                                         packby='$packby', `rem1`='$rem1', `rem2`='$rem2', `totdisc`='$totdisc',`grossamt`='$grossamt', cartpaid='$cartpaid',
                                         `debitac`='$purcode',`purcode`='$purcode', mobile='$mobile',`cashvouch`='$mcashvouch', `cartvouch`='$cartvouch',totvat='$totvat',`godown`='$godown', 
                                         `billamt`='$totbillamt', ldiscperc='$ldiscperc', lrno = '$lrno', lrdate = '$lrdate', transporter = '$transporter', 
                                          area = '$area', tvatperc='$tvatperc', `totadv`='$totadv', `totbal`='$totbal',  `username`='$username',`addpack`='$addpack',`addgst`='$addgst', 
                                         `totalqty`='$totalqty', `usertime`='$usertime',`architect`='$architect',`salesman`='$salesman' ,`ntprint`='$ntprint',
                                         `duedt`='$duedt', `archno`='$archno', `add1`='$add1', `add2`='$add2', `add3`='$add3', `archit_amt`='$tsuppamt',
                                         `commby`='$commby', `commperc`='$commperc', `commsqft`='$commsqft'  WHERE `vouchno` = '$mvouch' ") 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();
        }
    }
}

$advrecp = 0;

if ($addflag != 1) {

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

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

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

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

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

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

    ///////////////  payment recd. part

    $bsett = mysqli_query($conn, "SELECT SUM(setoff) AS setoff FROM `billsett` WHERE  `party`= '$accode' AND `yearno` = '$myyear' 
                                         AND `vouchno`='$getvouch' AND `type`='R' ") or die(mysqli_error($conn));
    $fsett = mysqli_fetch_object($bsett);
    $recd = $fsett->setoff;
    $recpstring = "";
    if ($recd > 0) {
        $recpstring = "showrecp_fr.php?vouchno=$getvouch";
    }

    $balance = $get['billamt'] - $recd;

    if ($balance > 0) {
        $badv = mysqli_query($conn, "SELECT * FROM `bankrecp` WHERE party = '$accode' and 
                                        vouchno not in (select bnkvouch from billsett where source = 'BR') ") or die(mysqli_error($conn));
        $advno = mysqli_num_rows($badv);
        if ($advno > 0) {
            $advrecp = 1;
            $bfet = mysqli_fetch_array($badv);
            $advvouch = $bfet['vouchno'];

            $callstring = "bankrecp.php?mode=edit&vouchno=$advvouch";
        } else {
            $cadv = mysqli_query($conn, "SELECT * FROM `cashrecp` WHERE party = '$accode' and 
                                         vouchno not in (select bnkvouch from billsett where source = 'CR') ") or die(mysqli_error($conn));
            $advno = mysqli_num_rows($cadv);
            if ($advno > 0) {
                $advrecp = 1;
                $cfet = mysqli_fetch_array($cadv);

                $advvouch = $cfet['vouchno'];

                $callstring = "cashrecp.php?mode=edit&vouchno=$advvouch";
                //                browse($callstring);
            } else {
                $advrecp = 0;
            }
        }
    }
}

if (isset($_GET["delete"])) {
    mysqli_query($conn, "LOCK TABLES `$maindb` WRITE, `$trandb` WRITE, `$stkdb` WRITE, `$trandb2` WRITE, `$trandb3` 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, "$trandb2", "$delcond2", "$file?mode=last");
    delnew($zdb, "$trandb3", "$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" type="text/javascript"></script>
<script src="MyScript/checkdate.js" type="text/javascript"></script>
<!--<script>
    $(document).ready(function () {
      
    })
</script>-->

</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-12">
                            <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-12">
                            <input type="date" value="<?= $zStartDate ?>" style="width: 1px;border: none" class="zstdate">
                            <input type="date" value="<?= $zEndDate ?>" style="width: 1px;border: none" class="zenddate">
                            <input type="hidden" class="form-control form commperc" name="commperc" value="<?php echo ($addflag != 1) ? $get["commperc"] : ""; ?>">
                            <input type="hidden" class="form-control form commsqft" name="commsqft" value="<?php echo ($addflag != 1) ? $get["commsqft"] : ""; ?>">
                            <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-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Voucher</label>
                            </div>
                            <div class="col-lg-1 col-md-2 col-sm-2 col-xs-2 pad">
                                <input type="text" name="vouchno" class="form-control vouchno" id="vouchno" value="<?php echo ($addflag != 1) ? $get['vouchno'] : $qvouch ?>" readonly>
                                <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 addflg" name="addflg" 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" name="cartvouch" value="<?php echo ($addflag != 1) ? $get["cartvouch"] : ""; ?>">
                                <input type="hidden" class="form-control form canc_flag" name="" value="<?php echo ($addflag != 1) ? $get["canc_flag"] : ""; ?>">
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-2 col-xs-3 text-right pad">
                                <label class="label-control marg">Date</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-3 col-xs-4 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>

                        <div class="row">
                            <div class="col-lg-1 col-md-1 col-sm-2 col-xs-2  pad text-right">
                                <label class="label-control marg">M/s.(BIll To)</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-7 col-xs-9  pad">
                                <input list='party' name='party' value="<?php echo ($addflag != 1 ) ? $lparty['name'] : '' ?>" class='memname form-control form ' autocomplete="off">
                                <datalist id='party' char="#">
                                    <option value=''></option>
                                    <?php
                                    $getname = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` where grpcode = '040' order by name") or die(mysqli_error($conn));
                                    while ($fetname = mysqli_fetch_array($getname)) {
                                        $name = $fetname['name'];
                                        echo "<option value='$name'>";
                                    }
                                    ?>
                                </datalist>
                            </div>
                        </div>

                        <!-- <div class="row">
                            <div class="col-lg-1 col-md-1 col-sm-2 col-xs-2  pad text-right">
                                <label class="label-control marg">Name on Invoice</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-7 col-xs-9  pad">
                                <input type="text" name="ntprint" class="form-control form ntprint" value="<?php echo ($addflag != 1) ? $get['ntprint'] : ""; ?>">
                            </div>
                        </div> -->

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

                            <div class="col-lg-1 col-md-1 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Invoice</label>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-3 col-xs-4 pad">
                                <input type="text" name="invno" class="form-control form invno" value="<?php echo ($addflag != 1) ? $get['invno'] : "$qvouch"; ?>" readonly>
                            </div>
                        </div>

                        <div class="row">

                            <div class="col-lg-1 col-md-1 col-sm-2 col-xs-2 text-right pad ">
                                <label class="label-control  marg">Address(Ship To)</label>
                            </div>
                            <div class="col-lg-3 col-md-2 col-sm-3 col-xs-3  pad">
                                <input type="text" name="add1" class="form-control form add1" value="<?php echo ($addflag != 1) ? $get['add1'] : ""; ?>">
                                <input type="text" name="add2" class="form-control form add2" value="<?php echo ($addflag != 1) ? $get['add2'] : ""; ?>">
                                <input type="text" name="add3" class="form-control form add3" value="<?php echo ($addflag != 1) ? $get['add3'] : ""; ?>">
                            </div>

                        </div>

                        <div class="row">
                            <div class="col-lg-1 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Architect</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-7 col-xs-9  pad">
                                <select class="form-control form architect select2" id="architect" name="architect" style="width: 100%">
                                    <option value="<?php echo ($addflag != 1) ? $larchitect["accode"] : ""; ?>"><?php echo ($addflag != 1) ? $larchitect["name"] : ""; ?></option>
                                    <?php
                                    //                                    do not remove this condition.Talk to Fairoz Sir first.
                                    //                                    if ($addflag == 1) {
                                    $garchitect = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `grpcode`='021' order by name") or die(mysqli_error($conn));
                                    while ($architect = mysqli_fetch_array($garchitect)) {
                                        echo "<option value='$architect[accode]'>$architect[name]</option>";
                                    }
                                    //                                    }
                                    ?>
                                </select>

                            </div>

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

                            <div class="col-lg-1 col-xs-2 pad text-right">
                                <label class="label-control marg">By</label>
                            </div>
                            <div class="col-lg-1 col-xs-4 pad">
                                <select id="commby" name="commby" class="form-control form select2 commby" >
                                    <option value=""></option>
                                    <option 
                                    <?php
                                    if ($get['commby'] == 'S') {
                                        echo "selected='selected'";
                                    }
                                    ?>  value="S">Sqft</option>

                                    <option <?php
                                    if ($get['commby'] == 'P') {
                                        echo "selected='selected'";
                                    }
                                    ?> value="P">Percentage</option>


                                </select>
                            </div>

                        </div>
                        <div class="row">
                            <div class="col-lg-1 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Sales Executive</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-7 col-xs-9  pad">

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

                                    <option value="<?php echo ($addflag != 1) ? $lsale["accode"] : "$saleexec"; ?>"><?php echo ($addflag != 1) ? $lsale["name"] : "$username"; ?></option>
                                    <?php
                                    //                                    do not remove this condition.Talk to Fairoz Sir first.
                                    if ($usertype == 1) {
                                        $gsales = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE grpcode = '040' order by name") or die(mysqli_error($conn));
                                        while ($sales = mysqli_fetch_array($gsales)) {
                                            echo "<option value='$sales[accode]'>$sales[name]</option>";
                                        }
                                    }
                                    ?>
                                </select>
                            </div>

                        </div>

                        <div class="row">
                            <div class="col-lg-1 col-xs-2 pad text-right">
                                <label class="label-control marg">Paid By</label>
                            </div>
                            <div class="col-lg-1 col-xs-4 pad">
                                <select id="paidby" name="paidby" class="form-control form select2 paidby" required>
                                    <option 
                                    <?php
                                    if ($get['paidby'] == 'C') {
                                        echo "selected='selected'";
                                    }
                                    ?> value="C">Cash</option>

                                    <option <?php
                                    if ($get['paidby'] == 'R') {
                                        echo "selected='selected'";
                                    }
                                    ?> value="R">Credit</option>


                                </select>
                            </div>
                            <div class="col-lg-2 col-xs-4 pad text-right">
                                <button type='button' class='btn btn-primary sale form' style='margin-left: 20px;' id='btn-sale'>Granite / Marble Details</button>
                            </div>
                            <div class="col-lg-2 col-xs-4 pad text-right">
                                <!--<button type='button' class='btn btn-primary sale form' style='margin-left: 20px;' id='btn-sale'>Granite / Marble Details</button>-->
                                <td class=" buttonform tooltip-bottom" id="hprint" style="display: <? echo $printdisabled ?>" data-toggle="tooltip" data-placement="top" title="" data-original-title="Print">
                                    <a id='print' class="btn btn-pad btn-square " style="background-color:#5BC0DE;" href="granitemarble_print.php?vouchno=<?= $qvouch . $para; ?>" target="_blank">
                                        <p class="" style="color:#ffffff"> Print Granite / Marble Details</p>
                                    </a>
                                </td>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-3 col-xs-5  pad text-right">
                                <label class="label-control marg">Due Date</label>
                            </div>
                            <div class="col-lg-1 col-md-2 col-sm-3 col-xs-3  pad">
                                <input type="date" name="duedt" class="form-control form duedt" value="<?php echo ($addflag != 1) ? $get['duedt'] : ""; ?>">
                            </div>
                        </div>



                        <div class="table-responsive">
                            <table class="table-striped table-condensed table-bordered tab" width="100%">
                                <thead class="mySearchTr">
                                    <tr style="font-size: 12px;">
                                        <th style="width: 1%"></th>
                                        <th style="width: 2%">Sr. No.</th>
                                        <th style='width: 4%' class="text-right">Qty.</th>
                                        <th style='width: 4%'>Unit</th>
                                        <th style="width: 9%;">Size</th>
                                        <th style='width: 5%' class="text-right">Sq.Ft.</th>
                                        <th style='width: 4%'>Cal By</th>
                                        <th style='width: 5%' class="text-right">Rate</th>
                                        <th style='width: 8%' class="text-right">Amount</th>
                                        <th style='width: 15%' class="text-left">Description</th>
                                        <th style='width: 4%' class="text-left">Delivery</th>
                                        <th style='width: 2%' class="text-left">Chl#</th>
                                        <th style='width: 7%' class="text-left">Vendor</th>
                                        <th style='width: 6%' class="text-left">Code</th>
                                        <th style='width: 4%' class="text-left">Mann. CP</th>
                                        <th style='width: 3%' class="text-left">CP</th>
                                        <th style='width: 12%' class="text-left">Supplier</th>
                                        <th style='width: 5%' class="text-left">Purchase</th>
                                        <?php
                                        if ($addflag != 1) {
                                            ?>
                                                            <!--<th style='width: 2%' class="text-center">Purchase</th>-->
                                            <?php
                                        }
                                        ?>
                                    </tr>
                                </thead>
                                <tbody class="tbody">
                                    <?php
                                    if ($addflag != 1) {
                                        $qry = mysqli_query($conn, "SELECT * FROM  `$trandb` WHERE vouchno='$getvouch' ORDER BY srno") or die(mysqli_error($conn));
                                        $ctr = 0;
                                        $salevouch = $getvouch;
                                        while ($row = mysqli_fetch_array($qry)) {

                                            $getpd = mysqli_query($conn, "SELECT accode,name FROM `accmast` WHERE `accode`= '$row[mansupp]'") or die(mysqli_error($conn));
                                            $lpd = mysqli_fetch_array($getpd);


                                            $itemname = mysqli_real_escape_string($conn, $row['itemname']);
                                            $size = mysqli_real_escape_string($conn, $row["size"]);

                                            $sqft = $row['sqft'];
                                            $qty = $row['qty'];

                                            if ($row['calby'] == "P") {
                                                $calname = "Pc";
                                            } elseif ($row['calby'] == "S") {
                                                $calname = "Sq.Ft.";
                                            } elseif ($row['calby'] == "B") {
                                                $calname = "Box";
                                            } else {
                                                $calname = "";
                                            }
                                            $delchal = "";
                                            if ($row['delchal'] == 1) {
                                                $delchal = "checked";
                                            }

                                            $puramt = 0;

                                            if ($calby == 'S') {
                                                $getcost = mysqli_query($conn, "SELECT supplier, purvouch, sum(`recdsqft`) as recd, recdcalby, `purcost` FROM `salepurch` 
                                                                WHERE `itemname`='$itemname' and size = '$size' and salevouch = '$salevouch' ") or die(mysqli_error($conn));
                                            } else {
                                                $getcost = mysqli_query($conn, "SELECT supplier, purvouch, sum(`recdqty`) as recd,  recdcalby, `purcost`  FROM `salepurch` 
                                                                WHERE `itemname`='$itemname' and size = '$size' and salevouch = '$salevouch' ") or die(mysqli_error($conn));
                                            }

                                            $fetcost = mysqli_fetch_array($getcost);
                                            $purcost = $fetcost['purcost'];
                                            $purvouch = $fetcost['purvouch'];
                                            $supplier = $fetcost['supplier'];
                                            $recdcalby = $fetcost['recdcalby'];

                                            $qsupp = mysqli_query($conn, "SELECT `name` FROM `accmast` where accode = '$supplier' ") or die(mysqli_error($conn));
                                            $fsupp = mysqli_fetch_array($qsupp);
                                            $suppname = $fsupp['name'];

                                            if ($recdcalby == 'S') {
                                                $puramt = $purcost * $sqft;
                                            } else {
                                                $puramt = $purcost * $qty;
                                            }
                                            $puramt = round($puramt, 0);

                                            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' class='form-control form text-right qty'     name='qty_$ctr' value='$row[qty]'></td>";
                                            //                                            Echo "<td><input type='text' class='form-control form unit'               name='unit_$ctr'  value='$row[unit]'></td>";
                                            //                                            Echo "<td><input type='text' class='form-control form size'            name='size_$ctr'  value='$row[size]'></td>";
                                            echo "<td>";
                                            echo "<input list='unit' name='unit_$ctr' class='unit form-control form ' autocomplete='off' value='$row[unit]'> ";
                                            echo "<datalist id='unit' char='#'>";
                                            echo "<option>";

                                            $mun = mysqli_query($conn, "SELECT `unit` FROM `product` group by unit") or die(mysqli_error($conn));

                                            while ($tun = mysqli_fetch_array($mun)) {
                                                $unname = $tun['name'];
                                                echo "<option value='$unname'>";
                                            }
                                            echo "</datalist>";
                                            echo "</td>";
                                            echo "<td>";
                                            echo "<input list='size' name='size_$ctr' class='size form-control form ' autocomplete='off' value='$row[size]'> ";
                                            echo "<datalist id='size' char='#'>";
                                            echo "<option>";

                                            $msi = mysqli_query($conn, "SELECT `name` FROM `size` group by name") or die(mysqli_error($conn));

                                            while ($tsi = mysqli_fetch_array($msi)) {
                                                $szname = $tsi['name'];
                                                echo "<option value='$szname'>";
                                            }
                                            echo "</datalist>";
                                            echo "</td>";
                                            echo "<td><input type='text' class='form-control form text-right sqft'     name='sqft_$ctr' value='$row[sqft]'></td>";

                                            echo "<td>";
                                            echo "<select name='calby_$ctr' class='form-control form calby'>";
                                            echo "<option value='$row[calby]'>$calname</option>";
                                            echo "<option value='P'>Pc</option>";
                                            echo "<option value='S'>Sq.Ft.</option>";
                                            echo "<option value='B'>Box</option>";
                                            echo "</select>";
                                            echo "</td>";

                                            echo "<td><input type='text' class='form-control form text-right rate'    name='rate_$ctr'  value='$row[rate]'></td>";
                                            echo "<td><input type='text' class='form-control form text-right amount'  name='amount_$ctr'  value='$row[amount]' >
                                                      <input type='hidden' class='form-control form suppamt' name='suppamt_$ctr' value='$row[suppamt]' ></td> ";

                                            echo "<td>";
                                            echo "<input list='itemname' name='itemname_$ctr' class='itemname form-control form ' autocomplete='off' value='$row[itemname]'> ";
                                            echo "<datalist id='itemname' char='#'>";
                                            echo "<option>";

                                            $mit = mysqli_query($conn, "SELECT `name` FROM `product` group by name") or die(mysqli_error($conn));

                                            while ($tit = mysqli_fetch_array($mit)) {
                                                $itname = $tit['name'];
                                                echo "<option value='$itname'>";
                                            }

                                            echo "</datalist>";
                                            echo "</td>";
                                            echo "<td><input type='date' class='form-control form delivery_date'  name='delivery_date_$ctr'  value='$row[delvdate]' ></td>";
                                            echo "<td><input type='number' class='form-control form delchal'  name='delchal_$ctr' value='$row[delchal]' ></td>";

                                            echo "<td>";
                                            echo "<select class='form-control form mansupp select' name='mansupp_$ctr'>";
                                            echo "<option value='$lpd[accode]'>$lpd[name]</option>";
                                            $getpd12 = mysqli_query($conn, "SELECT accode,name FROM `accmast` WHERE `grpcode`='009' order by name") or die(mysqli_error($conn));
                                            while ($row12 = mysqli_fetch_array($getpd12)) {
                                                echo "<option value='$row12[accode]'>$row12[name]</option>";
                                            }
                                            echo "</select>";
                                            echo "</td>";
                                            echo "<td><input type='text' class='form-control form sldesign'  name='sldesign_$ctr' value='$row[sldesign]'></td> ";

                                            echo "<td><input type='text' class='form-control form text-right mancp'  name='mancp_$ctr' value='$row[mancp]'></td> ";
                                            echo "<td><input type='number' class='form-control form text-right puramt'  name='puramt_$ctr' value='$puramt' readonly></td>";
                                            echo "<td><input type='text' class='form-control form suppname'  name='suppname_$ctr' value='$suppname' readonly ></td> ";
                                            echo "<td><input type='text' class='form-control form purvouch'  name='purvouch_$ctr' value='$purvouch' 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'></td>
                                            <td><input type='text' name='qty_0' class='qty text-right form-control form' value=''></td>
                                            <td>
                                                <input list='unit' name='unit_0' class='unit form-control form' value=''>
                                                <datalist id='unit' char="#">
                                                    <option value=''></option>
                                                    <?php
                                                    $mun = mysqli_query($conn, "SELECT `unit` FROM `product` group by unit") or die(mysqli_error($conn));

                                                    while ($tun = mysqli_fetch_array($mun)) {
                                                        $unname = $tun['name'];
                                                        echo "<option value='$unname'>";
                                                    }
                                                    ?>
                                                </datalist>
                                            </td>


                                            <td>
                                                <input list='size' name='size_0' class='size form-control form' value=''>
                                                <datalist id='size' char="#">
                                                    <option value=''></option>
                                                    <?php
                                                    $msi = mysqli_query($conn, "SELECT `name` FROM `size` group by name") or die(mysqli_error($conn));

                                                    while ($tsi = mysqli_fetch_array($msi)) {
                                                        $szname = $tsi['name'];
                                                        echo "<option value='$szname'>";
                                                    }
                                                    ?>
                                                </datalist>
                                                <!--<input type='text' name='size_0' class='size form-control form' value='' >-->
                                            </td>
                                            <td><input type='text' class='form-control form text-right sqft' name='sqft_0' value='0'></td>

                                            <td>
                                                <select name="calby_0" class="form-control form select calby">
                                                    <option value='P'>Pc</option>
                                                    <option value='S'>Sq.Ft.</option>
                                                    <option value='B'>Box</option>
                                                </select>
                                            </td>
                                            <td><input type='text' name='rate_0' class='rate text-right form-control form' value=''></td>
                                            <td><input type='text' name='amount_0' class='amount text-right form-control form' value=''>
                                                <input type='hidden' name='suppamt_0' class='suppamt form-control form' value=''></td>


                                            <td>
                                                <input list='itemname' name='itemname_0' class='itemname form-control form' value=''>
                                                <datalist id='itemname' char="#">
                                                    <option value=''></option>
                                                    <?php
                                                    $mit = mysqli_query($conn, "SELECT `name` FROM `product` group by name") or die(mysqli_error($conn));

                                                    while ($tit = mysqli_fetch_array($mit)) {
                                                        $itname = $tit['name'];
                                                        echo "<option value='$itname'>";
                                                    }
                                                    ?>
                                                </datalist>
                                            </td>
                                            <td><input type='date' name='delivery_date_0' class='delivery_date form-control form' value=''></td>
                                            <td><input type='number' name='delchal_0' class='delchal form-control form' value=''></td>
                                            <td>
                                                <select name="mansupp_0" class="form-control form select mansupp">
                                                    <option value=''></option>
                                                    <?php
                                                    $getpd12 = mysqli_query($conn, "SELECT accode,name FROM `accmast` WHERE `grpcode`='009' order by name") or die(mysqli_error($conn));
                                                    while ($row12 = mysqli_fetch_array($getpd12)) {
                                                        echo "<option value='$row12[accode]'>$row12[name]</option>";
                                                    }
                                                    ?>
                                                </select>
                                            </td>

                                            <td><input type='text' name='sldesign_0' class='sldesign form-control form' value=''></td>
                                            <td><input type='number' name='mancp_0' class='mancp text-right form-control form' value='0'></td>
                                            <td colspan="3"></td>
                                            <!--<td><button type='button' class='btn btn-primary purchase' style='margin-left: 20px;' id="btn-purchase">Purchase</button></td>-->
                                            <!--<td><button type='button' class='btn btn-primary purchase' id="btn-purchase">Ali</button></td>-->
                                        </tr>
                                        <?php
                                    }
                                    ?>
                                <input type="hidden" id="items" name="items" value="<?php echo ($addflag != 1) ? $ctr : 1; ?>">

                                </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" class="mandatoryId" name="manId" value="">-->
                        </div>
                        <div class="col-lg-12 col-xs-12 pad">


                            <div class="col-lg-12 col-xs-12 pad">
                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-8 pad"></div>
                                    <div class="col-lg-2 col-xs-7 label-control text-right marg">Total Qty.</div>
                                    <div class="col-lg-2 col-xs-5 pad">
                                        <input type="number" step="any" name="totalqty" class="form-control form text-right totalqty" value="<?php echo ($addflag != 1) ? $get['totalqty'] : "0"; ?>" readonly>
                                    </div>
                                    <div class="col-lg-10 col-xs-7 pad text-right">
                                        <label class="label-control marg">Subtotal</label>
                                    </div>
                                    <div class="col-lg-2 col-xs-5 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-5 pad"></div>
                                    <div class="col-lg-3 col-xs-5 pad text-right">
                                        <label class="label-control marg text-right">Less Discount</label>
                                    </div>
                                    <div class="col-lg-1 col-xs-3 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 col-xs-1 pad text-right">
                                        <label class="label-control marg">%</label>
                                    </div>
                                    <div class="col-lg-2 col-xs-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-4 col-xs-7 pad text-right">
                                        <label class="label-control marg">Sale Expense</label>
                                    </div>
                                    <div class="col-lg-2 col-xs-5 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"; ?>" readonly>
                                    </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-4 col-xs-7 pad text-right">
                                        <label class="label-control marg">Add GST</label>
                                    </div>
                                    <div class="col-lg-2 col-xs-5 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-1 col-xs-1 pad text-left">
                                        <?php if ($recpstring != "") { ?>
                                            <a href="<?= $recpstring ?>" target="_blank" name="" tabindex="-1">Payment Recd.</a>
                                        <?php } else { ?>
                                            Payment Recd.
                                        <?php } ?>
                                    </div>
                                    <div class="col-lg-1 col-xs-2 pad">
                                        <input type="text" name="recd" style="color:blue" class="form-control form text-right" value="<? echo ($addflag != 1) ? $recd : ""; ?> " readonly>
                                    </div>
                                    <div class="col-lg-1 col-xs-1 pad text-right">Balance</div>
                                    <div class="col-lg-1 col-xs-2 pad">
                                        <input type="text" name="balance" style="color:red" class="form-control form text-right" value="<? echo ($addflag != 1) ? $balance : ""; ?> " readonly>
                                    </div>
                                    <?php if ($advrecp > 0) { ?>
                                        <div class="col-lg-2 col-xs-2 text-right pad">
                                            <a href="<?= $callstring ?>" target="_blank" class="btn btn-primary advrecp" name="advrecp" tabindex="-1">Advance Receipt</a>
                                        </div>
                                    <?php } else { ?>
                                        <div class="col-lg-2 pad"></div>
                                    <?php } ?>
                                    <div class="col-lg-4 col-xs-4 pad text-right">
                                        <label class="label-control marg">Net Amount</label>
                                    </div>
                                    <div class="col-lg-2 col-xs-4 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-4 col-xs-7 pad text-right">
                                                                        <label class="label-control marg"  style="color: green;font-weight: bolder;">Payment Complete</label>
                                                                    </div>
                                                                    <div class="col-lg-2 col-xs-7 pad">
                                                                        <input type="date" name="paycompdt" class="form-control form paycompdt" value="<? echo ($addflag != 1) ? $get["paycompdt"] : ""; ?>" style="color: green;font-weight: bold">
                                                                    </div>
                                                                </div>-->
                            </div>


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

                                <div class="table-responsive" style="width:100%">
                                    <table class="table table-striped table-condensed table-bordered">
                                        <thead style="background: #8F4131;">
                                            <tr>
                                                <th width="5%"></th>
                                                <th width="5%" class='text-right'>Sr. No.</th>
                                                <th width="15%" class='text-right'>Sale Expense</th>
                                                <th width="60%">Description</th>
                                                <th width="15%" class='text-right'>Paid</th>
                                            </tr>
                                        </thead>
                                        <tbody class="tbodyexp">
                                            <?php
                                            if ($addflag != 1) {
                                                $ctr2 = 0;
                                                $gettran2 = mysqli_query($conn, "SELECT * FROM `$trandb2` WHERE `vouchno`='$get[vouchno]' ORDER BY `srno`") or die(mysqli_error($conn));
                                                while ($tran2 = mysqli_fetch_array($gettran2)) {
                                                    $gparty = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`='$tran2[descrip]'") or die(mysqli_error($conn));
                                                    $getdesc = mysqli_fetch_array($gparty);
                                                    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='srno2_$ctr2' value='$tran2[srno]'></td>";
                                                    echo "<td><input type='number' class='form-control form text-right samount' name='samount_$ctr2' value='$tran2[amount]'></td>";
                                                    echo "<td>";
                                                    echo "<select class='form-control form descrip' name='descrip_$ctr2' style='width:100%'>";
                                                    echo "<option value='$getdesc[accode]'>$getdesc[name]</option>";
                                                    $gexp = mysqli_query($conn, "SELECT * FROM `accmast` where `grpcode` = '012' order by name") or die(mysqli_error($conn));
                                                    while ($showexp = mysqli_fetch_array($gexp)) {
                                                        echo "<option value='$showexp[accode]'>$showexp[name]</option>";
                                                    }
                                                    echo "</select>";
                                                    echo "</td>";
                                                    echo "<td><input type='number' class='form-control form text-right eamount' name='tamount_$ctr2' value='$tran2[paid]'></td>";
                                                    echo "</tr >";
                                                    $ctr2++;
                                                }
                                            } else {
                                                $pctr2 = 0;
                                                ?>
                                                <tr>
                                                    <td><i class="fa fa-close remove"></i></td>
                                                    <td><input type="text" class="form-control form text-right srno" name="srno2_<?= $pctr2 ?>" value="1"></td>
                                                    <td><input type="number" step="any" class="form-control form text-right samount" name="samount_<?= $pctr2 ?>" value="0"></td>
                                                    <td>
                                                        <select class="form-control form descrip " name="descrip_<?= $pctr2 ?>" style='width:100%'>
                                                            <option value=""></option>
                                                            <?php
                                                            $getparty = mysqli_query($conn, "SELECT * FROM `accmast` where `grpcode` = '012' order by name") or die(mysqli_error($conn));
                                                            while ($showparty = mysqli_fetch_array($getparty)) {
                                                                echo "<option value='$showparty[accode]'>$showparty[name]</option>";
                                                            }
                                                            ?>
                                                        </select>
                                                    </td>
                                                    <td><input type="number" step="any" class="form-control form text-right eamount" name="tamount_<?= $pctr2 ?>" value="0"></td>
                                                </tr>
                                                <?
                                                $pctr2++;
                                            }
                                            ?>
                                        </tbody>
                                    </table>
                                </div>
                                <div class="col-lg-12 pad">
                                    <button type="button" class="btn btn-success btn-square form" id="addnew2">
                                        <i class="fa fa-plus" style="color:#ffffff" data-toggle='tooltip' title='Add Row'></i>
                                    </button>
                                    <input type="hidden" id="items2" name="items2" value="<?php echo ($addflag != 1) ? $ctr2 : $pctr2; ?>" />
                                </div>
                                <div class="col-lg-12 col-xs-12 pad">
                                    <div class="col-lg-4 col-xs-3 pad text-right">
                                        <label class="label-control marg " style="color:red">Purchase Expense</label>
                                    </div>
                                    <div class="col-lg-1 col-xs-7 pad">
                                        <input type="text" name="cartpaid" style="color:red" class="form-control form cartpaid text-right" value="<? echo ($addflag != 1) ? $get["cartpaid"] : ""; ?>" readonly>

                                    </div>
                                </div>

                            </div>
                            <div class="modal fade" id="modelWindow" role="dialog">
                                <div class="modal-dialog modal-lg vertical-align-center">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                                            <h4 class="modal-title">Granite / Marble Details</h4>
                                        </div>
                                        <div class="modal-body">
                                            <div class="table-responsive">
                                                <table class="table-striped table-condensed table-bordered tab" width="100%">
                                                    <thead class="mySearchTr">
                                                        <tr>
                                                            <th style="width: 2%"></th>
                                                            <th style="width: 3%">Sr. No.</th>
                                                            <th style="width: 40%">Description</th>
                                                            <th style="width: 10%" class="text-right">Qty.</th>
                                                            <th style="width: 10%">Size</th>
                                                            <th style="width: 10%" class="text-right">Sq.Ft.</th>
                                                            <th style="width: 25%">Remark</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody class="tbody2">
                                                        <?php
                                                        if ($addflag != 1) {
                                                            $qry3 = mysqli_query($conn, "SELECT * FROM $trandb3 WHERE vouchno = '$getvouch' ORDER BY srno") or die(mysqli_error($conn));
                                                            $ctr3 = 0;
                                                            while ($row3 = mysqli_fetch_array($qry3)) {
                                                                $gparty = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`='$row3[descrip]'") or die(mysqli_error($conn));
                                                                $getdesc = mysqli_fetch_array($gparty);

                                                                echo "<tr>";
                                                                echo "<td><i class='fa fa-close remove' style='display:none;'></i></td>";
                                                                echo "<td><input type='text' name='srno3_$ctr3' class='srno3 form-control  form'  value='$row3[srno]'></td>";
                                                                echo "<td><input type='text' class='form-control form descrip3'     name='descrip3_$ctr3' value='$row3[descrip]'></td>";

                                                                //                                                                Echo "<td>";
                                                                //                                                                Echo "<select class='form-control form descrip3' name='descrip3_$ctr3' style='width:100%'>";
                                                                //                                                                Echo "<option value='$getdesc[accode]'>$getdesc[name]</option>";
                                                                //                                                                $gexp = mysqli_query($conn, "SELECT accode,name FROM `accmast` where `grpcode` = '012' order by name")or die(mysqli_error($conn));
                                                                //                                                                while ($showexp = mysqli_fetch_array($gexp)) {
                                                                //                                                                    Echo "<option value='$showexp[accode]'>$showexp[name]</option>";
                                                                //                                                                }
                                                                //                                                                Echo "</select>";
                                                                //                                                                Echo "</td>";

                                                                echo "<td><input type='text' class='form-control form text-right qty3'     name='qty3_$ctr3' value='$row3[qty]'></td>";
                                                                echo "<td><input type='text' class='form-control form  size3'     name='size3_$ctr3' value='$row3[size]'></td>";
                                                                echo "<td><input type='text' class='form-control form text-right sqft3'     name='sqft3_$ctr3' value='$row3[sqft]'></td>";
                                                                echo "<td><input type='text' class='form-control form remarks3'     name='remarks3_$ctr3' value='$row3[remarks]'></td>";
                                                                echo "</tr>";
                                                                $ctr3++;
                                                            }
                                                        } else {
                                                            //                                                            
                                                            ?>
                                                            <tr>
                                                                <td><i class='fa fa-close remove'></i></td>
                                                                <td><input type='text' name='srno3_0' class='srno3 form-control form' value='1'></td>
                                                                <td><input type='text' name='descrip3_0' class='descrip3 form-control form' value=''></td>

                                                                                <!--                                                                <td>
                                                        <select name="descrip3_0" class="form-control form select descrip3">
                                                                <?php
                                                                //                                                                $gexp = mysqli_query($conn, "SELECT accode,name FROM `accmast` where `grpcode` = '012' order by name")or die(mysqli_error($conn));
                                                                //                                                                while ($showexp = mysqli_fetch_array($gexp)) {
                                                                //                                                                    Echo "<option value='$showexp[accode]'>$showexp[name]</option>";
                                                                //                                                                }    
                                                                ?>
                                                        </select>
                                                        </td>-->
                                                                <td><input type='text' name='qty3_0' class='qty3 form-control form text-right' value='0'></td>
                                                                <td><input type='text' name='size3_0' class='size3 form-control form' value=''></td>
                                                                <td><input type='text' name='sqft3_0' class='sqft3 form-control form text-right' value=''></td>
                                                                <td><input type='text' name='remarks3_0' class='remarks3 form-control form' value=''></td>

                                                            </tr>
                                                            <?php
                                                        }
                                                        ?>
                                        <!--<input type="hidden" id="itemspur" name="itemspur" value="<?php echo ($addflag != 1) ? $ctr : 1; ?>">-->

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

                                        </div>
                                        <div class="modal-footer">
                                            <div class="col-lg-1 pad">
                                                <button type="button" class="btn btn-primary btn-square form" id="sldescadd">
                                                    <i class="fa fa-plus" data-toggle='tooltip' title='Add Row'></i>
                                                </button>
                                                <input type="hidden" id="items3" name="items3" value="<?php echo ($addflag != 1) ? $ctr3 : 1; ?>" />

                                            </div>

                                            <!--<button type="button" data-dismiss="modal" class="form btn btn-default pursave">Save</button>-->
                                        </div>
                                    </div>
                                </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-2 col-xs-3 pad text-left">
                                    <label class="label-control marg">Packed By</label>
                                </div>
                                <div class="col-lg-4 col-xs-7 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-2 col-xs-3 pad text-left">
                                    <label class="label-control marg">Remarks</label>
                                </div>
                                <div class="col-lg-6 col-xs-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-2 col-xs-3 pad text-right"></div>
                                <div class="col-lg-6 col-xs-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>
                </div>
                <div class="col-lg-1 col-md-2 col-sm-2 col-xs-2 pad">

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

                </div>

                <div class="panel panel-default">
                    <div class="panel-body">



                        <?php
                        include("includes/buttsale.php");
                        ?>
                        <!--            <td class=" buttonform tooltip-bottom" id="hprint" style="display: <? echo $printdisabled ?>" data-toggle="tooltip" data-placement="top" title="" data-original-title="Print">
                <img src="MyStyle/pdficon.png" title="Delivery Challan Print" class="btnpdf pdf" style="height:50px;display: <?= $editdisabled ?>" onclick="window.open('deliverychal_pdf.php?vouchno=<?= $qvouch ?>')">                            
            </td>-->

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

                                var usertype = <?= $usertype ?>;
                                if (usertype == 3) {
                                    $("#hedit").hide();
                                }
                            });
                        </script>


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


    <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</option>
                                <option value="2">Voucher No.</option>
                                <option value="3">Invoice No.</option>
                                <option value="4">Date</option>
                                <option value="5">Architect</option>
                                <option value="6">Sales Executive</option>
                                <option value="7">Amount</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control soperator">
                                <option value="">Type of Search</option>
                                <option value="%">Like</option>
                                <option value="=">Exactly</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control sortBy">
                                <option value="">Sort By</option>
                                <option value="1">Party</option>
                                <option value="2">Voucher No.</option>
                                <option value="3">Invoice No.</option>
                                <option value="4">Date</option>
                                <option value="5">Architect</option>
                                <option value="6">Sales Executive</option>
                                <option value="7">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 No.</th>
                                    <th width="10%">Invoice No.</th>
                                    <th width="10%">Date</th>
                                    <th width="20%">Party</th>
                                    <th width="20%">Architect</th>
                                    <th width="20%">Sales Executive</th>
                                    <th width="15%" style="text-align:right">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>