use yii_app\records\MatrixBouquetForecast;
use yii_app\records\Product1cReplacement;
use yii_app\records\Products1c;
+use yii_app\records\Products1cNomenclature;
use yii_app\records\ReplacementInvoice;
use yii_app\records\ReplacementInvoiceProducts;
use yii_app\records\MarketplaceOrder1cStatuses;
public function actionAutoplannogrammaCalculate(): void
{
$date = new DateTime();
- $date->modify('+0 months');
+ $date->modify('+2 months');
$planDate = $date->format('Y-m-01');
$month = (int)$date->format('m');
$year = (int)$date->format('Y');
$service = new AutoPlannogrammaService();
$stores = CityStore::find()->where(['visible' => CityStore::IS_VISIBLE])->all();
-
+ $categories = Products1cNomenclature::find()->select('category')->distinct()->andWhere(['not in', 'category', ['', 'букет', 'сборка', 'сервис']])->column();
$this->stdout("Начало расчетов автопланограммы для $planDate\n", BaseConsole::FG_GREEN);
foreach ($stores as $store) {
'species' => null,
'plan_date' => $planDate
];
- $this->stdout("Рассчитана автопланограмма для магазина " . json_encode($forecastParams, JSON_UNESCAPED_UNICODE) . "\n", BaseConsole::FG_GREEN);
- $forecast = $service->calculateFullForecastForWeek($forecastParams);
+ $this->stdout("Параметры расчета " . json_encode($forecastParams, JSON_UNESCAPED_UNICODE) . "\n", BaseConsole::FG_GREEN);
+ $forecasts = [];
+ foreach ($categories as $category) {
+ $forecastParams['category'] = $category;
+ $forecast = $service->calculateFullForecastForWeek($forecastParams);
+ $forecasts = array_merge($forecasts, $forecast);
+ }
+
$logDir = Yii::getAlias('@runtime/logs/autoplannogramma');
if (!is_dir($logDir)) {
mkdir($logDir, 0755, true);
$file = $logDir . '/forecast_store_' . $store->id . '_' . date('Ymd_His') . '.json';
file_put_contents(
$file,
- json_encode($forecast, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
+ json_encode($forecasts, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
);
$this->stdout("Forecast сохранён в $file\n", BaseConsole::FG_BLUE);
- $writeOffsForecast = $service->getWeeklyProductsWriteoffsForecast($month, $year, $forecast, $store->id);
+ $writeOffsForecast = $service->getWeeklyProductsWriteoffsForecast($month, $year, $forecasts, $store->id);
$salesForecast = $service->getWeeklyBouquetProductsSalesForecast($month, $year, $store->id);
$this->stdout("Рассчитана автопланограмма для магазина {$store->name}\n", BaseConsole::FG_GREEN);
'month' => $month,
'year' => $year,
'store_id' => $store->id,
- 'week' => array_unique(array_column($forecast, 'week'))
+ 'week' => array_unique(array_column($forecasts, 'week'))
])
->indexBy(fn($record) => $record->week . '_' . $record->product_id)
->all();
- foreach ($forecast as $item) {
+ foreach ($forecasts as $item) {
$key = $item['week'] . '_' . $item['product_id'];
$model = $existingRecords[$key] ?? new Autoplannogramma();
$productId = $item['product_id'];
$service = new AutoPlannogrammaService();
//$goals = $service->calculateFullGoalChain($filters);
- $forecast = $service->calculateFullForecastForWeek($filters);
- var_dump( $forecast); die();
+ //$forecast = $service->calculateFullForecastForWeek($filters);
$monthCategoryShare = $service->getMonthCategoryShareOrWriteOff($filters['plan_date'], $filters);
$monthCategoryGoal = $service->getMonthCategoryGoal($monthCategoryShare, $filters['plan_date']);
$monthSubcategoryShare = $service->getMonthSubcategoryShareOrWriteOff($filters['plan_date'], $filters);
try {
$forecast = $service->calculateFullForecastForWeek($params);
- //var_dump($forecast);die();
$writeOffsForecast = $service->getWeeklyProductsWriteoffsForecast($month, $year, $forecast, $store_id);
$salesForecast = $service->getWeeklyBouquetProductsSalesForecast($month, $year, $store_id);