فهرست منبع

Merge branch 'master' of rav.triplestart.com:jmudaka/stagfe2

= 3 سال پیش
والد
کامیت
cdf5d9557f

+ 26 - 0
app/Helpers/helpers.php

@@ -214,6 +214,32 @@ if(!function_exists('friendly_date_time')) {
     }
 }
 
+if(!function_exists('friendly_date_time_with_seconds')) {
+    function friendly_date_time_with_seconds($value, $includeTime = true, $default = '-', $long_year=false) {
+        if(!$value || empty($value)) return $default;
+        try {
+            if($includeTime) {
+                $realTimezone = 'US/Eastern';
+                $date = new DateTime($value);
+                $date->setTimezone(new DateTimeZone($realTimezone));
+                return $date->format("m/d/y" . ($includeTime ? ", h:i:sa" : "")) . ($includeTime ? ' EST' : '');
+            }
+            else {
+                $result = strtotime($value);
+                if($long_year){
+                    $result = date("m/d/Y" . ($includeTime ? ", h:i:sa" : ""), $result);
+                }else{
+                    $result = date("m/d/y" . ($includeTime ? ", h:i:sa" : ""), $result);
+                }
+                return $result;
+            }
+        }
+        catch (Exception $e) {
+            return $value;
+        }
+    }
+}
+
 if(!function_exists('friendly_date_month_year')) {
     function friendly_date_month_year($value, $default = '-', $long_year=true) {
         if(!$value || empty($value)) return $default;

+ 251 - 0
app/Http/Controllers/InvoiceController.php

@@ -0,0 +1,251 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Models\AppSession;
+use App\Models\BillingReport;
+use App\Models\CareMonth;
+use App\Models\ClaimEDI;
+use App\Models\ClientProChange;
+use App\Models\Company;
+use App\Models\Customer;
+use App\Models\CustomerTransaction;
+use App\Models\GiftCard;
+use App\Models\Handout;
+use App\Models\Invoice;
+use App\Models\InvoiceTransaction;
+use App\Models\MBClaim;
+use App\Models\Measurement;
+use App\Models\Bill;
+use App\Models\Claim;
+use App\Models\Client;
+use App\Models\McpRequest;
+use App\Models\McCodeCheck;
+use App\Models\Note;
+use App\Models\Pack;
+use App\Models\Pro;
+use App\Models\Product;
+use App\Models\ProFavorite;
+use App\Models\ProGeneralAvailability;
+use App\Models\ProProAccess;
+use App\Models\ProRate;
+use App\Models\ProSpecificAvailability;
+use App\Models\ProSpecificUnavailability;
+use App\Models\ProTeam;
+use App\Models\ProTextShortcut;
+use App\Models\ProTransaction;
+use App\Models\Shipment;
+use App\Models\SupplyOrder;
+use App\Models\Team;
+use App\Models\Ticket;
+use App\Models\AccountInvite;
+use App\Models\ClientMeasurementDaysPerMonth;
+use App\Models\ClientBDTDevice;
+use App\Models\ClientMemo;
+use Carbon\Carbon;
+use Cassandra\Custom;
+use Illuminate\Pagination\LengthAwarePaginator;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Http;
+use PDF;
+use DateTime;
+use DateTimeZone;
+use Illuminate\Http\Request;
+use App\Models\SegmentTemplate;
+use App\Models\VisitTemplate;
+use App\Models\VisitTemplateSegmentTemplate;
+use App\Models\VisitTemplateAccess;
+
+class InvoiceController extends Controller
+{
+
+    private static $PAGE_SIZE = 25;
+
+    public function companies(Request $request) {
+        $records = Company::orderBy('name', 'ASC')->where('is_active', true)->paginate(InvoiceController::$PAGE_SIZE);
+        return view ('app.invoice-center.companies', compact('records'));
+    }
+
+    public function customers(Request $request) {
+        $records = Customer::orderBy('created_at', 'DESC');
+        $company = null;
+        if($request->input('companyUid')) {
+            $company = Company::where('uid', $request->input('companyUid'))->first();
+            if($company) {
+                $records = $records->where('company_id', $company->id);
+            }
+        }
+        $records = $records->paginate(InvoiceController::$PAGE_SIZE);
+        return view ('app.invoice-center.customers', compact('records', 'company'));
+    }
+
+    public function giftCards(Request $request) {
+        $records = GiftCard::orderBy('created_at', 'DESC');
+        $company = null;
+        if($request->input('companyUid')) {
+            $company = Company::where('uid', $request->input('companyUid'))->first();
+            if($company) {
+                $records = $records->where('company_id', $company->id);
+            }
+        }
+        $records = $records->paginate(InvoiceController::$PAGE_SIZE);
+        return view ('app.invoice-center.gift-cards', compact('records', 'company'));
+    }
+
+    public function invoices(Request $request) {
+        $records = Invoice::orderBy('created_at', 'DESC');
+        $customer = null;
+        if($request->input('customerUid')) {
+            $customer = Customer::where('uid', $request->input('customerUid'))->first();
+            if($customer) {
+                $records = $records->where('customer_id', $customer->id);
+            }
+        }
+        $records = $records->paginate(InvoiceController::$PAGE_SIZE);
+        return view ('app.invoice-center.invoices', compact('records', 'customer'));
+    }
+
+    public function customerTransactions(Request $request) {
+        $records = CustomerTransaction::orderBy('created_at', 'DESC');
+        $customer = null;
+        if($request->input('customerUid')) {
+            $customer = Customer::where('uid', $request->input('customerUid'))->first();
+            if($customer) {
+                $records = $records->where('customer_id', $customer->id);
+            }
+        }
+        $records = $records->paginate(InvoiceController::$PAGE_SIZE);
+        return view ('app.invoice-center.customer-transactions', compact('records', 'customer'));
+    }
+
+    public function invoiceTransactions(Request $request) {
+        $records = InvoiceTransaction::orderBy('created_at', 'DESC');
+        $invoice = null;
+        if($request->input('invoiceUid')) {
+            $invoice = Invoice::where('uid', $request->input('invoiceUid'))->first();
+            if($invoice) {
+                $records = $records->where('invoice_id', $invoice->id);
+            }
+        }
+        $records = $records->paginate(InvoiceController::$PAGE_SIZE);
+        return view ('app.invoice-center.invoice-transactions', compact('records', 'invoice'));
+    }
+
+    public function icPayInvoice(Request $request, $invoiceSlug) {
+        $invoice = Invoice::where('payment_link_slug', $invoiceSlug)->where('is_active', true)->first();
+        if (!$invoice) abort(404);
+        $customer = $invoice->customer;
+        $company = $customer->company;
+        return view('app.invoice-center.ic-pay-invoice', compact('invoice', 'customer', 'company'));
+    }
+
+    public function companySuggestJSON(Request $request) {
+        $term = $request->input('term') ? trim($request->input('term')) : '';
+        if (empty($term)) return '';
+        $matches = DB::select("
+SELECT company.uid,
+       company.name as text
+FROM company
+WHERE company.name ILIKE :term
+ORDER BY company.name",
+            ['term' => $term . '%']
+        );
+        return json_encode([
+            "success" => true,
+            "data" => $matches
+        ]);
+    }
+
+    public function clientSuggestJSON(Request $request) {
+        $term = $request->input('term') ? trim($request->input('term')) : '';
+        if (empty($term)) return '';
+
+        // if multiple words in query, check for all (max 2)
+        $term2 = '';
+        if(strpos($term, ' ') !== FALSE) {
+            $terms = explode(' ', $term);
+            $term = trim($terms[0]);
+            $term2 = trim($terms[1]);
+        }
+
+        if(!empty($term2)) {
+            $matches = DB::select("
+SELECT client.uid,
+       (client.name_first || ' ' || client.name_last) as text
+FROM client
+WHERE (client.name_first ILIKE :term OR client.name_last ILIKE :term OR client.name_first ILIKE :term2 OR client.name_last ILIKE :term2)
+ORDER BY client.name_first, client.name_last",
+                ['term' => $term . '%', 'term2' => $term2 . '%']
+            );
+        }
+        else {
+            $matches = DB::select("
+SELECT client.uid,
+       (client.name_first || ' ' || client.name_last) as text
+FROM client
+WHERE (client.name_first ILIKE :term OR client.name_last ILIKE :term)
+ORDER BY client.name_first, client.name_last",
+                ['term' => $term . '%']
+            );
+        }
+
+        return json_encode([
+            "success" => true,
+            "data" => $matches
+        ]);
+    }
+
+    public function customerSuggestJSON(Request $request) {
+        $term = $request->input('term') ? trim($request->input('term')) : '';
+        if (empty($term)) return '';
+
+        // if multiple words in query, check for all (max 2)
+        $term2 = '';
+        if(strpos($term, ' ') !== FALSE) {
+            $terms = explode(' ', $term);
+            $term = trim($terms[0]);
+            $term2 = trim($terms[1]);
+        }
+
+        if(!empty($term2)) {
+            $matches = DB::select("
+SELECT customer.uid,
+       (client.name_first || ' ' || client.name_last || ' (' || company.name || ')') as text
+FROM client join customer on client.id = customer.client_id join company on customer.company_id = company.id
+WHERE (client.name_first ILIKE :term OR client.name_last ILIKE :term OR client.name_first ILIKE :term2 OR client.name_last ILIKE :term2)
+ORDER BY client.name_first, client.name_last",
+                ['term' => $term . '%', 'term2' => $term2 . '%']
+            );
+        }
+        else {
+            $matches = DB::select("
+SELECT customer.uid,
+       (client.name_first || ' ' || client.name_last || ' (' || company.name || ')') as text
+FROM client join customer on client.id = customer.client_id join company on customer.company_id = company.id
+WHERE (client.name_first ILIKE :term OR client.name_last ILIKE :term)
+ORDER BY client.name_first, client.name_last",
+                ['term' => $term . '%']
+            );
+        }
+
+        return json_encode([
+            "success" => true,
+            "data" => $matches
+        ]);
+    }
+
+    public function customerInvoicesJSON(Request $request, Customer $customer) {
+        $invoices = [];
+        foreach ($customer->invoices as $invoice) {
+            $invoices[] = [
+                "uid" => $invoice->uid,
+                "text" => $invoice->displayName()
+            ];
+        }
+        return json_encode([
+            "success" => true,
+            "data" => $invoices
+        ]);
+    }
+   
+}

+ 9 - 0
app/Models/Company.php

@@ -2,6 +2,7 @@
 
 namespace App\Models;
 
+use Cassandra\Custom;
 use Illuminate\Database\Eloquent\Model;
 
 class Company extends Model
@@ -13,4 +14,12 @@ class Company extends Model
         return $this->hasMany(CompanyLocation::class, 'company_id', 'id')->orderBy('line1', 'ASC');
     }
 
+    public function customers(){
+        return $this->hasMany(Customer::class, 'company_id', 'id')->orderBy('created_at', 'DESC');
+    }
+
+    public function giftCards(){
+        return $this->hasMany(GiftCard::class, 'company_id', 'id')->orderBy('created_at', 'DESC');
+    }
+
 }

