]);
}
- public function actionWeeklyBouquetProductsForecast($storeId, $month, $year, $week)
+ public function actionWeeklyBouquetProductsForecast()
{
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
+ $request = Yii::$app->request;
+ $storeId = $request->get('storeId', null);
+ $month = $request->get('month');
+ $year = $request->get('year');
+ $week = $request->get('week');
if (!$month || !$year || $week === null) {
return ['success' => false, 'message' => 'Нет параметров'];
}
$row.after(tr);
});
+ document.body.addEventListener("mouseover", (e) => {
+ if (!e.target.matches("input[data-guid][data-store_id][data-bs-toggle='tooltip']")) return;
+ console.log('mouseover');
+ const input = e.target;
+ const guid = input.dataset.guid;
+ const storeId = input.dataset.store_id;
+ const week = document.getElementById("week")?.value;
+ console.log('mouseover', guid);
+ if (!guid || !storeId || !week) return;
+
+ const html = buildForecastTooltip(23, storeId, guid);
+ console.log(html);
+ if (html) {
+ input.setAttribute("title", ""); // обязательно
+ input.setAttribute("data-bs-original-title", html);
+ input.setAttribute("aria-label", html);
+
+ bootstrap.Tooltip.getOrCreateInstance(input, { html: true }).show();
+ }
+ });
})
.fail(xhr => alert('Ошибка: ' + xhr.responseText))
.always(() => {
const data = {
storeId: storeId,
year: year,
- week: week,
- month: month
+ week: 23,
+ month: 8
};
$.get('/auto-plannogramma/weekly-bouquet-products-forecast', data, (response) => {
if ($el.tooltip) {
$el.tooltip('dispose').tooltip();
}
+
});
});
return startMonth;
}
return startMonth;
-}
\ No newline at end of file
+}
+
+
+// Глобальный кэш прогнозов
+const forecastCache = {};
+
+document.addEventListener("DOMContentLoaded", async () => {
+ const week = '23';
+ const month = 6;
+ const year = new Date().getFullYear();
+
+ if (!week) return;
+
+ try {
+ const response = await fetch(`/auto-plannogramma/weekly-bouquet-products-forecast?month=${month}&year=${year}&week=${week}`);
+ const json = await response.json();
+ if (json.success && json.data) {
+ Object.assign(forecastCache, json.data);
+ }
+ console.log(json);
+ console.log(forecastCache);
+ } catch (e) {
+ console.error("Ошибка загрузки прогнозов:", e);
+ }
+});
+
+function buildForecastTooltip(week, storeId, guid) {
+ console.log(week, storeId, guid);
+ const weekData = forecastCache[week];
+ if (!weekData) return null;
+
+ const storeData = weekData[storeId];
+ if (!storeData) return null;
+
+ const productData = storeData[guid];
+ if (!productData) return null;
+
+ let tooltip = '<div><strong>Прогноз:</strong><br>';
+ for (const [type, groups] of Object.entries(productData)) {
+ tooltip += `<div><em>${type}</em><ul>`;
+ for (const [group, value] of Object.entries(groups)) {
+ tooltip += `<li>${group}: ${value}</li>`;
+ }
+ tooltip += `</ul></div>`;
+ }
+ tooltip += '</div>';
+
+ return tooltip;
+}
+
+
+
+