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

Supply-orders and shipments (wip)

Vijayakrishnan преди 4 години
родител
ревизия
d8e4186d28
променени са 4 файла, в които са добавени 185 реда и са изтрити 26 реда
  1. 4 0
      app/Models/Shipment.php
  2. 10 0
      app/Models/SystemFile.php
  3. 142 26
      public/js/yemi.js
  4. 29 0
      resources/views/app/patient/shipments.blade.php

+ 4 - 0
app/Models/Shipment.php

@@ -11,4 +11,8 @@ class Shipment extends Model
     public function supplyOrders() {
         return $this->hasMany(SupplyOrder::class, 'shipment_id', 'id');
     }
+
+    public function labelFile() {
+        return $this->hasOne(SystemFile::class, 'id', 'label_system_file_id');
+    }
 }

+ 10 - 0
app/Models/SystemFile.php

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

+ 142 - 26
public/js/yemi.js

@@ -124,6 +124,67 @@ var doAjax = function (url, data, pre, post, onSuccess, onFailure, suppressError
         });
 };
 
+var doAjaxFormData = function (url, data, pre, post, onSuccess, onFailure, suppressErrorMessage, onHttpFailure, shouldHideMask, immediatelyHideMaskOnReply) {
+    console.log(data);
+    if (ajaxGoing) {
+        console.log('ajax stopped!');
+        //return; TODO: fix and re-enable return
+    }
+    ajaxGoing = true;
+    if (!shouldHideMask) {
+        showMask();
+    }
+    jQuery.ajax(url, {
+        dataType: 'json',
+        data: data,
+        processData: false,
+        contentType: false,
+        type: 'POST',
+        beforeSend: function () {
+            if (pre) {
+                pre();
+            }
+        }
+    })
+        .done(function (response, b) {
+            console.log(response);
+            var success = response.success;
+            if (success) {
+                if (onSuccess) {
+                    onSuccess(response.data);
+                }
+            } else {
+                if (onFailure) {
+                    onFailure(response.message);
+                }
+                if (!suppressErrorMessage) {
+                    //toast the error message
+                    //alert(response.message);
+                    toastr.error(response.message); // , toastr.success("message") ... .warning(), .error()
+                }
+                hideMask();
+            }
+            if (immediatelyHideMaskOnReply) {
+                hideMask();
+            }
+            ajaxGoing = false;
+        })
+        .fail(function (jqXHR, textStatus) {
+            hideMask();
+            toastr.error('Unable to process');
+            if (onHttpFailure) {
+                onHttpFailure(textStatus);
+            }
+            ajaxGoing = false;
+        })
+        .always(function () {
+            if (post) {
+                post();
+            }
+            ajaxGoing = false;
+        });
+};
+
 var justLog = false; //THIS IS FOR TEST MODE, FORMS WILL NOT TRIGGER REFRESH/REDIR
 
 var pageReload = function () {
@@ -420,36 +481,91 @@ var initMoes = function() {
                 });
                 console.log(data);
                 //var doAjax = function (url, data, pre, post, onSuccess, onFailure, suppressErrorMessage, onHttpFailure, shouldHideMask, immediatelyHideMaskOnReply)
