From: fomichev Date: Thu, 3 Jul 2025 07:40:31 +0000 (+0300) Subject: добавление автопланограмммы X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=7591fb2c828ed613980d84261e25215a15a4db82;p=erp24_rep%2Fyii-erp24%2F.git добавление автопланограмммы --- diff --git a/erp24/config/console.php b/erp24/config/console.php index 7bedb5f5..bb3821ba 100755 --- a/erp24/config/console.php +++ b/erp24/config/console.php @@ -42,8 +42,8 @@ $config = [ // ], 'queue' => [ 'class' => Queue::class, - 'dsn' => 'amqp://admin:3qqHK2MRgGgxUdVT61@rabbitmq-yii_erp24:5672', - //'dsn' => 'amqp://admin:3qqHK2MRgGgxUdVT61@localhost:5672', + //'dsn' => 'amqp://admin:3qqHK2MRgGgxUdVT61@rabbitmq-yii_erp24:5672', + 'dsn' => 'amqp://admin:3qqHK2MRgGgxUdVT61@localhost:5672', 'queueName' => 'telegram-queue', 'as log' => \yii\queue\LogBehavior::class, 'ttr' => 300, // Время для выполнения задания diff --git a/erp24/config/web.php b/erp24/config/web.php index a0d8fb45..773e430d 100644 --- a/erp24/config/web.php +++ b/erp24/config/web.php @@ -42,8 +42,8 @@ $config = [ ], 'queue' => [ 'class' => Queue::class, - 'dsn' => 'amqp://admin:3qqHK2MRgGgxUdVT61@rabbitmq-yii_erp24:5672', - //'dsn' => 'amqp://admin:3qqHK2MRgGgxUdVT61@localhost:5672', + //'dsn' => 'amqp://admin:3qqHK2MRgGgxUdVT61@rabbitmq-yii_erp24:5672', + 'dsn' => 'amqp://admin:3qqHK2MRgGgxUdVT61@localhost:5672', 'queueName' => 'telegram-queue', 'as log' => \yii\queue\LogBehavior::class, 'ttr' => 300, // Время для выполнения задания diff --git a/erp24/jobs/RebuildAutoplannogramJob.php b/erp24/jobs/RebuildAutoplannogramJob.php deleted file mode 100644 index 651d999e..00000000 --- a/erp24/jobs/RebuildAutoplannogramJob.php +++ /dev/null @@ -1,128 +0,0 @@ -setDate($this->year, $this->month, 1); - $planDate = $date->format('Y-m-01'); - - /** @var CityStore $store */ - $store = CityStore::findOne($this->storeId); - if (!$store) { - throw new \RuntimeException("Store #{$this->storeId} not found"); - } - - try { - - $forecastParams = [ - 'month' => $this->month, - 'year' => $this->year, - 'type' => AutoPlannogrammaService::TYPE_SALES, - 'store_id' => $this->storeId, - 'category' => 'Срезка', - 'subcategory' => null, - 'species' => null, - 'plan_date' => $planDate, - ]; - $forecast = $service->calculateFullForecastForWeek($forecastParams); - $writeOffsForecast = $service->getWeeklyProductsWriteoffsForecast( - $this->month, $this->year, $forecast, $this->storeId - ); - $salesForecast = $service->getWeeklyBouquetProductsSalesForecast( - $this->month, $this->year, $this->storeId - ); - - $existing = Autoplannogramma::find() - ->where([ - 'store_id' => $this->storeId, - 'year' => $this->year, - 'month' => $this->month, - 'week' => array_unique(ArrayHelper::getColumn($forecast, 'week')), - ]) - ->indexBy(fn($m) => $m->week . '_' . $m->product_id) - ->all(); - - foreach ($forecast as $item) { - $key = $item['week'] . '_' . $item['product_id']; - $model = $existing[$key] ?? new Autoplannogramma(); - $quantity = (float)($item['forecast_week_pieces'] ?? 0); - $details = []; - $total = $quantity; - - if (!empty($writeOffsForecast[$item['product_id']][$item['week']]['writeOffs'])) { - $w = $writeOffsForecast[$item['product_id']][$item['week']]['writeOffs']; - $details['writeOffs']['quantity'] = $w; - $total += is_array($w) ? array_sum($w) : (float)$w; - } - - foreach (['offline','online','marketplace'] as $t) { - $block = ['share'=>0,'quantity'=>0,'groups'=>[]]; - if (!empty($salesForecast[$this->storeId][$item['product_id']][$t])) { - $share = $salesForecast[$this->storeId][$t]['share'] ?? 0; - $block['share'] = $share; - $block['quantity'] = round($quantity * $share,2); - $total += $block['quantity']; - - foreach ($salesForecast[$this->storeId][$item['product_id']][$t] as $k=>$v) { - $block['groups'][$k] = (float)$v; - $total += (float)$v; - } - } - $details[$t] = $block; - } - - $details['forecast'] = ['quantity' => $quantity]; - $total = (float) sprintf('%.2f', $total); - - $needsUpdate = $model->isNewRecord - || $model->calculate != $quantity - || ceil($model->total) != ceil($total) - || json_encode($model->details, JSON_UNESCAPED_UNICODE) - !== json_encode($details, JSON_UNESCAPED_UNICODE); - - if ($needsUpdate) { - $model->setAttributes([ - 'year' => $this->year, - 'month' => $this->month, - 'week' => $item['week'], - 'product_id' => $item['product_id'], - 'store_id' => $this->storeId, - 'is_archive' => false, - 'capacity_type' => 1, - 'details' => json_encode($details, JSON_UNESCAPED_UNICODE), - 'calculate' => $quantity, - 'modify' => ceil($total), - 'total' => ceil($total), - ]); - if (!$model->save()) { - \Yii::error( - 'Ошибка сохранения Autoplannogramma: ' - . json_encode($model->getErrors(), JSON_UNESCAPED_UNICODE), - __METHOD__ - ); - } - } - } - } catch (Throwable $e) { - \Yii::error("Job failed: " . $e->getMessage(), __METHOD__); - } - } -} \ No newline at end of file