From: marina Date: Wed, 23 Oct 2024 13:41:02 +0000 (+0300) Subject: ERP-150 Присвоить каждому магазину ID склада X-Git-Tag: 1.6~29 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=036f943fa192d905259ff9d5816785f4ec42a950;p=erp24_rep%2Fyii-erp24%2F.git ERP-150 Присвоить каждому магазину ID склада --- diff --git a/erp24/controllers/MarketplaceStoreController.php b/erp24/controllers/MarketplaceStoreController.php new file mode 100755 index 00000000..a5be886c --- /dev/null +++ b/erp24/controllers/MarketplaceStoreController.php @@ -0,0 +1,95 @@ + MarketplaceStore::find(), + 'pagination' => false, + ]); + + return $this->render('index', [ + 'dataProvider' => $dataProvider, + 'firms' => $firms + ]); + } + + public function actionView($id) + { + $model = $this->findModel($id); + $firms = Firms::getInn(); + + return $this->render('view', [ + 'model' => $model, + 'firms' => $firms, + ]); + } + + public function actionCreate() + { + $model = new MarketplaceStore(); + $stores = CityStore::getAllActiveIdName(); + $firms = Firms::getInn(); + $storesGuid = CityStore::getAllActiveGuidId(); + + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('create', [ + 'model' => $model, + 'stores' => $stores, + 'storesGuid' => $storesGuid, + 'firms' => $firms, + ]); + } + + public function actionUpdate($id) + { + $model = MarketplaceStore::findOne($id); + $stores = CityStore::getAllActiveIdName(); + $firms = Firms::getInn(); + $storesGuid = CityStore::getAllActiveGuidId(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('update', [ + 'model' => $model, + 'stores' => $stores, + 'storesGuid' => $storesGuid, + 'firms' => $firms, + ]); + } + + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + protected function findModel($id) + { + if (($model = MarketplaceStore::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } +} diff --git a/erp24/migrations/m241023_064710_create_marketplace_store_table.php b/erp24/migrations/m241023_064710_create_marketplace_store_table.php new file mode 100644 index 00000000..bf3cae0e --- /dev/null +++ b/erp24/migrations/m241023_064710_create_marketplace_store_table.php @@ -0,0 +1,44 @@ +db->schema->getTableSchema('erp24.marketplace_store', true)) { + $this->createTable('{{%erp24.marketplace_store}}', [ + 'id' => $this->primaryKey(), + 'store_id' => $this->integer()->notNull()->comment('id магазина'), + 'guid' => $this->string(255)->notNull()->comment('гуид магазина'), + 'name' => $this->string()->comment('название магазина(адрес) = название склада'), + 'yandex_market_id' => $this->integer()->comment('id склада в данном маркетплейсе'), + 'flowwow_id' => $this->integer()->comment('id склада в данном маркетплейсе'), + 'firm' => $this->string(255)->comment('юр . лицо, к которому относится магазин'), + 'created_at' => $this->datetime()->notNull()->comment('дата создания записи'), + 'created_by' => $this->integer()->notNull()->comment('автор создания записи'), + 'updated_at' => $this->datetime()->notNull()->comment('дата изменения записи'), + 'updated_by' => $this->integer()->notNull()->comment('автор изменения записи'), + ]); + + $this->addForeignKey('fk_marketplace_store_to_city_store', '{{%erp24.marketplace_store}}', 'store_id', '{{%city_store}}', 'id'); + } + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + if ($this->db->schema->getTableSchema('erp24.marketplace_store', true)) { + $this->dropForeignKey('fk_marketplace_store_to_city_store', '{{%erp24.marketplace_store}}'); + $this->dropTable('{{%erp24.marketplace_store}}'); + } + } +} diff --git a/erp24/records/CityStore.php b/erp24/records/CityStore.php index 34bdb099..36e1d3f8 100755 --- a/erp24/records/CityStore.php +++ b/erp24/records/CityStore.php @@ -265,6 +265,22 @@ class CityStore extends ActiveRecord return $result; } + + public static function getAllActiveGuidId() + { + $result = []; + + $values = self::find()->joinWith('storeGuid') + ->orderBy([self::tableName() . '.id' => SORT_ASC])->asArray() + ->all(); + + if (!empty($values)) { + $result = ArrayHelper::map($values, 'id', 'storeGuid.export_val'); + } + + return $result; + } + public static function getCityStoreById(int $id, $withGuid = false): array { $query = self::find(); diff --git a/erp24/records/MarketplaceStore.php b/erp24/records/MarketplaceStore.php new file mode 100755 index 00000000..7c30aa6a --- /dev/null +++ b/erp24/records/MarketplaceStore.php @@ -0,0 +1,96 @@ + CityStore::class, 'targetAttribute' => 'id'], + [['name', 'guid', 'firm'], 'string'], + [['store_id', 'yandex_market_id', 'flowwow_id', 'created_at', 'created_by', 'updated_at', 'updated_by'], 'integer'], + + ]; + } + + public function behaviors() + { + return [ + [ + 'class' => TimestampBehavior::class, + 'createdAtAttribute' => 'created_at', + 'updatedAtAttribute' => 'updated_at', + 'value' => new Expression('NOW()'), + ], + [ + 'class' => BlameableBehavior::class, + 'createdByAttribute' => 'created_by', + 'updatedByAttribute' => 'updated_by', + ], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'store_id' => 'ID магазина', + 'guid' => 'GUID магазина', + 'name' => 'Название магазина(адрес) = Название склада', + 'yandex_market_id' => 'ID склада в Яндекс Маркете', + 'flowwow_id' => 'ID склада в Flowwow', + 'firm' => 'Юр.лицо, к которому относится магазин', + 'created_at' => 'Дата создания записи', + 'created_by' => 'Автор создания записи', + 'updated_at' => 'Дата изменения записи', + 'updated_by' => 'Автор изменения записи' + ]; + } + + public function getStore() { + return $this->hasOne(CityStore::class, ['id' => 'store_id']); + } + + public function getCreatedBy() { + return $this->hasOne(Admin::class, ['id' => 'created_by']); + } + + public function getUpdatedBy() { + return $this->hasOne(Admin::class, ['id' => 'updated_by']); + } +} diff --git a/erp24/views/marketplace-store/_form.php b/erp24/views/marketplace-store/_form.php new file mode 100644 index 00000000..7331b3f4 --- /dev/null +++ b/erp24/views/marketplace-store/_form.php @@ -0,0 +1,39 @@ + + +
+ + + field($model, 'store_id')->dropDownList($stores, [ + 'prompt' => 'Выберите магазин', + 'onchange' => 'updateGuid(this.value)' // Вызов функции для обновления guid + ]) ?> + + field($model, 'guid')->textInput(['maxlength' => true, 'value' => $model->guid, 'readonly' => true, 'id' => 'guid-input']) ?> + field($model, 'yandex_market_id')->textInput() ?> + field($model, 'flowwow_id')->textInput(['type' => 'integer']) ?> + field($model, 'firm')->dropDownList($firms, ['prompt' => 'Выберите юр лицо']) ?> + +
+ isNewRecord ? 'Создать' : 'Сохранить', ['class' => 'btn btn-success']) ?> +
+ + + +
+ + + \ No newline at end of file diff --git a/erp24/views/marketplace-store/create.php b/erp24/views/marketplace-store/create.php new file mode 100644 index 00000000..c7031bae --- /dev/null +++ b/erp24/views/marketplace-store/create.php @@ -0,0 +1,21 @@ +title = 'Создать Магазин'; +$this->params['breadcrumbs'][] = ['label' => 'Список Магазинов', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> + +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + 'stores' => $stores, + 'storesGuid' => $storesGuid, + 'firms' => $firms, + ]) ?> + +
diff --git a/erp24/views/marketplace-store/index.php b/erp24/views/marketplace-store/index.php new file mode 100644 index 00000000..43c01573 --- /dev/null +++ b/erp24/views/marketplace-store/index.php @@ -0,0 +1,46 @@ +title = 'Список Магазинов'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ 'btn btn-success']) ?> +

