From 2dc84f7e79017fec174b306ac891d68a1a975769 Mon Sep 17 00:00:00 2001 From: marina Date: Tue, 27 Aug 2024 10:11:11 +0300 Subject: [PATCH] =?utf8?q?ERP-85=20=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?utf8?q?=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20=D0=BE=D0=B1=D0=BC=D0=B5=D0=BD?= =?utf8?q?=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D1=81=201=D0=A1=20?= =?utf8?q?=D0=91=D1=83=D1=85=D0=B3=D0=B0=D0=BB=D1=82=D0=B5=D1=80=D0=B8?= =?utf8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/records/Motivation.php | 2 +- ...ata_to_monitvation_from_motivation_buh.php | 24 ++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/erp24/records/Motivation.php b/erp24/records/Motivation.php index f308d382..65112bcd 100644 --- a/erp24/records/Motivation.php +++ b/erp24/records/Motivation.php @@ -89,7 +89,7 @@ class Motivation extends \yii\db\ActiveRecord public static function getWeek($date = null) { - $date = $date ?? $date('d'); + $date = $date ?? date('d'); $d = date("d", strtotime($date)); return intval(floor(($d - 1) / 7) + 1); diff --git a/erp24/scripts/tasks/task_33_insert_data_to_monitvation_from_motivation_buh.php b/erp24/scripts/tasks/task_33_insert_data_to_monitvation_from_motivation_buh.php index 6de9245e..a288bbf7 100644 --- a/erp24/scripts/tasks/task_33_insert_data_to_monitvation_from_motivation_buh.php +++ b/erp24/scripts/tasks/task_33_insert_data_to_monitvation_from_motivation_buh.php @@ -5,6 +5,7 @@ */ use yii\db\Exception; +use yii\db\Expression; use yii\helpers\ArrayHelper; use yii\helpers\Json; @@ -81,17 +82,23 @@ try { $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) { @@ -99,7 +106,7 @@ try { $motivation->setAttributes([ 'year' => $motivationBuh->year, 'month' => $motivationBuh->month, - 'store_id' => $value['store_id'] + 'store_id' => $value->store_id ]); $motivation->save(); } @@ -108,10 +115,11 @@ try { $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 ================'; -- 2.39.5