瀏覽代碼

Financial transactions > filters

Vijayakrishnan 3 年之前
父節點
當前提交
8ed4ab4cc9

+ 40 - 2
app/Http/Controllers/PracticeManagementController.php

@@ -80,8 +80,46 @@ class PracticeManagementController extends Controller
 
     public function financialTransactions(Request $request)
     {
-        $transactions = ProTransaction::where('pro_id', $this->performer()->pro->id)->orderBy('created_at', 'desc')->get();
-        return view('app.practice-management.financial-transactions', compact('transactions'));
+        $pro = $this->performer()->pro;
+        $transactions = null;
+        if($pro->pro_type === 'ADMIN') {
+            $transactions = ProTransaction::whereNotNull('id');
+        }
+        else {
+            $transactions = ProTransaction::where('pro_id', $pro->id);
+        }
+
+        $filter = $request->input('p');
+        if ($filter) {
+            $filterPro = Pro::where('uid', $filter)->first();
+            if($filterPro) {
+                $transactions = $transactions->where('pro_id', '=', $filterPro->id);
+            }
+        }
+
+        $filter = $request->input('t');
+        if ($filter) {
+            $transactions = $transactions->where('plus_or_minus', '=', $filter);
+        }
+
+        $filter = $request->input('c');
+        if ($filter) {
+            $transactions = $transactions->where('company_id', '=', $filter);
+        }
+
+        $filter = $request->input('bs');
+        if ($filter) {
+            $transactions = $transactions->where('created_at', '>=', $filter);
+        }
+
+        $filter = $request->input('be');
+        if ($filter) {
+            $transactions = $transactions->where('created_at', '<=', $filter);
+        }
+
+        $transactions = $transactions->orderBy('created_at', 'desc')->paginate();
+        $companies = Company::where('is_active', true)->orderBy('name')->get();
+        return view('app.practice-management.financial-transactions', compact('transactions', 'companies'));
     }
 
     public function pendingBillsToSign(Request $request)

+ 4 - 0
app/Models/ProTransaction.php

@@ -16,6 +16,10 @@ class ProTransaction extends Model
         return $this->belongsTo(Bill::class);
     }
 
+    public function pro() {
+        return $this->hasOne(Pro::class, 'id', 'pro_id');
+    }
+
     public function company() {
         return $this->hasOne(Company::class, 'id', 'company_id');
     }

+ 109 - 3
resources/views/app/practice-management/financial-transactions.blade.php

@@ -9,23 +9,73 @@
                     Financial Transactions
                 </strong>
                 <div class="ml-auto">
-                    <span class="">
+                    <b class="mr-2">{{$pro->displayName()}}</b>
+                    <i class="fa fa-arrow-right mr-2"></i>
+                    <span class="text-secondary">
                         <strong>Current Balance:</strong> ${{ $pro->balance }}
                     </span>&nbsp;
-                    <span>
+                    <span class="text-secondary">
                         <?php $lastPayment = $pro->lastPayment(); ?>
                         <strong>Last Payment:</strong>
                         {{ $lastPayment ? '$' . $lastPayment->amount . ' (' . friendly_date_time($lastPayment->created_at, false) . ')' : '-' }}
                     </span>
                 </div>
             </div>
