]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-140] подсчёт Стоимость товара факт мотивации
authorAlexander Smirnov <fredeom@mail.ru>
Tue, 3 Sep 2024 07:50:21 +0000 (10:50 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Tue, 3 Sep 2024 07:50:21 +0000 (10:50 +0300)
erp24/actions/motivation/TestFactAction.php
erp24/scripts/tasks/task_32_motivation_fact.php
erp24/services/MotivationService.php

index 4a784f209fa6780bf4fca7d2179daa5cde109ce5..3148ebc5b7bda861635df528399967cebbfed54f 100644 (file)
@@ -72,6 +72,8 @@ class TestFactAction extends Action
 
             MotivationService::calculateMonthCeoAndSaleOfWebsiteGoods($model->year, $model->month);
 
+            MotivationService::calculateMonthCostMotivation($model->year, $model->month);
+
             MotivationService::initMonth1cFields($model->year, $model->month);
         }
 
index 3d641799cfb6f6c66e4e7373753d616c9ca894e6..06d21f26698a4b50e7d41ef805dde80ff181a6be 100644 (file)
@@ -75,6 +75,8 @@ try {
 
         MotivationService::calculateMonthCeoAndSaleOfWebsiteGoods($year, $month);
 
+        MotivationService::calculateMonthCostMotivation($year, $month);
+
         MotivationService::initMonth1cFields($year, $month);
         //////////////////////////////////////////////
 
index f9795b7de40ed8704c72ca488580aa505a683a3d..8fdf2b87b6217ce5a9e2b055b910b2c3e133b214 100644 (file)
@@ -1490,6 +1490,25 @@ class MotivationService
         }
     }
 
+    public static function calculateMonthCostMotivation($year, $month) {
+        $monthStart = date("Y-m-d 00:00:00", strtotime("$year-$month-01"));
+        $monthEnd = date("Y-m-t 23:59:59", strtotime("$year-$month-01"));
+
+        $motivations = Motivation::find()
+            ->where(['year' => $year, 'month' => $month])
+            ->all();
+
+        foreach ($motivations as $motivation) {
+            /** @var $motivation Motivation */
+
+            // Рассчитываем сумму себестоимости за эту неделю
+            $costSum = self::getSelfCostSumByStore($monthStart, $monthEnd, $motivation->store_id);
+
+            self::saveOrUpdateMotivationValue($motivation->id,
+                "fact", self::CODE_COSTS_OF_GOODS, "float", $costSum);
+        }
+    }
+
     public static function initMonth1cFields($year, $month) {
         $motivations = Motivation::find()
             ->where(['year' => $year, 'month' => $month])