]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-85 Реализовать обмен данных с 1С Бухгалтерия
authormarina <m.zozirova@gmail.com>
Tue, 27 Aug 2024 06:36:57 +0000 (09:36 +0300)
committermarina <m.zozirova@gmail.com>
Tue, 27 Aug 2024 06:36:57 +0000 (09:36 +0300)
erp24/api2/controllers/DataBuhController.php
erp24/records/Motivation.php
erp24/scripts/tasks/task_33_insert_data_to_monitvation_from_motivation_buh.php [new file with mode: 0644]
erp24/services/MotivationServiceBuh.php

index 8268de9917e900180e2a8b8e5c42f9761930a285..d15c0c1911c800eab4b4c41757367d93b02ce614 100644 (file)
@@ -103,6 +103,7 @@ class DataBuhController extends BaseController
                 $apiCron->status = 2;
                 $apiCron->json_post = $request;
                 if ($apiCron->save()) {
+
                     MotivationServiceBuh::uploadBuhData($request);
                 }
 
index e6ecadd9033fb48e3768194377c3cbab7b375114..f308d3825592d7d864cb63dac9b33a11b494ee48 100644 (file)
@@ -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 (file)
index 0000000..6de9245
--- /dev/null
@@ -0,0 +1,152 @@
+<?php
+
+/**
+ * @var $time integer
+ */
+
+use yii\db\Exception;
+use yii\helpers\ArrayHelper;
+
+use yii\helpers\Json;
+use yii_app\records\ApiCronBuh;
+use yii_app\records\Firms;
+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\MotivationValueGroup;
+use yii_app\records\Users;
+use yii_app\records\UsersBonus;
+use yii_app\api3\modules\v1\models\orders\OrdersAmo;
+use yii_app\records\Sales;
+use yii_app\records\SchedulerTaskLog;
+use yii_app\records\NotifiableUser;
+
+ini_set('max_execution_time', (string)(60 * 60 * 1)); // 1 час
+ini_set('display_errors', 'on');
+ini_set('display_errors', 1);
+ini_set('display_startup_errors', 1);
+error_reporting(E_ALL);
+
+echo "time2_" . $time . "_time2 ";
+$taskNum = 33;
+$dateTask = date('Y-m-d H:i:s');
+$dateTaskStart = null;
+$dateTaskStop = null;
+$log = '';
+$error = '';
+$infoError = '';
+$infoText = '';
+$description = '';
+$result = 0;
+
+$enable = true;
+$start = false;
+$force = false;
+
+$minuetTimeInTask = date('i', $time);
+$fullTimeInTask = date('Y-m-d H:i:s', $time);
+
+try {
+    if (
+        (
+            (
+                date('H:i', $time) == "08:00" ||
+                date('H:i', $time) == "20:00"
+            )
+            || $force
+        )
+        && $enable
+    ) {
+
+        $dateTaskStart = date('Y-m-d H:i:s');
+        $info = ' ================ test Task ' . $taskNum . ' start ================';
+        echo $info;
+        $log .= $info;
+        $log .= $time;
+
+        $schedulerTaskLog = new SchedulerTaskLog();
+        $schedulerTaskLog->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
index 3bc463aa594e3ba36ddb5268ff4f1fa2ad2369a1..3ad27f31bfc8d962c0ecdd272c4b70f7510706b9 100644 (file)
@@ -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);
-    }
-
+    
 }