From: Alexander Smirnov Date: Wed, 4 Sep 2024 06:38:20 +0000 (+0300) Subject: [ERP-100] Использование правильной переменной для вычисления и небольшой рефактор X-Git-Tag: 1.4~10^2~1 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=d9c031c74c542a24399084a557733bc0169176c8;p=erp24_rep%2Fyii-erp24%2F.git [ERP-100] Использование правильной переменной для вычисления и небольшой рефактор --- diff --git a/erp24/services/MotivationService.php b/erp24/services/MotivationService.php index 5186306a..243a4ca9 100644 --- a/erp24/services/MotivationService.php +++ b/erp24/services/MotivationService.php @@ -560,26 +560,10 @@ class MotivationService ->andWhere(['product_id' => array_keys($products1c)]) ->asArray()->one(); - $motivationValueGroup = MotivationValueGroup::find()->where(['alias' => 'week' . $ind])->one(); - $motivationCostsItem = MotivationCostsItem::find()->where(['name' => 'Услуги по сборке'])->one(); - /** @var $motivationCostsItem MotivationCostsItem */ $motivation = Motivation::find()->where(['store_id' => $store_id, 'year' => $year, 'month' => $month])->one(); if ($motivation) { - $motivationValue = MotivationValue::find()->where(['motivation_id' => $motivation->id, - 'motivation_group_id' => $motivationValueGroup->id, 'value_id' => $motivationCostsItem->code])->one(); - if (!$motivationValue) { - $motivationValue = new MotivationValue; - $motivationValue->motivation_id = $motivation->id; - $motivationValue->motivation_group_id = $motivationValueGroup->id; - $motivationValue->value_id = $motivationCostsItem->code; - $motivationValue->value_type = $motivationCostsItem->data_type; - } - $motivationValue->value_float = $salesProduct['total']; - $motivationValue->save(); - //var_dump($motivationValue); die; - if ($motivationValue->getErrors()) { - throw new \Exception(Json::encode($motivationValue->getErrors())); - } + self::saveOrUpdateMotivationValue($motivation->id, 'week' . $ind, self::CODE_ASSEMBLY_SERVICES, + 'float', ($salesProduct['total'] ?? 0)); } // Ищем продажи по продуктовым гуидам по каталог-гуидам категории service_delivery @@ -601,26 +585,14 @@ class MotivationService ->select(['SUM(summ) as total']) ->where(['check_id' => $salesIds]) ->andWhere(['NOT IN', 'check_id', $returnSalesIds]) - ->andWhere(['product_id' => array_keys($products1c)]) + ->andWhere(['product_id' => array_keys($products1cDelivery)]) ->asArray()->one(); $motivationCostsItem = MotivationCostsItem::find()->where(['name' => 'Услуги по доставке'])->one(); /** @var $motivationCostsItem MotivationCostsItem */ if ($motivation) { - $motivationValue = MotivationValue::find()->where(['motivation_id' => $motivation->id, - 'motivation_group_id' => $motivationValueGroup->id, 'value_id' => $motivationCostsItem->code])->one(); - if (!$motivationValue) { - $motivationValue = new MotivationValue; - $motivationValue->motivation_id = $motivation->id; - $motivationValue->motivation_group_id = $motivationValueGroup->id; - $motivationValue->value_id = $motivationCostsItem->code; - $motivationValue->value_type = $motivationCostsItem->data_type; - } - $motivationValue->value_float = $salesProduct['total']; - $motivationValue->save(); - if ($motivationValue->getErrors()) { - throw new \Exception(Json::encode($motivationValue->getErrors())); - } + self::saveOrUpdateMotivationValue($motivation->id, 'week' . $ind, self::CODE_DELIVERY_SERVICES, + 'float', ($salesProduct['total'] ?? 0)); } } }