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

$formname = 'ITEM NEW';
$maindb = 'item';
$trandb = 'itemsub';
$proddb = 'product';
$grpdb = 'prodgrp';
$proddbtran = 'prodtran';

$printfile = "itemlst.php";
$invprintfile = "";
$file = 'item.php';
$trandbexist = 1;
$keyfld = "code";
$focusfield = "code";

$zseries = $_SESSION['user_series'];
$keycond = "";
$msource = "";

$myear = $_SESSION["tit_" . $dbname];
//browse($myear);

$gppdb = 'cepheisy_gpp_1_' . $myear;
$poidb = 'cepheisy_poi_1_' . $myear;
//browse($poidb);
$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
$usertype = $_SESSION["usertype"];

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

if (isset($_POST["submit"])) {
    $a = 1;
    /*     * Start sale exist check** */
    if ($_GET["mode"] == 'true') {
        $checkSaleExist = mysqli_query($conn, "SELECT `code` FROM `$maindb` WHERE `code`='$qvouch' ")or die(mysqli_error($conn));
        $checkSaleExt = mysqli_num_rows($checkSaleExist);
        if ($checkSaleExt > 0) {
            $a = 0;
        }
    }
    /** End sale exist check** */
    $series = $zseries;
//        $id         = $_POST[id];
    $qvouch = $_POST['code'];
//    $code = $_POST[code];
    $name = $_POST['name'];
    $size = $_POST['size'];
//    $comp = $_POST['cmbcomp'];
    $unit = $_POST['unit'];
    $itemgrp = $_POST['itemgrp'];
    $levelno = $_POST['levelno'];
    $nameprin = $_POST['nameprin'];
    $namecstmprin = $_POST['namecstmprin'];
    $nameprtyprin = $_POST['nameprtyprin'];
    $opstock = $_POST['opstock'];
    $minstock = $_POST['minstock'];
    $maxstock = $_POST['maxstock'];
    $taxperc = $_POST['taxperc'];
    $notinprint = $_POST['notinprint'];
    $hsncode = $_POST['hsncode'];
    $sizeprod = $_POST['sizeprod'];
    $cutavg = $_POST['cutavg'];
    $ratepcs = $_POST['ratepcs'];
    $length = $_POST['length'];
    $chest = $_POST['chest'];
    $namesize = $_POST['namesize'];
    $makeinpoi = $_POST['makeinpoi'];
    $makeingpp = $_POST['makeingpp'];
//    $orderinv = $_POST['orderinv'];


    $count = $_POST['items'];


    if (empty($name)) {
        browse("Name Cannot Be Empty");
        $a = 0;
    }

    if (isset($_POST["name"])) {
        $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE `name`= '$name' and size = '$size' AND code != '$qvouch'") or die(mysqli_error($conn));
        if (mysqli_num_rows($result) > 0) {
            $a = 0;
            browse("Name + Size Already Exist");
            header("refresh: ; $file?vouchno=$_GET[vouchno]");
        }
    }

    if ($a == 1) {
        if ($addflag == 1) {
            $gen1 = mysqli_query($conn, "SELECT MAX(code) AS maxcode FROM `$maindb` 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($poidb);
        mysqli_query($conn, "LOCK TABLES `$maindb` WRITE, `openstk` WRITE, minmax WRITE, $poidb.$maindb WRITE, $gppdb.$proddb WRITE, $gppdb.`$grpdb` WRITE, $poidb.`itemgrp` WRITE, $gppdb.$proddbtran WRITE, $poidb.unit WRITE, itemgrp WRITE");

        
        $getitemgrp = mysqli_query($conn, "SELECT code, name FROM `itemgrp` WHERE code='$itemgrp'") or die(mysqli_error($conn));
        $fetitemgrp = mysqli_fetch_array($getitemgrp);
        $itgrpname = $fetitemgrp['name'];
        if ($makeinpoi == '1') {

            if ($namesize != '1') {
                $newname = $name;
            } else {
                $newname = $name . ' - ' . $size;
            }

//        for poi
            $getpoi = mysqli_query($conn, "SELECT * FROM $poidb.`$maindb` WHERE name='$newname'") or die(mysqli_error($conn));
            if (mysqli_num_rows($getpoi) > 0) {
                $fetpoi = mysqli_fetch_array($getpoi);
                $pdpoi = $fetpoi['code'];
            } else {
                $genpoi = mysqli_query($conn, "SELECT MAX(code) AS maxcode FROM $poidb.`$maindb` LIMIT 0,1 ") or die(mysqli_error($conn));
                if (mysqli_num_rows($genpoi) > 0) {
                    $vpoi = mysqli_fetch_assoc($genpoi);
                    $pdpoi = $vpoi["maxcode"] + 1;
                } else {
                    $pdpoi = '1';
                }
                $getpoiunit = mysqli_query($conn, "SELECT code, name FROM $poidb.`unit` WHERE name='$unit'") or die(mysqli_error($conn));
                $fetpoiunit = mysqli_fetch_array($getpoiunit);
                $pdunitpoi = $fetpoiunit['code'];

                $getpoigrp = mysqli_query($conn, "SELECT code, name FROM $poidb.`itemgrp` WHERE name='$itgrpname'") or die(mysqli_error($conn));
                $fetpoigrp = mysqli_fetch_array($getpoigrp);
                $pdgrppoi = $fetpoigrp['code'];
                mysqli_query($conn, "INSERT INTO $poidb.`$maindb`(`code`, `name`, `unit`, `itemgrp`, `nameprin`, `gstperc`, `hsncode`, `grptype`)
                                    VALUES($pdpoi, '$newname', '$pdunitpoi', '$pdgrppoi', '$nameprin', '$taxperc','$hsncode', 'P')") or die(mysqli_error($conn));
            }
        }

        if ($makeingpp == '1') {
//        for gpp

            $getprod = mysqli_query($conn, "SELECT * FROM $gppdb.`$proddb` WHERE name='$name'") or die(mysqli_error($conn));
            if (mysqli_num_rows($getprod) > 0) {
                $fetprod = mysqli_fetch_array($getprod);
                $pdvouch = $fetprod['code'];
            } else {
                $genpd = mysqli_query($conn, "SELECT MAX(code) AS maxcode FROM $gppdb.`$proddb` LIMIT 0,1 ") or die(mysqli_error($conn));
                if (mysqli_num_rows($genpd) > 0) {
                    $vpd = mysqli_fetch_assoc($genpd);
                    $pdvouch = $vpd["maxcode"] + 1;
                } else {
                    $pdvouch = '1';
                }
                $getprodgrp = mysqli_query($conn, "SELECT code, name FROM $gppdb.`$grpdb` WHERE name='$itgrpname'") or die(mysqli_error($conn));
                $fetprodgrp = mysqli_fetch_array($getprodgrp);
                $pdgrpcode = $fetprodgrp['code'];
                mysqli_query($conn, "INSERT INTO $gppdb.`$proddb`(`code`, `name`, `unit`, `prodgrp`)
                                    VALUES($pdvouch, '$name', '$unit', '$pdgrpcode')") or die(mysqli_error($conn));
            }


//        $getpddtl = mysqli_query($conn, "SELECT * FROM $gppdb.`$proddbtran` WHERE code='$pdvouch' and size='$") or die(mysqli_error($conn));
            mysqli_query($conn, "DELETE FROM $gppdb.`$proddbtran` WHERE code='$pdvouch' and size='$size'") or die(mysqli_error($conn));

            mysqli_query($conn, "INSERT INTO $gppdb.`$proddbtran`(`code`, `prodcode`, `size`, `sizeprod`, `cutavg`, `rate`, `length`, `chest`)
                                    VALUES('$pdvouch', '$pdvouch', '$size', '$sizeprod', '$cutavg', '$ratepcs', '$length', '$chest')") or die(mysqli_error($conn));
        }

        if ($addflag == 1) {
            mysqli_query($conn, "INSERT INTO `$maindb`(`code`, `name`, `size`,  `unit`, `itemgrp`, `levelno`, `nameprin`, `namecstmprin`, `nameprtyprin`,`opstock`, `namesize`, `makeingpp`, `makeinpoi`,
                                    `minstock`, `maxstock`, `taxperc`, notinprint ,`hsncode`, `bcode`, `orderinv`, `sizeprod`, `cutavg`, `ratepcs`, `length`, `chest`)
                                    VALUES($qvouch, '$name', '$size', '$unit', '$itemgrp', '$levelno', '$nameprin', '$namecstmprin', '$nameprtyprin','$opstock', '$namesize', '$makeingpp', '$makeinpoi',
                                    '$minstock', '$maxstock', '$taxperc', '$notinprint','$hsncode','$zseries', '$orderinv', '$sizeprod', '$cutavg', '$ratepcs', '$length', '$chest')") or die(mysqli_error($conn));
            $mvouch = $qvouch; //1
        } else {
            mysqli_query($conn, "DELETE FROM `openstk` WHERE `itemname`='$name' and `size`='$size'") or die(mysqli_error($conn));
            $srl = 0;
            for ($i = 0; $i < $count; $i++) {
                $opseries = $_POST["opseries_$i"];
                $opsercode = $_POST["opsercode_$i"];
                $opstk = $_POST["opstk_$i"];
                $srl++;
//                if ($opstk > 0) {
                mysqli_query($conn, "INSERT INTO `openstk`(`id`,`srno`, `itemcode`, `itemname`, `size`, `actsize`, `unit`, `opstk`, `minstk`, `series`)
                            VALUES('', '', '$qvouch', '$name', '$size', '$size', '$unit', '$opstk', '', '$opsercode')") or die(mysqli_error($conn));
//                }
//                mysqli_query($conn, "UPDATE `openstk` set `opstk`='$opstk' where `series`='$opsercode' and `itemname`='$name' and `size`='$size'") or die(mysqli_error($conn));
            }

            $mvouch = $qvouch; //1

            mysqli_query($conn, "UPDATE `$maindb` SET  `name` = '$name', `size` = '$size', `unit` = '$unit', `itemgrp` = '$itemgrp', `namesize`='$namesize',
                    `levelno` = '$levelno', `nameprin` = '$nameprin', `namecstmprin`='$namecstmprin', `nameprtyprin`='$nameprtyprin',`opstock` = '$opstock', `minstock` = '$minstock', `maxstock` = '$maxstock',
                    `taxperc` = '$taxperc', notinprint='$notinprint', `hsncode` = '$hsncode', `bcode`='$zseries', `orderinv`='$orderinv', `makeingpp`='$makeingpp', `makeinpoi`='$makeinpoi',
                    `sizeprod`='$sizeprod', `cutavg`='$cutavg', `ratepcs`='$ratepcs', `length`='$length', `chest`='$chest' WHERE code = '$mvouch' ") or die(mysqli_error($conn));
        }

        ############################## MAIN  - challan part ######################################################
        mysqli_query($conn, "UNLOCK TABLES");

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


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

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

//    $getcompany = mysqli_query($conn, "SELECT * FROM `customer` WHERE `comp`='$get[comp]'") or die(mysqli_error($conn));
//    $gcomp = mysqli_fetch_array($getcompany);

    $getgroup = mysqli_query($conn, "SELECT * FROM `itemgrp` WHERE `code`='$get[itemgrp]'") or die(mysqli_error($conn));
    $group = mysqli_fetch_array($getgroup);
} else {
    $getvouch = '';
    if ($addflag == 0) {
        $getvouch = $_GET[$keyfld];
    } else {
        $getvouch = $qvouch;
    }
    $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE $keyfld < '$getvouch' ORDER BY $keyfld DESC LIMIT 0,1 ") or die(mysqli_error($conn));
    $get = mysqli_fetch_array($result);
    $oldname = $get['name'];
//    $oldsize = $get[size];    
    $oldsize = '';
    $oldunit = $get['unit'];
//    $oldcomp = $get[comp];
    $igrpcode = $get['itemgrp'];
    $oldprin = $get['nameprin'];
    $oldtax = $get['taxperc'];

    $res2 = mysqli_query($conn, "SELECT * FROM `itemgrp` WHERE code = '$igrpcode' ") or die(mysqli_error($conn));
    $geti = mysqli_fetch_array($res2);
    $igrpname = $geti['name'];
}

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

if (isset($_GET["delete"])) {
//    $getitemdtl = mysqli_query($conn, "SELECT * FROM `itemlink` WHERE `itemname` = '$get[name]' and `size` = '$get[size]'") or die(mysqli_error($conn));
    $getitemdtl = mysqli_query($conn, "SELECT * FROM `itemtran` WHERE `itemname` = '$get[name]' and `size` = '$get[size]'") or die(mysqli_error($conn));
    if (mysqli_num_rows($getitemdtl) > 0) {
        browse("Entry Exist in Transaction");
        header("refresh: 1; $file?mode=last");
    } else {
        mysqli_query($conn, "LOCK TABLES `$maindb` WRITE, `itemlink` write");

        $delcond = " code = '$getvouch' ";
        delnew($zdb, "$maindb", "$delcond", "$file?mode=last");

        $delcond1 = " itemname ='$get[name]' AND size='$get[size]' ";
        delnew($zdb, "itemlink", "$delcond1", "$file?mode=last");

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

include("includes/linkshead.php");
if ($addflag != 1) {
    $read = 'readonly';
}
?>
<script src="MyScript/item.js" type="text/javascript"></script>
<script src="MyScript/item_search.js" type="text/javascript"></script>
</head>
<body>
    <div id="preloader">
        <div><img src="assets/img/main.gif"></div>
    </div>
    <form action='' method='POST'>
        <!-- Default box -->
        <div class="row">
            <div class="col-lg-6 pad">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title" style="color :#05B2EA;"><?php
                            Echo $formname;
                            if ($usertype == 1) {
                                ?>
                                    <!--<input type="button" class="btn btn-danger delmulti" value="Delete Multi">-->
                            <?php } ?>
                        </h3>
                        <div class="actions pull-right" style="margin-right: 50px;">
                            <?php
                            $getmseries = mysqli_query($conn, "SELECT `code`, `name` FROM `series` WHERE `code`='$zseries'") or die(mysqli_error($conn));
                            $mseries = mysqli_fetch_array($getmseries);
                            ?>
                            <label class="label-control"><?php Echo $zseries; ?></label>  <label class="label-control"><?php Echo $mseries['name']; ?></label> 
                        </div>
                        <div class="actions pull-right">
                            <i class="fa fa-chevron-down"></i>
                            <i class="fa fa-times"></i>
                        </div>

                    </div>
                    <div class="panel-body">
                        <div class='row'>
                            <div class='col-lg-3 col-md-3 col-sm-3 col-xs-3 pad text-right'>
                                <label class='label-control tmarg'>Name</label>
                            </div>
                            <div class='col-lg-6 col-md-9 col-sm-9 col-xs-9 pad'>
                                <input type='text' class='form-control form name focusfield' name='name' value='<?php echo ($addflag != 1) ? $get['name'] : $oldname; ?>' <?= $read ?> autofocus>
                                <input type='hidden'  name='code' value='<?php echo ($addflag != 1) ? $get['code'] : ""; ?>'>
                                <input type="hidden" name="codehide" id="codehide" value="">
                                <input type="hidden" name="namehide" id="namehide" value="">
                                <input type="hidden" name="sizehide" id="sizehide" value="">
                            </div>
                        </div>
                        <div class='row'>
                            <div class='col-lg-3 col-md-3 col-sm-3 col-xs-3 pad text-right'>
                                <label class='label-control tmarg'>Size</label>
                            </div>
                            <div class='col-lg-2 col-md-2 col-sm-2 col-xs-2 pad'>
                                <input type='text' class='form-control form size' name='size' value='<?php echo ($addflag != 1) ? $get['size'] : $oldsize; ?>'>
                            </div>
                        </div>

                        <div class='row'>
                            <div class='col-lg-3 col-md-3 col-sm-3 col-xs-3 pad text-right'>
                                <label class='label-control tmarg'>Unit</label>
                            </div>
                            <div class='col-lg-2 col-md-2 col-sm-2 col-xs-2 pad'>
                                <input type='text' class='form-control form unit' name='unit' value='<?php echo ($addflag != 1) ? $get['unit'] : $oldunit; ?>'>
                            </div>
                        </div>
                        <div class='row'>
                            <div class='col-lg-3 col-md-3 col-sm-3 col-xs-3 pad text-right'>
                                <label class='label-control tmarg'>Group</label>
                            </div>
                            <div class='col-lg-6 col-md-9 col-sm-9 col-xs-9 pad'>
                                <select  class="select2 form-control form itemgrp" name="itemgrp">
                                    <option value="<?php Echo ($addflag != 1) ? $group['code'] : $igrpcode; ?>"><?php Echo ($addflag != 1) ? $group['name'] : $igrpname; ?></option>
                                    <?php
                                    $getgroup1 = mysqli_query($conn, "SELECT  *  FROM `itemgrp` where code != ''")or die(mysqli_error($conn));
                                    while ($grop = mysqli_fetch_array($getgroup1)) {
                                        Echo "<option value='$grop[code]'>$grop[name]</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                        <div class='row'>
                            <div class='col-lg-3 col-md-3 col-sm-3 col-xs-3 pad text-right'>
                                <label class='label-control tmarg'>Order For Invoice</label>
                            </div>
                            <div class='col-lg-1 col-md-1 col-sm-1 col-xs-1 pad'>
                                <input type='text' class='form-control form levelno' name='levelno' value='<?php echo ($addflag != 1) ? $get['levelno'] : ""; ?>'>
                            </div>
                        </div>
                        <div class='row'>
                            <div class='col-lg-3 col-md-3 col-sm-3 col-xs-3 pad text-right'>
                                <label class='label-control tmarg'>Name Print</label>
                            </div>
                            <div class='col-lg-6 col-md-9 col-sm-9 col-xs-9 pad'>
                                <input type='text' class='form-control form nameprin' name='nameprin' value='<?php echo ($addflag != 1) ? $get['nameprin'] : $oldprin; ?>'>
                            </div>
                        </div>
                        <div class='row'>
                            <div class='col-lg-3 col-md-3 col-sm-3 col-xs-3 pad text-right'>
                                <label class='label-control tmarg'>Name for Custom Invoice</label>
                            </div>
                            <div class='col-lg-6 col-md-9 col-sm-9 col-xs-9 pad'>
                                <input type='text' class='form-control form nameprin' name='namecstmprin' value='<?php echo ($addflag != 1) ? $get['namecstmprin'] : $oldprin; ?>'>
                            </div>
                        </div>
                        <div class='row'>
                            <div class='col-lg-3 col-md-3 col-sm-3 col-xs-3 pad text-right'>
                                <label class='label-control tmarg'>Name for Party Invoice</label>
                            </div>
                            <div class='col-lg-6 col-md-9 col-sm-9 col-xs-9 pad'>
                                <input type='text' class='form-control form nameprin' name='nameprtyprin' value='<?php echo ($addflag != 1) ? $get['nameprtyprin'] : $oldprin; ?>'>
                            </div>
                        </div>
                        <div class='row'>
                            <div class='col-lg-3 col-md-3 col-sm-3 col-xs-3 pad text-right'>
                                <label class='label-control tmarg'>Tax %age</label>
                            </div>
                            <div class='col-lg-1 col-md-2 col-sm-2 col-xs-2 pad'>
                                <input type='text' class='form-control form taxperc' name='taxperc' value='<?php echo ($addflag != 1) ? $get['taxperc'] : $oldtax; ?>'>
                            </div>
                            <div class='col-lg-2 col-md-3 col-sm-3 col-xs-3 pad text-right'>
                                <label class='label-control tmarg'>HSN Code</label>
                            </div>
                            <div class='col-lg-3 col-md-2 col-sm-2 col-xs-2 pad'>
                                <input type='text' class='form-control form hsncode ' name='hsncode' value='<?php echo ($addflag != 1) ? $get['hsncode'] : ""; ?>'>
                            </div>
                        </div>
                        <div class='row'>
                            <div class='col-lg-3 col-md-3 col-sm-3 col-xs-3 pad text-right'>
                                <label class='label-control tmarg' style="color:blue">Not in Print</label>
                            </div>
                            <div class='col-lg-1 col-md-2 col-sm-2 col-xs-2 pad'>
                                <input type="checkbox" class="form-control form notinprint" style="height: 25px;width: 25px;" name="notinprint" value="1" <?
                                if ($get['notinprint'] == 1) {
                                    Echo "checked";
                                }
                                ?>>
                            </div>
                            
                        </div>
                        <hr>
                        <div class="row">
                            <div class='col-lg-3 col-md-1 col-sm-3 col-xs-3 pad text-center'>
                                <label class='label-control tmarg' style="color: red;font-size: 18px;border-bottom: 2px solid black">For POI</label>
                            </div>     
                            <div class='col-lg-3 col-md-1 col-sm-3 col-xs-3 pad text-right'>
                                <label class='label-control tmarg' style="color: red;">Make in POI</label>
                            </div>     
                            <div class='col-lg-1 col-md-1 col-sm-3 col-xs-3 pad'>
                                <input type="checkbox" name="makeinpoi" class="form-control form makeinpoi"  style="height: 25px;width: 25px;" value="1" <?php
                                if ($get['makeinpoi'] == 1) {
                                    echo "checked";
                                }
                                ?> >
                            </div> 
                        </div>
                        <div class="row">
                            <div class='col-lg-3 col-md-3 col-sm-3 col-xs-3 pad text-right'>
                                <label class='label-control tmarg'>Name + Size</label>
                            </div>     
                            <div class='col-lg-1 col-md-1 col-sm-3 col-xs-3 pad '>
                                <input type="checkbox" class="form-control form" style="height: 25px;width: 25px;" name="namesize" value="1" <?
                                if ($get['namesize'] == 1) {
                                    Echo "checked";
                                }
                                ?>>
                            </div>     
                        </div>
                        <hr>
                        <div class="row">
                            <div class='col-lg-3 col-md-1 col-sm-3 col-xs-3 pad text-center'>
                                <label class='label-control tmarg' style="color: red;font-size: 18px;border-bottom: 2px solid black">For GPP</label>
                            </div>     
                            <div class='col-lg-3 col-md-1 col-sm-3 col-xs-3 pad text-right'>
                                <label class='label-control tmarg' style="color: red;">Make in GPP</label>
                            </div>     
                            <div class='col-lg-1 col-md-1 col-sm-3 col-xs-3 pad'>
                                <input type="checkbox" name="makeingpp" class="form-control form makeingpp" value="1"<?php
                                if ($get['makeingpp'] == 1) {
                                    echo "checked";
                                }
                                ?>> 
                            </div> 
                        </div>
                        <div class='row'>
                            <div class='col-lg-2 col-md-1 col-sm-3 col-xs-3 pad text-right'>
                                <label class='label-control tmarg'>Size(P)</label>
                            </div>
                            <div class='col-lg-1 col-md-1 col-sm-2 col-xs-2 pad'>
                                <input type='text' class='form-control form sizeprod text-right' name='sizeprod' value='<?php echo ($addflag != 1) ? $get['sizeprod'] : $sizeprod; ?>'>
                            </div>
                            <div class='col-lg-1 col-md-3 col-sm-3 col-xs-3 pad text-right'>
                                <label class='label-control tmarg'>Cut Avg.</label>
                            </div>
                            <div class='col-lg-1 col-md-1 col-sm-2 col-xs-2 pad'>
                                <input type='text' class='form-control form cutavg text-right' name='cutavg' value='<?php echo ($addflag != 1) ? $get['cutavg'] : $cutavg; ?>'>
                            </div>
                            <div class='col-lg-1 col-md-3 col-sm-3 col-xs-3 pad text-right'>
                                <label class='label-control tmarg'>Rate/Pcs.</label>
                            </div>
                            <div class='col-lg-1 col-md-1 col-sm-2 col-xs-2 pad'>
                                <input type='text' class='form-control form ratepcs text-right' name='ratepcs' value='<?php echo ($addflag != 1) ? $get['ratepcs'] : $ratepcs; ?>'>
                            </div>
                            <div class='col-lg-1 col-md-3 col-sm-3 col-xs-3 pad text-right'>
                                <label class='label-control tmarg'>Length</label>
                            </div>
                            <div class='col-lg-1 col-md-1 col-sm-2 col-xs-2 pad'>
                                <input type='text' class='form-control form length text-right' name='length' value='<?php echo ($addflag != 1) ? $get['length'] : $length; ?>'>
                            </div>
                            <div class='col-lg-1 col-md-3 col-sm-3 col-xs-3 pad text-right'>
                                <label class='label-control tmarg'>Chest</label>
                            </div>
                            <div class='col-lg-1 col-md-1 col-sm-2 col-xs-2 pad'>
                                <input type='text' class='form-control form chest text-right' name='chest' value='<?php echo ($addflag != 1) ? $get['chest'] : $chest; ?>'>
                            </div>
                        </div>

                        <!--                        <div class='row'>
                                                    <div class='col-lg-3 col-md-3 col-sm-3 col-xs-3 pad text-right'>
                                                        <label class='label-control tmarg'>Order For Invoice</label>
                                                    </div>
                                                    <div class='col-lg-2 col-md-2 col-sm-5 col-xs-5 pad'>
                                                        <input type='text' maxlength="4" class='form-control form orderinv' name='orderinv' value='<?php echo ($addflag != 1) ? $get['orderinv'] : ""; ?>'>
                                                    </div>
                                                </div>-->
                        <!--                        Series Button
                                                <div class='row'>
                                                    <div class='col-lg-2 col-md-2 col-sm-2 col-xs-2 pad text-right'>
                                                        <label class='label-control tmarg'></label>
                                                    </div>
                                                    <div class='col-lg-2 col-md-2 col-sm-2 col-xs-2 pad'>
                                                        <a style=" background-color:#05B2EA; color:#ffffff; "  id="search" title="Search" class="btn mybtn btn-labeled btn-default btn-form" data-toggle="modal" data-target=".slacker-modal">
                                                            <span class="btn-label"><i class=""></i></span> </a>
                                                    </div>
                                                </div>-->
                    </div>
                    <div class="panel-footer">
                        <?php // include("includes/buttons.php");   ?>
                        <?php include("includes/buttmast.php"); ?>
                    </div>
                </div>
            </div>
            <?php if ($addflag != 1) { ?>
                <div class="col-lg-6">
                    <label class='label-control tmarg'>Opening Stock</label>
                    <?php
                    $getallseries = mysqli_query($conn, "Select a.code, a.name, b.opstk from series a left join  openstk b on a.code=b.series
                                             and b.itemname='$get[name]' and b.size='$get[size]' order by a.name") or die(mysqli_error($conn));
                    ?>
                    <div class="panel-body">
                        <table style="width:70%" class="table table-bordered">
                            <thead>
                            <th style="width: 10%;">Code</th>
                            <th style="width: 30%;">Series</th>
                            <th class='text-right' style="width: 10%;">Opening</th>
                            </thead>
                            <?php
                            $ctr = 0;
                            while ($fetseries = mysqli_fetch_array($getallseries)) {

                                echo "<tr>";
                                echo "<td><input type='text' name='opsercode_$ctr' value='$fetseries[code]' class='form-control form' readonly></td>";
                                echo "<td><input type='text' name='opseries_$ctr' value='$fetseries[name]' class='form-control form' readonly></td>";
//                                if ($fetseries[opstk] != 0) {
                                echo "<td><input type='text' style='text-align:right;' name='opstk_$ctr' value='$fetseries[opstk]' class='form-control form'></td>";
//                                } else {
//                                    echo "<td><input type='text' style='text-align:right;' name='opstk_$ctr' value='$fetseries[opstk]' class='form-control form' readonly> </td>";
//                                }
                                echo "</tr>";
                                $ctr++;
                            }
                            ?>
                            <input type="hidden" name="items" id="items" class="" value="<?= $ctr ?>">
                        </table>
                    </div>
                </div>
            <?php } ?>
        </div>
    </form>
    <!--    <div class="modal fade bs-example-modal-lg DelMultiModal" 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="myMultiModal">Delete Multi Item</h4>
                    </div>
                    <div class="modal-body">
                        <div class="table-responsive" style="max-height: 400px;overflow: auto;">
                            <table id="" class="table table-striped table-condensed table-bordered" width="100%">
                                <thead>
                                    <tr style="background-color:#05B2EA;">
                                        <th style = "color: white;">Select</th>
                                        <th style="color: white;">Item Name</th>
                                        <th style="color: white;">Size</th>
                                        <th style="color: white;">Unit</th>
                                    </tr>
                                </thead>
                                <tbody class="sDelTbody">
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="modal-footer"></div>
                </div>
            </div>
        </div>
    -->
    <!--search part-->
    <div class="modal fade bs-example-modal-lg searchModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span>&times;</span></button>
                    <h4 class="modal-title" id="myLargeModalLabel">Search <? Echo $formname; ?></h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-lg-2">
                            <select class="form-control sfield">
                                <option value="1">Item Name</option>
                                <option value="2">Name To Print</option>
                                <option value="3">Size</option>
                                <option value="4">Unit</option>
                                <option value="5">Company</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control soperator">
                                <option value="">Type of Search</option>
                                <option value="%">Like</option>
                                <option value="=">Exactly</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control sortBy">
                                <option value="1">Item Name</option>
                                <option value="2">Name To Print</option>
                                <option value="3">Size</option>
                                <option value="4">Unit</option>
                                <option value="5">Company</option>
                            </select> 
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control orderAs">
                                <option value="asc">Asc</option>
                                <option value="desc">Desc</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 style="background-color:#05B2EA;">
                                    <th style="color: white;">Item Name</th>
                                    <th style="color: white;">Name To Print</th>
                                    <th style="color: white;">Size</th>
                                    <th style="color: white;">Unit</th>
                                    <th style="color: white;">Company</th>
                                    <!--<th style="color: white;">Stock</th>-->
                                    <th style="color: white;">Action</th>
                                    <?php if ($usertype == 1) { ?>
                                        <th style = "color: white;">Delete</th>
                                    <?php } ?>
                                </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>
    <!--search part-->

    <?php include("includes/linksfoot.php"); ?>
</body>
</html>
