소스 검색

Supply orders - read to ship page

Vijayakrishnan 4 년 전
부모
커밋
44b3f07f09

+ 22 - 4
app/Http/Controllers/PracticeManagementController.php

@@ -732,22 +732,40 @@ class PracticeManagementController extends Controller
     public function supplyOrdersReadyToShip(Request $request)
     {
         $counts = $this->getSupplyOrderCounts();
-        $supplyOrders = SupplyOrder::where('is_cleared_for_shipment', true)->where('is_cancelled', false)->whereNull('shipment_id')->orderBy('created_at', 'ASC')->paginate();
+        $supplyOrders = SupplyOrder
+            ::where('is_cleared_for_shipment', true)
+            ->where('is_cancelled', false)
+            ->whereNull('shipment_id')
+            ->orderBy('client_id', 'ASC')
+            ->orderBy('mailing_address_full', 'ASC')
+            ->orderBy('created_at', 'ASC')
+            ->paginate();
         return view('app.practice-management.supply-orders-ready-to-ship', compact('supplyOrders', 'counts'));
     }
 
     public function supplyOrdersShipmentUnderway(Request $request)
     {
         $counts = $this->getSupplyOrderCounts();
-        $supplyOrders = SupplyOrder::where('is_cancelled', false)->whereNotNull('shipment_id')->orderBy('created_at', 'ASC')->paginate();
+        $supplyOrders = SupplyOrder
+            ::where('is_cancelled', false)
+            ->whereNotNull('shipment_id')
+            ->orderBy('client_id', 'ASC')
+            ->orderBy('mailing_address_full', 'ASC')
+            ->orderBy('created_at', 'ASC')
+            ->paginate();
         return view('app.practice-management.supply-orders-shipment-underway', compact('supplyOrders', 'counts'));
     }
 
     private function getSupplyOrderCounts() {
         return [
             "supplyOrders" => SupplyOrder::count(),
-            "supplyOrdersReadyToShip" => SupplyOrder::where('is_cleared_for_shipment', true)->where('is_cancelled', false)->whereNull('shipment_id')->count(),
-            "supplyOrdersShipmentUnderway" => SupplyOrder::where('is_cancelled', false)->whereNotNull('shipment_id')->count()
+            "supplyOrdersReadyToShip" => SupplyOrder
+                ::where('is_cleared_for_shipment', true)
+                ->where('is_cancelled', false)
+                ->whereNull('shipment_id')->count(),
+            "supplyOrdersShipmentUnderway" => SupplyOrder
+                ::where('is_cancelled', false)
+                ->whereNotNull('shipment_id')->count()
         ];
     }
 

+ 5 - 0
public/css/style.css

