From 96641fbdedc8e37e132c56a2e3d5dd8e8abc4cd2 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Tue, 3 Sep 2024 12:10:27 +0300 Subject: [PATCH] =?utf8?q?[ERP-140]=20=D0=A0=D0=B0=D1=81=D1=85=D0=BE=D0=B4?= =?utf8?q?=D0=BD=D1=8B=D0=B5=20=D0=BC=D0=B0=D1=82=D0=B5=D1=80=D0=B8=D0=B0?= =?utf8?q?=D0=BB=D1=8B=20(=D0=BE=D0=B1=D0=B5=D1=81=D0=BF=D0=B5=D1=87=D0=B5?= =?utf8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B4=D0=B0=D0=B6)=20?= =?utf8?q?=D0=BF=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D1=8B=20=D0=B0?= =?utf8?q?=D0=BD=D0=B0=D0=BB=D0=B8=D1=82=D0=B8=D0=BA=D0=BE=D0=B9=20=D0=B8?= =?utf8?q?=D0=B7=201=D1=81=20=D1=80=D0=BE=D0=B7=D0=BD=D0=B8=D1=86=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/services/MotivationService.php | 42 +++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/erp24/services/MotivationService.php b/erp24/services/MotivationService.php index b13d9cb3..301b7cfd 100644 --- a/erp24/services/MotivationService.php +++ b/erp24/services/MotivationService.php @@ -1510,14 +1510,21 @@ class MotivationService } public static function calculateMonthMaterials($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 */ + $materials = self::getMotivationValue($motivation->id, 10, self::CODE_CONSUMABLES_SALES_SUPPORT); + $consumablesSalesSupport = self::getCostConsumablesSalesSupportByStore($monthStart, $monthEnd, $motivation->store_id); + self::saveOrUpdateMotivationValue($motivation->id, - "fact", self::CODE_CONSUMABLES_SALES_SUPPORT, "float", $materials); + "fact", self::CODE_CONSUMABLES_SALES_SUPPORT, "float", $materials + $consumablesSalesSupport); } } @@ -1844,6 +1851,39 @@ class MotivationService return $sum; } + public static function getCostConsumablesSalesSupportByStore($startDate, $endDate, $storeId) { + $exportImportTable = ExportImportTable::find()->select(['export_val'])->where(['entity' => 'city_store', 'entity_id' => $storeId, 'export_id' => 1])->one(); + + if ($exportImportTable) { + $writeOffs = WriteOffs::find()->alias('wo')->select(['wo.type', 'wo.date', 'wop.product_id', 'wop.quantity']) + ->rightJoin('write_offs_products wop', 'wop.write_offs_id = wo.id') + ->where(['between', 'wo.date', $startDate, $endDate]) + ->andWhere(['wo.store_id' => $exportImportTable->export_val]) + ->andWhere(['type' => 'Расходные материалы (обеспечение продаж)']) + ->asArray()->all(); + + $selfCostProduct = SelfCostProduct::find()->select(['price', 'product_guid', 'date']) + ->where(['between', 'date', $startDate, $endDate]) + ->andWhere(['store_id' => $storeId]) + ->asArray()->all(); + + $selfCostProductMap = []; + foreach ($selfCostProduct as $scp) { + $selfCostProductMap[$scp['date']][$scp['product_guid']] = floatval($scp['price']); + } + + $sum = 0; + foreach($writeOffs as $data) { + $sum += ($selfCostProductMap[date("Y-m-d", strtotime($data['date']))][$data['product_id']] ?? 0) + * ($data['quantity'] ?? 0); + } + + return $sum; + } + + return 0; + } + /** * Сохраняет мотивацию по себестоимости товара для указанного магазина и месяца. * -- 2.39.5