]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-360 Сборка страницы автопм
authormarina <m.zozirova@gmail.com>
Mon, 9 Jun 2025 21:27:30 +0000 (00:27 +0300)
committermarina <m.zozirova@gmail.com>
Mon, 9 Jun 2025 21:27:30 +0000 (00:27 +0300)
erp24/controllers/AutoPlannogrammaController.php
erp24/web/js/autoplannogramma/autoplannogramma.js

index af22e1351008d8786a59955da9003e10a3d88611..aa6acaafde7e0f272efe4229aadc35da56819e78 100644 (file)
@@ -168,7 +168,6 @@ class AutoPlannogrammaController extends BaseController
                 if ($model !== null) {
                     $model->quantity = $item['value'];
                     $model->auto_forecast = false;
-                    $model->save(false);
                 }
             } else {
                 $model = new Autoplannogramma();
@@ -180,7 +179,12 @@ class AutoPlannogrammaController extends BaseController
                 $model->quantity = $item['value'];
                 $model->quantity_forecast = 0;
                 $model->auto_forecast = false;
-                $model->save(false);
+            }
+
+            if ($model->validate()) {
+                $model->save();
+            } else {
+                return ['success' => false, 'message' => $model->getErrors()];
             }
         }
 
index bbd0512d7a3047cb4a5787eee72b1189b527fa59..b210824725a3fc7e020dbe84bbeff27d621e3e63 100644 (file)
@@ -214,8 +214,8 @@ $('.btn-save').on('click', function () {
             const product_id = $input.data('guid');
             const store_id = $input.data('store_id');
             const year = $('#year').val();
-            const month = $('.month-label').val();
             const week = $('#week').val();
+            const month = getMonthNumberByWeek(week, year);
             if (!product_id || !store_id || !year || !week) {
                 alert('Для новых записей обязательны: product_id, store_id, year, week.');
                 hasErrors = true;
@@ -300,6 +300,22 @@ function getMonthByWeek(week, year) {
     return startMonth === endMonth ? startMonth : `${startMonth} - ${endMonth}`;
 }
 
+function getMonthNumberByWeek(week, year) {
+    if (!(week) || !(year)) {
+        return;
+    }
+    const start = new Date(year, 0, 4 + (week - 1) * 7 - (new Date(year, 0, 4).getDay() || 7) + 1);
+    const end = new Date(start.getTime() + 6 * 24 * 60 * 60 * 1000);
+    const startMonth = start.getMonth() + 1;
+    const endMonth = end.getMonth() + 1;
+
+    if (startMonth === endMonth) {
+        return startMonth;
+    }
+    return startMonth;
+}
+
+
 $(document).ready(function () {
     if ($('#week').val().length > 0) {
         $('#edit-button').click();