Bug 22175: Make stock rotation table sortable
[koha-equinox.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / stockrotation.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE Branches %]
5 [% USE KohaDates %]
6 [% USE ColumnsSettings %]
7 [% SET footerjs = 1 %]
8 [% INCLUDE 'doc-head-open.inc' %]
9 <title>Koha &rsaquo; Stock rotation</title>
10 [% INCLUDE 'doc-head-close.inc' %]
11 </head>
12
13 <body id="tools_stockrotation" class="tools">
14 [% INCLUDE 'header.inc' %]
15 [% INCLUDE 'cat-search.inc' %]
16
17 <div id="breadcrumbs">
18     <a href="/cgi-bin/koha/mainpage.pl">Home</a>
19     &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
20
21 [% IF no_op_set %]
22     &rsaquo; Stock rotation
23 [% ELSE %]
24     &rsaquo; <a href="/cgi-bin/koha/tools/stockrotation.pl">Stock rotation</a>
25 [% END %]
26
27 [% IF (op == 'create_edit_rota' && rota.rota_id) %]
28     &rsaquo; Edit rota
29 [% ELSIF (op == 'create_edit_rota' && !rota.rota_id) %]
30     &rsaquo; Create rota
31 [% ELSIF (op == 'manage_stages') %]
32     &rsaquo; Manage stages
33 [% ELSIF (op == 'create_edit_stage' && stage.id) %]
34     <a href="?op=manage_stages&amp;rota_id=[% rota_id | uri %]">&rsaquo; Manage stages</a>
35     &rsaquo; Edit stage
36 [% ELSIF (op == 'create_edit_stage' && !stage.id) %]
37     <a href="?op=manage_stages&amp;rota_id=[% rota_id | uri %]">&rsaquo; Manage stages</a>
38     &rsaquo; Create stage
39 [% ELSIF (op == 'manage_items') %]
40     &rsaquo; Manage items
41 [% END %]
42
43 </div>
44
45 <div class="main container-fluid">
46     <div class="row">
47         <div class="col-sm-10 col-sm-push-2">
48             <main>
49
50             <div id="stockrotation">
51
52                 [% IF no_op_set %]
53
54                     [% INCLUDE 'stockrotation-toolbar.inc' %]
55
56                     <h2>Stock rotation</h2>
57
58                     [% IF existing_rotas.size > 0 %]
59                         <table id="stock_rotation" class="rotas_table" role="grid">
60                             <thead>
61                                 <tr>
62                                 <th class="anti-the">Name</th>
63                                 <th>Cyclical</th>
64                                 <th>Active</th>
65                                 <th>Description</th>
66                                 <th>Number of items</th>
67                                 <th class="NoSort">&nbsp;</th>
68                                 </tr>
69                             </thead>
70                             <tbody>
71                                 [% FOREACH rota IN existing_rotas %]
72                                     <tr>
73                                         <td>[% rota.title | html %]</td>
74                                         <td>[% rota.cyclical ? 'Yes' : 'No' | html %]</td>
75                                         <td>[% rota.active ? 'Yes' : 'No' | html %]</td>
76                                         <td>[% rota.description | html %]</td>
77                                         <td>[% rota.stockrotationitems.count | html %]</td>
78                                         <td class="actions">
79                                             <a class="btn btn-default btn-xs" href="?op=create_edit_rota&amp;rota_id=[% rota.rota_id | uri %]">
80                                                 <i class="fa fa-pencil"></i>
81                                                 Edit
82                                             </a>
83                                             <div class="btn-group dropup" role="group">
84                                                 <button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
85                                                     Manage
86                                                     <i class="fa fa-caret-down"></i>
87                                                 </button>
88                                                 <ul class="dropdown-menu pull-right">
89                                                     <li><a href="?op=manage_stages&amp;rota_id=[% rota.rota_id | uri %]">Stages</a></li>
90                                                     [% IF CAN_user_stockrotation_manage_rota_items && rota.stockrotationstages.count > 0 %]
91                                                     <li><a href="?op=manage_items&amp;rota_id=[% rota.rota_id | uri %]">Items</a></li>
92                                                     [% END %]
93                                                 </ul>
94                                             </div>
95                                             <a class="btn btn-default btn-xs" href="?op=toggle_rota&amp;rota_id=[% rota.rota_id | uri %]">
96                                                 <i class="fa fa-power-off"></i>
97                                                 [% IF !rota.active %]
98                                                     Activate
99                                                 [% ELSE %]
100                                                     Deactivate
101                                                 [% END %]
102                                             </a>
103                                         </td>
104                                     </tr>
105                                 [% END %]
106                             </tbody>
107                         </table>
108                     [% END %]
109
110                 [% ELSIF (op == 'create_edit_rota') %]
111
112                     [% IF rota.rota_id %]
113                         <h2>Edit "[% rota.title | html %]"</h2>
114                     [% ELSE %]
115                         <h2>Create new rota</h2>
116                     [% END %]
117
118                     [% IF error == 'invalid_form' %]
119                     <div class="dialog alert">
120                         <h3>There was a problem with your form submission</h3>
121                     </div>
122                     [% END %]
123
124                     <form id="rota_form" method="post" enctype="multipart/form-data" class="validated">
125                         <fieldset class="rows">
126                             <ol>
127                                 <li>
128                                     <label class="required" for="title">Name:</label>
129                                     <input type="text" id="title" name="title" value="[% rota.title | html %]" required="required" placeholder="Rota name">
130                                     <span class="required">Required</span>
131                                 </li>
132                                 <li>
133                                     <label for="cyclical">Cyclical:</label>
134                                     <select name="cyclical" id="cyclical">
135                                         [% IF rota.cyclical %]
136                                             <option value="1" selected>Yes</option>
137                                             <option value="0">No</option>
138                                         [% ELSE %]
139                                             <option value="1">Yes</option>
140                                             <option value="0" selected>No</option>
141                                         [% END %]
142                                     </select>
143                                 </li>
144                                 <li>
145                                     <label for="description">Description:</label>
146                                     <textarea id="description" name="description" placeholder="Rota description">[% rota.description | html %]</textarea>
147                                 </li>
148                             </ol>
149                         </fieldset>
150                         <fieldset class="action">
151                             <input type="submit" value="Save">
152                             <a href="/cgi-bin/koha/tools/stockrotation.pl" class="cancel">Cancel</a>
153                         </fieldset>
154                         [% IF rota.rota_id %]
155                             <input type="hidden" name="id" value="[% rota.rota_id | html %]">
156                         [% END %]
157                         <input type="hidden" name="op" value="process_rota">
158                     </form>
159
160                 [% ELSIF (op == 'manage_stages') %]
161
162                     [% INCLUDE 'stockrotation-toolbar.inc' %]
163
164                     [% IF error == 'invalid_form' %]
165                     <div class="dialog alert">
166                         <h3>There was a problem with your form submission</h3>
167                     </div>
168                     [% END %]
169
170                     <h2>Manage [% rota.title | html %] stages</h2>
171                     <div id="ajax_status"
172                         data-saving-msg="Saving changes..."
173                         data-success-msg=""
174                         data-failed-msg="Error: ">
175                         <span id="ajax_saving_msg"></span>
176                         <i id="ajax_saving_icon" class="fa fa-spinner fa-spin"></i>
177                         <i id="ajax_success_icon" class="fa fa-check"></i>
178                         <i id="ajax_failed_icon" class="fa fa-times"></i>
179                         <span id="ajax_success_msg"></span>
180                         <span id="ajax_failed_msg"></span>
181                     </div>
182
183                     <form id="stage_form" method="post" enctype="multipart/form-data" class="validated">
184                         <fieldset class="rows">
185                             <legend>Add stage</legend>
186                             <ol>
187                                 <li>
188                                     <label class="required" for="branch">Library:</label>
189                                     <select name="branchcode" id="branch">
190                                         [% FOREACH branch IN branches %]
191                                             [% IF branch.branchcode == stage.branchcode_id %]
192                                                 <option value="[% branch.branchcode | html %]" selected>[% Branches.GetName(branch.branchcode) | html %]</option>
193                                             [% ELSE %]
194                                                 <option value="[% branch.branchcode | html %]">[% Branches.GetName(branch.branchcode) | html %]</option>
195                                             [% END %]
196                                         [% END %]
197                                     </select>
198                                     <span class="required">Required</span>
199                                 </li>
200                                 <li>
201                                     <label class="required" for="duration">Duration:</label>
202                                     <input type="text" id="duration" name="duration" value="[% stage.duration | html %]" required="required" placeholder="Duration (days)">
203                                     <span class="required">Required</span>
204                                 </li>
205                             </ol>
206                         </fieldset>
207                         <fieldset class="action">
208                             <input type="submit" value="Submit">
209                         </fieldset>
210                         <input type="hidden" name="stage_id" value="[% stage.id | html %]">
211                         <input type="hidden" name="rota_id" value="[% rota_id | html %]">
212                         <input type="hidden" name="op" value="process_stage">
213                     </form>
214
215                     [% IF existing_stages.size > 0 %]
216                         <div id="manage_stages">
217                             <div id="manage_stages_help">
218                                 Stages can be re-ordered by using the <i class="drag_handle fa fa-lg fa-bars"></i>handle to drag and drop them to their new position
219                             </div>
220                             <div id="stage_list_headings">
221                                 <span class="stagename">Library</span>
222                                 <span class="stageduration">Duration (days)</span>
223                             </div>
224                             <ul id="sortable_stages" data-rota-id="[% rota.rota_id | html %]">
225                                 [% FOREACH stage IN existing_stages %]
226                                     <li id="stage_[% stage.stage_id | html %]">
227                                         <span data-toggle="tooltip" title="Drag and drop to move this stage to another position" data-placement="right" class="stagename">
228                                             [% IF existing_stages.size > 1 %]
229                                                 <i class="drag_handle fa fa-lg fa-bars"></i>
230                                             [% END %]
231                                             [% Branches.GetName(stage.branchcode_id) | html %]
232                                         </span>
233                                         <span class="stageduration">[% stage.duration | html %]</span>
234                                         <span class="stageactions">
235                                             <a class="btn btn-default btn-xs" href="?op=create_edit_stage&amp;stage_id=[% stage.stage_id | uri %]">
236                                                 <i class="fa fa-pencil"></i> Edit
237                                             </a>
238                                             <a class="btn btn-default btn-xs" href="?op=confirm_delete_stage&amp;stage_id=[% stage.stage_id | uri %]">
239                                                 <i class="fa fa-trash"></i> Delete
240                                             </a>
241                                         </span>
242                                     </li>
243                                 [% END %]
244                             </ul>
245                         </div>
246                     [% END %]
247
248                     <p><a href="stockrotation.pl">Return to rotas</a></p>
249
250                 [% ELSIF (op == 'create_edit_stage') %]
251
252                     [% IF stage.id %]
253                         <h2>Edit "[% Branches.GetName(stage.branchcode_id) | html %]"</h2>
254                     [% ELSE %]
255                         <h2>Create new stage</h2>
256                     [% END %]
257
258                     [% IF error == 'invalid_form' %]
259                     <div class="dialog alert">
260                         <h3>There was a problem with your form submission</h3>
261                     </div>
262                     [% END %]
263
264                     <form id="stage_form" method="post" enctype="multipart/form-data" class="validated">
265                         <fieldset class="rows">
266                             <ol>
267                                 <li>
268                                     <label class="required" for="branch">Library:</label>
269                                     <select name="branchcode" id="branch">
270                                         [% FOREACH branch IN branches %]
271                                             [% IF branch.branchcode == stage.branchcode_id %]
272                                                 <option value="[% branch.branchcode | html %]" selected>[% Branches.GetName(branch.branchcode) | html %]</option>
273                                             [% ELSE %]
274                                                 <option value="[% branch.branchcode | html %]">[% Branches.GetName(branch.branchcode) | html %]</option>
275                                             [% END %]
276                                         [% END %]
277                                     </select>
278                                     <span class="required">Required</span>
279                                 </li>
280                                 <li>
281                                     <label class="required" for="duration">Duration:</label>
282                                     <input type="text" id="duration" name="duration" value="[% stage.duration | html %]" required="required" placeholder="Duration (days)">
283                                     <span class="required">Required</span>
284                                 </li>
285                             </ol>
286                         </fieldset>
287                         <fieldset class="action">
288                             <input type="submit" value="Save">
289                             <a href="/cgi-bin/koha/tools/stockrotation.pl?op=manage_stages&amp;rota_id=[% rota_id | uri %]" class="cancel">Cancel</a>
290                         </fieldset>
291                         <input type="hidden" name="stage_id" value="[% stage.id | html %]">
292                         <input type="hidden" name="rota_id" value="[% rota_id | html %]">
293                         <input type="hidden" name="op" value="process_stage">
294                     </form>
295                 [% ELSIF (op == 'confirm_remove_from_rota') %]
296
297                     <div class="dialog alert">
298                         <h3>Are you sure you wish to remove this item from it's rota</h3>
299                         <p>
300                             <a class="btn btn-default btn-xs approve" href="?op=remove_item_from_stage&amp;item_id=[% item_id | uri %]&amp;stage_id=[% stage_id | uri %]&amp;rota_id=[% rota_id | uri %]"><i class="fa fa-fw fa-check"></i>Yes</a>
301                             <a class="btn btn-default btn-xs deny" href="?op=manage_items&amp;rota_id=[% rota_id | uri %]"><i class="fa fa-fw fa-remove"></i>No</a>
302                         </p>
303                     </div>
304                 [% ELSIF (op == 'confirm_delete_stage') %]
305
306                     <div class="dialog alert">
307                         <h3>Are you sure you want to delete this stage?</h3>
308                         [% IF stage.stockrotationitems.count > 0 %]
309                             <p>This stage contains the following item(s):</p>
310                             <ul>
311                                 [% FOREACH item IN stage.stockrotationitems %]
312                                     <li>[% item.itemnumber.biblio.title | html %] (Barcode: [% item.itemnumber.barcode | html %])</li>
313                                 [% END %]
314                             </ul>
315                         [% END %]
316                         <p>
317                             <a class="btn btn-default btn-xs approve" href="?op=delete_stage&amp;stage_id=[% stage.stage_id | uri %]"><i class="fa fa-fw fa-check"></i>Yes</a>
318                             <a class="btn btn-default btn-xs deny" href="?op=manage_stages&amp;rota_id=[% stage.rota.rota_id | uri %]"><i class="fa fa-fw fa-remove"></i>No</a>
319                         </p>
320                     </div>
321                 [% ELSIF (op == 'manage_items') %]
322
323                     [% INCLUDE 'stockrotation-toolbar.inc' %]
324
325                     [% IF error %]
326                         <div class="dialog alert">
327                             [% IF error == "item_not_found" %]
328                                 <h3>The item was not found</h3>
329                             [% ELSIF error == "already_on_rota" %]
330                                 <h3>This item is already on this rota</h3>
331                             [% END %]
332                         </div>
333                     [% END %]
334
335                     <h2>Manage [% rota.title | html %] items</h2>
336
337                     <div>
338                         <form id="add_rota_item_form" method="post" enctype="multipart/form-data" class="validated">
339                             <fieldset class="rows">
340                                 <legend>Add item to &quot;[% rota.title | html %]&quot;</legend>
341                                 <ol>
342                                     <li>
343                                         <label for="barcode">Barcode:</label>
344                                         <input type="text" id="barcode" name="barcode" placeholder="Item barcode" autofocus>
345                                     </li>
346                                 </ol>
347                             </fieldset>
348                             <fieldset class="rows">
349                                 <legend>Use a barcode file</legend>
350                                 <ol>
351                                     <li>
352                                         <label for="barcodefile">Barcode file:</label>
353                                         <input type="file" id="barcodefile" name="barcodefile">
354                                     </li>
355                                 </ol>
356                             </fieldset>
357                             <fieldset class="action">
358                                 <input type="submit" value="Save">
359                             </fieldset>
360                             <input type="hidden" name="rota_id" value="[% rota.id | html %]">
361                             <input type="hidden" name="op" value="add_items_to_rota">
362                         </form>
363                     </div>
364
365                     [% IF items.count > 0 %]
366                         <h3>Manage items assigned to &quot;[% rota.title | html %]&quot;</h3>
367                         <table id="stock_rotation_manage_items" class="items_table" role="grid">
368                             <thead>
369                                 <tr>
370                                     <th>Barcode</th>
371                                     <th>Title</th>
372                                     <th>Author</th>
373                                     <th>Call number</th>
374                                     <th class="NoSearch">In transit</th>
375                                     <th class="NoSort">Stages &amp; duration in days<br>(current stage highlighted)</th>
376                                     <th class="NoSort">&nbsp;</th>
377                                 </tr>
378                             </thead>
379                             <tbody>
380                                 [% FOREACH item IN items %]
381                                     <tr>
382                                         <td><a href="/cgi-bin/koha/catalogue/moredetail.pl?itemnumber=[% item.id | uri %]&amp;biblionumber=[% item.itemnumber.biblio.id | uri %]#item[% item.id | uri %]">[% item.itemnumber.barcode | html %]</a></td>
383                                         <td><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% item.itemnumber.biblio.id | uri %]">[% item.itemnumber.biblio.title | html %]</a></td>
384                                         <td>[% item.itemnumber.biblio.author | html %]</td>
385                                         <td>[% item.itemnumber.itemcallnumber | html %]</td>
386                                         <td>[% item.itemnumber.get_transfer ? 'Yes' : 'No' | html %]</td>
387                                         <td>
388                                             [% FOREACH this_stage IN stages %]
389                                                 [% IF this_stage.stage_id == item.stage.stage_id %]
390                                                     <span class="stage highlight_stage">
391                                                 [% ELSE %]
392                                                     <span class="stage">
393                                                 [% END %]
394                                                 [% Branches.GetName(this_stage.branchcode_id) | html %] ([% this_stage.duration | html %])
395                                                 </span>
396                                                 &raquo;
397                                             [% END %]
398                                             [% IF stages.size > 0 %]
399                                                 <span class="stage">[% rota.cyclical ? 'START' : 'END' | html %]</span>
400                                             [% END %]
401                                         </td>
402                                         <td class="actions">
403                                             [% in_transit = item.itemnumber.get_transfer %]
404                                             [% IF !in_transit && stages.size > 1 %]
405                                                 <a class="btn btn-default btn-xs" href="?op=move_to_next_stage&amp;rota_id=[% rota.id | uri %]&amp;item_id=[% item.id | uri %]&amp;stage_id=[% item.stage.stage_id | uri %]">
406                                             [% ELSE %]
407                                                 <a class="btn btn-default btn-xs" disabled>
408                                             [% END %]
409                                                 <i class="fa fa-arrow-right"></i>
410                                                 Move to next stage
411                                             </a>
412                                             [% IF !in_transit %]
413                                                 <a class="btn btn-default btn-xs" href="?op=toggle_in_demand&amp;stage_id=[% item.stage.stage_id | uri %]&amp;item_id=[% item.id | uri %]&amp;rota_id=[% rota.id | uri %]">
414                                             [% ELSE %]
415                                                 <a class="btn btn-default btn-xs" disabled>
416                                             [% END %]
417                                                 <i class="fa fa-fire"></i>
418                                                 [% IF item.indemand %]
419                                                 <span>Remove &quot;In demand&quot;</span>
420                                                 [% ELSE %]
421                                                 <span>Add &quot;In demand&quot;</span>
422                                                 [% END %]
423                                             </a>
424                                             [% IF !in_transit %]
425                                                 <a class="btn btn-default btn-xs" href="?op=confirm_remove_from_rota&amp;stage_id=[% item.stage.stage_id | uri %]&amp;item_id=[% item.id | uri %]&amp;rota_id=[% rota.id | uri %]">
426                                             [% ELSE %]
427                                                 <a class="btn btn-default btn-xs" disabled>
428                                             [% END %]
429                                                 <i class="fa fa-trash"></i>
430                                                 Remove from rota
431                                             </a>
432                                         </td>
433                                     </tr>
434                                 [% END %]
435                             </tbody>
436                         </table>
437                     [% END %]
438
439                     <p><a href="stockrotation.pl">Return to rotas</a></p>
440
441                 [% ELSIF op == 'add_items_to_rota' %]
442
443                     <div class="dialog message">
444                         <h3>Add items to rota report</h3>
445                     </div>
446
447                     <div>
448                         [% IF barcode_status.ok.size > 0 %]
449                             <h4>Items added to rota:</h4>
450                             <ul>
451                                 [% FOREACH item_ok IN barcode_status.ok %]
452                                     <li>[% item_ok.biblio.title | html %]</li>
453                                 [% END %]
454                             </ul>
455                         [% END %]
456                         [% IF barcode_status.on_this.size > 0 %]
457                             <h4>Items already on this rota:</h4>
458                             <ul>
459                                 [% FOREACH item_on_this IN barcode_status.on_this %]
460                                     <li>[% item_on_this.biblio.title | html %]</li>
461                                 [% END %]
462                             </ul>
463                         [% END %]
464                         [% IF barcode_status.not_found.size > 0 %]
465                             <h4>Barcodes not found:</h4>
466                             <ul>
467                                 [% FOREACH barcode_not_found IN barcode_status.not_found %]
468                                     <li>[% barcode_not_found | html %]</li>
469                                 [% END %]
470                             </ul>
471                         [% END %]
472                         [% IF barcode_status.on_other.size > 0 %]
473                             <h4>Items found on other rotas:</h4>
474                             <ul>
475                                 [% FOREACH item_on_other IN barcode_status.on_other %]
476                                     <li>[% item_on_other.biblio.title | html %]</li>
477                                 [% END %]
478                             </ul>
479                         [% END %]
480                     </div>
481                     [% IF barcode_status.on_other.size > 0 %]
482                         <form id="add_rota_item_form" method="post" enctype="multipart/form-data">
483                             <fieldset>
484                                 <legend>Select items to move to this rota:</legend>
485                                 [% FOREACH item_on_other IN barcode_status.on_other %]
486                                     <li><input type="checkbox" name="move_item" value="[% item_on_other.itemnumber | html %]"> [% item_on_other.biblio.title | html %] (Currently on &quot;[% item_on_other.stockrotationitem.stage.rota.title | html %]&quot;)</li>
487                                 [% END %]
488
489                             </fieldset>
490                             <fieldset class="action">
491                                 <input type="submit" value="Save">
492                             </fieldset>
493                             <input type="hidden" name="rota_id" value="[% rota_id | html %]">
494                             <input type="hidden" name="op" value="move_items_to_rota">
495                         </form>
496                     [% END %]
497                     <p><a href="?op=manage_items&amp;rota_id=[% rota_id | uri %]">Return to rota</a></p>
498
499                 [% END %]
500             </div>
501
502             </main>
503         </div> <!-- /.col-sm-10.col-sm-push-2 -->
504
505         <div class="col-sm-2 col-sm-pull-10">
506             <aside>
507                 [% INCLUDE 'tools-menu.inc' %]
508             </aside>
509         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
510     </div> <!-- /.row -->
511
512 [% MACRO jsinclude BLOCK %]
513     [% Asset.js("js/tools-menu.js") | $raw %]
514     [% INCLUDE 'datatables.inc' %]
515     [% INCLUDE 'columns_settings.inc' %]
516     [% Asset.js("js/pages/stockrotation.js") | $raw %]
517     <script>
518         var stock_rotation_items_columns_settings = [% ColumnsSettings.GetColumns( 'tools', 'stockrotation', 'stock_rotation_manage_items', 'json' ) | $raw %];
519         var stock_rotation_columns_settings = [% ColumnsSettings.GetColumns( 'tools', 'stockrotation', 'stock_rotation', 'json' ) | $raw %];
520     </script>
521 [% END %]
522
523 [% INCLUDE 'intranet-bottom.inc' %]