]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
правки таблиц для списаний
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 17 Jun 2025 10:43:50 +0000 (13:43 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 17 Jun 2025 10:43:50 +0000 (13:43 +0300)
erp24/migrations/m250610_085127_aletr_quantity_column_in_autoplannogramma.php
erp24/records/Autoplannogramma.php
erp24/services/AutoPlannogrammaService.php

index acaf378bb6e3008cdc1f9b7757be52692b47b3cc..76d4a56c292078e4763e554c1ab2c959e9b0a57c 100644 (file)
@@ -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('Количество списаний'));
     }
 }
index 63b15580b1ce1789239e09111d6d2e823cc37527..63c8c87d76f73947400e62466c2937d07b43247d 100644 (file)
@@ -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' => 'Дата создания',
index 15d9c773fd2fe2d40d1f563fc2e82a71234c9551..705ac472770b7457f690d7e34ef9ef706c278bb4 100644 (file)
@@ -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