From 21652ca797663c057c2289eba05d6113169d380c Mon Sep 17 00:00:00 2001 From: marina Date: Tue, 27 Aug 2024 09:36:57 +0300 Subject: [PATCH] =?utf8?q?ERP-85=20=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?utf8?q?=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20=D0=BE=D0=B1=D0=BC=D0=B5=D0=BD?= =?utf8?q?=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D1=81=201=D0=A1=20?= =?utf8?q?=D0=91=D1=83=D1=85=D0=B3=D0=B0=D0=BB=D1=82=D0=B5=D1=80=D0=B8?= =?utf8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/api2/controllers/DataBuhController.php | 1 + erp24/records/Motivation.php | 8 + ...ata_to_monitvation_from_motivation_buh.php | 152 ++++++++++++++++++ erp24/services/MotivationServiceBuh.php | 15 +- 4 files changed, 164 insertions(+), 12 deletions(-) create mode 100644 erp24/scripts/tasks/task_33_insert_data_to_monitvation_from_motivation_buh.php diff --git a/erp24/api2/controllers/DataBuhController.php b/erp24/api2/controllers/DataBuhController.php index 8268de99..d15c0c19 100644 --- a/erp24/api2/controllers/DataBuhController.php +++ b/erp24/api2/controllers/DataBuhController.php @@ -103,6 +103,7 @@ class DataBuhController extends BaseController $apiCron->status = 2; $apiCron->json_post = $request; if ($apiCron->save()) { + MotivationServiceBuh::uploadBuhData($request); } diff --git a/erp24/records/Motivation.php b/erp24/records/Motivation.php index e6ecadd9..f308d382 100644 --- a/erp24/records/Motivation.php +++ b/erp24/records/Motivation.php @@ -87,6 +87,14 @@ class Motivation extends \yii\db\ActiveRecord ]; } + public static function getWeek($date = null) + { + $date = $date ?? $date('d'); + $d = date("d", strtotime($date)); + return intval(floor(($d - 1) / 7) + 1); + + } + public static function getAdjustmentEditors() { return array( AdminGroup::GROUP_IT, 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 new file mode 100644 index 00000000..6de9245e --- /dev/null +++ b/erp24/scripts/tasks/task_33_insert_data_to_monitvation_from_motivation_buh.php @@ -0,0 +1,152 @@ +setTaskNum($taskNum) + ->setName('Task ' . $taskNum) + ->setDate($dateTask) + ->setDateStart($dateTaskStart); + $validate = $schedulerTaskLog->validate(); + if ($validate) { + $schedulerTaskLog->save(); + } + + $motivationGroup = MotivationValueGroup::findOne(['alias' => 'week' . Motivation::getWeek()]); + + $motivationBuhValue = MotivationBuhValue::find() + ->andWhere(['motivation_group_id' => $motivationGroup->id]) + ->groupBy('store_id, value_id, motivation_buh_id') + ->select('sum(value_float) as value_float', 'motivation_buh_id, value_id') + ->asArray(); + + foreach ($motivationBuhValue as $value) { + + $motivationBuh = MotivationBuh::findOne([$motivationBuhValue['motivation_buh_id']]); + + $motivation = Motivation::findOne([ + 'year' => $motivationBuh->year, + 'month' => $motivationBuh->month, + 'store_id' => $motivationBuhValue['store_id'], + ]); + + if (!$motivation) { + $motivation = new Motivation(); + $motivation->setAttributes([ + 'year' => $motivationBuh->year, + 'month' => $motivationBuh->month, + 'store_id' => $value['store_id'] + ]); + $motivation->save(); + } + + $motivationValue = new MotivationValue(); + $motivationValue->setAttributes([ + 'motivation_id' => $motivation->id, + 'motivation_group_id' => $motivationGroup->id, + 'value_id' => $value['value_id'], + 'value_type' => MotivationCostsItem::DATA_TYPE_FLOAT, + 'value_float' => $value['value_float'], + ]); + } + + $info = ' ================ test Task ' . $taskNum . ' stop ================'; + echo $info; + $log .= $info; + $log .= ' date >= ' . strtotime("-1 week", time()); + $dateTaskStop = date('Y-m-d H:i:s'); + } else { + $info = ' Task ' . $taskNum . ' skip '; + echo $info; + $log .= $info; + } +} catch (Exception $e) { + $error = 'Exception: ' . $e->getMessage() . ' ' . $e->getFile() . ' >>> ' . $e->getLine(); +} + +if (empty($schedulerTaskLog)) { + $schedulerTaskLog = new SchedulerTaskLog(); + $schedulerTaskLog->setTaskNum($taskNum) + ->setName('Task ' . $taskNum) + ->setDate($dateTask) + ->setDateStart($dateTaskStart) + ->setDateStop($dateTaskStop) + ->setDescription($description) + ->setError($error) + ->setInfo($infoText) + ->setLog($log); +} else { + $schedulerTaskLog->setDateStop($dateTaskStop) + ->setDescription($description) + ->setError($error) + ->setInfo($infoText) + ->setLog($log); +} +$validate = $schedulerTaskLog->validate(); +if ($validate) { + $schedulerTaskLog->save(); +} \ No newline at end of file diff --git a/erp24/services/MotivationServiceBuh.php b/erp24/services/MotivationServiceBuh.php index 3bc463aa..3ad27f31 100644 --- a/erp24/services/MotivationServiceBuh.php +++ b/erp24/services/MotivationServiceBuh.php @@ -2,6 +2,7 @@ namespace yii_app\services; +use yii_app\records\Motivation; use yii_app\records\MotivationBuh; use yii_app\records\MotivationBuhValue; use yii_app\records\StoreGuidBuh; @@ -27,11 +28,10 @@ class MotivationServiceBuh $month = date('m', strtotime($end)); $inn = $data['inn']; $week = null; - $validate = self::validateWeek($start, $end); if ($validate !== 'month') { - $week = self::getWeek($start) == self::getWeek($end) ? self::getWeek($start) : null; + $week = Motivation::getWeek($start) == Motivation::getWeek($end) ? Motivation::getWeek($start) : null; if (!$validate && !$week) { LogService::apiErrorLog(json_encode(["error_id" => 45, "error" => 'Указан некорректный период'], JSON_UNESCAPED_UNICODE)); return; @@ -40,7 +40,6 @@ class MotivationServiceBuh $alias = $validate === 'month' ? 'month' : 'week' . $week; $motivationValueGroup = MotivationValueGroup::findOne(['alias' => $alias]); - if (!empty($data['cost_items'])) { foreach ($data['cost_items'] as $stores) { foreach ($stores as $storeData) { @@ -113,7 +112,6 @@ class MotivationServiceBuh LogService::apiErrorLog(json_encode(["error_id" => 48, "error" => $exception->getMessage() . ' ' . $exception->getFile() . ' ' . $exception->getLine()], JSON_UNESCAPED_UNICODE)); } - } private static function validateWeek($startTime, $endTime) @@ -154,13 +152,6 @@ class MotivationServiceBuh return true; } - - - static function getWeek($date) - { - $d = date("d", strtotime($date)); - return intval(floor(($d - 1) / 7) + 1); - } - + } -- 2.39.5