ソースを参照

Shipment packs (wip)

Vijayakrishnan 4 年 前
コミット
fc700ab47e

+ 24 - 0
app/Models/Pack.php

@@ -0,0 +1,24 @@
+<?php
+
+namespace App\Models;
+
+# use Illuminate\Database\Eloquent\Model;
+
+class Pack extends Model
+{
+    protected $table = 'pack';
+
+    public function client()
+    {
+        return $this->hasOne(Client::class, 'id', 'client_id');
+    }
+
+    public function shipment()
+    {
+        return $this->hasOne(Shipment::class, 'id', 'shipment_id');
+    }
+
+    public function supplyOrders() {
+        return $this->hasMany(SupplyOrder::class, 'pack_id', 'id');
+    }
+}

+ 8 - 0
app/Models/Shipment.php

@@ -25,4 +25,12 @@ class Shipment extends Model
     {
         return $this->hasOne(AppSession::class, 'id', 'created_by_session_id');
     }
+
+    public function packs() {
+        return $this->hasMany(Pack::class, 'shipment_id', 'id');
+    }
+
+    public function supplyOrdersNotInPack() {
+        return $this->supplyOrders()->whereNull('pack_id');
+    }
 }

+ 134 - 0
resources/views/app/patient/partials/packs.blade.php

@@ -0,0 +1,134 @@
+<div class="d-flex align-items-center mb-2" id="shipment-packs-identifier">
+    <label class="m-0 font-weight-bold text-secondary">Packages</label>
+    <span class="mx-2 text-secondary">|</span>
+    <div moe bottom relative class="d-block">
+        <a start show>+ Add</a>
+        <form url="/api/pack/create">
+            <input type="hidden" name="shipmentUid" value="{{ $shipment->uid }}">
+            <div class="mb-2">
+                <label class="text-secondary mb-1 text-sm">Ship Date</label>
+                <input type="date" class="form-control form-control-sm"
+                       name="shipDate" value="">
+            </div>
+            <div class="mb-2">
+                <label class="text-secondary mb-1 text-sm">Courier</label>
+                <input type="text" class="form-control form-control-sm"
+                       name="courier" value="">
+            </div>
+            <div class="mb-2">
+                <label class="text-secondary mb-1 text-sm">Label File</label>
+                <input type="file" class="form-control form-control-sm"
+                       name="label" value="">
+            </div>
+            <div class="mb-2">
+                <label class="text-secondary mb-1 text-sm">Tracking Number</label>
+                <input type="text" class="form-control form-control-sm"
+                       name="trackingNumber" value="">
+            </div>
+            <div class="d-flex align-items-center">
+                <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
+                <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
+            </div>
+        </form>
+    </div>
+</div>
+
+<?php $packNumber = 0; ?>
+@if($shipment->packs && count($shipment->packs))
+    <table class="table table-sm table-striped table-bordered bg-white">
+        <thead>
+        <tr class="">
+            <th class="px-2 text-nowrap text-secondary border-bottom-0">#</th>
+            <th class="px-2 text-nowrap text-secondary border-bottom-0">Items</th>
+            <th class="px-2 text-nowrap text-secondary border-bottom-0">Label</th>
+            <th class="px-2 text-nowrap text-secondary border-bottom-0">Courier</th>
+            <th class="px-2 text-nowrap text-secondary border-bottom-0">Tracking #</th>
+            <th class="px-2 text-nowrap text-secondary border-bottom-0">Status</th>
+            <th class="px-2 text-nowrap text-secondary border-bottom-0">&nbsp;</th>
+        </tr>
+        </thead>
+        <tbody>
+        @foreach($shipment->packs as $pack)
+            <?php $packNumber++; ?>
+            @if($pack->status !== 'DELETED')
+                <tr class="">
+                    <td class="px-2">
+                        {{$packNumber}}
+                    </td>
+                    <td class="px-2">
+                        @foreach($pack->supplyOrders as $packSO)
+                            <div class="d-flex align-items-baseline mb-1">
+                                <span class="text-sm">{{$packSO->product->title}}</span>
+                                <div moe relative class="ml-2">
+                                    <a start show class="py-0 text-danger"><i class="fa fa-times-circle text-danger"></i></a>
+                                    <form url="/api/supplyOrder/removeFromPack" right>
+                                        <input type="hidden" name="uid" value="{{ $packSO->uid }}">
+                                        <p class="small">Remove this product from this package?</p>
+                                        <div class="d-flex align-items-center">
+                                            <button class="btn btn-sm btn-primary mr-2" submit>Submit</button>
+                                            <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
+                                        </div>
+                                    </form>
+                                </div>
+                            </div>
+                        @endforeach
+                        <?php $soNotInPack = $shipment->supplyOrdersNotInPack()->get();?>
+                        @if($soNotInPack && count($soNotInPack))
+                            <div>
+                                <select class="form-control form-control-sm add-product-to-pack shadow-none"
+                                        data-pack-uid="{{$pack->uid}}">
+                                    <option value="" selected>(add product)</option>
+                                    @foreach($soNotInPack as $soNotInPackItem)
+                                        <option value="{{$soNotInPackItem->uid}}">{{$soNotInPackItem->product->title}}</option>
+                                    @endforeach
+                                </select>
+                            </div>
+                        @endif
+                    </td>
+                    <td class="px-2">
+                        {{$pack->label_system_file_id}}
+                    </td>
+                    <td class="px-2">
+                        {{$pack->courier}}
+                    </td>
+                    <td class="px-2">
+                        {{$pack->tracking_number}}
+                    </td>
+                    <td class="px-2">
+                        {{$pack->status}}
+                    </td>
+                    <td class="px-2">
+                        <div moe relative>
+                            <a start show class="py-0 text-danger"><i class="fa fa-times-circle text-danger"></i></a>
+                            <form url="/api/pack/updateStatus" right>
+                                <input type="hidden" name="uid" value="{{ $pack->uid }}">
+                                <p class="small">Remove this package?</p>
+                                <div class="d-flex align-items-center">
+                                    <button class="btn btn-sm btn-primary mr-2" submit>Submit</button>
+                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
+                                </div>
+                            </form>
+                        </div>
+                    </td>
+                </tr>
+            @endif
+        @endforeach
+        </tbody>
+    </table>
+@endif
+
+<script>
+    (function() {
+        function init() {
+            $('.add-product-to-pack').on('change', function() {
+                $.post('/api/supplyOrder/putInPack', {
+                    uid: $(this).val(),
+                    packUid: $(this).attr('data-pack-uid'),
+                }, () => {
+                    fastReload();
+                });
+            });
+        }
+        addMCInitializer('shipment-packs', init, '#shipment-packs-identifier');
+    }).call(window);
+</script>

