@extends ('app.patient.invoicing.layout')
@section('invoicing-content')
    <div class="d-flex align-items-baseline pb-3">
        <a href="{{route('patients.view.invoicing-companies', ['patient' => $patient])}}" 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> Customer 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/customerTransaction/createManualPlus" class="mcp-theme-1">
                <input type="hidden" name="customerUid" value="{{@$customer->uid}}">
                <p class="mb-2 text-secondary font-weight-bold text-nowrap">Add Manual Plus</p>
                <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/customerTransaction/createManualMinus" class="mcp-theme-1">
                <input type="hidden" name="customerUid" value="{{@$customer->uid}}">
                <p class="mb-2 text-secondary font-weight-bold text-nowrap">Add Manual Minus</p>
                <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($customer->customerTransactions))
        <div class="border p-2">This customer does not have any customer transactions yet.</div>
    @else
        <table class="table table-sm table-bordered table-striped">
            <thead>
            <tr>
                <th class="border-bottom-0">Created <span class="font-weight-normal text-secondary text-sm">(newest first)</span></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">Type</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($customer->customerTransactions 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>{{ sanitize_state_name($record->reason_type)}}</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
@endsection
