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

$formname = 'Item';
$maindb = 'item';
$printfile = "itemprint.php";
$file = 'itemmain.php';
$trandbexist = 0;
$keyfld = "code";
$mgrpcode = "OP";
$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
$zroot = $_SESSION["zdir"];
$compcd = $_SESSION["comp_" . $dbname];
mysqli_select_db($conn, $zdb);

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

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

    $a = 1;
    $name = $_POST["name"];
    $unit = $_POST["unit"];
    $prodtype = $_POST["prodtype"];
    $pcsper = $_POST["pcsper"];
    $totpcs = $_POST["totpcs"];
    $itemgrp = $_POST["itemgrp"];
    $itemsubgrp = $_POST["itemsubgrp"];
    $cost = $_POST["cost"];
    $rate = $_POST["rate"];
    $msp = $_POST["msp"];
    $mrp = $_POST["mrp"];
    $opening = $_POST["opening"];
    $nmlabels = $_POST["nmlabels"];
    $hsncode = $_POST["hsncode"];
    $gstperc = $_POST["gstperc"];
    $nameprint = $_POST["nameprint"];

    $count = $_POST["items"];


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

        $path = "admin/itemimage/";

        $fileName = $qvouch . ".jpg";
        $img_file = $path . ($fileName);

//      $fileName = $_FILES["file1"]["name"]; // The file name
        $fileTmpLoc = $_FILES["file1"]["tmp_name"]; // File in the PHP tmp folder
        $fileType = $_FILES["file1"]["type"]; // The type of file it is
        $fileSize = $_FILES["file1"]["size"]; // File size in bytes
        $fileErrorMsg = $_FILES["file1"]["error"]; // 0 for false... and 1 for true