+ 24 - 0
app/Models/Customer.php

@@ -0,0 +1,24 @@
+<?php
+
+namespace App\Models;
+
+# use Illuminate\Database\Eloquent\Model;
+
+use Illuminate\Database\Eloquent\Relations\HasMany;
+
+class Customer extends Model
+{
+    protected $table = 'customer';
+
+    public function client() {
+        return $this->hasOne(Client::class, 'id', 'client_id');
+    }
+
+    public function company() {
+        return $this->hasOne(Company::class, 'id', 'company_id');
+    }
+
+    public function invoices() {
+        return $this->hasMany(Invoice::class, 'customer_id', 'id')->orderBy('created_at', 'DESC');
+    }
+}

+ 14 - 0
app/Models/CustomerTransaction.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace App\Models;
+
+# use Illuminate\Database\Eloquent\Model;
+
+class CustomerTransaction extends Model
+{
+    protected $table = 'customer_transaction';
+
+    public function customer() {
+        return $this->hasOne(Customer::class, 'id', 'customer_id');
+    }
+}

+ 14 - 0
app/Models/GiftCard.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace App\Models;
+
+# use Illuminate\Database\Eloquent\Model;
+
+class GiftCard extends Model
+{
+    protected $table = 'gift_card';
+
+    public function company() {
+        return $this->hasOne(Company::class, 'id', 'company_id');
+    }
+}

