From 7f882aac89e412ae14668f5abac2639569daebe9 Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Tue, 17 Jun 2025 13:43:50 +0300 Subject: [PATCH] =?utf8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D1=82?= =?utf8?q?=D0=B0=D0=B1=D0=BB=D0=B8=D1=86=20=D0=B4=D0=BB=D1=8F=20=D1=81?= =?utf8?q?=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- ...tr_quantity_column_in_autoplannogramma.php | 7 +-- erp24/records/Autoplannogramma.php | 4 +- erp24/services/AutoPlannogrammaService.php | 44 +++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/erp24/migrations/m250610_085127_aletr_quantity_column_in_autoplannogramma.php b/erp24/migrations/m250610_085127_aletr_quantity_column_in_autoplannogramma.php index acaf378b..76d4a56c 100644 --- a/erp24/migrations/m250610_085127_aletr_quantity_column_in_autoplannogramma.php +++ b/erp24/migrations/m250610_085127_aletr_quantity_column_in_autoplannogramma.php @@ -11,6 +11,7 @@ class m250610_085127_aletr_quantity_column_in_autoplannogramma extends Migration { $this->alterColumn('autoplannogramma', 'quantity', $this->float()->comment('Количество')); $this->alterColumn('autoplannogramma', 'quantity_forecast',$this->float()->comment('Количество рассчитанное')); + $this->addColumn('autoplannogramma', 'writeoffs_forecast',$this->float()->comment('Количество списаний')); } /** @@ -18,8 +19,8 @@ class m250610_085127_aletr_quantity_column_in_autoplannogramma extends Migration */ public function safeDown() { - $this->alterColumn('autoplannogramma', 'quantity', $this->integer()->comment('Количество')); - $this->alterColumn('autoplannogramma', 'quantity_forecast',$this->integer()->comment('Количество рассчитанное')); - + $this->dropColumn('autoplannogramma', 'quantity', $this->integer()->comment('Количество')); + $this->dropColumn('autoplannogramma', 'quantity_forecast',$this->integer()->comment('Количество рассчитанное')); + $this->dropColumn('autoplannogramma', 'writeoffs_forecast',$this->float()->comment('Количество списаний')); } } diff --git a/erp24/records/Autoplannogramma.php b/erp24/records/Autoplannogramma.php index 63b15580..63c8c87d 100644 --- a/erp24/records/Autoplannogramma.php +++ b/erp24/records/Autoplannogramma.php @@ -20,6 +20,7 @@ use yii\db\Expression; * @property int|null $capacity_type Тип планограммы * @property int|null $quantity Количество * @property int|null $quantity_forecast Количество рассчитанное + * @property int|null $writeoffs_forecast Количество списано * @property bool|null $is_archive Архивная ли запись? * @property bool|null $auto_forecast Значение спрогнозировано? * @property string|null $created_at Дата создания @@ -45,7 +46,7 @@ class Autoplannogramma extends \yii\db\ActiveRecord return [ [['week', 'month', 'year', 'store_id', 'capacity_type', 'created_by', 'updated_by'], 'integer'], [['is_archive', 'auto_forecast'], 'boolean'], - [[ 'quantity', 'quantity_forecast'], 'number'], + [[ 'quantity', 'quantity_forecast', 'writeoffs_forecast'], 'number'], [['created_at', 'updated_at'], 'safe'], [['auto_forecast'], 'default', 'value' => true], [['product_id'], 'string', 'max' => 255], @@ -84,6 +85,7 @@ class Autoplannogramma extends \yii\db\ActiveRecord 'capacity_type' => 'Тип планограммы', 'quantity' => 'Количество', 'quantity_forecast' => 'Количество рассчитанное', + 'writeoffs_forecast' => 'Количество списано', 'is_archive' => 'Архивная ли запись?', 'auto_forecast' => 'Значение спрогнозировано?', 'created_at' => 'Дата создания', diff --git a/erp24/services/AutoPlannogrammaService.php b/erp24/services/AutoPlannogrammaService.php index 15d9c773..705ac472 100644 --- a/erp24/services/AutoPlannogrammaService.php +++ b/erp24/services/AutoPlannogrammaService.php @@ -2843,4 +2843,48 @@ class AutoPlannogrammaService } + public function getWeeklyProductsWriteoffsForecast($month, $year, $storeId = null, $weekNumber = null) + { + $weeksProductForecast = []; + $filters = []; + + $dateFrom = date("Y-m-d 00:00:00", strtotime(sprintf('%04d-%02d-01', $year, $month))); + $monthYear = date("m-Y", strtotime($dateFrom)); + $filters['store_id'] = $storeId; + $filters['type'] = self::TYPE_WRITE_OFFS; + $filters['plan_date'] = $dateFrom; + + $monthSpeciesGoals = $this->calculateFullGoalChain($filters); + $monthSpeciesGoalsMap = []; + foreach ($monthSpeciesGoals as $monthSpeciesGoal) { + $monthSpeciesGoalsMap[$monthSpeciesGoal['store_id']] + [$monthSpeciesGoal['category']] + [$monthSpeciesGoal['subcategory']] + [$monthSpeciesGoal['species']] = $monthSpeciesGoal['goal']; + } + + $weeksShareResult = $this->getHistoricalWeeklySpeciesShare($monthYear, $filters, null, 'writeOffs'); + $weeksData = $this->calculateWeeklySpeciesGoals($weeksShareResult, $monthSpeciesGoals); + + foreach ($weeksData as $r) { + $forecasts = $this->calculateWeekForecastSpeciesProducts($r['category'], $r['subcategory'], $r['species'], $r['store_id'], $r['weekly_goal']); + + foreach ($forecasts as $forecast) { + $weeksProductForecast[] = [ + 'category' => $forecast['category'] ?? '', + 'subcategory' => $forecast['subcategory'] ?? '', + 'species' => $forecast['species'] ?? '', + 'product_id' => $forecast['product_id'] ?? '', + 'name' => $forecast['name'] ?? '', + 'price' => $forecast['price'] ?? '', + 'goal' => $forecast['goal'] ?? 0, + 'forecast' => $forecast['forecast'] ?? 0, + 'week' => $r['week'], + ]; + } + } + + return $weeksProductForecast; + } + } \ No newline at end of file -- 2.39.5