From: Alexander Smirnov Date: Tue, 3 Sep 2024 09:10:27 +0000 (+0300) Subject: [ERP-140] Расходные материалы (обеспечение продаж) пополнены аналитикой из 1с розница X-Git-Tag: 1.4~5^2~11 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=96641fbdedc8e37e132c56a2e3d5dd8e8abc4cd2;p=erp24_rep%2Fyii-erp24%2F.git [ERP-140] Расходные материалы (обеспечение продаж) пополнены аналитикой из 1с розница --- 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; + } + /** * Сохраняет мотивацию по себестоимости товара для указанного магазина и месяца. *