Commit 615358fb17e1482247b78120a8d7df0cdfdd8969

Authored by Administrator
1 parent 03bffb3b

Importers CRUD

backend/controllers/MarginsImportersImportController.php
... ... @@ -2,6 +2,8 @@
2 2  
3 3 namespace backend\controllers;
4 4  
  5 +use backend\models\Importers;
  6 +use common\models\Margins;
5 7 use Yii;
6 8 use common\models\MarginsImportersImport;
7 9 use common\models\MarginsImportersImportSearch;
... ... @@ -64,12 +66,15 @@ class MarginsImportersImportController extends Controller
64 66 public function actionCreate()
65 67 {
66 68 $model = new MarginsImportersImport();
67   -
  69 + $importers= Importers::find()->all();
  70 + $margin = Margins::find()->all();
68 71 if ($model->load(Yii::$app->request->post()) && $model->save()) {
69 72 return $this->redirect(['view', 'id' => $model->id]);
70 73 } else {
71 74 return $this->render('create', [
72 75 'model' => $model,
  76 + 'importers' => $importers,
  77 + 'margin' => $margin,
73 78 ]);
74 79 }
75 80 }
... ... @@ -83,12 +88,15 @@ class MarginsImportersImportController extends Controller
83 88 public function actionUpdate($id)
84 89 {
85 90 $model = $this->findModel($id);
86   -
  91 + $importers= Importers::find()->all();
  92 + $margin = Margins::find()->all();
87 93 if ($model->load(Yii::$app->request->post()) && $model->save()) {
88 94 return $this->redirect(['view', 'id' => $model->id]);
89 95 } else {
90 96 return $this->render('update', [
91 97 'model' => $model,
  98 + 'importers' => $importers,
  99 + 'margin' => $margin,
92 100 ]);
93 101 }
94 102 }
... ...
backend/controllers/OfficesController.php
... ... @@ -2,6 +2,7 @@
2 2  
3 3 namespace backend\controllers;
4 4  
  5 +use common\models\DicCities;
