]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Merge branch 'feature_zozirova_erp-360_autoplannogramma_build' into feature_zozirova_...
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 17 Jun 2025 11:31:59 +0000 (14:31 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 17 Jun 2025 11:31:59 +0000 (14:31 +0300)
# Conflicts:
# erp24/services/AutoPlannogrammaService.php

1  2 
erp24/services/AutoPlannogrammaService.php

index 705ac472770b7457f690d7e34ef9ef706c278bb4,9b3cb7613540a956f88f99634d21a4e6ed288cdc..27c6572d64aab172ab09d22b61e9920f83a9e5c9
@@@ -2839,52 -2848,18 +2848,62 @@@ class AutoPlannogrammaServic
                  ];
              }
          }
-         return $weeklyForecasts;
  
-     }
+         $grouped = [];
+         foreach ($weeklyForecasts as $item) {
+             $storeItem = (int)$item['store_id'];
+             $guid = (string)$item['product_guid'];
+             $group = (string)$item['matrix_group'];
+             $type = (string)$item['type'];
+             $forecastValue = (float)$item['week_forecast'];
  
+             $grouped[$storeItem][$guid][$type][$group] = $forecastValue;
+         }
+         return $grouped;
+     }
 +    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;
 +    }
 +
  }