From e177fe620bf165fb86e5d98573fe0210c1ad09bf Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Tue, 15 Oct 2024 17:27:12 +0300 Subject: [PATCH] =?utf8?q?[ERP-220]=20=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82?= =?utf8?q?=D0=BE=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/services/MotivationService.php | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/erp24/services/MotivationService.php b/erp24/services/MotivationService.php index 24034773..bab12c0f 100644 --- a/erp24/services/MotivationService.php +++ b/erp24/services/MotivationService.php @@ -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 = []; } -- 2.39.5