]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Добавление интервалов
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 11 Sep 2025 09:14:47 +0000 (12:14 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 11 Sep 2025 09:14:47 +0000 (12:14 +0300)
erp24/controllers/MatrixBouquetActualityController.php
erp24/views/matrix-bouquet-actuality/index.php
erp24/web/js/matrix-bouquet-actuality/index.js

index 413cb40c70a3d691efc0469e320846e0806d9543..f035d2a048e289fd03583943072a1a9b3f36f117 100644 (file)
@@ -262,6 +262,8 @@ class MatrixBouquetActualityController extends Controller
         ]);
     }
 
+
+
     private function getMatrixTypeDescendantsIds(int $rootId): array
     {
         $all = MatrixType::find()->select(['id','parent_id'])
index 8c355ccf65a477f6d82b110b0a0a562cf6579787..7e86cc85e4daf1ead2e19a3657e376a0ba0c62b5 100644 (file)
@@ -198,7 +198,9 @@ foreach ($subgroups as $sg) {
         'tableOptions' => ['class' => 'table table-bordered'],
         'containerOptions' => ['style' => 'overflow:auto;'],
         'rowOptions' => function($row) {
-            return $row['actuality'] ? ['class'=>'table-success'] : [];
+            $id = $row['product']->id ?? null;
+            $base = $row['actuality'] ? ['class' => 'table-success'] : [];
+            return $id ? array_merge($base, ['data-id' => $id]) : $base;
         },
         'columns' => [
             [
@@ -207,9 +209,19 @@ foreach ($subgroups as $sg) {
                 'contentOptions' => ['style'=>'min-width:150px;'],
                 'value' => function ($row, $key, $index) {
                     $product = $row['product'];
+                    $price = $row['price'] ?? null;
                     $name = Html::encode($product->name . ' (' . $product->guid . ')');
                     $anchor = Html::a($name, ['bouquet/view', 'id' => $product->id], ['target' => '_blank']);
-                    return '<div class="d-flex justify-content-between">' . $anchor . '</div>';
+                    $btn = Html::button('+ Добавить интервал', [
+                        'class' => 'btn btn-xs btn-outline-primary ms-2 add-actuality-row',
+                        'type' => 'button',
+                        'title' => 'Добавить интервал',
+                        'data-id' => $product->id,
+                        'data-guid' => $product->guid,
+                        'data-name' => $product->name,
+                        'data-price' => $price->price ?? null,
+                    ]);
+                    return '<div class="d-flex justify-content-between">' . $anchor . $btn . '</div>';
                 }
             ],
             [
index 6f259f87c7836fb28f2647b6c82b6521945f6db9..c0220c859a3687d7463f58c60c74a704992e511b 100644 (file)
@@ -8,6 +8,8 @@
     const monthsForNewRows = extendMonthsMap({ ...baseMonths }, 0);
     const monthsForExisting = baseMonths;
 
+
+
     let actualIdx = $('#actuality-form table tbody tr').length || 0;
     $('.from-month').each(function () {
         const hasActuality = $(this).data('actuality') == 1;
         });
     });
 
-    const inArchiveBtns    = document.getElementById('inArchiveBtn');
-    const outArchiveBtns  = document.getElementById('outArchiveBtn');
+    const onlyActive    = document.getElementById('onlyActiveCheckbox');
+    const onlyInactive  = document.getElementById('onlyInactiveCheckbox');
     if (onlyActive && onlyInactive) {
         onlyActive.addEventListener('change', () => { if (onlyActive.checked) { onlyInactive.checked = false; } });
         onlyInactive.addEventListener('change', () => { if (onlyInactive.checked) { onlyActive.checked = false; } });
         });
     });
 
+
+    $(document).on('click', '.add-actuality-row', function(){
+        const btn   = $(this);
+        const id  = btn.data('id');
+        const guid  = btn.data('guid');
+        const name  = btn.data('name');
+        const price  = btn.data('price');
+        const table = $('#actuality-form table');
+        // Все строки для этого товара
+        const $rows = table.find('tbody tr[data-id="'+ id +'"]');
+        const $lastRow = $rows.last();
+        actualIdx++;
+        console.log('add row', id, name);
+        const newRow = `
+            <tr class="table-info">
+                <td style="min-width:150px;">
+                    <div class="d-flex justify-content-between">${name} (${id}) <div class="text-danger mx-5">Новая запись. Заполните интервал</div></div>
+                </td>
+                <td style="text-align:center;">
+                    <div class="d-flex justify-content-between">${price}</div>
+                </td>
+                <td>
+                    <input type="hidden" name="actuality[${actualIdx}][guid]" value="${guid}">
+                    <input type="hidden" name="actuality[${actualIdx}][bouquet_id]" value="${id}">
+                    <div class="d-flex align-items-center">
+                        <select data-actuality="0" name="actuality[${actualIdx}][from]" class="form-select from-month form-select-sm me-1" style="width:auto;display:inline-block">
+                            <option value="">от</option>${monthOptions}
+                        </select>
+                        <select name="actuality[${actualIdx}][to]" class="form-select to-month form-select-sm" style="width:auto;display:inline-block">
+                            <option value="">до</option>${monthOptions}
+                        </select>
+                    </div>
+                </td>
+                <td style="width:60px;text-align:center;">
+                    
+                </td>
+                
+            </tr>
+        `;
+
+        let $inserted;
+        if ($lastRow.length) {
+            $lastRow.after(newRow);
+            $inserted = $lastRow.next();
+        } else {
+            table.find('tbody').append(newRow);
+            $inserted = table.find('tbody tr').last();
+        }
+        console.log(newRow);
+        applyFromMonthLimits($inserted.find('.from-month'), monthsForNewRows);
+        syncToWithFrom($inserted.find('.from-month'));
+    });
+
 })();
\ No newline at end of file