@@ -1492,3 +1492,8 @@ canvas.pdf-viewer-page.pdf-preview-page {
 .filter-head select {
     padding: 0 5px;
 }
+tr.sep td {
+    padding: 0;
+    background: #eee;
+    height: 6px;
+}

+ 102 - 95
resources/views/app/practice-management/supply-orders-ready-to-ship.blade.php

@@ -2,7 +2,7 @@
 
 @section('content')
 
-    <div id="practice-supply-orders" class="p-3 mcp-theme-1">
+    <div id="practice-supply-orders-ready-to-ship" class="p-3 mcp-theme-1">
         <div class="card">
 
             <div class="card-header px-3 py-3 d-flex align-items-center bg-white">
@@ -16,87 +16,64 @@
 <!--                <a href="{{route('practice-management.supply-orders-ready-to-ship')}}" class="ml-auto">Clear Filters</a>-->
             </div>
             <div class="card-body p-0">
-                <table class="table table-sm table-condensed p-0 m-0">
+                <table class="table table-sm table-condensed p-0 m-0" style="table-layout: fixed">
                     <thead class="bg-light">
                     <tr>
-                        <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>
+<!--                        <th class="border-0">Date</th>-->
+                        <th class="border-0">Patient</th>
+                        <th class="border-0">Address</th>
+                        <th class="border-0">Item(s)</th>
+                        <th class="border-0">Actions</th>
                     </tr>
                     </thead>
                     <tbody>
+                    <?php
+                    $prevClientAndAddress = null;
+                    $shipmentIndex = 0;
+                    ?>
                     @foreach ($supplyOrders as $supplyOrder)
-                        <tr class="{{$supplyOrder->is_cancelled ? 'bg-light' : ''}}">
-                            <td>{{$supplyOrder->client->displayName()}}</a></td>
-                            <td>{{$supplyOrder->product->title}}</td>
-                            <td>{{$supplyOrder->reason}}</td>
-                            <td>{{$supplyOrder->client_understanding_memo}}</td>
-                            <td>
-                                @if($supplyOrder->is_signed_by_pro)
-                                    <b>Signed</b>
-                                    <div class="text-secondary text-sm mt-1">
-                                        By {{$supplyOrder->signedPro->displayName()}}<br>
-                                        {{friendlier_date_time($supplyOrder->pro_signed_at)}}
-                                    </div>
-                                @else
-                                    Not Signed
+                        <?php
+                        $currentClientAndAddress = implode('|', [$supplyOrder->client_id, $supplyOrder->mailing_address_full]);
+                        $sameClientAndAddress = false;
+                        ?>
+                        @if($currentClientAndAddress !== $prevClientAndAddress)
+                            <tr class="sep"><td colspan="4"></td></tr>
+                            <?php
+                            $shipmentIndex++;
+                            $prevClientAndAddress = $currentClientAndAddress;
+                            ?>
+                        @else
+                            <?php $sameClientAndAddress = true; ?>
+                        @endif
+                        <tr class="{{$supplyOrder->is_cancelled ? 'bg-light' : ''}}"
+                            data-client-uid="{{$supplyOrder->client->uid}}"
+                            data-address-line1="{{$supplyOrder->mailing_address_line1}}"
+                            data-address-line2="{{$supplyOrder->mailing_address_line2}}"
+                            data-address-city="{{$supplyOrder->mailing_address_city}}"
+                            data-address-state="{{$supplyOrder->mailing_address_state}}"
+                            data-address-zip="{{$supplyOrder->mailing_address_zip}}"
+                            data-shipment-index="{{$shipmentIndex}}"
+                            data-supply-order-uid="{{$supplyOrder->uid}}">
+<!--                            <td class="align-top border-top-0">{{friendlier_date_time($supplyOrder->created_at)}}</td>-->
+                            <td class="align-top border-top-0">
+                                @if(!$sameClientAndAddress)
+                                    {{$supplyOrder->client->displayName()}}
                                 @endif
                             </td>
-                            <td>
-                                @if($supplyOrder->is_signed_by_client)
-                                    <b>Signed</b>
-                                    <div class="text-secondary text-sm mt-1">
-                                        By {{$patient->displayName()}}<br>
-                                        On {{friendlier_date_time($supplyOrder->client_signed_at)}}
-                                    </div>
-                                @elseif($supplyOrder->is_client_signature_waived)
-                                    <b>Waived</b>
-                                    <div class="text-secondary text-sm mt-1">
-                                        By {{$supplyOrder->waiverPro->displayName()}}<br>
-                                        on {{friendlier_date_time($supplyOrder->client_signature_waived_at)}}
-                                    </div>
-                                @else
-                                    Not Signed
+                            <td class="align-top border-top-0">
+                                @if(!$sameClientAndAddress)
+                                    {!! $supplyOrder->mailing_address_full ? implode(" ", [$supplyOrder->mailing_address_line1 . ' ' . $supplyOrder->mailing_address_line2, $supplyOrder->mailing_address_city . ' ' . $supplyOrder->mailing_address_state . ' ' . $supplyOrder->mailing_address_zip]) : '-'  !!}
                                 @endif
                             </td>
-                            <td>
-                                @if($supplyOrder->shipment_id)
-                                    <i class="fa fa-building"></i>
-                                    {{$supplyOrder->shipment->status}}
-                                    @if($supplyOrder->shipment && $supplyOrder->shipment->status === 'DELIVERED' && $supplyOrder->shipment->delivered_date)
-                                        <div class="text-secondary text-sm mt-1">
-                                            on {{friendlier_date_time($supplyOrder->shipment->delivered_date)}}
-                                        </div>
-                                    @endif
-                                @elseif($supplyOrder->is_cleared_for_shipment)
-                                    <i class="fa fa-user-nurse"></i>
-                                    Cleared for shipment
-                                    <div class="text-secondary text-sm mt-1">
-                                        By {{$supplyOrder->clearedForShipmentPro->displayName()}}<br>
-                                        on {{friendlier_date_time($supplyOrder->cleared_for_shipment_at)}}
-                                    </div>
-                                @else
-                                    <i class="fa fa-user-nurse"></i>
-                                    Not cleared for shipment
-                                @endif
+                            <td class="align-top border-top-0">
+                                {{$supplyOrder->product->title}}
+                                <span class="text-secondary text-sm">(Created: {{friendlier_date_time($supplyOrder->created_at)}})</span>
                             </td>
-                            <td>{{$supplyOrder->lot_number}}</td>
-                            <td>{{$supplyOrder->imei}}</td>
-                            <td>
-                                {{friendlier_date_time($supplyOrder->created_at)}}
-                                <div class="text-secondary text-sm mt-1">
-                                    By {{$supplyOrder->createdSession->pro->displayName()}}
-                                </div>
+                            <td class="align-top border-top-0">
+                                @if(!$sameClientAndAddress)
+                                    <a href="#" id="generate-shipment">Generate Shipment</a>
+                                @endif
                             </td>
-                            <td>{!! $supplyOrder->is_cancelled ? '<b class="text-warning-mellow">Yes</b>' : 'No' !!}</td>
                         </tr>
                     @endforeach
                     </tbody>
@@ -111,38 +88,68 @@
     <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]));
