浏览代码

Invoice-center (wip)

Vijayakrishnan 3 年之前
父节点
当前提交
d52dbd943a

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

@@ -0,0 +1,142 @@
+<?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 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
+{
+
+    public function customers(Request $request) {
+        $records = Customer::orderBy('created_at', 'DESC')->paginate();
+        return view ('app.invoice-center.customers', compact('records'));
+    }
+
+    public function giftCards(Request $request) {
+        $records = GiftCard::orderBy('created_at', 'DESC')->paginate();
+        return view ('app.invoice-center.gift-cards', compact('records'));
+    }
+
+    public function invoices(Request $request) {
+        $records = Invoice::orderBy('created_at', 'DESC')->paginate();
+        return view ('app.invoice-center.invoices', compact('records'));
+    }
+
+    public function customerTransactions(Request $request) {
+        $records = CustomerTransaction::orderBy('created_at', 'DESC')->paginate();
+        return view ('app.invoice-center.customer-transactions', compact('records'));
+    }
+
+    public function invoiceTransactions(Request $request) {
+        $records = InvoiceTransaction::orderBy('created_at', 'DESC')->paginate();
+        return view ('app.invoice-center.invoice-transactions', compact('records'));
+    }
+
+    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
+        ]);
+    }
+   
+}

+ 18 - 0
app/Models/Customer.php

@@ -0,0 +1,18 @@
+<?php
+
+namespace App\Models;
+
+# use Illuminate\Database\Eloquent\Model;
+
+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');
+    }
+}

+ 11 - 0
app/Models/CustomerTransaction.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+# use Illuminate\Database\Eloquent\Model;
+
+class CustomerTransaction extends Model
+{
+    protected $table = 'customer_transaction';
+
+}

+ 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');
+    }
+}

+ 11 - 0
app/Models/Invoice.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+# use Illuminate\Database\Eloquent\Model;
+
+class Invoice extends Model
+{
+    protected $table = 'invoice';
+
+}

+ 11 - 0
app/Models/InvoiceTransaction.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+# use Illuminate\Database\Eloquent\Model;
+
+class InvoiceTransaction extends Model
+{
+    protected $table = 'invoice_transaction';
+
+}

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

@@ -0,0 +1,4 @@
+@extends('layouts.invoice-center')
+@section('inner-content')
+    Customer Transactions
+@endsection

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

@@ -0,0 +1,116 @@
+@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">
+                    <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"
+                           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 Balance</th>
+                <th class="border-bottom-0">Pending Invoices 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>
+                        @if($record->is_active)
+                            <div moe class="ml-3">
+                                <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="ml-3">
+                                <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
+                    </td>
+                </tr>
+            @endforeach
+            </tbody>
+        </table>
+    @else
+        <div class="text-secondary">No customers yet!</div>
+    @endif
+@endsection

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

@@ -0,0 +1,106 @@
+@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">
+                    <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"
+                           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>
+    @else
+        <div class="text-secondary">No gift cards yet!</div>
+    @endif
+@endsection

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

@@ -0,0 +1,4 @@
+@extends('layouts.invoice-center')
+@section('inner-content')
+    Invoice Transactions
+@endsection

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

@@ -0,0 +1,4 @@
+@extends('layouts.invoice-center')
+@section('inner-content')
+    Invoices
+@endsection

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

@@ -0,0 +1,50 @@
+@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.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 pt-3 mcp-theme-1">
+			@yield('inner-content')
+		</main>
+	</div>
+</div>
+<script>
+	(function () {
+		function init() {
+			let parentSegment = $('#invoice-center');
+			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')]);
+					});
+		}
+		addMCInitializer('invoice-center', init, '#invoice-center')
+	}).call(window);
+</script>
+@endsection

+ 14 - 0
routes/web.php

@@ -224,6 +224,16 @@ Route::middleware('pro.auth')->group(function () {
        
     });
 
+    Route::name('invoice-center.')->prefix('invoice-center')->group(function () {
+        Route::middleware('pro.auth.admin')->group(function () {
+            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');
+        });
+    });
+
     Route::name('practice-management.')->prefix('practice-management')->group(function () {
 
 
@@ -635,6 +645,10 @@ 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');
+
     // Pro suggest
     Route::get('/pro-suggest', 'HomeController@proSuggest');
     Route::get('/pro-display-name/{pro}', 'HomeController@proDisplayName');