]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-85 Реализовать обмен данных с 1С Бухгалтерия
authormarina <m.zozirova@gmail.com>
Thu, 15 Aug 2024 08:14:34 +0000 (11:14 +0300)
committermarina <m.zozirova@gmail.com>
Thu, 15 Aug 2024 08:14:34 +0000 (11:14 +0300)
поправлено сохранение при получении

erp24/api2/config/api2.config.php
erp24/api2/controllers/DataBuhController.php
erp24/controllers/CronController.php
erp24/records/Firms.php

index 8aaaf73315dc6eca4ede45b761d1acb2ccdceb94..8cba7a248e2640b216b38afbd61657368ac3afdc 100644 (file)
@@ -39,6 +39,7 @@ return [
                 'auth' => 'auth/login',
                 'delivery/admin-auth' => 'delivery/admin-auth',
                 ['class' => 'yii\rest\UrlRule', 'controller' => ['task']],
+                'POST data-buh/request/<inn:\d+>' => 'data-buh/request'
             ],
         ],
         'request' => [
index 6ac6b6a6e34a3ed8795db6e7495324c4b9c0e539..4f613e53a23d2ec74c429c0235eacef283062d63 100644 (file)
@@ -7,6 +7,7 @@ use Exception;
 use Yii;
 use yii\helpers\Json;
 use yii_app\records\ApiCronBuh;
+use yii_app\records\Firms;
 
 class DataBuhController extends BaseController
 {
@@ -15,50 +16,53 @@ class DataBuhController extends BaseController
         "/var/www/erp24/api2/json_buh";
 //          "/var/www/www-root/data/www/api.bazacvetov24.ru/data/json";
 
-    public function actionRequest()
+    public function actionRequest($inn)
     {
         \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
-        \Yii::$app->response->headers->set('firm', 'IP_Belov');
 
         $request = \Yii::$app->request->getRawBody();
 
-        try {
-            $result = Json::decode($request);
-        } catch (\Exception $ex) {
-            return $this->asJson(['error' => ['code' => 400, 'message' => 'Json body invalid']]);
-        }
+        if (array_key_exists($inn, Firms::getInn())) {
+            try {
+                $result = Json::decode($request);
+            } catch (\Exception $ex) {
+                return $this->asJson(['error' => ['code' => 400, 'message' => 'Json body invalid']]);
+            }
 
-        $result['ver'] = $result['ver'] ?? '';
+            $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"]);
-        }
+            if (empty($result['ver']) || round($result['ver'], 2) < 1.1) {
+                return $this->asJson(["error_id" => 1, "error" => "minimal version is 1.1"]);
+            }
 
-        $json = '';
+            $json = '';
 
-        try {
-            $apiCronTest = ApiCronBuh::find()
-                ->where(['status' => 0])
-                ->orderBy(['date' => SORT_ASC])
-                ->one();
+            try {
+                $apiCronTest = ApiCronBuh::find()
+                    ->where(['status' => 0])
+                    ->orderBy(['date' => SORT_ASC])
+                    ->one();
 
-            if ($apiCronTest) {
-                $json = $apiCronTest->json_post;
+                if ($apiCronTest) {
+                    $json = $apiCronTest->json_post;
 
-                $apiCronTest->status = 1;
-                $apiCronTest->date_up = date("Y-m-d H:i:s");
+                    $apiCronTest->status = 1;
+                    $apiCronTest->date_up = date("Y-m-d H:i:s");
 
-                $validate = $apiCronTest->validate();
-                if ($validate) {
-                    $apiCronTest->save();
+                    $validate = $apiCronTest->validate();
+                    if ($validate) {
+                        $apiCronTest->save();
+                    }
                 }
+            } catch (Exception $e) {
+                return $e;
             }
-        } catch (Exception $e) {
-            return $e;
-        }
 
-        return $this->asJson(json_decode($json, true));
+            return $this->asJson(json_decode($json, true));
+        } else {
+            return 'Такого ИНН нет в списке';
+        }
     }
 
 
@@ -98,7 +102,7 @@ class DataBuhController extends BaseController
             file_put_contents(self::OUT_DIR . '/error_buh_upload.txt', PHP_EOL . 'result empty', FILE_APPEND);
         }
 
-        return $this->asJson(['response' => true]);
+        return $this->asJson(['request_id' => $requestId,'response' => true]);
     }
 
 }
\ No newline at end of file
index 0c58e5cbce5183eb7888af43fd47016f7ecebcda..9c4df8483b5e0913c908c812ada19c9df9f40557 100644 (file)
@@ -40,7 +40,7 @@ class CronController extends Controller
         }
         $dataProvider = new ActiveDataProvider([
             'query' => ApiCronBuh::find()
-                ->orderBy('request_id desc'),
+                ->orderBy('date_up desc'),
             'pagination' => [
                 'pageSize' => 30
             ],
index 87b64dbec21234c4d2d9298335966081c1f2fe93..e29ac619eb939545ab4d4a0a06c3a40cda1f4f3e 100644 (file)
@@ -50,6 +50,16 @@ class Firms extends \yii\db\ActiveRecord
         return 'firms';
     }
 
+    public static function getInn()
+    {
+        return array(
+            '525911109960' => 'ИП Белов',
+            '526003058422' => 'ИП Кузнецов',
+            '526107741457' => 'ИП Лазарев',
+            '891103803770' => 'ИП Мочалина'
+        );
+    }
+
     /**
      * {@inheritdoc}
      */