From: Alexander Smirnov Date: Tue, 3 Sep 2024 07:50:21 +0000 (+0300) Subject: [ERP-140] подсчёт Стоимость товара факт мотивации X-Git-Tag: 1.4~5^2~13 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=94b568d91b69572ad1be8d1afd3908159c045077;p=erp24_rep%2Fyii-erp24%2F.git [ERP-140] подсчёт Стоимость товара факт мотивации --- diff --git a/erp24/actions/motivation/TestFactAction.php b/erp24/actions/motivation/TestFactAction.php index 4a784f20..3148ebc5 100644 --- a/erp24/actions/motivation/TestFactAction.php +++ b/erp24/actions/motivation/TestFactAction.php @@ -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); } diff --git a/erp24/scripts/tasks/task_32_motivation_fact.php b/erp24/scripts/tasks/task_32_motivation_fact.php index 3d641799..06d21f26 100644 --- a/erp24/scripts/tasks/task_32_motivation_fact.php +++ b/erp24/scripts/tasks/task_32_motivation_fact.php @@ -75,6 +75,8 @@ try { MotivationService::calculateMonthCeoAndSaleOfWebsiteGoods($year, $month); + MotivationService::calculateMonthCostMotivation($year, $month); + MotivationService::initMonth1cFields($year, $month); ////////////////////////////////////////////// diff --git a/erp24/services/MotivationService.php b/erp24/services/MotivationService.php index f9795b7d..8fdf2b87 100644 --- a/erp24/services/MotivationService.php +++ b/erp24/services/MotivationService.php @@ -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])