@extends('layouts.pay_app')
@section('content')
    <div class="account">
        @if(count($invoices))
        <h4>{{$contact_name}} here are your invoices currently showing as unpaid.<br><br> Select the invoices you want to pay.<br><span style="font-weight:400;font-size:12px;">Click the invoice number to download a copy.</span></h4>

        <form action="{{route('pay.choose_pay')}}" id="invoices_list" method="post">
            @csrf
            <input type="hidden" name="invoice_currency" value="">
            <table class="invoices-table">

                <thead>

                <tr>

                    <th>Invoice</th>

                    <th>Date</th>

                    <th>Due</th>

                    <th><i class="fa fa-check" aria-hidden="true"></i></th>

                </tr>

                </thead>

                <tbody>

                @php

                $step = 1;
                @endphp

                @foreach ($invoices as $invoice)
                @if( $invoice['Type'] != 'ACCPAY')
                <tr>

                    <td><a style="text-decoration:underline" href="/download_invoice?invoice_id={{$invoice['InvoiceID']}}" target="_blank" data-download-invoice="" class="download-invoice">{{$invoice['InvoiceNumber']}}</a></td>

                    <td style="font-size:10px;">{{ $invoice['Date']->format('Y-m-d H:i:s') }}</td>

                    @php $amount_due = $invoice['AmountDue'];

                    $amount_due = (string)$amount_due;

                   @endphp

                    <td style="font-size:10px; text-align:right">{{\App\Services\PayService::showCurrency($invoice['CurrencyCode'])}} {{number_format($amount_due, 2, '.', ',') }} </td>

                    <td>

                        <input @if( !request()->get('invoice_number') || ( request()->get('invoice_number')  == $invoice['InvoiceNumber'] ) ) @endif  id="check{{$step}}"  type="checkbox" name="invoices[ {{$invoice['InvoiceNumber']}}]" value="{{$invoice['InvoiceID']}}" data-currency="{{$invoice['CurrencyCode']}}">

                        <label for="check{{$step}}"></label>

                    </td>

                    <input type="hidden" name="pay_amount[{{$invoice['InvoiceID']}}]" value="{{$invoice['AmountDue']}}">

                </tr>
                @endif
                @endforeach

                </tbody>

            </table>

            <div class="buttons">

                <a class="choise-button" href="{{route('pay.account')}}">Back</a>

                <a href="#" class="choise-button button-invoices disable">Continue</a>

            </div>

        </form>

        @else
        <h4>{{$contact_name}} has no invoices to pay</h4>

        <div class="buttons">

            <a class="choise-button" href="{{route('pay.account')}}">Back</a>

        </div>
        @endif
    </div>
@endsection
