From f96accfd17aabfa582fe1eb02f1174477c00d544 Mon Sep 17 00:00:00 2001 From: marina Date: Mon, 26 Aug 2024 15:06:13 +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 | 22 +++ erp24/records/MotivationCostsItem.php | 26 +++- .../task_32_create_request_for_1c_buh.php | 137 ++++++++++++++++++ erp24/services/MotivationServiceBuh.php | 26 ++-- 5 files changed, 195 insertions(+), 17 deletions(-) create mode 100644 erp24/scripts/tasks/task_32_create_request_for_1c_buh.php diff --git a/erp24/api2/controllers/DataBuhController.php b/erp24/api2/controllers/DataBuhController.php index 0a3ca131..8268de99 100644 --- a/erp24/api2/controllers/DataBuhController.php +++ b/erp24/api2/controllers/DataBuhController.php @@ -113,5 +113,4 @@ class DataBuhController extends BaseController return $this->asJson(['request_id' => $requestId, 'response' => true]); } - } \ No newline at end of file diff --git a/erp24/records/Motivation.php b/erp24/records/Motivation.php index e843bd00..e2649b21 100644 --- a/erp24/records/Motivation.php +++ b/erp24/records/Motivation.php @@ -64,4 +64,26 @@ class Motivation extends \yii\db\ActiveRecord 'created_at' => 'Created At', ]; } + + public static function getWeekRangeForDate($date = null) + { + $date = $date ?? date('Y-m-d'); + + $day = date('d', $date); + $month = date('m', $date); + $year = date('m', $date); + + $weekNumber = intdiv($day - 1, 7) + 1; + + $startDay = ($weekNumber - 1) * 7 + 1; + $endDay = min($weekNumber * 7, date('t')); + + $startDate = \DateTime::createFromFormat('Y-m-d', "$year-$month-$startDay"); + $endDate = \DateTime::createFromFormat('Y-m-d', "$year-$month-$endDay"); + + return [ + 'start_time' => $startDate->format('Y-m-d'), + 'end_time' => $endDate->format('Y-m-d'), + ]; + } } diff --git a/erp24/records/MotivationCostsItem.php b/erp24/records/MotivationCostsItem.php index 1f9de0be..9ee01e75 100644 --- a/erp24/records/MotivationCostsItem.php +++ b/erp24/records/MotivationCostsItem.php @@ -2,6 +2,7 @@ namespace yii_app\records; +use yii\behaviors\BlameableBehavior; use yii\db\ActiveRecord; use yii\behaviors\TimestampBehavior; use yii\db\Expression; @@ -29,13 +30,19 @@ class MotivationCostsItem extends ActiveRecord const ITEM_DEFECT_DUE_TO_EQUIPMENT_FAILURE = 'Брак из-за поломки оборудования'; const ITEM_REGRADING = 'Пересорт'; - public static function writeOffsToMotivationItemMap($itemType) { + public static function writeOffsToMotivationItemMap($itemType) + { switch ($itemType) { - case WriteOffsErp::WRITE_OFFS_TYPE_BRAK: return self::ITEM_WRITE_OFF_OF_ILLIQUID_GOODS_SPOILAGE_EXPIRATION_OF_SHELF_LIFE; - case WriteOffsErp::WRITE_OFFS_TYPE_DELIVERY_BRAK: return self::ITEM_DEFECTIVE_DELIVERY; - case WriteOffsErp::WRITE_OFFS_TYPE_DUE_TO_EQUIPMENT_FAILURE_BRAK: return self::ITEM_DEFECT_DUE_TO_EQUIPMENT_FAILURE; - case WriteOffsErp::WRITE_OFFS_TYPE_RESORTING_DOES_NOT_COUNT_TOWARDS_COST: return self::ITEM_REGRADING; - default: return ''; + case WriteOffsErp::WRITE_OFFS_TYPE_BRAK: + return self::ITEM_WRITE_OFF_OF_ILLIQUID_GOODS_SPOILAGE_EXPIRATION_OF_SHELF_LIFE; + case WriteOffsErp::WRITE_OFFS_TYPE_DELIVERY_BRAK: + return self::ITEM_DEFECTIVE_DELIVERY; + case WriteOffsErp::WRITE_OFFS_TYPE_DUE_TO_EQUIPMENT_FAILURE_BRAK: + return self::ITEM_DEFECT_DUE_TO_EQUIPMENT_FAILURE; + case WriteOffsErp::WRITE_OFFS_TYPE_RESORTING_DOES_NOT_COUNT_TOWARDS_COST: + return self::ITEM_REGRADING; + default: + return ''; } } @@ -80,7 +87,7 @@ class MotivationCostsItem extends ActiveRecord } - /** + /** * {@inheritdoc} */ public function behaviors() @@ -90,6 +97,11 @@ class MotivationCostsItem extends ActiveRecord 'class' => TimestampBehavior::class, 'value' => new Expression('NOW()'), ], + [ + 'class' => BlameableBehavior::class, + 'createdByAttribute' => 'created_by', + 'updatedByAttribute' => 'updated_by', + ], ]; } 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 new file mode 100644 index 00000000..a64edb8d --- /dev/null +++ b/erp24/scripts/tasks/task_32_create_request_for_1c_buh.php @@ -0,0 +1,137 @@ +setTaskNum($taskNum) + ->setName('Task ' . $taskNum) + ->setDate($dateTask) + ->setDateStart($dateTaskStart) + ; + $validate = $schedulerTaskLog->validate(); + if ($validate) { + $schedulerTaskLog->save(); + } + + $weekRange = Motivation::getWeekRangeForDate(); + + 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); + } + } + + + + + $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 637d0802..b10a5349 100644 --- a/erp24/services/MotivationServiceBuh.php +++ b/erp24/services/MotivationServiceBuh.php @@ -28,14 +28,18 @@ class MotivationServiceBuh $inn = preg_replace('/^.*_/', '', $data['request_id']); $week = null; - if (self::validateWeek($start, $end)) { + $validate = self::validateWeek($start, $end); + + if ($validate !== 'month') { $week = self::getWeek($start) == self::getWeek($end) ? self::getWeek($start) : null; + if (!$validate && !$week) { + LogService::apiErrorLog(json_encode(["error_id" => 45, "error" => 'Указан некорректный период'], JSON_UNESCAPED_UNICODE)); + return; + } } - if (!$week) { - LogService::apiErrorLog(json_encode(["error_id" => 45, "error" => 'Указан некорректный период'], JSON_UNESCAPED_UNICODE)); - return; - } + $alias = $validate === 'month' ? 'month' : 'week' . $week; + $motivationValueGroup = MotivationValueGroup::findOne(['alias' => $alias]); if (!empty($data['cost_items'])) { foreach ($data['cost_items'] as $stores) { @@ -74,13 +78,11 @@ class MotivationServiceBuh $motivationBuhValue = MotivationBuhValue::findOne([ 'motivation_buh_id' => $motivationBuh->id, 'store_id' => $store['id'], - 'motivation_group_id' => $week, + 'motivation_group_id' => $motivationValueGroup->id, 'value_id' => $value->id, 'value_type' => MotivationCostsItem::DATA_TYPE_FLOAT, ]); - $motivationValueGroup = MotivationValueGroup::findOne(['alias' => 'week' . $week]); - if ($motivationBuhValue) { $motivationBuhValue->setAttribute('value_float', $item['summ']); } else { @@ -130,6 +132,13 @@ class MotivationServiceBuh ) return null; + if ( + date('d', strtotime($startTime)) == 1 + && + (date('d', strtotime($endTime)) == date('t', strtotime($endTime))) + ) + return 'month'; + if ( (!in_array(intval(date('j', strtotime($startTime))), [1, 8, 15, 22, 29])) || @@ -143,7 +152,6 @@ class MotivationServiceBuh if ((date('d', strtotime($endTime)) != date('t', strtotime($endTime))) && date('d', strtotime($startTime)) == 29) return null; - return true; } -- 2.39.5