From 22abc75e6cf90de382c3041de20218fcfe19e887 Mon Sep 17 00:00:00 2001 From: Marina Zozirova Date: Wed, 4 Sep 2024 12:12:39 +0000 Subject: [PATCH] =?utf8?q?C=D0=B1=D0=BE=D1=80=20=D0=B8=20=D0=B2=D1=8B?= =?utf8?q?=D0=B2=D0=BE=D0=B4=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=201?= =?utf8?q?=D0=A1=20=D0=B1=D1=83=D1=85=D0=B3=D0=B0=D0=BB=D1=82=D0=B5=D1=80?= =?utf8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../task_32_create_request_for_1c_buh.php | 61 +++++++------------ ...ata_to_monitvation_from_motivation_buh.php | 2 +- erp24/services/MotivationServiceBuh.php | 16 +++-- erp24/views/motivation/index.php | 15 ++--- 4 files changed, 37 insertions(+), 57 deletions(-) diff --git a/erp24/scripts/tasks/task_32_create_request_for_1c_buh.php b/erp24/scripts/tasks/task_32_create_request_for_1c_buh.php index 857d1788..f9254fd8 100644 --- a/erp24/scripts/tasks/task_32_create_request_for_1c_buh.php +++ b/erp24/scripts/tasks/task_32_create_request_for_1c_buh.php @@ -68,9 +68,7 @@ try { $weekRange = Motivation::getWeekRangeForDate(); - if ((date('d') % 7 == 0 || date('t') == date('d'))) { - foreach (Firms::getInn() as $key => $firm) { for ($week = Motivation::getWeek(); $week >= 1; $week--) { sleep(1); @@ -85,52 +83,16 @@ try { $date = strtotime("{$day}-{$month}-{$year}"); $weekRange = Motivation::getWeekRangeForDate($date); - $model = new ApiCronBuh(); - $model->date = date('Y-m-d H:i:s'); - $model->request_id = strval(strtotime($model->date) . '_' . $key); - - $model->json_post = Json::encode([ - 'request_id' => $model->request_id, - 'cost_items' => [ - 'start_time' => date('Y-m-d 00:00:00', strtotime($weekRange['start_time'])), - 'end_time' => date('Y-m-d 23:59:59', strtotime($weekRange['end_time'])), - ] - ]); - $model->inn = $key; - try { - $model->save(); - } catch (Exception $e) { - throw new Exception($e); - } + createApiCron($key, $weekRange); } } } else { foreach (Firms::getInn() as $key => $firm) { - $model = new ApiCronBuh(); - $model->date = date('Y-m-d H:i:s'); - $model->request_id = strval(strtotime($model->date) . '_' . $key); - $model->json_post = Json::encode([ - 'request_id' => $model->request_id, - 'cost_items' => [ - 'start_time' => date('Y-m-d 00:00:00', strtotime($weekRange['start_time'])), - 'end_time' => date('Y-m-d 23:59:59', strtotime($weekRange['end_time'])), - ] - ]); - $model->inn = $key; - try { - $model->save(); - } catch (Exception $e) { - throw new Exception($e); - } - + createApiCron($key, $weekRange); } } - if (!in_array(Admin::findOne([Yii::$app->user->id])->group_id, [AdminGroup::GROUP_IT])) { - return $this->render('/site/index'); - } - $info = ' ================ test Task ' . $taskNum . ' stop ================'; echo $info; @@ -169,4 +131,23 @@ if (empty($schedulerTaskLog)) { $validate = $schedulerTaskLog->validate(); if ($validate) { $schedulerTaskLog->save(); +} + +function createApiCron($key, $weekRange) { + $model = new ApiCronBuh(); + $model->date = date('Y-m-d H:i:s'); + $model->request_id = strval(strtotime($model->date) . '_' . $key); + $model->json_post = Json::encode([ + 'request_id' => $model->request_id, + 'cost_items' => [ + 'start_time' => date('Y-m-d 00:00:00', strtotime($weekRange['start_time'])), + 'end_time' => date('Y-m-d 23:59:59', strtotime($weekRange['end_time'])), + ] + ]); + $model->inn = $key; + try { + $model->save(); + } catch (Exception $e) { + throw new Exception($e); + } } \ No newline at end of file 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 d229169b..464d9c56 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 @@ -111,7 +111,7 @@ try { $motivationValue = new MotivationValue(); $motivationValue->setAttributes([ 'motivation_id' => $motivation->id, - 'motivation_group_id' => $value->id, + 'motivation_group_id' => $value->motivation_group_id, 'value_id' => $value->value_id, 'value_type' => MotivationCostsItem::DATA_TYPE_FLOAT, 'value_float' => $value->value_float, diff --git a/erp24/services/MotivationServiceBuh.php b/erp24/services/MotivationServiceBuh.php index 583d9aae..d04dd0c4 100644 --- a/erp24/services/MotivationServiceBuh.php +++ b/erp24/services/MotivationServiceBuh.php @@ -42,8 +42,12 @@ class MotivationServiceBuh $alias = $validate === 'month' ? 'month' : 'week' . $week; $motivationValueGroup = MotivationValueGroup::findOne(['alias' => $alias]); - $storeBuhIds = ArrayHelper::map(StoreGuidBuh::find()->select(['store_guid', 'store_id'])->asArray()->all(), 'store_guid', 'store_id'); - $motivationCostsItems = ArrayHelper::map(MotivationCostsItem::find()->select(['name', 'code'])->asArray()->all(), 'name', 'code'); + $storeBuhIds = ArrayHelper::map( + StoreGuidBuh::find()->select(['store_guid', 'store_id'])->asArray()->all(), + 'store_guid', 'store_id'); + $motivationCostsItems = ArrayHelper::map( + MotivationCostsItem::find()->select(['name', 'code'])->asArray()->all(), + 'name', 'code'); if (!empty($data['cost_items'])) { foreach ($data['cost_items'] as $stores) { @@ -52,7 +56,7 @@ class MotivationServiceBuh if (!$storeBuh) { LogService::apiErrorLog(json_encode(["error_id" => 45, "error" => 'Несуществующий магазин! Название: ' . $storeData['store_name'] . ' , guid: ' . $storeData['store_guid']], JSON_UNESCAPED_UNICODE)); - return; + continue; } $storeId = $storeBuhIds[$storeData['store_guid']]; @@ -62,7 +66,7 @@ class MotivationServiceBuh if (!$value) { LogService::apiErrorLog(json_encode(["error_id" => 46, "error" => $item['name']], JSON_UNESCAPED_UNICODE)); - return; + continue; } $motivationBuh = MotivationBuh::findOne([ @@ -85,7 +89,7 @@ class MotivationServiceBuh 'motivation_buh_id' => $motivationBuh->id, 'store_id' => $storeId, 'motivation_group_id' => $motivationValueGroup->id, - 'value_id' => $motivationCostsItems[$storeData['items']], + 'value_id' => $motivationCostsItems[$item['name']], 'value_type' => MotivationCostsItem::DATA_TYPE_FLOAT, ]); @@ -97,7 +101,7 @@ class MotivationServiceBuh 'motivation_buh_id' => $motivationBuh->id, 'store_id' => $storeId, 'motivation_group_id' => $motivationValueGroup->id, - 'value_id' => $motivationCostsItems[$storeData['items']], + 'value_id' => $motivationCostsItems[$item['name']], 'value_type' => MotivationCostsItem::DATA_TYPE_FLOAT, 'value_float' => $item['summ'] ]); diff --git a/erp24/views/motivation/index.php b/erp24/views/motivation/index.php index 189ea595..581dea58 100644 --- a/erp24/views/motivation/index.php +++ b/erp24/views/motivation/index.php @@ -159,8 +159,7 @@ $this->registerJsFile('/js/motivation/index.js', ['position' => \yii\web\View::P 'header' => 'Неделя 1
(1-7)', 'value' => function ($model) { - return $model["week1"] !== null ? FormatHelper::asDecimalMotivation($model["week1"]) : " "; - + return $model["week1"] !== null ? FormatHelper::asDecimalMotivation($model["week1"]) : "0"; }, ], [ @@ -169,8 +168,7 @@ $this->registerJsFile('/js/motivation/index.js', ['position' => \yii\web\View::P 'header' => 'Неделя 2
(8-14)', 'value' => function ($model) { - return $model["week2"] !== null ? FormatHelper::asDecimalMotivation($model["week2"]) : " "; - + return $model["week2"] !== null ? FormatHelper::asDecimalMotivation($model["week2"]) : "0"; }, ], @@ -180,8 +178,7 @@ $this->registerJsFile('/js/motivation/index.js', ['position' => \yii\web\View::P 'header' => 'Неделя 3
(15-21)', 'value' => function ($model) { - return $model["week3"] !== null ? FormatHelper::asDecimalMotivation($model["week3"]) : " "; - + return $model["week3"] !== null ? FormatHelper::asDecimalMotivation($model["week3"]) : "0"; }, ], @@ -191,8 +188,7 @@ $this->registerJsFile('/js/motivation/index.js', ['position' => \yii\web\View::P 'header' => 'Неделя 4
(22-28)', 'value' => function ($model) { - return $model["week4"] !== null ? FormatHelper::asDecimalMotivation($model["week4"]) : " "; - + return $model["week4"] !== null ? FormatHelper::asDecimalMotivation($model["week4"]) : "0"; }, ], @@ -202,8 +198,7 @@ $this->registerJsFile('/js/motivation/index.js', ['position' => \yii\web\View::P 'header' => $week5Header, 'value' => function ($model) { - return $model["week5"] !== null ? FormatHelper::asDecimalMotivation($model["week5"]) : " "; - + return $model["week5"] !== null ? FormatHelper::asDecimalMotivation($model["week5"]) : "0"; }, ], [ -- 2.39.5