@extends ('app.patient.invoicing.layout')
@section('invoicing-content')
    <div class="d-flex align-items-baseline pb-3">
        <a href="{{route('patients.view.invoicing-invoices', ['patient' => $patient, 'customer' => $customer])}}" class="mr-2"><i class="fa fa-chevron-left mr-1"></i> Back</a>
        <h4 class="font-weight-bold m-0 font-size-16">{{$customer->company->name}} <i class="fa fa-chevron-right text-sm text-secondary mx-1"></i> Invoice Transactions</h4>
        <span class="text-secondary mx-2">|</span>
        <div moe class="">
            <a href="" start show class="font-weight-bold">
                + Add Manual Plus
            </a>
            <form url="/api/invoiceTransaction/createManualPlus" class="mcp-theme-1">
                <p class="mb-2 text-secondary font-weight-bold text-nowrap">Add Manual Plus</p>
                <input type="hidden" name="invoiceUid" value="{{$invoice->uid}}">
                <div class="mb-2">
                    <label class="text-sm text-secondary mb-1">Amount</label>
                    <input type="text"
                           name="amount"
                           autocomplete="off"
                           class="form-control form-control-sm"
                           required>
                </div>
                <div class="mb-2">
                    <label class="text-sm text-secondary mb-1">Memo</label>
                    <textarea rows="2"
                              name="customMemo"
                              autocomplete="off"
                              class="form-control form-control-sm"></textarea>
                </div>
                <div>
                    <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
                </div>
            </form>
        </div>
        <span class="text-secondary mx-2">|</span>
        <div moe class="">
            <a href="" start show class="font-weight-bold">
                + Add Manual Minus
            </a>
            <form url="/api/invoiceTransaction/createManualMinus" class="mcp-theme-1">
                <p class="mb-2 text-secondary font-weight-bold text-nowrap">Add Manual Minus</p>
                <input type="hidden" name="invoiceUid" value="{{$invoice->uid}}">
                <div class="mb-2">
                    <label class="text-sm text-secondary mb-1">Amount</label>
                    <input type="text"
                           name="amount"
                           autocomplete="off"
                           class="form-control form-control-sm"
                           required>
                </div>
                <div class="mb-2">
                    <label class="text-sm text-secondary mb-1">Memo</label>
                    <textarea rows="2"
                              name="customMemo"
                              autocomplete="off"
                              class="form-control form-control-sm"></textarea>
                </div>
                <div>
                    <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
                </div>
            </form>
        </div>
    </div>
    @if(!count($invoice->invoiceTransactions))
        <div class="border p-2 mb-3 font-weight-bold">This invoice does not have any transactions yet.</div>
    @else
        <table class="table table-sm table-bordered table-striped mb-3">
            <thead>
            <tr>
                <th class="border-bottom-0">Created</th>
                <th class="border-bottom-0">Plus / Minus</th>
                <th class="border-bottom-0">Amount</th>
                <th class="border-bottom-0">Memo</th>
                <th class="border-bottom-0">Starting<br>Balance</th>
                <th class="border-bottom-0">Resulting<br>Balance</th>
                <th class="border-bottom-0 w-50"></th>
            </tr>
            </thead>
            <tbody>
            @foreach($invoice->invoiceTransactions as $record)
                <tr>
                    <td>{{ friendly_date_time_with_seconds($record->created_at) }}</td>
                    <td>{{ sanitize_state_name($record->plus_or_minus) }}</td>
                    <td>${{ is_null($record->amount) ? 0 : $record->amount }}</td>
                    <td>{{ $record->custom_memo ?: '' }}</td>
                    <td>${{ is_null($record->starting_balance) ? 0 : $record->starting_balance }}</td>
                    <td>${{ is_null($record->resulting_balance) ? 0 : $record->resulting_balance }}</td>
                    <td></td>
                </tr>
            @endforeach
            </tbody>
        </table>
    @endif
    <div class="mb-2 border p-2 bg-aliceblue">
        <div class="d-flex align-items-baseline">
            <div class="mb-2 text-secondary font-weight-bold">Invoice Details</div>
            <!--<span class="mx-2 text-secondary">|</span>
            <a href="#" data-invoice-uid="{{$invoice->uid}}" data-uid="{{$invoice->customer->uid}}" class="generate-and-visit-ic-pay" native target="_blank">Visit Pay Link</a>-->
            <span class="mx-2 text-secondary">|</span>
            <a href="#" data-invoice-uid="{{$invoice->uid}}" data-uid="{{$invoice->customer->uid}}" class="generate-and-copy-ic-pay-url" native target="_blank">Copy Pay Link</a>
        </div>
        <table class="table table-sm table-bordered bg-white mb-0">
            <thead>
            <tr>
                <th class="border-bottom-0 text-secondary bg-light">Date</th>
                <th class="border-bottom-0 text-secondary bg-light">Company</th>
                <th class="border-bottom-0 text-secondary bg-light">Particulars</th>
                <th class="border-bottom-0 text-secondary bg-light">Total</th>
                <th class="border-bottom-0 text-secondary bg-light">Paid</th>
                <th class="border-bottom-0 text-secondary bg-light">Due</th>
                <th class="border-bottom-0 text-secondary bg-light w-50"></th>
            </tr>
            </thead>
            <tbody class="font-weight-normal">
            <tr>
                <td>{{friendly_date($invoice->created_at)}}</td>
                <td>{{$customer->company->name}}</td>
                <td>{{$invoice->description}}</td>
                <td class="font-weight-bold text-dark">${{!is_null($invoice->amount) ? $invoice->amount : 0}}</td>
                <td class="font-weight-bold text-success">${{!is_null($invoice->paid) ? $invoice->paid : 0}}</td>
                <td class="font-weight-bold text-warning-dark">${{!is_null($invoice->balance) ? $invoice->balance : 0}}</td>
                <td></td>
            </tr>
            <tr>
                <td class="p-2 text-right" colspan="7">
                    <div class="d-flex justify-content-start align-items-baseline mb-1">
                        <span class="text-secondary">Total Amount: </span>
                        <span class="width-50px text-left text-secondary font-weight-bold pl-2">${{!is_null($invoice->amount) ? $invoice->amount : 0}}</span>
                    </div>
                    <div class="d-flex justify-content-start align-items-baseline mb-1">
                        <span class="text-secondary">Total Paid: </span>
                        <span class="width-50px text-left text-secondary font-weight-bold pl-2">${{!is_null($invoice->paid) ? $invoice->paid : 0}}</span>
                    </div>
                    <div class="d-flex justify-content-start align-items-baseline">
                        <span class="font-weight-bold text-secondary">Total Due: </span>
                        <span class="width-50px text-left font-weight-bold pl-2 font-size-14">${{!is_null($invoice->balance) ? $invoice->balance : 0}}</span>
                    </div>
                    @if($invoice->balance <= 0)
                        <div class="text-left font-weight-bold mt-1">
                            <i class="fa fa-check text-success"></i>
                            <span class="text-success">PAID</span>
                        </div>
                    @endif
                </td>
            </tr>
            </tbody>
        </table>
    </div>
@endsection