+ 20 - 0
app/Models/Invoice.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace App\Models;
+
+# use Illuminate\Database\Eloquent\Model;
+
+class Invoice extends Model
+{
+    protected $table = 'invoice';
+
+    public function displayName() {
+        return '$' . $this->amount .
+        ($this->description ? ' | ' . substr($this->description, 0, 15) : '') .
+        ' | ' . friendly_date_time($this->created_at);
+    }
+
+    public function customer() {
+        return $this->hasOne(Customer::class, 'id', 'customer_id');
+    }
+}

+ 14 - 0
app/Models/InvoiceTransaction.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace App\Models;
+
+# use Illuminate\Database\Eloquent\Model;
+
+class InvoiceTransaction extends Model
+{
+    protected $table = 'invoice_transaction';
+
+    public function invoice() {
+        return $this->hasOne(Invoice::class, 'id', 'invoice_id');
+    }
+}

+ 2 - 1
config/app.php

@@ -65,7 +65,8 @@ return [
 
     'hrm2_url' => env('HRM2_URL'),
 
-    'asset_version' => 94,
+    'asset_version' => 95,
+
 
     'temp_dir' => env('TEMP_DIR'),
 

+ 2 - 2
js-dev/yemi.js

@@ -518,7 +518,7 @@ var initMoes = function() {
                             hideMoeFormMask();
                             hideMask();
                             runMCHook(hook);
-                        } else if(isDynamicStagPopupPresent()) {
+                        } else if(typeof isDynamicStagPopupPresent !== 'undefined' && isDynamicStagPopupPresent()) {
                             let targetUrl = false;
                             if (redir) {
                                 if (redir.indexOf('[data]') > -1) {
@@ -570,7 +570,7 @@ var initMoes = function() {
                             hideMoeFormMask();
                             hideMask();
                             runMCHook(hook);
-                        } else if(isDynamicStagPopupPresent()) {
+                        } else if(typeof isDynamicStagPopupPresent !== 'undefined' && isDynamicStagPopupPresent()) {
                             let targetUrl = false;
                             if (redir) {
                                 if (redir.indexOf('[data]') > -1) {

+ 52 - 0
resources/views/app/invoice-center/companies.blade.php

@@ -0,0 +1,52 @@
+@extends('layouts.invoice-center')
+@section('inner-content')
+    <div class="d-flex mb-2 pb-2 align-items-center border-bottom">
+        <div class="font-size-14 font-weight-bold">Companies</div>
+    </div>
+    @if(count($records))
+        <table class="table table-sm table-bordered table-striped">
+            <thead>
+            <tr>
+                <th class="border-bottom-0"></th>
+                <th class="border-bottom-0 width-300px">Name</th>
+                <th class="border-bottom-0">State</th>
+                <th class="border-bottom-0">Customers</th>
+                <th class="border-bottom-0">Gift Cards</th>
+                <th class="border-bottom-0">Created</th>
+            </tr>
+            </thead>
+            <tbody>
+            <?php $i = 1; ?>
+            @foreach($records as $record)
+                <tr>
+                    <td>{{ $i++ }}</td>
+                    <td>{{ $record->name }}</td>
+                    <td>{{ $record->state }}</td>
+                    <td>
+                        <a href="{{route('invoice-center.customers')}}?companyUid={{$record->uid}}"
+                           class="mr-2"
+                           open-in-stag-popup
+                           update-parent
+                           title="{{$record->name}}: Customers"
+                           popup-style="stag-popup-med overflow-visible"
+                           mc-initer="invoice-center">{{count($record->customers)}} customer{{count($record->customers) === 1 ? '' : 's'}}</a>
+                    </td>
+                    <td>
+                        <a href="{{route('invoice-center.giftCards')}}?companyUid={{$record->uid}}"
+                           class="mr-2"
+                           open-in-stag-popup
+                           update-parent
+                           title="{{$record->name}}: Gift Cards"
+                           popup-style="stag-popup-med overflow-visible"
+                           mc-initer="invoice-center">{{count($record->giftCards)}} gift card{{count($record->giftCards) === 1 ? '' : 's'}}</a>
+                    </td>
+                    <td>{{ friendly_date($record->created_at) }}</td>
+                </tr>
+            @endforeach
+            </tbody>
+        </table>
+        {{$records->withQueryString()->links()}}
+    @else
+        <div class="text-secondary">No companies yet!</div>
+    @endif
+@endsection

+ 131 - 0
resources/views/app/invoice-center/customer-transactions.blade.php

@@ -0,0 +1,131 @@
+@extends('layouts.invoice-center')
+@section('inner-content')
+    <div class="d-flex mb-2 pb-2 align-items-center border-bottom">
+        <div class="font-size-14 font-weight-bold">Customer Transactions</div>
+        <div moe class="ml-3">
+            <a href="" start show class="btn btn-sm btn-primary font-weight-normal text-white">
+                + Add Manual Plus Transaction
+            </a>
+            <form url="/api/customerTransaction/createManualPlus" class="mcp-theme-1">
+                <p class="mb-2 text-secondary font-weight-bold text-nowrap">Add Manual Plus Transaction</p>
+                <div class="mb-2">
+                    <label class="text-sm text-secondary mb-1">Customer</label>
+                    <input type="hidden" name="customerUid" value="{{@$customer->uid}}">
+                    <input type="text"
+                           name="customerName"
+                           target-key="uid"
+                           target-field="customerUid"
+                           autocomplete="off"
+                           class="form-control form-control-sm"
+                           stag-suggest
+                           stag-suggest-ep="/customer-suggest"
+                           value="{{@$customer && $customer->client ? @$customer->client->displayName() : ''}}"
+                           {{@$customer ? 'disabled readonly' : ''}}
+                           required>
+                </div>
+                <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 moe class="ml-3">
+            <a href="" start show class="btn btn-sm btn-primary font-weight-normal text-white">
+                + Add Manual Minus Transaction
+            </a>
+            <form url="/api/customerTransaction/createManualMinus" class="mcp-theme-1">
+                <p class="mb-2 text-secondary font-weight-bold text-nowrap">Add Manual Minus Transaction</p>
+                <div class="mb-2">
+                    <label class="text-sm text-secondary mb-1">Customer</label>
+                    <input type="hidden" name="customerUid" value="{{@$customer->uid}}">
+                    <input type="text"
+                           name="customerName"
+                           target-key="uid"
+                           target-field="customerUid"
+                           autocomplete="off"
+                           class="form-control form-control-sm"
+                           stag-suggest
+                           stag-suggest-ep="/customer-suggest"
+                           value="{{@$customer && $customer->client ? @$customer->client->displayName() : ''}}"
+                           {{@$customer ? 'disabled readonly' : ''}}
+                           required>
+                </div>
+                <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($records))
+        <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">Customer</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="b1order-bottom-0">Resulting<br>Balance</th>
+            </tr>
+            </thead>
+            <tbody>
+            @foreach($records as $record)
+                <tr>
+                    <td>{{ friendly_date_time_with_seconds($record->created_at) }}</td>
+                    <td>
+                        @if($record->customer && $record->customer->client)
+                            <a href="{{route('patients.view.dashboard', $record->customer->client)}}">
+                                {{$record->customer->client->displayName()}}
+                            </a>
+                        @else
+                            -
+                        @endif
+                    </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>
+                </tr>
+            @endforeach
+            </tbody>
+        </table>
+        {{$records->withQueryString()->links()}}
+    @else
+        <div class="text-secondary">No customer transactions yet!</div>
+    @endif
+@endsection

+ 135 - 0
resources/views/app/invoice-center/customers.blade.php

@@ -0,0 +1,135 @@
+@extends('layouts.invoice-center')
+@section('inner-content')
+    <div class="d-flex mb-2 pb-2 align-items-center border-bottom">
+        <div class="font-size-14 font-weight-bold">Customers</div>
+        <div moe class="ml-3">
+            <a href="" start show class="btn btn-sm btn-primary font-weight-normal text-white">
+                + Add Customer
+            </a>
+            <form url="/api/customer/create" class="mcp-theme-1">
+                <p class="mb-2 text-secondary font-weight-bold">Add Customer</p>
+                <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 class="mb-2">
+                    <label class="text-sm text-secondary mb-1">Client</label>
+                    <input type="hidden" name="clientUid">
+                    <input type="text"
+                           name="clientName"
+                           target-key="uid"
+                           target-field="clientUid"
+                           autocomplete="off"
+                           class="form-control form-control-sm"
+                           stag-suggest
+                           stag-suggest-ep="/client-suggest"
+                           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($records))
+        <table class="table table-sm table-bordered table-striped">
+            <thead>
+            <tr>
+                <th class="border-bottom-0"></th>
+                <th class="border-bottom-0">Customer</th>
+                <th class="border-bottom-0">Age/Gender</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">Created</th>
+                <th class="border-bottom-0">Active?</th>
+                <th class="border-bottom-0"></th>
+            </tr>
+            </thead>
+            <tbody>
+            <?php $i = 1; ?>
+            @foreach($records as $record)
+                <tr>
+                    <td>{{ $i++ }}</td>
+                    <td>
+                        @if($record->client)
+                            <a href="{{route('patients.view.dashboard', $record->client)}}">
+                                {{$record->client->displayName()}}
+                            </a>
+                        @else
+                            -
+                        @endif
+                        @if(!$record->is_active)
+                            <span class="text-sm font-weight-bold text-secondary ml-2">[INACTIVE]</span>
+                        @endif
+                    </td>
+                    <td>{{$record->client->age_in_years ?: '-' }} / {{ $record->client->sex ?: '-'}}</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>{{ 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('invoice-center.customerTransactions')}}?customerUid={{$record->uid}}"
+                               class="mr-2"
+                               open-in-stag-popup
+                               update-parent
+                               title="{{$record->client->displayName()}}: Customer Transactions"
+                               popup-style="stag-popup-med overflow-visible"
+                               mc-initer="invoice-center">Transactions</a>
+                            <a href="{{route('invoice-center.invoices')}}?customerUid={{$record->uid}}"
+                               class="mr-2"
+                               open-in-stag-popup
+                               update-parent
+                               title="{{$record->client->displayName()}}: Invoices"
+                               popup-style="stag-popup-med overflow-visible"
+                               mc-initer="invoice-center">Invoices</a>
+                        </div>
+                    </td>
+                </tr>
+            @endforeach
+            </tbody>
+        </table>
+        {{$records->withQueryString()->links()}}
+    @else
+        <div class="text-secondary">No customers yet!</div>
+    @endif
+@endsection

+ 109 - 0
resources/views/app/invoice-center/gift-cards.blade.php

@@ -0,0 +1,109 @@
+@extends('layouts.invoice-center')
+@section('inner-content')
+    <div class="d-flex mb-2 pb-2 align-items-center border-bottom">
+        <div class="font-size-14 font-weight-bold">Gift Cards</div>
+        <div moe class="ml-3">
+            <a href="" start show class="btn btn-sm btn-primary font-weight-normal text-white">
+                + Add Gift Card
+            </a>
+            <form url="/api/giftCard/create" class="mcp-theme-1">
+                <p class="mb-2 text-secondary font-weight-bold">Add Gift Card</p>
+                <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 class="mb-2">
+                    <label class="text-sm text-secondary mb-1">Code</label>
+                    <input type="text"
+                           name="code"
+                           autocomplete="off"
+                           class="form-control form-control-sm"
+                           required>
+                </div>
+                <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>
+                    <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($records))
+        <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">Code</th>
+                <th class="border-bottom-0">Amount</th>
+                <th class="border-bottom-0">Used?</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($records as $record)
+                <tr>
+                    <td>{{ $i++ }}</td>
+                    <td>{{ $record->company ? $record->company->name : '-' }}</td>
+                    <td>{{ $record->code ?: '-' }}</td>
+                    <td>${{ !is_null($record->amount) ? $record->amount : 0 }}</td>
+                    <td>{{ $record->is_used ? 'Yes' : 'No' }}</td>
+                    <td>{{ friendly_date($record->created_at) }}</td>
+                    <td class="{{ !$record->is_active ? 'text-warning-dark' : ''}}">{{ $record->is_active ? 'Yes' : 'No' }}</td>
+                    <td>
+                        @if($record->is_active)
+                            <div moe class="ml-3">
+                                <a href="" start show>Deactivate</a>
+                                <form url="/api/giftCard/deactivate" class="mcp-theme-1" right>
+                                    <p class="mb-2 text-nowrap">Deactivate this gift card?</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="ml-3">
+                                <a href="" start show>Reactivate</a>
+                                <form url="/api/giftCard/reactivate" class="mcp-theme-1" right>
+                                    <p class="mb-2 text-nowrap">Reactivate this gift card?</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
+                    </td>
+                </tr>
+            @endforeach
+            </tbody>
+        </table>
+        {{$records->withQueryString()->links()}}
+    @else
+        <div class="text-secondary">No gift cards yet!</div>
+    @endif
+@endsection

+ 96 - 0
resources/views/app/invoice-center/ic-pay-invoice.blade.php

@@ -0,0 +1,96 @@
+@extends ('layouts.guest_template')
+@section('content')
+<div class="container mcp-theme-1">
+    <h3 class="font-size-16 font-weight-bold my-3 text-dark">Invoice</h3>
+    <hr>
+    <div class="row">
+        <div class="col-md-8">
+            <div class="mb-3">Hi <b class="text-dark">{{$customer->client->displayName()}}</b>, please find your invoice below:</div>
+            <table class="table table-sm table-bordered">
+                <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>
+                </tr>
+                </thead>
+                <tbody class="font-weight-normal">
+                <tr>
+                    <td>{{friendly_date($invoice->created_at)}}</td>
+                    <td>{{$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>
+                </tr>
+                <tr>
+                    <td class="p-3 text-right" colspan="6">
+                        <div class="d-flex justify-content-end align-items-baseline mb-2">
+                            <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-end align-items-baseline mb-2">
+                            <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-end 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="mt-3 border rounded border-success p-2 text-center">
+                                <i class="fa fa-check text-success"></i>
+                                <span class="text-success">PAID</span>
+                            </div>
+                        @else
+                            @if($customer->customer_balance >= $invoice->balance)
+                                <div moe relative class="mt-3">
+                                    <a href="#" start show class="btn btn-sm btn-primary text-white font-weight-bold py-2">Pay <b>${{$invoice->balance}}</b> from your current balance (${{$customer->customer_balance}})</a>
+                                    <form url="/api/invoiceTransaction/createPlusForCustomerTransaction">
+                                        <p class="mb-2 text-left">Confirm Payment?</p>
+                                        <input type="hidden" name="invoiceUid" value="{{$invoice->uid}}">
+                                        <input type="hidden" name="amount" value="{{$invoice->balance}}">
+                                        <input type="hidden" name="customMemo" value="Payment by customer via balance">
+                                        <div class="text-left">
+                                            <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 class="mt-3 border rounded border-secondary p-2 text-center text-warning-dark">
+                                    Your current balance (${{$customer->customer_balance}}) is less than the due amount (${{$invoice->balance}}). If you have a gift card, use its code on the right hand side to add funds to your balance.
+                                </div>
+                            @endif
+                        @endif
+                    </td>
+                </tr>
+                </tbody>
+            </table>
+        </div>
+        <div class="col-md-4 border-left">
+            <div class="mb-3">
+                <span class="font-weight-bold text-secondary">Current Balance: </span>
+                <span class="font-weight-bold text-dark">${{!is_null($customer->customer_balance) ? $customer->customer_balance : 0}}</span>
+            </div>
+            <h3 class="font-weight-bold mb-2 text-secondary">Redeem Gift Card</h3>
+            <div moe>
+                <form url="/api/giftCard/redeem" show>
+                    <input type="hidden" name="customerUid" value="{{$customer->uid}}">
+                    <p class="mb-2">If you have a gift card from {{$company->name}}, please enter its code below:</p>
+                    <div class="mb-2">
+                        <input type="text" name="code" placeholder="Code" class="form-control form-control-sm">
+                    </div>
+                    <div class="text-left">
+                        <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>
+    </div>
+</div>
+@endsection

+ 164 - 0
resources/views/app/invoice-center/invoice-transactions.blade.php

@@ -0,0 +1,164 @@
+@extends('layouts.invoice-center')
+@section('inner-content')
+    <div id="invoice-transactions">
+        <div class="d-flex mb-2 pb-2 align-items-center border-bottom">
+            <div class="font-size-14 font-weight-bold">Invoice Transactions</div>
+            <div moe class="ml-3">
+                <a href="" start show class="btn btn-sm btn-primary font-weight-normal text-white">
+                    + Add Manual Plus Transaction
+                </a>
+                <form url="/api/invoiceTransaction/createManualPlus" class="mcp-theme-1">
+                    <p class="mb-2 text-secondary font-weight-bold text-nowrap">Add Manual Plus Transaction</p>
+                    <div class="mb-2">
+                        <label class="text-sm text-secondary mb-1">Customer</label>
+                        <input type="text"
+                               name="customerName"
+                               autocomplete="off"
+                               class="form-control form-control-sm customer-select"
+                               stag-suggest
+                               stag-suggest-ep="/customer-suggest"
+                               required>
+                    </div>
+                    <div class="mb-2">
+                        <label class="text-sm text-secondary mb-1">Invoice</label>
+                        <select name="invoiceUid"
+                               class="form-control form-control-sm"
+                               required>
+                            <option value="">-- select --</option>
+                        </select>
+                    </div>
+                    <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 moe class="ml-3">
+                <a href="" start show class="btn btn-sm btn-primary font-weight-normal text-white">
+                    + Add Manual Minus Transaction
+                </a>
+                <form url="/api/invoiceTransaction/createManualMinus" class="mcp-theme-1">
+                    <p class="mb-2 text-secondary font-weight-bold text-nowrap">Add Manual Minus Transaction</p>
+                    <div class="mb-2">
+                        <label class="text-sm text-secondary mb-1">Customer</label>
+                        <input type="hidden" name="customerUid">
+                        <input type="text"
+                               name="customerName"
+                               autocomplete="off"
+                               class="form-control form-control-sm customer-select"
+                               stag-suggest
+                               stag-suggest-ep="/customer-suggest"
+                               required>
+                    </div>
+                    <div class="mb-2">
+                        <label class="text-sm text-secondary mb-1">Invoice</label>
+                        <select name="invoiceUid"
+                                class="form-control form-control-sm"
+                                required>
+                            <option value="">-- select --</option>
+                        </select>
+                    </div>
+                    <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($records))
+            <table class="table table-sm table-bordered table-striped">
+                <thead>
+                <tr>
+                    <th class="border-bottom-0">Created</th>
+                    <th class="border-bottom-0">Customer</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="b1order-bottom-0">Resulting<br>Balance</th>
+                </tr>
+                </thead>
+                <tbody>
+                @foreach($records as $record)
+                    <tr>
+                        <td>{{ friendly_date_time_with_seconds($record->created_at) }}</td>
+                        <td>
+                            @if($record->invoice && $record->invoice->customer && $record->invoice->customer->client)
+                                <a href="{{route('patients.view.dashboard', $record->invoice->customer->client)}}">
+                                    {{$record->invoice->customer->client->displayName()}}
+                                </a>
+                            @else
+                                -
+                            @endif
+                        </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>
+                    </tr>
+                @endforeach
+                </tbody>
+            </table>
+            {{$records->withQueryString()->links()}}
+        @else
+            <div class="text-secondary">No customer transactions yet!</div>
+        @endif
+    </div>
+    <script>
+        (function () {
+            function init() {
+                initStagSuggest();
+                let parentSegment = $('#invoice-transactions');
+                parentSegment.find('input.customer-select')
+                    .off('stag-suggest-selected')
+                    .on('stag-suggest-selected', (_e, _input, _data) => {
+                        _input = $(_input);
+                        let select = _input.closest('form').find('select[name="invoiceUid"]').empty();
+                        select.append('<option value="">-- select --</option>');
+                        select.prop('disabled', true);
+                        $.get('/customer/invoicesJSON/' + _data.uid, _data => {
+                             if(!hasResponseError(_data)) {
+                                 for (let i = 0; i < _data.data.length; i++) {
+                                     select.append($('<option/>').attr('value', _data.data[i].uid).text(_data.data[i].text));
+                                 }
+                             }
+                        }, 'json').then(() => {
+                            select.prop('disabled', false);
+                        });
+                    });
+            }
+            addMCInitializer('invoice-transactions', init, '#invoice-transactions')
+        }).call(window);
+    </script>
+@endsection

+ 173 - 0
resources/views/app/invoice-center/invoices.blade.php

@@ -0,0 +1,173 @@
+@extends('layouts.invoice-center')
+@section('inner-content')
+    <div class="d-flex mb-2 pb-2 align-items-center border-bottom">
+        <div class="font-size-14 font-weight-bold">Invoices</div>
+        <div moe class="ml-3">
+            <a href="" start show class="btn btn-sm btn-primary font-weight-normal text-white">
+                + Add Invoice
+            </a>
+            <form url="/api/invoice/create" class="mcp-theme-1">
+                <p class="mb-2 text-secondary font-weight-bold">Add Invoice</p>
+                <div class="mb-2">
+                    <label class="text-sm text-secondary mb-1">Customer</label>
+                    <input type="hidden" name="customerUid" value="{{@$customer->uid}}">
+                    <input type="text"
+                           name="customerName"
+                           target-key="uid"
+                           target-field="customerUid"
+                           autocomplete="off"
+                           class="form-control form-control-sm"
+                           stag-suggest
+                           stag-suggest-ep="/customer-suggest"
+                           value="{{@$customer && $customer->client ? @$customer->client->displayName() : ''}}"
+                           {{@$customer ? 'disabled readonly' : ''}}
+                           required>
+                </div>
+                <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($records))
+        <table class="table table-sm table-bordered table-striped">
+            <thead>
+            <tr>
+                <th class="border-bottom-0"></th>
+                <th class="border-bottom-0">Customer</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">Created</th>
+                <th class="border-bottom-0">Active?</th>
+                <th class="border-bottom-0"></th>
+            </tr>
+            </thead>
+            <tbody>
+            <?php $i = 1; ?>
+            @foreach($records as $record)
+                <tr>
+                    <td>{{ $i++ }}</td>
+                    <td>
+                        @if($record->customer && $record->customer->client)
+                            <a href="{{route('patients.view.dashboard', $record->customer->client)}}">
+                                {{$record->customer->client->displayName()}}
+                            </a>
+                        @else
+                            -
+                        @endif
+                        @if(!$record->is_active)
+                            <span class="text-sm font-weight-bold text-secondary ml-2">[INACTIVE]</span>
+                        @endif
+                    </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="{{route('icPayInvoice', ['invoiceSlug' => $record->payment_link_slug])}}" native target="_blank">Visit</a>
+                        <a href="#" data-target="{{route('icPayInvoice', ['invoiceSlug' => $record->payment_link_slug])}}" native target="_blank" class="copy-target">Copy</a>
+                    </td>
+                    <td>${{ is_null($record->paid) ? 0 : $record->paid }}</td>
+                    <td>${{ is_null($record->balance) ? 0 : $record->balance }}</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/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('invoice-center.invoiceTransactions')}}?invoiceUid={{$record->uid}}"
+                               class="mr-2"
+                               open-in-stag-popup
+                               update-parent
+                               title="{{$record->displayName()}}: Invoice Transactions"
+                               popup-style="stag-popup-med overflow-visible"
+                               mc-initer="invoice-transactions">Transactions</a>
+                        </div>
+                    </td>
+                </tr>
+            @endforeach
+            </tbody>
+        </table>
+        {{$records->withQueryString()->links()}}
+    @else
+        <div class="text-secondary">No invoices yet!</div>
+    @endif
+@endsection

+ 61 - 0
resources/views/layouts/invoice-center.blade.php

@@ -0,0 +1,61 @@
+@extends(request()->input('popupmode') ? 'layouts.empty' : 'layouts.template')
+<?php
+$routeName = request()->route()->getName();
+?>
+@section('content')
+<div class="container-fluid h-100 popup-content-container" id="invoice-center">
+	<div class="main-row h-100 {{ !request()->input('popupmode') ? '' : 'px-0' }}">
+		@if(!request()->input('popupmode'))
+		<nav id="sidebarMenu" class="d-block bg-light sidebar collapse px-0">
+			<div class="sidebar-sticky pt-3">
+				<ul class="nav flex-column mcp-theme-1">
+					<li class="nav-item">
+						<a class="nav-link {{ strpos($routeName, 'invoice-center.companies') === 0 ? 'active' : '' }}" href="{{ route('invoice-center.companies') }}">Companies</a>
+					</li>
+					<li class="nav-item">
+						<a class="nav-link {{ strpos($routeName, 'invoice-center.customers') === 0 ? 'active' : '' }}" href="{{ route('invoice-center.customers') }}">Customers</a>
+					</li>
+					<li class="nav-item">
+						<a class="nav-link {{ strpos($routeName, 'invoice-center.giftCards') === 0 ? 'active' : '' }}" href="{{ route('invoice-center.giftCards') }}">Gift Cards</a>
+					</li>
+					<li class="nav-item">
+						<a class="nav-link {{ strpos($routeName, 'invoice-center.invoices') === 0 ? 'active' : '' }}" href="{{ route('invoice-center.invoices') }}">Invoices</a>
+					</li>
+					<li class="nav-item">
+						<a class="nav-link {{ strpos($routeName, 'invoice-center.customerTransactions') === 0 ? 'active' : '' }}" href="{{ route('invoice-center.customerTransactions') }}">Customer Transactions</a>
+					</li>
+					<li class="nav-item">
+						<a class="nav-link {{ strpos($routeName, 'invoice-center.invoiceTransactions') === 0 ? 'active' : '' }}" href="{{ route('invoice-center.invoiceTransactions') }}">Invoice Transactions</a>
+					</li>
+				</ul>
+			</div>
+		</nav>
+		@endif
+		<main role="main" class="w-100 mcp-theme-1">
+			<div class="pt-3 hide-inside-popup"></div>
+			@yield('inner-content')
+		</main>
+	</div>
+</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;
+					});
+		}
+		addMCInitializer('invoice-center', init)
+	}).call(window);
+</script>
+@endsection

