From: fomichev Date: Tue, 8 Apr 2025 14:32:54 +0000 (+0300) Subject: добавление цен и исправление недель X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=3e6736342011f03935d7b430074c8ddb666f7512;p=erp24_rep%2Fyii-erp24%2F.git добавление цен и исправление недель --- diff --git a/erp24/services/StorePlanService.php b/erp24/services/StorePlanService.php index dd088a6d..cba51c3f 100755 --- a/erp24/services/StorePlanService.php +++ b/erp24/services/StorePlanService.php @@ -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; } diff --git a/erp24/views/category-plan/show-history-data.php b/erp24/views/category-plan/show-history-data.php index bd79da79..76c07f36 100644 --- a/erp24/views/category-plan/show-history-data.php +++ b/erp24/views/category-plan/show-history-data.php @@ -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; - 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;?> +