From 741ecd87cd5ec8231a0f825ad5c6321b646c8594 Mon Sep 17 00:00:00 2001 From: Mihail Date: Fri, 16 Oct 2015 18:00:48 +0300 Subject: [PATCH] add migration for view Details Currency and change check-price view --- backend/controllers/CheckPriceController.php | 8 +++++--- backend/models/Currency.php | 7 ------- backend/models/Importers.php | 10 ++++++++++ backend/views/check-price/view.php | 35 ++++++++++++++++++++--------------- common/models/DetailsCurrency.php | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ console/migrations/m151016_130143_add_fk_currency_to_Importers.php | 11 ----------- console/migrations/m151016_144435_addViewDetailsCurrency.php | 30 ++++++++++++++++++++++++++++++ 7 files changed, 137 insertions(+), 36 deletions(-) create mode 100644 common/models/DetailsCurrency.php create mode 100644 console/migrations/m151016_144435_addViewDetailsCurrency.php diff --git a/backend/controllers/CheckPriceController.php b/backend/controllers/CheckPriceController.php index 3525ab3..a5a13f9 100644 --- a/backend/controllers/CheckPriceController.php +++ b/backend/controllers/CheckPriceController.php @@ -8,6 +8,7 @@ use yii\filters\AccessControl; use backend\components\base\BaseController; use yii\filters\VerbFilter; use backend\models\Details; +use common\models\DetailsCurrency; use backend\models\ImportersFiles; use backend\models\Importers; use yii\base\ErrorException; @@ -61,7 +62,7 @@ class CheckPriceController extends BaseController public function actionIndex() { - //$query = (new Query())->select('*')->from('{{%importer_files}}')->where(['not', ['time_end' => null]])->orderBy(['upload_time' => SORT_DESC]); + $query = Importers::find()->where(['active' => true])->orderBy(['price_date_update' => SORT_DESC]); $provider = new ActiveDataProvider([ 'query' => $query, @@ -79,11 +80,12 @@ class CheckPriceController extends BaseController public function actionView ($id, $date_update) { - $query = Details::find()->where(['IMPORT_ID' => $id, 'timestamp' => $date_update])->limit(20); + $query = DetailsCurrency::find()->where(['IMPORT_ID' => $id, 'timestamp' => $date_update])->limit(20); - $importer = Importers::findOne($id)->name; + $importer = Importers::findOne( $id ); $date = Yii::$app->formatter->asDate( $date_update, 'yyyy-MM-dd' ); + $provider = new ActiveDataProvider([ 'query' => $query, 'pagination' => false, diff --git a/backend/models/Currency.php b/backend/models/Currency.php index 819067c..fcb6570 100644 --- a/backend/models/Currency.php +++ b/backend/models/Currency.php @@ -15,13 +15,6 @@ use Yii; */ class Currency extends \yii\db\ActiveRecord { - /** - * @inheritdoc - */ - public static function tableName() - { - return 'w_currency'; - } /** * @inheritdoc diff --git a/backend/models/Importers.php b/backend/models/Importers.php index 221b09e..b07db1d 100644 --- a/backend/models/Importers.php +++ b/backend/models/Importers.php @@ -5,6 +5,7 @@ namespace backend\models; use common\components\CustomVarDamp; use Yii; use backend\components\base\BaseActiveRecord; +use backend\models\Currency; /** * @@ -89,6 +90,15 @@ class Importers extends BaseActiveRecord ]; } + public function getCurrency () + { + return $this->hasOne(Currency::className(), ['id' => 'currency_id'])->one()->name; + } + + public function getCurrencyRate () + { + return $this->hasOne(Currency::className(), ['id' => 'currency_id'])->one()->rate; + } public function getKeys () { diff --git a/backend/views/check-price/view.php b/backend/views/check-price/view.php index 680f946..9bcf7bd 100644 --- a/backend/views/check-price/view.php +++ b/backend/views/check-price/view.php @@ -8,24 +8,29 @@ use yii\bootstrap\Modal; /* @var $this yii\web\View */ /* @var $searchModel backend\models\CatalogSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ -$this->title = 'Прайс ' . Html::encode( "{$importer} от {$date}" ); +$this->title = 'Прайс ' . Html::encode("{$importer->name} от {$date}"); $this->params['breadcrumbs'][] = $this->title; ?> -
- -

title) ?>

