@extends('layouts.admin') @section('content')

<div class="card mb-3">
    <div class="card-header">
        <div class="row flex-between-end">
            <div class="col-auto align-self-center">
                <a href="{{ url()->previous() }}" class="btn btn-primary btn-sm"><i class="fas fa-arrow-circle-left"></i> Back</a>
                <a href='{{ url("/allmembers")}}' class="btn btn-primary btn-sm"><i class="fas fa-users"></i> All members</a>
                <a href='{{ url("/new_payment", $member->id)}}' class="btn btn-primary btn-sm"><i class="fas fa-user"></i> Add new payment</a>
                <a href='{{ url("/statement", $member->id)}}' class="btn btn-primary btn-sm"><i class="fas fa-user"></i>Print Statement</a>

                <a href='{{ url("/member_profile", $member->id)}}' class="btn btn-primary btn-sm"><i class="fas fa-user"></i> {{$member->name}} {{$member->surname}}'s Profile</a>

                <br>
                <br>

                <br>
                <h5 class="mb-0" data-anchor="data-anchor">List of payments</h5>
            </div>
        </div>
    </div>
    <div class="card-body pt-0">

        <div class="dt-responsive table-responsive">
            <small>
                <table class="table table-sm table-striped table-bordered nowrap">
                    <thead class="bg-200 text-900">
                        <tr>
                            <th>ID</th>                          
                            <th>Date</th>                     
                            <th>Amount</th>
                            <th>Payment Method</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody class="list">
                        @foreach ($payments as $payment)
                        <tr>
                            <td>{{$payment->id}}</td>                       
                            <td>
    @if ($payment->created_at)
        {{ $payment->payment_date }} - {{ $payment->created_at->diffForHumans() }}
    @else
        {{ $payment->payment_date }}
    @endif
</td>
             
                            <td>{{$payment->amount_paid}}</td>
                            <td>{{$payment->mode->name}}</td>
                            <td>
                                <a href='{{ url("/receipt", $payment->id)}}' class="btn btn-primary btn-sm"> Print</a>&nbsp;
                                <a href='{{ url("/payment_edit", $payment->id)}}' onclick="return confirm('Are you sure you want to delete this payment?')" class="btn btn-sm btn-danger btn-outline-primary">Delete Request</a>
                                @if (Auth::user()->role == 3) &nbsp;                     
                                <a href='{{ url("/delete_payment")}}/{{$payment->id }}/{{ $payment->member_id}}' class="btn btn-danger btn-sm" 
                                onclick="return confirm('Are you sure you want to delete this payment?')"> Delete </a>
                                @endif
                            </td>
                        </tr>
                        @endforeach
                    </tbody>
                </table>
            </small>

        </div>


    </div>

</div>
@endsection