From: marina Date: Mon, 9 Jun 2025 21:27:30 +0000 (+0300) Subject: ERP-360 Сборка страницы автопм X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=e155c0219c97691e827ae0cc6b6ef6f03dfaf67d;p=erp24_rep%2Fyii-erp24%2F.git ERP-360 Сборка страницы автопм --- 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();