<style>
    .actionButton{
        background-color:#ed9421!important;
    }
</style>
<div class="container-fluid container-fixed-lg bg-white" >
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title"> <?php print $title; ?></div>
        </div>
        <div class="panel-body form-group">
            <div class="row m-t-10">
                <div class="col-md-2">
                    <label><?php echo CommonLanguage::getMessage('Depot') ?></label>

                    <select required id="Depot_ID" name="Depot_Loc" class="full-width " data-init-plugin="select2">
                        <option value="All"><?php print CommonLanguage::getMessage('All') ?></option>
                        <?php foreach ($all_depots as $Depot): ?>
                            <option value="<?php echo $Depot['Depot_ID']; ?>"><?php echo $Depot['Depot_Name']; ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="col-md-3 ">
                    <label><?php echo CommonLanguage::getMessage('Date') ?></label>

                    <?php echo Forms::snippet_rangepicker(); ?>
                </div>


                <div class="col-md-2 m-t-25">
                    <button id="Generate_Report" type="button" class="btn bg-complete-darker white" data-toggle="dropdown" aria-expanded="false">
                        <?php print CommonLanguage::getMessage('generate_report'); ?>
                    </button>
                </div>
                <?php
                if ($permissions->hasPermission($is_actual ? ($is_adjust ? 'act_adjust_product_quantity' : 'act_assign_product_quantity') : ($is_adjust ? 'adjust_product_quantity' : 'assign_product_quantity'))) {
                    ?>
                    <div class="col-md-2 pull-right">    
                        <div class="floatingContainer ">
                            <a href="Stock/add_assign<?php echo ($is_actual ? '/act' : '') . ($is_adjust ? '/adj' : '') ?>" >
                                <div class="actionButton" >
                                    <p class="floatingText"><span class="floatingTextBG"><?php echo CommonLanguage::getMessage('add') ?></span></p>
                                </div>
                            </a>
                        </div>
                    </div>
                <?php } ?>
            </div>

            <div class="row">
                <div class="col-md-12">
                    <div class="table-responsive">
                        <table class="table table-bordered stock" id="tableWithSearch" >
                            <thead>
                                <tr>
                                    <th class="text-center">#</th>
                                    <th class="text-center" ><?php print CommonLanguage::getMessage('Depot'); ?></th>
                                    <th class="text-center no-print" ><?php print CommonLanguage::getMessage('note'); ?></th>
                                    <th class="text-center no-print" ><?php print CommonLanguage::getMessage('Date'); ?></th>
                                    <th class="text-center"  ><?php print CommonLanguage::getMessage('Action'); ?></th>

                                </tr>
                            </thead>
                            <tbody>
                            </tbody>

                        </table>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>
<script>
    var title = <?php echo json_encode($title); ?>,
            today = <?php echo json_encode($today); ?>,
            is_adjust = <?php echo json_encode($is_adjust); ?>,
            is_actual = <?php echo json_encode($is_actual); ?>;
    $(function () {
        build_table()
        rangepicker_js();
        $("#Generate_Report").on("click", function () {
            build_table()
        })

        $("#tableWithSearch").on("click", ".delete", function () {
            var entry_value = $(this).parents('.Action').attr('data-id');
            var data = {
                id: entry_value
            };
            IncludeDeleteModal(common_delete_modal, data, function () {
                build_table();
            }, "StockAjax/delete_assign_ajax");
        })
    })
    function build_table() {
        var currentData = {
            From_Date: window.start ? window.start : today,
            To_Date: window.end ? window.end : today,
            depot_id: $("#Depot_ID").val(),
            is_actual: is_actual,
            assign_type: is_adjust,
        }

        RebuildDataTable(title, [0, 1, 2, 3, 4], 'StockAjax/assign_list_ajax', currentData);


    }
</script>