- - $dataProvider, - - ] ); - - - ?> - - - -
+
+ +

title) ?>

+ + $dataProvider, + 'columns' => [ + ['attribute' => 'FULL_ARTICLE'], + ['attribute' => 'ARTICLE'], + ['attribute' => 'BRAND'], + ['attribute' => 'DESCR'], + ['attribute' => 'BOX'], + ['attribute' => 'ADD_BOX'], + ['attribute' => 'GROUP'], + ['attribute' => 'name'], + ['attribute' => 'PRICE'], + ] + ] ); ?> + +
\ No newline at end of file diff --git a/common/models/DetailsCurrency.php b/common/models/DetailsCurrency.php new file mode 100644 index 0000000..4a7960a --- /dev/null +++ b/common/models/DetailsCurrency.php @@ -0,0 +1,72 @@ + 100], + [['FULL_ARTICLE'], 'string', 'max' => 150], + [['DESCR', 'GROUP'], 'string', 'max' => 200], + [['name'], 'string', 'max' => 50] + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'ID' => Yii::t('app', 'ID'), + 'IMPORT_ID' => Yii::t('app', 'Import ID'), + 'BRAND' => Yii::t('app', 'Бренд'), + 'ARTICLE' => Yii::t('app', 'Имя'), + 'FULL_ARTICLE' => Yii::t('app', 'Артикул'), + 'PRICE' => Yii::t('app', 'Цена'), + 'DESCR' => Yii::t('app', 'Описание'), + 'BOX' => Yii::t('app', 'Кол-во'), + 'ADD_BOX' => Yii::t('app', 'В пути'), + 'GROUP' => Yii::t('app', 'Группа RG'), + 'timestamp' => Yii::t('app', 'Дата обновления'), + 'name' => Yii::t('app', 'Валюта'), + 'rate' => Yii::t('app', 'Курс'), + ]; + } +} diff --git a/console/migrations/m151016_130143_add_fk_currency_to_Importers.php b/console/migrations/m151016_130143_add_fk_currency_to_Importers.php index fa54aeb..45c6512 100644 --- a/console/migrations/m151016_130143_add_fk_currency_to_Importers.php +++ b/console/migrations/m151016_130143_add_fk_currency_to_Importers.php @@ -7,17 +7,6 @@ class m151016_130143_add_fk_currency_to_Importers extends Migration { public function safeUp() { -// // сначала отберем записи которых нет уже в поставщиках -// $id_arr = (new \yii\db\Query()) -// ->select(['{{%importers_files}}.id']) -// ->from('{{%importers_files}}') -// ->leftJoin('{{%importers}}', 'importer_id = {{%importers}}.id') -// ->where(['name' => null]) -// ->all(); -// $id_arr = array_column($id_arr,'id'); -// // удалим их -// $this->delete('{{%importers_files}}',['id' => $id_arr]); - $this->addForeignKey('currency_fk', '{{%importers}}', 'currency_id', '{{%currency}}', 'id'); } diff --git a/console/migrations/m151016_144435_addViewDetailsCurrency.php b/console/migrations/m151016_144435_addViewDetailsCurrency.php new file mode 100644 index 0000000..5ae3886 --- /dev/null +++ b/console/migrations/m151016_144435_addViewDetailsCurrency.php @@ -0,0 +1,30 @@ +execute($view); + + } + + public function down() + { + // вернем все как было + $drop_view = 'drop view if exists w_details_currency'; + + $this->execute($drop_view); + + } +} -- libgit2 0.21.4