<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title"> <?php print CommonLanguage::getMessage($title); ?></div>
            <div class="row ">
                <div class="col-md-2 ">
                    <select required id="type" name="type" class="full-width " data-init-plugin="select2">
                        <option value="0"><?php echo CommonLanguage::getMessage('sales'); ?></option>
                        <option value="1"><?php echo CommonLanguage::getMessage('purchase'); ?></option>
                    </select>
                </div>
                <div class=" col-md-3 pull-left">
                    <?php echo Forms::snippet_rangepicker(); ?>
                </div>
                <div class=" col-md-2">
                    <input id="StockThreshold" name="StockThreshold" placeholder="<?php print CommonLanguage::getMessage('threshold'); ?>" class="form-control" value="">
                </div>
                <div class="col-md-2">
                    <!--<h5> </h5>-->
                    <button style="color:white !important;" id="Generate_Report" type="button" class="btn bg-primary white" data-toggle="dropdown" aria-expanded="false">
                        <?php print CommonLanguage::getMessage('generate_report'); ?></button>
                </div>
            </div>
            <div class="row ">
                <div class="col-md-3 <?php echo $permissions->hasPermission('Branches') ? '':'hidden'; ?>">
                    <label><?php echo CommonLanguage::getMessage('choose_branch') ?></label>
                    <input id="search_branch_id" type="hidden" class="full-width" name="search_branch_id" >
                </div>


            </div>

        </div>
        <div class="panel-body">
            <div class="row">
                <div class="col-md-12 table-responsive">
                    <table class="table table-bordered inventory" id="tableWithSearch">
                        <thead>
                            <tr>
                                <th class="text-center" style="width:5%"><?php print CommonLanguage::getMessage('Code'); ?></th>
                                <th class="text-center" style="width:15%"><?php print CommonLanguage::getMessage('Item'); ?></th>
                                <th class="text-center" style="width:15%"><?php print CommonLanguage::getMessage('quantity'); ?></th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var title = <?php echo json_encode(CommonLanguage::getMessage('item_list')) ?>,
        today = <?php echo json_encode($today); ?>;
    var is_actual = <?php echo $is_actual; ?>;
    $(function() {
        build_select2($("#search_branch_id"), "xhr/CommonSearch?col_name=branch_name&col_id=branch_id&table=tbl_organization_branches");
        $('#search_branch_id').on('change', function () {
            getProductList();
        });

        getProductList()
        rangepicker_js();
        $("#FromDate").datepicker({
            autoclose: true
        })
        $("#ToDate").datepicker({
            autoclose: true
        })
        $("#Generate_Report").on("click", function(e) {
            getProductList();
        })
    })

    function getProductList() {
        var DateArr = {
            FromDate: window.start ? window.start : today,
            ToDate: window.end ? window.end : today,
            Threshold: $("#StockThreshold").val() ? $("#StockThreshold").val() : 0,
            type: $("#type").val(),
            actual: is_actual,
            search_branch_id: $("#search_branch_id").val()
        };
        RebuildDataTable(title, [0, 1, 2], 'InventoryAjax/UnmovedItemsAjax', DateArr)
    }
</script>