@extends('layouts.app')

@section('title', \App\Helpers\TranslationHelper::transFromDatabase('Customer Payments', __('Customer Payments')))

@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">{{ \App\Helpers\TranslationHelper::transFromDatabase('Customer Payments', __('Customer Payments')) }}</h3>
                    <div class="card-tools">
                        @can('customer-payments.create')
                        <a href="{{ route('customer-payments.create') }}" class="btn btn-sm btn-primary">
                            <i class="fas fa-plus"></i> {{ \App\Helpers\TranslationHelper::transFromDatabase('Add New Payment', __('Add New Payment')) }}
                        </a>
                        @endcan
                    </div>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-bordered table-striped">
                            <thead>
                                <tr>
                                    <th>#</th>
                                    <th>{{ \App\Helpers\TranslationHelper::transFromDatabase('Payment Number', __('Payment Number')) }}</th>
                                    <th>{{ __('Customer') }}</th>
                                    <th>{{ __('Invoice') }}</th>
                                    <th>{{ \App\Helpers\TranslationHelper::transFromDatabase('Payment Date', __('Payment Date')) }}</th>
                                    <th>{{ \App\Helpers\TranslationHelper::transFromDatabase('Payment Amount', __('Payment Amount')) }}</th>
                                    <th>{{ \App\Helpers\TranslationHelper::transFromDatabase('Payment Method', __('Payment Method')) }}</th>
                                    <th>{{ \App\Helpers\TranslationHelper::transFromDatabase('Treasury/Bank', __('Treasury/Bank')) }}</th>
                                    <th>{{ \App\Helpers\TranslationHelper::transFromDatabase('Reference Number', __('Reference Number')) }}</th>
                                    <th>{{ \App\Helpers\TranslationHelper::transFromDatabase('Actions', __('Actions')) }}</th>
                                </tr>
                            </thead>
                            <tbody>
                                @forelse($payments as $payment)
                                <tr>
                                    <td>{{ $loop->iteration }}</td>
                                    <td>{{ $payment->payment_number }}</td>
                                    <td>{{ $payment->customer->name }}</td>
                                    <td>
                                        @if($payment->invoice)
                                            <a href="{{ route('customer-invoices.show', $payment->invoice) }}">
                                                {{ $payment->invoice->invoice_number }}
                                            </a>
                                        @else
                                            <span class="text-muted">{{ __('No record') }}</span>
                                        @endif
                                    </td>
                                    <td>{{ $payment->payment_date->format('Y-m-d') }}</td>
                                    <td>{{ number_format($payment->amount, 2) }}</td>
                                    <td>
                                        @if($payment->payment_method == 'cash')
                                            <span class="badge badge-success">{{ \App\Helpers\TranslationHelper::transFromDatabase('Cash', __('Cash')) }}</span>
                                        @elseif($payment->payment_method == 'bank_transfer')
                                            <span class="badge badge-info">{{ \App\Helpers\TranslationHelper::transFromDatabase('Bank Transfer', __('Bank Transfer')) }}</span>
                                        @elseif($payment->payment_method == 'check')
                                            <span class="badge badge-primary">{{ \App\Helpers\TranslationHelper::transFromDatabase('Check', __('Check')) }}</span>
                                        @elseif($payment->payment_method == 'credit_card')
                                            <span class="badge badge-warning">{{ \App\Helpers\TranslationHelper::transFromDatabase('Credit Card', __('Credit Card')) }}</span>
                                        @else
                                            <span class="badge badge-secondary">{{ __('Other') }}</span>
                                        @endif
                                    </td>
                                    <td>
                                        @if($payment->treasury)
                                            <span class="text-success"><i class="fas fa-vault"></i> {{ $payment->treasury->name }}</span>
                                        @elseif($payment->bankAccount)
                                            <span class="text-info"><i class="fas fa-university"></i> {{ $payment->bankAccount->bank->name ?? '' }} ({{ $payment->bankAccount->account_number }})</span>
                                        @else
                                            <span class="text-muted">-</span>
                                        @endif
                                    </td>
                                    <td>{{ $payment->reference_number ?: __('No record') }}</td>
                                    <td>
                                        <div class="btn-group">
                                            @can('customer-payments.view')
                                            <a href="{{ route('customer-payments.show', $payment) }}" class="btn btn-sm btn-info" title="{{ \App\Helpers\TranslationHelper::transFromDatabase('View', __('View')) }}">
                                                <i class="fas fa-eye"></i>
                                            </a>
                                            @endcan
                                            
                                            @can('customer-payments.edit')
                                            <a href="{{ route('customer-payments.edit', $payment) }}" class="btn btn-sm btn-primary" title="{{ \App\Helpers\TranslationHelper::transFromDatabase('Edit', __('Edit')) }}">
                                                <i class="fas fa-edit"></i>
                                            </a>
                                            @endcan
                                            
                                            @can('customer-payments.delete')
                                            <form action="{{ route('customer-payments.destroy', $payment) }}" method="POST" class="d-inline">
                                                @csrf
                                                @method('DELETE')
                                                <button type="submit" class="btn btn-sm btn-danger" onclick="return confirm('{{ \App\Helpers\TranslationHelper::transFromDatabase('Are you sure?', __('Are you sure?')) }}')">
                                                    <i class="fas fa-trash"></i>
                                                </button>
                                            </form>
                                            @endcan
                                        </div>
                                    </td>
                                </tr>
                                @empty
                                <tr>
                                    <td colspan="9" class="text-center">{{ __('No payments found') }}</td>
                                </tr>
                                @endforelse
                            </tbody>
                        </table>
                    </div>
                    
                    <div class="mt-4">
                        {{ $payments->links() }}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
