@extends('adminlte::page')
@section('content')
    <?php Fun::lang()?>
    <div class="title-add">
        <div class="page-bar"> 
            <ul class="page-breadcrumb"> 
                <li> <a class="ng-binding" href="#"><i class="fa fa-dashboard"></i> Dashboard</a> </li>
                <li><a href="#">Operation</a></li>
                <li><a href="#">Manage Client</a></li>
                <li><a href="#">Manage CRM</a></li>
                <li><a href="#">CRM Report</a></li>
                <li><a href="#">Task</a></li>
            </ul> 
        </div>
    </div>
    <div class="page">
        <div class="top-content">
            <div class="row">
                <div class="col-sm-12 col-xs-12">
                    <div class="title-add">
                        <div class="pull-left">
                            <h3>{{__('administrator.task_report')}} </h3>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="top-content">
            <div class="row">
                <div class="col-sm-12 col-xs-12">
                    <div class="title-add">
                        {!! Form::open(array('route' => 'lead.task-report','method'=>'GET')) !!}
                        <div class="form-group col-sm-6 col-xs-12">
                            <div class="col-sm-3 col-xs-12 ">
                                <label for="name">{{__('administrator.agent')}} </label>
                            </div>
                            <div class="col-sm-9">
                                {!! Form::select('agent_id',$agent,null, array('placeholder' => __('administrator.please_select'),'class' => 'form-control  input-md select2','' )) !!}
                            </div>
                        </div>
                        <div class="form-group col-sm-5 col-xs-12">
                            <div class="col-sm-4 col-xs-12 ">
                                <label for="name">{{__('administrator.status')}} </label>
                            </div>
                            <div class="col-sm-8">
                                {!! Form::select('status',[''=> __('administrator.please_select'),'0'=> __('administrator.pending'),'1'=> __('administrator.complete')],null, array('class' => 'form-control  input-md select2','' )) !!}
                            </div>
                        </div>
                        <div class="col-sm-1 col-xs-12">
                            {!! Form::button( __('administrator.search'), array('type' => 'submit','class'=> 'pull-right btn btn-reddit',))!!}
                        </div>
                        <div class="form-group col-sm-6 col-xs-12">
                            <div class="col-sm-3 col-xs-12 ">
                                <label for="name">{{__('administrator.close_deal')}} </label>
                            </div>
                            <div class="col-sm-9">
                                {!! Form::select('close_deal',[''=> __('administrator.please_select'),'0'=> __('administrator.pending'),'1'=> __('administrator.success'),'2'=> __('administrator.fail')],null, array('class' => 'form-control  input-md select2','' )) !!}
                            </div>
                        </div>
                        <div class="form-group col-sm-5 col-xs-12">
                            <div class="col-sm-4 col-xs-12 ">
                                <label for="name">{{__('administrator.date')}} </label>
                            </div>
                            <div class="col-sm-8">
                                {!! Form::text('date',(@$_GET['date']?@$_GET['date']:''), array('placeholder' =>  __('administrator.date'),'class' => 'form-control  input-md date_picker','' )) !!}
                            </div>
                        </div>
                        <div class="col-sm-1 col-xs-12">
                            <a href="{{route('view-task-report')}}?agent_id={{isset($_GET['agent_id'])?$_GET['agent_id']:'0'}}&date={{isset($_GET['date'])?$_GET['date']:'0'}}&status={{isset($_GET['status'])?$_GET['status']:''}}&close_deal={{isset($_GET['close_deal'])?$_GET['close_deal']:''}}"
                               class="pull-right btn btn-reddit">{{__('administrator.print')}}</a>
                        </div>
                        {{ Form::close() }}
                    </div>
                </div>
            </div>
        </div>
        <div class="box-body">
            <table id="datatable_products" width="100%" class="table table-striped">
                <thead>
                <tr>
                    <th>#</th>
                    <th>{{__('administrator.follower')}}</th>
                    <th>{{__('administrator.lead')}}</th>
                    <th>{{ __('administrator.date') }}</th>
                    <th>{{ __('administrator.time') }}</th>
                    <th>{{ __('administrator.subject') }}</th>
                    <th>{{ __('administrator.task_type') }}</th>
                    <th>{{ __('administrator.contact') }}</th>
                    <th>{{ __('administrator.status') }}</th>
                    <th>{{ __('administrator.close_deal') }}</th>
                </tr>
                </thead>
                <tbody>

                </tbody>
            </table>
        </div>
        </div>

        @endsection
        @section('js')
            <script type="text/javascript">
                $(document).ready(function () {
                    path = window.location.pathname;
                    window.history.replaceState({}, document.title, path);
                    $('#datatable_products').DataTable({
                        ordering: false,
                        serverSide: true,
                        lengthMenu: [[20, 30, 50, 100, 200, 500, 1000], [20, 30, 50, 100, 200, 500, 1000]],
                        ajax: "{{ route('datatable.task-report') }}?agent_id={{isset($_GET['agent_id'])?$_GET['agent_id']:'0'}}&date={{isset($_GET['date'])?$_GET['date']:'0'}}&status={{isset($_GET['status'])?$_GET['status']:''}}&close_deal={{isset($_GET['close_deal'])?$_GET['close_deal']:''}}",
                        columns:
                            [
                                {data: 'DT_RowIndex'},
                                {data: 'agent_name'},
                                {data: 'lead_name'},
                                {data: 'date'},
                                {data: 'hour'},
                                {data: 'subject'},
                                {data: 'task_type'},
                                {data: 'contact'},
                                {data: 'complete_status'},
                                {data: 'convert_status'},
                            ],
                        "initComplete": function (settings, json) {
                        }
                    });
                    $.fn.dataTable.ext.errMode = 'throw';
                });
                $(document).on('click', '.delete_products', function () {
                    $('#form_delete').modal('show');
                    var id = $(this).data("id");
                    $(".deleteRecord").click(function () {
                        var token = $("meta[name='csrf-token']").attr("content");
                        $.ajax({
                            url: "{{route('lead.delete_lead')}}",
                            type: 'GET',
                            data: {
                                "id": id,
                                "_token": token,
                            },
                            success: function () {
                                $('#form_delete').modal('hide');
                                location.reload();

                            }
                        });
                    });
                });
            </script>
@stop

    

