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

$formname = 'Product';
$maindb = 'product';
$trandb = 'prodtran';

$file = 'product.php';
$grid = '';
$keyfld = "code";
$printfile = 'product_print.php';
$trandbexist = 1;
$focusfld = "name";

ini_set('display_errors', 1);
error_reporting(E_ERROR);

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdbroot"];
$adduser = $_SESSION['username_' . $dbname];
date_default_timezone_set("Asia/Kolkata");
$adddate = date("Y-m-d");
$addtime = date("h:i:sa");
$grate = mysqli_query($conn, "SELECT `rateperc` FROM $zroot.`company`") or die(mysqli_error($conn));
$frate = mysqli_fetch_array($grate);
$rateperc = $frate['rateperc'];

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

if (isset($_POST["submit"])) {

    $a = 1;
    $mvouch = $qvouch;

    foreach ($_POST as $key => $value) {
        $exclude_fld = ["addfg", "submit", "vouchno", "ncode", "nolabel", "name", "prodrem3", "prodrem2", "prodrem1", "srno", "lineitem", "weight", "items"];
        if (in_array($key, $exclude_fld)) {
            continue;
        }
        $$key = $value;
    }
    $name = $_POST['name'];
    $stkunit = $_POST['stkunit'];

    $name = mysqli_real_escape_string($conn, $_POST["name"]);
    $prodrem3 = mysqli_real_escape_string($conn, $_POST["prodrem3"]);
    $prodrem2 = mysqli_real_escape_string($conn, $_POST["prodrem2"]);
    $prodrem1 = mysqli_real_escape_string($conn, $_POST["prodrem1"]);

    if (isset($_POST["barcode"])) {
        $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE  `barcode` = '$barcode' and `code` != '$qvouch'") or die(mysqli_error($conn));
        if (mysqli_num_rows($result) > 0) {
            $a = 0;
            browse("Barcode Already Exist");
            header("refresh: 1; $file?code=$qvouch&mode=last");
        }
    }

    if (isset($_POST["name"])) {
        $result2 = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE  `name` = '$name' and `code` != '$qvouch'") or die(mysqli_error($conn));
        if (mysqli_num_rows($result2) > 0) {
            $a = 0;
            browse("Name Already Exist");
            browse($name);
            browse($qvouch);
            header("refresh: 1; $file?code=$qvouch&mode=last");
        }
    }


    $insert_fields .= "`code`, `name`, `barcode`, `prodgrp`, `cost`, `mrp`, `type`, `rate`, `unit`, `adddate`, `addtime`,`origin`, `bbf`, `batch`, `adduser`, `energy`, `kcal`, `fat`, `saturate`, `carbohydrate`, `sugar`, `fibre`, `protein`, `salt`, `prodrem1`, `prodrem2`, `prodrem3`, `prodrem`,`minstk`, `pouchflag`,`stkunit`";
    $insert_values .= "'$mvouch', '$name', '$barcode', '$prodgrp', '$cost', '$mrp', '$type', '$rate', '$unit', '$adddate', '$addtime', '$origin', '$bbf', '$batch', '$adduser', '$energy', '$kcal', '$fat', '$saturate', '$carbohydrate', '$sugar', '$fibre', '$protein', '$salt', '$prodrem1', '$prodrem2', '$prodrem3', '$prodrem','$minstk','$pouchflag','$stkunit'";
    $update_fields .= "`name`='$name',`prodgrp`='$prodgrp',`cost`='$cost',`mrp`='$mrp',`type`='$type',`rate`='$rate',`unit`='$unit',`editdate`='$adddate',`edittime`='$addtime',`origin`='$origin',`bbf`='$bbf',`batch`='$batch',`energy`='$energy',`kcal`='$kcal',`fat`='$fat',`saturate`='$saturate',`carbohydrate`='$carbohydrate',`sugar`='$sugar',`fibre`='$fibre',`protein`='$protein',`salt`='$salt',`prodrem1`='$prodrem1',`prodrem2`='$prodrem2',`prodrem3`='$prodrem3',`prodrem`='$prodrem',`minstk`='$minstk',`pouchflag`='$pouchflag',`stkunit`='$stkunit' ";

    if ($a == 1) {

        mysqli_query($conn, "LOCK TABLES `$maindb` WRITE, $trandb WRITE");

        mysqli_query($conn, "DELETE  FROM  `$trandb`  WHERE `code` = '$qvouch'") or die(mysqli_error($conn));
        $count = $_POST["items"];
        // browse($count);
        // if ($addflag == 1) {

        for ($i = 0; $i < $count; $i++) {

            $mlineitem = $_POST["lineitem_$i"];
            $mweight = $_POST["weight_$i"];
            $mpouch = $_POST["pouch_$i"];
            // browse($mbarcode);

            if ($mlineitem != '') {
                mysqli_query($conn, "INSERT INTO `$trandb`(`code`,  `lineitem`, `weight`,`pouch`)
                                        VALUES('$qvouch', '$mlineitem', '$mweight', '$mpouch')") or die(mysqli_error($conn));
            }
        }

        if ($addflag == 1) {
            $insert_qry = "INSERT INTO `$maindb` ($insert_fields) VALUES ($insert_values)";
            mysqli_query($conn, $insert_qry) or die(mysqli_error($conn));

            $mvouch = $qvouch;
            header("refresh: 1; $grid?para=A");

            header("refresh: 1; $file?mode=edit&$keyfld=$mvouch");
        } else {
            $mvouch = $qvouch;
            $update_qry = "UPDATE `$maindb` SET $update_fields  where code = '$mvouch'";
            mysqli_query($conn, $update_qry) or die(mysqli_error($conn));

            //            updmess();
            header("refresh: 1; $file?mode=edit&$keyfld=$mvouch");
        }
        mysqli_query($conn, "UNLOCK TABLES");
    }
}

if ($addflag != 1) {
    $getvouch = '';

    if ($addflag == 0) {
        $getvouch = $_GET[$keyfld];
    } else {
        $getvouch = $qvouch;
    }
    $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE $keyfld='$getvouch'") or die(mysqli_error($conn));
    $get = mysqli_fetch_array($result);

    $gunit = mysqli_query($conn, "SELECT * FROM $zroot.`unit` WHERE `code`='$get[stkunit]'") or die(mysqli_error($conn));
    $funit = mysqli_fetch_array($gunit);

    // $gpgrp = mysqli_query($conn, "SELECT * FROM `prodgrp` WHERE code='$get[prodgrp]'") or die(mysqli_error($conn));
    // $fprodgrp = mysqli_fetch_array($gpgrp);
    $rd = "readonly";
}

$senable = "";
$cenable = "";
if (isset($_GET["delete"])) {
    $chkresult = mysqli_query($conn, "SELECT itemcode FROM `inwtran` WHERE itemcode='$_GET[$keyfld]'") or die(mysqli_error($conn));
    $fetget = mysqli_num_rows($chkresult);
    if ($fetget > 0) {
        browse('Item Exist in Transaction');
    } else {
        delete($zdb, "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
    }
}

$versionToken = mt_rand();
include("includes/linkshead.php");
?>
<style type="text/css">
    .skbtn {
        width: 50px;
        padding: 2px;
        font-size: 1.5em;
        line-height: initial;
    }

    .skhead {
        background-color: rgba(199, 228, 199, 0.5);
        margin-right: -6px;
    }

    .skback {
        background-color: rgba(255, 237, 128, 0.5);
        margin-right: -6px;
    }

    .skback2 {
        background-color: rgba(218, 194, 232, 0.5);
        margin-right: -6px;
    }
</style>
<script src="MyScript/product.js<?= '?version=' . $versionToken ?>" type="text/javascript"></script>
<script src="MyScript/product_search.js" type="text/javascript"></script>
</head>

<body>

    <form action='' name="invoice" method='POST' enctype="multipart/form-data">

        <!-- Default box -->
        <div class="row">
            <div class="col-lg-5 pad">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><?php echo $formname; ?></h3>
                    </div>

                    <div class="panel-body">
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                                <label class="label-control marg">Barcode</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="hidden" class="form-control form rateperc" value="<?php echo $rateperc; ?>">
                                <input type="hidden" class="form-control form code" name="ncode" value="<?php echo ($addflag != 1) ? $get["code"] : "$qvouch"; ?>">
                                <input type="text" class="form-control form barcode focusfield" name="barcode" value="<?php echo ($addflag != 1) ? $get["barcode"] : ""; ?>" <?= $rd ?> autofocus>
                            </div>
                        </div>

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

                        <!-- <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right pad">
                                <label class="label-control marg">Group</label>
                            </div>
                            <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 pad">
                                <select class="form-control form select2 prodgrp" name="prodgrp" style="width:100%" required>
                                    <option value="<?php echo ($addflag != 1) ? $fprodgrp['code'] : ""; ?>"><? echo ($addflag != 1) ? $fprodgrp['name'] : ""; ?></option>
                        <?php
                        // $gprodgrp = mysqli_query($conn, "SELECT * FROM `prodgrp`")or die(mysqli_error($conn));
                        // while ($prodgrp = mysqli_fetch_object($gprodgrp)) {
                        //     Echo "<option value='$prodgrp->code'>$prodgrp->name</option>";
                        // }
                        ?>
                                </select>
                            </div>
                        </div> -->

                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                                <label class="label-control marg">Type</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-2 col-xs-6 pad">
                                <select class="form-control form type select2" name="type">
                                    <option value="<?php echo ($addflag != 1) ? $get["type"] : ""; ?>"><?php echo ($addflag != 1) ? $get["type"] : ""; ?></option>
                                    <option value="Organic">Organic</option>
                                    <option value="Conventional">Conventional</option>
                                    <option value="Other">Other</option>
                                </select>
                            </div>
                        </div>

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

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

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

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

                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                                <label class="label-control marg">Stock Unit</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-2 col-xs-6 pad">
                                <select class="form-control form stkunit select2" name="stkunit">
                                    <option value="<?php echo ($addflag != 1) ? $get["stkunit"] : ""; ?>"><?php echo ($addflag != 1) ? $funit["name"] : ""; ?></option>
                                    <?php
                                    $getunit = mysqli_query($conn, "SELECT * FROM $zroot.`unit` WHERE `code`!=''") or die(mysqli_error($conn));
                                    while ($fetunit = mysqli_fetch_array($getunit)) {
                                        echo "<option value='$fetunit[code]'>$fetunit[name]</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                                <label class="label-control marg">Cost</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-2 col-xs-6 pad">
                                <input type="number" step="any" class="form-control form cost" name="cost" value="<?php echo ($addflag != 1) ? $get["cost"] : 0; ?>">
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                                <label class="label-control marg" style="color:blue">Retail Rate</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-2 col-xs-6 pad">
                                <input type="number" step="any" class="form-control form rate" name="rate" value="<?php echo ($addflag != 1) ? $get["rate"] : 0; ?>" style="color:blue">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                                <label class="label-control marg">Min. Stock</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-2 col-xs-6 pad">
                                <input type="number" class="form-control form minstk" name="minstk" value="<?php echo ($addflag != 1) ? $get["minstk"] : 0; ?>">
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                                <label class="label-control marg">Online Rate </label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-2 col-xs-6 pad">
                                <input type="number" step="any" class="form-control form mrp" name="mrp" value="<?php echo ($addflag != 1) ? $get["mrp"] : 0; ?>">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right pad">
                                <label class="label-control marg">Pouch</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-2 col-xs-6 pad">
                                <input type="checkbox" class="form form-control pouchflag" id="pouchflag" name="pouchflag" value="1" <?php if ($get['pouchflag'] == 1) echo "checked"; ?>>
                            </div>
                        </div>


                        <div class="row skhead hidePouch">
                            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 text-center  pad">
                                <label class="label-control marg" style="font-weight: bold;">Nutritions</label>
                            </div>
                        </div>

                        <div class="row skback hidePouch">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                                <label class="label-control marg">Energy Kj</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-2 col-xs-6 pad">
                                <input type="text" class="form-control form text-right energy" name="energy" value="<?php echo ($addflag != 1) ? $get["energy"] : ""; ?>">
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                                <label class="label-control marg">Kcal</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-2 col-xs-6 pad">
                                <input type="text" class="form-control form text-right kcal" name="kcal" value="<?php echo ($addflag != 1) ? $get["kcal"] : ""; ?>">
                            </div>
                        </div>

                        <div class="row skback hidePouch">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                                <label class="label-control marg">Fat (g)</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-2 col-xs-6 pad">
                                <input type="text" class="form-control form text-right fat" name="fat" value="<?php echo ($addflag != 1) ? $get["fat"] : ""; ?>">
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                                <label class="label-control marg">Of which saturates</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-2 col-xs-6 pad">
                                <input type="text" class="form-control form text-right saturate" name="saturate" value="<?php echo ($addflag != 1) ? $get["saturate"] : ""; ?>">
                            </div>
                        </div>

                        <div class="row skback hidePouch">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                                <label class="label-control marg">Carbohydrate (g)</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-2 col-xs-6 pad">
                                <input type="text" class="form-control form text-right carbohydrate" name="carbohydrate" value="<?php echo ($addflag != 1) ? $get["carbohydrate"] : ""; ?>">
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                                <label class="label-control marg">Of which sugar</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-2 col-xs-6 pad">
                                <input type="text" class="form-control form text-right sugar" name="sugar" value="<?php echo ($addflag != 1) ? $get["sugar"] : ""; ?>">
                            </div>
                        </div>

                        <div class="row skback hidePouch">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                                <label class="label-control marg">Fibre (g)</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-2 col-xs-6 pad">
                                <input type="text" class="form-control form text-right fibre" name="fibre" value="<?php echo ($addflag != 1) ? $get["fibre"] : ""; ?>">
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                                <label class="label-control marg">Protein (g)</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-2 col-xs-6 pad">
                                <input type="text" class="form-control form text-right protein" name="protein" value="<?php echo ($addflag != 1) ? $get["protein"] : ""; ?>">
                            </div>
                        </div>

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

                        <div class="row skback2 hidePouch">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                                <label class="label-control marg">Ingredients</label>
                            </div>
                            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form prodrem1" maxlength="70" name="prodrem1" value="<?php echo ($addflag != 1) ? $get["prodrem1"] : ""; ?>">
                            </div>
                        </div>

                        <div class="row skback2 hidePouch">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                                <label class="label-control marg"></label>
                            </div>
                            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form prodrem2" maxlength="70" name="prodrem2" value="<?php echo ($addflag != 1) ? $get["prodrem2"] : ""; ?>">
                            </div>
                        </div>

                        <div class="row skback2 hidePouch">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric text-right  pad">
                                <label class="label-control marg"></label>
                            </div>
                            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form prodrem3" maxlength="70" name="prodrem3" value="<?php echo ($addflag != 1) ? $get["prodrem3"] : ""; ?>">
                            </div>
                        </div>



                        <!--                        <div class="row" style="">
                                                                                <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric pad" style="text-align: right">
                                                                                    <label class="label-control text-danger text-right marg">No. Of Labels</label>
                                                                                </div>
                                                                                <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 pad">
                                                                                    <input type='text' id="nolabel" name='nolabel' maxlength="4" class='form-control' style='width:70px;' <?php echo ($addflag != 1) ? '' : 'readonly'; ?>>
                                                                                </div>
                                                    <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                                        <button type="button" <?php if ($addflag != 1) { ?> onclick="window.open('prod_barcode_all.php?barcode=<?= $get['code']; ?>&para=3&number=' + document.invoice.nolabel.value + '&name=' + document.invoice.name.value + '&barcode=' + document.invoice.ncode.value, 'popUpWindow', 'height=600,width=970,left=20,top=20, resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes')" <?php
                                                                                                                                                                                                                                                                                                                                                                                                                                                                            } else {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                echo 'disabled';
                                                                                                                                                                                                                                                                                                                                                                                                                                                                            }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ?>><i class="fa  fa-barcode skbtn">ALL</i></button>
                                                    </div>
                                                </div> -->


                    </div>

                    <!-- </div> -->
                    <!-- <div class="panel-footer"> -->
                    <div class="row" style="margin-top: 10px;">
                        <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10 pad" style="margin-top: 10px;">
                            <?php include("includes/buttons.php"); ?>
                        </div>
                        <?php if ($addflag != 1) { ?>
                            <a href="prod_barcode_sc.php?para=3" target="_blank"><i class="fa fa-2x fa-barcode skbtn"></i></a>
                        <?php } else { ?>
                            <button disabled><i class="fa fa-2x fa-barcode skbtn"></i></button>
                        <?php } ?>
                        <!-- <div class="col-lg-1 col-md-2 col-sm-2 col-xs-2 pad marg text-left" style="margin-top: 10px;">
                            <button <?php if ($addflag != 1) { ?>
                                    onclick="window.open('prod_barcode_sc.php?para=3', 'popUpWindow', 'height=600,width=970,left=20,top=20, resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes')" <?php
                                                                                                                                                                                                                                        } else {
                                                                                                                                                                                                                                            echo "disabled";
                                                                                                                                                                                                                                        }
                                                                                                                                                                                                                                            ?>><i class="fa fa-2x fa-barcode skbtn"></i></button>
                        </div> -->
                    </div>
                </div>
            </div>
            <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 barcodeTable hidePouch">
                <div class="panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><?php echo "Barcodes"; ?></h3>

                    </div>
                    <div class="panel-heading">
                        <div class="row">
                            <table class="table table-bordered myTable">
                                <thead class="mySearchTr">
                                    <th style="width:5%;"></th>
                                    <th style="width:10%;">Sr.</th>
                                    <th style="width:55%;">Website Name</th>
                                    <th style="width:10%;">Weight</th>
                                    <th style="width:20%;">Pouch</th>
                                </thead>
                                <tbody class="tbody">
                                    <?php
                                    if ($addflag != 1) {
                                        $barqry = mysqli_query($conn, "Select * from `$trandb` where code='$getvouch' order by weight+0");
                                        // $numrows = mysqli_num_rows($barqry);
                                        // browse($numrows);
                                        $ctr = 0;
                                        $mctr = 0;
                                        while ($fetbar = mysqli_fetch_array($barqry)) {
                                            $getunit = mysqli_query($conn, "SELECT * FROM `product` WHERE code = '$fetbar[pouch]'") or die(mysqli_error($conn));
                                            $fetunit = mysqli_fetch_array($getunit);
                                            $mctr++;
                                            echo "<tr>";
                                            echo "<td><i class='fa fa-close remove' style='display:none;'></i></td>";

                                            echo "<td><input type='text' name='srno_$ctr' class='form-control form text-right srno' value='$mctr' readonly  tabindex='-1'></td>";
                                            echo "<td><input type='text' name='lineitem_$ctr' class='form-control form lineitem' value='$fetbar[lineitem]'></td>";
                                            echo "<td><input type='text' name='weight_$ctr' class='form-control form weight' value='$fetbar[weight]'></td>";
                                            echo "<td><select class='form-control select2 form' name='pouch_$ctr' style='width:100%;'>";
                                            echo "<option value='$fetunit[code]'>$fetunit[name]</option>";
                                            $ggetunit = mysqli_query($conn, "SELECT * FROM product WHERE code != '' AND pouchflag = 1 ORDER BY name") or die(mysqli_error($conn));
                                            while ($ffetunit = mysqli_fetch_array($ggetunit)) {
                                                echo "<option value='$ffetunit[code]'>$ffetunit[name]</option>";
                                            }
                                            echo "</select>";
                                            echo "</td>";
                                            echo "</tr>";
                                            $ctr++;
                                        }
                                    } else {
                                    ?>
                                        <tr>
                                            <td><i class='fa fa-close remove'></i></td>

                                            <td><input type="text" name="srno_0" class="form-control text-right srno" value="1" readonly tabindex='-1'></td>
                                            <td><input type="text" name="lineitem_0" class="form-control lineitem" value=""></td>
                                            <td><input type="text" name="weight_0" class="form-control weight" value=""></td>
                                            <td><select class='form-control select2 form' name='pouch_0' style='width:100%;'>";
                                                    <option value=""></option>
                                                    <?php
                                                    echo $ggetunit2 = mysqli_query($conn, "SELECT * FROM product WHERE code != '' AND pouchflag = 1 ORDER BY name") or die(mysqli_error($conn));
                                                    while ($ffetunit2 = mysqli_fetch_array($ggetunit2)) {
                                                        echo "<option value='$ffetunit2[code]'>$ffetunit2[name]</option>";
                                                    }
                                                    ?>
                                                </select>
                                            </td>
                                        </tr>
                                    <?php }
                                    ?>
                                    <input type="hidden" name="items" id="items" value="<?php echo ($addflag != 1) ? $ctr : 1; ?>">
                                </tbody>

                            </table>
                            <button type="button" class="btn btn-primary btn-square form" id="addnew">
                                <i class="fa fa-plus" data-toggle='tooltip' title='Add Row'></i>
                            </button>
                        </div>
                    </div>
                </div>

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

    <div class="modal fade bs-example-modal-lg searchModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span>&times;</span></button>
                    <h4 class="modal-title" id="myLargeModalLabel">Search <? echo $formname; ?></h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-lg-2">
                            <select class="form-control sfield">
                                <option value="1">Name</option>
                                <option value="2">Barcode</option>
                                <option value="3">Cost Price</option>
                                <option value="4">Selling Price</option>
                                <option value="5">Pouch</option>
                                <!--                                <option value="5">Barcode</option>
                                                                <option value="6">GST %</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">Name</option>
                                <option value="2">Barcode</option>
                                <option value="3">Cost Price</option>
                                <option value="4">Selling Price</option>
                                <option value="5">Pouch</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="15%">Barcode</th>
                                    <th width="30%">Name</th>
                                    <th width="10%">Type</th>
                                    <th width="10%">Country Origin</th>
                                    <th width="7%">B / B Mon.</th>
                                    <th width="7%">Batch</th>
                                    <th width="7%">Unit</th>
                                    <!-- <th width="7%">Gram</th> -->
                                    <th width="7%">Pouch</th>
                                    <!--                                    <th width="10%">Barcode</th>

                                    <th width="10%">GST %</th>-->
                                    <th width="8%">Action</th>
                                </tr>
                            </thead>
                            <tbody class="sTbody">
                            </tbody>
                        </table>
                    </div>
                    <div class="row">
                        <div class="col-xs-12 text-right search-action-bar">
                            <input type="button" class="btn btn-primary sprev" value="Previous">
                            <input type="button" class="btn btn-primary snext" value="Next">
                        </div>
                    </div>
                </div>
                <div class="modal-footer"></div>
            </div>
        </div>
    </div>

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

</html>