<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title">
                <h4 class="bold"><?php echo $title; ?> </h4>
            </div>
            <div class="row">
                <div class="col-md-2">
                    <label><?php echo CommonLanguage::getMessage('users'); ?></label>
                    <select id="users" class="full-width Account_Code " multiple data-init-plugin="select2">
                        <?php foreach ($users as $user) : ?>
                            <option value="<?php echo $user['User_ID']; ?>"><?php echo $user['User_Name']; ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class=" col-md-3 input-daterange " id="datepicker-range">
                    <label><?php print CommonLanguage::getMessage('range_date'); ?></label>
                    <input id="From_To_Date" type="text" class="form-control" name="From_To_Date">
                </div>
                <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" id="MyTable">
                    <table class="table table-bordered inventory" id="tableWithSearch">
                        <thead>
                            <tr>
                                <th class="text-center" style="width:5%"><?php print CommonLanguage::getMessage('Name'); ?></th>
                                <th class="text-center" style="width:5%"><?php print CommonLanguage::getMessage('Code'); ?></th>
                                <th class="text-center" style="width:10%"><?php print CommonLanguage::getMessage('quantity'); ?></th>
                                <th class="text-center" style="width:10%"><?php print CommonLanguage::getMessage('Price'); ?></th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var ViewLang = <?php echo json_encode(CommonLanguage::getMessage('view')); ?>;
    var title = <?php echo json_encode(CommonLanguage::getMessage('invoice_per_time')); ?>;
    var fromdate = <?php echo json_encode($from_day) ?>,
        today = <?php echo json_encode($today) ?>;
    var is_actual = <?php echo json_encode($is_actual); ?>;
    $(function() {
        build_select2($("#search_branch_id"), "xhr/CommonSearch?col_name=branch_name&col_id=branch_id&table=tbl_organization_branches");
 
        $("input[name=From_To_Date]").daterangepicker({
            locale: {
                format: 'YYYY-MM-DD'
            },
            startDate: fromdate
        }, function(start, end, label) {
            window.startDate = start.format("YYYY-MM-DD"),
                window.endDate = end.format("YYYY-MM-DD")
            ActualAjax()
        });
        ActualAjax()
        $("#users,#search_branch_id").on("change", function() {
            ActualAjax()
        })
    })

    function ActualAjax() {
        var CurrentDate = {
            From_Date: window.startDate ? window.startDate : fromdate,
            To_Date: window.endDate ? window.endDate : today,
            users: $("#users").val(),
            search_branch_id: $("#search_branch_id").val(),
            is_customer: 1,
            is_actual: is_actual
        };
        RebuildDataTable(title, [0, 1, 2], "InventoryAjax/TotalReturnItemsPerDateAjax", CurrentDate)
    }
</script>