$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;
}
} 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) {
*/
public static function getPriceForProductAndMonth($productId, $year, $month)
{
- // Для проверки возьмем первый день месяца
$dateToCheck = "$year-$month-01";
$priceRecord = PricesDynamic::find()
->where(['product_id' => $productId, 'active' => 1])
$monthlySales = [];
$monthlyWeighted = [];
$weightedSum = 0;
+ $monthlyPrice = [];
foreach ($weightedMonths as $mInfo) {
$mKey = $mInfo['month'];
$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;
}
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;
<?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>