+ 13 - 10
resources/views/app/patient/shipments.blade.php

@@ -82,9 +82,6 @@
                     <tr class="bg-light">
                         <th class="px-2 text-nowrap text-secondary border-bottom-0"><div class="text-ellipsis">Created At</div></th>
                         <th class="px-2 text-nowrap text-secondary border-bottom-0"><div class="text-ellipsis">Supply Orders</div></th>
-                        <th class="px-2 text-nowrap text-secondary border-bottom-0"><div class="text-ellipsis">Label File</div></th>
-                        <th class="px-2 text-nowrap text-secondary border-bottom-0"><div class="text-ellipsis">Courier</div></th>
-                        <th class="px-2 text-nowrap text-secondary border-bottom-0"><div class="text-ellipsis">Tracking #</div></th>
                         <th class="px-2 text-nowrap text-secondary border-bottom-0"><div class="text-ellipsis">Status</div></th>
                     </tr>
                     </thead>
@@ -97,7 +94,7 @@
                                 </a>
                             </td>
                             <td class="px-2">{{count($iShipment->supplyOrders)}}</td>
-                            <td class="px-2">
+<!--                            <td class="px-2">
                                 @if($iShipment->label_system_file_id)
                                     <a class="pdf-viewer-trigger" native="" target="_blank"
                                        href="/api/shipment/downloadLabel/{{$iShipment->uid}}" title="View">
@@ -107,7 +104,7 @@
                                 @endif
                             </td>
                             <td class="px-2">{{ $iShipment->courier }}</td>
-                            <td class="px-2">{{ $iShipment->tracking_number }}</td>
+                            <td class="px-2">{{ $iShipment->tracking_number }}</td>-->
                             <td class="px-2">{{ $iShipment->status }}</td>
                         </tr>
                     @endforeach
@@ -124,9 +121,9 @@
             </div>
 
             @if($shipment)
-                <div class="min-width-500px ml-2 border align-self-stretch p-3">
+                <div class="min-width-700px ml-2 border align-self-stretch p-3">
                     <div class="d-flex align-items-center mb-3">
-                        <h3 class="font-size-16 m-0">Shipment (created on {{ friendlier_date_time($shipment->created_at) }})</h3>
+                        <h3 class="font-size-16 m-0">Shipment (created on {{ friendlier_date_time($shipment->created_at) }}) #{{$shipment->id}}</h3>
                         <a class="ml-auto" href="{{route('patients.view.shipments', ['patient' => $patient])}}">
                             <i class="fa fa-times-circle on-hover-opaque"></i>
                         </a>
@@ -189,7 +186,7 @@
                         </div>
                     @endif
 
-                    <div class="mb-4">
+                    <div class="mb-3">
 <!--                        <label class="mb-2 font-weight-bold text-secondary">Supply Orders in this Shipment</label>-->
                         <table class="table table-sm table-striped table-bordered mb-0 bg-white">
                             @if($shipment->supplyOrders && count($shipment->supplyOrders))
@@ -204,7 +201,7 @@
                                 <tbody>
                                 @foreach($shipment->supplyOrders as $iSupplyOrder)
                                     <tr class="">
-                                        <td class="px-2">{{ $iSupplyOrder->product->title }}</td>
+                                        <td class="px-2">{{ $iSupplyOrder->product->title }} {{$iSupplyOrder->pack_id ? $iSupplyOrder->pack_id : '(boo)'}}</td>
                                         <td class="px-2">
                                             <div moe relative class="d-block">
                                                 <a start show>{{ $iSupplyOrder->imei ? $iSupplyOrder->imei : '(not set)' }}</a>
@@ -269,6 +266,9 @@
                         </table>
                     </div>
 
+                    @include('app.patient.partials.packs')
+
+{{--
                     <div class="mb-2 d-flex align-items-baseline">
                         <label class="text-secondary text-sm mb-0 width-90px mr-2">Ship Date</label>
                         <div moe bottom relative class="d-block">
@@ -315,7 +315,9 @@
                                title="View">
                                 <i class="fa fa-file-pdf text-danger on-hover-opaque"></i>
                                 View
-                                {{--{{ $shipment->labelFile->file_name }}--}}
+                                --}}
+{{--{{ $shipment->labelFile->file_name }}--}}{{--
+
                             </a>
                             <span class="mx-2 text-secondary">|</span>
                         @endif
@@ -354,6 +356,7 @@
                             </form>
                         </div>
                     </div>
+--}}
 
                     <div class="mb-2 d-flex align-items-baseline">
                         <label class="text-secondary text-sm mb-0 width-90px mr-2">Status</label>