-                doAjax(url, data, null, function () {
-                    moe.isProcessing = false;
-                }, function (data) {
-                    if (justLog) { // this is to test!
-                        console.log('RETURNED', data);
-                    } else if (redir) {
-                        if (redir == "back") {
-                            window.top.history.back();
+
+                // override with FormData if the form has any files
+                let useFormData = false;
+                if($(form).find('input[type="file"]').length) {
+                    let formData = new FormData();
+                    for(let x in data) {
+                        if(data.hasOwnProperty(x)) {
+                            formData.set(x, data[x]);
+                        }
+                    }
+                    $(form).find('input[type="file"]').each(function() {
+                        let fieldName = this.name;
+                        if(this.files && this.files.length) {
+                            formData.append(fieldName, this.files[0]);
+                        }
+                    });
+                    data = formData;
+                    useFormData = true;
+                }
+
+                if(!useFormData) {
+                    doAjax(url, data, null, function () {
+                        moe.isProcessing = false;
+                    }, function (data) {
+                        if (justLog) { // this is to test!
+                            console.log('RETURNED', data);
+                        } else if (redir) {
+                            if (redir == "back") {
+                                window.top.history.back();
+                            } else {
+                                if (redir.indexOf('[data]') > -1) {
+                                    redir = redir.replace('[data]', data);
+                                }
+                                fastLoad(redir, true, false);
+                            }
+                        } else if (moeParent.length) {
+                            showMask();
+                            $.get(moeParent.attr('url'), function (_data) {
+                                moeParent.html(_data);
+                                hideMask();
+                                hideMoeFormMask();
+                                initMoes();
+                                initFastLoad(moeParent);
+                                initAutoRxAndICDComplete();
+                            });
                         } else {
-                            if (redir.indexOf('[data]') > -1) {
-                                redir = redir.replace('[data]', data);
+                            pageReload();
+                        }
+                    }, function (errorMessage) {
+
+                    }, false);
+                }
+                else {
+                    doAjaxFormData(url, data, null, function () {
+                        moe.isProcessing = false;
+                    }, function (data) {
+                        if (justLog) { // this is to test!
+                            console.log('RETURNED', data);
+                        } else if (redir) {
+                            if (redir == "back") {
+                                window.top.history.back();
+                            } else {
+                                if (redir.indexOf('[data]') > -1) {
+                                    redir = redir.replace('[data]', data);
+                                }
+                                fastLoad(redir, true, false);
                             }
-                            fastLoad(redir, true, false);
+                        } else if (moeParent.length) {
+                            showMask();
+                            $.get(moeParent.attr('url'), function (_data) {
+                                moeParent.html(_data);
+                                hideMask();
+                                hideMoeFormMask();
+                                initMoes();
+                                initFastLoad(moeParent);
+                                initAutoRxAndICDComplete();
+                            });
+                        } else {
+                            pageReload();
                         }
-                    } else if (moeParent.length) {
-                        showMask();
-                        $.get(moeParent.attr('url'), function (_data) {
-                            moeParent.html(_data);
-                            hideMask();
-                            hideMoeFormMask();
-                            initMoes();
-                            initFastLoad(moeParent);
-                            initAutoRxAndICDComplete();
-                        });
-                    } else {
-                        pageReload();
-                    }
-                }, function (errorMessage) {
+                    }, function (errorMessage) {
+
+                    }, false);
+                }
 
-                }, false);
             }
         });
 

+ 29 - 0
resources/views/app/patient/shipments.blade.php

@@ -297,6 +297,35 @@
                         </div>
                     </div>
 
+                    <div class="mb-2 d-flex align-items-baseline">
+                        <label class="text-secondary text-sm mb-0 width-90px mr-2">Label File</label>
+                        @if($shipment->label_system_file_id)
+                            <a class="pdf-viewer-trigger" native target="_blank"
+                               href="/api/shipment/downloadLabel/{{ $shipment->uid }}"
+                               title="View">
+                                <i class="fa fa-file-pdf text-danger on-hover-opaque"></i>
+                                View
+                                {{--{{ $shipment->labelFile->file_name }}--}}
+                            </a>
+                            <span class="mx-2 text-secondary">|</span>
+                        @endif
+                        <div moe bottom relative class="d-block">
+                            <a start show>Upload</a>
+                            <form url="/api/shipment/setLabelSystemFile">
+                                <input type="hidden" name="uid" value="{{ $shipment->uid }}">
+                                <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="labelSystemFile">
+                                </div>
+                                <div class="d-flex align-items-center">
+                                    <button class="btn btn-sm btn-primary mr-2" submit>Upload</button>
+                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
+                                </div>
+                            </form>
+                        </div>
+                    </div>
+
                     <div class="mb-2 d-flex align-items-baseline">
                         <label class="text-secondary text-sm mb-0 width-90px mr-2">Tracking #</label>
                         <div moe bottom relative class="d-block">