From: vladfo Date: Fri, 4 Oct 2024 14:23:03 +0000 (+0300) Subject: Проверка на существование записи MotivationValue X-Git-Tag: 1.6~42^2~4 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=c6b21841ea23abe4ae16906e3d016d47ed514fe2;p=erp24_rep%2Fyii-erp24%2F.git Проверка на существование записи MotivationValue --- 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 547e5f85..a59dad51 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 @@ -109,7 +109,7 @@ try { ]) ->all(); - $motivationVal = []; + foreach ($motivationBuhValue as $value) { $motivationBuh = MotivationBuh::findOne([$value->motivation_buh_id]); @@ -119,6 +119,7 @@ try { 'store_id' => $value->store_id, ]); + if (!$motivation) { $motivation = new Motivation(); $motivation->setAttributes([ @@ -129,15 +130,29 @@ try { $motivation->save(); } - $motivationValue = new MotivationValue(); - $motivationValue->setAttributes([ + + $motivationValue = MotivationValue::findOne([ 'motivation_id' => $motivation->id, 'motivation_group_id' => $value->motivation_group_id, 'value_id' => $value->value_id, - 'value_type' => MotivationCostsItem::DATA_TYPE_FLOAT, - 'value_float' => $value->value_float, ]); - $motivationVal[] = $value->value_float; + + + if ($motivationValue) { + $motivationValue->value_float = $value->value_float; + } else { + + $motivationValue = new MotivationValue(); + $motivationValue->setAttributes([ + 'motivation_id' => $motivation->id, + 'motivation_group_id' => $value->motivation_group_id, + 'value_id' => $value->value_id, + 'value_type' => MotivationCostsItem::DATA_TYPE_FLOAT, + 'value_float' => $value->value_float, + ]); + } + + $motivationValue->save(); }