]);
}
- public function actionWeeklyBouquetProductsForecast()
+ public function actionWeeklyBouquetProductsForecast($storeId, $month, $year, $week)
{
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
- $request = Yii::$app->request;
- $storeIdRequest = $request->get('storeId');
- $monthRequest = $request->get('month');
- $yearRequest = $request->get('year');
- $weekRequest = $request->get('week');
-
- if (!$monthRequest || !$yearRequest || $weekRequest === null) {
+ if (!$month || !$year || $week === null) {
return ['success' => false, 'message' => 'Нет параметров'];
}
$service = new AutoPlannogrammaService();
- $result = $service->getWeeklyBouquetProductsForecast($monthRequest, $yearRequest, $storeIdRequest);
+ $result = $service->getWeeklyBouquetProductsForecast($month, $year, $storeId);
if (!is_array($result)) {
return ['success' => false, 'message' => 'Ошибка структуры данных'];
}
- if ($weekRequest !== null) {
- $week = (int)$weekRequest;
+ if ($week !== null) {
+ $week = (int)$week;
$grouped = isset($grouped[$week]) ? [$week => $grouped[$week]] : [];
}
'success' => true,
'data' => $grouped,
];
-
-
}
public function actionGetSubcategories(string $category, int $year, int $week): array
const isVisible = $(`table tbody tr:first td:eq(${index})`).is(':visible');
if (!isVisible) return;
- const val = valuesMap[storeId] || { quantity: '', id: '' };
+ const val = valuesMap[storeId] || {quantity: '', id: ''};
const td = $(`
<td data-store-id="${storeId}">
const year = $('#year').val();
const week = $('#week').val();
$('.loader-overlay').removeClass('d-none');
- $.get('/auto-plannogramma/get-subcategories', { category, year, week }, function (subcategories) {
+ $.get('/auto-plannogramma/get-subcategories', {category, year, week}, function (subcategories) {
const subMap = {};
subcategories.forEach(sub => {
subMap[sub.name] = sub.hasdata;
});
}
+$(document).on('click', '.input', function () {
+ const $el = $(this);
+
+ if ($el.data('tooltip-loaded')) return;
+
+ const storeId = $el.data('store_id');
+ const year = $('#year').val();
+ const week = $('#week').val();
+ const month = getMonthByWeek(week, year, true);
+
+ const data = {
+ storeId: storeId,
+ year: year,
+ week: week,
+ month: month
+ };
+
+ $.get('/auto-plannogramma/weekly-bouquet-products-forecast', data, (response) => {
+ const titleText = typeof response === 'object' ? JSON.stringify(response) : response;
+ $el.attr('title', titleText).data('tooltip-loaded', true);
+
+ if ($el.tooltip) {
+ $el.tooltip('dispose').tooltip();
+ }
+ });
+});
+
$('.btn-save').on('click', function () {
const changedValues = [];
let hasErrors = false;
});
$('.btn-reset').on('click', resetStoreFilter);
-function getMonthByWeek(week, year) {
- if (!(week) || !(year)) {
+function getMonthByWeek(week, year, returnNumber = false) {
+ 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 months = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'];
- const startMonth = months[start.getMonth()];
- const endMonth = months[end.getMonth()];
-
- return startMonth === endMonth ? startMonth : `${startMonth} - ${endMonth}`;
+ if (returnNumber) {
+ const startMonthNum = start.getMonth() + 1; // от 1 до 12
+ const endMonthNum = end.getMonth() + 1;
+ return startMonthNum === endMonthNum ? startMonthNum : `${startMonthNum}-${endMonthNum}`;
+ } else {
+ const months = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'];
+ const startMonth = months[start.getMonth()];
+ const endMonth = months[end.getMonth()];
+ return startMonth === endMonth ? startMonth : `${startMonth} - ${endMonth}`;
+ }
}
function getMonthNumberByWeek(week, year) {