]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-242] числа с продуктами
authorAlexander Smirnov <fredeom@mail.ru>
Tue, 3 Dec 2024 14:03:54 +0000 (17:03 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Tue, 3 Dec 2024 14:03:54 +0000 (17:03 +0300)
erp24/controllers/ShiftTransferController.php
erp24/views/shift-transfer/update.php
erp24/web/js/shift-transfer/update.js

index 0617d72eafa66baa31c7279e64a94a8867839bda..e9fc994af079e2608f8b078d6ad807c697ff1eca 100644 (file)
@@ -156,6 +156,21 @@ class ShiftTransferController extends Controller
         return ['groupLabel' => $productClass->tip ?? 'other_items', 'price' => $price->price ?? 0, 'selfCost' => $selfCost->price ?? 0, 'quantity' => $balance->quantity ?? 0];
     }
 
+    public function actionGetProductsWithRemains() {
+        Yii::$app->response->format = Response::FORMAT_JSON;
+        $storeGuid = Yii::$app->request->post('storeGuid');
+        $balance = ArrayHelper::map(Balances::find()->select(['quantity', 'product_id'])->where(['store_id' => $storeGuid])->all(), 'product_id', 'quantity');
+        $products = ArrayHelper::map(Products1c::find()->select(['id', 'name'])
+            ->where(['tip' => 'products'])->orderBy(['name' => SORT_ASC])->all(), 'id', 'name');
+        $result = [];
+        foreach ($products as $key => $name) {
+            if (isset($balance[$key])) {
+                $result[$key] = $name . ' - ' . $balance[$key];
+            }
+        }
+        return $result;
+    }
+
     public function actionView($id)
     {
         if (Yii::$app->request->post()) {
index ffed0866454bfc928acbf21e65fb1d68dfb25c16..b1f0aecc59c9546d845055fc58ab76984bf32333 100644 (file)
@@ -48,7 +48,7 @@ $this->registerCss('
 
     <div class="row">
         <div class="col-6">
-            <?= $form->field($shiftTransfer, 'store_guid')->dropDownList($storeNameById) ?>
+            <?= $form->field($shiftTransfer, 'store_guid')->dropDownList($storeNameById, ['onchange' => 'updateProductsWithBalanceAll();']) ?>
         </div>
     </div>
     <div class="row">
index e50d2c82f64baf0a2a26c04aa8b723bc44ac754e..aea5b7e09674a7a8d715024324cfea7b39c8774b 100644 (file)
@@ -4,6 +4,35 @@
 const param24 = $('meta[name=csrf-param]').attr('content');
 const token24 = $('meta[name=csrf-token]').attr('content');
 
+function updateProductsWithBalance(currentIndex, row) {
+    const store = $('#shifttransfer-store_guid');
+    const productGuid = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-product_guid');
+    productGuid.empty();
+    $.ajax({
+        type: 'POST',
+        url: '/shift-transfer/get-products-with-remains',
+        data: { storeGuid: store.val(), [param24]: token24 },
+        dataType: 'json',
+        success: (data) => {
+            console.log(data);
+            $.each(data, (key, el) => {
+                console.log(key, el)
+                const opt = document.createElement('option');
+                opt.text = el;
+                opt.value = key;
+                productGuid.append(opt);
+            })
+        }
+    });
+}
+
+function updateProductsWithBalanceAll() {
+    const rows = $('.multiple-input-list__item');
+    for (let currentIndex = 0; currentIndex < rows.length; currentIndex++) {
+        updateProductsWithBalance(currentIndex + 1, rows[currentIndex]);
+    }
+}
+
 function checkInputRow(currentIndex, row, errorContainer) {
     const productGuid = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-product_guid');
     const productName = $(row).find('#select2-shifttransfer-shiftremainscopy-' + currentIndex + '-product_guid-container').text();
@@ -43,6 +72,7 @@ function checkInputs() {
 }
 
 function setMultipleInputHandlers(currentIndex, row) {
+    updateProductsWithBalance(currentIndex, row);
     const store = $('#shifttransfer-store_guid');
     const groupLabel = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-group_label');
     const productGuid = $(row).find('#shifttransfer-shiftremainscopy-' + currentIndex + '-product_guid');