]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-100] Использование правильной переменной для вычисления и небольшой рефактор
authorAlexander Smirnov <fredeom@mail.ru>
Wed, 4 Sep 2024 06:38:20 +0000 (09:38 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Wed, 4 Sep 2024 06:38:20 +0000 (09:38 +0300)
erp24/services/MotivationService.php

index 5186306a9f39a4d4158191be7810e18a268163a7..243a4ca97bf950a83e36f7d076101bf1ceb22582 100644 (file)
@@ -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));
             }
         }
     }