use yii_app\records\Admin;
use yii_app\records\AdminGroup;
use yii_app\records\AnalystsBusinessOperations;
+use yii_app\records\AnalystsBusinessOperationsTypes;
use yii_app\records\ApiCron;
use yii_app\records\Assemblies;
use yii_app\records\Balances;
$existingOperations = AnalystsBusinessOperations::find()
->select(['id'])
->column();
+ $existingTypes = AnalystsBusinessOperationsTypes::find()
+ ->indexBy('code')
+ ->asArray()
+ ->all();
foreach ($result["analysts_business_operations"] as $operation) {
if (!in_array($operation['guid'], $existingOperations)) {
$newOperation = new AnalystsBusinessOperations();
$newOperation->id = $operation['guid'];
$newOperation->name = $operation['name'];
$newOperation->type = $operation['type'];
+ if (!in_array($newOperation->type, array_column($existingTypes, 'code'))) {
+ $newType = new AnalystsBusinessOperationsTypes();
+ $newType->code = $operation['type'];
+ if ($newType->save()) {
+ $newOperation->type_id = $newType->id;
+ } else {
+ Yii::error('Ошибка сохранение типа ' . json_encode($newType->getErrors(), JSON_UNESCAPED_UNICODE), __METHOD__ );
+ }
+ } else {
+ $newOperation->type_id = $existingTypes[$operation['type']]['id'];
+ }
+
if (!$newOperation->save()) {
LogService::apiErrorLog(
json_encode(
)
);
}
+
}
}
$config = Configuration::getDefaultConfiguration()->setApiKey('Api-Key', Yii::$app->params['YANDEX_MARKET_API_KEY']);
- $products = Products1c::find()->alias('p')->leftJoin('products_class pc', 'p.parent_id = pc.category_id')
- ->where(['pc.tip' => [ProductsClass::MARKETPLACE, ProductsClass::MARKETPLACE_ADDITIONAL]])->all();
+ $products = Products1c::find()
+ ->alias('p')
+ ->leftJoin('products_class pc', 'p.parent_id = pc.category_id')
+ ->where(['pc.tip' => [ProductsClass::MARKETPLACE, ProductsClass::MARKETPLACE_ADDITIONAL]])
+ ->all();
$matrixErp = MatrixErp::find()->where(['guid' => ArrayHelper::getColumn($products, 'id')])->all();
$matrixErpByGuid = [];
$hiddenOfferings = [];
--- /dev/null
+<?php
+
+namespace app\controllers;
+
+use yii_app\records\AnalystsBusinessOperationsTypes;
+use yii\data\ActiveDataProvider;
+use yii\web\Controller;
+use yii\web\NotFoundHttpException;
+use yii\filters\VerbFilter;
+
+/**
+ * AnalystsBusinessOperationsTypesController implements the CRUD actions for AnalystsBusinessOperationsTypes model.
+ */
+class AnalystsBusinessOperationsTypesController extends Controller
+{
+ /**
+ * @inheritDoc
+ */
+ public function behaviors()
+ {
+ return array_merge(
+ parent::behaviors(),
+ [
+ 'verbs' => [
+ 'class' => VerbFilter::className(),
+ 'actions' => [
+ 'delete' => ['POST'],
+ ],
+ ],
+ ]
+ );
+ }
+
+ /**
+ * Lists all AnalystsBusinessOperationsTypes models.
+ *
+ * @return string
+ */
+ public function actionIndex()
+ {
+ $dataProvider = new ActiveDataProvider([
+ 'query' => AnalystsBusinessOperationsTypes::find(),
+ /*
+ 'pagination' => [
+ 'pageSize' => 50
+ ],
+ 'sort' => [
+ 'defaultOrder' => [
+ 'id' => SORT_DESC,
+ ]
+ ],
+ */
+ ]);
+
+ return $this->render('index', [
+ 'dataProvider' => $dataProvider,
+ ]);
+ }
+
+ /**
+ * Displays a single AnalystsBusinessOperationsTypes model.
+ * @param int $id ID
+ * @return string
+ * @throws NotFoundHttpException if the model cannot be found
+ */
+ public function actionView($id)
+ {
+ return $this->render('view', [
+ 'model' => $this->findModel($id),
+ ]);
+ }
+
+ /**
+ * Creates a new AnalystsBusinessOperationsTypes model.
+ * If creation is successful, the browser will be redirected to the 'view' page.
+ * @return string|\yii\web\Response
+ */
+ public function actionCreate()
+ {
+ $model = new AnalystsBusinessOperationsTypes();
+
+ if ($this->request->isPost) {
+ if ($model->load($this->request->post()) && $model->save()) {
+ return $this->redirect(['view', 'id' => $model->id]);
+ }
+ } else {
+ $model->loadDefaultValues();
+ }
+
+ return $this->render('create', [
+ 'model' => $model,
+ ]);
+ }
+
+ /**
+ * Updates an existing AnalystsBusinessOperationsTypes model.
+ * If update is successful, the browser will be redirected to the 'view' page.
+ * @param int $id ID
+ * @return string|\yii\web\Response
+ * @throws NotFoundHttpException if the model cannot be found
+ */
+ public function actionUpdate($id)
+ {
+ $model = $this->findModel($id);
+
+ if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
+ return $this->redirect(['view', 'id' => $model->id]);
+ }
+
+ return $this->render('update', [
+ 'model' => $model,
+ ]);
+ }
+
+ /**
+ * Deletes an existing AnalystsBusinessOperationsTypes model.
+ * If deletion is successful, the browser will be redirected to the 'index' page.
+ * @param int $id ID
+ * @return \yii\web\Response
+ * @throws NotFoundHttpException if the model cannot be found
+ */
+ public function actionDelete($id)
+ {
+ $this->findModel($id)->delete();
+
+ return $this->redirect(['index']);
+ }
+
+ /**
+ * Finds the AnalystsBusinessOperationsTypes model based on its primary key value.
+ * If the model is not found, a 404 HTTP exception will be thrown.
+ * @param int $id ID
+ * @return AnalystsBusinessOperationsTypes the loaded model
+ * @throws NotFoundHttpException if the model cannot be found
+ */
+ protected function findModel($id)
+ {
+ if (($model = AnalystsBusinessOperationsTypes::findOne(['id' => $id])) !== null) {
+ return $model;
+ }
+
+ throw new NotFoundHttpException('The requested page does not exist.');
+ }
+}
'id' => $this->string()->notNull()->unique()->comment('GUID аналитики'),
'name' => $this->string()->notNull()->comment('Название аналитики'),
'type' => $this->integer()->notNull()->comment('Вид использования хозяйственной операции'),
- 'type_id' => $this->string()->null()->comment('ID Вида'),
+ 'type_id' => $this->integer()->null()->comment('ID Вида'),
'created_at' => $this->dateTime()->notNull()->comment('Дата создания'),
]);
$this->addPrimaryKey('pk_analytics_id', self::TABLE_NAME, 'id');
--- /dev/null
+<?php
+
+use yii\db\Migration;
+
+class m250826_061451_add_analysts_business_operations_types_table extends Migration
+{
+ const TABLE_NAME = 'erp24.analysts_business_operations_types';
+ /**
+ * {@inheritdoc}
+ */
+ public function safeUp()
+ {
+ $tableSchema = $this->db->getTableSchema(self::TABLE_NAME);
+
+ if (!isset($tableSchema)) {
+ $this->createTable(self::TABLE_NAME, [
+ 'id' => $this->primaryKey()->comment('ID типа операции'),
+ 'code' => $this->integer()->notNull()->unique()->comment('Код типа (0,1,2...)'),
+ 'name' => $this->string()->notNull()->comment('Название типа операции'),
+ 'created_at' => $this->dateTime()->notNull()->defaultExpression('NOW()'),
+ ]);
+ $this->addForeignKey(
+ 'fk_operations_type',
+ 'analysts_business_operations',
+ 'type_id',
+ 'analysts_business_operations_types',
+ 'id'
+ );
+
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ $tableSchema = $this->db->getTableSchema(self::TABLE_NAME);
+ if (isset($tableSchema)) {
+ $this->dropForeignKey('fk_operations_type', self::TABLE_NAME);
+ $this->dropTable(self::TABLE_NAME);
+ }
+ }
+ /*
+ // Use up()/down() to run migration code without a transaction.
+ public function up()
+ {
+
+ }
+
+ public function down()
+ {
+ echo "m250826_061451_add_analysts_business_operations_types_table cannot be reverted.\n";
+
+ return false;
+ }
+ */
+}
--- /dev/null
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "analysts_business_operations_types".
+ *
+ * @property int $id ID типа операции
+ * @property int $code Код типа (0,1,2...)
+ * @property string $name Название типа операции
+ * @property string $created_at
+ *
+ * @property AnalystsBusinessOperations[] $analystsBusinessOperations
+ */
+class AnalystsBusinessOperationsTypes extends \yii\db\ActiveRecord
+{
+
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function tableName()
+ {
+ return 'analysts_business_operations_types';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function rules()
+ {
+ return [
+ [['code'], 'required'],
+ [['code'], 'default', 'value' => null],
+ [['code'], 'integer'],
+ [['created_at'], 'safe'],
+ [['name'], 'string', 'max' => 255],
+ [['code'], 'unique'],
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function attributeLabels()
+ {
+ return [
+ 'id' => 'ID',
+ 'code' => 'Code',
+ 'name' => 'Name',
+ 'created_at' => 'Created At',
+ ];
+ }
+
+ /**
+ * Gets query for [[AnalystsBusinessOperations]].
+ *
+ * @return \yii\db\ActiveQuery
+ */
+ public function getAnalystsBusinessOperations()
+ {
+ return $this->hasMany(AnalystsBusinessOperations::class, ['type_id' => 'id']);
+ }
+
+}
--- /dev/null
+<?php
+
+use yii\helpers\Html;
+use yii\widgets\ActiveForm;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\AnalystsBusinessOperationsTypes $model */
+/** @var yii\widgets\ActiveForm $form */
+?>
+
+<div class="analysts-business-operations-types-form">
+
+ <?php $form = ActiveForm::begin(); ?>
+
+ <?= $form->field($model, 'code')->textInput() ?>
+
+ <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
+
+ <?= $form->field($model, 'created_at')->textInput() ?>
+
+ <div class="form-group">
+ <?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
+ </div>
+
+ <?php ActiveForm::end(); ?>
+
+</div>
--- /dev/null
+<?php
+
+use yii\helpers\Html;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\AnalystsBusinessOperationsTypes $model */
+
+$this->title = 'Создать тип ';
+$this->params['breadcrumbs'][] = ['label' => 'Analysts Business Operations Types', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="analysts-business-operations-types-create p-4">
+
+ <h1><?= Html::encode($this->title) ?></h1>
+
+ <?= $this->render('_form', [
+ 'model' => $model,
+ ]) ?>
+
+</div>
--- /dev/null
+<?php
+
+use yii_app\records\AnalystsBusinessOperationsTypes;
+use yii\helpers\Html;
+use yii\helpers\Url;
+use yii\grid\ActionColumn;
+use yii\grid\GridView;
+
+/** @var yii\web\View $this */
+/** @var yii\data\ActiveDataProvider $dataProvider */
+
+$this->title = 'Типы бизнес операций из 1С';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="analysts-business-operations-types-index p-4">
+
+ <h1><?= Html::encode($this->title) ?></h1>
+
+ <p>
+ <?= Html::a('Создать тип', ['create'], ['class' => 'btn btn-success']) ?>
+ </p>
+
+
+ <?= GridView::widget([
+ 'dataProvider' => $dataProvider,
+ 'columns' => [
+ ['class' => 'yii\grid\SerialColumn'],
+
+ 'id',
+ 'code',
+ 'name',
+ 'created_at',
+ [
+ 'class' => ActionColumn::class,
+ 'urlCreator' => function ($action, AnalystsBusinessOperationsTypes $model, $key, $index, $column) {
+ return Url::toRoute([$action, 'id' => $model->id]);
+ }
+ ],
+ ],
+ ]); ?>
+
+
+</div>
--- /dev/null
+<?php
+
+use yii\helpers\Html;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\AnalystsBusinessOperationsTypes $model */
+
+$this->title = 'Изменить тип: ' . $model->name;
+$this->params['breadcrumbs'][] = ['label' => 'Analysts Business Operations Types', 'url' => ['index']];
+$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
+$this->params['breadcrumbs'][] = 'Update';
+?>
+<div class="analysts-business-operations-types-update p-4">
+
+ <h1><?= Html::encode($this->title) ?></h1>
+
+ <?= $this->render('_form', [
+ 'model' => $model,
+ ]) ?>
+
+</div>
--- /dev/null
+<?php
+
+use yii\helpers\Html;
+use yii\widgets\DetailView;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\AnalystsBusinessOperationsTypes $model */
+
+$this->title = $model->name;
+$this->params['breadcrumbs'][] = ['label' => 'Analysts Business Operations Types', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+\yii\web\YiiAsset::register($this);
+?>
+<div class="analysts-business-operations-types-view p-4">
+
+ <h1><?= Html::encode($this->title) ?></h1>
+
+ <p>
+ <?= Html::a('Изменить', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
+ <?= Html::a('Удалить', ['delete', 'id' => $model->id], [
+ 'class' => 'btn btn-danger',
+ 'data' => [
+ 'confirm' => 'Вы уверены, что хотите удалить запись?',
+ 'method' => 'post',
+ ],
+ ]) ?>
+ </p>
+
+ <?= DetailView::widget([
+ 'model' => $model,
+ 'attributes' => [
+ 'id',
+ 'code',
+ 'name',
+ 'created_at',
+ ],
+ ]) ?>
+
+</div>