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

$formname = 'Supplier Bulk Update';
$maindb = 'accmast';
$file = 'suppbulkupdate.php?mode=last';

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

if (isset($_GET["mode"]) == "true") {
    $addflag = 1;
} else {
    $addflag = 0;
}

if (isset($_POST['submit'])) {
    $count = $_POST["count"];

    for ($i = 0; $i < $count; $i++) {
        $code = $_POST['code_' . $i];
        $retail = $_POST['retail_' . $i];
        
        mysqli_query($conn, "UPDATE `$maindb` SET `retail`='$retail' WHERE code='$code' ") or die(mysqli_error($conn));
    }
    updmess();
    header("refresh: 1; $file");
}

include("includes/linkshead.php");
?>

<script>
    $(document).ready(function () {
        $("#cmbgrp").change(function () {
            var cmbgrp = $('#cmbgrp').val();
            $.ajax({
                type: "GET",
                url: "get_item_bulk.php",
                data: {code: cmbgrp},
                success: function (result) {
                    $("#data").html(result);
                }
            });
        });



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

    $(document).keydown(function (event) {
        //19 for Mac Command+S
        if (!(String.fromCharCode(event.which).toLowerCase() == 's' && event.ctrlKey) && !(event.which == 19))
            return true;
        //alert("Ctrl-s pressed");
        $("#submit").click();
        event.preventDefault();
        return false;
    });
</script>
<!-- main content start-->
<div class="panel panel-widget forms-panel my-div width col-lg-12" >
    <div class="forms">
        <div class="form-grids widget-shadow" data-example-id="basic-forms"> 
            <div class="form-title">
                <h4><?php echo $formname ?> </h4>
            </div>
            <form name="" class="validation" id="form" action="" method="post">
                <div class="row">
                    <h3 style='color:red'>For Active Enter "1",  For Inactive Enter "0"</h3>

                </div>

                <div class="row">
                    <div class="form-body">
                        <div class="form-group has-error">
                            <label class="col-sm-2 control-label">Supplier</label>
                            <div class="col-sm-5">
                                <select id="cmbgrp" name="cmbgrp" style="height:35px;"  class="cmbgrp form-control">
                                    <option value=  ""></option>
                                    <option value="">All</option>
                                    <?php
                                    $mown = mysqli_query($conn, "SELECT accode, `name` FROM `accmast` where grpcode = '009' order by name ") or die(mysqli_error($conn));
                                    while ($trow = mysqli_fetch_array($mown)) {
                                        echo "<option value='$trow[accode]'>$trow[name]</option>";
                                    }
                                    ?>  

                                </select>
                                <input type="text" id="custhidden" hidden>
                            </div>                            
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div style="overflow: auto; border: 0px ;">
                        <div style="float:left;">
                            <div style="overflow-y:scroll;height:400px" class="table-responsive">
                                <table class="table table-bordered table-responsive " width="100%" >
                                    <tr class='mySearchTr' style='background-color:#64CCFC'>
                                        <th style='width:15%'><label class='control-label right'>Name </label></th>
                                        <th style='width:10%'><label class='control-label right'>Add 1</label></th>
                                        <th style='width:10%'><label class='control-label right'>Add 2</label></th>
                                        <th style='width:10%'><label class='control-label right'>Add 3</label></th>
                                        <th style='width:7%'><label class='control-label right'>Mob 1</label></th>
                                        <th style='width:7%'><label class='control-label right'>Mob 2</label></th>
                                        <th style='width:10%'><label class='control-label right'>Email</label></th>
                                        <th style='width:10%'><label class='control-label right'>Con. Pers</label></th>
                                        <th style='width:9%'><label class='control-label right'>Gst No.</label></th>
                                        <th style='width:5%'><label class='control-label right'>Open Bal</label></th>
                                        <th style='width:2%'><label class='control-label right'>Open DC</label></th>
                                        <th align='right'  style='width:5%'><label class='control-label right'>Status</label></th>
                                    </tr>
                                    <tbody id='data' >

                                    </tbody>
                                </table>
                            </div>                  
                        </div> 
                    </div>
                </div>
                <div style="overflow: auto; ">
                    <table class="table-condensed" style="margin: 0 auto;">
                        <tr>
                            <td class=" buttonform tooltip-bottom" id="ssubmit" style="display: <? Echo $savedisabled ?>" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Save Record">
                                <button id='submit' type='submit' name='submit' value='<?php echo ($addflag == 0) ? "Update" : "Save"; ?>' class="btn btn-pad btn-square " style="background-color:#008D4C; ">
                                    <i class="fa fa-check" style="color:#ffffff"></i>
                                </button>
                            </td>
                            <td class=" buttonform tooltip-bottom" id="hexit" style="display: <? Echo $exitdisabled ?>" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Exit">
                                <button id='exit' type="button" class="btn btn-pad btn-square " style="background-color:#cccccc; "  onClick="window.location.href = '<?= 'karbulkupdate.php' ?>'">
                                    <i class="fa fa-power-off" style="color:red"></i>
                                </button>
                            </td>
                        </tr>
                    </table>
                </div>
            </form>
        </div>
    </div>
</div>
<!--//validator js-->
<?php
include("includes/linksfoot.php");
include("includes/valid.php");
?>
</body>
</html>
