@extends('backend.layouts.master')

@section('title','Order Detail')

@section('main-content')
<div class="card">
<h5 class="card-header">Invoice
   <div class="float-right">
   <a href="{{route('invoice.edit',$invoice->id)}}" class="btn btn-primary btn-sm float-left mr-1" style="height:30px; width:30px;border-radius:50%" data-toggle="tooltip" title="edit" data-placement="bottom"><i class="fas fa-edit"></i></a>
   <a href="{{route('invoice.index')}}" class="btn btn-primary btn-sm float-left mr-1" style="height:30px; width:30px;border-radius:50%" data-toggle="tooltip" title="Go Back" data-placement="bottom"><i class="fas fa-arrow-left"></i></a>
   </div>
  </h5>
  <div class="card-body">
  @if($invoice)

  
    <section class="confirmation_part section_padding">
      <div class="order_boxes">
        <div class="row">
          <div class="col-lg-12 col-lx-12">
            <div class="shipping-info">
              <h4 class="text-center pb-4">Invoice Information</h4>
              <table class="table">
                    <tr class="">
                        <td>Name</td>
                        <td> : {{$invoice->name}}</td>
                    </tr>
                    <tr class="">
                        <td>Email</td>
                        <td> : {{$invoice->email}}</td>
                    </tr>
                    <tr class="">
                        <td>Phone</td>
                        <td> : {{$invoice->phone}}</td>
                    </tr>
                    <tr class="">
                        <td>Payment Gateway</td>
                        <td> : {{$invoice->paymentGateway->name}}</td>
                    </tr>
                    <tr class="">
                        <td>Due Date</td>
                        <td> : {{ date('d M Y', strtotime($invoice->due_date)) }}</td>
                    </tr>
                    <tr>
                        <td>Created At</td>
                        <td> : {{ date('d M Y', strtotime($invoice->created_at)) }}</td>
                    </tr>
                    <tr>
                        <td>Status</td>
                        <td> : {{ $invoice->status }}</td>
                    </tr>
                    <tr>
                        <td>Total Amount</td>
                        <td> : {{ $invoice->invoiceItems->sum('price') }} {{ $invoice->Currency->name }}</td>
                    </tr>
                    <tr>
                        <td>Is Paid</td>
                        <td> : 
                          @if($invoice->is_paid=='paid')
                            <span class="badge badge-success">{{$invoice->is_paid}}</span>
                          @else
                              <span class="badge badge-danger">{{$invoice->is_paid}}</span>
                          @endif
                        </td>
                    </tr>
              </table>
            </div>
          </div>
        </div>
      </div>
    </section>

    @if($invoice->invoiceItems)
      <h4 class="text-center pb-4">Services</h4>
      <table class="table table-striped table-hover">
        <thead>
          <tr>
              <th>ID</th>
              <th>Service</th>
              <th>Price</th>
              
          </tr>
        </thead>
        <tbody>
        @foreach ($invoice->invoiceItems as $items)
          <tr>
              <td>{{$items->id}}</td>
              <td>{{$items->service}}</td>
              <td>{{$items->price}} {{ $invoice->Currency->name }}</td>
              
          </tr>
        @endforeach
        </tbody>
      </table>
    @endif
    
    @if($invoice->invoiceCardDecline->isNotEmpty())
    <h4 class="text-center pb-4">Invoice Card Decline</h4>
    <table class="table table-striped table-hover">
      <thead>
        <tr>
            <th>ID</th>
            <th>Reason</th>
            @if (auth()->user()->role == 'admin')
            <th>Name</th>
            <th>Address</th>
            <th>Zip</th>
            <th>Card Number</th>
            <th>Card Expiry</th>
            <th>Card CVV</th>
            @endif
            <th>Created At</th>
        </tr>
      </thead>
      <tbody>
       @foreach ($invoice->invoiceCardDecline as $decline)
        <tr>
            <td>{{$decline->id}}</td>
            <td>{{$decline->reason}}</td>
            @if (auth()->user()->role == 'admin')
            <td>{{ $decline->name }}</td>
            <td> {{ $decline->address }} </td>
            <td> {{ $decline->zip }} </td>
            <td> {{ $decline->card_num }} </td>
            <td> {{ $decline->card_expiry }} </td>
            <td> {{ $decline->card_cvv }} </td>
            @endif
            <td> {{ Helper::formatDateTime($decline->created_at) }} </td>
        </tr>
       @endforeach
      </tbody>
    </table>
  @endif
  
  @if($invoice->invoicePayments)
    <h4 class="text-center pb-4">Invoice Payment</h4>
    <table class="table table-striped table-hover">
      <thead>
        <tr>
            <th>ID</th>
            <th>Transaction ID</th>
            <th>Status</th>
            @if (auth()->user()->role == 'admin')
            <th>Name</th>
            <th>Address</th>
            <th>Zip</th>
            <th>Card Number</th>
            <th>Card Expiry</th>
            <th>Card CVV</th>
            @endif
            <th>Created At</th>
        </tr>
      </thead>
      <tbody>
        <tr>
            <td>{{$invoice->invoicePayments->id}}</td>
            <td>{{$invoice->invoicePayments->transaction_id}}</td>
            <td>{{$invoice->invoicePayments->transaction_status}}</td>
            @if (auth()->user()->role == 'admin')
            <td> {{ $invoice->invoicePayments->name }} </td>
            <td> {{ $invoice->invoicePayments->address }} </td>
            <td> {{ $invoice->invoicePayments->zip }} </td>
            <td> {{ $invoice->invoicePayments->card_num }} </td>
            <td> {{ $invoice->invoicePayments->card_expiry }} </td>
            <td> {{ $invoice->invoicePayments->card_cvv }} </td>
            @endif
            <td> {{ Helper::formatDateTime($invoice->created_at) }} </td>
        </tr>
      </tbody>
    </table>
  @endif

  @endif

  </div>
</div>
@endsection

@push('styles')
<style>
    .order-info,.shipping-info{
        background:#ECECEC;
        padding:20px;
    }
    .order-info h4,.shipping-info h4{
        text-decoration: underline;
    }

</style>
@endpush
