]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-140] В случае отсутствия себестоимости записываем summ от продукта
authorAlexander Smirnov <fredeom@mail.ru>
Wed, 4 Sep 2024 13:18:35 +0000 (16:18 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Wed, 4 Sep 2024 13:18:35 +0000 (16:18 +0300)
erp24/services/MotivationService.php

index beeba4afd5d81d29ffb70049518ff4b819aeeb23..848a7a5c248422aa84153137f8a47fd396886c8f 100644 (file)
@@ -1279,7 +1279,7 @@ class MotivationService
 
         foreach ($exportImportTables as $store_id => $store_guid) {
             if (isset($motivations[$store_id])) {
-                $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', $monthStart, $monthEnd])
                     ->andWhere(['wo.store_id' => $store_guid])
@@ -1299,8 +1299,9 @@ class MotivationService
                     $sum = 0;
                     foreach($writeOffs as $data) {
                         if (($data['type'] ?? '') == $key) {
-                            $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'] ?? 0);
                         }
                     }
 
@@ -1884,7 +1885,7 @@ class MotivationService
             foreach($writeOffs as $data) {
                 $value = ($selfCostProductMap[date("Y-m-d", strtotime($data['date']))][$data['product_id']] ?? 0)
                     * ($data['quantity'] ?? 0);
-                $sum = $value > 0 ? $value : $data['summ'];
+                $sum += $value > 0 ? $value : ($data['summ'] ?? 0);
             }
 
             return $sum;