try {
$apiCronTest = ApiCronBuh::find()
- ->where(['status' => 0])
- ->orderBy(['date' => SORT_ASC])
+ ->andWhere(['inn' => $inn])
+ ->andWhere(['status' => 0])
+ ->orderBy(['id' => SORT_ASC])
->one();
if ($apiCronTest) {
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
],
--- /dev/null
+<?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 запроса'),);
+ }
+}
* @property int $status Статус
* @property string|null $json_post Тело запроса
* @property string $request_id id запроса
+ * @property int $inn ИНН
*/
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],
];
'status' => 'Status',
'json_post' => 'Тело запроса',
'request_id' => 'ID запроса',
+ 'inn' => 'ИНН',
];
}
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii_app\records\ApiCronBuh;
+use yii_app\records\Firms;
/** @var yii\web\View $this */
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;