From 78061f08847e15e473b7fb5df10ed2f0d3b4c2cf Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Tue, 15 Oct 2024 19:17:34 +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 | 39 +++++++++------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/erp24/services/MotivationService.php b/erp24/services/MotivationService.php index bab12c0f..04593770 100644 --- a/erp24/services/MotivationService.php +++ b/erp24/services/MotivationService.php @@ -476,23 +476,15 @@ class MotivationService } if ($exportImportTable) { - $writeOffs = self::getWriteOffs($exportImportTable->export_val, $weekStart, $weekEnd); + $writeOffs = self::getWriteOffs($weekStart, $weekEnd, $exportImportTable->export_val); - $selfCostProduct = SelfCostProduct::find()->select(['price', 'product_guid', 'date']) - ->where(['between', 'date', $weekStart, $weekEnd]) - ->andWhere(['store_id' => $store_id]) - ->asArray()->all(); - - $selfCostProductMap = []; - foreach ($selfCostProduct as $scp) { - $selfCostProductMap[$scp['date']][$scp['product_guid']] = floatval($scp['price']); - } + $selfCostProductMap = self::getSelfCostProductMap($store_id, $weekStart, $weekEnd); foreach (MotivationCostsItem::getWriteOffsItems() as $key) { if ($key == WriteOffsErp::WRITE_OFFS_TYPE_DELIVERY_BRAK) { if ($store_id == 4 /* Аэродромная */ ) { - $writeOffsResult = self::getWriteOffsAllStores($weekStart, $weekEnd); + $writeOffsResult = self::getWriteOffs($weekStart, $weekEnd); } else { $writeOffsResult = []; } @@ -1314,21 +1306,14 @@ class MotivationService return $selfCostProductMap; } - private static function getWriteOffs($storeGuid, $periodStart, $periodEnd) { - $writeOffs = WriteOffs::find()->alias('wo')->select(['wo.type', 'wo.date', 'wop.product_id', 'wop.quantity', 'wop.price']) + private static function getWriteOffs($periodStart, $periodEnd, $storeGuid = null) { + $writeOffsQuery = 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]) - ->andWhere(['wo.store_id' => $storeGuid]) - ->asArray()->all(); - - 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(); + ->where(['between', 'wo.date', $periodStart, $periodEnd]); + if ($storeGuid) { + $writeOffsQuery->andWhere(['wo.store_id' => $storeGuid]); + } + $writeOffs = $writeOffsQuery->asArray()->all(); return $writeOffs; } @@ -1344,14 +1329,14 @@ class MotivationService foreach ($exportImportTables as $store_id => $store_guid) { if (isset($motivations[$store_id])) { - $writeOffs = self::getWriteOffs($store_guid, $monthStart, $monthEnd); + $writeOffs = self::getWriteOffs($monthStart, $monthEnd, $store_guid); $selfCostProductMap = self::getSelfCostProductMap($store_id, $monthStart, $monthEnd); foreach (MotivationCostsItem::writeOffsToMotivationItemArray() as $key => $motivationItemType) { if ($key == WriteOffsErp::WRITE_OFFS_TYPE_DELIVERY_BRAK) { if ($store_id == 4 /* Аэродромная */) { - $writeOffsResult = self::getWriteOffsAllStores($monthStart, $monthEnd); + $writeOffsResult = self::getWriteOffs($monthStart, $monthEnd); } else { $writeOffsResult = []; } -- 2.39.5