Просмотр исходного кода

Client single > invoicing (wip)

Vijayakrishnan 3 лет назад
Родитель
Сommit
f8195b76cb

+ 11 - 4
app/Http/Controllers/PatientController.php

@@ -11,11 +11,13 @@ use App\Models\ClientInfoLine;
 use App\Models\ClientPrimaryCoverage;
 use App\Models\ClientProAccess;
 use App\Models\CompanyPro;
+use App\Models\Customer;
 use App\Models\Erx;
 use App\Models\Facility;
 use App\Models\Handout;
 use App\Models\HandoutClient;
 use App\Models\IncomingReport;
+use App\Models\Invoice;
 use App\Models\MBClaim;
 use App\Models\MBPayer;
 use App\Models\Note;
@@ -43,12 +45,17 @@ class PatientController extends Controller
         return view('app.patient.invoicing.companies', compact('patient'));
     }
 
-    public function invoicingInvoices(Request $request, Client $patient) {
-        return view('app.patient.invoicing.invoices', compact('patient'));
+    public function invoicingInvoices(Request $request, Client $patient, Customer $customer) {
+        return view('app.patient.invoicing.invoices', compact('patient', 'customer'));
     }
 
-    public function invoicingTransactions(Request $request, Client $patient) {
-        return view('app.patient.invoicing.transactions', compact('patient'));
+    public function invoicingCustomerTransactions(Request $request, Client $patient, Customer $customer) {
+        return view('app.patient.invoicing.customer-transactions', compact('patient', 'customer'));
+    }
+
+    public function invoicingInvoiceTransactions(Request $request, Client $patient, Invoice $invoice) {
+        $customer = $invoice->customer;
+        return view('app.patient.invoicing.invoice-transactions', compact('patient', 'invoice', 'customer'));
     }
 
     public function claimsResolver(Request $request, Client $patient)

+ 5 - 0
app/Models/Client.php

@@ -1045,4 +1045,9 @@ ORDER BY m.ts DESC
         return $this->hasOne(ClientRepFollowUp::class, 'id', 'client_rep_follow_up_id');
     }
 
+    public function customers() {
+        return $this->hasMany(Customer::class, 'client_id', 'id')
+            ->orderBy('created_at', 'desc');
+    }
+
 }

+ 4 - 0
app/Models/Invoice.php

@@ -17,4 +17,8 @@ class Invoice extends Model
     public function customer() {
         return $this->hasOne(Customer::class, 'id', 'customer_id');
     }
+
+    public function invoiceTransactions() {
+        return $this->hasMany(InvoiceTransaction::class, 'invoice_id', 'id')->orderBy('created_at', 'ASC');
+    }
 }

+ 0 - 0
resources/views/app/patient/invoicing/_common.blade.php


+ 100 - 3
resources/views/app/patient/invoicing/companies.blade.php

