]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-220] рефактор
authorAlexander Smirnov <fredeom@mail.ru>
Tue, 15 Oct 2024 14:27:12 +0000 (17:27 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Tue, 15 Oct 2024 14:27:12 +0000 (17:27 +0300)
erp24/services/MotivationService.php

index 24034773cc2140e39ac6d7f7e1037bd7ae71dd58..bab12c0f025dec53a3b1dc18c1c091ce9c79f38d 100644 (file)
@@ -476,11 +476,7 @@ class MotivationService
             }
 
             if ($exportImportTable) {
-                $writeOffs = WriteOffs::find()->alias('wo')->select(['wo.type', 'wo.date', 'wop.product_id', 'wop.quantity', 'wop.price'])
-                    ->rightJoin('write_offs_products wop', 'wop.write_offs_id = wo.id')
-                    ->where(['between', 'wo.date', $weekStart, $weekEnd])
-                    ->andWhere(['wo.store_id' => $exportImportTable->export_val])
-                    ->asArray()->all();
+                $writeOffs = self::getWriteOffs($exportImportTable->export_val, $weekStart, $weekEnd);
 
                 $selfCostProduct = SelfCostProduct::find()->select(['price', 'product_guid', 'date'])
                     ->where(['between', 'date', $weekStart, $weekEnd])
@@ -496,10 +492,7 @@ class MotivationService
 
                     if ($key == WriteOffsErp::WRITE_OFFS_TYPE_DELIVERY_BRAK) {
                         if ($store_id == 4 /* Аэродромная */ ) {
-                            $writeOffsResult = WriteOffs::find()->alias('wo')->select(['wo.type', 'wo.date', 'wop.product_id', 'wop.quantity', 'wop.price'])
-                                ->rightJoin('write_offs_products wop', 'wop.write_offs_id = wo.id')
-                                ->where(['between', 'wo.date', $weekStart, $weekEnd])
-                                ->asArray()->all();
+                            $writeOffsResult = self::getWriteOffsAllStores($weekStart, $weekEnd);
                         } else {
                             $writeOffsResult = [];
                         }
@@ -1331,6 +1324,15 @@ class MotivationService
         return $writeOffs;
     }
 
+    private static function getWriteOffsAllStores($periodStart, $periodEnd) {
+        $writeOffs = WriteOffs::find()->alias('wo')->select(['wo.type', 'wo.date', 'wop.product_id', 'wop.quantity', 'wop.price'])
+            ->rightJoin('write_offs_products wop', 'wop.write_offs_id = wo.id')
+            ->where(['between', 'wo.date', $periodStart, $periodEnd])
+            ->asArray()->all();
+
+        return $writeOffs;
+    }
+
     public static function calculateMonthDefect($year, $month) {
         $monthStart = date("Y-m-d 00:00:00", strtotime($year . '-' . $month . '-1'));
         $monthEnd = date("Y-m-t 23:59:59", strtotime($year . '-' . $month . '-1'));
@@ -1349,10 +1351,7 @@ class MotivationService
                 foreach (MotivationCostsItem::writeOffsToMotivationItemArray() as $key => $motivationItemType) {
                     if ($key == WriteOffsErp::WRITE_OFFS_TYPE_DELIVERY_BRAK) {
                         if ($store_id == 4 /* Аэродромная */) {
-                            $writeOffsResult = WriteOffs::find()->alias('wo')->select(['wo.type', 'wo.date', 'wop.product_id', 'wop.quantity', 'wop.price'])
-                                ->rightJoin('write_offs_products wop', 'wop.write_offs_id = wo.id')
-                                ->where(['between', 'wo.date', $monthStart, $monthEnd])
-                                ->asArray()->all();
+                            $writeOffsResult = self::getWriteOffsAllStores($monthStart, $monthEnd);
                         } else {
                             $writeOffsResult = [];
                         }