//        if (!$fileTmpLoc) { // if file not chosen
//            echo "ERROR: Please browse for a file before clicking the upload button.";
//            exit();
//        }

        browse($fileName);
        browse($fileTmpLoc);


        if (!empty($fileTmpLoc)) {
            if (move_uploaded_file($fileTmpLoc, "$img_file")) {

                browse("$fileName upload is complete");

                ###########################SAVE PART################################################   
                $imgp = mysqli_query($conn, "SELECT * FROM `itemimage`")or die(mysqli_error($conn));
                $gimg = mysqli_fetch_array($imgp);

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

                if ($gimg[vouchno] == $qvouch) {
//        print " UPDATE `itemimage` SET `vouchno`='$qvouch', `imgpath`='$img_file' WHERE `vouchno`='$qvouch' ";
                    mysqli_query($conn, "UPDATE `itemimage` SET `vouchno`='$qvouch', `imgpath`='$img_file' WHERE `vouchno`='$qvouch' ") or die(mysqli_error($conn));
                }

                mysqli_query($conn, "INSERT INTO `itemimage`(`vouchno`,`imgpath`)
                            VALUES('$qvouch', '$img_file')") or die(mysqli_error($conn));
            } else {
                browse("move_uploaded_file function failed");
            }
        }


        ############################## MAIN  ######################################################
        if ($addflag == 1) {
//            BROWSE('1');
            mysqli_query($conn, "INSERT INTO $maindb(`code`,  `name`, `unit`, `itemgrp`, `itemsubgrp`, `prodtype`,  `cost`, `rate`,`msp`,`mrp`,`opening`,
                                               `nmlabels`, `hsncode`,`gstperc`,`nameprint`,totpcs,pcsper)
                                        VALUES($qvouch, '$name', '$unit', '$itemgrp','$itemsubgrp', '$prodtype', '$cost', '$rate', '$msp','$mrp','$opening',
                                               '$nmlabels','$hsncode','$gstperc','$nameprint','$totpcs', '$pcsper')") or die(mysqli_error($conn));
        } else {
            mysqli_query($conn, "UPDATE $maindb SET `name`='$name', `unit`='$unit', `itemgrp`='$itemgrp', `itemsubgrp`='$itemsubgrp', `prodtype`='$prodtype', 
                                 `cost`='$cost', `rate`='$rate', `msp`='$msp', `mrp`='$mrp', `opening`='$opening', `nmlabels`='$nmlabels',
                                 `hsncode`='$hsncode', `gstperc`='$gstperc',`nameprint`='$nameprint',totpcs='$totpcs',pcsper='$pcsper' WHERE code = '$mvouch' ") or die(mysqli_error($conn));
        }

        if ($addflag == 1) {
            insmess();
            $mvouch = $qvouch; //1
            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);

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

    $finditemgrp = mysqli_query($conn, "SELECT * FROM `itemgrp` WHERE `code`='$get[itemgrp]'") or die(mysqli_error($conn));
    $fitemgrp = mysqli_fetch_array($finditemgrp);

    $finditemsub = mysqli_query($conn, "SELECT * FROM `itemsubgrp` WHERE `code`='$get[itemsubgrp]'") or die(mysqli_error($conn));
    $fitemsub = mysqli_fetch_array($finditemsub);

    $getimg = mysqli_query($conn, "SELECT * FROM `itemimage` WHERE `vouchno`='$qvouch'")or die(mysqli_error($conn));
    $img = mysqli_fetch_array($getimg);
    $imgpath = $img[imgpath] . "?a=" . mt_rand();
}

if (isset($_GET["delete"])) {

    $chkdel = mysqli_query($conn, "Select itemcode from `transacn` where `itemcode`='$_GET[$keyfld]'") or die(mysqli_error($conn));
    $cntdel = mysqli_num_rows($chkdel);
    if ($cntdel > 0) {
        browse("Item Exist in Transactions");
    } else {
        delete($zdb, "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
    }
}

include("includes/linkshead.php");
?>
<script  type="text/javascript">
    $(document).ready(function () {
        $("body").on("change", ".itemgrp", gethsn);

        function gethsn() {
            var itemgrp = $('.itemgrp').val();
            $.post('gethsn.php', {itemgrp: itemgrp}, function (data) {
                $('.hsncode').val(data.hsn);
                $('.gstperc').val(data.gst);
            }, 'json');
        }
    });
</script>
<script src="MyScript/itemmain.js" type="text/javascript"></script>

</head>
<body>
    <form action='' method='POST' enctype="multipart/form-data">

        <!-- Default box -->
        <div class="col-lg-6 col-md-12 col-sm-12 col-xs-12  pad">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><?php Echo $formname; ?></h3>
                    <div class="actions pull-right">
                        <i class="fa fa-chevron-down"></i>
                    </div>
                </div>
                <div class="panel-body">
                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric pad">
                            <label class="label-control marg">Code</label>
                        </div>
                        <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                            <input type="text" class="form-control form" name="code" value="<?php Echo ($addflag != 1) ? $get["code"] : " $qvouch"; ?>" required readonly>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric pad">
                            <label class="label-control marg">Name</label>
                        </div>
                        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 pad">
                            <input type="text" class="form-control form item" name="name" value="<?php Echo ($addflag != 1) ? $get["name"] : ""; ?>" required autofocus>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric pad">
                            <label class="label-control marg">Item Group</label>
                        </div>
                        <div class="col-lg-4 col-md-6 col-sm-6 col-xs-6 pad">
                            <select class="form-control itemgrp form select2" name="itemgrp" required>
                                <option value="<?php echo ($addflag != 1) ? $fitemgrp['code'] : ""; ?>"><? echo ($addflag != 1) ? $fitemgrp['name'] : ""; ?></option>
                                <?php
                                $gitemgrp = mysqli_query($conn, "SELECT * FROM `itemgrp`")or die(mysqli_error($conn));
                                while ($itemgrp = mysqli_fetch_object($gitemgrp)) {
                                    Echo "<option value='$itemgrp->code'>$itemgrp->name</option>";
                                }
                                ?>
                            </select>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric pad">
                            <label class="label-control marg">Item Sub Group</label>
                        </div>
                        <div class="col-lg-4 col-md-6 col-sm-6 col-xs-6 pad">
                            <select class="form-control form select2" name="itemsubgrp" required >
                                <option value="<?php echo ($addflag != 1) ? $fitemsub['code'] : ""; ?>"><? echo ($addflag != 1) ? $fitemsub['name'] : ""; ?></option>
                                <?php
                                $gitemsub = mysqli_query($conn, "SELECT * FROM `itemsubgrp`")or die(mysqli_error($conn));
                                while ($mitemsub = mysqli_fetch_object($gitemsub)) {
                                    Echo "<option value='$mitemsub->code'>$mitemsub->name</option>";
                                }
                                ?>
                            </select>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric pad">
                            <label class="label-control marg">Name to Print</label>
                        </div>
                        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 pad">
                            <input type="text" class="form-control form " name="nameprint" value="<?php Echo ($addflag != 1) ? $get["nameprint"] : ""; ?>" >
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                            <label class="label-control marg" style="color: #78909C">HSN Code</label>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                            <input type="text" step="any" class="form-control form hsncode" name="hsncode" value="<?php Echo ($addflag != 1) ? $get["hsncode"] : ""; ?>"> 
                        </div>
                        <div class="col-lg-1 col-md-2 col-sm-3 col-xs-3 text-right pad">
                            <label class="label-control marg" style="color: #78909C">GST &nbsp; %</label>
                        </div>
                        <div class="col-lg-2 col-md-2 col-sm-2 col-xs-3 pad">
                            <input type="text" step="any" class="form-control form gstperc" name="gstperc" value="<?php Echo ($addflag != 1) ? $get["gstperc"] : ""; ?>"> 
                        </div>
                    </div>
                    <!--                    <div class="row">
                                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric pad">
                                                <label class="label-control marg">Unit</label>
                                            </div>
                                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                                                <select class="form-control form select2" name="unit" style="width:100%" required="required"> 
                                                    <option value=" <?php echo $gunit['code'] ?>"><?php echo $gunit['name'] ?></option>
                    <?php
                    $funit = mysqli_query($conn, "SELECT `code`,`name` FROM `unit`")or die(mysqli_error($conn));
                    while ($unit1 = mysqli_fetch_object($funit)) {
                        Echo "<option value='$unit1->code'>$unit1->name</option>";
                    }
                    ?>
                                                </select>
                                            </div>
                                        </div>-->

                    <!--                    <div class="row">
                                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric pad">
                                                <label class="label-control marg">Product Type</label>
                                            </div>
                                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                                                <select class="form-control form select2" name="prodtype" style="width:100%"> 
                                                    <option value="<?php Echo ($addflag != 1) ? $get["prodtype"] : ""; ?>">
                    <?php
                    if ($get["prodtype"] == "P") {
                        Echo "PERFUME";
                    } elseif ($get["prodtype"] == "O") {
                        Echo "OTHERS";
                    }
                    ?>
                                                    </option>
                                                    <option value="P">PERFUMES</option>
                                                    <option value="O">OTHERS</option>
                                                </select>
                                            </div>
                                        </div>-->
                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric pad">
                            <label class="label-control marg">PCS Per</label>
                        </div>
                        <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                            <select class="form-control form select2" name="pcsper" style="width:100%"> 
                                <option value="<?php Echo ($addflag != 1) ? $get["pcsper"] : ""; ?>">
                                    <?php
                                    if ($get["pcsper"] == "Y") {
                                        Echo "YARD";
                                    } elseif ($get["pcsper"] == "M") {
                                        Echo "METERS";
                                    }
                                    ?>
                                </option>
                                <option value="Y">YARD</option>
                                <option value="M">METERS</option>
                            </select>
                        </div>
                        <div class="col-lg-1 col-md-1 col-sm-2 col-xs-2 pad">
                            <input type="number" step="any" class="form-control form cost totpcs" name="totpcs" value="<? Echo ($addflag != 1 ) ? $get[totpcs] : 0.00; ?>">
                        </div>
                        <div class="col-lg-1 col-md-1 col-sm-2 col-xs-2 pad">
                            <label class="label-control marg">PCS</label>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric pad">
                            <label class="label-control marg">Cost</label>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                            <input type="text" class="form-control form cost numeric" name="cost" value="<? Echo ($addflag != 1 ) ? $get[cost] : ""; ?>">
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric pad">
                            <label class="label-control marg">Rate</label>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                            <input type="text" class="form-control form rate numeric" name="rate" value="<? Echo ($addflag != 1 ) ? $get[rate] : ""; ?>">
                        </div>
                    </div>
                    <hr>
                    <!--                    <div class="row">
                                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric pad">
                                                <label class="label-control text-danger marg">Minimum Selling Price</label>
                                            </div>
                                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                                <input type="text" class="form-control form rate numeric" name="msp" value="<? Echo ($addflag != 1 ) ? $get[msp] : ""; ?>">
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric pad">
                                                <label class="label-control text-danger marg">MRP</label>
                                            </div>
                                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                                <input type="text" class="form-control form rate numeric" name="mrp" value="<? Echo ($addflag != 1 ) ? $get[mrp] : ""; ?>">
                                            </div>
                                        </div>-->
                    <!--                    <div class="row">
                                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                                <hr>
                                            </div>
                                            <b>STOCK</b>
                                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 numeric pad">
                                                <hr>
                                            </div>
                                        </div>-->
                    <!--                    <div class="row">
                                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 numeric pad">
                                                <label class="label-control text-danger marg">Opening</label>
                                            </div>
                                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 pad">
                                                <input type="text" class="form-control form rate numeric" name="opening" value="<? Echo ($addflag != 1 ) ? $get[opening] : ""; ?>">
                                            </div>
                                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 numeric pad">
                                                <label class="label-control text-danger 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-2 col-md-3 col-sm-3 col-xs-3 pad">
                                                                        <button <?php if ($addflag != 1) { ?> onclick="window.open('blankbar.php?barcode=<?= $get[itemcode] ?>&number=' + document.invoice.nolabel.value + '&name=' + document.invoice.name.value + '&mrp=' + document.invoice.mrp.value +  '&barcode=' + document.invoice.code.value + '&msp=' + document.invoice.msp.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-th-large btn"></i></button>
                                                                    </div>
                                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 pad">
                                                <button <?php if ($addflag != 1) { ?> onclick="window.open('thermal_barcode3.php?vouchno=<?= $qvouch ?>&vouchdt=<?= $vouchdt ?>&para=3&number=' + document.invoice.nolabel.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-th-large btn"></i></button>
                                            </div>
                    
                                        </div>-->
                </div>
                <div class="panel-footer">
                    <?php include("includes/buttons.php"); ?>
                </div>
            </div>
        </div>
        <div class="col-lg-6 pad">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <!--<h3 class="panel-title"><?php // Echo $formname;                 ?></h3>-->
                    <div class="actions pull-right">
                        <i class="fa fa-chevron-down"></i>

                    </div>
                </div>
                <div class="panel-body">
                    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="float: right">
                        <h4>SALE</h4>
                        <table class="table table-striped table-condensed table-bordered" width="50%">
                            <thead  style="" class="mySearchTr">
                                <tr>
                                    <th width="5%">Bill No.</th>
                                    <th width="15%" class=''>Date</th>
                                    <th width="40%"class=''>Party</th>
                                    <th width="10%"class='text-right'>Qty.</th>
                                    <th width="15%"class='text-right'>Rate</th>
                                    <th width="15%"class='text-right'>Amount</th>
                                </tr>
                            </thead>
                            <tbody class="tbody">
                                <?php
                                $gettran = mysqli_query($conn, "SELECT a.*,b.*,DATE_FORMAT(a.vouchdt,'%d-%m-%Y')as date  FROM `saletran` a,`salemain` b WHERE a.`item`='$qvouch'  and a.vouchno = b.vouchno
                                                            order by b.vouchdt DESC limit 0,3")or die(mysqli_error($conn));
                                $count = mysqli_num_rows($gettran);
                                if ($count > 0) {
                                    while ($tran = mysqli_fetch_array($gettran)) {
                                        $gitem = mysqli_query($conn, "SELECT code,name FROM `item` WHERE `code`='$tran[item]'") or die(mysqli_error($conn));
                                        $fitem = mysqli_fetch_array($gitem);

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

                                        Echo "<tr>";
                                        Echo "<td>$tran[vouchno]</td>";
                                        Echo "<td>$tran[date]</td>";
                                        Echo "<td>$fparty[name]</td>";
                                        Echo "<td class='text-right'>$tran[qty]</td>";
                                        Echo "<td class='text-right'>$tran[rate]</td>";
                                        Echo "<td class='text-right'>$tran[amount]</td>";
                                        Echo "</tr>";
                                    }
                                }
                                ?>
                            </tbody>
                        </table>

                    </div>
                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                            <label class="label-control marg">Choose File</label>
                        </div>
                        <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                            <input type="file" name="file1" id="file1" class="form btn btn-primary">
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-12">
                            <img id="preview" src="<?php Echo $imgpath; ?>" alt="your image"/>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </form>
    <div class="modal fade bs-example-modal-lg" 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=" table-responsive">
                        <table id="example1" class="table table-striped table-bordered">
                            <thead>
                                <tr style="" class="mySearchTr">
                                    <th style="width:10px;  text-align:left">Code</th>
                                    <th style="width:70px;  text-align:left">Name</th>
                                    <th style="width:70px;  text-align:left">Group</th>
                                    <th style="width:70px;  text-align:right">Cost</th>
                                    <th style="width:10px;  text-align:right">Rate</th>
                                    <th style="width:10px;  text-align:left">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                if ($addflag != 1) {
                                    $srchresult = mysqli_query($conn, "SELECT `code`,`name`,itemgrp, cost,rate FROM `$maindb` ORDER BY `name`")or die(mysqli_error($conn));
                                    while ($row = mysqli_fetch_array($srchresult)) {
                                        $srcunit = mysqli_query($conn, "SELECT `code`,`name` FROM `unit` where `code`='$row[unit]' ORDER BY `name`")or die(mysqli_error($conn));
                                        $sunit = mysqli_fetch_array($srcunit);

                                        $srcgroup = mysqli_query($conn, "SELECT `code`,`name` FROM `itemgrp` where `code`='$row[itemgrp]' ORDER BY `name`")or die(mysqli_error($conn));
                                        $sgroup = mysqli_fetch_array($srcgroup);

                                        $srcsubgroup = mysqli_query($conn, "SELECT `code`,`name` FROM `itemsubgrp` where `code`='$row[itemsubgrp]' ORDER BY `name`")or die(mysqli_error($conn));
                                        $ssubgroup = mysqli_fetch_array($srcsubgroup);

                                        echo "<tr class='clickable-row' data-href='$file?mode=edit&$keyfld=$row[$keyfld]'>";
                                        echo "<td style='width:10px;  text-align:left; padding-left:20px;'>$row[code]</td>";
                                        echo "<td style='width:10px;  text-align:left; padding-left:20px;'>$row[name]</td>";
                                        echo "<td style='width:10px;  text-align:left; padding-left:20px;'>$sgroup[name]</td>";
                                        echo "<td style='width:10px;  text-align:right; padding-left:20px;'>$row[cost]</td>";
                                        echo "<td style='width:10px;  text-align:right; padding-left:20px;'>$row[rate]</td>";
                                        echo "<td style='width:10px;  text-align:left; padding-left:20px;'><a href=\"$file?mode=edit&$keyfld=$row[code]\"><i class='fa fa-pencil' style='font-size:1.3em;color:#00C0EF;cursor:pointer;'></i></a></td>";
                                        echo "</tr>";
                                    }
                                }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="modal-footer"></div>
            </div>
        </div>
    </div>
    <?php include("includes/linksfoot.php"); ?>
</body>
