]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
добавление цен и исправление недель
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 8 Apr 2025 14:32:54 +0000 (17:32 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 8 Apr 2025 14:32:54 +0000 (17:32 +0300)
erp24/services/StorePlanService.php
erp24/views/category-plan/show-history-data.php

index dd088a6dea4da3d6581c2d60664d839dc6ff07c2..cba51c3f30cb22c9570b2808f33d4b160c7e5efe 100755 (executable)
@@ -221,9 +221,11 @@ class StorePlanService
             $month = date('m', $prevTimestamp);
             $periods[$month] = [];
         }
-       // var_dump($periods); die();
+        //var_dump($periods); die();
         foreach ($periods as $monthKey => $month) {
-            for ($weekNumber = 1; $weekNumber <= 4; $weekNumber++) {
+            $days = cal_days_in_month(CAL_GREGORIAN, (int)$monthKey, (int)$year);
+            $weeks = $days > 28 ? 5 : 4;
+            for ($weekNumber = 1; $weekNumber <= $weeks; $weekNumber++) {
                 $range = Motivation::getWeekRange(null, $weekNumber, (int)$monthKey, $year);
                 $periods[$monthKey][$weekNumber - 1] = $range;
             }
@@ -286,7 +288,7 @@ class StorePlanService
                 } else {
                     $weekData = [];
                     $activeWeeks = 0;
-                    for ($weekIndex = 0; $weekIndex < 4; $weekIndex++) {
+                    for ($weekIndex = 0; $weekIndex < 5; $weekIndex++) {
                         $salesCount = isset($monthsData[$monthKey][$weekIndex]) ? $monthsData[$monthKey][$weekIndex] : 0;
                         $weekData[$weekIndex] = $salesCount;
                         if ($salesCount > 0) {
@@ -450,7 +452,6 @@ class StorePlanService
      */
     public static function getPriceForProductAndMonth($productId, $year, $month)
     {
-        // Для проверки возьмем первый день месяца
         $dateToCheck = "$year-$month-01";
         $priceRecord = PricesDynamic::find()
             ->where(['product_id' => $productId, 'active' => 1])
@@ -513,6 +514,7 @@ class StorePlanService
             $monthlySales = [];
             $monthlyWeighted = [];
             $weightedSum = 0;
+            $monthlyPrice = [];
 
             foreach ($weightedMonths as $mInfo) {
                 $mKey = $mInfo['month'];
@@ -522,12 +524,14 @@ class StorePlanService
                 $monthlySales[$mKey] = $sales;
                 $weightedValue = $sales * $price * $mInfo['weight'];
                 $monthlyWeighted[$mKey] = $weightedValue;
+                $monthlyPrice[$mKey] = $price;
                 $weightedSum += $weightedValue;
             }
             $productsData[$guid] = [
                 'monthlySales'    => $monthlySales,
                 'monthlyWeighted' => $monthlyWeighted,
                 'weightedSum'     => $weightedSum,
+                'monthlyPrice'     => $monthlyPrice,
             ];
             $globalTotal += $weightedSum;
         }
index bd79da791592175304a8da2da5ce856d5777a2ec..76c07f362d44ee057718c587e40d331be5ff7cfc 100644 (file)
@@ -4,6 +4,7 @@ use yii\helpers\ArrayHelper;
 use yii\widgets\ActiveForm;
 use yii\base\DynamicModel;
 use yii_app\records\CityStore;
+use yii_app\records\PricesDynamic;
 use yii_app\records\Products1c;
 use yii_app\records\Products1cNomenclature;
 
@@ -205,9 +206,18 @@ JS;
                         <?php endif; ?>
                     </td>
                     <td>
-                        <?= isset($weighted[$product['guid']]) ? (\yii_app\records\PricesDynamic::find()
+                        <?php  $query = PricesDynamic::find()
                             ->where(['product_id' => $product['guid']])
-                            ->andWhere(['active' => 1])->one()->price) *
+                            ->andWhere(['active' => 1]);
+                        if (CityStore::find()->where(['id' => $model->storeId])->one()->city_id == 1342) {
+                           $region = 52;
+                        } elseif (CityStore::find()->where(['id' => $model->storeId])->one()->city_id == 1) {
+                            $region = 77;
+                        } else {
+                            $region = null;
+                        }
+                           $price = $query->andWhere(['region_id' => $region])->one()->price;?>
+                        <?= isset($weighted[$product['guid']]) ? $price *
                             $weighted[$product['guid']]['weightedValue'] : 0 ?>
                     </td>
                 </tr>