+ 1 - 0
resources/views/layouts/template.blade.php

@@ -204,6 +204,7 @@
                             <a class="dropdown-item" href="{{ route('practice-management.client-pro-changes') }}">Client Pro Changes</a>
                             <a class="dropdown-item" href="{{ route('practice-management.rpmMatrix') }}">RPM Matrix</a>
                             {{--<a class="dropdown-item" href="{{ route('practice-management.previousBills') }}">Previous Bills</a>--}}
+                            <a class="dropdown-item" href="{{ route('invoice-center.companies') }}">Invoice Center</a>
                             <a class="dropdown-item" href="{{ route('practice-management.financialTransactions') }}">Financial Transactions</a>
                             <a class="dropdown-item" href="/practice-management/bills/not-yet-signed">Pending Bills to Sign</a>
                             <a class="dropdown-item" href="/practice-management/notes/not-yet-signed">Pending Notes to Sign</a>

+ 20 - 0
routes/web.php

@@ -235,6 +235,20 @@ Route::middleware('pro.auth')->group(function () {
        
     });
 
+    Route::name('invoice-center.')->prefix('invoice-center')->group(function () {
+        Route::middleware('pro.auth.admin')->group(function () {
+            Route::get('companies', 'InvoiceController@companies')->name('companies');
+            Route::get('customers', 'InvoiceController@customers')->name('customers');
+            Route::get('gift-cards', 'InvoiceController@giftCards')->name('giftCards');
+            Route::get('invoices', 'InvoiceController@invoices')->name('invoices');
+            Route::get('customer-transactions', 'InvoiceController@customerTransactions')->name('customerTransactions');
+            Route::get('invoice-transactions', 'InvoiceController@invoiceTransactions')->name('invoiceTransactions');
+        });
+    });
+
+    // ic pages - client facing
+    Route::get('/ic/pay/{invoiceSlug}', 'InvoiceController@icPayInvoice')->name('icPayInvoice');
+
     Route::name('practice-management.')->prefix('practice-management')->group(function () {
 
 
@@ -649,6 +663,12 @@ Route::middleware('pro.auth')->group(function () {
     // Pharmacy suggest
     Route::get('/pharmacy-suggest', 'HomeController@pharmacySuggest');
 
+    // Company/client suggest
+    Route::get('/company-suggest', 'InvoiceController@companySuggestJSON')->name('company-suggest-json');
+    Route::get('/client-suggest', 'InvoiceController@clientSuggestJSON')->name('client-suggest-json');
+    Route::get('/customer-suggest', 'InvoiceController@customerSuggestJSON')->name('customer-suggest-json');
+    Route::get('/customer/invoicesJSON/{customer}', 'InvoiceController@customerInvoicesJSON')->name('customer-invoices-json');
+
     // Pro suggest
     Route::get('/pro-suggest', 'HomeController@proSuggest');
     Route::get('/pro-display-name/{pro}', 'HomeController@proDisplayName');