@extends('layouts.app')
@section('page-title')
    {{ __('Payments') }}
@endsection
@php
    $admin_logo = getSettingsValByName('company_logo');
    $settings = settings();
@endphp
@push('script-page')
    <script>
        $(document).on('click', '.print', function() {
            var printContents = document.getElementById('invoice-print').innerHTML;
            var originalContents = document.body.innerHTML;

            document.body.innerHTML = printContents;

            window.print();

            document.body.innerHTML = originalContents;

        });
    </script>
@endpush
@section('breadcrumb')
    <ul class="breadcrumb mb-0">
        <li class="breadcrumb-item">
            <a href="{{ route('dashboard') }}">
                {{ __('Dashboard') }}
            </a>
        </li>
        <li class="breadcrumb-item">
            <a href="{{ route('membership-payment.index') }}">{{ __('Payments') }}</a>
        </li>
        <li class="breadcrumb-item active">
            <a href="#">{{ __('Details') }}</a>
        </li>
    </ul>
@endsection

<style>
    @media print {
        .no-print {
            display: none !important;
        }
    }
</style>
@section('content')
    <div class="row" id="invoice-print">
        <div class="row">
            <div class="col-sm-12">
                <div class="d-print-none card mb-3">
                    <div class="card-body p-3">
                        <ul class="list-inline ms-auto mb-0 d-flex justify-content-end flex-wrap">

                            <li class="list-inline-item align-bottom me-2">
                                @if ($payment->status != 'Paid')
                                    <a href="#" class="btn btn-secondary btn-sm ml-20 customModal" data-size="md"
                                        data-url="{{ route('membership-payment.edit', $payment->id) }}"
                                        data-title="{{ __('Add Payment') }}">
                                        <i class="ph-duotone ph-credit-card"></i> {{ __('Add Payment') }}
                                    </a>
                                @endif
                            </li>
                            <li class="list-inline-item align-bottom me-2">
                                <a href="#" class="btn btn-secondary btn-sm print">
                                    <i class="ph-duotone ph-printer"></i> {{ __('Download') }}
                                </a>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="card">

                    <div class="card-body">
                        <div class="row g-3">
                            <div class="col-12">
                                <div class="row align-items-center g-3">
                                    <div class="col-sm-6">
                                        <div class="d-flex align-items-center mb-2 navbar-brand img-fluid invoice-logo">
                                            <img src="{{ asset(Storage::url('upload/logo/')) . '/' . (isset($admin_logo) && !empty($admin_logo) ? $admin_logo : 'logo.png') }}"
                                                class="img-fluid brand-logo" alt="images" />
                                        </div>
                                        <p class="mb-0">{{ paymentPrefix() . $payment->payment_id }}</p>
                                    </div>
                                    <div class="col-sm-6 text-sm-end">
                                        <h6>
                                            {{ __('Start Date') }}
                                            <span class="text-muted f-w-400">
                                                {{ !empty($membership) ? dateFormat($membership->start_date) : '-' }}</span>
                                        </h6>
                                        <h6>
                                            {{ __('End Date') }}
                                            <span
                                                class="text-muted f-w-400">{{ !empty($membership) ? dateFormat($membership->expiry_date) : '-' }}</span>
                                        </h6>
                                        <h6>
                                            {{ __('Status') }}
                                            @if ($payment->status == 'Paid')
                                                <span class="badge text-bg-success">{{ $payment->status }}</span>
                                            @else
                                                <span class="badge text-bg-danger">{{ $payment->status }}</span>
                                            @endif
                                        </h6>
                                    </div>
                                </div>
                            </div>
                            <div class="col-sm-6">
                                <div class="border rounded p-3">
                                    <h6 class="mb-0">From:</h6>
                                    <h5>{{ $settings['company_name'] }}</h5>
                                    <p class="mb-0">{{ $settings['company_phone'] }}</p>
                                    <p class="mb-0">{{ $settings['company_email'] }}</p>
                                </div>
                            </div>
                            <div class="col-sm-6">
                                <div class="border rounded p-3">
                                    <h6 class="mb-0">To:</h6>
                                    <h5> <span
                                            class="text-sm text-muted">{{ memberPrefix() . $payment->members->member_id }}</span>
                                        <br>
                                        {{ !empty($payment->members) ? $payment->members->first_name . ' ' . $payment->members->last_name : '-' }}
                                    </h5>
                                    <p class="mb-0">
                                        {{ !empty($payment->members) ? $payment->members->phone : '-' }}
                                    </p>
                                    <p class="mb-0">
                                        {{ !empty($payment->members) ? $payment->members->address : '' }}
                                    </p>
                                </div>
                            </div>
                            <div class="col-12">
                                <div class="table-responsive">
                                    <table class="table table-hover mb-0">
                                        <thead>
                                            <tr>
                                                {{-- <th>{{ __('ID') }}</th> --}}
                                                <th>{{ __('Plan Name') }}</th>
                                                <th>{{ __('Duration') }}</th>
                                                <th>{{ __('Billing Frequency') }}</th>
                                                <th>{{ __('Period') }}</th>
                                                <th>{{ __('Amount') }}</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr>
                                                {{-- <td>{{ $payment->plan_id }}</td> --}}
                                                <td>{{ $payment->plans->plan_name }}</td>
                                                <td>{{ $payment->plans->duration }}</td>
                                                <td>{{ $payment->plans->billing_frequency }}</td>
                                                <td> {{ dateFormat($membership->start_date) ?? '-' }} -  {{ dateFormat($membership->expiry_date) ?? '-' }}</td>
                                                <td>{{ priceFormat($payment->plans->price) }}</td>
                                            </tr>
                                    </table>
                                </div>
                                <div class="text-start">
                                    <hr class="mb-2 mt-1 border-secondary border-opacity-50" />
                                </div>
                            </div>
                        </div>


                    </div>
                </div>

            </div>
        </div>
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h5>{{ __('Payment History') }}</h5>
                    </div>
                    <div class="card-body pt-0">
                        <div class="dt-responsive table-responsive">
                            <table class="table table-hover ">
                                <thead>
                                    <tr>
                                        <th>{{ __('Payment Date') }}</th>
                                        <th>{{ __('Amount') }}</th>
                                        <th>{{ __('Type') }}</th>
                                        <th>{{ __('Notes') }}</th>
                                        @can('delete membership payment')
                                            <th class="text-right no-print">{{ __('Action') }}</th>
                                        @endcan
                                    </tr>
                                </thead>
                                <tbody>
                                    @if ($payment->status == 'Paid')
                                        <tr role="row">
                                            <td>{{ dateFormat($payment->payment_date) }} </td>
                                            <td>{{ priceFormat($payment->amount) }} </td>
                                            <td>{{ __($payment->payment_method) }} </td>
                                            <td>{{ !empty($payment->notes) ? $payment->notes : '-' }} </td>

                                            @can('delete membership payment')
                                                <td class="text-right no-print">
                                                    <div class="cart-action">
                                                        {!! Form::open([
                                                            'route' => ['membership-payment.destroy', $payment->id],
                                                            'method' => 'DELETE',
                                                        ]) !!}
                                                        <a class=" avtar avtar-xs btn-link-danger text-danger confirm_dialog"
                                                            data-bs-toggle="tooltip"
                                                            data-bs-original-title="{{ __('Detete') }}" href="#">
                                                            <i data-feather="trash-2"></i>
                                                        </a>
                                                        {!! Form::close() !!}
                                                    </div>
                                                </td>
                                            @endcan
                                        </tr>
                                    @endif
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

