Kaynağa Gözat

added dashboard numbers

Josh Kamau 5 yıl önce
ebeveyn
işleme
b7006a562e

+ 12 - 0
app/Http/Controllers/Controller.php

@@ -2,11 +2,14 @@
 
 namespace App\Http\Controllers;
 
+use App\Models\AppSession;
 use App\Models\Pro;
 use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
 use Illuminate\Foundation\Bus\DispatchesJobs;
 use Illuminate\Foundation\Validation\ValidatesRequests;
+use Illuminate\Http\Request;
 use Illuminate\Routing\Controller as BaseController;
+use Illuminate\Support\Facades\Cookie;
 
 class Controller extends BaseController
 {
@@ -21,4 +24,13 @@ class Controller extends BaseController
         }
         view()->share('pros', Pro::all());
     }
+
+    public function performer(){
+        $sessionKey = Cookie::get('sessionKey');
+        if ($sessionKey == null){
+            throw new \Exception('No session key in cookie.');
+        }
+        $performer = AppSession::where('session_key', $sessionKey)->first();
+        return $performer;
+    }
 }

+ 57 - 1
app/Http/Controllers/HomeController.php

@@ -4,13 +4,69 @@ namespace App\Http\Controllers;
 
 use App\Models\AppSession;
 use App\Models\Client;
+use App\Models\Bill;
+use App\Models\Note;
+use App\Models\ProTransaction;
 use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
 
 class HomeController extends Controller
 {
     public function dashboard(Request $request)
     {
-        return view('app/dashboard');
+
+        //patients where performer is the mcp
+        $performer = $this->performer();
+
+        $keyNumbers  = [];
+
+        $totalPatients = Client::where('mcp_pro_id', $performer->pro->id)->count();
+        $keyNumbers['totalPatients'] = $totalPatients;
+
+        $patientNotSeenYet = Client::where('mcp_pro_id', $performer->pro->id)
+            ->where(function($query){
+                $query->where('has_mcp_done_onboarding_visit', 'UNKNOWN')
+                ->orWhere('has_mcp_done_onboarding_visit', 'NO');
+            })->count();
+        $keyNumbers['patientsNotSeenYet'] = $patientNotSeenYet;
+
+        $performerProID = $performer->pro->id;
+        $pendingBillsToSign = Bill::where(function($query) use ($performerProID){
+            $query->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false);
+        })
+        ->orWhere(function($query) use ($performerProID){
+            $query->where('cm_pro_id', $performerProID)->where('is_signed_by_cm', false);
+        })->orWhere(function($query) use ($performerProID){
+            $query->where('rme_pro_id', $performerProID)->where('is_signed_by_rme', false);
+        })->orWhere(function($query) use ($performerProID){
+            $query->where('rmm_pro_id', $performerProID)->where('is_signed_by_rmm', false);
+        })->count();
+        
+        $keyNumbers['pendingBillsToSign'] = $pendingBillsToSign;
+
+        $pendingNotesToSign = Note::where(function($query) use ($performerProID){
+            $query->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false);
+        })
+        ->orWhere(function($query) use ($performerProID){
+            $query->where('ally_pro_id', $performerProID)->where('is_signed_by_ally', false);
+        })->count();
+        
+        $keyNumbers['pendingNotesToSign'] = $pendingNotesToSign;
+
+        $reimbursement = [];
+        $reimbursement["currentBalance"] = $performer->pro->balance;
+        $reimbursement["nextPaymentDate"] = '--';
+        $lastPayment = ProTransaction::where('pro_id', $performerProID)->where('plus_or_minus', 'PLUS')->orderBy('created_at', 'DESC')->first();
+        if($lastPayment) {
+            $reimbursement["lastPayment"] = $lastPayment->amount;
+            $reimbursement["lastPaymentDate"] = $lastPayment->created_at;
+        }else{
+            $reimbursement["lastPayment"] = '--';
+            $reimbursement["lastPaymentDate"] = '--';   
+        }
+        
+
+        return view('app/dashboard', compact('keyNumbers','reimbursement'));
     }
 
     public function patients(Request $request)

+ 1 - 1
app/Models/ProTransaction.php

@@ -6,5 +6,5 @@ namespace App\Models;
 
 class ProTransaction extends Model
 {
-    //
+    protected $table = 'pro_transaction';
 }

+ 8 - 8
resources/views/app/dashboard.blade.php

@@ -16,19 +16,19 @@
                             <table class="table table-condensed table-bordered m-0">
                                 <tbody>
                                 <tr>
-                                    <th>0</th>
+                                    <th>{{$keyNumbers['totalPatients']}}</th>
                                     <th>Total patients</th>
                                 </tr>
                                 <tr>
-                                    <th>0</th>
+                                    <th>{{$keyNumbers['patientsNotSeenYet']}}</th>
                                     <th>Patients I have not seen yet</th>
                                 </tr>
                                 <tr>
-                                    <th>0</th>
+                                    <th>{{$keyNumbers['pendingBillsToSign']}}</th>
                                     <th>Pending bills to sign</th>
                                 </tr>
                                 <tr>
-                                    <th>0</th>
+                                    <th>{{$keyNumbers['pendingNotesToSign']}}</th>
                                     <th>Pending notes to sign</th>
                                 </tr>
                                 </tbody>
@@ -45,19 +45,19 @@
                             <table class="table table-condensed table-bordered m-0">
                                 <tbody>
                                 <tr>
-                                    <th>$1034.90</th>
+                                    <th>{{$reimbursement['currentBalance']}}</th>
                                     <th>Current balance</th>
                                 </tr>
                                 <tr>
-                                    <th>30 June, 2020</th>
+                                    <th>{{$reimbursement['nextPaymentDate']}}</th>
                                     <th>Next Payment Date</th>
                                 </tr>
                                 <tr>
-                                    <th>$1023.00</th>
+                                    <th>{{$reimbursement['lastPayment']}}</th>
                                     <th>Last payment</th>
                                 </tr>
                                 <tr>
-                                    <th>15 June, 2020</th>
+                                    <th>{{$reimbursement['lastPaymentDate']}}</th>
                                     <th>Last payment date</th>
                                 </tr>
                                 </tbody>