Commit f9e2ff5ecca46c118b45a15f70d3b304f909ff0e

Authored by Yarik
2 parents 885e52f4 7af4d34d

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	frontend/controllers/CabinetController.php
frontend/controllers/CabinetController.php
... ... @@ -9,6 +9,7 @@
9 9 use frontend\models\UserPassport;
10 10 use yii\filters\AccessControl;
11 11 use yii\filters\VerbFilter;
  12 + use yii\helpers\VarDumper;
12 13 use yii\web\Controller;
13 14 use yii\web\NotFoundHttpException;
14 15  
... ... @@ -81,7 +82,7 @@
81 82 );
82 83 }
83 84  
84   - public function actionSales($id = null)
  85 + public function actionSales($id = NULL)
85 86 {
86 87 $newRecord = false;
87 88 if ($id) {
... ... @@ -131,11 +132,12 @@
131 132  
132 133 public function actionList()
133 134 {
134   - $table = IntellectualProperty::find()// ->where(
135   - // [
136   - // 'user_id' => \Yii::$app->user->identity->id,
137   - // ]
138   - // )
  135 + $table = IntellectualProperty::find()
  136 +// ->where(
  137 +// [
  138 +// 'user_id' => \Yii::$app->user->identity->id,
  139 +// ]
  140 +// )
139 141 ->all();
140 142 return $this->render(
141 143 'list',
... ... @@ -147,9 +149,20 @@
147 149  
148 150 public function actionArrivals()
149 151 {
150   - $reports = Report::find()
151   - ->with('intellectualProperty')
152   - ->all();
  152 + /**
  153 + * @var User $user
  154 + */
  155 + $user = \Yii::$app->user->identity;
  156 + if ($user->isAdmin()) {
  157 + $reports = Report::find()
  158 + ->with('intellectualProperty')
  159 + ->all();
  160 + } else {
  161 + $reports = Report::find()
  162 + ->joinWith('intellectualProperty.creativeRoles')
  163 + ->where([ 'creative_role.user_id' => $user->id ])
  164 + ->all();
  165 + }
153 166 return $this->render(
154 167 'arrivals',
155 168 [
... ... @@ -160,8 +173,20 @@
160 173  
161 174 public function actionNotifications()
162 175 {
163   - $table = Report::find()
164   - ->all();
  176 + /**
  177 + * @var User $user
  178 + */
  179 + $user = \Yii::$app->user->identity;
  180 + if ($user->isAdmin()) {
  181 + $table = Report::find()
  182 + ->with('intellectualProperty')
  183 + ->all();
  184 + } else {
  185 + $table = Report::find()
  186 + ->joinWith('intellectualProperty.creativeRoles')
  187 + ->where([ 'creative_role.user_id' => $user->id ])
  188 + ->all();
  189 + }
165 190 return $this->render(
166 191 'notifications',
167 192 [
... ... @@ -172,9 +197,21 @@
172 197  
173 198 public function actionUsers()
174 199 {
175   - $reports = Report::find()
176   - ->with('intellectualProperty')
177   - ->all();
  200 + /**
  201 + * @var User $user
  202 + */
  203 + $user = \Yii::$app->user->identity;
  204 + if ($user->isAdmin()) {
  205 + $reports = Report::find()
  206 + ->with('intellectualProperty')
  207 + ->all();
  208 + } else {
  209 + $reports = Report::find()
  210 + ->joinWith('intellectualProperty.creativeRoles')
  211 + ->where([ 'creative_role.user_id' => $user->id ])
  212 + ->all();
  213 + }
  214 +
178 215 return $this->render(
179 216 'users',
180 217 [
... ... @@ -286,7 +323,7 @@
286 323 $response = \Yii::$app->response;
287 324 $response->format = $response::FORMAT_JSON;
288 325  
289   - if (!empty( $request->post('id') )) {
  326 + if (!empty($request->post('id'))) {
290 327 $role = IntellectualProperty::findOne($request->post('id'));
291 328 if ($role->delete()) {
292 329 return [
... ... @@ -368,7 +405,7 @@
368 405 $response = \Yii::$app->response;
369 406 $response->format = $response::FORMAT_JSON;
370 407  
371   - if (!empty( $request->post('id') )) {
  408 + if (!empty($request->post('id'))) {
372 409 $role = CreativeRole::findOne($request->post('id'));
373 410 if ($role->delete()) {
374 411 return [
... ...
frontend/views/cabinet/arrivals.php
1 1 <?php
  2 + use common\models\User;
2 3 use frontend\models\Report;
3 4 use yii\helpers\Html;
4 5 use yii\web\View;
... ... @@ -6,7 +7,9 @@
6 7 /**
7 8 * @var View $this
8 9 * @var Report[] $reports
  10 + * @var User $user
9 11 */
  12 + $user = \Yii::$app->user->identity;
10 13 ?>
11 14 <div class="style cab_content_list">
12 15 <div class="title_forms">Мої надходження</div>
... ... @@ -15,22 +18,25 @@
15 18 <tr>
16 19 <td>№<br/>п/п</td>
17 20 <td>Користувач</td>
18   - <td>Виконавець</td>
19 21 <td>Твір</td>
20 22 <td>Кількість сповіщень</td>
21 23 <td>Перерахована сума</td>
22 24 </tr>
23 25 <?php
24 26 foreach ($reports as $index => $report) {
  27 + if ($user->isAdmin()) {
  28 + $sum = $report->sum;
  29 + } else {
  30 + $sum = $report->sum * $report->intellectualProperty->creativeRoles[0]->part /100;
  31 + }
25 32 ?>
26 33 <tr>
27 34 <?php
28 35 echo Html::tag('td', ++$index);
29 36 echo Html::tag('td', $report->user);
30   - echo Html::tag('td', $report->artist);
31 37 echo Html::tag('td', $report->intellectualProperty->title);
32 38 echo Html::tag('td', $report->count);
33   - echo Html::tag('td', $report->sum);
  39 + echo Html::tag('td', $sum);
34 40 ?>
35 41 </tr>
36 42 <?php
... ...
frontend/views/cabinet/notifications.php
1 1 <?php
  2 + use common\models\User;
2 3 use frontend\models\Report;
3 4 use yii\web\View;
4 5  
5 6 /**
6 7 * @var View $this
7 8 * @var Report[] $table
  9 + * @var User $user
8 10 */
  11 + $user = \Yii::$app->user->identity;
9 12 ?>
10 13 <div class="style cab_content_list">
11 14 <div class="cab_content_list-dropdown">
... ... @@ -30,11 +33,16 @@
30 33 <tr>
31 34 <td><?=$i?></td>
32 35 <td><span class="name-songs"><?=$row->intellectualProperty->title?></span></td>
33   - <td><?=$row->artist?></td>
34 36 <td>-</td>
35 37 <td>-</td>
36 38 <td>—</td>
37   - <td><?=$row->royalty?></td>
  39 + <td><?php
  40 + if ($user->isAdmin()) {
  41 + echo $row->royalty;
  42 + } else {
  43 + echo $row->royalty * $row->intellectualProperty->creativeRoles[0]->part /100;
  44 + }
  45 + ?></td>
38 46 <td><?=$row->count?></td>
39 47 <td>—</td>
40 48 </tr>
... ...
frontend/views/cabinet/users.php
1 1 <?php
  2 + use common\models\User;
2 3 use frontend\models\IntellectualProperty;
3 4 use frontend\models\Report;
4 5 use yii\helpers\Html;
... ... @@ -9,14 +10,17 @@
9 10 /**
10 11 * @var View $this
11 12 * @var Report[] $reports
  13 + * @var User $user
12 14 */
  15 +
  16 + $user = \Yii::$app->user->identity;
13 17 ?>
14 18 <div class="style cab_content_list">
15 19 <div class="cab_content_list-dropdown">
16 20 <div class="style table-forms tables-1">
17 21 <div class="title_forms">Звіт про загальну суму винагороди (у розрізі користувачів)</div>
18 22 <div class="btn-submit-blue">
19   - <?php echo Html::button(
  23 + <?php if ($user->isAdmin()) echo Html::button(
20 24 'Добавить',
21 25 [
22 26 'type' => 'button',
... ... @@ -40,7 +44,6 @@
40 44 <tr>
41 45 <td>№<br/>п/п</td>
42 46 <td>Користувач</td>
43   - <td>Виконавець</td>
44 47 <td>Твір</td>
45 48 <td>Кількість сповіщень</td>
46 49 <td>Перерахована сума</td>
... ... @@ -51,19 +54,23 @@
51 54 </tr>
52 55 <?php
53 56 foreach ($reports as $index => $report) {
  57 + if ($user->isAdmin()) {
  58 + $sum = $report->sum;
  59 + } else {
  60 + $sum = $report->sum * $report->intellectualProperty->creativeRoles[0]->part / 100;
  61 + }
54 62 ?>
55 63 <tr>
56 64 <?php
57 65 echo Html::tag('td', ++$index);
58 66 echo Html::tag('td', $report->user);
59   - echo Html::tag('td', $report->artist);
60 67 echo Html::tag('td', $report->intellectualProperty->title);
61 68 echo Html::tag('td', $report->count);
62   - echo Html::tag('td', $report->sum);
63   - echo Html::tag('td', $report->sum*0.2);
64   - echo Html::tag('td', $report->sum*0.8);
65   - echo Html::tag('td', $report->sum*0.8*0.195);
66   - echo Html::tag('td', $report->sum*0.8*0.805);
  69 + echo Html::tag('td', $sum);
  70 + echo Html::tag('td', $sum*0.2);
  71 + echo Html::tag('td', $sum*0.8);
  72 + echo Html::tag('td', $sum*0.8*0.195);
  73 + echo Html::tag('td', $sum*0.8*0.805);
67 74 ?>
68 75 </tr>
69 76 <?php
... ... @@ -98,7 +105,7 @@
98 105 <?php
99 106 echo $form->field($report, 'user')
100 107 ->textInput();
101   - echo $form->field($report, 'artist');
  108 +// echo $form->field($report, 'artist');
102 109 echo $form->field($report, 'intellectual_property_id')
103 110 ->dropDownList(
104 111 IntellectualProperty::find()
... ...