if ($model !== null) {
$model->quantity = $item['value'];
$model->auto_forecast = false;
- $model->save(false);
}
} else {
$model = new Autoplannogramma();
$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()];
}
}
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;
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();