@@ -1,4 +1,101 @@
-@extends ('layouts.patient')
-@section('inner-content')
-    <h4 class="font-weight-bold m-0 font-size-16">Companies</h4>
+@extends ('app.patient.invoicing.layout')
+@section('invoicing-content')
+    <div class="d-flex align-items-baseline pb-3">
+        <h4 class="font-weight-bold m-0 font-size-16">Companies</h4>
+        <span class="text-secondary mx-2">|</span>
+        <div moe>
+            <a href="" start show class="font-weight-bold">
+                + Add
+            </a>
+            <form url="/api/customer/create" class="mcp-theme-1">
+                <p class="mb-2 text-secondary font-weight-bold">Add As Customer</p>
+                <input type="hidden" name="clientUid" value="{{$patient->uid}}">
+                <div class="mb-2">
+                    <label class="text-sm text-secondary mb-1">Company</label>
+                    <input type="hidden" name="companyUid" value="{{@$company->uid}}">
+                    <input type="text"
+                           name="companyName"
+                           target-key="uid"
+                           target-field="companyUid"
+                           autocomplete="off"
+                           class="form-control form-control-sm"
+                           stag-suggest
+                           stag-suggest-ep="/company-suggest"
+                           value="{{@$company ? @$company->name : ''}}"
+                           {{@$company ? 'disabled readonly' : ''}}
+                           required>
+                </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($patient->customers))
+        <div class="border p-2">This patient is not registered as a customer in any company yet.</div>
+    @else
+        <table class="table table-sm table-bordered table-striped">
+            <thead>
+            <tr>
+                <th class="border-bottom-0"></th>
+                <th class="border-bottom-0">Company</th>
+                <th class="border-bottom-0">Customer<br>Balance</th>
+                <th class="border-bottom-0">Pending Invoices<br>Balance</th>
+                <th class="border-bottom-0">Portal</th>
+                <th class="border-bottom-0">Created</th>
+                <th class="border-bottom-0">Active?</th>
+                <th class="border-bottom-0"></th>
+            </tr>
+            </thead>
+            <tbody>
+            <?php $i = 1; ?>
+            @foreach($patient->customers as $record)
+                <tr>
+                    <td>{{ $i++ }}</td>
+                    <td>{{ $record->company ? $record->company->name : '-' }}</td>
+                    <td>${{ is_null($record->customer_balance) ? 0 : $record->customer_balance }}</td>
+                    <td>${{ is_null($record->pending_invoices_balance_total) ? 0 : $record->pending_invoices_balance_total }}</td>
+                    <td>
+                        <a href="#" data-uid="{{$record->uid}}" class="generate-and-visit-ic-portal" native target="_blank">Visit</a>
+                        <a href="#" data-uid="{{$record->uid}}" class="generate-and-copy-ic-portal-url ml-1" native target="_blank">Copy</a>
+                    </td>
+                    <td>{{ friendly_date($record->created_at) }}</td>
+                    <td class="{{ !$record->is_active ? 'text-warning-dark' : ''}}">{{ $record->is_active ? 'Yes' : 'No' }}</td>
+                    <td>
+                        <div class="d-flex flex-wrap">
+                            @if($record->is_active)
+                                <div moe class="mr-2">
+                                    <a href="" start show>Deactivate</a>
+                                    <form url="/api/customer/deactivate" class="mcp-theme-1" right>
+                                        <p class="mb-2 text-nowrap">Deactivate this customer?</p>
+                                        <input type="hidden" name="uid" value="{{$record->uid}}">
+                                        <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>
+                            @else
+                                <div moe class="mr-2">
+                                    <a href="" start show>Reactivate</a>
+                                    <form url="/api/customer/reactivate" class="mcp-theme-1" right>
+                                        <p class="mb-2 text-nowrap">Reactivate this customer?</p>
+                                        <input type="hidden" name="uid" value="{{$record->uid}}">
+                                        <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>
+                            @endif
+                            <a href="{{route('patients.view.invoicing-customer-transactions', ['patient' => $patient, 'customer' => $record])}}" class="mr-2">Transactions</a>
+                            <a href="{{route('patients.view.invoicing-invoices', ['patient' => $patient, 'customer' => $record])}}">Invoices</a>
+                        </div>
+                    </td>
+                </tr>
+            @endforeach
+            </tbody>
+        </table>
+    @endif
 @endsection

+ 97 - 0
resources/views/app/patient/invoicing/customer-transactions.blade.php

@@ -0,0 +1,97 @@
+@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

+ 150 - 0
resources/views/app/patient/invoicing/invoice-transactions.blade.php

@@ -0,0 +1,150 @@
+@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

+ 140 - 3
resources/views/app/patient/invoicing/invoices.blade.php

