Bug 33908: Improve translation of title tags: Acquisitions
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / acqui / orderreceive.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE KohaDates %]
5 [% USE Branches %]
6 [% USE AuthorisedValues %]
7 [% USE ItemTypes %]
8 [% USE Price %]
9 [% SET footerjs = 1 %]
10 [% PROCESS 'i18n.inc' %]
11 [% INCLUDE 'doc-head-open.inc' %]
12 <title>[% FILTER collapse %]
13     [% IF ( invoice ) %]
14         [% tx("Receipt summary for {vendor}, invoice {invoice_number}", { vendor = name, invoice_number = invoice }) | html %]
15     [% ELSE %]
16         [% tx("Receipt summary for {vendor}", { vendor = name }) | html %]
17     [% END %] &rsaquo;
18     [% t("Acquisitions") | html %] &rsaquo;
19     [% t("Koha") | html %]
20 [% END %]</title>
21 [% INCLUDE 'doc-head-close.inc' %]
22     <style>
23         @media (min-width: 1200px) {
24             #receive-modal, #receive-modal {
25                 width: 98%;
26             }
27         }
28         #receive-modal .modal-body {
29             background-color: #F3F4F4;
30         }
31
32         .lbl {
33             font-weight: 700;
34             text-align: right;
35         }
36         .modal-body ol {
37             list-style-type: none;
38         }
39
40         .modal-body ol li {
41             list-style-type: none;
42             padding-bottom: 1em;
43             width: 100%;
44         }
45
46         .modal-body h4 {
47             margin-left: 1em;
48             padding: .2em .5em;
49             margin-bottom: 17px;
50         }
51
52         .modal-body label {
53             margin-right: 1em;
54             text-align: right;
55             width: 11em;
56             display: inline-block;
57             font-weight: 700;
58         }
59
60         .modal-body textarea {
61             vertical-align: text-top;
62         }
63
64         .modal-header {
65             display: flex;
66             justify-content: space-between;
67         }
68
69         .modal-header::before,
70         .modal-header::after {
71             content: none;
72         }
73
74     </style>
75 </head>
76
77 <body id="acq_orderreceive" class="acq">
78 [% WRAPPER 'header.inc' %]
79     [% INCLUDE 'acquisitions-search.inc' %]
80 [% END %]
81
82 [% WRAPPER 'sub-header.inc' %]
83     [% WRAPPER breadcrumbs %]
84         [% WRAPPER breadcrumb_item %]
85             <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a>
86         [% END %]
87         [% WRAPPER breadcrumb_item %]
88             <a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% vendor.id | uri %]">[% name | html %]</a>
89         [% END %]
90         [% WRAPPER breadcrumb_item bc_active= 1 %]
91             [% IF ( invoice ) %]
92                 <span>Receive items from: [% name | html %] [[% invoice | html %]] (order #[% multiple_orders | html %])</span>
93             [% ELSE %]
94                 <span>Receive items from: [% name | html %] (order #[% multiple_orders | html %])</span>
95             [% END %]
96         [% END %]
97     [% END #/ WRAPPER breadcrumbs %]
98 [% END #/ WRAPPER sub-header.inc %]
99
100 <div class="main container-fluid">
101     <div class="row">
102         <div class="col-sm-10 col-sm-push-2">
103             <main>
104
105 <h1>Receive items from : [% name | html %] [% IF ( invoice ) %][[% invoice | html %]] [% END %] (order #[% multiple_orders | html %])</h1>
106 [% SET only_one_order = ( multiple_orders.split(',').size == 1 ) %]
107 [% IF multiple_orders %]
108     <table id="multiple_orders" class="table table-bordered table-striped">
109         <thead>
110             <tr>
111                 <th>Order</th>
112                 <th>Title</th>
113                 <th>Author</th>
114                 <th>ISBN</th>
115                 <th>Date received</th>
116                 <th>Fund</th>
117                 <th>Quantity</th>
118                 <th>&nbsp;</th>
119             </tr>
120         </thead>
121     </table>
122
123     <div class="col">
124         <fieldset class="action">
125             <button class="save btn btn-primary" disabled>Confirm</button>
126             <a class="cancel btn btn-default" href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid | html %]&sticky_filters=1">Cancel</a>
127         </fieldset>
128         <div id="jobpanel">
129             <div id="jobstatus" class="progress_panel">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
130         </div>
131     </div>
132
133     <div class="modal fade" id="order_edit" tabindex="-1" role="dialog" aria-labelledby="Order edit">
134         <div id="receive-modal" class="modal-dialog modal-lg" role="document">
135             <div class="modal-content">
136                 <div class="modal-header">
137                     <h4 class="col-md-10 modal-title"></h4>
138                     <button type="button" class="close col-md-1" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
139                 </div>
140                 <div class="modal-body">
141                     <div class="hide" id="loading">Loading ...</div>
142                     <div id="modal-order-main" class="row">
143                         <!--ul>
144                             <li><a href="#info-panel">Info</a></li>
145                             <li><a href="#accounting-panel">Accounting</a></li>
146                             <li><a href="#history-panel">Receipt history</a></li>
147                             <li><a href="#items-panel">Items</a></li>
148                         </ul-->
149
150                         <div class="col-md-12 col-lg-6">
151                             <div id="info-panel" class="page-section">
152                                 <div>
153                                     <h4>Catalog details</h4>
154
155                                     <div class="row"> <span class="lbl col-sm-4">Title: </span><span class="col-sm-8" id="biblio_title"></span></div>
156                                     <div class="row"> <span class="lbl col-sm-4">Author: </span><span class="col-sm-8" id="biblio_author"></span></div>
157                                     <div class="row"> <span class="lbl col-sm-4">Copyright: </span><span class="col-sm-8" id="biblio_copyright_date"></span></div>
158                                     <div class="row"> <span class="lbl col-sm-4">ISBN: </span><span class="col-sm-8" id="biblio_isbn"></span></div>
159                                     <div class="row"> <span class="lbl col-sm-4">Series: </span><span class="col-sm-8" id="biblio_series_title"></span></div>
160
161                                 </div>
162                                 <div id="suggestion_fieldset">
163                                     <h4>Suggestion</h4>
164                                     <div class="row">
165                                         <span class="lbl col-sm-4">Suggested by: </span> <span class="col-sm-8" id="biblio_suggestion_suggester"></span>
166                                     </div>
167                                     <div class="row" id="suggestion_reason">
168                                         <span class="lbl col-sm-4">Reason:</span>
169                                         <div class="col-sm-8">
170                                             [% SET suggestion_reasons = AuthorisedValues.GetAuthValueDropbox( 'SUGGEST' ) %]
171                                             <select class="select-reason" id="reason" name="reason">
172                                                 <option value=""> -- Choose a reason -- </option>
173                                                 [% FOREACH reason IN suggestion_reasons %]
174                                                 <option value="[% reason.lib | html %]">[% reason.lib | html %]</option>
175                                                 [% END %]
176                                                 <option value="other">Others...</option>
177                                             </select>
178
179                                             <span id="other_reason" name="other_reason">
180                                                 <input type="text" size="31" id="select-other_reason" name="other_reason" placeholder="please note your reason here..." />
181                                                 <a href="#back">Cancel</a>
182                                             </span>
183                                         </div>
184                                     </div>
185                                 </div>
186                             </div>
187                             <div id="history-panel" class="page-section">
188                                 <div id="child_orders">
189                                     <h4>Receipt history for this subscription</h4>
190                                     <table id="child_orders_table">
191                                         <thead>
192                                             <tr>
193                                                 <th>Invoice</th>
194                                                 <th>Order number</th>
195                                                 <th>Creation date</th>
196                                                 <th>Receive date</th>
197                                                 <th>Quantity received</th>
198                                                 <th>Status</th>
199                                                 <th title="Actual cost tax exc. / Actual cost tax inc.">Spent</th>
200                                                 <th>Internal note</th>
201                                             </tr>
202                                         </thead>
203                                     </table>
204                                 </div>
205                             </div>
206                             <div id="items-panel" class="page-section">
207                                 <div id="acq-create-receiving">
208                                     <div id="items_list" style="display: none">
209                                         <h4>Items list</h4>
210                                         <div style="width:100%;overflow:auto;">
211                                             <table>
212                                                 <thead>
213                                                     <tr>
214                                                         <th>Actions</th>
215                                                         <th>Barcode</th>
216                                                         <th>Home library</th>
217                                                         <th>Holding library</th>
218                                                         <th>Not for loan</th>
219                                                         <th>Restricted</th>
220                                                         <th>Location</th>
221                                                         <th>Call number</th>
222                                                         <th>Copy number</th>
223                                                         <th>Inventory number</th>
224                                                         <th>Collection</th>
225                                                         <th>Item type</th>
226                                                         <th>Materials</th>
227                                                         <th>Notes</th>
228                                                     </tr>
229                                                 </thead>
230                                                 <tbody>
231                                                 </tbody>
232                                             </table>
233                                         </div>
234                                     </div>
235
236                                     <div id="itemfieldset">
237                                         <h4>Item</h4>
238                                         [% IF ( NoACQframework ) %]
239                                             <p class="required">
240                                                 No ACQ framework, using default. You should create a
241                                                 framework with code ACQ, the items framework would be
242                                                 used
243                                             </p>
244                                         [% END %]
245                                         <div id="outeritemblock"></div>
246                                     </div>
247                                 </div>
248                                 <div id="acq-create-ordering">
249                                     <h4>Items</h4>
250                                     <div style="width:100%;overflow:auto">
251                                         <table>
252                                             <thead>
253                                                 <tr>
254                                                     <th>Receive?</th>
255                                                     <th>&nbsp;</th>
256                                                     <th>Barcode</th>
257                                                     <th>Home library</th>
258                                                     <th>Current library</th>
259                                                     <th>Not for loan</th>
260                                                     <th>Restricted</th>
261                                                     <th>Location</th>
262                                                     <th>Call number</th>
263                                                     <th>Copy number</th>
264                                                     <th>Inventory number</th>
265                                                     <th>Collection</th>
266                                                     <th>Item type</th>
267                                                     <th>Materials</th>
268                                                     <th>Notes</th>
269                                                 </tr>
270                                             </thead>
271                                             <tbody>
272                                             </tbody>
273                                         </table>
274                                     </div>
275                                 </div>
276                             </div>
277                         </div>
278                         <div class="col-md-12 col-lg-6">
279                             <div id="accounting-panel" class="page-section">
280                                 <h4>Accounting details</h4>
281                                 <form action="/cgi-bin/koha/acqui/orderreceive.pl" class="validated">
282                                     <ol>
283                                         <li>
284                                             <label for="datereceived">Date received: </label>
285                                             <input type="text" size="10" id="datereceived" name="datereceived" class="flatpickr" />
286                                         </li>
287                                         <li>
288                                             <label for="bookfund" class="required">Fund: </label>
289                                             <select id="bookfund" name="bookfund">
290                                                 <optgroup label="Current">
291                                                     <option id="selected_bookfund" selected="selected"></option>
292                                                 </optgroup>
293                                             [% FOREACH budget_period_id IN budget_loops.keys %]
294                                                 [% SET budget_period = budget_loops.$budget_period_id %]
295                                                 [% IF budget_period.active %]
296                                                     <optgroup label="[% budget_period.description | html %]">
297                                                 [% ELSE %]
298                                                     <optgroup class="inactive_budget" label="[% budget_period.description | html %] (Inactive)">
299                                                 [% END %]
300                                                 [% FOREACH budget_loo IN budget_period.funds %]
301                                                 [% level_indent_cnt = 0 %]
302                                                     [% level_indent = "" %]
303                                                     [% WHILE level_indent_cnt < budget_loo.b_level %]
304                                                         [% level_indent = level_indent _ " -- " %]
305                                                         [% level_indent_cnt = level_indent_cnt +1 %]
306                                                     [% END %]
307
308                                                     [% IF ( budget_loo.b_sel ) %]
309                                                         [% active_count = 0 #select no other fund %]
310                                                         <option value="[% budget_loo.b_id | html %]" selected="selected" data-sort1-authcat="[% budget_loo.b_sort1_authcat | html %]" data-sort2-authcat="[% budget_loo.b_sort2_authcat | html %]">
311                                                     [% ELSIF active_count==1 && budget_loo.b_active %]
312                                                         <option value="[% budget_loo.b_id | html %]" selected="selected" data-sort1-authcat="[% budget_loo.b_sort1_authcat | html %]" data-sort2-authcat="[% budget_loo.b_sort2_authcat | html %]">
313                                                     [% ELSE %]
314                                                         [% bdgclass=budget_loo.b_active? "": "inactive_budget" | html %]
315                                                         <option value="[% budget_loo.b_id | html %]" class="[% bdgclass | html %]" data-sort1-authcat="[% budget_loo.b_sort1_authcat | html %]" data-sort2-authcat="[% budget_loo.b_sort2_authcat | html %]">
316                                                     [% END %]
317                                                         [% level_indent | html %][% budget_loo.b_txt | html %][% IF !budget_loo.b_active %] (inactive)[% END %]
318                                                     </option>
319                                                 [% END %]
320                                                 </optgroup>
321                                             [% END %]
322                                             </select>
323                                             <span class="required">Required</span>
324                                         </li>
325                                         <li>
326                                             <label>&nbsp;</label>
327                                             <span id="current-fund" class="hint"></span>
328                                         </li>
329                                         <li>
330                                             <label for="showallbudgets">&nbsp;Show inactive:</label>
331                                             <input type="checkbox" id="showallbudgets" />
332                                         </li>
333                                         <li>
334                                             <label for="creator">Ordered by: </label>
335                                             <span id="creator"></span>
336                                         </li>
337                                         <li>
338                                             <label for="quantity_to_receive">Quantity ordered: </label>
339                                             <input type="text" readonly="readonly" id="quantity_to_receive" name="quantity" />
340                                         </li>
341                                         <li>
342                                             <label for="quantity">Quantity received: </label>
343                                             <input type="text" inputmode="numeric" pattern="[0-9]*" size="20" name="quantityrec" id="quantity" />
344                                             <div id="qtyrecerror" style="display:none">
345                                                 <p class="error">Warning, you have entered more items than expected.
346                                                 Items will not be created.</p>
347                                             </div>
348                                         </li>
349
350                                         [% IF ( gst_values ) %]
351                                         <li>
352                                             <label for="tax_rate">Tax rate: </label>
353                                             <select name="tax_rate" id="tax_rate">
354                                             [% FOREACH gst IN gst_values %]
355                                                 <option value="[% gst.option | html %]">[% gst.option * 100 | html %]%</option>
356                                             [% END %]
357                                             </select>
358                                         </li>
359                                         [% END %]
360
361                                         <li>
362                                             <label for="rrp">Retail price: </label>
363                                             <span id="rrp"></span>
364                                         <li>
365                                             <label for="replacementprice">Replacement price:</label>
366                                             <input class="decimal" type="text" size="20" name="replacementprice" id="replacementprice" />
367                                         </li>
368                                         <li>
369                                             <label for="ecost">Budgeted cost: </label>
370                                             <span id="ecost"></span>
371                                         </li>
372                                         <li>
373                                             <label for="unitprice">Actual cost:</label>
374                                             <input class="decimal" type="text" size="20" name="unitprice" id="unitprice" />
375                                             <span id="unitprice_hint" class="hint"></span>
376                                         </li>
377                                         <li>
378                                             <label style="margin-left: 12em; text-align: left; font-weight: inherit; float:none;"><input type="checkbox" id="change_currency" name="change_currency">Change currency</label>
379                                         </li>
380                                         <li id="select_currency">
381                                             <label for="invoice_unitprice"></label>
382                                             <input class="decimal" type="text" size="20" name="invoice_unitprice" id="invoice_unitprice" value="" />
383                                             [% IF currencies.count %]
384                                             <select name="invoice_currency" id="invoice_currency">
385                                                 <option value="[% active_currency.currency | html %]" data-rate="[% active_currency.rate | html %]" selected>[% active_currency.currency | html %] ([% active_currency.symbol | html %])</option>
386                                                 [% FOR currency IN currencies %]
387                                                 <option value="[% currency.currency | html %]" data-rate="[% currency.rate | html %]">[% currency.currency | html %] ([% currency.symbol | html %])</option>
388                                                 [% END %]
389                                             </select>
390                                             [% END %]
391                                         </li>
392                                         <li>
393                                             <label for="order_internalnote">Internal note: </label>
394                                             <textarea name="order_internalnote" id="order_internalnote" width="40" rows="8" ></textarea>
395                                         </li>
396                                         <li>
397                                             <label for="order_vendornote">Vendor note: </label>
398                                             <span id="order_vendornote"></span>
399                                         </li>
400                                     </ol>
401                                 </form>
402                             </div>
403                         </div>
404                     </div>
405                 </div>
406                 <div class="modal-footer">
407                 [% IF only_one_order %]
408                     <button type="button" class="btn btn-primary modal-save" disabled>Confirm</button>
409                     <a class="cancel btn btn-default" href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid | html %]&sticky_filters=1">Cancel</a>
410                 [% ELSE %]
411                     <button type="button" class="btn btn-default modal-prev">Previous order</button>
412                     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
413                     <button type="button" class="btn btn-primary modal-save">Save changes</button>
414                     <button type="button" class="btn btn-default modal-next">Next order</button>
415                 [% END %]
416                 </div>
417             </div>
418         </div>
419     </div>
420     <div class="modal fade" id="modal_messages" tabindex="-1" role="dialog" aria-labelledby="Order edit">
421         <div class="modal-dialog" role="document">
422             <div class="modal-content">
423                 <div class="modal-header">
424                     <h4 class="col-md-11 modal-title"></h4>
425                     <button type="button" class="close col-md-1" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
426                 </div>
427                 <div class="modal-body">
428                     <ul></ul>
429                 </div>
430                 <div class="modal-footer">
431                     <button type="button" class="btn btn-primary accept">Accept</button>
432                     <button type="button" class="btn btn-default cancel">Cancel</button>
433                 </div>
434             </div>
435         </div>
436     </div>
437 [% ELSE %]
438     This ordernumber does not exist.
439 [% END %]
440
441 </main>
442 </div> <!-- /.col-sm-10.col-sm-push-2 -->
443
444 <div class="col-sm-2 col-sm-pull-10">
445     <aside>
446         [% INCLUDE 'acquisitions-menu.inc' %]
447     </aside>
448 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
449 </div> <!-- /.row -->
450 [% MACRO jsinclude BLOCK %]
451     [% Asset.js("js/acquisitions-menu.js") | $raw %]
452     [% INCLUDE 'calendar.inc' %]
453     [% Asset.js("js/additem.js") | $raw %]
454     [% Asset.js("js/cataloging.js") | $raw %]
455     [% INCLUDE 'select2.inc' %]
456     [% INCLUDE 'datatables.inc' %]
457     [% INCLUDE 'js-date-format.inc' %]
458     [% INCLUDE 'format_price.inc' %]
459     [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %]
460     <script>
461         function display_string(key, strings, fallback) {
462             if ( strings.hasOwnProperty(key) ) {
463                 return strings[key].str && escape_str(strings[key].str) || '';
464             }
465             return fallback != null ? fallback : '';
466         }
467
468         var _build_item = function(item, tr) {
469             var chb = $('<input type="checkbox" name="items_to_receive" value="'+item.item_id+'" />')
470                 .prop('checked', item._checked)
471                 .change(function() {
472                     item._checked = $(this).prop('checked');
473                 });
474             tr.append($('<td style="text-align:center"></td>').append(chb));
475             tr.append('<td><a style="cursor:pointer" onclick="PopupEditPage('+item.biblio_id+', '+item.item_id+');">'+EDIT[0].toUpperCase()+EDIT.substr(1).toLowerCase()+'</a></td>');
476             tr.append('<td>'+(item.external_id||'')+'</td>');
477             tr.append('<td>'+display_string( 'home_library_id', item._strings, item.home_library_id ) || ''+'</td>');
478             tr.append('<td>'+display_string( 'holding_library_id', item._strings, item.holding_library_id )+'</td>');
479             tr.append('<td>'+display_string( 'not_for_loan_status', item._strings, item.not_for_loan_status )+'</td>');
480             tr.append('<td>'+display_string( 'restricted_status', item._strings, item.restricted_status )+'</td>');
481             tr.append('<td><span class="shelvingloc">'+display_string( 'location', item._strings, item.location )+'</span></td>');
482             tr.append('<td>'+(item.callnumber||'')+'</td>');
483             tr.append('<td>'+(item.copy_number||'')+'</td>');
484             tr.append('<td>'+(item.inventory_number||'')+'</td>');
485             tr.append('<td>'+display_string( 'collection', item._strings, item.collection )+'</td>');
486             tr.append('<td>'+display_string( 'item_type_id', item._strings, item.item_type_id )+'</td>');
487             tr.append('<td>'+display_string( 'materials_notes', item._strings, item.materials_notes )+'</td>');
488             tr.append('<td>'+(item.public_notes||'')+'</td>');
489         };
490
491         var items_columns = [null, null, 'external_id', 'home_library_id',
492                 'holding_library_id', 'not_for_loan_status', 'restricted_status', 'location',
493                 'callnumber', 'copy_number', 'inventory_number', 'collection_code',
494                 'item_type', 'materials_notes', 'public_notes'];
495
496         function PopupEditPage(biblionumber, itemnumber) {
497             var url = "/cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber="
498                 + biblionumber + "&itemnumber=" + itemnumber + "&popup=1#edititem";
499             var w = window.open(url);
500             var watchClose = setInterval(function() {
501                 if (w.closed) {
502                     clearTimeout(watchClose);
503                     $.ajax({
504                         dataType: "json",
505                         headers: {
506                             "x-koha-embed": "+strings"
507                         },
508                         url: '/api/v1/items/'+itemnumber,
509                         success: function(item) {
510                             var tr = $("#item_"+itemnumber);
511                             item._checked = $(tr).find('input[type="checkbox"]').prop('checked');
512                             tr.html('');
513                             _build_item(item, tr);
514                         }
515                     });
516                 }
517             }, 500);
518         }
519
520         var periods={};
521         var funds={};
522         var funds_tree = [];
523
524         var QTY_TOTAL = _("Receiving %0$s out of %1$s");
525         var EDIT = _("Edit");
526         var MOD_TITLE = _("Edit order #%s (%s)");
527         var SUGGESTION = _("suggestion #%s");
528         var FUND_KEEP = _("Keep current (%0$s - %1$s)");
529         var FUNC_CUR = _("(Current: %0$s - %1$s)");
530         var ADJ_TAX_INC = _("(adjusted for %s, tax inclusive)");
531         var ADJ_TAX_EXC = _("(adjusted for %s, tax exclusive)");
532         var TAX_INC = _("(tax inclusive)");
533         var TAX_EXC = _("(tax exclusive)");
534         var SAVE_WARNING = _("Order %s: Warning, you have entered more items than expected. Extra items will not be created.");
535         var SAVE_WARNING_NO_ITEMS = _("Order %s: No quantity to receive set. No items will be created.");
536         var SAVE_ERROR = _("Order %s: An error occurred while saving");
537         var SAVE_WARNING_TITLE = _("Warning");
538         var SAVE_ERROR_TITLE = _("Error");
539
540
541         var CAN_user_acquisition = "[% CAN_user_acquisition | html %]";
542         var AcqCreateItem = "[% Koha.Preference('AcqCreateItem') | html %]";
543         var edit_mode = "[% edit | html %]";
544         var invoiceincgst = "[% invoiceincgst | html %]";
545         var active_currency = "[% active_currency.currency | html %]";
546         var invoice_id = "[% invoiceid | html %]";
547
548         $(document).ready(function(){
549             // keep a copy for re-rendering
550             var $funds_tree = $('#bookfund').html();
551             var base_query = { "order_id": {"in": [[% multiple_orders | html %]]}};
552             var pending_orders_url = "/api/v1/acquisitions/orders?only_active=1";
553             var options = {
554                 "ajax": {
555                     "url": pending_orders_url + "&q=" + encodeURI(JSON.stringify(base_query))
556                 },
557                 "embed": [
558                     "basket",
559                     "biblio.suggestions.suggester",
560                     "fund.budget",
561                     "items+strings",
562                     "creator"
563                 ],
564                 'dom': 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
565                 "columns": [
566                     {
567                         "data": "order_id",
568                         "searchable": true,
569                         "orderable": true
570                     },
571                     {
572                         "data": "biblio.title",
573                         "searchable": true,
574                         "orderable": true,
575                         "render": function(data, type, row, meta) {
576                             if ( data == null ) {
577                                 return "";
578                             }
579                             else {
580                                 return data;
581                             }
582                         }
583                     },
584                     {
585                         "data": "biblio.author",
586                         "searchable": true,
587                         "orderable": true,
588                         "render": function(data, type, row, meta) {
589                             if ( data == null ) {
590                                 return "";
591                             }
592                             else {
593                                 return data;
594                             }
595                         }
596                     },
597                     {
598                         "data": "biblio.isbn",
599                         "searchable": true,
600                         "orderable": true,
601                         "render": function(data, type, row, meta) {
602                             if ( data == null ) {
603                                 return "";
604                             }
605                             else {
606                                 return data;
607                             }
608                         }
609                     },
610                     {
611                         "searchable": false,
612                         "orderable": false,
613                         "data": function(row, type, val, meta) {
614                             return $date(row.date_received||new Date().toISOString());
615                         }
616                     },
617                     {
618                         "data": "fund.name",
619                         "searchable": true,
620                         "orderable": false,
621                         "render": function(data, type, row, meta) {
622                             return row.fund.budget.budget_period_description+" - "+row.fund.name;
623                         }
624                     },
625                     {
626                         "searchable": false,
627                         "orderable": true,
628                         "data": "quantity_received",
629                         "render": function(data, type, row, meta) {
630                             var data = $("#order_edit").data();
631                             return QTY_TOTAL.format(row.subscription_id&&(!data.saved||!data.saved.hasOwnProperty(row.order_id))?row.quantity:row.quantity_received, row.quantity);
632                         }
633                     },
634                     {
635                         "searchable": false,
636                         "orderable": false,
637                         "render": function(data, type, row, meta) {
638                             return '<a class="btn btn-default btn-xs order_edit_toggle" data-toggle="modal" href="#order_edit" data-row="'+meta.row+'" role="button"><i class="fa fa-pencil" aria-hidden="true"></i> '+EDIT+'</a>';
639                         }
640                     }
641                 ],
642                 [% IF only_one_order %]
643                     "drawCallback": function( settings ) {
644                         $(this).find("tbody tr td:last-child a.order_edit_toggle").click();
645                     },
646                 [% END %]
647             };
648             var orders_table = $("#multiple_orders").kohaTable(options);
649             var api = orders_table.api();
650
651             api.on('preDraw', function() {
652                 var saved = $("#order_edit").data('saved');
653                 if(saved) {
654                     var data = api.data();
655                     for(var i = 0; i<data.length; i++) {
656                         var row = data[i];
657                         var srow = saved[row.order_id];
658                         if(srow) {
659                             if(row.fund_id != srow.fund_id) {
660                                 row.fund.budget.budget_period_description = $("#bookfund option[value="+srow.fund_id+"]").parent().attr('label');
661                                 row.fund.name = $("#bookfund option[value="+srow.fund_id+"]").html();
662                             }
663                             row.date_received = srow.date_received;
664                             row.quantity = srow.quantity;
665                             row.quantity_received = srow.quantity_received;
666                         }
667                     }
668                 }
669             });
670
671             [% IF only_one_order %]
672             $("#quantity").on('change', function() {
673                 $('.modal-save').prop('disabled', $(this).val() < 1 );
674             });
675             [% END %]
676
677             var _doSave = function(params) {
678                 $.ajax($.extend({
679                     method: 'POST',
680                     url: '/cgi-bin/koha/acqui/finishreceive.pl'
681                 }, params));
682             };
683
684             var _transform_row = function(row, origrec) {
685                 var params = {};
686                 params['biblionumber'] = row.biblio_id;
687                 params['invoiceid'] = invoice_id;
688                 params['ordernumber'] = row.order_id;
689                 params['booksellerid'] = row.basket.vendor_id;
690
691                 if(row.biblio.suggestions.length && row.biblio.suggestions[0].reason) {
692                     params["suggestionid"] = row.biblio.suggestions[0].suggestion_id;
693                     if($("#reason option[value='"+row.biblio.suggestions[0].reason+"']").length) {
694                         params['reason'] =  row.biblio.suggestions[0].reason;
695                     } else {
696                         params['reason'] = 'other';
697                         params['other_reason'] = row.biblio.suggestions[0].reason;
698                     }
699                 }
700                 params['datereceived'] = row.date_received;
701                 params['bookfund'] = row.fund_id;
702                 params['quantity'] = row.quantity;
703                 params['quantityrec'] = row.quantity_received;
704                 params['origquantityrec'] = origrec;
705                 var effective_create_items = row.basket.create_items || AcqCreateItem;
706                 params['tax_rate'] = (effective_create_items == 'receiving')?row.tax_rate_on_receiving:row.tax_rate_on_ordering;
707                 params['replacementprice'] = row.replacement_price;
708                 params['unitprice'] = ( invoiceincgst=="1" ) ? ( row.unit_price_tax_included || row.ecost_tax_included ) : ( row.unit_price_tax_excluded || row.ecost_tax_excluded );
709                 params['order_internalnote'] = row.internal_note;
710                 if (effective_create_items == 'receiving') {
711                     row.items.forEach(function(item){
712                         Object.keys(item).forEach(function(item_field){
713                             Object.keys(item[item_field]).forEach(function(key){
714                                 if (!params[key]) params[key] = [];
715                                 params[key].push(item[item_field][key]);
716                             });
717                         });
718                     });
719                 } else if(effective_create_items == 'ordering') {
720                     params['items_to_receive[]'] = (row.items||[])
721                         .filter(function(item) {
722                             return item._checked
723                         })
724                         .map(function(item) {
725                             return item.item_id;
726                         })
727                 }
728                 params['invoice_currency'] = row.invoice_currency;
729                 params['invoice_unitprice'] = row.invoice_unit_price;
730                 return params;
731             };
732
733             var save_rows = function(rows, data) {
734                 if(rows.length) {
735                     $('#jobpanel, #jobstatus').show();
736                     errors = []
737                     var loopRows = function(i) {
738                         var row = rows[i];
739                         if(!row) {
740                             if(!errors.length) {
741                                 location.href = "/cgi-bin/koha/acqui/parcel.pl?invoiceid="+invoice_id
742                             } else {
743                                 $('#modal_messages .modal-header h4').html(SAVE_ERROR_TITLE);
744                                 $('#modal_messages .modal-body ul').html('');
745                                 errors.forEach(function(error) {
746                                     $('#modal_messages .modal-body ul').append('<li>'+error+'</li>');
747                                 });
748                                 $('#modal_messages .modal-footer .cancel').hide();
749                                 $('#modal_messages .modal-footer .accept').html(_("Accept"));
750                                 $('#modal_messages .modal-footer .accept').one('click', function() {
751                                     location.href = "/cgi-bin/koha/acqui/parcel.pl?invoiceid="+invoice_id
752                                 });
753                                 $('#modal_messages').modal('show');
754                             }
755                             return;
756                         }
757                         if(data.saved && data.saved[row.order_id]) {
758                             row = data.saved[row.order_id];
759                             var origrec = data.origrec[row.order_id];
760                         } else {
761                             var origrec = row.quantity_received;
762                         }
763                         var _set_percentage = function() {
764                             var percentage = Math.round(( (i+1) / rows.length) * 100);
765                             var bgproperty = (parseInt(percentage*2)-300)+"px 0px";
766                             $("#jobprogress").css("background-position",bgproperty);
767                             $("#jobprogresspercent").text(percentage);
768                         }
769                         _doSave({
770                             data: _transform_row(row, origrec),
771                             success: function() {
772                                 _set_percentage();
773                                 loopRows(i+1);
774                             },
775                             error: function() {
776                                 _set_percentage()
777                                 errors.push(SAVE_ERROR.format(row.order_id));
778                                 loopRows(i+1);
779                             }
780                         });
781                     };
782                     loopRows(0)
783                 }
784             };
785
786             var get_warnings = function(rows) {
787                 var warnings = [];
788                 rows.forEach(function(row) {
789                     if(row.quantity_received > row.quantity) {
790                         warnings.push(SAVE_WARNING.format(row.order_id));
791                         row.quantity_received = row.quantity;
792                     }
793                     if(row.quantity_received == '0') {
794                         warnings.push(SAVE_WARNING_NO_ITEMS.format(row.order_id));
795                     }
796                 })
797                 return warnings;
798             }
799
800             $('#modal_messages .modal-footer .cancel').on('click', function() {
801                 $('#modal_messages .modal-footer .accept').off('click');
802                 $('#modal_messages').modal('hide');
803             })
804             $('.save').click(function() {
805                 var data = $("#order_edit").data();
806                 var rows = api.rows().data().toArray();
807                 var redirect = true;
808                 var warnings = get_warnings(rows);
809                 if(warnings.length) {
810                     $('#modal_messages .modal-header h4').html(SAVE_WARNING_TITLE);
811                     $('#modal_messages .modal-body ul').html('');
812                     warnings.forEach(function(warning) {
813                         $('#modal_messages .modal-body ul').append('<li>'+warning+'</li>');
814                     });
815                     $('#modal_messages .modal-footer .cancel').show();
816                     $('#modal_messages .modal-footer .accept').html(_("Continue"));
817                     $('#modal_messages .modal-footer .accept').one('click', function() {
818                         $('#modal_messages').modal('hide');
819                         save_rows(rows, data);
820                     });
821                     $('#modal_messages').modal('show');
822                 } else {
823                     save_rows(rows, data);
824                 }
825             });
826
827
828             $("#order_edit").on("change", "#reason", function() {
829                 var val = $(this).val();
830                 var row = $("#order_edit").data('row');
831                 if(val == 'other') {
832                     $("#other_reason").show();
833                     $(this).hide();
834                 } else {
835                     row.biblio.suggestions[0].reason = val;
836                 }
837             });
838
839             $("#order_edit").on("change", "#select-other_reason", function() {
840                 var val = $(this).val();
841                 var row = $("#order_edit").data('row');
842                 row.biblio.suggestions[0].reason = val;
843             });
844
845             $("#order_edit").on("click", "#other_reason a", function() {
846                 $("#other_reason").hide();
847                 $("#reason").val(null).show();
848             });
849
850             $("#order_edit").on("change", "#datereceived", function() {
851                 var val = $(this).val();
852                 var row = $("#order_edit").data('row');
853                 row.date_received = val;
854             });
855
856             $("#order_edit").on("change", "#bookfund", function() {
857                 var val = $(this).val();
858                 var row = $("#order_edit").data('row');
859                 row.fund_id = val;
860             });
861
862             $("#order_edit").on("change", "#quantity_to_receive", function() {
863                 var val = $(this).val();
864                 var row = $("#order_edit").data('row');
865                 row.quantity = val;
866                 if(row.subscription_id) {
867                     $("#quantity").val(val).change();
868                 }
869             });
870
871             $("#order_edit").on("change", "#quantity", function() {
872                 var val = $(this).val();
873                 var row = $("#order_edit").data('row');
874                 row.quantity_received = val;
875                 var qtyto = parseInt($("#quantity_to_receive").val());
876                 if(parseInt(val) > qtyto) {
877                     $("#qtyrecerror").show();
878                 } else {
879                     $("#qtyrecerror").hide();
880                 }
881                 $("input[name='items_to_receive']").each(function() {
882                     $(this).prop('checked', false).change();
883                 });
884                 $("input[name='items_to_receive']:lt("+val+")").each(function () {
885                     $(this).prop('checked', true).change();
886                 });
887             });
888
889             $("#order_edit").on("change", "input[name='items_to_receive']", function() {
890                 var qty = $("input[name='items_to_receive']:checked").length;
891                 $("#quantity").val(qty);
892                 var row = $("#order_edit").data('row');
893                 row.quantity_received = qty;
894             [% IF only_one_order %]
895                 $('.modal-save').prop('disabled', qty < 1 );
896             [% END %]
897             })
898
899             $("#order_edit").on("change", "#tax_rate", function() {
900                 var val = $(this).val();
901                 if(val === null) $(this).val($('option:first-child', this).attr('value'));
902                 val = $(this).val();
903                 var row = $("#order_edit").data('row');
904                 var effective_create_items = row.basket.create_items || AcqCreateItem;
905                 if(effective_create_items == 'receiving') {
906                     row.tax_rate_on_receiving = val;
907                 } else {
908                     row.tax_rate_on_ordering = val;
909                 }
910
911             });
912
913             $("#order_edit").on("change", "#unitprice", function() {
914                 var val = $(this).val();
915                 var row = $("#order_edit").data('row');
916                 if(invoiceincgst == "1") {
917                     row.unit_price_tax_included = val;
918                 } else {
919                     row.unit_price_tax_excluded = val;
920                 }
921
922             });
923
924             function _update_unitprice() {
925                 let row = $("#order_edit").data('row');
926
927                 let unitprice = $("#unitprice").val();
928                 let invoice_currency = $("#invoice_currency").val();
929                 let invoice_unitprice = $("#invoice_unitprice").val();
930                 let change_currency = $("#change_currency").is(":checked");
931
932                 if ( change_currency ) {
933                     $("#select_currency").show();
934                     if(!$("#invoice_unitprice").val()){
935                         invoice_unitprice = unitprice;
936                     }
937                     var rate = Number($("#invoice_currency option:selected").data('rate'));
938                     unitprice = Number( invoice_unitprice * rate ).toFixed(2);
939                     $("#unitprice").prop("readonly", "true");
940                 } else {
941                     $("#select_currency").hide();
942                     $("#unitprice").prop("readonly", "");
943                     invoice_unitprice = "";
944                     invoice_currency = active_currency;
945                 }
946
947                 $("#invoice_unitprice").val(invoice_unitprice);
948                 $("#invoice_currency").val(invoice_currency);
949                 $("#unitprice").val(unitprice).change();
950
951                 row.invoice_currency = invoice_currency;
952                 row.invoice_unit_price = invoice_unitprice;
953             }
954             $("#order_edit").on("change", "#invoice_currency",  _update_unitprice );
955             $("#order_edit").on("change", "#invoice_unitprice", _update_unitprice );
956             $("#order_edit").on("change", "#change_currency",   _update_unitprice );
957
958             $("#order_edit").on("change", "#replacementprice", function() {
959                 var val = $(this).val();
960                 var row = $("#order_edit").data('row');
961                 row.replacement_price = val;
962             });
963
964             $("#order_edit").on("change", "#order_internalnote", function() {
965                 var val = $(this).val();
966                 var row = $("#order_edit").data('row');
967                 row.internal_note = val;
968
969             });
970
971             var keep_row = function() {
972                 var row = $("#order_edit").data('row');
973                 var kept = $("#order_edit").data('kept')||{};
974                 if($('#items_list tbody tr').length) {
975                     row.items = [];
976                     $('#items_list tbody tr').each(function() {
977                         var item = {};
978                         $('#'+$(this).attr('idblock')).find('*[name=kohafield]').each(function() {
979                             var kf = $(this).val();
980                             var obj = {};
981                             $(this).parent().find('*[name]').each(function() {
982                                 obj[$(this).prop('name')] = $(this).val();
983                             });
984                             item[kf] = obj;
985                         });
986                         row.items.push(item);
987                     });
988                 }
989                 kept[row.order_id] = row;
990                 $("#order_edit").data('kept', kept);
991             };
992
993             var save_row = function() {
994                 keep_row();
995                 var saved = $("#order_edit").data('saved')||{};
996                 var kept = $("#order_edit").data('kept');
997                 var saved_rows = $.extend(saved, kept);
998                 $("#order_edit").data('saved', saved_rows);
999                 api.draw();
1000                 return saved_rows;
1001             }
1002
1003             var set_modal_buttons = function() {
1004                 var n = $("#order_edit").data('n');
1005                 var info = api.page.info();
1006
1007                 $('.modal-prev').prop('disabled', info.page == 0 && n == 0);
1008                 $('.modal-next').prop('disabled', info.pages - 1 == info.page && info.end - info.start - 1 == n);
1009             };
1010
1011             var show_subs = function(row) {
1012                 //$("#child_orders").show();
1013                 var had_rows = false;
1014                 var base_query = { "subscription_id": row.subscription_id, "parent_order_id": row.order_id, "order_id": {"!=": row.order_id}};
1015                 var pending_orders_url = "/api/v1/acquisitions/orders";
1016                 var options = {
1017                     "ajax": {
1018                         "url": pending_orders_url + "?q=" + encodeURI(JSON.stringify(base_query))
1019                     },
1020                     "header_filter": true,
1021                     "embed": [
1022                         "invoice",
1023                         "basket"
1024                     ],
1025                     "order": [[1, 'asc']],
1026                     'dom': 'C<"top pager"ilpfB>tr<"bottom pager"ip>',
1027                     "columns": [
1028                         {
1029                             "searchable": false,
1030                             "orderable": false,
1031                             "data": function(row, type, val, meta) {
1032                                 if(row.invoice) {
1033                                     if(CAN_user_acquisition) {
1034                                         return '<a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid='+row.invoice_id+'" title="Invoice detail page">'+row.invoice.invoice_number+"</a>";
1035                                     }
1036                                     return row.invoice.invoice_number;
1037                                 }
1038                             }
1039                         },
1040                         {
1041                             "data": "order_id",
1042                             "searchable": false,
1043                             "orderable": false
1044                         },
1045                         {
1046                             "searchable": false,
1047                             "orderable": false,
1048                             "data": "basket.creation_date",
1049                             "render": function(data, type, row, meta) {
1050                                 return $date(row.basket.creation_date);
1051                             }
1052                         },
1053                         {
1054                             "searchable": false,
1055                             "orderable": false,
1056                             "data": function(row, type, val, meta) {
1057                                 return $date(row.date_received);
1058                             }
1059                         },
1060                         {
1061                             "searchable": false,
1062                             "orderable": false,
1063                             "data": function(row, type, val, meta) {
1064                                 return row.quantity_received;
1065                             }
1066                         },
1067                         {
1068                             "searchable": false,
1069                             "orderable": true,
1070                             "data": function(row, type, val, meta) {
1071                                 if(!row.status) return;
1072                                 var first_letter = row.status[0].toUpperCase();
1073                                 return first_letter+row.status.substr(1).toLowerCase();
1074                             }
1075                         },
1076                         {
1077                             "searchable": false,
1078                             "orderable": false,
1079                             "data": function(row, type, val, meta) {
1080                                 if(!row.date_received) return;
1081                                 return Number(row.unit_price_tax_excluded * row.quantity_received).format_price()+' / '+Number(row.unit_price_tax_included * row.quantity_received).format_price()
1082                             }
1083                         },
1084                         {
1085                             "searchable": false,
1086                             "orderable": false,
1087                             "data": function(row, type, val, meta) {
1088                                 return row.internal_note;
1089                             }
1090                         }
1091                     ]
1092                 };
1093                 var child_orders_table = $("#child_orders_table").api(options);
1094                 var child_api = child_orders_table.api();
1095                 child_api.on('preDraw', function() {
1096                     if(!child_api.data().length && !had_rows) return;
1097                     $("#history-panel").show();
1098                     had_rows = true;
1099                 });
1100             };
1101
1102             var set_editor = function() {
1103                 var modal = $("#order_edit");
1104                 var row = modal.data('row');
1105                 var origrec = $("#order_edit").data('origrec')||{};
1106                 if(!origrec.hasOwnProperty(row.order_id)) {
1107                     origrec[row.order_id] = row.quantity_received;
1108                     $("#order_edit").data('origrec', origrec);
1109                 }
1110                 if(row.subscription_id) {
1111                     row.quantity_received = row.quantity;
1112                 }
1113                 var keep = $("#order_edit").data('kept');
1114                 if(keep && keep[row.order_id]) {
1115                     row = keep[row.order_id];
1116                     modal.data('row', row);
1117                 }
1118                 $('input, select, textarea', '.modal-body').val(null)
1119                 modal.find(".modal-title").text(MOD_TITLE.format(escape_str(row.order_id),escape_str(row.biblio.title)));
1120                 ["title", "author", "copyright_date", "isbn", "series_title"].forEach(function(key){
1121                     var o = modal.find(".modal-body #biblio_"+key);
1122                     if(row.biblio[key] !== null) {
1123                         o.parent().show();
1124                         o.html(row.biblio[key]);
1125                     } else {
1126                         o.parent().hide();
1127                     }
1128                 });
1129                 if(row.biblio.suggestions.length) {
1130                     $("#suggestion_fieldset").show();
1131                     if(row.biblio.suggestions[0].suggester) {
1132                         $("#biblio_suggestion_suggester").parent().show();
1133                         $("#biblio_suggestion_suggester")
1134                             .html(
1135                                 [row.biblio.suggestions[0].suggester.surname, row.biblio.suggestions[0].suggester.firstname]
1136                                     .filter(function(name){
1137                                         return name
1138                                     })
1139                                     .join(', ')+' (<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid='+row.biblio.suggestions[0].suggestion_id+'&op=show">'+SUGGESTION.format(row.biblio.suggestions[0].suggestion_id)+'</a>)'
1140                             );
1141                     } else {
1142                         $("#biblio_suggestion_suggester").parent().hide();
1143                     }
1144                     if(row.biblio.suggestions[0].reason) {
1145                         $("#suggestion_reason").show();
1146                         if($("#reason option[value='"+row.biblio.suggestions[0].reason+"']").length) {
1147                              $("#other_reason a").click();
1148                             $("#reason").val(row.biblio.suggestions[0].reason);
1149                             $("#select-other_reason").val(null);
1150                         } else {
1151                             $("#reason").val("other").change();
1152                             $("#select-other_reason").val(row.biblio.suggestions[0].reason);
1153                         }
1154
1155                     } else {
1156                         $("#suggestion_reason").hide();
1157                     }
1158                 } else {
1159                     $("#suggestion_fieldset").hide();
1160                 }
1161
1162                 var effective_create_items = row.basket.create_items || AcqCreateItem;
1163
1164                 // set today if no date_received in row
1165                 document.querySelector("#datereceived")._flatpickr.setDate(row.date_received||new Date());
1166
1167                 // restore the full tree
1168                 $("#bookfund").html($funds_tree);
1169                 $("#selected_bookfund")
1170                     .html(FUND_KEEP.format(row.fund.budget.budget_period_description, row.fund.name))
1171                     .attr( 'data-sort1-authcat', row.fund.sort1_authcat )
1172                     .attr( 'data-sort2-authcat', row.fund.sort2_authcat );
1173                 if (row.fund_id != row.fund.fund_id) {
1174                     $("#bookfund").val(row.fund_id);
1175                 }
1176                 $("#bookfund").select2({ width: '50%' });
1177                 $("#current-fund").html(FUNC_CUR.format(row.fund.budget.budget_period_description, row.fund.name));
1178                 if( row.creator ) {
1179                     $("#creator").html([row.creator.surname, row.creator.firstname].filter(function(name){return name}).join(', ')+" ("+row.creator.patron_id+')')
1180                 } else {
1181                     $("#creator").html(__("Account has been deleted"));
1182                 }
1183                 $("#quantity_to_receive").val(row.quantity).prop('readonly', !row.subscription_id);
1184                 $("#quantity").val( effective_create_items == 'cataloguing' ? row.quantity_received || 1 : row.quantity_received )
1185                               .prop('readonly', !row.subscription_id && effective_create_items == 'receiving')
1186                               .change();
1187                 [% IF only_one_order %]
1188                     $(".modal-save").prop('disabled', $("#quantity").val() == 0);
1189                 [% END %]
1190                 $('#qtyrecerror').hide();
1191                 var tax_rate = row.tax_rate_on_receiving || row.tax_rate_on_ordering;
1192                 $("#tax_rate").val(tax_rate).change();
1193                 var rrp_txt;
1194                 var ecost_txt;
1195                 if(invoiceincgst == "1") {
1196                     rrp_txt = Number(row.rrp_tax_included).format_price()+'<span class="hint"> '+ADJ_TAX_INC.format(active_currency)+"</span>";
1197                     ecost_txt = Number(row.ecost_tax_included).format_price()+'<span class="hint"> '+TAX_INC+"</span>";
1198                     $("#unitprice").val(row.unit_price_tax_included > 0 ? Number(row.unit_price_tax_included).format_price() : Number(row.ecost_tax_included).format_price());
1199                     $("#unitprice_hint").html(TAX_INC);
1200                 } else {
1201                     rrp_txt = Number(row.rrp_tax_excluded).format_price()+'<span class="hint"> '+ADJ_TAX_EXC.format(active_currency)+"</span>";
1202                     ecost_txt = Number(row.ecost_tax_excluded).format_price()+'<span class="hint"> '+TAX_EXC+"</span>";
1203                     $("#unitprice").val(row.unit_price_tax_excluded > 0 ? Number(row.unit_price_tax_excluded).format_price() : Number(row.ecost_tax_excluded).format_price());
1204                     $("#unitprice_hint").html(TAX_EXC);
1205                 }
1206                 $("#rrp").html(rrp_txt);
1207                 $("#replacementprice").val(row.replacement_price);
1208                 $("#ecost").html(ecost_txt);
1209                 $("#order_internalnote").val(row.internal_note);
1210                 if(row.vendor_note) {
1211                     $("#order_vendornote").html(row.vendor_note);
1212                     $("#order_vendornote").parent().show();
1213                 } else {
1214                     $("#order_vendornote").parent().hide();
1215                 }
1216
1217
1218                 $("#history-panel").hide();
1219
1220                 $('#items_list tbody tr, #outeritemblock > *, #acq-create-ordering tbody tr').remove();
1221                 $('#items_list').hide();
1222                 if(row.subscription_id) {
1223                     $('#modal-order-main #items-panel').removeClass('show').addClass('hide');
1224                     $('#modal-order-main #history-panel').removeClass('hide').addClass('show');
1225                 } else {
1226                     $('#modal-order-main #history-panel').removeClass('show').addClass('hide');
1227                     $('#modal-order-main #items-panel').removeClass('hide').addClass('show');
1228                     if(effective_create_items == 'receiving') {
1229                         $("#acq-create-receiving").show();
1230                         $("#acq-create-ordering").hide();
1231                         if(row.items && row.items.length) {
1232                             row.items.forEach(function(item, index) {
1233                                 cloneItemBlock(index, '[% UniqueItemFields | html %]', function(block_id) {
1234                                     var block = $('#'+block_id).hide();
1235                                     Object.keys(item).forEach(function(key) {
1236                                         block
1237                                             .find('*[name=kohafield][value="'+key+'"]')
1238                                             .parent()
1239                                             .find('*[name=field_value]')
1240                                             .val(item[key].field_value);
1241                                     });
1242                                     addItemInList(block_id, '[% UniqueItemFields | html %]');
1243                                     block.find("input[name='buttonPlus']").val( (window.MSG_ADDITEM_JS_UPDATEITEM ) );
1244                                     block.find("input[name='buttonPlusMulti']").remove();
1245                                     block.find("input[name='multiValue']").remove();
1246                                 });
1247                             });
1248                         }
1249                         cloneItemBlock((row.items && row.items.length) || 0, '[% UniqueItemFields | html %]');
1250                     } else if (effective_create_items == 'ordering') {
1251                         $("#acq-create-receiving").hide();
1252                         $("#acq-create-ordering").show();
1253                         if(row.items.length) {
1254                             $("#acq-create-ordering tbody").append(
1255                                 row.items.map(function(item) {
1256                                     var tr = $('<tr id="item_'+item.item_id+'"/>');
1257                                     _build_item(item, tr);
1258                                     return tr;
1259                                 })
1260                             );
1261                         }
1262                     } else {
1263                         $('#modal-order-main #items-panel').removeClass('show').addClass('hide');
1264                     }
1265                 }
1266                 if(row.invoice_currency && row.invoice_currency != active_currency) {
1267                     $("#select_currency").show();
1268                     $("#unitprice").prop("readonly", true);
1269                     $("#change_currency").prop('checked', true);
1270                     $("#invoice_currency").val(row.invoice_currency);
1271                     $("#invoice_unitprice").val(row.invoice_unit_price);
1272                 } else {
1273                     $("#select_currency").hide();
1274                     $("#unitprice").prop("readonly", "");
1275                     $("#change_currency").prop('checked', false);
1276                     $("#invoice_currency").val(active_currency);
1277                     $("#invoice_unitprice").val('');
1278                 }
1279
1280                 disabledBudgetsCopy = $('#bookfund').html();
1281                 $('#bookfund .inactive_budget').remove();
1282
1283                 $('#showallbudgets').click(function() {
1284                     if ($(this).is(":checked")) {
1285                         $('#bookfund').html(disabledBudgetsCopy); //Puts back all the funds
1286                     }
1287                     else {
1288                         $('#bookfund .inactive_budget').remove();
1289                     }
1290                 });
1291                 set_modal_buttons();
1292             };
1293
1294             $('.modal-prev').click(function() {
1295                 var modal = $("#order_edit");
1296                 keep_row();
1297                 var n = modal.data('n');
1298                 if(n > 0) {
1299                     n--;
1300                     modal.data('row', JSON.parse(JSON.stringify(api.row(n).data())));
1301                     modal.data('n', n);
1302                     set_editor();
1303                 } else {
1304                     $('.modal-next, .modal-prev').prop('disabled', true);
1305                     orders_table.one('draw.dt', function() {
1306                         var info = api.page.info();
1307                         n = info.end - info.start - 1;
1308                         modal.data('row', JSON.parse(JSON.stringify(api.row(n).data())));
1309                         modal.data('n', n);
1310                         set_editor();
1311                     });
1312                     api.page('previous').draw( 'page' );
1313                 }
1314             });
1315
1316             $('.modal-next').click(function() {
1317                 var modal = $("#order_edit");
1318                 keep_row();
1319                 var n = modal.data('n');
1320                 var info = api.page.info();
1321                 if(n < info.end - info.start - 1) {
1322                     n++;
1323                     modal.data('row', JSON.parse(JSON.stringify(api.row(n).data())));
1324                     modal.data('n', n);
1325                     set_editor();
1326                 } else {
1327                     $('.modal-next, .modal-prev').prop('disabled', true);
1328                     orders_table.one('draw.dt', function() {
1329                         var info = api.page.info();
1330                         n = 0;
1331                         modal.data('row', JSON.parse(JSON.stringify(api.row(n).data())));
1332                         modal.data('n', n);
1333                         set_editor();
1334                     });
1335                     api.page('next').draw( 'page' );
1336                 }
1337             });
1338
1339             $('.modal-save').click(function() {
1340                 var saved_rows = save_row();
1341                 if(Object.keys(saved_rows).length) $('.save').prop('disabled', false);
1342                 $("#order_edit").modal('hide');
1343                 [% IF only_one_order %]
1344                     $(".save").click();
1345                 [% END %]
1346             })
1347
1348             $("#order_edit").on("show.bs.modal", function (event) {
1349                 var anchor = $(event.relatedTarget);
1350                 var n = anchor.data("row");
1351                 var row = api.row(n).data();
1352
1353                 var modal = $(this);
1354                 modal.data('row', JSON.parse(JSON.stringify(row)));
1355                 modal.data('n', n);
1356                 modal.data('keep', modal.data('saved')||{});
1357                 //$('#modal-order-main').tabs("option", "active", 0);
1358                 set_editor();
1359             });
1360
1361             $("#order_edit").on("hide.bs.modal", function() {
1362             [% IF only_one_order %] [%# On the single case, dismissing the modal equals to cancelling %]
1363                 location.href = "/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid | html %]&sticky_filters=1";
1364             [% ELSE %]
1365                 $("#child_orders_table").DataTable().off('preDraw').destroy();
1366             [% END %]
1367             });
1368         });
1369     </script>
1370 [% END %]
1371
1372 [% INCLUDE 'intranet-bottom.inc' %]