Răsfoiți Sursa

Integrate supplyOrder/bulkPutInShipment

Vijayakrishnan 4 ani în urmă
părinte
comite
0ad25d09b6

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

@@ -39,8 +39,8 @@
                     @foreach ($supplyOrders as $supplyOrder)
                         <?php
                             $patient = $supplyOrder->client;
-                        $currentClientAndAddress = implode('|', [$supplyOrder->client_id, $supplyOrder->mailing_address_full]);
-                        $sameClientAndAddress = false;
+                            $currentClientAndAddress = implode('|', [$supplyOrder->client_id, $supplyOrder->mailing_address_full]);
+                            $sameClientAndAddress = false;
                         ?>
                         @if($currentClientAndAddress !== $prevClientAndAddress)
                             <tr class="sep"><td colspan="4"></td></tr>
@@ -144,40 +144,23 @@
                             mailingAddressZip: row.attr('data-address-zip'),
                         }, (_data) => {
                             if(!hasError(_data)) {
-                                let addToShipmentRequests = [],
-                                    shipmentIndex = row.attr('data-shipment-index'),
+                                let shipmentIndex = row.attr('data-shipment-index'),
                                     rows = $('tr[data-shipment-index="' + shipmentIndex + '"]'),
-                                    totalSupplyOrders = rows.length,
-                                    succeededSupplyOrders = 0;
+                                    rowUids = [];
                                 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');
-                                    })());
+                                    rowUids.push($(this).attr('data-supply-order-uid'));
                                 });
-                                Promise.all(addToShipmentRequests).then(() => {
-                                    // all requests finished successfully
-                                    fastReload();
-                                }).catch(() => {
-                                    // all requests finished but one or more failed
-                                    alert(succeededSupplyOrders + ' supply requests added to shipment. ' +
-                                        (totalSupplyOrders - succeededSupplyOrders) + ' could not be added to shipment'
-                                    );
-                                    fastReload();
-                                })
+                                rowUids = rowUids.join('|');
+                                return $.post('/api/supplyOrder/bulkPutInShipment', {
+                                    supplyOrderUids: rowUids,
+                                    shipmentUid: _data.data
+                                }, (_data) => {
+                                    if(!hasError(_data)) {
+                                        fastReload();
+                                    }
+                                }, 'json');
                             }
                         }, 'json');
-
-                        // 1. create shipment
-                            // 2. put each supply-order in shipment
-                                // 3 . reload once all done
                     });
             }