+            <div class="card-header p-3">
+                <div class="d-flex align-items-center">
+                    <div class="width-200px">
+                        <select provider-search data-pro-uid="{{ request()->input('p') ? request()->input('p') : '' }}"
+                                name="proUid" class="form-control form-control-sm mr-auto width-200px min-width-unset"
+                                onchange="return transactionsFilter('p', this.value)">
+                            <option value="" {{!request()->input('p') ? 'selected' : ''}}>All Pros</option>
+                        </select>
+                    </div>
+                    <select name="filter" class="form-control form-control-sm width-200px ml-2"
+                            onchange="return transactionsFilter('t', this.value)">
+                        <option {{request()->input('t') === '' ? 'selected' : ''}} value="">All Transactions</option>
+                        <option {{request()->input('t') === 'PLUS' ? 'selected' : ''}} value="PLUS">Credits
+                        </option>
+                        <option {{request()->input('t') === 'MINUS' ? 'selected' : ''}} value="MINUS">Debits
+                        </option>
+                    </select>
+                    <select name="filter" class="form-control form-control-sm width-200px ml-2"
+                            onchange="return transactionsFilter('c', this.value)">
+                        <option {{!request()->input('c') ? 'selected' : ''}} value="">All Companies</option>
+                        @foreach($companies as $company)
+                            <option {{request()->input('c') == $company->id ? 'selected' : ''}}
+                                    value="{{$company->id}}">
+                                {{$company->name}}
+                            </option>
+                        @endforeach
+                    </select>
+                    <div class="ml-4 d-inline-flex align-items-center">
+                        <span class="mr-2">Date</span>
+                        <input type="date"
+                               value="{{request()->input('bs')}}"
+                               onchange="return transactionsFilter('bs', this.value)"
+                               class="form-control form-control-sm width-150px" name="bpdFrom">
+                        <span class="mx-2">to</span>
+                        <input type="date"
+                               value="{{request()->input('be')}}"
+                               onchange="return transactionsFilter('be', this.value)"
+                               class="form-control form-control-sm width-150px" name="bpdTo">
+                    </div>
+                    @if(count(array_filter(request()->all(), function($_x) { return !!$_x;})))
+                        <a href="/practice-management/financial-transactions" class="ml-4">Clear Filters</a>
+                    @endif
+                </div>
+            </div>
             <div class="card-body p-0">
-                <table class="table table-sm table-condensed p-0 m-0" style="table-layout: fixed">
+                <table class="table table-sm table-condensed p-0 m-0">
                     <thead class="bg-light">
                         <tr>
                             <th class="px-3 border-0">Date</th>
                             <th class="border-0">Type</th>
                             <th class="border-0">Client</th>
+                            @if($pro->pro_type === 'ADMIN')
+                                <th class="border-0">Pro</th>
+                            @endif
+                            <th class="border-0">Company</th>
                             <th class="border-0">Context</th>
                             <th class="border-0">Amount</th>
                             <th class="border-0">Balance</th>
@@ -49,7 +99,15 @@
                                         -
                                     @endif
                                 </td>
+                                @if($pro->pro_type === 'ADMIN')
+                                    <td>
+                                        {{$transaction->pro ? $transaction->pro->displayName() : ''}}
+                                    </td>
+                                @endif
                                 <td>
+                                    {{$transaction->company ? $transaction->company->name : ''}}
+                                </td>
+                                <td class="text-nowrap">
                                     @if($transaction->bill && $transaction->bill->note)
                                         <a href="{{route('patients.view.notes.view.dashboard', ['patient'=>$transaction->client, 'note'=>$transaction->bill->note])}}">
                                             ({{$transaction->bill->note->effective_dateest}})
@@ -108,5 +166,53 @@
                 </table>
             </div>
         </div>
+
+        <div class="d-flex align-items-center mt-3">
+            {{ $transactions->withQueryString()->links() }}
+        </div>
     </div>
+    <script>
+        (function() {
+            window.transactionsFilter = function(_key, _value) {
+
+                <?php
+                $keys = ['p', 'bs', 'be', 't', 'c'];
+                $currentParams = [];
+                for($i = 0; $i < count($keys); $i++) {
+                    if(!!request()->input($keys[$i])) {
+                        $currentParams[$keys[$i]] = request()->input($keys[$i]);
+                    }
+                }
+                ?>
+
+                let base = '/practice-management/financial-transactions',
+                    keys = ['p', 'bs', 'be', 't', 'c'].filter(_x => _x !== _key),
+                    currentParams = {!! json_encode($currentParams) !!},
+                    url = [];
+
+                // base
+                url.push(base);
+                url.push('?');
+
+                // params
+                let getParams = [];
+                for (let i = 0; i < keys.length; i++) {
+                    if(currentParams[keys[i]]) {
+                        getParams.push(keys[i] + '=' + encodeURIComponent(currentParams[keys[i]]));
+                    }
+                }
+
+                // new params
+                getParams.push(_key + '=' + encodeURIComponent(_value));
+
+                // generate url
+                url.push(getParams.join('&'));
+
+                // go
+                fastLoad(url.join(''));
+
+                return false;
+            };
+        }).call(window);
+    </script>
 @endsection