Browse Source

Bills refactor

Samson Mutunga 1 year ago
parent
commit
1d3a082bee

+ 30 - 2
app/Helpers/helpers.php

@@ -10,6 +10,7 @@ use App\Models\AppSession;
 use App\Models\Client;
 use App\Models\Pro;
 use App\Models\Bill;
+use App\Models\BillView;
 //require_once './class.Diff.php';
 use Illuminate\Support\Facades\Http;
 use Soundasleep\Html2Text as Html2Text;
@@ -137,9 +138,36 @@ if(!function_exists('inchesAfterFeetFromInches')) {
     }
 }
 
+if(!function_exists('genericBillsView')) {
+    function genericBillsView(Pro $performerPro, $patient,$careMonth, $entityType, $entityUid) {
+        $genericBills = BillView::where('bill_service_type', 'GENERIC');
+        if($performerPro->pro_type !== 'ADMIN') {
+            $genericBills = $genericBills->where('generic_pro_id', $performerPro->id);
+        }
+        if($patient) {
+            $genericBills = $genericBills->where('client_id', $patient->id);
+        }
+
+
+        if($careMonth){
+            $genericBills = $genericBills->where('care_month_id', $careMonth->id);
+        }
+
+        if($entityType && $entityUid) {
+
+            $genericBills = $genericBills
+                ->where('generic_target_entity_type', $entityType)
+                ->where('generic_target_entity_uid', $entityUid);
+
+
+        }
+        return $genericBills->orderBy('created_at', 'DESC')->paginate(20);
+    }
+}
+
 if(!function_exists('genericBills')) {
     function genericBills(Pro $performerPro, $patient,$careMonth, $entityType, $entityUid) {
-        $genericBills = Bill::where('bill_service_type', 'GENERIC');
+        $genericBills = Bill::where('bill_service_type', 'GENERIC')->with('genericPro');
         if($performerPro->pro_type !== 'ADMIN') {
             $genericBills = $genericBills->where('generic_pro_id', $performerPro->id);
         }
@@ -160,7 +188,7 @@ if(!function_exists('genericBills')) {
 
 
         }
-        return $genericBills->orderBy('created_at', 'DESC')->get();
+        return $genericBills->orderBy('created_at', 'DESC')->paginate(10000);
     }
 }
 

+ 1 - 1
app/Http/Controllers/PracticeManagementController.php

@@ -475,7 +475,7 @@ OFFSET {$offset} LIMIT {$perPage}
         $allAllyProsIDs = DB::table('note')->pluck('ally_pro_id')->toArray();
         $allAllyPros = Pro::whereIn('id', $allAllyProsIDs)->get();
 
-        $notes = $query->orderBy('created_at', 'desc')->paginate(30);
+        $notes = $query->with('client', 'hcpPro', 'allyPro')->orderBy('created_at', 'desc')->paginate(30);
 
         return view('app.practice-management.all-notes', compact('notes', 'filters','allProsWithNotes', 'allPatientsWithNotes', 'allAllyPros'));
     }

+ 10 - 0
app/Models/BillView.php

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

+ 4 - 1
resources/views/app/generic-bills/add-bill-form/_default-fields.blade.php

@@ -66,7 +66,10 @@
             </select>
         </div>
     </div>
-    <input type="hidden" name="numberOfUnits" value="1">
+    <div>
+        <label for="" class="text-secondary text-sm mb-1">Number of Units</label>
+        <input type="number" class="form-control form-control-sm" name="numberOfUnits" value="1" />
+    </div>
     <div class="mb-2" calculated-generic-amount></div>
 </div>
 @if($entityType !== 'Note')

+ 5 - 2
resources/views/app/generic-bills/inline.blade.php

@@ -11,7 +11,7 @@ use App\Models\Client;
 /** @var $entityType */
 /** @var $entityUid */
 
-$genericBills = genericBills($pro, @$patient, @$careMonth, @$entityType, @$entityUid);
+$genericBills = genericBillsView($pro, @$patient, @$careMonth, @$entityType, @$entityUid);
 ?>
 
 @if(!count($genericBills))
@@ -55,7 +55,7 @@ $genericBills = genericBills($pro, @$patient, @$careMonth, @$entityType, @$entit
                     <tr class="{{$bill->is_cancelled ? 'bg-light text-secondary' : ''}}">
                         <td class="text-nowrap">{{friendlier_date_time($bill->effective_date, false)}}</td>
                         <td class="">
-                            <div class="text-nowrap font-weight-bold text-secondary">{{ $bill->genericPro->displayName() }}</div>
+                            <div class="text-nowrap font-weight-bold text-secondary">{{ $bill->generic_pro_display_name }}</div>
                             <div class="text-nowrap mt-1 screen-only">
                                 <span class="text-secondary">Paid: </span>
                                 <span>{{ $bill->has_generic_pro_been_paid ? 'Yes' : 'No' }}</span>
@@ -313,4 +313,7 @@ $genericBills = genericBills($pro, @$patient, @$careMonth, @$entityType, @$entit
                 </tbody>
             </table>
     </div>
+    <div class="mt-3 d-flex justify-content-center">
+    {{ $genericBills->withQueryString()->links() }}
+    </div>
 @endif