Преглед на файлове

Supply orders matrix filters

Vijayakrishnan преди 4 години
родител
ревизия
38ee1c7668
променени са 2 файла, в които са добавени 209 реда и са изтрити 18 реда
  1. 69 3
      app/Http/Controllers/PracticeManagementController.php
  2. 140 15
      resources/views/app/practice-management/supply-orders.blade.php

+ 69 - 3
app/Http/Controllers/PracticeManagementController.php

@@ -10,6 +10,7 @@ use App\Models\Client;
 use App\Models\McpRequest;
 use App\Models\Note;
 use App\Models\Pro;
+use App\Models\Product;
 use App\Models\ProFavorite;
 use App\Models\ProGeneralAvailability;
 use App\Models\ProProAccess;
@@ -533,9 +534,74 @@ class PracticeManagementController extends Controller
         return view('app.practice-management.tickets', compact('tickets'));
     }
 
-    public function supplyOrders(Request $request, $filter = null) {
-        $supplyOrders = SupplyOrder::orderBy('created_at', 'desc')->paginate();
-        return view('app.practice-management.supply-orders', compact('supplyOrders'));
+    public function supplyOrders(Request $request) {
+
+        // so clients
+        $soClientIDs = DB::table('supply_order')->select('client_id')->distinct()->get()->toArray();
+        $soClientIDs = array_map(function($_x) {
+            return $_x->client_id;
+        }, $soClientIDs);
+        $soClients = Client::whereIn('id', $soClientIDs)->get();
+
+        // so products
+        $soProductIDs = DB::table('supply_order')->select('product_id')->distinct()->get()->toArray();
+        $soProductIDs = array_map(function($_x) {
+            return $_x->product_id;
+        }, $soProductIDs);
+        $soProducts = Product::whereIn('id', $soProductIDs)->get();
+
+        $filters = [];
+        $filters['client'] = $request->input('client');
+        $filters['product'] = $request->input('product');
+        $filters['reason'] = $request->input('reason');
+        $filters['cu_memo'] = $request->input('cu_memo');
+        $filters['pro_sign'] = $request->input('pro_sign');
+        $filters['client_sign'] = $request->input('client_sign');
+        $filters['shipment'] = $request->input('shipment');
+        $filters['lot_number'] = $request->input('lot_number');
+        $filters['imei'] = $request->input('imei');
+        $filters['cancelled'] = $request->input('cancelled');
+
+        $supplyOrders = SupplyOrder::where('id', '>', 0);
+
+        // apply filters
+        if($filters['client']) $supplyOrders->where('client_id', $filters['client']);
+        if($filters['product']) $supplyOrders->where('product_id', $filters['product']);
+        if($filters['reason']) $supplyOrders->where('reason', 'ILIKE', '%' . $filters['reason'] . '%');
+        if($filters['cu_memo']) $supplyOrders->where('cu_memo', 'ILIKE', '%' . $filters['cu_memo'] . '%');
+        if($filters['pro_sign']) $supplyOrders->where('is_signed_by_pro', ($filters['pro_sign'] === 'signed'));
+
+        if($filters['client_sign']) {
+            if($filters['client_sign'] === 'signed')
+                $supplyOrders->where('is_signed_by_client', true);
+            elseif($filters['client_sign'] === 'waived')
+                $supplyOrders->where('is_client_signature_waived', true);
+            else
+                $supplyOrders->where('is_client_signature_waived', false)->where('is_signed_by_client', false);
+        }
+
+        if ($filters['shipment']) {
+            if ($filters['shipment'] === 'not_cleared_for_shipment')
+                $supplyOrders->where('is_cleared_for_shipment', false);
+            elseif ($filters['shipment'] === 'cleared_for_shipment')
+                $supplyOrders->where('is_cleared_for_shipment', true);
+            else
+                $supplyOrders
+                    ->whereNotNull('shipment_id')
+                    ->whereRaw('(SELECT status FROM shipment WHERE id = ? LIMIT 1) = shipment_id', [$filters['shipment']]);
+        }
+
+        if($filters['lot_number']) $supplyOrders->where('lot_number', 'ILIKE', '%' . $filters['lot_number'] . '%');
+        if($filters['imei']) $supplyOrders->where('imei', 'ILIKE', '%' . $filters['imei'] . '%');
+        if($filters['cancelled']) $supplyOrders->where('is_cancelled', ($filters['cancelled'] === 'cancelled'));
+
+        $supplyOrders = $supplyOrders->orderBy('created_at', 'desc')->paginate();
+
+        return view('app.practice-management.supply-orders',
+            compact('supplyOrders', 'filters',
+                'soClients', 'soProducts'
+            )
+        );
     }
 
     public function shipments(Request $request, $filter = null) {

+ 140 - 15
resources/views/app/practice-management/supply-orders.blade.php

@@ -2,7 +2,7 @@
 
 @section('content')
 
-    <div class="p-3 mcp-theme-1">
+    <div id="practice-supply-orders" class="p-3 mcp-theme-1">
     <div class="card">
 
         <div class="card-header px-3 py-2 d-flex align-items-center">
@@ -10,28 +10,115 @@
                 <i class="fas fa-user-injured"></i>
                 Supply Orders
             </strong>
-
+            <a href="/practice-management/supply-orders" class="ml-auto">Clear Filters</a>
         </div>
         <div class="card-body p-0">
             <table class="table table-sm table-condensed p-0 m-0">
                 <thead class="bg-light">
                 <tr>
-                    <th>Client</th>
-                    <th>Product</th>
-                    <th>Reason</th>
-                    <th>Client Understanding Memo</th>
-                    <th>Pro Sign</th>
-                    <th>Client Sign</th>
-                    <th>Shipment</th>
-                    <th>Lot #</th>
-                    <th>IMEI</th>
-                    <th>Created At</th>
-                    <th>Cancelled?</th>
+                    <th class="border-0">Client</th>
+                    <th class="border-0">Product</th>
+                    <th class="border-0">Reason</th>
+                    <th class="border-0">Client Understanding Memo</th>
+                    <th class="border-0">Pro Sign</th>
+                    <th class="border-0">Client Sign</th>
+                    <th class="border-0">Shipment</th>
+                    <th class="border-0">Lot #</th>
+                    <th class="border-0">IMEI</th>
+                    <th class="border-0">Created At</th>
+                    <th class="border-0">Cancelled?</th>
+                </tr>
+                <tr>
+                    <th class="p-0 border-bottom-0 border-right">
+                        <select class="form-control form-control-sm bg-aliceblue min-width-unset rounded-0 shadow-none border-0"
+                                data-filter="client">
+                            <option value="">All</option>
+                            @foreach($soClients as $soClient)
+                                <option value="{{$soClient->id}}"
+                                    {{$filters['client'] == $soClient->id ? 'selected' : ''}}>{{$soClient->displayName()}}</option>
+                            @endforeach
+                        </select>
+                    </th>
+                    <th class="p-0 border-bottom-0 border-right">
+                        <select class="form-control form-control-sm bg-aliceblue min-width-unset rounded-0 shadow-none border-0"
+                                data-filter="product">
+                            <option value="">All</option>
+                            @foreach($soProducts as $soProduct)
+                                <option value="{{$soProduct->id}}"
+                                    {{$filters['product'] == $soProduct->id ? 'selected' : ''}}>{{$soProduct->title}}</option>
+                            @endforeach
+                        </select>
+                    </th>
+                    <th class="p-0 border-bottom-0 border-right">
+                        <input type="text" class="form-control form-control-sm bg-aliceblue min-width-unset rounded-0 shadow-none border-0"
+                               data-filter="reason"
+                               value="{{$filters['reason']}}" placeholder="Any">
+                    </th>
+                    <th class="p-0 border-bottom-0 border-right">
+                        <input type="text" class="form-control form-control-sm bg-aliceblue min-width-unset rounded-0 shadow-none border-0"
+                               data-filter="cu_memo"
+                               value="{{$filters['cu_memo']}}" placeholder="Any">
+                    </th>
+                    <th class="p-0 border-bottom-0 border-right">
+                        <select class="form-control form-control-sm bg-aliceblue min-width-unset rounded-0 shadow-none border-0"
+                                data-filter="pro_sign">
+                            <option value="">All</option>
+                            <option {{$filters['pro_sign'] == 'not_signed' ? 'selected' : ''}} value="not_signed">Not Signed</option>
+                            <option {{$filters['pro_sign'] == 'signed' ? 'selected' : ''}} value="signed">Signed</option>
+                        </select>
+                    </th>
+                    <th class="p-0 border-bottom-0 border-right">
+                        <select class="form-control form-control-sm bg-aliceblue min-width-unset rounded-0 shadow-none border-0"
+                                data-filter="client_sign">
+                            <option value="">All</option>
+                            <option {{$filters['client_sign'] == 'not_signed' ? 'selected' : ''}} value="not_signed">Not Signed</option>
+                            <option {{$filters['client_sign'] == 'signed' ? 'selected' : ''}} value="signed">Signed</option>
+                            <option {{$filters['client_sign'] == 'waived' ? 'selected' : ''}} value="waived">Waived</option>
+                        </select>
+                    </th>
+                    <th class="p-0 border-bottom-0 border-right">
+                        <select class="form-control form-control-sm bg-aliceblue min-width-unset rounded-0 shadow-none border-0"
+                                data-filter="shipment">
+                            <option value="">All</option>
+                            <optgroup label="Pro">
+                                <option {{$filters['shipment'] == 'not_cleared_for_shipment' ? 'selected' : ''}} value="not_cleared_for_shipment">Not Cleared for Shipment</option>
+                                <option {{$filters['shipment'] == 'cleared_for_shipment' ? 'selected' : ''}} value="cleared_for_shipment">Cleared for Shipment</option>
+                            </optgroup>
+                            <optgroup label="Warehouse">
+                                <option {{$filters['shipment'] == 'CREATED' ? 'selected' : ''}} value="CREATED">Created</option>
+                                <option {{$filters['shipment'] == 'SHIPPED' ? 'selected' : ''}} value="SHIPPED">Shipped</option>
+                                <option {{$filters['shipment'] == 'DELIVERED' ? 'selected' : ''}} value="DELIVERED">Delivered</option>
+                                <option {{$filters['shipment'] == 'RETURNED_TO_SENDER' ? 'selected' : ''}} value="RETURNED_TO_SENDER">Returned to Sender</option>
+                                <option {{$filters['shipment'] == 'CANCELLED' ? 'selected' : ''}} value="CANCELLED">Cancelled</option>
+                            </optgroup>
+                        </select>
+                    </th>
+                    <th class="p-0 border-bottom-0 border-right">
+                        <input type="text" class="form-control form-control-sm bg-aliceblue min-width-unset rounded-0 shadow-none border-0"
+                               data-filter="lot_number"
+                               value="{{$filters['lot_number']}}" placeholder="Any">
+                    </th>
+                    <th class="p-0 border-bottom-0 border-right">
+                        <input type="text" class="form-control form-control-sm bg-aliceblue min-width-unset rounded-0 shadow-none border-0"
+                               data-filter="imei"
+                               value="{{$filters['imei']}}" placeholder="Any">
+                    </th>
+                    <th class="p-0 border-bottom-0 border-right">
+
+                    </th>
+                    <th class="p-0 border-bottom-0 border-right">
+                        <select class="form-control form-control-sm bg-aliceblue min-width-unset rounded-0 shadow-none border-0"
+                                data-filter="cancelled">
+                            <option value="">All</option>
+                            <option {{$filters['cancelled'] == 'not_cancelled' ? 'selected' : ''}} value="not_cancelled">Not Cancelled</option>
+                            <option {{$filters['cancelled'] == 'cancelled' ? 'selected' : ''}} value="cancelled">Cancelled</option>
+                        </select>
+                    </th>
                 </tr>
                 </thead>
                 <tbody>
                 @foreach ($supplyOrders as $supplyOrder)
-                    <tr>
+                    <tr class="{{$supplyOrder->is_cancelled ? 'bg-light' : ''}}">
                         <td>{{$supplyOrder->client->displayName()}}</a></td>
                         <td>{{$supplyOrder->product->title}}</td>
                         <td>{{$supplyOrder->reason}}</td>
@@ -93,7 +180,7 @@
                                 By {{$supplyOrder->createdSession->pro->displayName()}}
                             </div>
                         </td>
-                        <td>{{$supplyOrder->is_cancelled ? 'Yes' : 'No'}}</td>
+                        <td>{!! $supplyOrder->is_cancelled ? '<b class="text-warning-mellow">Yes</b>' : 'No' !!}</td>
                     </tr>
                 @endforeach
                 </tbody>
@@ -105,4 +192,42 @@
     </div>
     </div>
 
+    <script>
+        (function() {
+
+            function applyFilters() {
+                let params = {}, queryLine = [];
+                $('[data-filter]').each(function() {
+                    if($.trim($(this).val())) {
+                        params[$(this).attr('data-filter')] = $.trim($(this).val());
+                    }
+                });
+                for(let x in params) {
+                    if(params.hasOwnProperty(x)) {
+                        queryLine.push(x + '=' + encodeURIComponent(params[x]));
+                    }
+                }
+                queryLine = queryLine.join('&');
+
+                fastLoad('/practice-management/supply-orders?' + queryLine);
+            }
+
+            function init() {
+                $('select[data-filter]')
+                    .off('change')
+                    .on('change', applyFilters);
+                $('input[data-filter]')
+                    .off('keyup')
+                    .on('keyup', function(_event) {
+                        if(_event.which === 13) {
+                            applyFilters();
+                            return false;
+                        }
+                    });
+            }
+
+            addMCInitializer('practice-supply-orders', init, '#practice-supply-orders')
+
+        }).call(window);
+    </script>
 @endsection