<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('collected_points_list') ?></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" autocomplete="off" />
                    </div>
                </div>
                <div class="col-md-3">
                    <label><?php echo CommonLanguage::getMessage('customer_name') ?></label>
                    <input id="customer_id" type="hidden" class="full-width" name="customer_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>
                            <th class="text-center" style="width:10%"><?php print CommonLanguage::getMessage('customer_name'); ?></th>
                            <th class="text-center" style="width:10%"><?php print CommonLanguage::getMessage('customer_phone'); ?></th>
                            <th class="text-center" style="width:10%"><?php print CommonLanguage::getMessage('collected_points'); ?></th>
                            <th class="text-center" style="width:10%"><?php print CommonLanguage::getMessage('date'); ?></th>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div> 
<script> 
    var title = <?php echo json_encode(CommonLanguage::getMessage('general_setting')); ?>;
    $(function() {
        build_select2($('#customer_id'), 'xhr/customerSearch');
        ChangeTable()
       $("#customer_id").on("change", function() {
            ChangeTable()
        });

        var data_session = get_storage_element(page_link);
        
        if (data_session.Date != '') {
            window.startDate = data_session.from_date;
            window.endDate = data_session.to_date;
            $("input[name=From_To_Date]").val(data_session.Date)
        }
        $("input[name=From_To_Date]").daterangepicker({
            ranges: {
                'Today': [moment(), moment()],
                'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                'This Month': [moment().startOf('month'), moment().endOf('month')],
                'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
            },
            locale: {
                cancelLabel: 'Clear'
            },
            allowEmpty: false,
            autoUpdateInput: false
        });

        $("input[name=From_To_Date]").on('apply.daterangepicker', function(ev, picker) {
            window.startDate = picker.startDate.format('YYYY-MM-DD'),
                window.endDate = picker.endDate.format('YYYY-MM-DD');
            $(this).val(picker.startDate.format('YYYY-MM-DD') + ' - ' + picker.endDate.format('YYYY-MM-DD'));
            ChangeTable();
        });
        $("input[name=From_To_Date]").on('cancel.daterangepicker', function(ev, picker) {
            window.startDate = ''
            window.endDate = ''
            $(this).val('');
            ChangeTable();
        });
      
    })

    function ChangeTable() {

        var Data = {
            from_date: window.startDate,
            to_date: window.endDate,
            customer_id: $('#customer_id').val()
        }
        
        RebuildDataTable(title, [0, 1], 'InventoryAjax/collected_points_list', Data);

    } 
    
</script>
      