From 615358fb17e1482247b78120a8d7df0cdfdd8969 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 21 Oct 2015 12:24:12 +0300 Subject: [PATCH] Importers CRUD --- backend/controllers/MarginsImportersImportController.php | 12 ++++++++++-- backend/controllers/OfficesController.php | 9 ++++++--- backend/views/layouts/column.php | 2 +- backend/views/margins-groups/_form.php | 4 ++-- backend/views/margins-importers-import/_form.php | 9 ++++----- backend/views/margins-importers-import/create.php | 2 ++ backend/views/margins-importers-import/index.php | 11 ++++++++--- backend/views/margins-importers-import/update.php | 2 ++ backend/views/margins-importers/_form.php | 4 ++-- backend/views/margins-importers/index.php | 10 ++++++++-- backend/views/offices/_form.php | 6 +----- backend/views/offices/create.php | 1 + backend/views/offices/index.php | 14 +++++++------- backend/views/offices/update.php | 1 + common/models/MarginsGroupsSearch.php | 2 +- common/models/MarginsImportersImport.php | 19 +++++++++++++++---- common/models/MarginsImportersImportSearch.php | 11 +++++++---- common/models/MarginsImportersSearch.php | 10 ++++++---- common/models/Offices.php | 17 +++++++++++------ 19 files changed, 95 insertions(+), 51 deletions(-) diff --git a/backend/controllers/MarginsImportersImportController.php b/backend/controllers/MarginsImportersImportController.php index 7c7270b..698b2ec 100644 --- a/backend/controllers/MarginsImportersImportController.php +++ b/backend/controllers/MarginsImportersImportController.php @@ -2,6 +2,8 @@ namespace backend\controllers; +use backend\models\Importers; +use common\models\Margins; use Yii; use common\models\MarginsImportersImport; use common\models\MarginsImportersImportSearch; @@ -64,12 +66,15 @@ class MarginsImportersImportController extends Controller public function actionCreate() { $model = new MarginsImportersImport(); - + $importers= Importers::find()->all(); + $margin = Margins::find()->all(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', [ 'model' => $model, + 'importers' => $importers, + 'margin' => $margin, ]); } } @@ -83,12 +88,15 @@ class MarginsImportersImportController extends Controller public function actionUpdate($id) { $model = $this->findModel($id); - + $importers= Importers::find()->all(); + $margin = Margins::find()->all(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', [ 'model' => $model, + 'importers' => $importers, + 'margin' => $margin, ]); } } diff --git a/backend/controllers/OfficesController.php b/backend/controllers/OfficesController.php index c0beae4..2cd19be 100644 --- a/backend/controllers/OfficesController.php +++ b/backend/controllers/OfficesController.php @@ -2,6 +2,7 @@ namespace backend\controllers; +use common\models\DicCities; use Yii; use common\models\Offices; use common\models\OfficesSearch; @@ -13,7 +14,7 @@ use yii\filters\VerbFilter; * OfficesController implements the CRUD actions for Offices model. */ class OfficesController extends Controller -{ +{ public $layout = "/column"; public function behaviors() { return [ @@ -61,12 +62,13 @@ class OfficesController extends Controller public function actionCreate() { $model = new Offices(); - + $cities = DicCities::find()->all(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', [ 'model' => $model, + 'cities' => $cities, ]); } } @@ -80,12 +82,13 @@ class OfficesController extends Controller public function actionUpdate($id) { $model = $this->findModel($id); - + $cities = DicCities::find()->all(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', [ 'model' => $model, + 'cities' => $cities, ]); } } diff --git a/backend/views/layouts/column.php b/backend/views/layouts/column.php index cab80ad..048a5c8 100644 --- a/backend/views/layouts/column.php +++ b/backend/views/layouts/column.php @@ -316,7 +316,7 @@ $this->beginContent('@app/views/layouts/main.php'); ['label' => 'Категории товаров', 'url' => ['currency/index']], ['label' => 'Vin коды', 'url' => ['currency/index']], ['label' => 'Запросы по номеру', 'url' => ['currency/index']], - ['label' => 'Офисы', 'url' => ['currency/index']], + ['label' => 'Офисы', 'url' => ['offices/index']], ], ], ['label' => 'Справочник', 'url' => ['#'], 'items' => [ diff --git a/backend/views/margins-groups/_form.php b/backend/views/margins-groups/_form.php index 71926fd..b3b57c7 100644 --- a/backend/views/margins-groups/_form.php +++ b/backend/views/margins-groups/_form.php @@ -11,9 +11,9 @@ use yii\helpers\ArrayHelper;
- field($model, 'importer_id')->dropDownList(ArrayHelper::map($importers, 'id', 'name'), ['prompt' => 'Выберие город']) ?> + field($model, 'importer_id')->dropDownList(ArrayHelper::map($importers, 'id', 'name')) ?> - field($model, 'margin_id')->dropDownList(ArrayHelper::map($margin, 'id', 'name'), ['prompt' => 'Выберие город']) ?> + field($model, 'margin_id')->dropDownList(ArrayHelper::map($margin, 'id', 'name')) ?> field($model, 'group')->textInput(['maxlength' => true]) ?> diff --git a/backend/views/margins-importers-import/_form.php b/backend/views/margins-importers-import/_form.php index 2205356..5b035f5 100644 --- a/backend/views/margins-importers-import/_form.php +++ b/backend/views/margins-importers-import/_form.php @@ -2,7 +2,7 @@ use yii\helpers\Html; use yii\widgets\ActiveForm; - +use \yii\helpers\ArrayHelper; /* @var $this yii\web\View */ /* @var $model common\models\MarginsImportersImport */ /* @var $form yii\widgets\ActiveForm */ @@ -12,14 +12,13 @@ use yii\widgets\ActiveForm; - field($model, 'importer_id')->textInput() ?> + field($model, 'importer_id')->dropDownList(ArrayHelper::map($importers, 'id', 'name')) ?> - field($model, 'margin_id')->textInput() ?> + field($model, 'margin_id')->dropDownList(ArrayHelper::map($margin, 'id', 'name')) ?> field($model, 'koef')->textInput() ?> - field($model, 'finish')->textInput() ?> - + field($model, 'finish')->checkbox() ?>
isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
diff --git a/backend/views/margins-importers-import/create.php b/backend/views/margins-importers-import/create.php index e436a73..58fa978 100644 --- a/backend/views/margins-importers-import/create.php +++ b/backend/views/margins-importers-import/create.php @@ -16,6 +16,8 @@ $this->params['breadcrumbs'][] = $this->title; render('_form', [ 'model' => $model, + 'importers' => $importers, + 'margin' => $margin, ]) ?>
diff --git a/backend/views/margins-importers-import/index.php b/backend/views/margins-importers-import/index.php index da39077..e42c4e2 100644 --- a/backend/views/margins-importers-import/index.php +++ b/backend/views/margins-importers-import/index.php @@ -25,9 +25,14 @@ $this->params['breadcrumbs'][] = $this->title; 'columns' => [ ['class' => 'yii\grid\SerialColumn'], - //'id', - 'importer_id', - 'margin_id', + [ + 'attribute' => 'importer_id', + 'value' => 'importers.name' + ], + [ + 'attribute' => 'margin_id', + 'value' => 'margins.name' + ], 'koef', 'finish', diff --git a/backend/views/margins-importers-import/update.php b/backend/views/margins-importers-import/update.php index bc85715..2b2907d 100644 --- a/backend/views/margins-importers-import/update.php +++ b/backend/views/margins-importers-import/update.php @@ -16,6 +16,8 @@ $this->params['breadcrumbs'][] = 'Update'; render('_form', [ 'model' => $model, + 'importers' => $importers, + 'margin' => $margin, ]) ?> diff --git a/backend/views/margins-importers/_form.php b/backend/views/margins-importers/_form.php index 926438a..dff16f3 100644 --- a/backend/views/margins-importers/_form.php +++ b/backend/views/margins-importers/_form.php @@ -12,9 +12,9 @@ use yii\helpers\ArrayHelper; - field($model, 'importer_id')->dropDownList(ArrayHelper::map($importers, 'id', 'name'), ['prompt' => 'Выберие город']) ?> + field($model, 'importer_id')->dropDownList(ArrayHelper::map($importers, 'id', 'name')) ?> - field($model, 'margin_id')->dropDownList(ArrayHelper::map($margin, 'id', 'name'), ['prompt' => 'Выберие город']) ?> + field($model, 'margin_id')->dropDownList(ArrayHelper::map($margin, 'id', 'name')) ?> field($model, 'koef')->textInput() ?> diff --git a/backend/views/margins-importers/index.php b/backend/views/margins-importers/index.php index a4ac91f..135a475 100644 --- a/backend/views/margins-importers/index.php +++ b/backend/views/margins-importers/index.php @@ -25,8 +25,14 @@ $this->params['breadcrumbs'][] = $this->title; 'columns' => [ ['class' => 'yii\grid\SerialColumn'], - 'importers.name', - 'margins.name', + [ + 'attribute' => 'importer_id', + 'value' => 'importers.name' + ], + [ + 'attribute' => 'margin_id', + 'value' => 'margins.name' + ], 'koef', ['class' => 'yii\grid\ActionColumn'], diff --git a/backend/views/offices/_form.php b/backend/views/offices/_form.php index a5a0b64..b5ccc42 100644 --- a/backend/views/offices/_form.php +++ b/backend/views/offices/_form.php @@ -16,11 +16,7 @@ use yii\widgets\ActiveForm; field($model, 'info')->textarea(['rows' => 6]) ?> - field($model, 'city_id')->textInput() ?> - - field($model, 'is_default')->textInput() ?> - - field($model, 'content_delete')->textarea(['rows' => 6]) ?> + field($model, 'city_id')->dropDownList(\yii\helpers\ArrayHelper::map($cities, 'id', 'name'), ['prompt' => 'Выберие город']) ?> field($model, 'coords')->textInput(['maxlength' => true]) ?> diff --git a/backend/views/offices/create.php b/backend/views/offices/create.php index 41d2a4c..d143d84 100644 --- a/backend/views/offices/create.php +++ b/backend/views/offices/create.php @@ -16,6 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; render('_form', [ 'model' => $model, + 'cities' => $cities, ]) ?> diff --git a/backend/views/offices/index.php b/backend/views/offices/index.php index b1d62f3..308afdf 100644 --- a/backend/views/offices/index.php +++ b/backend/views/offices/index.php @@ -25,17 +25,17 @@ $this->params['breadcrumbs'][] = $this->title; 'columns' => [ ['class' => 'yii\grid\SerialColumn'], - 'id', 'name', - 'info:ntext', - 'city_id', - 'is_default', + [ + 'attribute' => 'city_id', + 'value' => 'dicCities.name' + ], // 'content_delete:ntext', // 'coords', // 'phones', - // 'address', - // 'email:email', - // 'skype', + 'address', + 'email:email', + 'skype', ['class' => 'yii\grid\ActionColumn'], ], diff --git a/backend/views/offices/update.php b/backend/views/offices/update.php index 8c682b2..f288c43 100644 --- a/backend/views/offices/update.php +++ b/backend/views/offices/update.php @@ -16,6 +16,7 @@ $this->params['breadcrumbs'][] = 'Update'; render('_form', [ 'model' => $model, + 'cities' => $cities, ]) ?> diff --git a/common/models/MarginsGroupsSearch.php b/common/models/MarginsGroupsSearch.php index f5e43df..3f37a40 100644 --- a/common/models/MarginsGroupsSearch.php +++ b/common/models/MarginsGroupsSearch.php @@ -68,7 +68,7 @@ class MarginsGroupsSearch extends MarginsGroups ]); $query->andFilterWhere(['like', 'group', $this->group]); - $query->andFilterWhere(['like', Importers::tableName().'name', $this->importer_id]); + $query->andFilterWhere(['like', Importers::tableName().'.name', $this->importer_id]); $query->andFilterWhere(['like', Margins::tableName().'.name', $this->margin_id]); return $dataProvider; diff --git a/common/models/MarginsImportersImport.php b/common/models/MarginsImportersImport.php index 05fcda5..e953536 100644 --- a/common/models/MarginsImportersImport.php +++ b/common/models/MarginsImportersImport.php @@ -2,6 +2,7 @@ namespace common\models; +use backend\models\Importers; use Yii; /** @@ -43,10 +44,20 @@ class MarginsImportersImport extends \yii\db\ActiveRecord { return [ 'id' => 'ID', - 'importer_id' => 'Importer ID', - 'margin_id' => 'Margin ID', - 'koef' => 'Koef', - 'finish' => 'Finish', + 'importer_id' => 'Поставщик', + 'margin_id' => 'Тип цены', + 'koef' => 'Коэффициент', + 'finish' => 'Активно', ]; } + + public function getImporters() + { + return $this->hasOne(Importers::className(), ['id' => 'importer_id']); + } + + public function getMargins() + { + return $this->hasOne(Margins::className(), ['id' => 'margin_id']); + } } diff --git a/common/models/MarginsImportersImportSearch.php b/common/models/MarginsImportersImportSearch.php index f299de4..7cb3a85 100644 --- a/common/models/MarginsImportersImportSearch.php +++ b/common/models/MarginsImportersImportSearch.php @@ -2,6 +2,7 @@ namespace common\models; +use backend\models\Importers; use Yii; use yii\base\Model; use yii\data\ActiveDataProvider; @@ -18,8 +19,9 @@ class MarginsImportersImportSearch extends MarginsImportersImport public function rules() { return [ - [['id', 'importer_id', 'margin_id', 'finish'], 'integer'], + [['id', 'finish'], 'integer'], [['koef'], 'number'], + [[ 'importer_id', 'margin_id',], 'safe'] ]; } @@ -54,15 +56,16 @@ class MarginsImportersImportSearch extends MarginsImportersImport // $query->where('0=1'); return $dataProvider; } - + $query->joinWith(['importers','margins']); $query->andFilterWhere([ 'id' => $this->id, - 'importer_id' => $this->importer_id, - 'margin_id' => $this->margin_id, 'koef' => $this->koef, 'finish' => $this->finish, ]); + $query->andFilterWhere(['like', Importers::tableName().'.name', $this->importer_id]); + $query->andFilterWhere(['like', Margins::tableName().'.name', $this->margin_id]); + return $dataProvider; } } diff --git a/common/models/MarginsImportersSearch.php b/common/models/MarginsImportersSearch.php index 4412a00..0810591 100644 --- a/common/models/MarginsImportersSearch.php +++ b/common/models/MarginsImportersSearch.php @@ -2,6 +2,7 @@ namespace common\models; +use backend\models\Importers; use Yii; use yii\base\Model; use yii\data\ActiveDataProvider; @@ -18,7 +19,8 @@ class MarginsImportersSearch extends MarginsImporters public function rules() { return [ - [['id', 'importer_id', 'margin_id'], 'integer'], + [['id',], 'integer'], + [[ 'importer_id', 'margin_id',], 'safe'], [['koef'], 'number'], ]; } @@ -54,14 +56,14 @@ class MarginsImportersSearch extends MarginsImporters // $query->where('0=1'); return $dataProvider; } - + $query->joinWith(['importers','margins']); $query->andFilterWhere([ 'id' => $this->id, - 'importer_id' => $this->importer_id, - 'margin_id' => $this->margin_id, 'koef' => $this->koef, ]); + $query->andFilterWhere(['like', Importers::tableName().'.name', $this->importer_id]); + $query->andFilterWhere(['like', Margins::tableName().'.name', $this->margin_id]); return $dataProvider; } } diff --git a/common/models/Offices.php b/common/models/Offices.php index ab36ee6..0618ae4 100644 --- a/common/models/Offices.php +++ b/common/models/Offices.php @@ -52,16 +52,21 @@ class Offices extends \yii\db\ActiveRecord { return [ 'id' => 'ID', - 'name' => 'Name', - 'info' => 'Info', - 'city_id' => 'City ID', + 'name' => 'Название', + 'info' => 'Описание', + 'city_id' => 'Город', 'is_default' => 'Is Default', 'content_delete' => 'Content Delete', - 'coords' => 'Coords', - 'phones' => 'Phones', - 'address' => 'Address', + 'coords' => 'Координаты карты Google', + 'phones' => 'Телефоны', + 'address' => 'Адрес', 'email' => 'Email', 'skype' => 'Skype', ]; } + + public function getDicCities() + { + return $this->hasOne(DicCities::className(), ['id' => 'city_id']); + } } -- libgit2 0.21.4