@extends('crm.layouts.app')

@section('styles')
  <link rel="stylesheet" href="{{asset('css/invoice_template.css')}}">
  <style>
    .invoice-top {
        background: url("{{asset('images/invoice_bg')}}");
        background: -moz-radial-gradient(center center, circle farthest-corner, #333333 10%, #000000);
        background: -webkit-radial-gradient(center center, circle farthest-corner, #333333 10%, #000000);
        background: radial-gradient(circle farthest-corner at center center, #333333 10%, #000000);
        color: #fff;
        padding: 40px 40px 30px 40px;
    }
    .logo{
      max-height: 150px;
    }
  </style>
@endsection

@section('content')
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="card ">
          <div class="card-header ">
            <span class="float-left pt-1">{{@$invoice->invoice_date}}</span></span>
            @if (@$invoice->invoice_paid == 'no')
              <span class="badge bg-danger float-right">Unpaid</span>
              @else 
              <a href="{{route('crm.invoice.download', $invoice->id)}}" class="btn btn-sm btn btn-outline-success float-right" target="_blank">Download</a>
            @endif
          </div>
          <div class="card-body">
            <div id="container">

              <div class="invoice-top">
                <section id="memo">
                  
                  <div class="logo">
                    @if ($logo == null)
                      <img src="{{asset('images/test-logo.png')}}" alt="{{ config('app.name') }}">
                    @else
                      <img src="{{asset('storage/adminfiles').'/'.@$logo->field_value}}" alt="{{ config('app.name') }}">
                    @endif
                    
                  </div>
                  
                  <div class="company-info">
                    <span class="company-name">{{ @$company_name->field_value }}</span>
        
                    <span class="spacer"></span>
        
                    <div>, {{ @$company_city->field_value }} [{{ @$company_zip->field_value }}], {{ @$company_state->field_value }}</div>
                    <div>{{ @$company_address->field_value }}</div>
                    
        
                    <span class="clearfix"></span>
        
                    <div>{{ @$company_phone->field_value }}</div>
                    <div>{{ @$company_email->field_value }}</div>
                  </div>
        
                </section>
                
                <section id="invoice-info">
                  
                  <div>
                    <span class="text-text-bold">{{$invoice->prefix}} {{ @$invoice->invoice_number }}</span>
                    <span>{{__('Issued at:')}}</span>
                    {{-- <span>{net_term_label}</span>
                    <span>{due_date_label}</span>
                    <span>{po_number_label}</span> --}}
                  </div>
                  
                  <div>
                    <span></span>
                    <span>{{$invoice->created_at}}</span>
                    {{-- <span>{net_term}</span>
                    <span>{due_date}</span>
                    <span>{po_number}</span> --}}
                  </div>
        
                  <span class="clearfix"></span>
        
                  <section id="invoice-title-number">
                
                    <span id="">{{ Str::limit($invoice->invoice_title, 80)   }}</span> <br>
                    
                    
                  </section>
                  
                  <section class="mt-1">
                      @if (@$invoice->invoice_paid == 'yes')
                      <span class="bg-default">
                        <i class="fas fa-check text-success"> {{__('Invoice Paid')}}</i>  
                      </span>
                      @if (@$invoice->payment_confirmed == 'no')
                        <i class="fas fa-question text-danger"> {{__('Confirmation pending')}}</i>
                        
                      @else
                      <i class="fas fa-check text-success"> {{__('Payment Confirmed')}}</i>    
                      @endif
                  
                      <br>
                      {{__('By')}} {{@$invoice->payment_mode->gateway_name}}
                      <br>
                      {{__('Time')}}: {{@$invoice->updated_at}}
                      <br>
                      {{__('Txn No.')}} {{@$invoice->txn_number}}
                  
                      @if (@$invoice->txn_receipt != null)
                        <br>
                        <a href="storage/invoice_receipts/{{@$invoice->txn_receipt}}">{{__('Receipt')}}</a>
                      @endif
                    @else 
                    <span class="float-right">
                      {{-- <h1><span class="badge bg-danger">Unpaid</span></h1> --}}
                      {{-- <a href="#" data-toggle="modal" data-target="#payment{{@$invoice->id}}" class="btn btn-sm btn-primary">Pay Now</a> --}}
                    </span>
                    @endif
                  </section>

                </section>
                
                <section id="client-info">
                  <span>{{__('Bill to')}}:</span>
                  <div>
                      @if ($invoice->customer->company_name != null)
                        <span class="text-text-bold">
                          {{@$invoice->customer->company_name}}
                        </span>
                        <span>{{@$invoice->customer->first_contact->first_name}} {{@$invoice->customer->first_contact->last_name}}</span>
                        <span>{{@$invoice->customer->first_contact->title->name}} </span>
                      @else   
                        <span  class="text-text-bold">{{@$invoice->customer->first_contact->first_name}} {{@$invoice->customer->first_contact->last_name}}</span>
                        <span>{{@$invoice->customer->first_contact->title->name}} </span>
                      @endif
                  </div>
                  
                  <div>
                    <span>{{ @$customer_address->address_line_1 }} {{ @$customer_address->address_line_2 }}</span>
                  </div>
                  
                  <div>
                    <span>{{ @$customer_address->city_name }} {{ @$customer_address->state_name }}</span>
                  </div>
                  
                  <div>
                    <span>{{ @$customer_address->phone }}</span>
                  </div>
                  
                  <div>
                    <span>{{ @$customer_address->email }}</span>
                  </div>

                </section>
        
                <div class="clearfix"></div>
              </div>
        
              <div class="clearfix"></div>
        
              <div class="">
                <section id="items">
                  {{-- Invoice Data starts --}}
                  {{-- invoice Products Table starts --}}
                  <table width='100%' class="borderGray font13 text-text-bold">
                    <tr class="width100 tr1">
                      <td width="35%" class="borderGray text-bold">{{__('Product/Item')}}</td>
                      <td width="18%" class="borderGray text-bold">{{__('Price')}}</td>
                      <td width="10%" class="borderGray text-bold">{{__('Qty')}}</td>
                      <td width="18%" class="borderGray text-bold">{{__('Tax')}}</td>
                      <td width="20%" class="borderGray text-bold">{{__('Amount')}}</td>
                    </tr>
                    
                  @foreach (json_decode($invoice->selected_products) as $product)
                  <tr class="width100">
                    <td width="36%" class="borderGray">{{$product->name}}</td>
                    <td width="18%" class="borderGray">{{@$invoice->currency->symbol}} {{$product->price}}</td>
                    <td width="12%" class="borderGray">{{$product->quantity}}</td>
                    <td width="18%" class="borderGray">{{$product->tax_amount}} %</td>
                    <td width="20%" class="borderGray">{{@$invoice->currency->symbol}} {{$product->total_p_amount}}</td>
                  </tr>
                  @endforeach
                  <tr class="tr">
                    <td width="35%" class="borderGray"></td>
                    <td width="18%" class="borderGray"></td>
                    <td width="10%" class="borderGray"></td>
                    <td width="18%" class="borderGray text-bold">{{__('Sub Total')}}</td>
                    <td width="20%" class="borderGray">{{@$invoice->currency->symbol}} {{@$invoice->sub_total}}</td>
                  </tr>
                  <tr class="width100">
                    <td width="35%" class="borderGray"></td>
                    <td width="18%" class="borderGray text-bold">{{__('Discount')}}</td>
                    <td width="10%" class="borderGray">{{@$invoice->discount_type}}</td>
                    <td width="18%" class="borderGray">{{@$invoice->discount_percentage}} %</td>
                    <td width="20%" class="borderGray">{{@$invoice->currency->symbol}} {{@$invoice->discount_total}}</td>
                  </tr>
                  <tr class="tr">
                    <td width="35%" class="borderGray"></td>
                    <td width="18%" class="borderGray"></td>
                    <td width="10%" class="borderGray"></td>
                    <td width="18%" class="borderGray text-bold">{{__('Adjustments')}}</td>
                    <td width="20%" class="borderGray">{{@$invoice->currency->symbol}} {{@$invoice->adjustments}}</td>
                  </tr>
                  <tr class="width100">
                    <td width="35%" class="borderGray"></td>
                    <td width="18%" class="borderGray"></td>
                    <td width="10%" class="borderGray"></td>
                    <td width="18%" class="borderGray text-bold">{{__('Total Amount')}}</td>
                    <td width="20%" class="borderGray font15">{{@$invoice->currency->symbol}} {{@$invoice->total_amount}}</td>
                  </tr>
                  </table>

 <div class="row mt-2">
   <div class="col-md-12">
              {{-- Payment section starts here --}}
              @if (@$invoice->invoice_paid == 'yes')
              <span class="bg-default">
                <i class="fas fa-check text-success"> {{__('Invoice Paid')}}</i>  
              </span>
              @if (@$invoice->payment_confirmed == 'no')
                <i class="fas fa-question text-danger"> {{__('Confirmation pending')}}</i>
                
              @else
              <i class="fas fa-check text-success"> {{__('Payment Confirmed')}}</i>    
              @endif
          
              <br>
              {{__('By')}} <span class="text-bold">{{@$invoice->payment_mode->gateway_name}}</span>
              <br>
              {{__('Time')}}: {{@$invoice->updated_at}}
              <br>
              {{__('Txn No.')}} {{@$invoice->txn_number}}
          
              @if (@$invoice->txn_receipt != null)
                <br>
                <a href="storage/invoice_receipts/{{@$invoice->txn_receipt}}">{{__('Receipt')}}</a>
              @endif
            @else 
            <span class="badge badge-danger float-left">Unpaid</span>
            {{-- <span class="float-right">
              <span class="text-text-bold">{{__('Pay through: ')}}</span>
              <br>
              <a href="#" data-toggle="modal" data-target="#payment{{@$invoice->id}}" class="btn btn-sm btn-primary mb-1">Cash/Cheque</a>
              <br>
              <form action="{{route('payment')}}" method="post">
                @csrf
                <input type="hidden" name="invoice_id" value="{{@$invoice->id}}">
                <input type="submit" class="btn btn-sm btn-primary mb-1" value="PayPal">
              </form>
            </span> --}}
            @endif
              {{-- Payment section ends here --}}     
   </div>
</div>                 
                  
                  {{-- invoice Products Table ends --}}
                  <p class="mt-2 mb-2 text-danger">{{__('Invoice Due Date')}}: {{@$invoice->due_date}}</p>
                  <div class="row">
                    <div class="col-md-12">
                      @if (@$invoice->termsandconditions != NULL || @$invoice->termsandconditions != '')
                      Terms and conditions: <br>
                      {{@$invoice->termsandconditions}} <br><br>
                      @endif
                      @if (@$invoice->customer_notes != NULL || @$invoice->customer_notes != '')
                      Note to customer: <br>
                      {{@$invoice->customer_notes}} <br> <br>
                      @endif
                    </div>
                  </div>
                  {{-- Invoice data ends --}}                    
                </section>
              </div>

            </div>
          </div>
        </div>
      </div>
    </section>
  </div>


  {{-- SECTION  modal Starts Here --}}
<div class="modal fade" id="payment{{@$invoice->id}}" tabindex="-1" role="dialog" aria-labelledby="payment{{@$invoice->id}}Label" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" >{{__('Payment Options')}}</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form action="{{url('client/invoice/pay')}}" method="POST"  enctype="multipart/form-data">
            @csrf
            <div class="form-group">
              <input type="hidden" name="invoice_number" value="{{@$invoice->id}}">
              <label for="">{{__('Select Payment Mode')}}</label>
              <select name="payment_mode_id" id="payment_mode"  class="form-control">
                <option disabled selected>{{__('Select Payment Mode')}}</option>
                @foreach ($payment_modes as $payment_mode)
                    <option value="{{@$payment_mode->id}}">{{@$payment_mode->name}}</option>
                @endforeach
              </select>
            </div>
            <div class="form-group d-hide" id="details_card">
              <textarea id="payment_details" class="form-control" disabled readonly></textarea>
            </div>
            <div class="form-group">
              <label for="">{{__('Transaction Number')}}</label>
              <input type="text" name="txn_number" class="form-control form-control-sm">
            </div>
            <div class="form-group">
              <label for="">{{__('Transaction Receipt')}}</label>
              <input type="file" name="txn_receipt" class="form-control form-control-sm">
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">{{__('Close')}}</button>
            <button type="submit" class="btn btn-info">{{__('Checkout')}}</button>
          </div>
        </form>
    </div>
  </div>
</div>
{{-- !SECTION  modal ends here --}}
@endsection

@section('scripts')
  @include('client.invoice.index_js')
@endsection