@@ -1,4 +1,141 @@
-@extends ('layouts.patient')
-@section('inner-content')
-    <h4 class="font-weight-bold m-0 font-size-16">Invoices</h4>
+@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> Invoices</h4>
+        <span class="text-secondary mx-2">|</span>
+        <div moe>
+            <a href="" start show class="font-weight-bold">
+                + Add
+            </a>
+            <form url="/api/invoice/create" class="mcp-theme-1">
+                <input type="hidden" name="customerUid" value="{{$customer->uid}}">
+                <p class="mb-2 text-secondary font-weight-bold">Add Invoice</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">Description</label>
+                    <textarea rows="2"
+                              name="description"
+                              autocomplete="off"
+                              class="form-control form-control-sm" required></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->invoices))
+        <div class="border p-2">This patient does not have any invoices from {{$customer->company->name}} yet.</div>
+    @else
+        <table class="table table-sm table-bordered table-striped">
+            <thead>
+            <tr>
+                <th class="border-bottom-0"></th>
+                <th class="border-bottom-0">Created</th>
+                <th class="border-bottom-0">Amount</th>
+                <th class="border-bottom-0">Description</th>
+                <th class="border-bottom-0">Pay Link</th>
+                <th class="border-bottom-0">Paid</th>
+                <th class="border-bottom-0">Balance</th>
+                <th class="border-bottom-0">Active?</th>
+                <th class="border-bottom-0"></th>
+            </tr>
+            </thead>
+            <tbody>
+            <?php $i = 1; ?>
+            @foreach($customer->invoices as $record)
+                <tr>
+                    <td>{{ $i++ }}</td>
+                    <td>{{ friendly_date($record->created_at) }}</td>
+                    <td>${{ is_null($record->amount) ? 0 : $record->amount }}
+                        <div moe relative class="ml-1">
+                            <a href="#" start show><i class="fa fa-edit on-hover-opaque"></i></a>
+                            <form url="/api/invoice/changeAmount">
+                                <input type="hidden" name="invoiceUid" value="{{$record->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"
+                                           value="{{$record->amount}}"
+                                           required>
+                                </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>
+                    </td>
+                    <td>{{ $record->description ?: '' }}
+                        <div moe relative class="ml-1">
+                            <a href="#" start show><i class="fa fa-edit on-hover-opaque"></i></a>
+                            <form url="/api/invoice/changeDescription">
+                                <input type="hidden" name="invoiceUid" value="{{$record->uid}}">
+                                <div class="mb-2">
+                                    <label class="text-sm text-secondary mb-1">Description</label>
+                                    <textarea rows="2"
+                                              name="description"
+                                              autocomplete="off"
+                                              class="form-control form-control-sm" required>{{$record->description}}</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>
+                    </td>
+                    <td>
+                        <a href="#" data-invoice-uid="{{$record->uid}}" data-uid="{{$record->customer->uid}}" class="generate-and-visit-ic-pay" native target="_blank">Visit</a>
+                        <a href="#" data-invoice-uid="{{$record->uid}}" data-uid="{{$record->customer->uid}}" class="generate-and-copy-ic-pay-url ml-1" native target="_blank">Copy</a>
+                    </td>
+                    <td>${{ is_null($record->paid) ? 0 : $record->paid }}</td>
+                    <td>${{ is_null($record->balance) ? 0 : $record->balance }}</td>
+                    <td class="{{ !$record->is_active ? 'text-warning-dark' : ''}}">{{ $record->is_active ? 'Yes' : 'No' }}</td>
+                    <td>
+                        <div class="d-flex flex-wrap">
+                            @if($record->is_active)
+                                <div moe class="mr-2">
+                                    <a href="" start show>Deactivate</a>
+                                    <form url="/api/invoice/deactivate" class="mcp-theme-1" right>
+                                        <p class="mb-2 text-nowrap">Deactivate this invoice?</p>
+                                        <input type="hidden" name="uid" value="{{$record->uid}}">
+                                        <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>
+                            @else
+                                <div moe class="mr-2">
+                                    <a href="" start show>Reactivate</a>
+                                    <form url="/api/invoice/reactivate" class="mcp-theme-1" right>
+                                        <p class="mb-2 text-nowrap">Reactivate this invoice?</p>
+                                        <input type="hidden" name="uid" value="{{$record->uid}}">
+                                        <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>
+                            @endif
+                            <a href="{{route('patients.view.invoicing-invoice-transactions', ['patient' => $patient, 'invoice' => $record])}}" class="mr-2">Transactions</a>
+                        </div>
+                    </td>
+                </tr>
+            @endforeach
+            </tbody>
+        </table>
+    @endif
 @endsection

+ 84 - 0
resources/views/app/patient/invoicing/layout.blade.php

@@ -0,0 +1,84 @@
+@extends ('layouts.patient')
+@section('inner-content')
+<div id="invoicing-{{$patient->uid}}">
+    @yield('invoicing-content')
+</div>
+<script>
+    (function () {
+        function init() {
+            initStagSuggest();
+            let parentSegment = $('body');
+            parentSegment.find('input[stag-suggest][target-key][target-field]')
+                .off('stag-suggest-selected')
+                .on('stag-suggest-selected', (_e, _input, _data) => {
+                    _input = $(_input);
+                    _input.closest('form').find('input[name="' + _input.attr('target-field') + '"]').val(_data[_input.attr('target-key')]);
+                });
+            parentSegment.find('.copy-target')
+                .off('click.copy-target')
+                .on('click.copy-target', function() {
+                    copyTextToClipboard($(this).attr('data-target'));
+                    return false;
+                });
+
+            parentSegment.find('.generate-and-visit-ic-portal')
+                .off('click.generate-and-visit-ic-portal')
+                .on('click.generate-and-visit-ic-portal', function() {
+                    $.post('/api/session/proLogInAsCustomer', {
+                        customerUid: $(this).attr('data-uid')
+                    }, _data => {
+                        if(!hasResponseError(_data)) {
+                            window.location.href = '/ic/home/' + _data.data;
+                            return false;
+                        }
+                    });
+                    return false;
+                });
+
+            parentSegment.find('.generate-and-copy-ic-portal-url')
+                .off('click.generate-and-copy-ic-portal-url')
+                .on('click.generate-and-copy-ic-portal-url', function() {
+                    $.post('/api/session/proLogInAsCustomer', {
+                        customerUid: $(this).attr('data-uid')
+                    }, _data => {
+                        if(!hasResponseError(_data)) {
+                            copyTextToClipboard('{{config('app.url')}}/ic/home/' + _data.data);
+                            return false;
+                        }
+                    });
+                    return false;
+                });
+
+            parentSegment.find('.generate-and-visit-ic-pay')
+                .off('click.generate-and-visit-ic-pay')
+                .on('click.generate-and-visit-ic-pay', function() {
+                    $.post('/api/session/proLogInAsCustomer', {
+                        customerUid: $(this).attr('data-uid')
+                    }, _data => {
+                        if(!hasResponseError(_data)) {
+                            window.location.href = '/ic/pay/' + $(this).attr('data-invoice-uid') + '/' + _data.data;
+                            return false;
+                        }
+                    });
+                    return false;
+                });
+
+            parentSegment.find('.generate-and-copy-ic-pay-url')
+                .off('click.generate-and-copy-ic-pay-url')
+                .on('click.generate-and-copy-ic-pay-url', function() {
+                    $.post('/api/session/proLogInAsCustomer', {
+                        customerUid: $(this).attr('data-uid')
+                    }, _data => {
+                        if(!hasResponseError(_data)) {
+                            copyTextToClipboard('{{config('app.url')}}/ic/pay/' + $(this).attr('data-invoice-uid') + '/' + _data.data);
+                            return false;
+                        }
+                    });
+                    return false;
+                });
+        }
+        addMCInitializer('invoicing-{{$patient->uid}}', init, '#invoicing-{{$patient->uid}}')
+    }).call(window);
+</script>
+@endsection
+

