Commit c85057452abad0e39da1e1e018af0ab74de0c428
1 parent
c77aa128
Importers CRUD
Showing
21 changed files
with
110 additions
and
41 deletions
Show diff stats
backend/controllers/MarginsGroupsController.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\MarginsGroups; |
| 7 | 9 | use common\models\MarginsGroupsSearch; |
| ... | ... | @@ -64,11 +66,16 @@ class MarginsGroupsController extends Controller |
| 64 | 66 | { |
| 65 | 67 | $model = new MarginsGroups(); |
| 66 | 68 | |
| 69 | + $importers= Importers::find()->all(); | |
| 70 | + $margin = Margins::find()->all(); | |
| 71 | + | |
| 67 | 72 | if ($model->load(Yii::$app->request->post()) && $model->save()) { |
| 68 | 73 | return $this->redirect(['view', 'id' => $model->id]); |
| 69 | 74 | } else { |
| 70 | 75 | return $this->render('create', [ |
| 71 | 76 | 'model' => $model, |
| 77 | + 'importers' => $importers, | |
| 78 | + 'margin' => $margin, | |
| 72 | 79 | ]); |
| 73 | 80 | } |
| 74 | 81 | } |
| ... | ... | @@ -83,11 +90,16 @@ class MarginsGroupsController extends Controller |
| 83 | 90 | { |
| 84 | 91 | $model = $this->findModel($id); |
| 85 | 92 | |
| 93 | + $importers = Importers::find()->all(); | |
| 94 | + $margin = Margins::find()->all(); | |
| 95 | + | |
| 86 | 96 | if ($model->load(Yii::$app->request->post()) && $model->save()) { |
| 87 | 97 | return $this->redirect(['view', 'id' => $model->id]); |
| 88 | 98 | } else { |
| 89 | 99 | return $this->render('update', [ |
| 90 | 100 | 'model' => $model, |
| 101 | + 'importers' => $importers, | |
| 102 | + 'margin' => $margin, | |
| 91 | 103 | ]); |
| 92 | 104 | } |
| 93 | 105 | } | ... | ... |
backend/controllers/MarginsImportersController.php
| ... | ... | @@ -8,6 +8,8 @@ use common\models\MarginsImportersSearch; |
| 8 | 8 | use yii\web\Controller; |
| 9 | 9 | use yii\web\NotFoundHttpException; |
| 10 | 10 | use yii\filters\VerbFilter; |
| 11 | +use backend\models\Importers; | |
| 12 | +use common\models\Margins; | |
| 11 | 13 | |
| 12 | 14 | /** |
| 13 | 15 | * MarginsImportersController implements the CRUD actions for MarginsImporters model. |
| ... | ... | @@ -64,12 +66,16 @@ class MarginsImportersController extends Controller |
| 64 | 66 | public function actionCreate() |
| 65 | 67 | { |
| 66 | 68 | $model = new MarginsImporters(); |
| 69 | + $importers= Importers::find()->all(); | |
| 70 | + $margin = Margins::find()->all(); | |
| 67 | 71 | |
| 68 | 72 | if ($model->load(Yii::$app->request->post()) && $model->save()) { |
| 69 | 73 | return $this->redirect(['view', 'id' => $model->id]); |
| 70 | 74 | } else { |
| 71 | 75 | return $this->render('create', [ |
| 72 | 76 | 'model' => $model, |
| 77 | + 'importers' => $importers, | |
| 78 | + 'margin' => $margin, | |
| 73 | 79 | ]); |
| 74 | 80 | } |
| 75 | 81 | } |
| ... | ... | @@ -83,12 +89,16 @@ class MarginsImportersController extends Controller |
| 83 | 89 | public function actionUpdate($id) |
| 84 | 90 | { |
| 85 | 91 | $model = $this->findModel($id); |
| 92 | + $importers= Importers::find()->all(); | |
| 93 | + $margin = Margins::find()->all(); | |
| 86 | 94 | |
| 87 | 95 | if ($model->load(Yii::$app->request->post()) && $model->save()) { |
| 88 | 96 | return $this->redirect(['view', 'id' => $model->id]); |
| 89 | 97 | } else { |
| 90 | 98 | return $this->render('update', [ |
| 91 | 99 | 'model' => $model, |
| 100 | + 'importers' => $importers, | |
| 101 | + 'margin' => $margin, | |
| 92 | 102 | ]); |
| 93 | 103 | } |
| 94 | 104 | } | ... | ... |
backend/views/currency/_form.php
| ... | ... | @@ -16,10 +16,6 @@ use yii\widgets\ActiveForm; |
| 16 | 16 | |
| 17 | 17 | <?= $form->field($model, 'rate')->textInput() ?> |
| 18 | 18 | |
| 19 | - <?= $form->field($model, 'is_default')->textInput() ?> | |
| 20 | - | |
| 21 | - <?= $form->field($model, 'timestamp')->textInput() ?> | |
| 22 | - | |
| 23 | 19 | <div class="form-group"> |
| 24 | 20 | <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> |
| 25 | 21 | </div> | ... | ... |
backend/views/currency/_search.php
backend/views/currency/index.php
backend/views/currency/view.php
backend/views/margins-groups/_form.php
| ... | ... | @@ -2,25 +2,23 @@ |
| 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\MarginsGroups */ |
| 8 | 8 | /* @var $form yii\widgets\ActiveForm */ |
| 9 | 9 | ?> |
| 10 | 10 | |
| 11 | 11 | <div class="margins-groups-form"> |
| 12 | - | |
| 13 | 12 | <?php $form = ActiveForm::begin(); ?> |
| 14 | 13 | |
| 15 | - <?= $form->field($model, 'importer_id')->textInput() ?> | |
| 14 | + <?= $form->field($model, 'importer_id')->dropDownList(ArrayHelper::map($importers, 'id', 'name'), ['prompt' => 'Выберие город']) ?> | |
| 16 | 15 | |
| 17 | - <?= $form->field($model, 'margin_id')->textInput() ?> | |
| 16 | + <?= $form->field($model, 'margin_id')->dropDownList(ArrayHelper::map($margin, 'id', 'name'), ['prompt' => 'Выберие город']) ?> | |
| 18 | 17 | |
| 19 | 18 | <?= $form->field($model, 'group')->textInput(['maxlength' => true]) ?> |
| 20 | 19 | |
| 21 | 20 | <?= $form->field($model, 'koef')->textInput() ?> |
| 22 | 21 | |
| 23 | - <?= $form->field($model, 'timestamp')->textInput() ?> | |
| 24 | 22 | |
| 25 | 23 | <div class="form-group"> |
| 26 | 24 | <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | ... | ... |
backend/views/margins-groups/create.php
backend/views/margins-groups/index.php
| ... | ... | @@ -24,13 +24,17 @@ $this->params['breadcrumbs'][] = $this->title; |
| 24 | 24 | 'filterModel' => $searchModel, |
| 25 | 25 | 'columns' => [ |
| 26 | 26 | ['class' => 'yii\grid\SerialColumn'], |
| 27 | - | |
| 28 | - 'id', | |
| 29 | - 'importer_id', | |
| 30 | - 'margin_id', | |
| 27 | + [ | |
| 28 | + 'attribute' => 'importer_id', | |
| 29 | + 'value' => 'importers.name' | |
| 30 | + ], | |
| 31 | + [ | |
| 32 | + 'attribute' => 'margin_id', | |
| 33 | + 'value' => 'margins.name' | |
| 34 | + ], | |
| 31 | 35 | 'group', |
| 32 | 36 | 'koef', |
| 33 | - // 'timestamp', | |
| 37 | + 'timestamp', | |
| 34 | 38 | |
| 35 | 39 | ['class' => 'yii\grid\ActionColumn'], |
| 36 | 40 | ], | ... | ... |
backend/views/margins-groups/update.php
backend/views/margins-importers-import/index.php
backend/views/margins-importers/_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\MarginsImporters */ |
| 8 | 8 | /* @var $form yii\widgets\ActiveForm */ |
| ... | ... | @@ -12,9 +12,9 @@ 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'), ['prompt' => 'Выберие город']) ?> | |
| 16 | 16 | |
| 17 | - <?= $form->field($model, 'margin_id')->textInput() ?> | |
| 17 | + <?= $form->field($model, 'margin_id')->dropDownList(ArrayHelper::map($margin, 'id', 'name'), ['prompt' => 'Выберие город']) ?> | |
| 18 | 18 | |
| 19 | 19 | <?= $form->field($model, 'koef')->textInput() ?> |
| 20 | 20 | ... | ... |
backend/views/margins-importers/create.php
backend/views/margins-importers/index.php
| ... | ... | @@ -25,9 +25,8 @@ $this->params['breadcrumbs'][] = $this->title; |
| 25 | 25 | 'columns' => [ |
| 26 | 26 | ['class' => 'yii\grid\SerialColumn'], |
| 27 | 27 | |
| 28 | - 'id', | |
| 29 | - 'importer_id', | |
| 30 | - 'margin_id', | |
| 28 | + 'importers.name', | |
| 29 | + 'margins.name', | |
| 31 | 30 | 'koef', |
| 32 | 31 | |
| 33 | 32 | ['class' => 'yii\grid\ActionColumn'], | ... | ... |
backend/views/margins-importers/update.php
backend/views/margins/index.php
common/models/Currency.php
| ... | ... | @@ -52,4 +52,15 @@ class Currency extends \yii\db\ActiveRecord |
| 52 | 52 | 'timestamp' => 'Дата обновления', |
| 53 | 53 | ]; |
| 54 | 54 | } |
| 55 | + | |
| 56 | + | |
| 57 | + public function beforeSave($insert) | |
| 58 | + { | |
| 59 | + if (parent::beforeSave($insert)) { | |
| 60 | + $this->timestamp = date("Y-m-d H:i:s"); | |
| 61 | + return true; | |
| 62 | + } else { | |
| 63 | + return false; | |
| 64 | + } | |
| 65 | + } | |
| 55 | 66 | } | ... | ... |
common/models/Margins.php
common/models/MarginsGroups.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 | /** |
| ... | ... | @@ -46,11 +47,31 @@ class MarginsGroups extends \yii\db\ActiveRecord |
| 46 | 47 | { |
| 47 | 48 | return [ |
| 48 | 49 | 'id' => 'ID', |
| 49 | - 'importer_id' => 'Importer ID', | |
| 50 | - 'margin_id' => 'Margin ID', | |
| 51 | - 'group' => 'Group', | |
| 52 | - 'koef' => 'Koef', | |
| 53 | - 'timestamp' => 'Timestamp', | |
| 50 | + 'importer_id' => 'Поставщик', | |
| 51 | + 'margin_id' => 'Тип цены', | |
| 52 | + 'group' => 'ГРУППА', | |
| 53 | + 'koef' => 'Коэффициент', | |
| 54 | + 'timestamp' => 'ДАТА', | |
| 54 | 55 | ]; |
| 55 | 56 | } |
| 57 | + | |
| 58 | + public function beforeSave($insert) | |
| 59 | + { | |
| 60 | + if (parent::beforeSave($insert)) { | |
| 61 | + $this->timestamp = date("Y-m-d H:i:s"); | |
| 62 | + return true; | |
| 63 | + } else { | |
| 64 | + return false; | |
| 65 | + } | |
| 66 | + } | |
| 67 | + | |
| 68 | + public function getImporters() | |
| 69 | + { | |
| 70 | + return $this->hasOne(Importers::className(), ['id' => 'importer_id']); | |
| 71 | + } | |
| 72 | + | |
| 73 | + public function getMargins() | |
| 74 | + { | |
| 75 | + return $this->hasOne(Margins::className(), ['id' => 'margin_id']); | |
| 76 | + } | |
| 56 | 77 | } | ... | ... |
common/models/MarginsGroupsSearch.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,8 @@ class MarginsGroupsSearch extends MarginsGroups |
| 18 | 19 | public function rules() |
| 19 | 20 | { |
| 20 | 21 | return [ |
| 21 | - [['id', 'importer_id', 'margin_id'], 'integer'], | |
| 22 | - [['group', 'timestamp'], 'safe'], | |
| 22 | + [['id',], 'integer'], | |
| 23 | + [['group', 'timestamp', 'importer_id', 'margin_id'], 'safe'], | |
| 23 | 24 | [['koef'], 'number'], |
| 24 | 25 | ]; |
| 25 | 26 | } |
| ... | ... | @@ -56,15 +57,19 @@ class MarginsGroupsSearch extends MarginsGroups |
| 56 | 57 | return $dataProvider; |
| 57 | 58 | } |
| 58 | 59 | |
| 60 | + | |
| 61 | + $query->joinWith(['importers','margins']); | |
| 62 | + | |
| 63 | + | |
| 59 | 64 | $query->andFilterWhere([ |
| 60 | 65 | 'id' => $this->id, |
| 61 | - 'importer_id' => $this->importer_id, | |
| 62 | - 'margin_id' => $this->margin_id, | |
| 63 | 66 | 'koef' => $this->koef, |
| 64 | 67 | 'timestamp' => $this->timestamp, |
| 65 | 68 | ]); |
| 66 | 69 | |
| 67 | 70 | $query->andFilterWhere(['like', 'group', $this->group]); |
| 71 | + $query->andFilterWhere(['like', Importers::tableName().'name', $this->importer_id]); | |
| 72 | + $query->andFilterWhere(['like', Margins::tableName().'.name', $this->margin_id]); | |
| 68 | 73 | |
| 69 | 74 | return $dataProvider; |
| 70 | 75 | } | ... | ... |
common/models/MarginsImporters.php
| ... | ... | @@ -3,6 +3,7 @@ |
| 3 | 3 | namespace common\models; |
| 4 | 4 | |
| 5 | 5 | use Yii; |
| 6 | +use backend\models\Importers; | |
| 6 | 7 | |
| 7 | 8 | /** |
| 8 | 9 | * This is the model class for table "w_margins_importers". |
| ... | ... | @@ -42,9 +43,19 @@ class MarginsImporters extends \yii\db\ActiveRecord |
| 42 | 43 | { |
| 43 | 44 | return [ |
| 44 | 45 | 'id' => 'ID', |
| 45 | - 'importer_id' => 'Importer ID', | |
| 46 | - 'margin_id' => 'Margin ID', | |
| 47 | - 'koef' => 'Koef', | |
| 46 | + 'importer_id' => 'Поставщик', | |
| 47 | + 'margin_id' => 'Тип цены', | |
| 48 | + 'koef' => 'Коэффициент', | |
| 48 | 49 | ]; |
| 49 | 50 | } |
| 51 | + | |
| 52 | + public function getImporters() | |
| 53 | + { | |
| 54 | + return $this->hasOne(Importers::className(), ['id' => 'importer_id']); | |
| 55 | + } | |
| 56 | + | |
| 57 | + public function getMargins() | |
| 58 | + { | |
| 59 | + return $this->hasOne(Margins::className(), ['id' => 'margin_id']); | |
| 60 | + } | |
| 50 | 61 | } | ... | ... |