'p1n.id AS product_id',
'p1n.name AS product_name',
'a.store_id',
- 'a.quantity',
+ 'a.modify',
+ 'a.details',
'a.month'
])
->asArray()
'product_id' => $productId,
'name' => $productName,
'values' => [],
+ 'title' => [],
];
}
$result[$productId]['values'][] = [
'id' => $model['plan_id'],
- 'quantity' => (int)$model['quantity'],
+ 'quantity' => (int)$model['modify'],
'store_id' => (int)$model['store_id'],
+ 'title' => !empty($model['details']) ? json_decode($model['details'], true) : null,
];
}
- $forecast = (new AutoPlannogrammaService())->getWeeklyBouquetProductsForecast($filters['month'], $filters['year'], null, $filters['week']);
-
- foreach ($result as &$productData) {
- foreach ($productData['values'] as &$value) {
- $storeId = $value['store_id'] ?? null;
- $quantity = $value['quantity'] ?? 0;
- $value['title'] = [];
-
- if (!isset($forecast[$storeId])) {
- continue;
- }
-
-
- foreach (['offline', 'marketplace', 'online'] as $channel) {
- $channelData = $forecast[$storeId][$channel] ?? [];
- $titleData = [];
-
- if (isset($channelData['share']) && is_numeric($channelData['share'])) {
- $titleData[0] = round($quantity * $channelData['share'], 2);
- }
-
- if (isset($productData['product_id']) && isset($forecast[$storeId][$productData['product_id']][$channel])) {
- $details = $forecast[$storeId][$productData['product_id']][$channel];
- $titleData[0] = $titleData[0] ?? round($quantity * array_sum($details), 2);
- $titleData[1] = ['details' => array_map(fn($val) => round($val, 2), $details)];
- }
-
- $value['title'][$channel] = $titleData ?: [];
- }
-
- $value['title']['write_offs'] = null;
- if (isset($value['id']) && is_numeric($value['id'])) {
- $autoplannogramma = Autoplannogramma::findOne(['id' => $value['id']]);
- if ($autoplannogramma) {
- $value['title']['write_offs'] = $autoplannogramma->writeoffs_forecast;
- }
- }
- }
- }
-
return array_values($result);
}
if (isset($item['id'])) {
$model = Autoplannogramma::findOne($item['id']);
if ($model !== null) {
- $model->quantity = $item['value'];
+ $model->modify = $item['value'];
$model->auto_forecast = false;
}
} else {
$model->year = $item['year'] ?? null;
$model->month = $item['month'] ?? null;
$model->week = $item['week'] ?? null;
- $model->quantity = $item['value'];
- $model->quantity_forecast = 0;
+ $model->modify = $item['value'];
+ $model->calculate = 0;
$model->auto_forecast = false;
}
offline: 'Оффлайн',
online: 'Онлайн',
marketplace: 'Маркетплейс',
- write_offs: 'Списания'
+ writeOffs: 'Списания'
};
const parts = Object.entries(titleObj)
.map(([typeKey, typeValue]) => {
const title = typeTitles[typeKey] || typeKey;
-
- if (Array.isArray(typeValue) && typeValue.length >= 1) {
- const numericValue = parseFloat(typeValue[0]);
- const details = typeValue[1]?.details || {};
- const lines = Object.entries(details)
+ if (
+ typeof typeValue === 'object' &&
+ typeValue !== null &&
+ typeof typeValue.groups === 'object'
+ ) {
+ const lines = Object.entries(typeValue.groups)
.map(([key, val]) => `- ${key.replace(/_/g, ' ')}: ${parseFloat(val).toFixed(2)}`);
- return `${title}: ${numericValue.toFixed(2)}${lines.length ? '\n' + lines.join('\n') : ''}`;
- }
-
- if (typeof typeValue === 'number') {
- return `${title}: ${typeValue.toFixed(2)}`;
+ return `${title}:\n${lines.join('\n')}`;
}
return '';
.filter(Boolean);
return parts.join('\n\n');
-};
\ No newline at end of file
+};