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

$formname = 'Opening Stock';
$maindb = 'item';
$file = 'openstock.php';
$trandbexist = 0;
$grid = '';
$keyfld = "code";
$focusfield = "name";

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);

if (isset($_POST["submit"])) {
    $a = 1;
    if ($a == 1) {


        $a = 1;
        $count = $_POST["count"];
//    browse($count);
        $mvouch = $qvouch;
        $cnt = 0;
        for ($i = 0; $i <= $count; $i++) {
            $cost = $_POST["cost_$i"];
            $selling = $_POST["selling_$i"];
            $msp = $_POST["msp_$i"];
            $mrp = $_POST["mrp_$i"];
//            $opening = $_POST["opening_$i"];
            $code = $_POST["code_$i"];

            mysqli_query($conn, "UPDATE `$maindb` SET  `cost`='$cost', `rate`='$selling' WHERE `code`='$code'") or die(mysqli_error($conn));
        }

        updmess();
        header("Refresh: 1; openstock.php");
    }
}

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

include("includes/linkshead.php");
?>
<script>
    $(document).ready(function () {
        $(".savetabl").hide();

        $("#proceed").click(function () {
            var itemgrp = $('#itemgrp').val();
            var subgrp = $('#subgrp').val();

            $.ajax({
                type: "GET",
                url: "opnstksrch.php",
                data: {itemgrp: itemgrp, subgrp: subgrp},
                success: function (result) {
                    if (result != '') {
                        $(".savetabl").show();
                        $(".proctabl").hide();
                    } else {
                        $(".proctabl").show();
                    }
                    $("#data").html(result);

                }
            });
        });
//        $('#submit').click(function () {
//
//            $('#bill').submit();
//        });

    });

</script>
</head>
<body>
    <form action='' method='POST'>
        <!-- Default box -->
        <div class="row">
            <div class="col-lg-12">
                <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>
                            <i class="fa fa-times"></i>
                        </div>
                    </div>
                    <div class="panel-body proctabl">
                        <div class="row">
                            <div class="col-lg-4 col-md-1 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Item Group</label>
                            </div>
                            <div class="col-lg-3 col-md-1 col-sm-3 col-xs-3 pad">
                                <select id="itemgrp" name="itemgrp" style="height:35px;"  class="itemgrp form-control">
                                    <option></option>
                                    <?php
                                    $mown = mysqli_query($conn, "SELECT code, `name` FROM `itemgrp` ") or die(mysqli_error($conn));
                                    while ($trow = mysqli_fetch_array($mown)) {
                                        echo "<option value=$trow[code]>$trow[name]</option>";
                                    }
                                    ?>

                                </select>
                                <input type="text" id="custhidden" hidden>
                            </div>
                        </div>
<!--                        <div class="row">
                            <div class="col-lg-4 col-md-1 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Sub Group</label>
                            </div>
                            <div class="col-lg-3 col-md-1 col-sm-3 col-xs-3 pad">
                                <select id="subgrp" name="subgrp" style="height:35px;"  class="subgrp form-control">
                                    <option></option>
                                    <?php
                                    $mown1 = mysqli_query($conn, "SELECT code, `name` FROM `itemsubgrp` ") or die(mysqli_error($conn));
                                    while ($trow1 = mysqli_fetch_array($mown1)) {
                                        echo "<option value=$trow1[code]>$trow1[name]</option>";
                                    }
                                    ?>

                                </select>
                                <input type="text" id="custhidden" hidden>
                            </div>
                        </div>-->
                    </div>
                </div>
                <div class='panel-footer'>
                    <div style="overflow: auto; ">
                        <table class="table-condensed proctabl" style="margin: 0 auto;">
                            <tr>
                                <td>
                                    <input id="proceed" type='button' name='proceed'  value='Proceed' class="btn btn-success">

                                    <!--                                    <button id='proceed' type='proceed' name='proceed' value='Proceed' class="btn btn-pad btn-square " style="background-color: greenyellow">Proceed
                                                                        </button>-->
                                </td>
                                <td>
                                    <input class="btn btn-danger" type="button" onClick="window.location.href = '<?= 'default.php' ?>'" value="Exit   " />
<!--                                    <button id='exit' type="button" class="btn btn-pad btn-square " style="background-color:#cccccc; "  onClick="window.location.href = '<?= 'default.php' ?>'">
                                        Exit
                                    </button>-->
                                </td>
    <!--                                    <td class=" buttonform tooltip-bottom" id="scancel" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Cancel Record">
                                            <button id='cancel' type="button" class="btn btn-pad btn-square " style="background-color:#39CCCC; "  onClick="window.location.href = '<?= $file . "?mode=last" ?>'">
                                                <i class="fa fa-times" style="color:#ffffff"></i>
                                            </button>
                                        </td>-->
                            </tr>
                        </table>
                        <table class="table-condensed savetabl"  style="margin: 0 auto;">
                            <tr>
                                <td>
                                    <input id="submit" type='submit' name='submit'  value='Save   ' class="btn btn-success">
                                </td>
                                <td>
                                    <input class="btn btn-danger" type="button" onClick="window.location.href = '<?= $file ?>'" value="Exit   " />
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
                <div class="col-lg-12" id="data" style="overflow-x: scroll;height:500px;">

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


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