+ + $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + [ + 'attribute' => 'store_id', + 'value' => function ($model) { + return $model->store->name; + } + ], + 'guid', + 'yandex_market_id', + 'flowwow_id', + [ + 'attribute' => 'firm', + 'value' => function ($model) { + return Firms::getInn()[$model->firm]; + } + ], + 'created_at', + 'updated_at', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> + +
diff --git a/erp24/views/marketplace-store/update.php b/erp24/views/marketplace-store/update.php new file mode 100644 index 00000000..f5e9bca5 --- /dev/null +++ b/erp24/views/marketplace-store/update.php @@ -0,0 +1,21 @@ +title = 'Обновить Магазин: ' . $model->store->name; +$this->params['breadcrumbs'][] = ['label' => 'Список Магазинов', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> + +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + 'stores' => $stores, + 'storesGuid' => $storesGuid, + 'firms' => $firms, + ]) ?> + +
diff --git a/erp24/views/marketplace-store/view.php b/erp24/views/marketplace-store/view.php new file mode 100644 index 00000000..7c988264 --- /dev/null +++ b/erp24/views/marketplace-store/view.php @@ -0,0 +1,68 @@ +title = 'Просмотр магазина: ' . $model->store->name; +$this->params['breadcrumbs'][] = ['label' => 'Список Магазинов', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> + +
+ +

title) ?>

+ +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Вы уверены, что хотите удалить этот элемент?', + 'method' => 'post', + ], + ]) ?> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IDid) ?>
ID Магазинаstore->name) ?>
GUIDguid) ?>
ID в Яндекс.Маркетеyandex_market_id) ?>
ID в Flowwowflowwow_id) ?>
Юридическое Лицоfirm]) ?>
Автор созданияcreatedBy->name) ?>
Дата созданияcreated_at))) ?>
Автор обновленияupdatedBy->name) ?>
Дата обновленияupdated_at))) ?>
+ +