From e155c0219c97691e827ae0cc6b6ef6f03dfaf67d Mon Sep 17 00:00:00 2001 From: marina Date: Tue, 10 Jun 2025 00:27:30 +0300 Subject: [PATCH] =?utf8?q?ERP-360=20=D0=A1=D0=B1=D0=BE=D1=80=D0=BA=D0=B0?= =?utf8?q?=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=8B=20=D0=B0?= =?utf8?q?=D0=B2=D1=82=D0=BE=D0=BF=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../controllers/AutoPlannogrammaController.php | 8 ++++++-- .../js/autoplannogramma/autoplannogramma.js | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index af22e135..aa6acaaf 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -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()]; } } diff --git a/erp24/web/js/autoplannogramma/autoplannogramma.js b/erp24/web/js/autoplannogramma/autoplannogramma.js index bbd0512d..b2108247 100644 --- a/erp24/web/js/autoplannogramma/autoplannogramma.js +++ b/erp24/web/js/autoplannogramma/autoplannogramma.js @@ -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(); -- 2.39.5