From beecf2731478595c6ebe6c9929679b9cfb274bf9 Mon Sep 17 00:00:00 2001 From: marina Date: Wed, 16 Oct 2024 12:16:13 +0300 Subject: [PATCH] =?utf8?q?ERP-225=20=D0=9D=D0=B5=20=D0=BF=D1=80=D0=B0?= =?utf8?q?=D0=B2=D0=B8=D0=BB=D1=8C=D0=BD=D0=BE=20=D1=81=D1=87=D0=B8=D1=82?= =?utf8?q?=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20=D0=9F=D1=80=D0=BE=D0=B3=D0=BD?= =?utf8?q?=D0=BE=D0=B7=20=D0=B7=D0=B0=20=D0=BC=D0=B5=D1=81=D1=8F=D1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- ...ata_to_monitvation_from_motivation_buh.php | 69 ++++++++++++- erp24/services/MotivationService.php | 97 ------------------- 2 files changed, 68 insertions(+), 98 deletions(-) diff --git a/erp24/scripts/tasks/task_33_insert_data_to_monitvation_from_motivation_buh.php b/erp24/scripts/tasks/task_33_insert_data_to_monitvation_from_motivation_buh.php index cb97050b..fae62877 100644 --- a/erp24/scripts/tasks/task_33_insert_data_to_monitvation_from_motivation_buh.php +++ b/erp24/scripts/tasks/task_33_insert_data_to_monitvation_from_motivation_buh.php @@ -6,12 +6,17 @@ use yii\db\Exception; use yii\db\Expression; +use yii\helpers\ArrayHelper; +use yii_app\records\CityStore; use yii_app\records\Motivation; use yii_app\records\MotivationBuh; use yii_app\records\MotivationBuhValue; use yii_app\records\MotivationCostsItem; use yii_app\records\MotivationValue; use yii_app\records\SchedulerTaskLog; +use yii_app\records\SelfCostProduct; +use yii_app\records\WriteOffs; +use yii_app\records\WriteOffsProducts; ini_set('max_execution_time', (string)(60 * 60 * 1)); // 1 час ini_set('display_errors', 'on'); @@ -35,7 +40,7 @@ $result = 0; $enable = true; $start = false; -$force = false; +$force = true; $minuteTimeInTask = date('i', $time); $fullTimeInTask = date('Y-m-d H:i:s', $time); @@ -88,6 +93,9 @@ try { $yearValue = intval(date('Y', $time)); } + $monthValue = 8; + $yearValue = 2024; + $month = MotivationBuh::find() ->select('id') ->andWhere(['month' => $monthValue]) @@ -177,6 +185,65 @@ try { ]); $motivationValue->save(); } + + + if ($motivationValue->value === MotivationCostsItem::findOne(['code' => 10])->id) { + $summa = []; + + if ($motivationValue->motivation_group_id <= 5 && $motivationValue->motivation_group_id >= 1) { + $period = Motivation::getWeekRange(null, $motivationValue->motivation_group_id); + } else if ($motivationValue->motivation_group_id == 10) { + $period = array( + 'startDate' => "$motivation->year-$motivation->month-01 00:00:00", + 'endDate' => "$motivation->year-$motivation->month-" . date('t', strtotime("$motivation->year-$motivation->month-01")) . " 23:59:59" + ); + } + + $stores = ArrayHelper::map(CityStore::find() + ->joinWith('storeGuid') + ->select('city_store.id as id, export_import_table.export_val as store_guid') + ->andWhere('city_store.id is not null') + ->andWhere('export_import_table.export_val is not null') + ->andWhere('export_import_table.export_val <> \'\'') + ->orderBy('id desc') + ->asArray() + ->all(), 'id', 'store_guid'); + + if (!empty(array_key_exists($motivation->store_id,$stores))) { + $writeOffs = WriteOffs::find() + ->andWhere(['type' => 'Расходные материалы (обеспечение продаж)']) + ->andWhere(['>', 'date', $period['startDate']]) + ->andWhere(['<=', 'date', $period['endDate']]) + ->andWhere(['store_id' => $stores[$motivation->store_id]]) + ->all(); + + foreach ($writeOffs as $writeOff) { + $writeOffProducts = WriteOffsProducts::find() + ->andWhere(['write_offs_id' => $writeOff->id]) + ->all(); + + foreach ($writeOffProducts as $offProduct) { + if (empty(array_search($writeOff->store_id, $stores))) { + continue; + } + + $price = SelfCostProduct::find() + ->andWhere(['product_guid' => $offProduct->product_id]) + ->andWhere(['store_id' => array_search($writeOff->store_id, $stores)]) + ->andWhere(['date' => date('Y-m-d', strtotime($writeOff->date))]) + ->one(); + if (empty($price)) { + $price = $offProduct; + } + + $summa += ($price->price * $offProduct->quantity); + } + } + } + + $motivationValue += $summa; + $motivationValue->save(); + } } $info = ' ================ test Task ' . $taskNum . ' stop ================'; diff --git a/erp24/services/MotivationService.php b/erp24/services/MotivationService.php index d816046d..d0219e66 100644 --- a/erp24/services/MotivationService.php +++ b/erp24/services/MotivationService.php @@ -238,17 +238,6 @@ class MotivationService $result[$costsItem->order][$groupAlias] = $actualValue; } - - // Подстановка значений расходных материалов - //190 - порядок для расходных материалов - $consumable = self::getConsumable($motivation->id); - $result[190]['week1'] = $consumable['week1']; - $result[190]['week2'] = $consumable['week2']; - $result[190]['week3'] = $consumable['week3']; - $result[190]['week4'] = $consumable['week4']; - $result[190]['week5'] = $consumable['week5']; - - // Сортировка результата по ключу (order) ksort($result); @@ -2021,90 +2010,4 @@ class MotivationService return $success; } - - public static function getConsumable($motivationId) - { - $summa = []; - $motivation = Motivation::findOne($motivationId); - $startDate = "$motivation->year-$motivation->month-01 00:00:00"; - $endDate = "$motivation->year-$motivation->month-" . date('t', strtotime($startDate)) . " 23:59:59"; - - $stores = ArrayHelper::map(CityStore::find() - ->joinWith('storeGuid') - ->select('city_store.id as id, export_import_table.export_val as store_guid') - ->andWhere('city_store.id is not null') - ->andWhere('export_import_table.export_val is not null') - ->andWhere('export_import_table.export_val <> \'\'') - ->orderBy('id desc') - ->asArray() - ->all(), 'id', 'store_guid'); - - if (!empty(array_key_exists($motivation->store_id,$stores))) { - $writeOffs = WriteOffs::find() - ->andWhere(['type' => 'Расходные материалы (обеспечение продаж)']) - ->andWhere(['>', 'date', $startDate]) - ->andWhere(['<=', 'date', $endDate]) - ->andWhere(['store_id' => $stores[$motivation->store_id]]) - ->all(); - - foreach ($writeOffs as $writeOff) { - $writeOffProducts = WriteOffsProducts::find() - ->andWhere(['write_offs_id' => $writeOff->id]) - ->all(); - - foreach ($writeOffProducts as $offProduct) { - if (empty(array_search($writeOff->store_id, $stores))) { - continue; - } - - $price = SelfCostProduct::find() - ->andWhere(['product_guid' => $offProduct->product_id]) - ->andWhere(['store_id' => array_search($writeOff->store_id, $stores)]) - ->andWhere(['date' => date('Y-m-d', strtotime($writeOff->date))]) - ->one(); - if (empty($price)) { - $price = $offProduct; - } - - - $sum = $price->price * $offProduct->quantity; - - $summa[] = ['date' => date('Y-m-d', strtotime($writeOff->date)), 'sum' => $sum]; - - } - } - } - - $weeklySums = array_fill(1, 5, 0); - $weeklySums = array_combine( - array_map(function($i) { return "week$i"; }, array_keys($weeklySums)), - $weeklySums - ); - - foreach ($summa as $value) { - $week = Motivation::getWeek($value['date']); - if ($week >= 1 && $week <= 5) { - $key = "week$week"; - $weeklySums[$key] += $value['sum']; - } - } - - $motivationValues = MotivationValue::find() - ->andWhere(['motivation_id' => $motivationId]) - ->andWhere(['value_id' => self::CODE_CONSUMABLES_SALES_SUPPORT]) - ->select('motivation_group_id, value_float') - ->all(); - - foreach ($motivationValues as $value) { - $week = $value['motivation_group_id']; - if ($week >= 1 && $week <= 5) { - $key = "week$week"; - $weeklySums[$key] += $value['value_float']; - } - } - - return $weeklySums; - - } - } -- 2.39.5