OSDN Git Service

Изменён тип хранения информации о проинвентаризированных, учтённых, и непроверенных...
[invent/invent.git] / views / items / index.php
1 <?php
2
3 use yii\helpers\Html;
4 use yii\grid\GridView;
5 use yii\widgets\Pjax;
6 use yii\helpers\Url;
7 use yii\widgets\DetailView;
8 use yii\helpers\ArrayHelper;
9 use app\models\Status;
10 use app\models\User;
11
12 /* @var $this yii\web\View */
13 /* @var $searchModel app\models\ItemsSearch */
14 /* @var $dataProvider yii\data\ActiveDataProvider */
15
16 $this->title = Yii::t('items', 'Items');
17 $this->params[ 'breadcrumbs' ][] = $this->title;
18
19 // Формирование колонок и кнопок
20 // номер строки
21 $columns = [[ 'class' => 'yii\grid\SerialColumn' ]];
22 // Кнопки действий {view} {update} {delete} {print}
23 $template = '';
24 $buttons = [];
25
26 $pageSize = Yii::$app->session['pageSize'] ?? 20;
27
28 if (User::canPermission('createRecord'))
29 {
30     $template .= ' {copy}';
31     $buttons [ 'copy' ] = function ($url, $model, $key)
32         {
33             return Html::a('<span class="glyphicon glyphicon-share"></span>',
34                 Url::to([ 'addcopy', 'is' => $model->id ]), [ 'title' => Yii::t('items', 'Copy from curren item'), ]);
35         };
36 }
37
38 if (User::canPermission('updateRecord'))
39 {
40     // Кнопки
41     $template .= ' {delete}';
42     // Инвентарный номер
43     array_push($columns, [ 'attribute' => 'invent',
44         'value' => function ($data)
45         {
46             return showUrlUpdate($data->invent, $data);
47         },
48         'format' => 'raw',
49     ] );
50
51     // Серийный номер
52     array_push($columns, [ 'attribute' => 'serial',
53         'value' => function ($data)
54         {
55             return showUrlUpdate($data->serial, $data);
56         },
57         'format' => 'raw',
58     ] );
59
60     // Модель
61     array_push($columns, [ 'attribute' => 'modelName',
62         'value' => function ($data)
63         {
64             if ($data->name == '')
65             {
66                 return showUrlUpdate($data->modelName, $data);
67             }
68             else
69             {
70                 return showUrlUpdate($data->modelName . ' (' . $data->name . ')', $data);
71             }
72         },
73         'format' => 'raw',
74     ] );
75
76     /* // Идентификатор записи
77     array_push($columns, [ 'attribute' => 'id',
78         'value' => function ($data)
79         {
80             return showUrlUpdate($data->id, $data);
81         },
82         'format' => 'raw',
83     ] ); // */
84
85     /* // Сетевое имя
86     array_push($columns, [ 'attribute' => 'name',
87         'value' => function ($data)
88         {
89             return showUrlUpdate($data->name, $data);
90         },
91         'format' => 'raw',
92     ] ); // */
93
94     // Название подразделения
95     array_push($columns, [ 'attribute' => 'regionName',
96         'value' => function ($data)
97         {
98             return showUrlUpdate($data->regionName . ' (' . $data->locationName . ')', $data);
99         },
100         'format' => 'raw',
101     ] ); // */
102
103     // Состояние
104     array_push($columns, [ 'attribute' => 'statusName',
105         'filter' => Html::activeDropDownList(
106             $searchModel,
107             'statusName',
108             ArrayHelper::merge(
109                 [ '' => Yii::t('app', 'All statuses'), ],
110                 ArrayHelper::map(Status::find()->orderBy('name')->all(), 'name', 'name')
111             ),
112             [ 'class' => 'form-control', ],
113         ) ,
114         'value' => function ($data)
115         {
116             return showUrlUpdate($data->statusName, $data);
117         },
118         'format' => 'raw',
119     ] ); // */
120
121     /* // Операционная система
122     array_push($columns, [ 'attribute' => 'os',
123         'value' => function ($data)
124         {
125             return showUrlUpdate($data->os, $data);
126         },
127         'format' => 'raw',
128     ] ); // */
129
130     /* // МАС - адрес
131     array_push($columns, [ 'attribute' => 'mac',
132         'value' => function ($data)
133         {
134             return showUrlUpdate($data->mac, $data);
135         },
136         'format' => 'raw',
137     ] ); // */
138
139     /* // Примечания
140     array_push($columns, [ 'attribute' => 'comment',
141         'value' => function ($data)
142         {
143             return showUrlUpdate($data->comment, $data);
144         },
145         'format' => 'raw',
146     ] ); // */
147
148
149 }
150 else
151 {
152     array_push($columns, 'invent');
153     array_push($columns, 'serial');
154     array_push($columns, 'modelName');
155     //array_push($columns, 'id');
156     //array_push($columns, 'name');
157     array_push($columns, [ 'attribute' => 'regionName',
158         'value' => function($data)
159         {
160             return $data->regionName .  ' (' . $data->locationName . ')';
161         },
162     ]);
163     array_push($columns, [ 'attribute' => 'statusName',
164         'filter' => Html::activeDropDownList(
165             $searchModel,
166             'statusName',
167             ArrayHelper::merge(
168                 [ '' => Yii::t('app', 'All statuses') ],
169                 ArrayHelper::map(Status::find()->orderBy('name')->all(), 'name', 'name')),
170             [ 'class' => 'form-control' ],
171         ),
172         'value' => 'statusName',
173     ]);
174     //array_push($columns, 'os');
175     //array_push($columns, 'mac');
176     //array_push($columns, 'product');
177     //array_push($columns, 'modelnumber');
178     //array_push($columns, 'comment');
179 }
180
181 if (User::canPermission('takingInventory'))
182 {
183     // Кнопки
184     $template .= ' {print}';
185     $buttons[ 'print' ] = function ($url, $model, $key)
186         {
187             return Html::a('<span class="glyphicon glyphicon-print"></span>',
188                 Url::to([ 'print', 'id[]' => $model->id ], 'http'),
189                 [ 'target' => '_blank',
190                     'onclick' => 'markToPrint($(this));',
191                     'data-pjax' => 0,
192                     'title' => Yii::t('items', 'Print selected labels'),
193                 ]);
194         };
195     // Чекбоксы для выбора предметов/оборудования для печати QR меток
196     array_push($columns,
197             [ 'class' => 'yii\grid\CheckboxColumn',
198                 'checkboxOptions' => function($model, $key, $index, $column)
199                     {
200                         return [ 'value' => $model->id, ];
201                     },
202             ]
203     );
204 }
205
206 array_push($columns, [
207     'class' => 'yii\grid\ActionColumn',
208     'template' => $template,
209     'buttons' => $buttons,
210     'header' => Html::dropDownList(
211             'pageSize', $pageSize, [
212                 20 => 20,
213                 50 => 50,
214                 100 => 100,
215                 0 => 'Все',
216             ],
217             [ 'onChange' => '$.pjax.reload({container: "#ItemsTable", url: $(location).attr("href") + "&pageSize=" + $(this).val()});',
218               'title' => Yii::t('app', 'Lines per page'),
219             ]
220         ),
221 ]);
222
223 ?>
224 <div class="items-index">
225
226     <h1><?= Html::encode($this->title) ?></h1>
227
228 <script language="JavaScript">
229     function markToPrint(href)
230     {
231         url = href.attr("href");
232         var ids = $("input[name='selection[]']");
233         var res = '';
234         for ( var i = 0; i < ids.length; i++)
235         {
236             if (ids[ i ][ "checked" ] == 1)
237             {
238                 res += "&id[]=" + ids[ i ][ "value" ];
239             }
240         }
241         href.attr("href", url + res);
242         return false;
243     }
244 </script>
245
246     <div class="row">
247         <?php // Кнопки на форме 
248             if (User::canPermission('createRecord'))
249             {
250         ?>
251         <div class="col-md-2"><?= Html::a(Yii::t('items', 'Create Items'),
252             [ 'create' ],
253             [ 'class' => 'btn btn-success' ]) ?></div>
254             <?php
255             }
256             if (User::canPermission('updateRecord'))
257             {
258             ?>
259         <div class="col-md-2"><?= Html::a(Yii::t('items', 'Import'),
260             [ 'import' ],
261             [ 'class' => 'btn btn-success',
262                 'style' => 'width: 100%;',
263             ]) ?></div>
264         <div class="col-md-2"><?= Html::a(Yii::t('items', 'Print Items'),
265             Url::to([ 'print' ], 'http'),
266             [ 'class' => 'btn btn-warning',
267                 'style' => 'width: 100%;',
268                 'target' => '_blank',
269             ]) ?></div>
270             <?php
271             }
272             if (User::canPermission('takingInventory'))
273             {
274             ?>
275         <div class="col-md-2"><?= Html::a(Yii::t('items', 'Start checking'),
276             [ 'start_checking' ],
277             [ 'class' => 'btn btn-info',
278             ]) ?></div>
279         <?php
280             }
281         ?>
282     </div>
283
284     <?php Pjax::begin(); ?>
285     <?= GridView::widget([
286         'id' => 'ItemsTable',
287         'dataProvider' => $dataProvider, // Источник данных
288         'filterModel' => $searchModel,   // Модель поиска
289         'rowOptions' => function($model) // Функция окраски неинвентаризированных предметов/оборудования
290             {
291                 if ($model->checked == 0)     // Критерий проверки планируется
292                 {
293                     return [ 'class' => 'danger' ]; // Отметка неинвентаризированной строки
294                 } else
295                 if ($model->checked == 2)
296                 {
297                     return [ 'class' => 'warning' ]; // Отметка непроверенной строки
298                 } else
299                 if ($model->statusName == 'Списано')
300                 {
301                     return [ 'class' => 'info' ];
302                 }
303             },
304         'columns' => $columns,
305     ]); ?>
306     <?php Pjax::end(); ?>
307
308 </div>