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

index 8b524a868ec0aea150e77bbb7c96dbffe01c66e4..4cef58387bddb3d7ed53bcf56536ae1bf1005738 100644 (file)
@@ -28,7 +28,8 @@
         "yiisoft/yii2-imagine": "^2.3",
         "kartik-v/yii2-builder": "dev-master",
         "kartik-v/yii2-bootstrap5-dropdown": "@dev",
-        "kartik-v/yii2-grid": "@dev"
+        "kartik-v/yii2-grid": "@dev",
+        "kartik-v/yii2-widget-datepicker": "dev-master",
         "phpoffice/phpspreadsheet": "^2.2"
     },
     "require-dev": {
index 71803f92f15ee4e9bdb2d244a56011739e5f2939..0c58e5cbce5183eb7888af43fd47016f7ecebcda 100644 (file)
@@ -2,11 +2,53 @@
 
 namespace app\controllers;
 
+use yii\data\ActiveDataProvider;
+use yii\db\Exception;
+use yii\helpers\Json;
 use yii\web\Controller;
+use yii_app\records\ApiCronBuh;
 
 class CronController extends Controller
 {
     public function action1c() {
         return $this->render('1c');
     }
+
+    /**
+     * @throws Exception
+     */
+    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);
+            }
+        }
+        $dataProvider = new ActiveDataProvider([
+            'query' => ApiCronBuh::find()
+                ->orderBy('request_id desc'),
+            'pagination' => [
+                'pageSize' => 30
+            ],
+
+        ]);
+
+        return $this->render('1c_buh', [
+            'dataProvider' => $dataProvider,
+        ]);
+    }
 }
\ No newline at end of file
index fbd0789bb7dc40bde9f2298b418536fdd99c59a4..8e34dfea24bbfa1a6ed57cd897870a41c9f8b0cd 100644 (file)
@@ -16,6 +16,11 @@ use Yii;
  */
 class ApiCronBuh extends \yii\db\ActiveRecord
 {
+
+    const WAIT = 0;
+    const SEND = 1;
+    const RECEIVED = 2;
+
     /**
      * {@inheritdoc}
      */
@@ -30,7 +35,7 @@ class ApiCronBuh extends \yii\db\ActiveRecord
     public function rules()
     {
         return [
-            [['date', 'date_up', 'request_id'], 'required'],
+            [['date','request_id'], 'required'],
             [['date', 'date_up'], 'safe'],
             [['status'], 'integer'],
             [['json_post'], 'string'],
@@ -45,11 +50,22 @@ class ApiCronBuh extends \yii\db\ActiveRecord
     {
         return [
             'id' => 'ID',
-            'date' => 'Date',
-            'date_up' => 'Date Up',
+            'date' => 'Дата',
+            'date_up' => 'Дата обработки',
             'status' => 'Status',
-            'json_post' => 'Json Post',
-            'request_id' => 'Request ID',
+            'json_post' => 'Тело запроса',
+            'request_id' => 'ID запроса',
         ];
     }
+
+    public static function getStatus($status)
+    {
+        $labels = [
+            self::WAIT => 'Ожидает',
+            self::SEND => 'Отправлено',
+            self::RECEIVED => 'Обработано',
+        ];
+
+        return $labels[$status] ?? '';
+    }
 }
diff --git a/erp24/views/cron/1c_buh.php b/erp24/views/cron/1c_buh.php
new file mode 100644 (file)
index 0000000..d65255d
--- /dev/null
@@ -0,0 +1,89 @@
+<?php
+
+use kartik\date\DatePicker;
+use kartik\grid\GridView;
+use yii\helpers\Html;
+use yii\widgets\ActiveForm;
+use yii_app\records\ApiCronBuh;
+
+
+/** @var yii\web\View $this */
+/** @var yii\data\ActiveDataProvider $dataProvider */
+
+
+$this->title = Yii::t('app', 'Задачи для 1С Бухгалтерии');
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="1c-buh-model-index m-5 row">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <?php $form = ActiveForm::begin(); ?>
+
+    <div class="form-row">
+        <div class="form-group col-md-5">
+            <?php
+            echo DatePicker::widget([
+                'name' => 'start_date',
+                'pluginOptions' => [
+                    'autoclose' => true,
+                    'format' => 'dd-mm-yyyy'
+                ],
+                'options' => [
+                    'class' => 'form-control',
+                    'placeholder' => 'Начало периода',]
+            ]);
+            ?>
+        </div>
+        <div class="form-group col-md-5">
+            <?php
+            echo DatePicker::widget([
+                'name' => 'end_date',
+                'pluginOptions' => [
+                    'autoclose' => true,
+                    'format' => 'dd-mm-yyyy'
+                ],
+                'options' => [
+                    'class' => 'form-control',
+                    'placeholder' => 'Конец периода',]
+            ]);
+            ?>
+        </div>
+        <?= Html::submitButton('Создать задачу', ['class' => 'btn btn-primary col-md-2 h-25']); ?>
+    </div>
+
+    <?php ActiveForm::end(); ?>
+
+
+    <?= GridView::widget([
+        'dataProvider' => $dataProvider,
+        'columns' => [
+            'request_id',
+            'date',
+            'json_post',
+            [
+                'attribute' => 'status',
+                'value' => function ($model) {
+                    return ApiCronBuh::getStatus($model->status);
+                }
+            ],
+            'date_up'
+        ],
+        'rowOptions' => function ($model) {
+            $status = $model->status;
+            $class = '';
+            switch ($status) {
+                case ApiCronBuh::SEND:
+                    $class = 'bg-warning';
+                    break;
+                case ApiCronBuh::RECEIVED:
+                    $class = 'bg-success';
+                    break;
+                default:
+            }
+            return ['class' => $class];
+        }
+    ]); ?>
+
+
+</div>