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

index d15c0c1911c800eab4b4c41757367d93b02ce614..a20e2f618f1e6116ea98d1b74c4e7da645c288a2 100644 (file)
@@ -109,7 +109,7 @@ class DataBuhController extends BaseController
 
             }
         } catch (Exception $e) {
-            file_put_contents(self::OUT_DIR . '/error_buh_upload.txt', PHP_EOL . 'result empty', FILE_APPEND);
+//            file_put_contents(self::OUT_DIR . '/error_buh_upload.txt', PHP_EOL . 'result empty', FILE_APPEND);
         }
 
         return $this->asJson(['request_id' => $requestId, 'response' => true]);
index 14fee7b8dcbd0a1e5367662a1a095b19c7d17e53..399fc071593948b0ddbc00201bab5faab05c857d 100644 (file)
@@ -67,6 +67,7 @@ class Motivation extends \yii\db\ActiveRecord
 
     public static function getWeekRangeForDate($date = null)
     {
+
         $date = $date ?? strtotime(date('Y-m-d'));
 
         $day = date('d', $date);
@@ -89,8 +90,8 @@ class Motivation extends \yii\db\ActiveRecord
 
     public static function getWeek($date = null)
     {
-        $date = $date ?? date("d");
-        $d = date("d", strtotime($date));
+        $date = $date ?? date('d-m-Y');
+        $d = date('j', strtotime($date));
         return intval(floor(($d - 1) / 7) + 1);
 
     }
index c5c4c0b695cfd6aa8d155d0310c01a15a5f538d6..857d1788a0b563bf1fec3d65353bfc6ca3cf0879 100644 (file)
@@ -5,6 +5,8 @@
  */
 
 use yii\helpers\Json;
+use yii_app\records\Admin;
+use yii_app\records\AdminGroup;
 use yii_app\records\ApiCronBuh;
 use yii_app\records\Firms;
 use yii_app\records\Motivation;
@@ -66,27 +68,68 @@ try {
 
         $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);
+
+        if ((date('d') % 7 == 0 || date('t') == date('d'))) {
+
+            foreach (Firms::getInn() as $key => $firm) {
+                for ($week = Motivation::getWeek(); $week >= 1; $week--) {
+                    sleep(1);
+                    $day = $week * 7;
+                    $month = date('m');
+                    $year = date('Y');
+
+                    if ($week == 5) {
+                        $day = ($week - 1) * 7 + 1;
+                    }
+
+                    $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);
+                    }
+                }
+            }
+        } 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);
+                }
+
             }
-        }
 
+        }
 
+        if (!in_array(Admin::findOne([Yii::$app->user->id])->group_id, [AdminGroup::GROUP_IT])) {
+            return $this->render('/site/index');
+        }
 
 
         $info = ' ================ test Task ' . $taskNum . ' stop ================';
index 3ad27f31bfc8d962c0ecdd272c4b70f7510706b9..b61108c22107e2fcf3bc8d6592f96a83ff5783a0 100644 (file)
@@ -47,9 +47,12 @@ class MotivationServiceBuh
                             ->andWhere(['store_guid' => $storeData['store_guid']])
                             ->one();
 
-                        if (isset($storeBuh)) {
-                            $store = CityStore::getCityStoreById($storeBuh->store_id, true);
+                        if (!$storeBuh) {
+                            LogService::apiErrorLog(json_encode(["error_id" => 45, "error" => 'Несуществующий магазин! Название: ' . $storeData['store_name'] . ' , guid: ' . $storeData['store_guid']], JSON_UNESCAPED_UNICODE));
+                            return;
+                        }
 
+                            $store = CityStore::getCityStoreById($storeBuh->store_id, true);
                             foreach ($storeData['items'] as $items) {
                                 foreach ($items as $item) {
                                     $value = MotivationCostsItem::findOne(['name' => $item['name']]);
@@ -103,7 +106,7 @@ class MotivationServiceBuh
                                     }
                                 }
                             }
-                        }
+
 
                     }
                 }