
<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">
            <input name="is_crm" id="is_crm" type="hidden" value="<?php echo $is_crm  ? 1: 0;?>"/>
            <div class="row form-group ">
                <div class="col-md-2">
                    <label><?php  echo CommonLanguage::getMessage('Date');?><span class="red-star">*</span></label>
                    <input type="text" id="current_date" name="current_date" class="form-control"  value="<?php  echo date("Y-m-d");?>"/>
                </div>
                <div class="col-md-2 ">
                    <label><?php  echo CommonLanguage::getMessage('salesman');?></label>
                    <input type="hidden" id="employee_id" name="employee_id" class="full-width" />
                </div>
                <div class="col-md-2 ">
                    <label><?php  echo CommonLanguage::getMessage('user');?></label>
                    <input type="hidden" id="user_id" name="user_id" class="full-width" />
                </div>
                <div class="col-md-2">
                    <label><?php  echo CommonLanguage::getMessage('routes');?></label>
                    <input type="hidden" id="route_ids" name="route_ids" class="full-width" />
                </div> 
                <div class="col-md-4 <?php  echo $is_crm ? 'hidden' : '';?>">
                    <label><?php  echo CommonLanguage::getMessage('type');?></label>
                    <select id="current_type" name="current_type[]" class="full-width" data-init-plugin="select2" multiple >
                         <?php  if(!$is_crm){?>
                        <option value="1" selected><?php  echo CommonLanguage::getMessage('invoices');?></option>
                        <option value="2" selected><?php  echo CommonLanguage::getMessage('customer_visits');?></option>
                        <option value="3" selected><?php  echo CommonLanguage::getMessage('receipts');?></option>
                        <?php }else{?>
                        <option value="" ><?php  echo CommonLanguage::getMessage('select');?></option>
                        <option value="4" selected><?php  echo CommonLanguage::getMessage('meeting');?></option>
                        <?php }?>
                    </select>
                </div>
                <div class="col-md-2">
                    <label><?php echo CommonLanguage::getMessage('status');?></label>
                     <select id="status_id" name="status_id" class="full-width" data-init-plugin="select2" >
                         <option value=""><?php  echo CommonLanguage::getMessage('select');?></option>
                        <option value="1"><?php  echo CommonLanguage::getMessage('with_actions');?></option>
                        <option value="2" selected><?php  echo CommonLanguage::getMessage('without_actions');?></option>
                       
                    </select>
                </div>
                <div class="col-md-2 m-t-20 pull-right">
                    <button style="color:white !important;" class="btn bg-primary-darker white pull-right" id="generate"><?php print CommonLanguage::getMessage('generate_report'); ?></button>
                </div>
            </div>
            <div class=" row   ">
                <div class="col-md-12 table-responsive">
                    <table class="table table-bordered  general-table" id="tableWithSearch" >
                        <thead>
                            <tr>
                                <th class="text-center" style="width:15%" ><?php print CommonLanguage::getMessage('route'); ?></th>
                                <th class="text-center" style="width:15%" ><?php print CommonLanguage::getMessage('user'); ?></th>
                                <th class="text-center" style="width:15%" ><?php print CommonLanguage::getMessage('salesman'); ?></th>
                                <th class="text-center" style="width:15%" ><?php print CommonLanguage::getMessage('customer'); ?></th>
                                <th class="text-center" style="width:15%" ><?php print CommonLanguage::getMessage('Action'); ?></th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        ChangeTable();
        $('#current_date').datepicker({autoclose:true});
//        $('#current_date').datepicker('setDate',new Date());
        build_select2($("#user_id"), "xhr/CommonSearch?col_id=User_ID&col_name=User_Name&table=tbl_common_users");
        build_select2($("#employee_id"), "xhr/employeeSearch");
        build_select2($("#route_ids"), "xhr/commonSearch?table=tbl_route&col_id=route_id&col_name=route_name",1);
        $('#generate').on('click',function(){
            if(!$('#current_date').val()){
                toastr.error('<?php echo CommonLanguage::getMessage('choose_date');?>');
                return;
            }
            ChangeTable();
        });
    });
    function ChangeTable(){
        var data = {current_date:$('#current_date').val(),employee_id:$('#employee_id').val(),
                    user_id:$('#user_id').val(),route_ids:$('#route_ids').val(),
                    current_type:$('#current_type').val(),is_crm:$('#is_crm').val(),
                    status_id:$('#status_id').val()};
        $.ajax({
            url: "GeneralAjax/route_report",
            data: data,
            complete: function (v1, v2) {
                if (v2 == 'success') {
                    $("#tableWithSearch").DataTable().destroy();
                    $("#tableWithSearch tbody").empty().html(v1.responseText);
                    RebuildDataTable($('#panel-heading .panel-title').html(), [], "", {});
                }
            }
        });
    }
</script>