From: Alexander Smirnov Date: Mon, 2 Sep 2024 12:19:09 +0000 (+0300) Subject: [ERP-130] Дебаг 011 X-Git-Tag: 1.4~11^2~14 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=5e4303330f2e0924a34c4c26ffc331c9b6905267;p=erp24_rep%2Fyii-erp24%2F.git [ERP-130] Дебаг 011 --- diff --git a/erp24/services/MotivationService.php b/erp24/services/MotivationService.php index 0afaf554..161f5dcf 100644 --- a/erp24/services/MotivationService.php +++ b/erp24/services/MotivationService.php @@ -454,39 +454,37 @@ class MotivationService } if ($exportImportTable) { - $writeOffs = WriteOffs::find()->select(['items', 'type', 'date']) - ->where(['between', 'date', $weekStart, $weekEnd]) - ->andWhere(['store_id' => $exportImportTable->export_val]) + $writeOffs = WriteOffs::find()->alias('wo')->select(['wo.type', 'wo.date', 'wop.product_id', 'wop.quantity']) + ->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(); - $selfCostProduct = SelfCostProduct::find()->select(['price', 'product_guid']) + $selfCostProduct = SelfCostProduct::find()->select(['price', 'product_guid, date']) ->where(['between', 'date', $weekStart, $weekEnd]) ->andWhere(['store_id' => $store_id]) - ->indexBy('product_guid') ->asArray()->all(); + $selfCostProductMap = []; + foreach ($selfCostProduct as $scp) { + $selfCostProductMap[$scp['date']][$scp['product_guid']] = floatval($scp['price']); + } + foreach (MotivationCostsItem::getWriteOffsItems() as $key) { $sum = 0; foreach($writeOffs as $data) { if (($data['type'] ?? '') != $key) { continue; } - if (!empty($data)) { - try { - $json = Json::decode($data['items'] ?? '[]'); + $sum += ($selfCostProductMap[$data['date']][$data['product_id']] ?? 0) * ($data['quantity'] ?? 0); + } - foreach ($json as $itemArr) { - $sum += floatval(($selfCostProduct[$itemArr['product_id']]["price"] ?? 0)) * ($itemArr['quantity'] ?? 0); - } - } catch (\Exception $ex) {} - } - $motivationItemType = MotivationCostsItem::writeOffsToMotivationItemMap($key); - $motivationCostsItem = MotivationCostsItem::find()->where(['name' => $motivationItemType])->one(); - /** @var $motivationCostsItem MotivationCostsItem */ - if ($motivation && $motivationCostsItem) { - self::saveOrUpdateMotivationValue($motivation->id, 'week' . $ind, $motivationCostsItem->code, - MotivationCostsItem::DATA_TYPE_FLOAT, $sum); - } + $motivationItemType = MotivationCostsItem::writeOffsToMotivationItemMap($key); + $motivationCostsItem = MotivationCostsItem::find()->where(['name' => $motivationItemType])->one(); + /** @var $motivationCostsItem MotivationCostsItem */ + if ($motivation && $motivationCostsItem) { + self::saveOrUpdateMotivationValue($motivation->id, 'week' . $ind, $motivationCostsItem->code, + MotivationCostsItem::DATA_TYPE_FLOAT, $sum); } } }