]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-85 Реализовать обмен данных с 1С Бухгалтерия
authormarina <m.zozirova@gmail.com>
Tue, 6 Aug 2024 09:21:15 +0000 (12:21 +0300)
committermarina <m.zozirova@gmail.com>
Tue, 6 Aug 2024 09:21:15 +0000 (12:21 +0300)
erp24/api2/controllers/DataBuhController.php [new file with mode: 0644]
erp24/api2/controllers/DataBuhTestController.php [deleted file]
erp24/migrations/m240805_071431_create_api_cron_buh_table.php [new file with mode: 0644]
erp24/migrations/m240805_071431_create_api_cron_buh_test_table.php [deleted file]
erp24/records/ApiCronBuh.php [new file with mode: 0644]
erp24/records/ApiCronBuhTest.php [deleted file]

diff --git a/erp24/api2/controllers/DataBuhController.php b/erp24/api2/controllers/DataBuhController.php
new file mode 100644 (file)
index 0000000..b37dbd7
--- /dev/null
@@ -0,0 +1,95 @@
+<?php
+
+namespace app\api2\controllers;
+
+
+use app\controllers\BaseController;
+use Exception;
+use Yii;
+use yii\helpers\Json;
+use yii_app\records\ApiCronBuh;
+
+class DataBuhController extends BaseController
+{
+    public function actionRequest() {
+        \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
+
+        $request = \Yii::$app->request->getRawBody();
+
+        try {
+            $result = Json::decode($request);
+        } catch (\Exception $ex) {
+            return $this->asJson(['error' => ['code' => 400, 'message' => 'Json body invalid']]);
+        }
+
+        $result['ver'] = $result['ver'] ?? '';
+
+
+        if (empty($result['ver']) || round($result['ver'], 2) < 1.1) {
+            return $this->asJson(["error_id" => 1, "error" => "minimal version is 1.1"]);
+        }
+
+        $json = '';
+
+        try {
+            $apiCronTest = ApiCronBuh::find()
+                ->where(['status' => 0])
+                ->orderBy(['date' => SORT_ASC])
+                ->one();
+            if ($apiCronTest) {
+                $json = $apiCronTest->json_post;
+
+                $apiCronTest->status = 1;
+                $apiCronTest->date_up = date("Y-m-d H:i:s");
+
+                $validate = $apiCronTest->validate();
+                if ($validate) {
+                    $apiCronTest->save();
+                }
+            }
+        } catch (Exception $e) {
+
+        }
+
+        return $this->asJson(json_decode($json, true));
+    }
+
+
+    public function actionUpload() {
+        set_time_limit(600);
+        Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
+
+        $request = Yii::$app->request->getRawBody();
+
+        try {
+            $result = Json::decode($request);
+        } catch (Exception $ex) {
+            return $this->asJson(['error' => ['code' => 400, 'message' => 'Json body invalid']]);
+        }
+
+        $requestId = '';
+        if (!empty($result["request_id"])) {
+            $requestId = $result["request_id"];
+        }
+
+        try {
+
+            $apiCronTest = new ApiCronBuh();
+            $apiCronTest->date = date("Y-m-d H:i:s");
+            $apiCronTest->date_up = date("Y-m-d H:i:s");
+            $apiCronTest->status = 2;
+            $apiCronTest->json_post = $request;
+            $apiCronTest->request_id = $requestId;
+            $validate = $apiCronTest->validate();
+            if ($validate) {
+                $apiCronTest->save();
+            }
+
+        } catch (Exception $e) {
+
+        }
+
+        return $this->asJson(['response' => true]);
+    }
+
+}
\ No newline at end of file
diff --git a/erp24/api2/controllers/DataBuhTestController.php b/erp24/api2/controllers/DataBuhTestController.php
deleted file mode 100644 (file)
index d9a7729..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-<?php
-
-namespace app\api2\controllers;
-
-use app\controllers\BaseController;
-use Exception;
-use Yii;
-use yii\helpers\Json;
-use yii_app\records\ApiCronBuhTest;
-
-class DataBuhTestController extends BaseController
-{
-    public function actionRequest() {
-        \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
-
-        $request = \Yii::$app->request->getRawBody();
-
-        try {
-            $result = Json::decode($request);
-        } catch (\Exception $ex) {
-            return $this->asJson(['error' => ['code' => 400, 'message' => 'Json body invalid']]);
-        }
-
-        $result['ver'] = $result['ver'] ?? '';
-
-
-        if (empty($result['ver']) || round($result['ver'], 2) < 1.1) {
-            return $this->asJson(["error_id" => 1, "error" => "minimal version is 1.1"]);
-        }
-
-        $json = '';
-
-        try {
-            $apiCronTest = ApiCronBuhTest::find()
-                ->where(['status' => 0])
-                ->andWhere(['direct_id' => 1])
-                ->orderBy(['date' => SORT_ASC])
-                ->one();
-            if ($apiCronTest) {
-                $json = $apiCronTest->json_post;
-
-                $apiCronTest->status = 1;
-                $apiCronTest->date_up = date("Y-m-d H:i:s");
-
-                $validate = $apiCronTest->validate();
-                if ($validate) {
-                    $apiCronTest->save();
-                }
-            }
-        } catch (Exception $e) {
-
-        }
-
-        return $this->asJson(json_decode($json, true));
-    }
-
-
-    public function actionUpload() {
-        set_time_limit(600);
-        Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
-
-        $request = Yii::$app->request->getRawBody();
-
-        try {
-            $result = Json::decode($request);
-        } catch (Exception $ex) {
-            return $this->asJson(['error' => ['code' => 400, 'message' => 'Json body invalid']]);
-        }
-
-        $requestId = '';
-        if (!empty($result["request_id"])) {
-            $requestId = $result["request_id"];
-        }
-
-        try {
-
-
-            $apiCronTest = new ApiCronBuhTest();
-            $apiCronTest->date = date("Y-m-d H:i:s");
-            $apiCronTest->date_up = date("Y-m-d H:i:s");
-            $apiCronTest->status = 2;
-            $apiCronTest->json_post = $request;
-            $apiCronTest->request_id = $requestId;
-            $apiCronTest->direct_id = 2;
-            $validate = $apiCronTest->validate();
-            if ($validate) {
-                $apiCronTest->save();
-            }
-
-        } catch (Exception $e) {
-
-        }
-
-        return $this->asJson(['response' => true]);
-    }
-
-}
\ No newline at end of file
diff --git a/erp24/migrations/m240805_071431_create_api_cron_buh_table.php b/erp24/migrations/m240805_071431_create_api_cron_buh_table.php
new file mode 100644 (file)
index 0000000..d531b5d
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Handles the creation of table `{{%api_cron_buh_test}}`.
+ */
+class m240805_071431_create_api_cron_buh_table extends Migration
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $this->createTable('{{%erp24.api_cron_buh}}', [
+            'id' => $this->primaryKey(),
+            'date' => $this->dateTime()->notNull(),
+            'date_up' => $this->dateTime()->notNull(),
+            'status' => $this->integer()->notNull()->defaultValue(0)->comment('Статус'),
+            'json_post' => $this->text()->null()->comment('Тело запроса'),
+            'request_id' => $this->string(36)->notNull()->comment('id запроса'),
+        ]);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown()
+    {
+        $this->dropTable('{{%erp24.api_cron_buh}}');
+    }
+}
diff --git a/erp24/migrations/m240805_071431_create_api_cron_buh_test_table.php b/erp24/migrations/m240805_071431_create_api_cron_buh_test_table.php
deleted file mode 100644 (file)
index 6d56733..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php
-
-use yii\db\Migration;
-
-/**
- * Handles the creation of table `{{%api_cron_buh_test}}`.
- */
-class m240805_071431_create_api_cron_buh_test_table extends Migration
-{
-    /**
-     * {@inheritdoc}
-     */
-    public function safeUp()
-    {
-        $this->createTable('{{%api_cron_buh_test}}', [
-            'id' => $this->primaryKey(),
-            'date' => $this->dateTime()->notNull(),
-            'date_up' => $this->dateTime()->notNull(),
-            'status' => $this->integer()->notNull()->defaultValue(0)->comment('Статус'),
-            'json_post' => $this->text()->null()->comment('Тело запроса'),
-            'request_id' => $this->string(36)->notNull()->comment('id запроса'),
-        ]);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function safeDown()
-    {
-        $this->dropTable('{{%api_cron_buh_test}}');
-    }
-}
diff --git a/erp24/records/ApiCronBuh.php b/erp24/records/ApiCronBuh.php
new file mode 100644 (file)
index 0000000..cc77bec
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "api_cron_buh_test".
+ *
+ * @property int $id ID
+ * @property string $date
+ * @property string $date_up
+ * @property int $status Статус
+ * @property string|null $json_post Тело запроса
+ * @property string $request_id id запроса
+ */
+class ApiCronBuh extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'api_cron_buh_test';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['date', 'date_up', 'request_id'], 'required'],
+            [['date', 'date_up'], 'safe'],
+            [['status'], 'integer'],
+            [['json_post'], 'string'],
+            [['request_id'], 'string', 'max' => 36],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'ID',
+            'date' => 'Date',
+            'date_up' => 'Date Up',
+            'status' => 'Status',
+            'json_post' => 'Json Post',
+            'request_id' => 'Request ID',
+        ];
+    }
+}
diff --git a/erp24/records/ApiCronBuhTest.php b/erp24/records/ApiCronBuhTest.php
deleted file mode 100644 (file)
index 48eb250..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-
-namespace yii_app\records;
-
-use Yii;
-
-/**
- * This is the model class for table "api_cron_buh_test".
- *
- * @property int $id ID
- * @property string $date
- * @property string $date_up
- * @property int $status Статус
- * @property string|null $json_post Тело запроса
- * @property string $request_id id запроса
- */
-class ApiCronBuhTest extends \yii\db\ActiveRecord
-{
-    /**
-     * {@inheritdoc}
-     */
-    public static function tableName()
-    {
-        return 'api_cron_buh_test';
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function rules()
-    {
-        return [
-            [['date', 'date_up', 'request_id'], 'required'],
-            [['date', 'date_up'], 'safe'],
-            [['status'], 'integer'],
-            [['json_post'], 'string'],
-            [['request_id'], 'string', 'max' => 36],
-        ];
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function attributeLabels()
-    {
-        return [
-            'id' => 'ID',
-            'date' => 'Date',
-            'date_up' => 'Date Up',
-            'status' => 'Status',
-            'json_post' => 'Json Post',
-            'request_id' => 'Request ID',
-        ];
-    }
-}