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

$zdb = $_SESSION["zdbyear_" . $dbname];
$zyear = right($zdb, 4);
$mfrdate = getzdates($zyear, 'S');
$mtodate = getzdates($zyear, 'E');

$formname = "Stock";
$action = "stock_fr.php";
mysqli_select_db($conn, $zdb);

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

        $("body").on('change', '#forclosestk', chkClosestk);


        $(".stkvl").hide();
        $('#prnval').on('change', function() {
            if (this.value == '2') {
                $(".stkvl").show();
            } else {
                $(".stkvl").hide();
            }
        });

        function chkClosestk() {
            var forclosestk = $('.forclosestk').val();
            var fromdate = $('.fromdate').val(),
                todate = $('.todate').val();

            if (forclosestk > 0) {
                $(".prodcode").val("");
                $(".product").val("").trigger("change");
                $(".prodgrp").val("").trigger("change");
                $("#mfrdt").val(fromdate);
                $("#mtodt").val(todate);
                $(".prnval").val("2").trigger("change");
            } else {
                $(".prnval").val("1").trigger("change");
            }

        }

    });
</script>
<script src="MyScript/stock.js" type="text/javascript"></script>
</head>

<body>
    <form method='POST' action="<?= $action; ?>">
        <!-- Default box -->

        <div class="col-lg-5 col-md-5 col-sm-10 col-xs-10 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-ms-3 col-xs-3 text-right pad">
                            <label class="label-control marg">For Closing Stock</label>
                        </div>
                        <div class="col-lg-2 col-md-2 col-sm-8 col-lg-8 pad">
                            <select name="forclosestk" id="forclosestk" class="form-control select2 forclosestk" style="height:33px;">
                                <option value="0">No</option>
                                <option value="1">Yes</option>
                            </select>
                        </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">Barcode</label>
                        </div>
                        <div class="col-lg-4 col-md-6 col-sm-8 col-xs-8 pad">
                            <input type="text" class="form-control prodcode" name="prodcode" value="">
                        </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">Product</label>
                        </div>
                        <div class="col-lg-6 col-md-6 col-sm-8 col-xs-8 pad">
                            <select class="form-control select2 product" name="product">
                                <option></option>
                                <?php
                                $gprod = mysqli_query($conn, "SELECT code, barcode, `name` FROM `product` order by `name` ") or die(mysqli_error($conn));
                                while ($prod = mysqli_fetch_array($gprod)) {
                                    echo "<option value='$prod[code]'>$prod[name]</option>";
                                }
                                ?>
                            </select>
                        </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">Type</label>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-8 col-xs-8 pad">
                            <select class="form-control select2 type" name="type">
                                <option value=""></option>
                                <option value="Organic">ORGANIC</option>
                                <option value="Other">CONVENTIONAL</option>
                            </select>
                        </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">From Date</label>
                        </div>
                        <div class="col-lg-3 col-md-4 col-sm-6 col-xs-6 pad">
                            <input type="date" id="mfrdt" name="frmdt" class="form-control" value="<?php echo $mfrdate; ?>">
                            <input type="hidden" class="fromdate" value="<?php echo $mfrdate; ?>" />
                        </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">To Date</label>
                        </div>
                        <div class="col-lg-3 col-md-4 col-sm-8 col-xs-8 pad">
                            <input type="date" id="mtodt" name="todt" class="form-control" value="<?php echo $mtodate; ?>">
                            <input type="hidden" class="todate" value="<?php echo $mtodate; ?>" />
                        </div>
                    </div>


                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-ms-3 col-xs-3 text-right pad">
                            <label class="label-control marg">Print Value</label>
                        </div>
                        <div class="col-lg-2 col-md-2 col-sm-8 col-lg-8 pad">
                            <select name="prnval" id="prnval" class="form-control select2 prnval" style="height:33px;">
                                <option value="1">No</option>
                                <option value="2">Yes</option>
                            </select>
                        </div>
                    </div>

                    <!-- <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right stkvl pad">
                            <label class="label-control marg">Stock By</label>
                        </div>
                        <div class="col-lg-2 col-md-2 col-sm-8 col-lg-8 stkvl pad">
                            <select class='form-control select2 prinval' name='prinval'  style="height:33px;" >
                                <option value=""></option>
                                <option value="C" selected>Cost</option>
                                <option value="R">Rate</option>
                            </select>
                        </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">Print Value</label>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-8 col-xs-8 pad">
                            <select class="form-control select2 prinval" name="prinval">
                                <option></option>
                                <?php
                                // echo "<option value='C'>Cost Price</option>";
                                // echo "<option value='R'>Selling Price</option>";
                                ?>
                            </select>
                        </div>
                    </div> -->


                </div>
                <div class="panel-footer text-center">
                    <?php include("includes/but_rep.php"); ?>
                </div>
            </div>
        </div>
    </form>
    <?php include("includes/linksfoot.php"); ?>
</body>

</html>