5 6 use Yii;
6 7 use common\models\Offices;
7 8 use common\models\OfficesSearch;
... ... @@ -13,7 +14,7 @@ use yii\filters\VerbFilter;
13 14 * OfficesController implements the CRUD actions for Offices model.
14 15 */
15 16 class OfficesController extends Controller
16   -{
  17 +{ public $layout = "/column";
17 18 public function behaviors()
18 19 {
19 20 return [
... ... @@ -61,12 +62,13 @@ class OfficesController extends Controller
61 62 public function actionCreate()
62 63 {
63 64 $model = new Offices();
64   -
  65 + $cities = DicCities::find()->all();
65 66 if ($model->load(Yii::$app->request->post()) && $model->save()) {
66 67 return $this->redirect(['view', 'id' => $model->id]);
67 68 } else {
68 69 return $this->render('create', [
69 70 'model' => $model,
  71 + 'cities' => $cities,
70 72 ]);
71 73 }
72 74 }
... ... @@ -80,12 +82,13 @@ class OfficesController extends Controller
80 82 public function actionUpdate($id)
81 83 {
82 84 $model = $this->findModel($id);
83   -
  85 + $cities = DicCities::find()->all();
84 86 if ($model->load(Yii::$app->request->post()) && $model->save()) {
85 87 return $this->redirect(['view', 'id' => $model->id]);
86 88 } else {
87 89 return $this->render('update', [
88 90 'model' => $model,
  91 + 'cities' => $cities,
89 92 ]);
90 93 }
91 94 }
... ...
backend/views/layouts/column.php
... ... @@ -316,7 +316,7 @@ $this->beginContent('@app/views/layouts/main.php');
316 316 ['label' => 'Категории товаров', 'url' => ['currency/index']],
317 317 ['label' => 'Vin коды', 'url' => ['currency/index']],
318 318 ['label' => 'Запросы по номеру', 'url' => ['currency/index']],
319   - ['label' => 'Офисы', 'url' => ['currency/index']],
  319 + ['label' => 'Офисы', 'url' => ['offices/index']],
320 320 ],
321 321 ],
322 322 ['label' => 'Справочник', 'url' => ['#'], 'items' => [
... ...
backend/views/margins-groups/_form.php
... ... @@ -11,9 +11,9 @@ use yii\helpers\ArrayHelper;
11 11 <div class="margins-groups-form">
12 12 <?php $form = ActiveForm::begin(); ?>
13 13  
14   - <?= $form->field($model, 'importer_id')->dropDownList(ArrayHelper::map($importers, 'id', 'name'), ['prompt' => 'Выберие город']) ?>
  14 + <?= $form->field($model, 'importer_id')->dropDownList(ArrayHelper::map($importers, 'id', 'name')) ?>
15 15  
16   - <?= $form->field($model, 'margin_id')->dropDownList(ArrayHelper::map($margin, 'id', 'name'), ['prompt' => 'Выберие город']) ?>
  16 + <?= $form->field($model, 'margin_id')->dropDownList(ArrayHelper::map($margin, 'id', 'name')) ?>
17 17  
18 18 <?= $form->field($model, 'group')->textInput(['maxlength' => true]) ?>
19 19  
... ...
backend/views/margins-importers-import/_form.php
... ... @@ -2,7 +2,7 @@
2 2  
3 3 use yii\helpers\Html;
4 4 use yii\widgets\ActiveForm;
5   -
  5 +use \yii\helpers\ArrayHelper;
6 6 /* @var $this yii\web\View */
7 7 /* @var $model common\models\MarginsImportersImport */
8 8 /* @var $form yii\widgets\ActiveForm */
... ... @@ -12,14 +12,13 @@ use yii\widgets\ActiveForm;
12 12  
13 13 <?php $form = ActiveForm::begin(); ?>
14 14  
15   - <?= $form->field($model, 'importer_id')->textInput() ?>
  15 + <?= $form->field($model, 'importer_id')->dropDownList(ArrayHelper::map($importers, 'id', 'name')) ?>
16 16  
17   - <?= $form->field($model, 'margin_id')->textInput() ?>
  17 + <?= $form->field($model, 'margin_id')->dropDownList(ArrayHelper::map($margin, 'id', 'name')) ?>
18 18  
19 19 <?= $form->field($model, 'koef')->textInput() ?>
20 20  
21   - <?= $form->field($model, 'finish')->textInput() ?>
22   -
  21 + <?= $form->field($model, 'finish')->checkbox() ?>
23 22 <div class="form-group">
24 23 <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
25 24 </div>
... ...
backend/views/margins-importers-import/create.php
... ... @@ -16,6 +16,8 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
16 16  
17 17 <?= $this->render('_form', [
18 18 'model' => $model,
  19 + 'importers' => $importers,
  20 + 'margin' => $margin,
19 21 ]) ?>
20 22  
21 23 </div>
... ...
backend/views/margins-importers-import/index.php
... ... @@ -25,9 +25,14 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
25 25 'columns' => [
26 26 ['class' => 'yii\grid\SerialColumn'],
27 27  
28   - //'id',
29   - 'importer_id',
30   - 'margin_id',
  28 + [
  29 + 'attribute' => 'importer_id',
  30 + 'value' => 'importers.name'
  31 + ],
  32 + [
  33 + 'attribute' => 'margin_id',
  34 + 'value' => 'margins.name'
  35 + ],
31 36 'koef',
32 37 'finish',
33 38  
... ...
backend/views/margins-importers-import/update.php
... ... @@ -16,6 +16,8 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = &#39;Update&#39;;
16 16  
17 17 <?= $this->render('_form', [
18 18 'model' => $model,
  19 + 'importers' => $importers,
  20 + 'margin' => $margin,
19 21 ]) ?>
20 22  
21 23 </div>
... ...
backend/views/margins-importers/_form.php
... ... @@ -12,9 +12,9 @@ use yii\helpers\ArrayHelper;
12 12  
13 13 <?php $form = ActiveForm::begin(); ?>
14 14  
15   - <?= $form->field($model, 'importer_id')->dropDownList(ArrayHelper::map($importers, 'id', 'name'), ['prompt' => 'Выберие город']) ?>
  15 + <?= $form->field($model, 'importer_id')->dropDownList(ArrayHelper::map($importers, 'id', 'name')) ?>
16 16  
17   - <?= $form->field($model, 'margin_id')->dropDownList(ArrayHelper::map($margin, 'id', 'name'), ['prompt' => 'Выберие город']) ?>
  17 + <?= $form->field($model, 'margin_id')->dropDownList(ArrayHelper::map($margin, 'id', 'name')) ?>
18 18  
19 19 <?= $form->field($model, 'koef')->textInput() ?>
20 20  
... ...
backend/views/margins-importers/index.php
... ... @@ -25,8 +25,14 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
25 25 'columns' => [
26 26 ['class' => 'yii\grid\SerialColumn'],
27 27  
28   - 'importers.name',
29   - 'margins.name',
  28 + [
  29 + 'attribute' => 'importer_id',
  30 + 'value' => 'importers.name'
  31 + ],
  32 + [
  33 + 'attribute' => 'margin_id',
  34 + 'value' => 'margins.name'
  35 + ],
30 36 'koef',
31 37  
32 38 ['class' => 'yii\grid\ActionColumn'],
... ...
backend/views/offices/_form.php
... ... @@ -16,11 +16,7 @@ use yii\widgets\ActiveForm;
16 16  
17 17 <?= $form->field($model, 'info')->textarea(['rows' => 6]) ?>
18 18  
19   - <?= $form->field($model, 'city_id')->textInput() ?>
20   -
21   - <?= $form->field($model, 'is_default')->textInput() ?>
22   -
23   - <?= $form->field($model, 'content_delete')->textarea(['rows' => 6]) ?>
  19 + <?= $form->field($model, 'city_id')->dropDownList(\yii\helpers\ArrayHelper::map($cities, 'id', 'name'), ['prompt' => 'Выберие город']) ?>
24 20  
25 21 <?= $form->field($model, 'coords')->textInput(['maxlength' => true]) ?>
26 22  
... ...
backend/views/offices/create.php
... ... @@ -16,6 +16,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
16 16  
17 17 <?= $this->render('_form', [
18 18 'model' => $model,
  19 + 'cities' => $cities,
19 20 ]) ?>
20 21  
21 22 </div>
... ...
backend/views/offices/index.php
... ... @@ -25,17 +25,17 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
25 25 'columns' => [
26 26 ['class' => 'yii\grid\SerialColumn'],
27 27  
28   - 'id',
29 28 'name',
30   - 'info:ntext',
31   - 'city_id',
32   - 'is_default',
  29 + [
  30 + 'attribute' => 'city_id',
  31 + 'value' => 'dicCities.name'
  32 + ],
33 33 // 'content_delete:ntext',
34 34 // 'coords',
35 35 // 'phones',
36   - // 'address',
37   - // 'email:email',
38   - // 'skype',
  36 + 'address',
  37 + 'email:email',
  38 + 'skype',
39 39  
40 40 ['class' => 'yii\grid\ActionColumn'],
41 41 ],
... ...
backend/views/offices/update.php
... ... @@ -16,6 +16,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = &#39;Update&#39;;
16 16  
17 17 <?= $this->render('_form', [
18 18 'model' => $model,
  19 + 'cities' => $cities,
19 20 ]) ?>
20 21  
21 22 </div>
... ...
common/models/MarginsGroupsSearch.php
... ... @@ -68,7 +68,7 @@ class MarginsGroupsSearch extends MarginsGroups
68 68 ]);
69 69  
70 70 $query->andFilterWhere(['like', 'group', $this->group]);
71   - $query->andFilterWhere(['like', Importers::tableName().'name', $this->importer_id]);
  71 + $query->andFilterWhere(['like', Importers::tableName().'.name', $this->importer_id]);
72 72 $query->andFilterWhere(['like', Margins::tableName().'.name', $this->margin_id]);
73 73  
74 74 return $dataProvider;
... ...
common/models/MarginsImportersImport.php
... ... @@ -2,6 +2,7 @@
2 2  
3 3 namespace common\models;
4 4  
  5 +use backend\models\Importers;
5 6 use Yii;
6 7  
7 8 /**
... ... @@ -43,10 +44,20 @@ class MarginsImportersImport extends \yii\db\ActiveRecord
43 44 {
44 45 return [
45 46 'id' => 'ID',
46   - 'importer_id' => 'Importer ID',
47   - 'margin_id' => 'Margin ID',
48   - 'koef' => 'Koef',
49   - 'finish' => 'Finish',
  47 + 'importer_id' => 'Поставщик',
  48 + 'margin_id' => 'Тип цены',
  49 + 'koef' => 'Коэффициент',
  50 + 'finish' => 'Активно',
50 51 ];
51 52 }
  53 +
  54 + public function getImporters()
  55 + {
  56 + return $this->hasOne(Importers::className(), ['id' => 'importer_id']);
  57 + }
  58 +
  59 + public function getMargins()
  60 + {
  61 + return $this->hasOne(Margins::className(), ['id' => 'margin_id']);
  62 + }
52 63 }
... ...
common/models/MarginsImportersImportSearch.php
... ... @@ -2,6 +2,7 @@
2 2  
3 3 namespace common\models;
4 4  
  5 +use backend\models\Importers;
5 6 use Yii;
6 7 use yii\base\Model;
7 8 use yii\data\ActiveDataProvider;
... ... @@ -18,8 +19,9 @@ class MarginsImportersImportSearch extends MarginsImportersImport
18 19 public function rules()
19 20 {
20 21 return [
21   - [['id', 'importer_id', 'margin_id', 'finish'], 'integer'],
  22 + [['id', 'finish'], 'integer'],
22 23 [['koef'], 'number'],
  24 + [[ 'importer_id', 'margin_id',], 'safe']
23 25 ];
24 26 }
25 27  
... ... @@ -54,15 +56,16 @@ class MarginsImportersImportSearch extends MarginsImportersImport
54 56 // $query->where('0=1');
55 57 return $dataProvider;
56 58 }
57   -
  59 + $query->joinWith(['importers','margins']);
58 60 $query->andFilterWhere([
59 61 'id' => $this->id,
60   - 'importer_id' => $this->importer_id,
61   - 'margin_id' => $this->margin_id,
62 62 'koef' => $this->koef,
63 63 'finish' => $this->finish,
64 64 ]);
65 65  
  66 + $query->andFilterWhere(['like', Importers::tableName().'.name', $this->importer_id]);
  67 + $query->andFilterWhere(['like', Margins::tableName().'.name', $this->margin_id]);
  68 +
66 69 return $dataProvider;
67 70 }
68 71 }
... ...
common/models/MarginsImportersSearch.php
... ... @@ -2,6 +2,7 @@
2 2  
3 3 namespace common\models;
4 4  
  5 +use backend\models\Importers;
5 6 use Yii;
6 7 use yii\base\Model;
7 8 use yii\data\ActiveDataProvider;
... ... @@ -18,7 +19,8 @@ class MarginsImportersSearch extends MarginsImporters
18 19 public function rules()
19 20 {
20 21 return [
21   - [['id', 'importer_id', 'margin_id'], 'integer'],
  22 + [['id',], 'integer'],
  23 + [[ 'importer_id', 'margin_id',], 'safe'],
22 24 [['koef'], 'number'],
23 25 ];
24 26 }
... ... @@ -54,14 +56,14 @@ class MarginsImportersSearch extends MarginsImporters
54 56 // $query->where('0=1');
55 57 return $dataProvider;
56 58 }
57   -
  59 + $query->joinWith(['importers','margins']);
58 60 $query->andFilterWhere([
59 61 'id' => $this->id,
60   - 'importer_id' => $this->importer_id,
61   - 'margin_id' => $this->margin_id,
62 62 'koef' => $this->koef,
63 63 ]);
64 64  
  65 + $query->andFilterWhere(['like', Importers::tableName().'.name', $this->importer_id]);
  66 + $query->andFilterWhere(['like', Margins::tableName().'.name', $this->margin_id]);
65 67 return $dataProvider;
66 68 }
67 69 }
... ...
common/models/Offices.php
... ... @@ -52,16 +52,21 @@ class Offices extends \yii\db\ActiveRecord
52 52 {
53 53 return [
54 54 'id' => 'ID',
55   - 'name' => 'Name',
56   - 'info' => 'Info',
57   - 'city_id' => 'City ID',
  55 + 'name' => 'Название',
  56 + 'info' => 'Описание',
  57 + 'city_id' => 'Город',
58 58 'is_default' => 'Is Default',
59 59 'content_delete' => 'Content Delete',
60   - 'coords' => 'Coords',
61   - 'phones' => 'Phones',
62   - 'address' => 'Address',
  60 + 'coords' => 'Координаты карты Google',
  61 + 'phones' => 'Телефоны',
  62 + 'address' => 'Адрес',
63 63 'email' => 'Email',
64 64 'skype' => 'Skype',
65 65 ];
66 66 }
  67 +
  68 + public function getDicCities()
  69 + {
  70 + return $this->hasOne(DicCities::className(), ['id' => 'city_id']);
  71 + }
67 72 }
... ...