const OUT_DIR =
// __DIR__ . "/../json";
- // "/www/api2/json";
- "/var/www/erp24/api2/json";
+ "/www/api2/json";
+ //"/var/www/erp24/api2/json";
// "/var/www/www-root/data/www/api.bazacvetov24.ru/data/json";
private static function getPathJson()
$newOperation = new AnalystsBusinessOperations();
$newOperation->id = $operation['guid'];
$newOperation->name = $operation['name'];
- $newOperation->type = $operation['type'];
+ $newOperation->type = (int)$operation['type'];
if (!in_array($newOperation->type, array_column($existingTypes, 'code'))) {
$newType = new AnalystsBusinessOperationsTypes();
- $newType->code = $operation['type'];
+ $newType->code = (int)$operation['type'];
+ $newType->name = null;
+ $newType->created_at = date('Y-m-d H:i:s');
if ($newType->save()) {
$newOperation->type_id = $newType->id;
} else {
+ $newOperation->type_id = null;
Yii::error('Ошибка сохранение типа ' . json_encode($newType->getErrors(), JSON_UNESCAPED_UNICODE), __METHOD__ );
}
} else {
$newOperation->type_id = $existingTypes[$operation['type']]['id'];
}
-
+ $newOperation->created_at = date('Y-m-d H:i:s');
if (!$newOperation->save()) {
LogService::apiErrorLog(
json_encode(
public function actionIndex()
{
$dataProvider = new ActiveDataProvider([
- 'query' => AnalystsBusinessOperations::find(),
+ 'query' => AnalystsBusinessOperations::find()->with('typeRel'),
/*
'pagination' => [
'pageSize' => 50
'name' => $this->string()->notNull()->comment('Название аналитики'),
'type' => $this->integer()->notNull()->comment('Вид использования хозяйственной операции'),
'type_id' => $this->integer()->null()->comment('ID Вида'),
- 'created_at' => $this->dateTime()->notNull()->comment('Дата создания'),
+ 'created_at' => $this->dateTime()->notNull()->defaultExpression('NOW()'),
]);
$this->addPrimaryKey('pk_analytics_id', self::TABLE_NAME, 'id');
}
$this->createTable(self::TABLE_NAME, [
'id' => $this->primaryKey()->comment('ID типа операции'),
'code' => $this->integer()->notNull()->unique()->comment('Код типа (0,1,2...)'),
- 'name' => $this->string()->notNull()->comment('Название типа операции'),
+ 'name' => $this->string()->null()->comment('Название типа операции'),
'created_at' => $this->dateTime()->notNull()->defaultExpression('NOW()'),
]);
- $this->addForeignKey(
- 'fk_operations_type',
- 'analysts_business_operations',
- 'type_id',
- 'analysts_business_operations_types',
- 'id'
- );
+ $this->batchInsert(self::TABLE_NAME, ['code', 'name'], [
+ [0, 'Оприходование'],
+ [1, 'Списание'],
+ [2, 'Пересорт'],
+ ]);
}
}
{
$tableSchema = $this->db->getTableSchema(self::TABLE_NAME);
if (isset($tableSchema)) {
- $this->dropForeignKey('fk_operations_type', self::TABLE_NAME);
$this->dropTable(self::TABLE_NAME);
}
}
* @property string $id GUID аналитики
* @property string $name Название аналитики
* @property int $type Вид использования хозяйственной операции
- * @property string|null $type_id ID Вида
+ * @property int|null $type_id ID Вида
* @property string $created_at Дата создания
*/
class AnalystsBusinessOperations extends \yii\db\ActiveRecord
[['type_id'], 'default', 'value' => null],
[['id', 'name', 'type', 'created_at'], 'required'],
[['type'], 'default', 'value' => null],
- [['type'], 'integer'],
+ [['type', 'type_id'], 'integer'],
[['created_at'], 'safe'],
- [['id', 'name', 'type_id'], 'string', 'max' => 255],
+ [['id', 'name'], 'string', 'max' => 255],
[['id'], 'unique'],
];
}
];
}
+ public function getTypeRel()
+ {
+ return $this->hasOne(AnalystsBusinessOperationsTypes::class, ['id' => 'type_id']);
+ }
+
}
*
* @property int $id ID типа операции
* @property int $code Код типа (0,1,2...)
- * @property string $name Название типа операции
+ * @property string|null $name Название типа операции
* @property string $created_at
*
* @property AnalystsBusinessOperations[] $analystsBusinessOperations
{
return [
[['code'], 'required'],
- [['code'], 'default', 'value' => null],
+ [['name'], 'default', 'value' => null],
[['code'], 'integer'],
[['created_at'], 'safe'],
[['name'], 'string', 'max' => 255],
*
* @return \yii\db\ActiveQuery
*/
- public function getAnalystsBusinessOperations()
+ public function getTypeRel()
{
- return $this->hasMany(AnalystsBusinessOperations::class, ['type_id' => 'id']);
+ return $this->hasOne(AnalystsBusinessOperationsTypes::class, ['id' => 'type_id']);
}
}
'id',
'name',
+ [
+ 'attribute' => 'type_id',
+ 'label' => 'Тип (из справочника)',
+ 'value' => function ($model) {
+ return $model->typeRel->name ?? '—';
+ },
+ ],
'type',
'type_id',
'created_at',