@extends('layouts.app')

@section('content')
<div class="card">
    <div class="card-body">
        <h4 class="card-title">Pending Plot Booking Report</h4>
        <div class="table-responsive">
            <table class="table table-bordered" id="customers-table">
                    <thead>
                        <tr>
                            <th>Id</th>
                            <th>Name</th>
                            <th>Username</th>
                            <th>Plot/Block/Sector/Project</th>
                            <th>Created At</th>
                            <th>Updated At</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                </table>
        </div>
    </div>
</div>
<!-- The Modal -->
<div class="modal fade" id="loadModalAjax" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="display: none;" aria-hidden="true">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">

      <!-- Modal Header -->
      <div class="modal-header">
        <h4 class="modal-title">Deal Cancellation</h4>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>

      <!-- Modal body -->
      <div class="modal-body">
        {!! Form::open(['method' => 'POST','id'=> 'cancel_payment', 'data-parsley-validate'=>'', 'url' => ['']]) !!}
        <div class="row">
          <div class="col-md-12">
              <div class="form-group">
                  <input type="checkbox" id="confirm" name="confirm" class="filled-in" />
                  <label class="control-label" for="confirm">Once deal is cancelled it can't be reversed. Are You Sure?</label>
              </div>
          </div>
        </div>
        {!! Form::submit('Submit', ['class' => 'btn btn-danger']) !!}
        {!! Form::close() !!}
      </div>

      <!-- Modal footer -->
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
      </div>

    </div>
  </div>
</div>

@stop

@section('javascript')
    <script>
        $('#customers-table').DataTable({
                processing: true,
                serverSide: true,
                ajax: '{!! url('/') !!}/admin/deals/anydataPendingplotdeals',
                dom: 'Blfrtip',
                'pageLength': 30,
                'lengthMenu': [ [10, 30, 50, -1], [10, 30, 50, "All"] ],
                'buttons': [
                            'copy', 'csv', 'excel', 'pdf', 'print'
                        ],
                'columns': [
                    { data: 'id', name: 'id' },
                    { data: 'full_name', name: 'full_name' },
                    { data: 'username', name: 'username' },
                    { data: 'name', name: 'name' },
                    { data: 'created_at', name: 'created_at' },
                    { data: 'updated_at', name: 'updated_at' },
                    { data: 'action', name: 'action' }
                ],
                'order': [[1, 'asc']],
                drawCallback: function( settings ) {
                    openModal();
                  },
                initComplete: function() {
                    
                }
            });

            function openModal(){
                $('button.cancelDeal').click(function(){
                  $('form#cancel_payment').attr('action', $(this).attr('data-url'));
                  $('#loadModalAjax').modal({show:true});
                });
                
                $('.activate').click(function(){
                    var ele = $(this);
                    $.ajax({
                       url: '{{ url('/') }}/admin/deals/ajax_update/' + $(this).attr('data-id'),
                       type: 'PUT',
                       data: { "_token": "{{ csrf_token() }}", id : $(this).attr('data-id'), active : $(this).attr('data-active') },
                       success: function(response) {
                         if(response == true){
                            if(ele.attr('data-active') == 1){
                                ele.removeClass('btn-warning').addClass('btn-danger').attr('data-active','0').find('span.ladda-label').text('Deactivate');
                            }else{
                                ele.removeClass('btn-danger').addClass('btn-warning').attr('data-active','1').find('span.ladda-label').text('Activate');
                            }
                         }else{
                            alert('error'+ response);
                         }
                       }
                    });
                });              
            }

    </script>
@endsection
