Bug 34478: Manual fix - duplicate_orders (cud-select)
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / acqui / duplicate_orders.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE KohaDates %]
5 [% SET footerjs = 1 %]
6 [% PROCESS 'i18n.inc' %]
7 [% INCLUDE 'doc-head-open.inc' %]
8 <title>[% FILTER collapse %]
9     [% UNLESS blocking_error %]
10         [% tx("Basket {basketnumber}", { basketnumber = basket.basketno }) | html %] &rsaquo;
11         [% t("Duplicate existing orders") | html %] &rsaquo;
12     [% END %]
13     [% t("Acquisitions") | html %] &rsaquo;
14     [% t("Koha") | html %]
15 [% END %]</title>
16 [% INCLUDE 'doc-head-close.inc' %]
17 <style>
18     .picked_to_duplicate > td { background-color: #bcdb89 !important; }
19     span.hint { margin-left: 1em; }
20 </style>
21 </head>
22
23 <body id="acq_duplicate_orders" class="acq">
24
25 [% WRAPPER 'header.inc' %]
26     [% INCLUDE 'acquisitions-search.inc' %]
27 [% END %]
28
29 [% WRAPPER 'sub-header.inc' %]
30     [% WRAPPER breadcrumbs %]
31         [% WRAPPER breadcrumb_item %]
32             <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a>
33         [% END %]
34         [% UNLESS blocking_error %]
35             [% WRAPPER breadcrumb_item %]
36                 <a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% vendor.id | uri %]">[% vendor.name | html %]</a>
37             [% END %]
38             [% WRAPPER breadcrumb_item %]
39                 <a href="/cgi-bin/koha/acqui/basket.pl?basketno=[% basket.basketno | uri %]">Basket [% basket.basketno | html %]</a>
40             [% END %]
41             [% WRAPPER breadcrumb_item bc_active= 1 %]
42                 <span>Duplicate existing orders</span>
43             [% END %]
44         [% END # /UNLESS blocking_error %]
45     [% END #/ WRAPPER breadcrumbs %]
46 [% END #/ WRAPPER sub-header.inc %]
47
48 <div class="main container-fluid">
49     <div class="row">
50         <div class="col-sm-10 col-sm-push-2">
51             <main>
52                 [% INCLUDE 'messages.inc' %]
53
54 <h1>Duplicate existing orders</h1>
55
56 [% IF op == 'search' || op == 'select' %]
57 <form action="/cgi-bin/koha/acqui/duplicate_orders.pl" method="get">
58     <fieldset class="rows">
59         <legend>
60             [% IF op == 'search' %]
61                 <span>Search orders</span>
62             [% ELSE %]
63                 <span>Refine search</span>
64             [% END %]
65             <span class="toggle_orders_filters" id="show_orders_filters"><a href="#">[+]</a></span>
66             <span class="toggle_orders_filters" id="hide_orders_filters"><a href="#">[-]</a></span>
67         </legend>
68         <div id="orders_filters">
69             [% INCLUDE 'filter-orders.inc' %]
70             <input type="hidden" name="op" value="select" />
71             <input type="hidden" name="basketno" value="[% basket.basketno | html %]" />
72
73             <input type="hidden" name="ordernumbers" value="[% ordernumbers.join(',') | html %]" />
74         </div>
75     </fieldset>
76     <fieldset class="action"><input type="submit" class="btn btn-primary" value="Search" /></fieldset>
77 </form>
78 [% END %]
79
80 [% BLOCK display_order_line %]
81     [% IF selected %]
82     <tr class="picked_to_duplicate" data-ordernumber="[% order.ordernumber | html %]">
83     [% ELSE %]
84     <tr data-ordernumber="[% order.ordernumber | html %]">
85     [% END %]
86         <td>
87             [% IF can_check %]
88                 [% IF selected %]
89                     <input type="checkbox" name="ordernumber" value="[% order.ordernumber | html %]" checked="checked" />
90                 [% ELSE %]
91                     <input type="checkbox" name="ordernumber" value="[% order.ordernumber | html %]" />
92                 [% END %]
93             [% END %]
94             [% order.ordernumber | html %]
95             [% IF order.ordernumber != order.parent_ordernumber %]([% order.parent_ordernumber | html %])[% END %]
96         </td>
97         <td>
98             [% SWITCH order.orderstatus %]
99                 [% CASE 'new' %]<span>New</span>
100                 [% CASE 'ordered' %]<span>Ordered</span>
101                 [% CASE 'partial' %]<span>Partially received</span>
102                 [% CASE 'complete' %]<span>Received</span>
103                 [% CASE 'cancelled' %]<span>Cancelled</span>
104             [% END %]
105         </td>
106         <td>[% order.basketname | html %] (<a href="basket.pl?basketno=[% order.basketno | uri %]">[% order.basketno | html %]</a>)</td>
107         <td>[% order.authorisedbyname | html %]</td>
108         <td>
109             [% IF ( order.basketgroupid ) %]
110                 [% order.groupname | html %] (<a href="basketgroup.pl?op=add&booksellerid=[% order.id | uri %]&basketgroupid=[% order.basketgroupid | uri %]">[% order.basketgroupid | html %]</a>)
111             [% ELSE %]
112                 &nbsp;
113             [% END %]
114         </td>
115         <td>[% IF ( order.invoicenumber ) %]
116                 <a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% order.invoiceid | uri %]">[% order.invoicenumber | html %]</a>
117             [% ELSE %]
118                 &nbsp;
119             [% END %]
120         </td>
121         <td>
122             <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% order.biblionumber | uri %]">[% order.title |html %]</a>
123             <br />[% order.author | html %] <br /> [% order.isbn | html %]
124         </td>
125         <td><a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% order.id | uri %]">[% order.name | html %]</a></td>
126         <td data-order="[% order.creationdate | html %]">[% order.creationdate | $KohaDates %]</td>
127         <td data-order="[% order.datereceived | html %]">
128             [% order.datereceived | $KohaDates %]
129         </td>
130         <td>[% order.quantityreceived | html %]</td>
131         <td>[% order.quantity | html %]</td>
132         <td>[% order.ecost | html %]</td>
133         <td>[% order.budget_name | html %]</td>
134     </tr>
135 [% END %]
136
137
138 [% IF op == 'select' && ( result_order_loop || selected_order_loop ) %]
139 <form method="post" action="/cgi-bin/koha/acqui/duplicate_orders.pl">
140     [% INCLUDE 'csrf-token.inc' %]
141     <div id="orders_to_copy" class="page-section">
142         <table id="table_orders">
143             <caption>
144                 <span class="actions"><a href="#" id="select_all"><i class="fa fa-check"></i> Select all</a>
145                 | <a href="#" id="clear_all"><i class="fa fa-times"></i> Clear all</a></span>
146             </caption>
147
148             <thead>
149                     <tr>
150                     <th>Order line (parent)</th>
151                     <th>Status</th>
152                     <th>Basket</th>
153                     <th>Basket creator</th>
154                     <th>Basket group</th>
155                     <th>Invoice number</th>
156                     <th class="anti-the">Summary</th>
157                     <th>Vendor</th>
158                     <th>Placed on</th>
159                     <th>Received on</th>
160                     <th>Quantity received</th>
161                     <th>Quantity ordered</th>
162                     <th>Unit cost</th>
163                     <th>Fund</th>
164                 </tr>
165             </thead>
166             <tfoot>
167             [% FOREACH order IN selected_order_loop %]
168                 [% INCLUDE display_order_line selected => 1 can_check => 1%]
169             [% END %]
170             </tfoot>
171             <tbody>
172             [% FOREACH order IN result_order_loop %]
173                 [% INCLUDE display_order_line can_check => 1 %]
174             [% END %]
175             </tbody>
176         </table>
177     </div>
178     <fieldset class="action">
179         <input type="hidden" name="op" value="cud-batch_edit" />
180         <input type="hidden" name="basketno" value="[% basket.basketno | html %]" />
181         <button type="submit" class="btn btn-primary go_to_batch_edit">Next <i class="fa fa-fw fa-arrow-right"></i></button>
182     </fieldset>
183 </form>
184
185 [% ELSIF op == "batch_edit" %]
186
187 <form method="post" action="/cgi-bin/koha/acqui/duplicate_orders.pl" id="batch_edit_form">
188     [% INCLUDE 'csrf-token.inc' %]
189     <div id="accounting_details">
190       <p>Duplicate all the orders with the following accounting details:</p>
191       <fieldset class="rows" style="float:none;">
192           <legend>Accounting details</legend>
193           <div class="hint" style="margin: 1em 1em 0">Check boxes to duplicate the original values</div>
194           <ol>
195               <li>
196                   <label for="all_currency">Currency:</label>
197                   <input type="checkbox" name="copy_existing_value" value="currency" title="Copy existing value" />
198                   <select name="all_currency" id="all_currency">
199                   [% FOREACH currency IN currencies %]
200                       [% IF currency.currency == vendor.listprice %]
201                           <option value="[% currency.currency | html %]" selected="selected">[% currency.currency | html %]</option>
202                       [% ELSIF not currency.archived %]
203                           <option value="[% currency.currency | html %]">[% currency.currency | html %]</option>
204                       [% END %]
205                   [% END %]
206                   </select>
207                   <span class="hint" id="hint_currency">The original currency value will be copied</span>
208               </li>
209               <li>
210                   <label for="all_budget_id">Fund: </label>
211                   <input type="checkbox" name="copy_existing_value" value="budget_id" title="Copy existing value" />
212                   <select id="all_budget_id" name="all_budget_id">
213                     <option value="">Select a fund</option>
214                   [% FOREACH budget_loo IN budget_loop %]
215                       [% IF ( budget_loo.b_active ) %]<option value="[% budget_loo.b_id | html %]" data-sort1-authcat="[% budget_loo.b_sort1_authcat | html %]" data-sort2-authcat="[% budget_loo.b_sort2_authcat | html %]">[% budget_loo.b_txt | html %]</option>
216                       [% ELSE %]<option value="[% budget_loo.b_id | html %]" class="b_inactive" data-sort1-authcat="[% budget_loo.b_sort1_authcat | html %]" data-sort2-authcat="[% budget_loo.b_sort2_authcat | html %]">[% budget_loo.b_txt | html %] (inactive)</option>
217                       [% END %]
218                   [% END %]
219                   </select>
220                   <label for="all_showallbudgets" style="float:none;width:auto;margin-right:0;">&nbsp;Show inactive:</label>
221                   <input type="checkbox" id="all_showallbudgets" />
222                   <span class="hint" id="hint_budget_id">The original fund will be used</span>
223               </li>
224               <li>
225                   <label for="all_order_internalnote">Internal note: </label>
226                   <input type="checkbox" name="copy_existing_value" value="order_internalnote" title="Copy existing value" />
227                   <textarea id="all_order_internalnote" cols="30" rows="3" name="all_order_internalnote"></textarea>
228                   <span class="hint" id="hint_order_internalnote">The original internal note will be used</span>
229               </li>
230               <li>
231                   <label for="all_order_vendornote">Vendor note: </label>
232                   <input type="checkbox" name="copy_existing_value" value="order_vendornote" title="Copy existing value" />
233                   <textarea id="all_order_vendornote" cols="30" rows="3" name="all_order_vendornote"></textarea>
234                   <span class="hint" id="hint_order_vendornote">The original vendor note will be used</span>
235               </li>
236               <li>
237                   <div class="hint">The 2 following fields are available for your own usage. They can be useful for statistical purposes</div>
238                   <label for="all_sort1">Statistic 1: </label>
239                   <input type="checkbox" name="copy_existing_value" value="sort1" title="Copy existing value" />
240                   <input type="text" id="all_sort1" size="20" name="all_sort1" value="" />
241                   <span class="hint" id="hint_sort1">The original statistic 1 will be used</span>
242
243               </li>
244               <li>
245                   <label for="all_sort2">Statistic 2: </label>
246                   <input type="checkbox" name="copy_existing_value" value="sort2" title="Copy existing value" />
247                   <input type="text" id="all_sort2" size="20" name="all_sort2" value="" />
248                   <span class="hint" id="hint_sort2">The original statistic 2 will be used</span>
249               </li>
250           </ol>
251       </fieldset>
252     </div>
253
254     <fieldset class="action">
255         [% FOREACH ordernumber IN ordernumbers %]
256             <input type="hidden" name="ordernumber" value="[% ordernumber | html %]" />
257         [% END %]
258         <input type="hidden" name="op" value="cud-do_duplicate" />
259         <input type="hidden" name="basketno" value="[% basket.basketno | html %]" />
260         <!-- origquantityrec only here for javascript compatibility (additem.js needs it, useless here, useful when receiveing an order -->
261         <input id="origquantityrec" readonly="readonly" type="hidden" name="origquantityrec" value="1" />
262         <button type="submit" class="btn btn-primary">Duplicate orders</button>
263         <a class="cancel" href="/cgi-bin/koha/acqui/duplicate_orders.pl?basketno=[% basket.basketno | html %]">Cancel</a>
264     </fieldset>
265 </form>
266
267 [% ELSIF op == 'duplication_done' %]
268     [% IF new_orders %]
269         <div class="page-section">
270             <table id="table_neworders">
271                 <thead>
272                     <tr>
273                         <th>Order line</th>
274                         <th>Status</th>
275                         <th>Basket</th>
276                         <th>Basket creator</th>
277                         <th>Basket group</th>
278                         <th>Invoice number</th>
279                         <th class="anti-the">Summary</th>
280                         <th>Vendor</th>
281                         <th>Placed on</th>
282                         <th>Received on</th>
283                         <th>Quantity received</th>
284                         <th>Quantity ordered</th>
285                         <th>Unit cost</th>
286                         <th>Fund</th>
287                     </tr>
288                 </thead>
289                 <tbody>
290                 [% FOREACH order IN new_orders %]
291                     [% INCLUDE display_order_line %]
292                 [% END %]
293                 </tbody>
294             </table>
295         </div>
296         <a class="btn btn-default" href="/cgi-bin/koha/acqui/basket.pl?basketno=[% basket.basketno | html %]"><i class="fa fa-fw fa-arrow-left"></i> Return to the basket</a
297     [% ELSE %]
298         <span>No order has been duplicated. Maybe something wrong happened?</span>
299     [% END %]
300 [% END %]
301
302 </main>
303 </div> <!-- /.col-sm-10.col-sm-push-2 -->
304
305 <div class="col-sm-2 col-sm-pull-10">
306     <aside>
307         [% INCLUDE 'acquisitions-menu.inc' %]
308     </aside>
309 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
310 </div>
311
312 [% MACRO jsinclude BLOCK %]
313     [% Asset.js("js/acquisitions-menu.js") | $raw %]
314     [% INCLUDE 'calendar.inc' %]
315     [% INCLUDE 'datatables.inc' %]
316     [% INCLUDE 'columns_settings.inc' %]
317     [% Asset.js("js/acq.js") | $raw %]
318     [% Asset.js("js/funds_sorts.js") | $raw %]
319     <script>
320         function update_ordernumber_list(){
321             var ordernumbers = [];
322             $("input[name='ordernumber']").filter(":checked").each(function(){
323                 ordernumbers.push($(this).val());
324             });
325             $("input[name='ordernumbers']").val(ordernumbers.join(','));
326         }
327
328         var MSG_REMOVE_PATRON = _("Remove");
329         var MSG_NO_ITEM_SELECTED = _("Nothing is selected.");
330         var MSG_NO_FUND_SELECTED = _("No fund selected.");
331         $(document).ready(function() {
332             $('span.hint').hide();
333             KohaTable("table_orders", {
334                 "paginate": false
335             });
336
337             [% IF op == 'search' OR op == 'select' %]
338                 function AddPatron( patron_name, value, container, input_name ) {
339                     div = "<div id='borrower_" + value + "'>" + patron_name + " ( <a href='#' class='removePatron'><i class='fa fa-trash-can' aria-hidden='true'></i> " + MSG_REMOVE_PATRON + " </a> ) <input type='hidden' name='" + input_name + "' value='" + value + "' /></div>";
340                     $(container).append( div );
341
342                     $(container).parent().show( 800 );
343                 }
344                 function RemovePatron( cardnumber, container ) {
345                     $( '#borrower_' + cardnumber ).remove();
346
347                     if ( ! $(container).html() ) {
348                         $(container).parent("fieldset").hide( 800 );
349                     }
350                 }
351                 patron_autocomplete($("#find_patron"), {
352                     'on-select-callback': function( event, ui ) {
353                         var field = ui.item.borrowernumber;
354                         AddPatron( ui.item.firstname + " " + ( ui.item.middle_name || "" ) + " " + ui.item.surname, field, $("#basket_creators"), 'created_by' );
355                         $("#find_patron").val('').focus();
356                         return false;
357                     }
358                 });
359                 $("body").on("click",".removePatron",function(e){
360                     e.preventDefault();
361                     var divid = $(this).parent().attr("id");
362                     var cardnumber = divid.replace("borrower_","");
363                     RemovePatron(cardnumber, $("#basket_creators"));
364                 });
365
366             [% END %]
367
368             $("#show_orders_filters, #hide_orders_filters").on('click', function(e) {
369                 e.preventDefault();
370                 $('#orders_filters').toggle();
371                 $('.toggle_orders_filters').toggle();
372             });
373             [% IF op == 'search' OR op == 'select' AND NOT result_order_loop %]
374                 $("#show_orders_filters").hide();
375                 $("#orders_filters").show();
376             [% ELSE %]
377                 $("#hide_orders_filters").hide();
378                 $("#orders_filters").hide();
379             [% END %]
380
381             $("input[name='ordernumber']").on("change", function(){
382                 if ( $(this).is(':checked') ) {
383                     $(this).parents("tr").addClass("picked_to_duplicate");
384                 } else {
385                     $(this).parents("tr").removeClass("picked_to_duplicate");
386                 }
387             }).on("click", function(e){
388                 update_ordernumber_list();
389             });
390
391             $("#select_all").on("click",function(e){
392                 e.preventDefault();
393                 selectAll();
394                 update_ordernumber_list();
395             });
396
397             $("#clear_all").on("click",function(e){
398                 e.preventDefault();
399                 clearAll();
400                 update_ordernumber_list();
401             });
402             function selectAll () {
403                 $("#table_orders").find("input[type='checkbox'][name='ordernumber']").each(function(){
404                     $(this).prop("checked", true).change();
405                 });
406                 return false;
407             }
408             function clearAll () {
409                 $("#table_orders").find("input[type='checkbox'][name='ordernumber']").each(function(){
410                     $(this).prop("checked", false).change();
411                 });
412                 return false;
413             }
414
415             $(".go_to_batch_edit").on("click",function(e){
416                 if ($("input[name='ordernumber']").filter(":checked").length == 0){
417                     alert(MSG_NO_ITEM_SELECTED);
418                     e.preventDefault();
419                 }
420             });
421
422             $("#batch_edit_form").on("submit", function(e){
423                 var budget_value_will_be_reused = $("input[name='copy_existing_value'][value='budget_id']").is(':checked');
424                 if ( ! budget_value_will_be_reused ) {
425                     if ($("#all_budget_id").find("option:selected").val() == "" ) {
426                         alert(MSG_NO_FUND_SELECTED);
427                         e.preventDefault();
428                     }
429                 }
430             });
431             $("input[name='copy_existing_value']").click(function(){
432                 render_disabled(this);
433             });
434
435             $("input[name='copy_existing_value']").each(function(){
436                 render_disabled(this);
437             });
438         });
439         function render_disabled (elt) {
440             var field = $(elt).val();
441             var hint_node = $("#hint_" + field);
442             var input_element = $(elt).parent().find("[name='all_"+field+"']");
443             if ($(elt).is(":checked")) {
444                 $(input_element).prop('disabled', true);
445                 $(hint_node).show();
446             } else {
447                 $(input_element).prop('disabled', false);
448                 $(hint_node).hide();
449             }
450         }
451     </script>
452 [% END %]
453
454 [% INCLUDE 'intranet-bottom.inc' %]