<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('view_customer_visits') ?></div>
            <div class="row">
                <div class="  col-md-3" >
                    <label><?php echo CommonLanguage::getMessage('Date'); ?></label>
                    <div class="input-group">
                        <span class="input-group-addon bg-primary"><i class="fa fa-calendar"></i></span>
                        <input id="From_To_Date" type="text" class="form-control" name="From_To_Date" >
                    </div>
                </div>
                <div class="col-md-3">
                    <label><?php echo CommonLanguage::getMessage('users'); ?></label>
                    <select  id="users"  class="full-width Account_Code " data-init-plugin="select2">
                        <option value="0"><?php echo CommonLanguage::getMessage('All'); ?></option>
                        <?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">
                    <label><?php echo CommonLanguage::getMessage('customer'); ?></label>
                    <input type="hidden" id="customer_filter" class="full-width"/>
                </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><?php print CommonLanguage::getMessage('username') ?></th>
                                <th><?php print CommonLanguage::getMessage('customer') ?></th>
                                <th><?php print CommonLanguage::getMessage('Date') ?></th>
                                <th><?php print CommonLanguage::getMessage('time') ?></th>
                                <th><?php print CommonLanguage::getMessage('Action') ?></th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var act_title = <?php echo json_encode(CommonLanguage::getMessage('view_customer_visits')); ?>;
    var today = <?php echo json_encode($today) ?>;
    var is_actual = 0;
    $(function () {
        rebuild_table()
        build_select2($("#customer_filter"), "xhr/customerSearch")
        $("input[name=From_To_Date]").daterangepicker({
        }, function (start, end, label) {
            window.startDate = start.format("YYYY-MM-DD"),
                window.endDate = end.format("YYYY-MM-DD")
            rebuild_table()
        });
        $("#users,#customer_filter,input[name=From_To_Date]").on("change", function () {
            rebuild_table()
        });
    })
    function rebuild_table() {
        RebuildDataTable(act_title, [0, 1, 2, 3, 4], "InventoryAjax/view_customer_visits",
                         {user: $("#users").val(), customer: $("#customer_filter").val(),
                          from: (window.startDate ? window.startDate : today),
                          to: (window.endDate ? window.endDate : today)})
    }
</script>