Selaa lähdekoodia

Active/Cancelled filter top-right for patient > supply orders

Vijayakrishnan 4 vuotta sitten
vanhempi
commit
d585599a7e
2 muutettua tiedostoa jossa 39 lisäystä ja 5 poistoa
  1. 14 0
      app/Models/Client.php
  2. 25 5
      resources/views/app/patient/supply-orders.blade.php

+ 14 - 0
app/Models/Client.php

@@ -451,6 +451,20 @@ class Client extends Model
             ->orderBy('created_at', 'desc');
     }
 
+    public function activeSupplyOrders()
+    {
+        return $this->hasMany(SupplyOrder::class, 'client_id', 'id')
+            ->where('is_cancelled', false)
+            ->orderBy('created_at', 'desc');
+    }
+
+    public function cancelledSupplyOrders()
+    {
+        return $this->hasMany(SupplyOrder::class, 'client_id', 'id')
+            ->where('is_cancelled', true)
+            ->orderBy('created_at', 'desc');
+    }
+
     public function readyToShipSupplyOrders()
     {
         return $this->hasMany(SupplyOrder::class, 'client_id', 'id')

+ 25 - 5
resources/views/app/patient/supply-orders.blade.php

@@ -54,11 +54,31 @@
                     </form>
                 </div>
             @endif
+            <select class="ml-auto max-width-300px form-control form-control-sm"
+                    onchange="fastLoad('/patients/view/{{$patient->uid}}/supply-orders{{@$supplyOrder ? '/' . $supplyOrder->uid : '' }}?filter=' + this.value, true, false, false)">
+                <option value="active" {{ !request()->input('filter') || request()->input('filter') === 'active' ? 'selected' : '' }}>Active Supply Orders</option>
+                <option value="cancelled" {{ request()->input('filter') === 'cancelled' ? 'selected' : '' }}>Cancelled Supply Orders</option>
+                <option value="all" {{ request()->input('filter') === 'all' ? 'selected' : '' }}>All Supply Orders</option>
+            </select>
         </div>
         <div class="d-flex align-items-start h-100">
             <div class="flex-grow-1">
                 <table class="table table-sm table-bordered mb-0" style="table-layout: fixed">
-                    @if($patient->supplyOrders && count($patient->supplyOrders))
+                    <?php
+                    $supplyOrdersList = $patient->activeSupplyOrders;
+                    if(request()->input('filter')) {
+                        switch(request()->input('filter')) {
+                            case 'cancelled':
+                                $supplyOrdersList = $patient->cancelledSupplyOrders;
+                                break;
+                            case 'all':
+                                $supplyOrdersList = $patient->supplyOrders;
+                                break;
+                        }
+                    }
+                    ?>
+
+                    @if($supplyOrdersList && count($supplyOrdersList))
                         <thead>
                         <tr class="bg-light">
                             <th class="px-2 text-nowrap text-secondary border-bottom-0"><div class="text-ellipsis">Title</div></th>
@@ -70,10 +90,10 @@
                         </tr>
                         </thead>
                         <tbody>
-                        @foreach($patient->supplyOrders as $iSupplyOrder)
+                        @foreach($supplyOrdersList as $iSupplyOrder)
                             <tr class="{{@$supplyOrder && @$supplyOrder->uid === $iSupplyOrder->uid ? 'bg-aliceblue' : ''}} {{$iSupplyOrder->is_cancelled ? 'on-hover-opaque' : ''}}">
                                 <td class="px-2">
-                                    <a href="{{route('patients.view.supply-orders', ['patient' => $patient, 'supplyOrder' => $iSupplyOrder])}}">
+                                    <a href="{{route('patients.view.supply-orders', ['patient' => $patient, 'supplyOrder' => $iSupplyOrder])}}{{request()->input('filter') ? '?filter=' . request()->input('filter') : ''}}">
                                         {{ $iSupplyOrder->product->title }}
                                     </a>
                                     @if($iSupplyOrder->is_cancelled)
@@ -106,7 +126,7 @@
                     @else
                         <tbody>
                         <tr>
-                            <td class="text-secondary p-3">No supply orders have been created for this patient</td>
+                            <td class="text-secondary p-3">No supply orders matching the criteria</td>
                         </tr>
                         </tbody>
                     @endif
@@ -116,7 +136,7 @@
                 <div class="min-width-500px ml-2 border align-self-stretch p-3">
                     <div class="d-flex align-items-center">
                         <h3 class="font-size-16 m-0">{{$supplyOrder->product->title}}</h3>
-                        <a class="ml-auto" href="{{route('patients.view.supply-orders', ['patient' => $patient])}}">
+                        <a class="ml-auto" href="/patients/view/{{$patient->uid}}/supply-orders{{request()->input('filter') ? '?filter=' . request()->input('filter') : ''}}">
                             <i class="fa fa-times-circle on-hover-opaque"></i>
                         </a>
                     </div>