@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="#">Lead</a></li>
                <li><a href="#">Appointment</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.appointment_log')}} </h3>
                        </div>
                        <div class="pull-right">
                                <a href="{{route('meeting.index')}}" class="button_sm button_info bg-olive"> {{ __('administrator.meeting_log') }} </a>
                                <a href="#" class="button_sm button_success "> {{ __('administrator.appointment_log') }}</a>
                                <a href="{{route('call-log.index')}}" class="button_sm button_info bg-olive">{{ __('administrator.call_log') }}</a>
                                <a href="{{route('lead.index')}}" class="button_sm button_info bg-olive"> {{ __('administrator.lead') }}</a>
                        </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' => 'appointment.index','method'=>'GET')) !!}
                        <div class="form-group col-sm-3 col-xs-12">
                            <div class="col-sm-4 col-xs-12 ">
                                <label for="name">{{__('administrator.follower')}} </label>
                            </div>
                            <div class="col-sm-8">
                                {!! Form::select('agent_id',$agent,null, array('placeholder' =>__('administrator.please_select'),'class' => 'form-control  input-sm select2','' )) !!}
                            </div>
                        </div>
                        <div class="form-group col-sm-3 col-xs-12">
                            <div class="col-sm-4 col-xs-12 ">
                                <label for="name">{{__('administrator.lead')}} </label>
                            </div>
                            <div class="col-sm-8">
                                {!! Form::select('leadname',$lead,(@$_GET['leadname']?@$_GET['leadname']:''), array('placeholder' =>__('administrator.please_select'),'class' => 'form-control   input-sm select2','' )) !!}
                            </div>
                        </div>
                        <div class="form-group col-sm-3 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-sm date_picker','' )) !!}
                            </div>
                        </div>
                        <div class="col-sm-1 col-xs-12">
                            {!! Form::button(__('administrator.search'), array('type' => 'submit','class'=> 'pull-right btn btn-default',))!!}
                        </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.subject')}} </th>
                    <th>{{__('administrator.place')}} </th>
                    <th>{{__('administrator.date')}} </th>
                    <th>{{__('administrator.time')}} </th>
                    <th>{{__('administrator.note')}} </th>
                    <th width="9%">{{__('administrator.status')}} </th>
                    <th>{{__('administrator.action')}} </th>
                </tr>
                </thead>
                <tbody>

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

    <div class="modal fade bs-modal-lg" id="form_delete" tabindex="-1" role="dialog" aria-hidden="true">
            <div class="modal-dialog modal-dm">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                        <h3 class="modal-title">Are you sure?</h3>
                    </div>
                    <br/>
                    <form role="form" method="delete" id="delete">
                        {{csrf_field()}}
                        <div class="row">
                            <div class="col-md-12">
                                <div class="col-md-10">
                                    <h4>Are you want to delete?</h4>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" data-dismiss="modal" class="button_danger"><i class="fa fa-close"></i> No</button>
                            <button type="button" class="button_primary deleteRecord" data-toggle="modal"><i class="fa fa-save"></i> OK</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
@endsection



@section('js')
    <script type="text/javascript">
        $(document).ready(function() {
            $('#datatable_products').DataTable({
                ordering: false,
                serverSide: true,
                lengthMenu: [[10, 20, 40, 100,200,500,1000], [10, 20, 40, 100,200,500,1000]],
                ajax: "{{ route('datatable_appointment') }}?agent_id={{isset($_GET['agent_id'])?$_GET['agent_id']:'0'}}&date={{isset($_GET['date'])?$_GET['date']:'0'}}&leadname={{isset($_GET['leadname'])?$_GET['leadname']:'0'}}",
                columns:
                    [
                        {data: 'DT_RowIndex','searchable':false},
                        {data: 'agent_name',"name":"users.name"},
                        {data: 'lead_id',"name":'nso007_crm_leads.name'},
                        {data: 'subject','name':'nso007_crm_task.subject'},
                        {data: 'where','name':'nso007_crm_task.where'},
                        {data: 'date','name':'nso007_crm_task.date'},
                        {data: 'hour','name':'nso007_crm_task.hour'},
                        {data: 'note','name':'nso007_crm_task.note'},
                        {data: 'complete_status'},
                        {data: 'action'},
                    ],
                "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('appointment.delete_appointment')}}",
                    type: 'GET',
                    data: {
                        "id": id,
                        "_token": token,
                    },
                    success: function (){
                        $('#form_delete').modal('hide');
                        location.reload();

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



