@extends('layouts.app')

@section('content')
    <div class="card card-outline-info">
        <div class="card-header">
            <h4 class="m-b-0 text-white">Create Payment</h4>
        </div>
    <div class="card-body">
    {!! Form::open(['method' => 'POST','id'=> 'register_frm', 'data-parsley-validate'=>'', 'url' => [url('/admin/advancePayments/addPayment/').'/'.$associate->id]]) !!}
        <div class="form-body control-group">
            <h3 class="card-title">Select Method</h3>
            <div class="row">
              <div class="col-md-3">
                  <div class="form-group">
                      <label class="control-label" for="payment_type">Payment Mode*</label>
                      {!! Form::select('payment_type', $payment_methods, [], ['class' => 'form-control form-control-normal', 'id'=>'payment_type']) !!}
                      @if($errors->has('payment_type'))
                          <p class="help-block error alert">
                            {{ $errors->first('payment_type') }}
                          </p>
                      @endif
                  </div>
              </div>
              <div class="col-md-3">
                  <div class="form-group">
                      <label class="control-label" for="amount">Amount*</label>
                      <input type="text" id="amount" name="amount" required="required" class="form-control" value="">
                        @if ($errors->has('amount'))
                          <p class="help-block">
                              <strong>{{ $errors->first('amount') }}</strong>
                          </p>
                        @endif
                  </div>
              </div>
              <div class="col-md-3 payOpt">
                  <div class="form-group">
                      <label class="control-label" for="bank_name">Bank Name*</label>
                      <input type="text" id="bank_name" name="bank_name" required="required" class="form-control" value="">
                        @if ($errors->has('bank_name'))
                          <p class="help-block">
                              <strong>{{ $errors->first('bank_name') }}</strong>
                          </p>
                        @endif
                  </div>
              </div>
              <div class="col-md-3 payOpt">
                  <div class="form-group">
                      <label class="control-label" for="bank_branch">Branch Address*</label>
                      <input type="text" id="bank_branch" name="bank_branch" required="required" class="form-control" value="">
                        @if ($errors->has('bank_branch'))
                          <p class="help-block">
                              <strong>{{ $errors->first('bank_branch') }}</strong>
                          </p>
                        @endif
                  </div>
              </div>
              <div class="col-md-3 payOpt">
                  <div class="form-group">
                      <label class="control-label" for="payment_reference">Cheque/DD/UTR/TXN No.*</label>
                      <input type="text" id="payment_reference" name="payment_reference" required="required" class="form-control" value="">
                        @if ($errors->has('payment_reference'))
                          <p class="help-block">
                              <strong>{{ $errors->first('payment_reference') }}</strong>
                          </p>
                        @endif
                  </div>
              </div>
              <div class="col-md-3 payOpt">
                  <div class="form-group">
                      <label class="control-label" for="payment_date">Cheque/DD/NEFT/RTGS Date*</label>
                      <input type="text" id="payment_date" name="payment_date" required="required" class="form-control mydatepicker" value="">
                        @if ($errors->has('payment_date'))
                          <p class="help-block">
                              <strong>{{ $errors->first('payment_date') }}</strong>
                          </p>
                        @endif
                  </div>
              </div>
              <div class="col-md-3">
                  <div class="form-group">
                      <label class="control-label" for="comment">Remarks</label>
                      <input type="text" id="comment" name="comment" class="form-control" value="">
                        @if ($errors->has('comment'))
                          <p class="help-block">
                              <strong>{{ $errors->first('comment') }}</strong>
                          </p>
                        @endif
                  </div>
              </div>
            </div>
            <div class="row" id="emi_payment">
            </div>
            <input type="hidden" name="associate_id" id="associate_id" value="{{$associate->id}}">
    {!! Form::submit('Submit', ['class' => 'btn btn-danger', 'id' => 'submit-button']) !!}
    {!! Form::close() !!}
    </div>
    </div>
    <div class="row">
    <div class="card-body">
        <h3 class="card-title">Business Partner Detail</h3>
        <div class="row">
          <div class="col-md-3" id="registryAmount">
            <div class="form-group">
                <label class="control-label font-bold" for="registry_amount">Name : </label>
                <span class="" id="registry_amount">{{ $associate->full_name }}</span>
            </div>
          </div>
          <div class="col-md-3" id="registryAmount">
              <div class="form-group">
                  <label class="control-label font-bold" for="registry_amount">Username : </label>
                  <span class="" id="registry_amount">{{ $associate->username }}</span>
              </div>
          </div>
          <div class="col-md-3" id="registryAmount">
              <div class="form-group">
                  <label class="control-label font-bold" for="registry_amount">Designation : </label>
                  <span class="" id="registry_amount">{{ $associate->commission_rate }}%</span>
              </div>
          </div>
        </div>
        <h3 class="card-title">Previous Advance Payments Granted</h3>
        <div class="x_content">
          <table id="datatable-fixed-header" class="table table-striped table-bordered">
            <thead>
              <tr>
                <th>Amount</th>
                <th>Remark</th>
                <th>Status</th>
                <th>Created at</th>
                <th>Action</th>
              </tr>
            </thead>


            <tbody>
            @foreach ($advancePayments as $payment)
              <tr>
                <td>{{ IND_money_format($payment->amount) }}</td>
                <td>{!! str_replace('/////////////', '<br />', $payment->comment) !!}</td>
                <td>{{ ($payment->status==1)?'Cancelled':'Approved' }}</td>
                <td>{{ $payment->created_at }}</td>
                <td>
                  @if($payment->status == 0)
                    <button type="button" class="btn btn-sm btn-danger cancel_payment" data-url="{{ url('/admin/advancePayments/cancelpayment'.'/'.$payment->id) }}">Cancel</button>
                  @else
                    <span class="bg-{{($payment->status == 1)?'danger':''}}" style="color: #fff;">{{($payment->status == 1)?'Cancelled':''}} on {{$payment->paid_on}}</span>
                  @endif
                </td>
              </tr>
            @endforeach
            </tbody>
          </table>
        </div>
      </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">Payment 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">
                  <label class="control-label" for="payment_reference">Remark</label>
                  <textarea type="text" id="cancel_comment" name="comment" required="required" class="form-control" value=""></textarea>
              </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')
    <!-- Date picker plugins css -->
    <link href="{{ url('assets') }}/plugins/bootstrap-datepicker/bootstrap-datepicker.min.css" rel="stylesheet" type="text/css" />
    <!-- Daterange picker plugins css -->
    <link href="{{ url('assets') }}/plugins/timepicker/bootstrap-timepicker.min.css" rel="stylesheet">
    <link href="{{ url('assets') }}/plugins/bootstrap-daterangepicker/daterangepicker.css" rel="stylesheet">
    <!-- Date Picker Plugin JavaScript -->
    <script src="{{ url('assets') }}/plugins/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
    <!-- Date range Plugin JavaScript -->
    <script src="{{ url('assets') }}/plugins/timepicker/bootstrap-timepicker.min.js"></script>
    <script src="{{ url('assets') }}/plugins/bootstrap-daterangepicker/daterangepicker.js"></script>
    <script src="{{ url('assets') }}/js/jqBootstrapValidation.js"></script>
    <link href="{{ url('assets') }}/plugins/EasyAutocomplete/easy-autocomplete.min.css" rel="stylesheet">
    <script src="{{ url('assets') }}/plugins/EasyAutocomplete/jquery.easy-autocomplete.min.js"></script>
    <script src="{{ url('assets') }}/js/typeahead.bundle.js"></script>
    <!-- Parsley -->
    <script>
      
      jQuery(document).ready(function() {
      $('div.payOpt').hide();
      jQuery('.mydatepicker, #datepicker').datepicker({format: 'yyyy-mm-dd'});
      $('select#payment_type').on('change', function() {
        if( this.value == 'Cash' || this.value == ''){
          $('div.payOpt').hide();
        }else{
          $('div.payOpt').show();
        }
      });
       jQuery('#datatable-fixed-header').DataTable({
          fixedHeader: true
        });
        $('button.cancel_payment').click(function(){
          $('form#cancel_payment').attr('action', $(this).attr('data-url'));
          $('#loadModalAjax').modal({show:true});
        });
        
        $('input,textarea,select').filter('[required]').addClass('data-required');

        $('#submit-button').on('click', function(event) {
            $('.data-required').prop('required', true);
            $('input,textarea,select').filter('[required]:hidden').prop('required', false);
            return true;
        });
      });
  </script>
@endsection