-                    }
+            function hasError (_data) {
+                let msg = 'Unknown error!';
+                if (_data) {
+                    if (_data.success) return false;
+                    else if (_data.message) msg = _data.message;
                 }
-                queryLine = queryLine.join('&');
-
-                fastLoad('/practice-management/supply-orders?' + queryLine);
+                toastr.error(msg);
+                return true;
             }
 
             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;
-                        }
+                $(document)
+                    .off('click', '#generate-shipment')
+                    .on('click', '#generate-shipment', function() {
+                        let row = $(this).closest('tr');
+                        $.post('/api/shipment/create', {
+                            clientUid: row.attr('data-client-uid'),
+                            mailingAddressLine1: row.attr('data-address-line1'),
+                            mailingAddressLine2: row.attr('data-address-line2'),
+                            mailingAddressCity: row.attr('data-address-city'),
+                            mailingAddressState: row.attr('data-address-state'),
+                            mailingAddressZip: row.attr('data-address-zip'),
+                        }, (_data) => {
+                            if(!hasError(_data)) {
+                                let addToShipmentRequests = [],
+                                    shipmentIndex = row.attr('data-shipment-index'),
+                                    rows = $('tr[data-shipment-index="' + shipmentIndex + '"]'),
+                                    totalSupplyOrders = rows.length,
+                                    succeededSupplyOrders = 0;
+                                rows.each(function() {
+                                    let supplyOrderUid = $(this).attr('data-supply-order-uid');
+                                    addToShipmentRequests.push((function () {
+                                        return $.post('/api/supplyOrder/putInShipment', {
+                                            uid: supplyOrderUid,
+                                            shipmentUid: _data.data
+                                        }, (_data) => {
+                                            if(!hasError(_data)) {
+                                                succeededSupplyOrders++;
+                                            }
+                                        }, 'json');
+                                    })());
+                                });
+                                Promise.all(addToShipmentRequests).then(() => {
+                                    // all requests finished successfully
+                                    window.location.reload();
+                                }).catch(() => {
+                                    // all requests finished but one or more failed
+                                    alert(succeededSupplyOrders + ' supply requests added to shipment. ' +
+                                        (totalSupplyOrders - succeededSupplyOrders) + ' could not be added to shipment'
+                                    );
+                                    window.location.reload();
+                                })
+                            }
+                        }, 'json');
+
+                        // 1. create shipment
+                            // 2. put each supply-order in shipment
+                                // 3 . reload once all done
                     });
             }
 
-            addMCInitializer('practice-supply-orders', init, '#practice-supply-orders')
+            addMCInitializer('practice-supply-orders-ready-to-ship', init, '#practice-supply-orders-ready-to-ship')
 
         }).call(window);
     </script>

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

@@ -124,7 +124,7 @@
                 <tbody>
                 @foreach ($supplyOrders as $supplyOrder)
                     <tr class="{{$supplyOrder->is_cancelled ? 'bg-light' : ''}}">
-                        <td>{{$supplyOrder->client->displayName()}}</a></td>
+                        <td>{{$supplyOrder->client->displayName()}}</td>
                         <td>{{$supplyOrder->product->title}}</td>
                         <td>{{$supplyOrder->reason}}</td>
                         <td>{{$supplyOrder->client_understanding_memo}}</td>