$month = date('m');
$year = date('Y');
$planDate = $year . '-' . str_pad($month, 2, '0', STR_PAD_LEFT) . '-01';
+ $this->stdout("Начало расчетов автопланнограммы\n", BaseConsole::FG_GREEN);
$service = new AutoPlannogrammaService();
$stores = CityStore::findAll(['visible' => CityStore::IS_VISIBLE]);
foreach ($stores as $store) {
- $forecast = $service->calculateFullForecastForWeek(['month' => $month, 'year' => $year, 'store_id' => $store->id, 'plan_date' => $planDate]);
- Yii::error("Рассчитана автопланограмма для магазина $store->id");
+ $this->stdout("Начало рассчетов автопланограммы для магазина $store->id\n", BaseConsole::FG_GREEN);
+ $forecast = $service->calculateFullForecastForWeek([
+ 'month' => $month,
+ 'year' => $year,
+ 'type' => AutoPlannogrammaService::TYPE_SALES,
+ 'store_id' => $store->id,
+ 'category' => null,
+ 'subcategory' => null,
+ 'species' => null,
+ 'plan_date' => $planDate
+ ]);
+ $this->stdout("Рассчитана автопланограмма для магазина $store->id\n", BaseConsole::FG_GREEN);
+// $this->stdout(print_r($forecast, true)); die();
foreach ($forecast as $item) {
$model = new Autoplannogramma();
-// $model->week = $weekNumber;
$model->month = $month;
$model->year = $year;
$model->product_id = $item['product_id'];
$model->store_id = $item['store_id'];
-// $model->quantity = round($item[$weekKey]);
- $model->quantity_forecast = round($item[$weekKey]);
+ $model->quantity = $item['forecast_week_pieces'];
+ $model->quantity_forecast = $item['forecast_week_pieces'];
$model->is_archive = false;
+ $model->capacity_type = 'max';
if (!$model->save()) {
Yii::error("Ошибка сохранения: " . json_encode($model->errors), __METHOD__);
--- /dev/null
+<?php
+
+use yii\db\Migration;
+
+class m250610_085127_aletr_quantity_column_in_autoplannogramma extends Migration
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function safeUp()
+ {
+ $this->alterColumn('autoplannogramma', 'quantity', $this->float()->comment('Количество'));
+ $this->alterColumn('autoplannogramma', 'quantity_forecast',$this->float()->comment('Количество рассчитанное'));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ $this->alterColumn('autoplannogramma', 'quantity', $this->integer()->comment('Количество'));
+ $this->alterColumn('autoplannogramma', 'quantity_forecast',$this->integer()->comment('Количество рассчитанное'));
+
+ }
+}