From 0a9600cb00480e8e15334d5b3decdae8a7275cfa Mon Sep 17 00:00:00 2001 From: SoHardKI Date: Thu, 27 Jun 2019 15:41:58 +0300 Subject: [PATCH 1/6] transfer_to_new_table --- .../card/controllers/UserCardController.php | 7 ++++-- backend/modules/card/models/UserCard.php | 24 +++++++++++-------- backend/modules/company/models/Company.php | 2 +- .../modules/company/views/company/view.php | 4 ++-- .../project/controllers/ProjectController.php | 5 +++- backend/modules/project/models/Project.php | 22 ++++++++++------- .../AdditionalFieldsController.php | 1 + backend/views/layouts/left.php | 2 +- common/models/Company.php | 2 +- common/models/Project.php | 2 +- common/models/UserCard.php | 2 +- 11 files changed, 45 insertions(+), 28 deletions(-) diff --git a/backend/modules/card/controllers/UserCardController.php b/backend/modules/card/controllers/UserCardController.php index 2bad674..682223a 100755 --- a/backend/modules/card/controllers/UserCardController.php +++ b/backend/modules/card/controllers/UserCardController.php @@ -6,6 +6,7 @@ use common\classes\Debug; use common\models\AdditionalFields; use common\models\CardSkill; use common\models\FieldsValue; +use common\models\FieldsValueNew; use common\models\Status; use Yii; use backend\modules\card\models\UserCard; @@ -62,7 +63,9 @@ class UserCardController extends Controller public function actionView($id) { $dataProvider = new ActiveDataProvider([ - 'query' => FieldsValue::find()->where(['card_id' => $id])->orderBy('order'), + 'query' => FieldsValueNew::find() + ->where(['item_id' => $id, 'item_type' => FieldsValueNew::TYPE_PROFILE]) + ->orderBy('order'), 'pagination' => [ 'pageSize' => 200, ], @@ -105,7 +108,7 @@ class UserCardController extends Controller public function actionUpdate($id) { $model = $this->findModel($id); - +// Debug::dd($model); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } diff --git a/backend/modules/card/models/UserCard.php b/backend/modules/card/models/UserCard.php index f1ead04..ae2e498 100755 --- a/backend/modules/card/models/UserCard.php +++ b/backend/modules/card/models/UserCard.php @@ -5,6 +5,7 @@ namespace backend\modules\card\models; use backend\modules\settings\models\Skill; use common\models\CardSkill; use common\models\FieldsValue; +use common\models\FieldsValueNew; use yii\helpers\ArrayHelper; class UserCard extends \common\models\UserCard @@ -16,17 +17,20 @@ class UserCard extends \common\models\UserCard { parent::init(); - $fieldValue = FieldsValue::find()->where( + $fieldValue = FieldsValueNew::find()->where( [ - 'card_id' => \Yii::$app->request->get('id'), - 'project_id' => null, - 'company_id' => null, + 'item_id' => \Yii::$app->request->get('id'), + 'item_type' => FieldsValueNew::TYPE_PROFILE, ]) ->all(); $array = []; if(!empty($fieldValue)){ foreach ($fieldValue as $item){ - array_push($array, ['field_id' => $item->field_id, 'value' => $item->value, 'order' => $item->order]); + array_push($array, + ['field_id' => $item->field_id, + 'value' => $item->value, + 'order' => $item->order, + 'field_name' => $item->field->name]); } $this->fields = $array; } @@ -36,6 +40,7 @@ class UserCard extends \common\models\UserCard 'field_id' => null, 'value' => null, 'order' => null, + 'field_name' => null, ], ]; } @@ -54,17 +59,16 @@ class UserCard extends \common\models\UserCard { $post = \Yii::$app->request->post('UserCard'); - - if($post['fields']){ - FieldsValue::deleteAll(['card_id' => $this->id]); + FieldsValueNew::deleteAll(['item_id' => $this->id, 'item_type' => FieldsValueNew::TYPE_PROFILE]); foreach ( $post['fields'] as $item) { - $fildsValue = new FieldsValue(); + $fildsValue = new FieldsValueNew(); $fildsValue->field_id = $item['field_id']; $fildsValue->value = $item['value']; $fildsValue->order = $item['order']; - $fildsValue->card_id = $this->id; + $fildsValue->item_id = $this->id; + $fildsValue->item_type = FieldsValueNew::TYPE_PROFILE; $fildsValue->save(); } diff --git a/backend/modules/company/models/Company.php b/backend/modules/company/models/Company.php index fe44a2a..19f6d7f 100755 --- a/backend/modules/company/models/Company.php +++ b/backend/modules/company/models/Company.php @@ -47,7 +47,7 @@ class Company extends \common\models\Company { $post = \Yii::$app->request->post('Company'); - FieldsValue::deleteAll(['company_id' => $this->id]); + FieldsValueNew::deleteAll(['item_id' => $this->id, 'item_type' => FieldsValueNew::TYPE_COMPANY]); foreach ( $post['fields'] as $item) { $fildsValue = new FieldsValueNew(); diff --git a/backend/modules/company/views/company/view.php b/backend/modules/company/views/company/view.php index 4ddd155..df256a4 100755 --- a/backend/modules/company/views/company/view.php +++ b/backend/modules/company/views/company/view.php @@ -15,8 +15,8 @@ $this->params['breadcrumbs'][] = $this->title;

'btn btn-primary']) ?> - $model->id], ['class' => 'btn btn-primary']) ?> - $model->id], [ + $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ 'class' => 'btn btn-danger', 'data' => [ 'confirm' => 'Are you sure you want to delete this item?', diff --git a/backend/modules/project/controllers/ProjectController.php b/backend/modules/project/controllers/ProjectController.php index ca147bb..1db532d 100755 --- a/backend/modules/project/controllers/ProjectController.php +++ b/backend/modules/project/controllers/ProjectController.php @@ -3,6 +3,7 @@ namespace backend\modules\project\controllers; use common\models\FieldsValue; +use common\models\FieldsValueNew; use common\models\Hh; use common\models\HhJob; use common\models\ProjectUser; @@ -72,7 +73,9 @@ class ProjectController extends Controller $dataProvider = new ActiveDataProvider([ - 'query' => FieldsValue::find()->where(['project_id' => $id])->orderBy('order'), + 'query' => FieldsValueNew::find() + ->where(['item_id' => $id, 'item_type' => FieldsValueNew::TYPE_PROJECT]) + ->orderBy('order'), 'pagination' => [ 'pageSize' => 200, ], diff --git a/backend/modules/project/models/Project.php b/backend/modules/project/models/Project.php index cc0c31a..57fc08a 100755 --- a/backend/modules/project/models/Project.php +++ b/backend/modules/project/models/Project.php @@ -4,6 +4,7 @@ namespace backend\modules\project\models; use common\classes\Debug; use common\models\FieldsValue; +use common\models\FieldsValueNew; use common\models\ProjectUser; use yii\helpers\ArrayHelper; @@ -16,18 +17,21 @@ class Project extends \common\models\Project { parent::init(); - $fieldValue = FieldsValue::find() + $fieldValue = FieldsValueNew::find() ->where( [ - 'project_id' => \Yii::$app->request->get('id'), - 'card_id' => null, - 'company_id' => null, + 'item_id' => \Yii::$app->request->get('id'), + 'item_type' => FieldsValueNew::TYPE_PROJECT, ]) ->all(); $array = []; if (!empty($fieldValue)) { foreach ($fieldValue as $item) { - array_push($array, ['field_id' => $item->field_id, 'value' => $item->value, 'order' => $item->order]); + array_push($array, [ + 'field_id' => $item->field_id, + 'value' => $item->value, + 'order' => $item->order, + 'field_name' => $item->field->name]); } $this->fields = $array; } else { @@ -36,6 +40,7 @@ class Project extends \common\models\Project 'field_id' => null, 'value' => null, 'order' => null, + 'field_name' => null, ], ]; } @@ -53,14 +58,15 @@ class Project extends \common\models\Project { $post = \Yii::$app->request->post('Project'); - FieldsValue::deleteAll(['project_id' => $this->id]); + FieldsValueNew::deleteAll(['item_id' => $this->id, 'item_type' => FieldsValueNew::TYPE_PROJECT]); foreach ($post['fields'] as $item) { - $fildsValue = new FieldsValue(); + $fildsValue = new FieldsValueNew(); $fildsValue->field_id = $item['field_id']; $fildsValue->value = $item['value']; $fildsValue->order = $item['order']; - $fildsValue->project_id = $this->id; + $fildsValue->item_id = $this->id; + $fildsValue->item_type = FieldsValueNew::TYPE_PROJECT; $fildsValue->save(); } diff --git a/backend/modules/settings/controllers/AdditionalFieldsController.php b/backend/modules/settings/controllers/AdditionalFieldsController.php index fa157af..aac3dce 100755 --- a/backend/modules/settings/controllers/AdditionalFieldsController.php +++ b/backend/modules/settings/controllers/AdditionalFieldsController.php @@ -2,6 +2,7 @@ namespace backend\modules\settings\controllers; +use common\classes\Debug; use common\models\UseField; use Yii; use backend\modules\settings\models\AdditionalFields; diff --git a/backend/views/layouts/left.php b/backend/views/layouts/left.php index a1ca583..8a001ed 100755 --- a/backend/views/layouts/left.php +++ b/backend/views/layouts/left.php @@ -25,7 +25,7 @@ 'label' => 'Профили', 'icon' => 'users', 'url' => '#', 'items' => $menuItems, ], - ['label' => 'Пректы', 'icon' => 'files-o', 'url' => ['/project/project']], + ['label' => 'Проекты', 'icon' => 'files-o', 'url' => ['/project/project']], ['label' => 'Компании', 'icon' => 'files-o', 'url' => ['/company/company']], [ 'label' => 'Hh.ru', 'icon' => 'user-circle', 'url' => '#', diff --git a/common/models/Company.php b/common/models/Company.php index 0deafe7..7c74d00 100755 --- a/common/models/Company.php +++ b/common/models/Company.php @@ -86,7 +86,7 @@ class Company extends \yii\db\ActiveRecord */ public function getFieldsValues() { - return $this->hasMany(FieldsValue::className(), ['company_id' => 'id']); + return $this->hasMany(FieldsValueNew::class, ['item_id' => 'id'])->where(['item_type' => FieldsValueNew::TYPE_COMPANY])->with('field'); } /** diff --git a/common/models/Project.php b/common/models/Project.php index b82da67..c83910d 100755 --- a/common/models/Project.php +++ b/common/models/Project.php @@ -84,7 +84,7 @@ class Project extends \yii\db\ActiveRecord */ public function getFieldsValues() { - return $this->hasMany(FieldsValue::class, ['project_id' => 'id']); + return $this->hasMany(FieldsValueNew::class, ['item_id' => 'id'])->where(['item_type' => FieldsValueNew::TYPE_PROJECT])->with('field'); } /** diff --git a/common/models/UserCard.php b/common/models/UserCard.php index cfe477a..de772fe 100755 --- a/common/models/UserCard.php +++ b/common/models/UserCard.php @@ -98,7 +98,7 @@ class UserCard extends \yii\db\ActiveRecord */ public function getFieldsValues() { - return $this->hasMany(FieldsValue::class, ['card_id' => 'id']); + return $this->hasMany(FieldsValueNew::class, ['item_id' => 'id'])->where(['item_type' => FieldsValueNew::TYPE_PROFILE])->with('field'); } /** From 91cc9c0e2d50b41fd0ee59b584c86d18c8e281d2 Mon Sep 17 00:00:00 2001 From: SoHardKI Date: Thu, 27 Jun 2019 17:36:56 +0300 Subject: [PATCH 2/6] add_script_for_transfer --- console/controllers/MovingController.php | 51 ++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 console/controllers/MovingController.php diff --git a/console/controllers/MovingController.php b/console/controllers/MovingController.php new file mode 100644 index 0000000..5d392c4 --- /dev/null +++ b/console/controllers/MovingController.php @@ -0,0 +1,51 @@ +all(); + +// var_dump($field_value[1]->id); + for($i=0;$iorder = $field_value[$i]->order; +// echo $send_value->order; +// echo '
'; + $send_value->field_id = $field_value[$i]->field_id; + $send_value->value = $field_value[$i]->value; + if($field_value[$i]->card_id != null) + { + $send_value->item_type = 0; + $send_value->item_id = $field_value[$i]->card_id; + } + if($field_value[$i]->balance_id != null) + { + $send_value->item_type = 3 ; + $send_value->item_id = $field_value[$i]->balance_id; + } + if($field_value[$i]->project_id != null) + { + $send_value->item_type = 1; + $send_value->item_id = $field_value[$i]->project_id; + } + if($field_value[$i]->company_id!= null) + { + $send_value->item_type = 2; + $send_value->item_id = $field_value[$i]->company_id; + } + $send_value->save(); + + } + } +} \ No newline at end of file From b24bbf51aa66a2534d06b2ab78cb69125d98f11e Mon Sep 17 00:00:00 2001 From: SoHardKI Date: Fri, 28 Jun 2019 11:36:50 +0300 Subject: [PATCH 3/6] change_cycle --- .../card/controllers/UserCardController.php | 1 - console/controllers/MovingController.php | 56 +++++++++---------- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/backend/modules/card/controllers/UserCardController.php b/backend/modules/card/controllers/UserCardController.php index 682223a..139417b 100755 --- a/backend/modules/card/controllers/UserCardController.php +++ b/backend/modules/card/controllers/UserCardController.php @@ -44,7 +44,6 @@ class UserCardController extends Controller public function actionIndex() { $status = new Status(); - //Debug::dd($status->getUseStatuses()); $searchModel = new UserCardSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); diff --git a/console/controllers/MovingController.php b/console/controllers/MovingController.php index 5d392c4..769d441 100644 --- a/console/controllers/MovingController.php +++ b/console/controllers/MovingController.php @@ -15,37 +15,35 @@ class MovingController extends Controller { $field_value = \common\models\FieldsValue::find()->all(); -// var_dump($field_value[1]->id); - for($i=0;$iorder = $field_value[$i]->order; -// echo $send_value->order; -// echo '
'; - $send_value->field_id = $field_value[$i]->field_id; - $send_value->value = $field_value[$i]->value; - if($field_value[$i]->card_id != null) - { - $send_value->item_type = 0; - $send_value->item_id = $field_value[$i]->card_id; - } - if($field_value[$i]->balance_id != null) - { - $send_value->item_type = 3 ; - $send_value->item_id = $field_value[$i]->balance_id; - } - if($field_value[$i]->project_id != null) - { - $send_value->item_type = 1; - $send_value->item_id = $field_value[$i]->project_id; - } - if($field_value[$i]->company_id!= null) - { - $send_value->item_type = 2; - $send_value->item_id = $field_value[$i]->company_id; - } - $send_value->save(); + $new_value = new FieldsValueNew(); + $new_value->order = $item->order; + $new_value->field_id = $item->field_id; + $new_value->value = $item->value; + if($item->card_id != null) + { + $new_value->item_type = 0; + $new_value->item_id = $item->card_id; + } + if($item->balance_id != null) + { + $new_value->item_type = 3 ; + $new_value->item_id = $item->balance_id; + } + if($item->project_id != null) + { + $new_value->item_type = 1; + $new_value->item_id = $item->project_id; + } + if($item->company_id!= null) + { + $new_value->item_type = 2; + $new_value->item_id = $item->company_id; + } + + $new_value->save(); } } } \ No newline at end of file From f2c34d595fb7d38a227ae5e11c04657cd901543a Mon Sep 17 00:00:00 2001 From: SoHardKI Date: Fri, 28 Jun 2019 12:29:54 +0300 Subject: [PATCH 4/6] add_summ_info --- .../balance/controllers/BalanceController.php | 6 ++-- .../modules/balance/models/BalanceSearch.php | 28 ++++++++++++++++++- .../modules/balance/views/balance/index.php | 11 +++++++- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/backend/modules/balance/controllers/BalanceController.php b/backend/modules/balance/controllers/BalanceController.php index b223b08..ed760b5 100644 --- a/backend/modules/balance/controllers/BalanceController.php +++ b/backend/modules/balance/controllers/BalanceController.php @@ -30,11 +30,9 @@ class BalanceController extends Controller $searchModel->dt_to = date('Y-m-d', strtotime('last day of previous month')); } $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + $summ_info = $searchModel->getSummInfo(); - return $this->render('index',[ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); + return $this->render('index',compact('dataProvider', 'searchModel', 'summ_info')); } public function actionView($id) diff --git a/backend/modules/balance/models/BalanceSearch.php b/backend/modules/balance/models/BalanceSearch.php index 1f232eb..6db036c 100644 --- a/backend/modules/balance/models/BalanceSearch.php +++ b/backend/modules/balance/models/BalanceSearch.php @@ -2,13 +2,13 @@ namespace backend\modules\balance\models; +use backend\modules\balance\models\Balance; use common\classes\Debug; use common\models\FieldsValueNew; use DateTime; use Yii; use yii\base\Model; use yii\data\ActiveDataProvider; -use backend\modules\balance\models\Balance; /** * BalanceSearch represents the model behind the search form of `backend\modules\balance\models\Balance`. @@ -21,6 +21,9 @@ class BalanceSearch extends Balance public $dt_to; public $field_name; public $field_value; + public $active_summ; + public $passive_summ; + public $difference; /** * {@inheritdoc} */ @@ -87,4 +90,27 @@ class BalanceSearch extends Balance return $dataProvider; } + + public function getSummInfo() + { + $query = Balance::find() + ->andFilterWhere(['>=','dt_add', strtotime($this->dt_from) ?: null]) + ->andFilterWhere(['<=','dt_add', strtotime($this->dt_to) ?: null]) + ->all(); +// Debug::dd($query); + $active_summ = 0; + $passive_summ = 0; + $difference = 0; + foreach ($query as $item) + { + if($item->type == 1) + { + $active_summ += $item->summ; + } else { + $passive_summ += $item->summ; + } + } + $difference = $active_summ - $passive_summ; + return compact('active_summ', 'passive_summ', 'difference'); + } } diff --git a/backend/modules/balance/views/balance/index.php b/backend/modules/balance/views/balance/index.php index b5ab6a2..7a2a37c 100644 --- a/backend/modules/balance/views/balance/index.php +++ b/backend/modules/balance/views/balance/index.php @@ -22,7 +22,16 @@ $this->params['breadcrumps'][] = $this->title; true], ['class' => 'btn btn-primary']) ?> true], ['class' => 'btn btn-primary']) ?>

-fields); ?> +

+ +

+

+ +

+

+ +

+ $dataProvider, 'filterModel' => $searchModel, From 2689ce0bed7b453640e848e4eb4edac184d0b3bf Mon Sep 17 00:00:00 2001 From: SoHardKI Date: Fri, 28 Jun 2019 12:33:10 +0300 Subject: [PATCH 5/6] add_summ_info --- backend/modules/balance/models/BalanceSearch.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/modules/balance/models/BalanceSearch.php b/backend/modules/balance/models/BalanceSearch.php index 6db036c..6a93ca1 100644 --- a/backend/modules/balance/models/BalanceSearch.php +++ b/backend/modules/balance/models/BalanceSearch.php @@ -97,7 +97,6 @@ class BalanceSearch extends Balance ->andFilterWhere(['>=','dt_add', strtotime($this->dt_from) ?: null]) ->andFilterWhere(['<=','dt_add', strtotime($this->dt_to) ?: null]) ->all(); -// Debug::dd($query); $active_summ = 0; $passive_summ = 0; $difference = 0; @@ -111,6 +110,7 @@ class BalanceSearch extends Balance } } $difference = $active_summ - $passive_summ; + return compact('active_summ', 'passive_summ', 'difference'); } } From 9b67008df7a00d82b3995bd380d51e33cbc89b89 Mon Sep 17 00:00:00 2001 From: SoHardKI Date: Fri, 28 Jun 2019 12:59:04 +0300 Subject: [PATCH 6/6] small_fixes --- backend/modules/balance/views/balance/index.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/modules/balance/views/balance/index.php b/backend/modules/balance/views/balance/index.php index 7a2a37c..7f8f7a6 100644 --- a/backend/modules/balance/views/balance/index.php +++ b/backend/modules/balance/views/balance/index.php @@ -23,10 +23,10 @@ $this->params['breadcrumps'][] = $this->title; true], ['class' => 'btn btn-primary']) ?>

- +

- +

@@ -35,6 +35,7 @@ $this->params['breadcrumps'][] = $this->title; $dataProvider, 'filterModel' => $searchModel, +// 'layout'=> "{items}\n{summary}", // перемещение информации о записях под таблицу 'columns' => [ ['class' => 'yii\grid\SerialColumn'], [