Commit 71837d74632c17c5c644919aa79066e456177943

Authored by Yarik
1 parent 423c02d3

Sales fix

frontend/controllers/CabinetController.php
@@ -84,9 +84,23 @@ @@ -84,9 +84,23 @@
84 84
85 public function actionSales($id = null) 85 public function actionSales($id = null)
86 { 86 {
  87 + /**
  88 + * @var User $user
  89 + */
  90 + $user = \Yii::$app->user->identity;
87 $newRecord = false; 91 $newRecord = false;
88 if ($id) { 92 if ($id) {
89 - $property = $this->findProperty($id); 93 + $propertyQuery = IntellectualProperty::find();
  94 + if (!$user->isAdmin()) {
  95 + $propertyQuery->joinWith('creativeRoles')
  96 + ->where([ 'intellectual_property.user_id' => $user->id ])
  97 + ->orWhere([ 'creative_role.user_id' => $user->id ]);
  98 + }
  99 + $propertyQuery->andWhere([ 'intellectual_property.id' => $id ]);
  100 + $property = $propertyQuery->one();
  101 + if (empty( $property )) {
  102 + throw new NotFoundHttpException();
  103 + }
90 } else { 104 } else {
91 $property = new IntellectualProperty( 105 $property = new IntellectualProperty(
92 [ 106 [
frontend/views/cabinet/_update_form.php
@@ -2,7 +2,9 @@ @@ -2,7 +2,9 @@
2 /** 2 /**
3 * @var CreativeRole $model 3 * @var CreativeRole $model
4 */ 4 */
  5 + use common\models\User;
5 use frontend\models\CreativeRole; 6 use frontend\models\CreativeRole;
  7 + use yii\helpers\ArrayHelper;
6 use yii\helpers\Html; 8 use yii\helpers\Html;
7 use yii\widgets\ActiveForm; 9 use yii\widgets\ActiveForm;
8 ?> 10 ?>
@@ -30,6 +32,24 @@ @@ -30,6 +32,24 @@
30 <?php 32 <?php
31 echo $form->field($model, 'title'); 33 echo $form->field($model, 'title');
32 ?> 34 ?>
  35 +
  36 + <?php
  37 + echo $form->field($model, 'user_id')
  38 + ->dropDownList(
  39 + ArrayHelper::getColumn(
  40 + User::find()
  41 + ->joinWith('userData')
  42 + ->indexBy('id')
  43 + ->all(),
  44 + function ($element) {
  45 + /**
  46 + * @var User $element
  47 + */
  48 + return $element->userData->name . ' ' . $element->userData->surname;
  49 + }
  50 + )
  51 + );
  52 + ?>
33 53
34 <?php 54 <?php
35 echo $form->field($model, 'part'); 55 echo $form->field($model, 'part');
frontend/views/cabinet/index.php
1 <?php 1 <?php
2 2
3 /** 3 /**
4 - * @var UserData $userData  
5 - * @var UserPassport $userPassport  
6 - * @var yii\web\View $this 4 + * @var UserData $userData
  5 + * @var UserPassport $userPassport
  6 + * @var yii\web\View $this
7 * @var IntellectualProperty[] $table 7 * @var IntellectualProperty[] $table
8 */ 8 */
9 9
@@ -51,11 +51,13 @@ @@ -51,11 +51,13 @@
51 ) ?> 51 ) ?>
52 </div> 52 </div>
53 <div class="style table-forms-wrapp"> 53 <div class="style table-forms-wrapp">
54 - <?php  
55 - Pjax::begin([  
56 - 'id' => 'int-prop-greed',  
57 - ]);  
58 - ?> 54 + <?php
  55 + Pjax::begin(
  56 + [
  57 + 'id' => 'int-prop-greed',
  58 + ]
  59 + );
  60 + ?>
59 <table class="table-1" cellpadding="0" cellspacing="0" border="0"> 61 <table class="table-1" cellpadding="0" cellspacing="0" border="0">
60 <tr> 62 <tr>
61 <td>№<br/>п/п</td> 63 <td>№<br/>п/п</td>
@@ -70,128 +72,131 @@ @@ -70,128 +72,131 @@
70 <?php 72 <?php
71 $i = 1; 73 $i = 1;
72 foreach ($table as $row) { 74 foreach ($table as $row) {
73 - ?>  
74 - <tr>  
75 - <td><?= $i; ?></td>  
76 - <td>  
77 - <?php  
78 - if($user->isAdmin() || $row->user_id == $user->id) {  
79 - echo Html::a($row->title, ['sales', 'id' => $row->id]);  
80 - } else {  
81 - echo $row->title;  
82 - }  
83 - ?>  
84 - </td>  
85 - <td><?= $row->registration_date ?></td>  
86 - <td><?= $row->genre ?></td>  
87 - <td>  
88 - <?php  
89 - if(!empty($row->creativeRole)) {  
90 - echo $row->creativeRole->title;  
91 - } elseif($user->isAdmin()) {  
92 - echo '-';  
93 - } else {  
94 - echo 'У Вас немає ролі в даному ОІВ';  
95 - }  
96 - ?>  
97 - </td>  
98 - <td>  
99 - <?php  
100 - if(!empty($row->creativeRole)) {  
101 - echo $row->creativeRole->part.'%';  
102 - } else {  
103 - echo '-';  
104 - }  
105 - ?>  
106 - </td>  
107 - <td>  
108 - <?php  
109 - if(!empty($row->creativeRole)) {  
110 - $sum = 0;  
111 - foreach ($row->reports as $report) {  
112 - $sum += $report->sum;  
113 - }  
114 - echo ($sum * $row->creativeRole->part / 100);  
115 - unset($sum);  
116 - } else {  
117 - echo '-';  
118 - }  
119 - ?>  
120 - </td>  
121 - <td>  
122 - <?php  
123 - $sum = 0;  
124 - foreach ($row->reports as $report) {  
125 - $sum += $report->count;  
126 - }  
127 - echo $sum;  
128 - unset($sum);  
129 - ?>  
130 - </td>  
131 - </tr>  
132 - <?php 75 + ?>
  76 + <tr>
  77 + <td><?= $i; ?></td>
  78 + <td>
  79 + <?php
  80 + echo Html::a($row->title,
  81 + [
  82 + 'sales',
  83 + 'id' => $row->id,
  84 + ]
  85 + );
  86 + ?>
  87 + </td>
  88 + <td><?= $row->registration_date ?></td>
  89 + <td><?= $row->genre ?></td>
  90 + <td>
  91 + <?php
  92 + if (!empty( $row->creativeRole )) {
  93 + echo $row->creativeRole->title;
  94 + } elseif ($user->isAdmin()) {
  95 + echo '-';
  96 + } else {
  97 + echo 'У Вас немає ролі в даному ОІВ';
  98 + }
  99 + ?>
  100 + </td>
  101 + <td>
  102 + <?php
  103 + if (!empty( $row->creativeRole )) {
  104 + echo $row->creativeRole->part . '%';
  105 + } else {
  106 + echo '-';
  107 + }
  108 + ?>
  109 + </td>
  110 + <td>
  111 + <?php
  112 + if (!empty( $row->creativeRole )) {
  113 + $sum = 0;
  114 + foreach ($row->reports as $report) {
  115 + $sum += $report->sum;
  116 + }
  117 + echo( $sum * $row->creativeRole->part / 100 );
  118 + unset( $sum );
  119 + } else {
  120 + echo '-';
  121 + }
  122 + ?>
  123 + </td>
  124 + <td>
  125 + <?php
  126 + $sum = 0;
  127 + foreach ($row->reports as $report) {
  128 + $sum += $report->count;
  129 + }
  130 + echo $sum;
  131 + unset( $sum );
  132 + ?>
  133 + </td>
  134 + </tr>
  135 + <?php
133 $i++; 136 $i++;
134 } 137 }
135 - ?> 138 + ?>
136 </table> 139 </table>
137 - <?php  
138 - Pjax::end();  
139 - ?> 140 + <?php
  141 + Pjax::end();
  142 + ?>
140 </div> 143 </div>
141 </div> 144 </div>
142 </div> 145 </div>
143 <!-- Modal --> 146 <!-- Modal -->
144 <div class="modal fade" id="add-composition-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> 147 <div class="modal fade" id="add-composition-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
145 - <div class="modal-dialog" role="document">  
146 - <div class="modal-content">  
147 - <div class="modal-header">  
148 - <button type="button" class="close" data-dismiss="modal" aria-label="Close">  
149 - <span aria-hidden="true">&times;</span></button>  
150 - <h4 class="modal-title" id="myModalLabel">Додати твір</h4>  
151 - </div>  
152 - <?php  
153 - $form = ActiveForm::begin(  
154 - [  
155 - 'action' => 'add-int-prop',  
156 - 'id' => 'add-int-prop-form',  
157 - ]  
158 - );  
159 - $addIntProp = new IntellectualProperty();  
160 - ?>  
161 - <div class="modal-body forms-cabinet forms-2">  
162 -  
163 -  
164 -  
165 - <?php  
166 - echo $form->field($addIntProp, 'title');  
167 - ?>  
168 -  
169 - <?php  
170 - echo $form->field($addIntProp, 'registration_date')->textInput([  
171 - 'class' => '_datepicker form-control',  
172 - ]);  
173 - ?>  
174 -  
175 - <?php  
176 - echo $form->field($addIntProp, 'genre');  
177 - ?>  
178 -  
179 - <?php  
180 - echo $form->field($addIntProp, 'author_role');  
181 - ?>  
182 -  
183 - </div>  
184 - <div class="modal-footer btn-submit-blue">  
185 - <?php  
186 - echo Html::submitButton(  
187 - 'OK'  
188 - );  
189 - ?>  
190 - </div>  
191 - <?php  
192 - $form::end();  
193 - ?> 148 + <div class="modal-dialog" role="document">
  149 + <div class="modal-content">
  150 + <div class="modal-header">
  151 + <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  152 + <span aria-hidden="true">&times;</span></button>
  153 + <h4 class="modal-title" id="myModalLabel">Додати твір</h4>
  154 + </div>
  155 + <?php
  156 + $form = ActiveForm::begin(
  157 + [
  158 + 'action' => 'add-int-prop',
  159 + 'id' => 'add-int-prop-form',
  160 + ]
  161 + );
  162 + $addIntProp = new IntellectualProperty();
  163 + ?>
  164 + <div class="modal-body forms-cabinet forms-2">
  165 +
  166 +
  167 + <?php
  168 + echo $form->field($addIntProp, 'title');
  169 + ?>
  170 +
  171 + <?php
  172 + echo $form->field($addIntProp, 'registration_date')
  173 + ->textInput(
  174 + [
  175 + 'class' => '_datepicker form-control',
  176 + ]
  177 + );
  178 + ?>
  179 +
  180 + <?php
  181 + echo $form->field($addIntProp, 'genre');
  182 + ?>
  183 +
  184 + <?php
  185 + echo $form->field($addIntProp, 'author_role');
  186 + ?>
  187 +
  188 + </div>
  189 + <div class="modal-footer btn-submit-blue">
  190 + <?php
  191 + echo Html::submitButton(
  192 + 'OK'
  193 + );
  194 + ?>
  195 + </div>
  196 + <?php
  197 + $form::end();
  198 + ?>
  199 + </div>
194 </div> 200 </div>
195 - </div>  
196 </div> 201 </div>
197 202
frontend/views/cabinet/sales.php
@@ -13,6 +13,11 @@ @@ -13,6 +13,11 @@
13 * @var IntellectualProperty $property 13 * @var IntellectualProperty $property
14 * @var CreativeRole[] $table 14 * @var CreativeRole[] $table
15 */ 15 */
  16 +
  17 + /**
  18 + * @var User $user
  19 + */
  20 + $user = \Yii::$app->user->identity;
16 ?> 21 ?>
17 <div class="style cab_content_list"> 22 <div class="style cab_content_list">
18 <div class="cab_content_list-dropdown"> 23 <div class="cab_content_list-dropdown">
@@ -27,134 +32,145 @@ @@ -27,134 +32,145 @@
27 ?> 32 ?>
28 <div class="title_forms">Продаж ОІВ</div> 33 <div class="title_forms">Продаж ОІВ</div>
29 <?php 34 <?php
30 - $form = ActiveForm::begin(  
31 - [  
32 - 'id' => 'property-form',  
33 - 'action' => \Yii::$app->request->url,  
34 - ]  
35 - );  
36 - ?>  
37 - <div class="style background_form">  
38 - <?php  
39 - echo $form->field(  
40 - $property,  
41 - 'title',  
42 - [  
43 - 'options' => [  
44 - 'class' => 'input-wrapp-757',  
45 - 'style' => 'margin-right: 40px;',  
46 - ],  
47 - ]  
48 - )  
49 - ->textarea(  
50 - [  
51 - 'cols' => 30,  
52 - 'rows' => 10,  
53 - ]  
54 - );  
55 - echo $form->field(  
56 - $property,  
57 - 'creation_date', 35 + if ($user->isAdmin() || $property->user_id == $user->id) {
  36 + $form = ActiveForm::begin(
58 [ 37 [
59 - 'options' => [  
60 - 'class' => 'input-wrapp-130',  
61 - ], 38 + 'id' => 'property-form',
  39 + 'action' => \Yii::$app->request->url,
62 ] 40 ]
63 - )  
64 - ->textInput(  
65 - [  
66 - 'class' => '_datepicer',  
67 - ]  
68 - );  
69 - ?>  
70 - <div class="style">  
71 - <?php  
72 - echo $form->field(  
73 - $property,  
74 - 'code',  
75 - [  
76 - 'options' => [  
77 - 'class' => 'input-wrapp-320',  
78 - ],  
79 - ]  
80 - )  
81 - ->textInput();  
82 - ?>  
83 - </div>  
84 - <div class="style">  
85 - <?php  
86 - echo $form->field(  
87 - $property,  
88 - 'genre',  
89 - [  
90 - 'options' => [  
91 - 'class' => 'input-wrapp-320',  
92 - ],  
93 - ]  
94 - )  
95 - ->textInput();  
96 - ?>  
97 - </div>  
98 - <div class="style">  
99 - <?php  
100 - echo $form->field(  
101 - $property,  
102 - 'registration_date',  
103 - [  
104 - 'options' => [  
105 - 'class' => 'input-wrapp-320',  
106 - ],  
107 - ]  
108 - )  
109 - ->textInput(  
110 - [  
111 - 'class' => '_datepicer',  
112 - ]  
113 - ); 41 + );
  42 + }
  43 + ?>
  44 + <?php
  45 + if ($user->isAdmin() || $property->user_id == $user->id) {
114 ?> 46 ?>
115 - </div>  
116 - <div class="style"> 47 + <div class="style background_form">
  48 + <?php
  49 + echo $form->field(
  50 + $property,
  51 + 'title',
  52 + [
  53 + 'options' => [
  54 + 'class' => 'input-wrapp-757',
  55 + 'style' => 'margin-right: 40px;',
  56 + ],
  57 + ]
  58 + )
  59 + ->textarea(
  60 + [
  61 + 'cols' => 30,
  62 + 'rows' => 10,
  63 + ]
  64 + );
  65 + echo $form->field(
  66 + $property,
  67 + 'creation_date',
  68 + [
  69 + 'options' => [
  70 + 'class' => 'input-wrapp-130',
  71 + ],
  72 + ]
  73 + )
  74 + ->textInput(
  75 + [
  76 + 'class' => '_datepicer',
  77 + ]
  78 + );
  79 + ?>
  80 + <div class="style">
  81 + <?php
  82 + echo $form->field(
  83 + $property,
  84 + 'code',
  85 + [
  86 + 'options' => [
  87 + 'class' => 'input-wrapp-320',
  88 + ],
  89 + ]
  90 + )
  91 + ->textInput();
  92 + ?>
  93 + </div>
  94 + <div class="style">
  95 + <?php
  96 + echo $form->field(
  97 + $property,
  98 + 'genre',
  99 + [
  100 + 'options' => [
  101 + 'class' => 'input-wrapp-320',
  102 + ],
  103 + ]
  104 + )
  105 + ->textInput();
  106 + ?>
  107 + </div>
  108 + <div class="style">
  109 + <?php
  110 + echo $form->field(
  111 + $property,
  112 + 'registration_date',
  113 + [
  114 + 'options' => [
  115 + 'class' => 'input-wrapp-320',
  116 + ],
  117 + ]
  118 + )
  119 + ->textInput(
  120 + [
  121 + 'class' => '_datepicer',
  122 + ]
  123 + );
  124 + ?>
  125 + </div>
  126 + <div class="style">
  127 + <?php
  128 + echo $form->field(
  129 + $property,
  130 + 'contract',
  131 + [
  132 + 'options' => [
  133 + 'class' => 'input-wrapp-320',
  134 + 'style' => 'margin-right: 40px;',
  135 + ],
  136 + ]
  137 + )
  138 + ->textInput();
  139 + echo $form->field(
  140 + $property,
  141 + 'type',
  142 + [
  143 + 'options' => [
  144 + 'class' => 'input-wrapp-320',
  145 + ],
  146 + ]
  147 + )
  148 + ->textInput();
  149 + ?>
  150 + </div>
  151 +
  152 + </div>
117 <?php 153 <?php
118 - echo $form->field(  
119 - $property,  
120 - 'contract',  
121 - [  
122 - 'options' => [  
123 - 'class' => 'input-wrapp-320',  
124 - 'style' => 'margin-right: 40px;',  
125 - ],  
126 - ]  
127 - )  
128 - ->textInput();  
129 - echo $form->field(  
130 - $property,  
131 - 'type',  
132 - [  
133 - 'options' => [  
134 - 'class' => 'input-wrapp-320',  
135 - ],  
136 - ]  
137 - )  
138 - ->textInput();  
139 - ?>  
140 - </div>  
141 -  
142 - </div>  
143 - 154 + }
  155 + ?>
144 <?php 156 <?php
145 if (!$property->isNewRecord) { 157 if (!$property->isNewRecord) {
  158 + if ($user->isAdmin() || $property->user_id == $user->id) {
  159 + ?>
  160 + <div class="btn-submit-blue">
  161 + <?php echo Html::button(
  162 + 'Додати',
  163 + [
  164 + 'type' => 'button',
  165 + 'class' => 'add-role-button',
  166 + 'data-toggle' => 'modal',
  167 + 'data-target' => '#add-role-modal',
  168 + ]
  169 + ) ?>
  170 + </div>
  171 + <?php
  172 + }
146 ?> 173 ?>
147 - <div class="btn-submit-blue">  
148 - <?php echo Html::button(  
149 - 'Додати',  
150 - [  
151 - 'type' => 'button',  
152 - 'class' => 'add-role-button',  
153 - 'data-toggle' => 'modal',  
154 - 'data-target' => '#add-role-modal',  
155 - ]  
156 - ) ?>  
157 - </div>  
158 174
159 <div class="style wrapp-tabs-table"> 175 <div class="style wrapp-tabs-table">
160 <div class="style table-wrapp-2"> 176 <div class="style table-wrapp-2">
@@ -181,13 +197,20 @@ @@ -181,13 +197,20 @@
181 ?> 197 ?>
182 <tr> 198 <tr>
183 <td><?= $row->title ?></td> 199 <td><?= $row->title ?></td>
184 - <td></td> 200 + <td><?= $row->user->userData->name . ' ' . $row->user->userData->surname ?></td>
185 <td><?= $row->part ?></td> 201 <td><?= $row->part ?></td>
186 <td><?= $row->code ?></td> 202 <td><?= $row->code ?></td>
187 <td><?= $row->iri ?></td> 203 <td><?= $row->iri ?></td>
188 <td><?= $row->society ?></td> 204 <td><?= $row->society ?></td>
189 <td> 205 <td>
190 - <a href="#" class="edit-table update-role" data-id="<?= $row->id ?>"></a><a href="#" class="remove-table delete-role" data-id="<?= $row->id ?>"></a> 206 + <?php
  207 + if ($user->isAdmin() || $property->user_id == $user->id) {
  208 + ?>
  209 + <a href="#" class="edit-table update-role" data-id="<?= $row->id ?>"></a>
  210 + <a href="#" class="remove-table delete-role" data-id="<?= $row->id ?>"></a>
  211 + <?php
  212 + }
  213 + ?>
191 </td> 214 </td>
192 </tr> 215 </tr>
193 <?php 216 <?php
@@ -203,20 +226,25 @@ @@ -203,20 +226,25 @@
203 <?php 226 <?php
204 } 227 }
205 ?> 228 ?>
206 -  
207 - <div class="input-wrapp btn-submit-blue">  
208 - <?php  
209 - echo Html::submitButton('зберегти');  
210 - ?>  
211 - </div>  
212 <?php 229 <?php
213 - $form::end(); 230 + if ($user->isAdmin() || $property->user_id == $user->id) {
  231 + ?>
  232 + <div class="input-wrapp btn-submit-blue">
  233 + <?php
  234 + echo Html::submitButton('зберегти');
  235 + ?>
  236 + </div>
  237 + <?php
  238 + $form::end();
  239 + }
  240 + ?>
  241 + <?php
214 Pjax::end(); 242 Pjax::end();
215 ?> 243 ?>
216 </div> 244 </div>
217 </div> 245 </div>
218 <?php 246 <?php
219 - if (!$property->isNewRecord) { 247 + if (!$property->isNewRecord && ( $user->isAdmin() || $property->user_id == $user->id )) {
220 ?> 248 ?>
221 <!-- Modal --> 249 <!-- Modal -->
222 <div class="modal fade" id="add-role-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> 250 <div class="modal fade" id="add-role-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
frontend/views/layouts/cabinet.php
@@ -343,6 +343,24 @@ EOT; @@ -343,6 +343,24 @@ EOT;
343 'class' => 'disabled', 343 'class' => 'disabled',
344 ], 344 ],
345 ], 345 ],
  346 + [
  347 + 'label' => Html::tag(
  348 + 'span',
  349 + '',
  350 + [
  351 + 'style' => "background: url('/images/cabinet/icon-menu/ico-1.png') 50% 50% no-repeat",
  352 + ]
  353 + ) . Html::tag(
  354 + 'span',
  355 + '',
  356 + [
  357 + 'class' => 'act_bg',
  358 + 'style' => "background: url('/images/cabinet/icon-menu/ico-1-act.png') 50% 50% no-repeat",
  359 + ]
  360 + ) . 'Вийти',
  361 + 'url' => [ 'site/logout' ],
  362 + 'template' => '<a href="{url}" data-method="post">{label}</a>'
  363 + ],
346 ], 364 ],
347 ] 365 ]
348 ); 366 );