+ 0 - 4
resources/views/app/patient/invoicing/transactions.blade.php

@@ -1,4 +0,0 @@
-@extends ('layouts.patient')
-@section('inner-content')
-    <h4 class="font-weight-bold m-0 font-size-16">Transactions</h4>
-@endsection

+ 1 - 12
resources/views/layouts/patient.blade.php

@@ -41,18 +41,7 @@ $isOldClient = (date_diff(date_create(config('app.point_impl_date')), date_creat
 
 					@if($pro->pro_type === 'ADMIN')
 						<li class="nav-item">
-							<a class="nav-link" href="{{ route('patients.view.invoicing-companies', ['patient' => $patient]) }}" title="Deprecated">Invoicing</a>
-							<ul class="m-0 p-0 nav-child-list">
-								<li class="nav-item">
-									<a class="nav-link {{ strpos($routeName, 'patients.view.invoicing-companies') === 0 ? 'active' : '' }}" href="{{ route('patients.view.invoicing-companies', ['patient' => $patient]) }}">Companies</a>
-								</li>
-								<li class="nav-item">
-									<a class="nav-link {{ strpos($routeName, 'patients.view.invoicing-invoices') === 0 ? 'active' : '' }}" href="{{ route('patients.view.invoicing-invoices', ['patient' => $patient]) }}">Invoices</a>
-								</li>
-								<li class="nav-item">
-									<a class="nav-link {{ strpos($routeName, 'patients.view.invoicing-transactions') === 0 ? 'active' : '' }}" href="{{ route('patients.view.invoicing-transactions', ['patient' => $patient]) }}">Transactions</a>
-								</li>
-							</ul>
+							<a class="nav-link {{ strpos($routeName, 'patients.view.invoicing-') === 0 ? 'active' : '' }}" href="{{ route('patients.view.invoicing-companies', ['patient' => $patient]) }}" title="Deprecated">Invoicing</a>
 						</li>
 					@endif
 

+ 3 - 2
routes/web.php

@@ -590,8 +590,9 @@ Route::middleware('pro.auth')->group(function () {
 
             // invoicing
             Route::get('invoicing/companies', 'PatientController@invoicingCompanies')->name('invoicing-companies');
-            Route::get('invoicing/invoices', 'PatientController@invoicingInvoices')->name('invoicing-invoices');
-            Route::get('invoicing/transactions', 'PatientController@invoicingTransactions')->name('invoicing-transactions');
+            Route::get('invoicing/invoices/{customer}', 'PatientController@invoicingInvoices')->name('invoicing-invoices');
+            Route::get('invoicing/customer-transactions/{customer}', 'PatientController@invoicingCustomerTransactions')->name('invoicing-customer-transactions');
+            Route::get('invoicing/invoice-transactions/{invoice}', 'PatientController@invoicingInvoiceTransactions')->name('invoicing-invoice-transactions');
 
             // prescriptions (new)
             Route::get('prescriptions/{type?}/{currentErx?}', 'PatientController@prescriptions')->name('patient-prescriptions');