@extends('layouts.master')
  @section('page_title')
      @if(isset($page_title))
          {{ $page_title }}
      @endif
  @endsection

@section('content')
  <div class="">
      <div class="page-title">
        <div class="title_left">
          <div class="title_left">
            <ol class="breadcrumb">
              <li><a href="{!! url('dashboard') !!}">Dashboard</a></li>
              <li class="active">Meeting Reports</li>
            </ol>
          </div>
        </div>

        <div class="title_right">
          <div class="row">
            <form method="GET" action="{!! url('reports') !!}">
              <div class="col-md-5 col-sm-5 col-xs-12 form-group">
                <div style="margin-top:1px; margin-right:-90px;" class="top_search">
                  {!! Form::select('filter', $columns, null, ['class' => 'form-control', 'placeholder' => 'Select Filter here']) !!}
                </div>
              </div>
              <div class="col-md-5 col-sm-5 col-xs-12 form-group pull-right top_search" style="margin-top: -2px;">
                <div class="input-group">
                  <input type="text" name="keyword" class="form-control" placeholder="Keyword here...">
                  <span class="input-group-btn">
                    <button type="submit" class="btn btn-primary" style="color: #fff;" type="button">Go!</button>
                  </span>
                </div>
              </div>
            </form>
          </div>
          <div class="row">
              <div class="col-sm-12">
              <div class="pull-right">
                  <a href="{!! url('reports') !!}" class="btn btn-warning btn-xs"><i class="fa fa-refresh"></i> Reset Filter</a>
              </div>
              </div>
          </div>
        </div>
      </div>

      <div class="clearfix"></div>
      <div class="row">
        @include('commons.notifications')
        <div class="col-md-12 col-sm-12 col-xs-12">
        <div class="x_panel">
          <div class="x_title">
            <h2> Meeting Reports </h2>
            <div class="pull-right">
                <a class="btn btn-primary btn-sm" href="{!! url('reports/create') !!}"><i class="fa fa-plus-circle"></i> Add Records
                </a>
            </div>
            <div class="clearfix"></div>
          </div>

          <div class="x_content">

            <div class="table-responsive">
              <table class="table table-striped ">
                <thead>
                  <tr class="headings">
                    <th class="" style="width: 15%;">Client</th>
                    <th class="" style="width: 8%;">Account Manager</th>
                    <th class="" style="width: 10%;">Email</th>
                    <th class="" style="width: 20%;">Discussion</th>
                    <th class="" style="width: 7%;">Payment Type</th>
                    <th class="" style="width: 20%;">Sam's Comments</th>
                    <th class="column-title no-link last" style="width: 5%;"><span class="nobr">Action</span>
                    </th>
                    <th class="bulk-actions" colspan="7">
                      <a class="antoo" style="color:#fff; font-weight:500;">Bulk Actions ( <span class="action-cnt"> </span> ) <i class="fa fa-chevron-down"></i></a>
                    </th>
                  </tr>
                </thead>

                <tbody>
                  @if ($meeting_report_arr->isEmpty())
                    <tr>
                      <td class="text-center bg-danger" colspan="7">You have not made any entries yet</td>
                    </tr>
                  @else
                  @foreach ($meeting_report_arr as $row)
                  <tr class="even pointer">
                    <td class="mes-td" >
                      <strong>{{ $row->client_info->name }}</strong>
                      <br />
                      <small>Contact Person : {{ $row->contact_person }}</small>

                    </td>
                    <td class="mes-td" >{{ $row->auth_user_info->name }}</td>
                    <td class="mes-td" >{{ $row->email }}</td>
                    <td class="mes-td" >{{ $row->discussion }}</td>
                    <td class="mes-td" >{{ $payment_type[$row->payment_type] }}</td>
                    <td class="mes-td" >{{ substr($row->sam_comment, 0, 150) }}</td>
                    
                    <td class="last" >
                      @if($row->auth_user_info->id == session('current_user.id'))
                      <!-- <a href="{!! route('reports.show', [$row->id]) !!}" class="btn btn-xs btn-info"><i class="fa fa-info-circle"></i></a> -->
                      <a href="{!! route('reports.edit', [$row->id]) !!}" class="btn btn-xs btn-primary"><i class="fa fa-edit"></i></a>
                      
                      <a title="Remove Service" class="btn btn-xs btn-danger removeReport"><i class="fa fa-trash"></i></a>                  
                      <input type="hidden" name="report_id" class="reportID" value="{{ $row->id }}">
                      @else
                        <a href="{!! route('reports.show', [$row->id]) !!}" class="btn btn-xs btn-info"><i class="fa fa-info-circle"></i></a>
                      @endif
                    </td>

                  </tr>
                  @endforeach
                  @endif
                </tbody>
              </table>
            </div>
            {{ $meeting_report_arr->links() }} <br>
            Page : {{ $meeting_report_arr->currentPage() }} of {{ $meeting_report_arr->lastPage() }} |
            Total Records : <span id="totalRecords">{{ $meeting_report_arr->total() }}</span>
          </div>
        </div>
      </div>
    </div>
</div>

@endsection

@section('javascript')
  <script type="text/javascript">
  $(document).ready(function(){
    //$('select').select2();
      $(".removeReport").click(function(evt){
          var recordsTotal = Number($('#totalRecords').text());
          var Rrow = $(this).parents('tr');
          var theUrl = "{!! url('reports/destroy') !!}";
          var reportID = $(this).siblings('.reportID').val();
          var linker = base_url + "/reports/" + reportID;
          swal({
              title: "Delete Confirmation",
              text: "This will remove the Report completely from the system. Do you want to continue",
              type: "info",
              showCancelButton: true,
              confirmButtonClass: "btn-danger conBtn",
              confirmButtonText: "Yes, remove it!",
              showLoaderOnConfirm: true,
              closeOnConfirm: false,
              closeOnCancel: false
            },
            function(isConfirm){
              if (isConfirm) {
                  $.ajax({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    type: "DELETE",
                    data: { id: reportID },
                    url: base_url + "/reports/" + reportID,
                    success: function(data){
                        if (data.code === 1) {
                            $(Rrow).remove();
                            $('#totalRecords').text(recordsTotal - 1);
                            swal("Deleted!", "Selected Report has been removed .", "success");
                        }
                        if (data.code === 3) {
                            swal("Not Permitted", "This Operator has transactions! .", "warning");
                        }
                    }
                  });// end of ajax function
              } else {
                swal("Cancelled", "You cancelled the operation :)", "error");
              }
            });
    });
  });
  </script>


@endsection
