]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-140] после 174ой
authorAlexander Smirnov <fredeom@mail.ru>
Wed, 4 Sep 2024 12:48:46 +0000 (15:48 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Wed, 4 Sep 2024 12:48:46 +0000 (15:48 +0300)
erp24/services/MotivationService.php

index d7a92f1721254f6a16b9d58ab92a010deef6fd12..beeba4afd5d81d29ffb70049518ff4b819aeeb23 100644 (file)
@@ -1446,11 +1446,11 @@ class MotivationService
         foreach ($motivations as $motivation) {
             /** @var $motivation Motivation */
 
-            // Рассчитываем сумму себестоимости за эту неделю
+            $correction = self::getMotivationValue($motivation->id, 8, self::CODE_COSTS_OF_GOODS);
             $costSum = self::getSelfCostSumByStore($monthStart, $monthEnd, $motivation->store_id);
 
             self::saveOrUpdateMotivationValue($motivation->id,
-                "fact", self::CODE_COSTS_OF_GOODS, "float", $costSum);
+                "fact", self::CODE_COSTS_OF_GOODS, "float", $costSum + $correction);
         }
     }
 
@@ -1863,7 +1863,7 @@ class MotivationService
         $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'])
+            $writeOffs = WriteOffs::find()->alias('wo')->select(['wo.type', 'wo.date', 'wop.product_id', 'wop.quantity', 'wop.summ'])
                 ->rightJoin('write_offs_products wop', 'wop.write_offs_id = wo.id')
                 ->where(['between', 'wo.date', $startDate, $endDate])
                 ->andWhere(['wo.store_id' => $exportImportTable->export_val])
@@ -1882,8 +1882,9 @@ class MotivationService
 
             $sum = 0;
             foreach($writeOffs as $data) {
-                $sum += ($selfCostProductMap[date("Y-m-d", strtotime($data['date']))][$data['product_id']] ?? 0)
+                $value = ($selfCostProductMap[date("Y-m-d", strtotime($data['date']))][$data['product_id']] ?? 0)
                     * ($data['quantity'] ?? 0);
+                $sum = $value > 0 ? $value : $data['summ'];
             }
 
             return $sum;