diff --git a/console/migrations/m161228_100649_add_report_columns.php b/console/migrations/m161228_100649_add_report_columns.php new file mode 100644 index 0000000..fd6448e --- /dev/null +++ b/console/migrations/m161228_100649_add_report_columns.php @@ -0,0 +1,18 @@ +addColumn('report', 'user', $this->string()); + $this->addColumn('report', 'sum', $this->decimal()); + } + + public function down() + { + $this->dropColumn('report', 'user'); + $this->dropColumn('report', 'sum'); + } +} diff --git a/console/migrations/m161228_105659_alter_intellectual_columns.php b/console/migrations/m161228_105659_alter_intellectual_columns.php new file mode 100644 index 0000000..9e1e5de --- /dev/null +++ b/console/migrations/m161228_105659_alter_intellectual_columns.php @@ -0,0 +1,17 @@ +alterColumn('intellectual_property', 'percent', 'numeric(10,0) USING (percent::float)'); + $this->alterColumn('intellectual_property', 'calculated', 'numeric(10,0) USING (percent::float)'); + } + + public function down() + { + + } +} diff --git a/frontend/controllers/CabinetController.php b/frontend/controllers/CabinetController.php index 994ef88..dcfbbaf 100755 --- a/frontend/controllers/CabinetController.php +++ b/frontend/controllers/CabinetController.php @@ -4,6 +4,7 @@ use common\models\User; use frontend\models\CreativeRole; use frontend\models\IntellectualProperty; + use frontend\models\Report; use frontend\models\UserData; use frontend\models\UserPassport; use yii\filters\VerbFilter; @@ -71,7 +72,7 @@ ); } - public function actionSales($id = NULL) + public function actionSales($id = null) { $newRecord = false; if ($id) { @@ -134,7 +135,15 @@ public function actionArrivals() { - return $this->render('arrivals'); + $reports = Report::find() + ->with('intellectualProperty') + ->all(); + return $this->render( + 'arrivals', + [ + 'reports' => $reports, + ] + ); } public function actionNotifications() @@ -144,7 +153,37 @@ public function actionUsers() { - return $this->render('users'); + $reports = Report::find() + ->with('intellectualProperty') + ->all(); + return $this->render( + 'users', + [ + 'reports' => $reports, + ] + ); + } + + public function actionUsersAdd() + { + $request = \Yii::$app->request; + $response = \Yii::$app->response; + $response->format = $response::FORMAT_JSON; + /** + * @var User $user + */ + $report = new Report(); + if ($report->load($request->post()) && $report->save()) { + return [ + 'success' => true, + 'message' => 'Данные успешно сохранены', + ]; + } else { + return [ + 'error' => true, + 'message' => 'Ошибка сохранения данных', + ]; + } } public function actionPersonal() @@ -221,14 +260,14 @@ ]; } } - + public function actionDeleteIntProperty() { $request = \Yii::$app->request; $response = \Yii::$app->response; $response->format = $response::FORMAT_JSON; - - if (!empty($request->post('id'))) { + + if (!empty( $request->post('id') )) { $role = IntellectualProperty::findOne($request->post('id')); if ($role->delete()) { return [ @@ -276,7 +315,7 @@ $response = \Yii::$app->response; $response->format = $response::FORMAT_JSON; - if (!empty($request->post('id'))) { + if (!empty( $request->post('id') )) { $role = CreativeRole::findOne($request->post('id')); if ($role->delete()) { return [ @@ -300,7 +339,7 @@ public function findProperty($id) { $model = IntellectualProperty::findOne($id); - if (empty($model)) { + if (empty( $model )) { throw new NotFoundHttpException(); } return $model; diff --git a/frontend/models/Report.php b/frontend/models/Report.php index 49567d6..533901b 100755 --- a/frontend/models/Report.php +++ b/frontend/models/Report.php @@ -1,70 +1,117 @@ 255, + ], + [ + [ 'intellectual_property_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => IntellectualProperty::className(), + 'targetAttribute' => [ 'intellectual_property_id' => 'id' ], + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'intellectual_property_id' => 'Твір', + 'title' => 'Title', + 'artist' => 'Виконавець', + 'music_author' => 'Music Author', + 'text_author' => 'Text Author', + 'time' => 'Time', + 'total_time' => 'Total Time', + 'royalty' => 'Royalty', + 'count' => 'Кількість сповіщень', + 'sum' => 'Перерахована сума', + 'user' => 'Користувач', + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getIntellectualProperty() + { + return $this->hasOne(IntellectualProperty::className(), [ 'id' => 'intellectual_property_id' ]); + } + + public function afterSave($insert, $changedAttributes) + { + if (!empty( $property = IntellectualProperty::findOne($this->intellectual_property_id) )) { + var_dump($property); die(); + $sum = 0; + foreach ($property->reports as $report) { + $sum += $report->sum; + } + $property->calculated = $property->percent * $sum / 100; + $property->save(true, [ 'calculated' ]); + } + parent::afterSave($insert, $changedAttributes); + } } - - /** - * @inheritdoc - */ - public function rules() - { - return [ - [['intellectual_property_id', 'time', 'total_time', 'count'], 'integer'], - [['royalty'], 'number'], - [['title', 'artist', 'music_author', 'text_author'], 'string', 'max' => 255], - [['intellectual_property_id'], 'exist', 'skipOnError' => true, 'targetClass' => IntellectualProperty::className(), 'targetAttribute' => ['intellectual_property_id' => 'id']], - ]; - } - - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'id' => 'ID', - 'intellectual_property_id' => 'Intellectual Property ID', - 'title' => 'Title', - 'artist' => 'Artist', - 'music_author' => 'Music Author', - 'text_author' => 'Text Author', - 'time' => 'Time', - 'total_time' => 'Total Time', - 'royalty' => 'Royalty', - 'count' => 'Count', - ]; - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getIntellectualProperty() - { - return $this->hasOne(IntellectualProperty::className(), ['id' => 'intellectual_property_id']); - } -} diff --git a/frontend/views/cabinet/arrivals.php b/frontend/views/cabinet/arrivals.php index dfff1ef..bda8813 100755 --- a/frontend/views/cabinet/arrivals.php +++ b/frontend/views/cabinet/arrivals.php @@ -1,14 +1,16 @@
Мої надходження
- @@ -18,273 +20,22 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + $report) { + ?> + + user); + echo Html::tag('td', $report->artist); + echo Html::tag('td', $report->intellectualProperty->title); + echo Html::tag('td', $report->count); + echo Html::tag('td', $report->sum); + ?> + +

п/п
Кількість сповіщень Перерахована сума
1Радіо "BOOM"Джорж ВашингтонНью-Йорк10100
2Радіо "MUSOFF"Джорж ВашингтонКалифорнія880
3Радіо "MUSOFF"Джорж ВашингтонІллінойс660
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/frontend/views/cabinet/users.php b/frontend/views/cabinet/users.php index 38c5727..d414155 100755 --- a/frontend/views/cabinet/users.php +++ b/frontend/views/cabinet/users.php @@ -1,11 +1,14 @@
@@ -23,51 +26,45 @@ ] ) ?>
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

п/п
КористувачВиконавецьТвірКількість сповіщеньПерерахована сума
1Радіо "BOOM"Джорж ВашингтонНью-Йорк10100
2Радіо "MUSOFF"Джорж ВашингтонКалифорнія880
3Радіо "MUSOFF"Джорж ВашингтонІллінойс660
-
+ 'users-table', + 'options' => [ + 'class' => 'style table-forms-wrapp', + ], + ] + ); + ?> + + + + + + + + + + $report) { + ?> + + user); + echo Html::tag('td', $report->artist); + echo Html::tag('td', $report->intellectualProperty->title); + echo Html::tag('td', $report->count); + echo Html::tag('td', $report->sum); + ?> + + +

п/п
КористувачВиконавецьТвірКількість сповіщеньПерерахована сума
+ @@ -83,7 +80,7 @@ ['/cabinet/users-add'], + 'action' => [ '/cabinet/users-add' ], 'id' => 'users-add-form', ] ); @@ -91,17 +88,29 @@ ?> +