*/
use yii\db\Exception;
+use yii\db\Expression;
use yii\helpers\ArrayHelper;
use yii\helpers\Json;
$motivationBuhValue = MotivationBuhValue::find()
->andWhere(['motivation_group_id' => $motivationGroup->id])
->groupBy('store_id, value_id, motivation_buh_id')
- ->select('sum(value_float) as value_float', 'motivation_buh_id, value_id')
- ->asArray();
+ ->select([
+ new Expression(
+ 'sum(value_float) as value_float,
+ motivation_buh_id as motivation_buh_id,
+ value_id as value_id,
+ store_id as store_id'
+ )
+ ])
+ ->all();
foreach ($motivationBuhValue as $value) {
-
- $motivationBuh = MotivationBuh::findOne([$motivationBuhValue['motivation_buh_id']]);
+ $motivationBuh = MotivationBuh::findOne([$value->motivation_buh_id]);
$motivation = Motivation::findOne([
'year' => $motivationBuh->year,
'month' => $motivationBuh->month,
- 'store_id' => $motivationBuhValue['store_id'],
+ 'store_id' => $value->store_id,
]);
if (!$motivation) {
$motivation->setAttributes([
'year' => $motivationBuh->year,
'month' => $motivationBuh->month,
- 'store_id' => $value['store_id']
+ 'store_id' => $value->store_id
]);
$motivation->save();
}
$motivationValue->setAttributes([
'motivation_id' => $motivation->id,
'motivation_group_id' => $motivationGroup->id,
- 'value_id' => $value['value_id'],
+ 'value_id' => $value->value_id,
'value_type' => MotivationCostsItem::DATA_TYPE_FLOAT,
- 'value_float' => $value['value_float'],
+ 'value_float' => $value->value_float,
]);
+ $motivationValue->save();
}
$info = ' ================ test Task ' . $taskNum . ' stop ================';