From: marina Date: Thu, 15 Aug 2024 09:02:32 +0000 (+0300) Subject: ERP-85 Реализовать обмен данных с 1С Бухгалтерия X-Git-Tag: 1.4~22^2~26 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=99ad2057170ce8706f16ca43eb223e329b5c846b;p=erp24_rep%2Fyii-erp24%2F.git ERP-85 Реализовать обмен данных с 1С Бухгалтерия --- diff --git a/erp24/api2/controllers/DataBuhController.php b/erp24/api2/controllers/DataBuhController.php index 4f613e53..cb75aad3 100644 --- a/erp24/api2/controllers/DataBuhController.php +++ b/erp24/api2/controllers/DataBuhController.php @@ -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) { diff --git a/erp24/controllers/CronController.php b/erp24/controllers/CronController.php index 9c4df848..965eebcf 100644 --- a/erp24/controllers/CronController.php +++ b/erp24/controllers/CronController.php @@ -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 index 00000000..2ab67604 --- /dev/null +++ b/erp24/migrations/m240815_081804_add_new_column_to_api_cron_buh.php @@ -0,0 +1,29 @@ +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 запроса'),); + } +} diff --git a/erp24/records/ApiCronBuh.php b/erp24/records/ApiCronBuh.php index 8e34dfea..ea7455b7 100644 --- a/erp24/records/ApiCronBuh.php +++ b/erp24/records/ApiCronBuh.php @@ -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' => 'ИНН', ]; } diff --git a/erp24/views/cron/1c_buh.php b/erp24/views/cron/1c_buh.php index d65255dd..94d04186 100644 --- a/erp24/views/cron/1c_buh.php +++ b/erp24/views/cron/1c_buh.php @@ -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;