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

index 4f613e53a23d2ec74c429c0235eacef283062d63..cb75aad32496b34e97cf66229ddd89fec5fbd53a 100644 (file)
@@ -40,8 +40,9 @@ class DataBuhController extends BaseController
 
             try {
                 $apiCronTest = ApiCronBuh::find()
-                    ->where(['status' => 0])
-                    ->orderBy(['date' => SORT_ASC])
+                    ->andWhere(['inn' => $inn])
+                    ->andWhere(['status' => 0])
+                    ->orderBy(['id' => SORT_ASC])
                     ->one();
 
                 if ($apiCronTest) {
index 9c4df8483b5e0913c908c812ada19c9df9f40557..965eebcf7e56225deb046673a1c9b2161ca68ae9 100644 (file)
@@ -7,40 +7,47 @@ use yii\db\Exception;
 use yii\helpers\Json;
 use yii\web\Controller;
 use yii_app\records\ApiCronBuh;
+use yii_app\records\Firms;
 
 class CronController extends Controller
 {
-    public function action1c() {
+    public function action1c()
+    {
         return $this->render('1c');
     }
 
     /**
      * @throws Exception
      */
-    public function action1cBuh() {
+    public function action1cBuh()
+    {
         $request = \Yii::$app->request->post();
 
         if ($request && !empty($request['start_date']) && !empty($request['end_date'])) {
-            $model = new ApiCronBuh();
-            $model->date = date('Y-m-d H:i:s');
-            $model->request_id = strval(strtotime($model->date));
-            $model->json_post = Json::encode([
-                'request_id' => $model->request_id,
-                'cost_items' => [
-                    'start_time' => date('Y-m-d 00:00:00', strtotime($request['start_date'])),
-                    'end_time' => date('Y-m-d 23:59:59', strtotime($request['end_date'])),
-                ]
-            ]);
-
-            try {
-                $model->save();
-            } catch (Exception $e) {
-                throw new Exception($e);
+            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($request['start_date'])),
+                        'end_time' => date('Y-m-d 23:59:59', strtotime($request['end_date'])),
+                    ]
+                ]);
+                $model->inn = $key;
+
+                try {
+                    $model->save();
+                } catch (Exception $e) {
+                    throw new Exception($e);
+                }
             }
         }
+
         $dataProvider = new ActiveDataProvider([
             'query' => ApiCronBuh::find()
-                ->orderBy('date_up desc'),
+                ->orderBy('id desc'),
             'pagination' => [
                 'pageSize' => 30
             ],
diff --git a/erp24/migrations/m240815_081804_add_new_column_to_api_cron_buh.php b/erp24/migrations/m240815_081804_add_new_column_to_api_cron_buh.php
new file mode 100644 (file)
index 0000000..2ab6760
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m240815_081804_add_new_column_to_api_cron_buh
+ */
+class m240815_081804_add_new_column_to_api_cron_buh extends Migration
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $this->dropColumn('api_cron_buh', 'request_id');
+        $this->addColumn('api_cron_buh', 'request_id', $this->string(36)->unique()->comment('ID запроса'));
+        $this->addColumn('api_cron_buh', 'inn', $this->bigInteger()->comment('ИНН'));
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown()
+    {
+        $this->dropColumn('api_cron_buh', 'inn');
+        $this->dropColumn('api_cron_buh', 'request_id');
+        $this->addColumn('api_cron_buh', 'request_id',  $this->string(36)->comment('id запроса'),);
+    }
+}
index 8e34dfea24bbfa1a6ed57cd897870a41c9f8b0cd..ea7455b73b23aaf25e69bab183ce9227cb54bd39 100644 (file)
@@ -13,6 +13,7 @@ use Yii;
  * @property int $status Статус
  * @property string|null $json_post Тело запроса
  * @property string $request_id id запроса
+ * @property int $inn ИНН
  */
 class ApiCronBuh extends \yii\db\ActiveRecord
 {
@@ -35,9 +36,9 @@ class ApiCronBuh extends \yii\db\ActiveRecord
     public function rules()
     {
         return [
-            [['date','request_id'], 'required'],
+            [['date','request_id', 'inn'], 'required'],
             [['date', 'date_up'], 'safe'],
-            [['status'], 'integer'],
+            [['status', 'inn'], 'integer'],
             [['json_post'], 'string'],
             [['request_id'], 'string', 'max' => 36],
         ];
@@ -55,6 +56,7 @@ class ApiCronBuh extends \yii\db\ActiveRecord
             'status' => 'Status',
             'json_post' => 'Тело запроса',
             'request_id' => 'ID запроса',
+            'inn' => 'ИНН',
         ];
     }
 
index d65255ddb34da29f3be55c5cac5abd40d78b9518..94d04186ead502a402390287204386a429119bc2 100644 (file)
@@ -5,6 +5,7 @@ use kartik\grid\GridView;
 use yii\helpers\Html;
 use yii\widgets\ActiveForm;
 use yii_app\records\ApiCronBuh;
+use yii_app\records\Firms;
 
 
 /** @var yii\web\View $this */
@@ -67,7 +68,13 @@ $this->params['breadcrumbs'][] = $this->title;
                     return ApiCronBuh::getStatus($model->status);
                 }
             ],
-            'date_up'
+            'date_up',
+            [
+                'attribute' => 'inn',
+                'value' => function ($model) {
+                    return !empty($model->inn) ? Firms::getInn()[$model->inn] : '';
+                }
+            ],
         ],
         'rowOptions' => function ($model) {
             $status = $model->status;