Bug 34913: DataTables upgrade: Update CSS and option names
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / acqui / parcel.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE KohaDates %]
5 [% USE Price %]
6 [% PROCESS 'i18n.inc' %]
7 [% SET footerjs = 1 %]
8 [% INCLUDE 'doc-head-open.inc' %]
9 <title>[% FILTER collapse %]
10     [% IF ( invoiceclosedate ) %]
11         [% IF ( invoice ) %]
12             [% tx("Receipt summary for {vendor}, invoice {invoice_number}", { vendor = name, invoice_number = invoice }) | html %]
13         [% ELSE %]
14             [% tx("Receipt summary for {vendor}", { vendor = name }) | html %]
15         [% END %]
16     [% ELSE %]
17         [% tx("Receive orders from {vendor}", { vendor = name }) | html %]
18     [% END %] &rsaquo;
19     [% t("Acquisitions") | html %] &rsaquo;
20     [% t("Koha") | html %]
21 [% END %]</title>
22 [% INCLUDE 'doc-head-close.inc' %]
23 </head>
24
25 <body id="acq_parcel" class="acq">
26 [% WRAPPER 'header.inc' %]
27     [% INCLUDE 'acquisitions-search.inc' %]
28 [% END %]
29
30 [% WRAPPER 'sub-header.inc' %]
31     [% WRAPPER breadcrumbs %]
32         [% WRAPPER breadcrumb_item %]
33             <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a>
34         [% END %]
35         [% IF invoiceclosedate %]
36             [% WRAPPER breadcrumb_item bc_active= 1 %]
37                 [% IF ( invoice ) %]
38                     <span>Receipt summary for <em>[% name | html %] [ [% invoice | html %] ]</em></span>
39                 [% ELSE %]
40                     <span>Receipt summary for <em>[% name | html %]</em></span>
41                 [% END %]
42             [% END %]
43         [% ELSE %]
44             [% WRAPPER breadcrumb_item %]
45                 <a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% booksellerid | uri %]">[% name | html %]</a>
46             [% END %]
47             [% WRAPPER breadcrumb_item bc_active= 1 %]
48                 <span>Receive orders from [% name | html %]</span>
49             [% END %]
50         [% END %]
51     [% END #/ WRAPPER breadcrumbs %]
52 [% END #/ WRAPPER sub-header.inc %]
53
54 <div class="main container-fluid">
55     <div class="row">
56         <div class="col-sm-10 col-sm-push-2">
57             <main>
58
59     [% IF ( receive_error ) %]
60     <div class="dialog alert">
61     <h3>Error adding items:</h3>
62     <ul>
63     [% FOREACH error_loo IN error_loop %]
64         <li>[% error_loo.error_param | html %][% IF ( error_loo.error_duplicate_barcode ) %]Duplicate barcode[% END %] <!-- todo: other error conditions come here. --></li>
65     [% END %]
66     </ul>
67     </div>
68     [% END %]
69     <h1>
70         [% IF ( invoiceclosedate ) %]
71             <span>Receipt summary for <em>[% name | html %]</em></span> [% IF ( invoice ) %] <em> [ [% invoice | html %] ] </em>[% END %]
72         [% ELSE %]
73             <span>Receive orders from [% name | html %]</span>
74         [% END %]
75     </h1>
76
77     [% IF ( success_delorder ) %]
78     <div class="dialog message">The order has been successfully canceled.</div>
79     [% ELSE %]
80     [% IF ( error_delitem ) %]
81         <div class="dialog alert">The order has been canceled, although one or more items could not have been deleted.</div>
82     [% END %]
83     [% IF ( error_delbiblio ) %]
84         <div class="dialog alert">The order has been canceled, although the record has not been deleted.</div>
85     [% END %]
86     [% END %]
87
88     [% IF (error_cancelling_receipt) %]
89       <div class="dialog alert">
90       <span>Cannot cancel receipt. Possible reasons:</span>
91       <ul>
92         <li>
93           The order line you are trying to cancel was created from a partial receipt
94           of another order line which is already received. Try to cancel this
95           one first and retry.
96         </li>
97         <li>
98           The order line you are trying to cancel was created from a partial receipt
99           of another order line which has been deleted. Cancellation is not
100           possible.
101         </li>
102       </ul>
103       </div>
104     [% END %]
105
106     [% IF error_invoice_not_known %]
107         <div class="dialog alert">
108             The invoice referenced by this invoiceid does not exist.
109         </div>
110     [% END %]
111
112 [% UNLESS no_orders_to_display %]
113 <div id="acqui_receive_summary">
114 <p><strong>Invoice number:</strong> [% invoice | html %] <strong>Shipment date:</strong> [% shipmentdate | $KohaDates %]</p>
115 </div>
116 [% UNLESS (invoiceclosedate) %]
117     <div id="acqui_receive_search" class="page-section">
118         <h3>Pending orders</h3>
119         <table id="pending_orders" class="table table-bordered table-striped">
120             <thead>
121                 <tr>
122                     <th></th>
123                     <th>Basket</th>
124                     <th>Basket group</th>
125                     <th>Order line</th>
126                     <th>Summary</th>
127                     <th>View</th>
128                     <th>Replacement price</th>
129                     <th>Quantity</th>
130                     <th>Unit cost</th>
131                     <th>Order cost</th>
132                     <th>Fund</th>
133                     <th>&nbsp;</th>
134                     <th>&nbsp;</th>
135                 </tr>
136             </thead>
137         </table>
138       <fieldset class="action">
139         <button id="select_multiple" class="btn btn-primary"></button>
140       </fieldset>
141     </div>
142 [% ELSE %]
143     <p>
144         <span>Invoice is closed, so you can't receive orders anymore.</span>
145         [% IF CAN_user_acquisition_reopen_closed_invoices %]
146             <a href="/cgi-bin/koha/acqui/invoice.pl?op=reopen&invoiceid=[% invoiceid | uri %]&referer=/cgi-bin/koha/acqui/parcel.pl%3Finvoiceid=[% invoiceid | uri %]">Reopen it</a>.
147         [% END %]
148     </p>
149 [% END %]
150
151 <div id="acqui_receive_receivelist" class="page-section">
152     <h3>Already received</h3>
153
154    [% IF ( loop_received ) %]
155    <form action="/cgi-bin/koha/acqui/parcel.pl" method="get" name="orderform">
156     <table id="receivedt">
157       <thead>
158         <tr>
159           <th>Basket</th>
160           <th>Basket group</th>
161           <th>Order line</th>
162           <th title="Item holds / Total holds">Holds</th>
163           <th>Summary</th>
164           <th>More</th>
165           <th>Replacement price</th>
166           <th>Quantity</th>
167           <th>Fund</th>
168           <th>Est cost</th>
169           <th>Actual cost</th>
170           <th>TOTAL</th>
171           <th></th>
172         </tr>
173       </thead>
174     <tfoot>
175         [% FOREACH key IN subtotal_for_funds.keys.sort %]
176             <tr>
177                 [% IF invoiceincgst %]
178                     <td colspan="6" class="total">(Tax inc.)</td>
179                 [% ELSE %]
180                     <td colspan="6" class="total">(Tax exc.)</td>
181                 [% END %]
182                 <td colspan="3"><em>Subtotal for</em> [% key | html %]</td>
183                 <td>[% subtotal_for_funds.$key.ecost | $Price %]</td>
184                 <td>[% subtotal_for_funds.$key.unitprice | $Price %]</td>
185                 <td>&nbsp;</td>
186                 <td>&nbsp;</td>
187             </tr>
188         [% END %]
189         <tr>
190             <th colspan="11" class="total">Total tax exc.</th>
191             <th>[% total_tax_excluded | $Price %]</th>
192             <th></th>
193         </tr>
194         [% FOREACH book_foot IN book_foot_loop %]
195             <tr>
196                 <th colspan="11">Total (GST [% book_foot.tax_rate * 100 | html %]%)</th>
197                 <th>[% book_foot.tax_value | $Price %]</th>
198                 <th></th>
199             </tr>
200         [% END %]
201         <tr>
202             <th colspan="11" class="total">Total tax inc.</th>
203             <th>[% total_tax_included | $Price %]</th>
204             <th></th>
205         </tr>
206     </tfoot>
207     <tbody class="filterclass">
208         [% FOREACH order IN loop_received %]
209             <tr>
210                 <td><a href="/cgi-bin/koha/acqui/basket.pl?basketno=[% order.basketno | uri %]"> [% order.basketname | html %] ([% order.basketno | html %])</a></td>
211                 <td>
212                   [% IF order.basketgroupid %]
213                   <a href="/cgi-bin/koha/acqui/basketgroup.pl?op=add&amp;booksellerid=[% booksellerid | uri %]">[% order.basketgroupname | html %] ([% order.basketgroupid | html %])</a>
214                   [% ELSE %]
215                     No basket group
216                   [% END %]
217                 </td>
218                 <td>
219                   <a href="neworderempty.pl?ordernumber=[% order.ordernumber | uri %]&amp;booksellerid=[% booksellerid | uri %]">[% order.ordernumber | html %]</a>
220                   [% IF (order.parent_ordernumber && (order.parent_ordernumber != order.ordernumber)) %]
221                     (<a href="neworderempty.pl?ordernumber=[% order.parent_ordernumber | uri %]&amp;booksellerid=[% booksellerid | uri %]" title="Original order line">[% order.parent_ordernumber | html %]</a>)
222                   [% END %]
223                 </td>
224                 <td>
225                   [% IF order.total_holds > 0 %]
226                     [% IF order.item_holds > 0 %]
227                       <span class="error"><a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% order.biblionumber | uri %]">[% order.item_holds | html %]</a></span>
228                     [% ELSE %]
229                       0
230                     [% END %]
231                     /
232                     <span class="error"><a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% order.biblionumber | uri %]">[% order.total_holds | html %]</a></span>
233                   [% ELSE %]
234                     0
235                   [% END %]
236                 </td>
237                 <td>
238                     [% INCLUDE 'biblio-title.inc' biblio=order link = 1 %]
239                 [% IF ( order.author ) %] / [% order.author | html %][% END %]
240                 [% IF ( order.isbn ) %] - [% order.isbn | html %][% END %]
241                 [% IF ( order.publishercode ) %]
242                     <br />Publisher: [% order.publishercode | html %]
243                     [%- IF    ( order.publicationyear > 0) -%], [% order.publicationyear | html %]
244                     [%- ELSIF ( order.copyrightdate   > 0) -%] [% order.copyrightdate | html %]
245                     [% END %]
246                 [% END %]
247                 [% IF ( order.suggestionid ) %]
248                     <br/>
249                     Suggested by: [% order.surnamesuggestedby | html %][% IF ( order.firstnamesuggestedby ) %], [% order.firstnamesuggestedby | html %] [% END %]
250                     (<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid=[% order.suggestionid | uri %]&amp;op=show">suggestion #[% order.suggestionid | html %]</a>)
251                 [% END %]
252                 <br />
253                 [% IF ( order.order_internalnote ) %]
254                     <p class="ordernote"><strong>Internal note: </strong>[% order.order_internalnote | html %] [<a href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=[% order.ordernumber | uri %]&amp;referrer=/cgi-bin/koha/acqui/parcel.pl%3Finvoiceid=[% invoiceid | uri %]&type=internal">Change internal note</a>]</p>
255                 [% ELSE %]
256                     [<a href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=[% order.ordernumber | uri %]&amp;referrer=/cgi-bin/koha/acqui/parcel.pl%3Finvoiceid=[% invoiceid | uri %]&type=internal">Add internal note</a>]
257                 [% END %]
258                 [% IF ( order.order_vendornote ) %]
259                     <p class="ordernote"><strong>Vendor note: </strong>[% order.order_vendornote | html %]</p>
260                 [% ELSE %]
261                     [<a href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=[% order.ordernumber | uri %]&amp;referrer=/cgi-bin/koha/acqui/parcel.pl%3Finvoiceid=[% invoiceid | uri %]&type=vendor">Add vendor note</a>]
262                 [% END %]
263                 </td>
264                 <td>
265                   <a href="/cgi-bin/koha/acqui/showorder.pl?ordernumber=[% order.ordernumber | uri %]" class="previewData">[% tp('noun', 'Order') | html %]</a><br>
266                   <a href="/cgi-bin/koha/catalogue/showmarc.pl?id=[% order.biblionumber | uri %]" class="previewData">MARC</a><br>
267                   <a href="/cgi-bin/koha/catalogue/showmarc.pl?viewas=card&amp;id=[% order.biblionumber | uri %]" class="previewData">Card</a>
268                 </td>
269                 <td>[% order.replacementprice | $Price %]</td>
270                 <td>[% order.quantityreceived | html %]</td>
271                 <td>[% order.budget.budget_name | html %]</td>
272                 <td>[% order.ecost | $Price %]</td>
273                 <td>[% order.unitprice | $Price %]</td>
274                 <td>[% order.total | $Price %]</td>
275                 <td>
276                     [% IF loop_receive.cannot_cancel or ( order.basket.effective_create_items == "receiving" and loop_receive.holds > 0 ) %]
277                       [% IF loop_receive.cannot_cancel %]
278                         [% span_title = BLOCK %]
279                             <span>Cannot cancel receipt of this order line because it
280                             was created from a partial receipt of order line no.
281                             [% order.parent_ordernumber | html %], which is
282                             already received. Try cancelling this one first and
283                             retry.</span>
284                         [% END %]
285                       [% ELSE %]
286                         [%# FIXME Here we block the cancellation if holds exist. Actually it could be possible if items will be exist after the deletion %]
287                         [%# Some additional checks should be added in the pl file %]
288                         [% span_title = BLOCK %]
289                           <span>Cannot cancel receipt of this order line because at least one hold exists on the records.</span>
290                         [% END %]
291                       [% END %]
292                       <span title="[% span_title | collapse | html %]">
293                           Can't cancel receipt
294                       </span>
295                     [% ELSE %]
296                         <a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid | uri %]&op=cancelreceipt&ordernumber=[% order.ordernumber | uri %]">Cancel receipt</a>
297                     [% END %]
298                 </td>
299             </tr>
300         [% END %]
301     </tbody>
302     </table>
303     </form>
304
305     [% ELSE %]There are no received orders.[% END %]
306 </div>
307
308 <div class="modal" id="dataPreview" tabindex="-1" role="dialog" aria-labelledby="dataPreviewLabel">
309     <div class="modal-dialog modal-wide" role="document">
310         <div class="modal-content">
311             <div class="modal-header">
312                 <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
313                 <h3 id="dataPreviewLabel">MARC previews</h3>
314             </div>
315             <div class="modal-body">
316                 <div id="loading"> <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading </div>
317             </div>
318             <div class="modal-footer">
319                 <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
320             </div>
321         </div> <!-- /.modal-content -->
322     </div> <!-- /.modal-dialog -->
323 </div> <!-- /.modal -->
324
325 [% IF (invoiceclosedate) %]
326     <a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% invoiceid | uri %]">View invoice</a>
327 [% ELSE %]
328     <form action="/cgi-bin/koha/acqui/invoice.pl" method="get">
329         <input type="hidden" name="invoiceid" value="[% invoiceid | html %]" />
330         <fieldset class="action">
331             <input type="submit" class="btn btn-primary" value="Finish receiving" />
332         </fieldset>
333     </form>
334 [% END %]
335
336 [% END %]
337
338 </main>
339 </div> <!-- /.col-sm-10.col-sm-push-2 -->
340
341 <div class="col-sm-2 col-sm-pull-10">
342 <aside>
343
344 [% INCLUDE 'acquisitions-menu.inc' %]
345     </aside>
346 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
347 </div> <!-- /.row -->
348
349 [% MACRO jsinclude BLOCK %]
350     [% Asset.js("js/acquisitions-menu.js") | $raw %]
351     [% INCLUDE 'datatables.inc' %]
352     [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %]
353     <style>fieldset.action { margin-bottom: 20px }</style>
354     <script>
355         dt_overwrite_html_sorting_localeCompare();
356         var PENDING_MULTI_SELECTION = _("Receive selected (%s)");
357         var columns_filter = {};
358
359         $(document).ready(function(){
360
361             if ( $("#receivedt").length ) {
362                 var receivedt = $("#receivedt").dataTable($.extend(true, {}, dataTablesDefaults, {
363                     "stateSave": true,
364                     "pageLength": 10,
365                     "lengthMenu": [[5, 10, 20, 50, 100, -1], [5, 10, 20, 50, 100, _("All")]],
366                     "columnDefs": [
367                         { "targets": [ 5, -1 ], "orderable": false, "searchable":  false },
368                     ],
369                     "columns": [
370                         { "type": "html" },
371                         { "type": "html" },
372                         { "type": "html" },
373                         { "type": "num-html" },
374                         { "type": "anti-the" },
375                         null,
376                         null,
377                         null,
378                         null,
379                         null,
380                         null,
381                         null,
382                         null
383                     ],
384                     "pagingType": "full"
385                 }));
386             }
387
388             var options = {
389                 "ajax": {
390                     "url": '/api/v1/acquisitions/orders?only_active=1'
391                 },
392                 "embed": [
393                     "basket.basket_group",
394                     "biblio.active_orders+count",
395                     "biblio.holds+count",
396                     "biblio.items+count",
397                     "biblio.suggestions.suggester",
398                     "fund",
399                     "current_item_level_holds+count",
400                     "items"
401                 ],
402                 "stateSave": true, // remember state on page reload
403                 "drawCallback": function (settings) {
404                     $(".previewData").on("click", function(e){
405                         e.preventDefault();
406                         var ltitle = $(this).text();
407                         var page = $(this).attr("href");
408                         $("#dataPreviewLabel").text(ltitle);
409                         $("#dataPreview .modal-body").load(page + " div");
410                         $('#dataPreview').modal({show:true});
411                     });
412                 },
413                 "columns": [
414                     { "data": "basket.name",
415                       "searchable": true,
416                       "orderable": true,
417                       "render": function(data, type, row, meta) {
418                         if (type != 'display') return escape_str(data);
419                         return "<a href=\"/cgi-bin/koha/acqui/basket.pl?basketno=" + encodeURIComponent(row.basket.basket_id) + "\">" + escape_str(data) + " (" + escape_str(row.basket.basket_id) + ")</a>";
420                       }
421                     },
422                     { "data": "basket.basket_group.name",
423                       "orderable": true,
424                       "render": function(data, type, row, meta) {
425                         if ( type != 'display' ) {
426                             return escape_str(data);
427                         }
428                         if ( row.basket.basket_group_id == null ) {
429                             return _("No basket group");
430                         }
431                         else {
432                             return "<a href=\"/cgi-bin/koha/acqui/basketgroup.pl?op=add&amp;booksellerid="
433                                     + encodeURIComponent(row.basket.vendor_id) + "&amp;basketgroupid="
434                                     + encodeURIComponent(row.basket.basket_group_id) + "\">"
435                                     + escape_str(row.basket.basket_group.name) + " (" + escape_str(row.basket.basket_group_id) + ")</a>";
436                         }
437                       }
438                     },
439                     {
440                         "data": "order_id",
441                         "render": function(data, type, row, meta) {
442                             if (type != 'display') return escape_str(data);
443                             return "<a href=\"neworderempty.pl?ordernumber="+encodeURIComponent(data)+"&amp;booksellerid="+encodeURIComponent(row.basket.vendor_id)+"\">"+escape_str(data)+"</a>";
444                         }
445                     },
446                     {
447                         [% SET summary_fields = "biblio.title:biblio.author:biblio.isbn:biblio.publisher:me.internal_note:me.vendor_note" %]
448                         [% IF Koha.Preference('marcflavour')=='UNIMARC' %][% SET summary_fields = summary_fields _ ":biblio.ean" %][% END %]
449                         "data": "[% summary_fields | html %]",
450                         "render": function(data, type, row, meta) {
451                             var result = '';
452                             if ( row && row.biblio_id != null ) {
453                                 result = "<p><a href=\"/cgi-bin/koha/catalogue/detail.pl?biblionumber="+encodeURIComponent(row.biblio_id)+"\">"+escape_str(row.biblio.title)+"</a>";
454                                 if ( row.biblio.author != null )
455                                     result += _(" by ") + escape_str(row.biblio.author);
456                                 if ( row.biblio.isbn != null )
457                                     result += " &ndash; " + escape_str(row.biblio.isbn);
458                                 [% IF Koha.Preference('marcflavour')=='UNIMARC' %]
459                                     if ( row.biblio.ean != null )
460                                         result += " &ndash; EAN:" + escape_str(row.biblio.ean);
461                                 [% END %]
462                                 if ( row.biblio.publisher != null ) {
463                                     result += "<br/>" + _("Publisher: ") + escape_str(row.biblio.publisher);
464                                     if ( row.biblio.publication_year != null ) {
465                                         result += ", " + escape_str(row.biblio.publication_year);
466                                     }
467                                     else if ( row.biblio.copyright_date != null ) {
468                                         result += escape_str(row.biblio.copyright_date);
469                                     }
470                                 }
471                                 var suggestions = row.biblio.suggestions;
472                                 if ( suggestions != null && suggestions.length > 0 ) {
473                                     var suggestion = suggestions[0];
474                                     if ( suggestion.suggester != null ) {
475                                         var suggester = suggestion.suggester;
476                                         var suggested_by = [];
477                                         if ( suggester.surname != null ) {
478                                             suggested_by.push(escape_str(suggester.surname));
479                                         }
480                                         if ( suggester.firstname != null ) {
481                                             suggested_by.push(escape_str(suggester.firstname));
482                                         }
483
484                                             result += "<br/>" + _("Suggested by: ") +
485                                                         '<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid='
486                                                             + encodeURIComponent(suggestion.suggestionid)
487                                                             + '&amp;op=show">'
488                                                             + suggested_by.join(", ")
489                                                             + " (#" + escape_str(suggestions[0].suggestionid) + ")</a>"; // FIXME: could be changed if we allow matching multiple suggestions
490                                     }
491                                 }
492                                 result += '</p>';
493                             }
494
495                             var internal_note = row.internal_note;
496                             if ( internal_note != null && internal_note != '' ) {
497                                 result += '<p class="ordernote"><strong>'
498                                             + _("Internal note: ")
499                                             + '</strong>' + escape_str(internal_note)
500                                             + ' [<a href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber='
501                                             + encodeURIComponent(row.order_id) + '&amp;referrer=/cgi-bin/koha/acqui/parcel.pl%3Finvoiceid=[% invoiceid | uri %]'
502                                             + '&type=internal">' + _("Change internal note") + '</a>]</p>';
503                             }
504                             else {
505                                 result += ' [<a href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber='
506                                             + encodeURIComponent(row.order_id) + '&amp;referrer=/cgi-bin/koha/acqui/parcel.pl%3Finvoiceid=[% invoiceid | uri %]'
507                                             + '&type=internal">' + _("Add internal note") + '</a>]';
508                             }
509
510                             var vendor_note = row.vendor_note;
511                             if ( vendor_note != null && vendor_note != '' ) {
512                                 result += '<p class="ordernote"><strong>'
513                                             + _("Vendor note: ")
514                                             + '</strong>' + escape_str(vendor_note) + '</p>';
515                             }
516                             else {
517                                 result += ' [<a href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber='
518                                             + encodeURIComponent(row.order_id) + '&amp;referrer=/cgi-bin/koha/acqui/parcel.pl%3Finvoiceid=[% invoiceid | uri %]'
519                                             + '&type=vendor">' + _("Add vendor note") + '</a>]';
520                             }
521
522                             return result;
523                         },
524                         "orderable": true,
525                     },
526                     {
527                         "data": "",
528                         "render": function(data, type, row, meta) {
529                             var result = '<div class="btn-group dropup">';
530                             result += '<button id="view' + row.order_id + '" type="button" class="btn btn-default btn-xs" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">';
531                                 result += ' <i class="fa-solid fa-eye aria-hidden="true"></i> ' + _("View");
532                                 result += ' <span class="caret"></span> ';
533                             result += '</button>';
534                             result += '<ul class="dropdown-menu" aria-labelledby="view' + row.order_id + '">';
535                                 result += '<li><a href="/cgi-bin/koha/acqui/showorder.pl?ordernumber=' + encodeURIComponent(row.order_id) + '" class="previewData">[% tp("noun", "Order") | html %]</a></li>';
536                                 result += '<li><a href="/cgi-bin/koha/catalogue/showmarc.pl?id=' + encodeURIComponent(row.biblio_id) + '" class="previewData">' + _("MARC") + '</a></li>';
537                                 result += '<li><a href="/cgi-bin/koha/catalogue/showmarc.pl?viewas=card&amp;id=' + encodeURIComponent(row.biblio_id) + '" class="previewData">' + _("Card") + '</a></li>';
538                             result += '</ul>';
539                             result += '</div>';
540                             return result;
541                         },
542                         "orderable": false,
543                         "searchable": false
544                     },
545                     {
546                         "data": "replacement_price",
547                         "render": function(data, type, row, meta) {
548                             return escape_price(row.replacement_price);
549                         },
550                     },
551                     {
552                         "data": "quantity",
553                         "orderable": true
554                     },
555                     {
556                         "data": "ecost",
557                         "render": function(data, type, row, meta) {
558                             return escape_price(row.ecost);
559                         },
560                     },
561                     {
562                         "data": "",
563                         "render": function(data, type, row, meta) {
564                             return escape_price(row.quantity * row.ecost);
565                         },
566                         "orderable": false, // FIXME: How can we do it in DBIC?
567                         "searchable": false
568                     },
569                     {
570                         "data": "fund.name",
571                         "render": function(data, type, row, meta) {
572                             if (type != 'display') return escape_str(data);
573                             return escape_str(row.fund.name);
574                         }
575                     },
576                     {
577                         "data": "",
578                         "render": function(data, type, row, meta) {
579                             return '<a href="orderreceive.pl?multiple_orders='
580                                     + encodeURIComponent(row.order_id) + '&amp;invoiceid=[% invoiceid | uri %]' + '">'
581                                     + _("Receive") + '</a><br/>'
582                                     + '<a href="#" onclick="transfer_order_popup(' + escape_str(row.order_id) + '); return false;">'
583                                     + _("Transfer") + '</a>';
584                         },
585                         "orderable": false,
586                         "searchable": false
587                     },
588                     {
589                         "data": "",
590                         "render": function(data, type, row, meta) {
591                             var result = "";
592
593                             if ( row.current_holds_count > 0 ) {
594                                 result += '<span class="button" title="'
595                                         + _("Can't cancel order, (%s) holds are linked with this order. Cancel holds first").format( escape_str(row.holds_count) ) + '">'
596                                         + _("Can't cancel order") + '</span><br/>';
597                             }
598                             else {
599                                 result += '<a href="/cgi-bin/koha/acqui/cancelorder.pl?ordernumber='
600                                             + encodeURIComponent(row.order_id)
601                                             + '&biblionumber=' + encodeURIComponent(row.biblio_id)
602                                             + '&referrer=/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid | uri %]">'
603                                             + _("Cancel order") + '</a><br/>';
604                             }
605
606                             if ( row.biblio != null ) {
607                                 if ( row.biblio.items_count - row.items.length > 0 ||
608                                     row.biblio.active_orders_count > 1 ||
609                                     row.biblio.subscriptions_count > 0 ||
610                                     row.biblio.holds_count > 0 ) { // biblio can be deleted
611                                     result += '<span class="button" title="'
612                                             + _("Can't delete catalog record, see constraints below") + '">'
613                                             + _("Can't cancel order and delete catalog record") + '</span><br>';
614                                 }
615                                 else {
616                                     result += '<a href="/cgi-bin/koha/acqui/cancelorder.pl?ordernumber='
617                                             + encodeURIComponent(row.order_id) + '&biblionumber=' + encodeURIComponent(row.biblio_id)
618                                             + '&del_biblio=1&referrer="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[$ invoiceid | uri ]">'
619                                             + _("Cancel order and catalog record") + '</a><br/>';
620                                 }
621
622                                 if ( row.biblio.items_count - row.items.length > 0 ) {
623                                     result += '<strong title="'
624                                             + _("Can't delete catalog record, because of %s existing item(s)").format(row.items.length)
625                                             +'">' + (row.biblio.items_count - row.items.length) + _(" item(s) left") + '</strong><br/>';
626                                 }
627
628                                 if ( row.biblio.active_orders_count > 1 ) {
629                                     result += '<strong title="'
630                                             + _("Can't delete catalog record, delete other orders linked to it first") + '">'
631                                             + (row.biblio.active_orders_count - 1) + _(" order(s) left") + '</strong><br/>';
632                                 }
633
634                                 if ( row.biblio.subscriptions_count > 0 ) {
635                                     result += '<strong title="' + _("Can't delete catalog record, delete subscriptions first") + '">'
636                                             + _("%s subscription(s) left").format(row.biblio.subscriptions_count)
637                                             + '</strong><br>';
638                                 }
639
640                                 if ( row.biblio.holds_count > 0 ) {
641                                     result += '<strong title="' + _("Can't delete catalog record or order, cancel holds first") + '">'
642                                             + _("%s hold(s) left").format(row.biblio.holds_count) + '</strong>';
643                                 }
644                             }
645
646                             return result;
647                         },
648                         "orderable": false,
649                         "searchable": false
650                     }
651                 ]
652             };
653
654             var selected_rows = {};
655             $('#select_multiple').click(function () {
656                 var ids = Object.keys(selected_rows);
657                 if (!ids.length) return;
658                 location.href = 'orderreceive.pl?multiple_orders=' + ids.join(',') + '&invoiceid=[% invoiceid | uri %]';
659             }).html(PENDING_MULTI_SELECTION.format('0'))
660             options.order = [[1, 'asc']];
661             options.columns.unshift({
662                 "data": function (row, type, val, meta) {
663                     return '<input type="checkbox" class="selOrder" />';
664                 },
665                 "searchable": false,
666                 "orderable": false
667             });
668
669             var pending_orders_table = $("#pending_orders").kohaTable(options, {}, 1, { "basket.vendor_id": [% booksellerid | html %] });
670
671             var api = pending_orders_table.api();
672             api.on('draw', function () {
673                 api.rows().every(function () {
674                     var row = this;
675                     var data = row.data();
676                     $('.selOrder', row.node()).on('click', function (event) {
677                         if ($(this).prop('checked')) {
678                             selected_rows[data.order_id] = data;
679                         } else {
680                             delete selected_rows[data.order_id];
681                         }
682                         $('#select_multiple').html(PENDING_MULTI_SELECTION.format(Object.keys(selected_rows).length));
683                     });
684                     if (selected_rows[data.order_id]) {
685                         $('.selOrder', row.node()).prop('checked', true);
686                     }
687                 });
688             });
689
690
691             $(".previewData").on("click", function(e){
692                 e.preventDefault();
693                 var ltitle = $(this).text();
694                 var page = $(this).attr("href");
695                 $("#dataPreviewLabel").text(ltitle);
696                 $("#dataPreview .modal-body").load(page + " div");
697                 $('#dataPreview').modal("show");
698             });
699
700             $("#dataPreview").on("hidden.bs.modal", function(){
701                 $("#dataPreviewLabel").html("");
702                 $("#dataPreview .modal-body").html("<div id=\"loading\"><img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> "+_("Loading")+"</div>");
703             });
704         });
705
706         // Case-insensitive version of jquery's contains function
707         jQuery.extend(jQuery.expr[':'], {
708             icontains : "jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0"
709         });
710
711         // Contains exactly function
712         jQuery.extend(jQuery.expr[':'], {
713             containsExactly: "$(a).text() == m[3]"
714         });
715
716         function transfer_order_popup(ordernumber) {
717         var url = "/cgi-bin/koha/acqui/transferorder.pl?"
718             + "ordernumber=" + ordernumber
719             window.open(url, 'TransferOrder');
720         }
721     </script>
722 [% END %]
723
724 [% INCLUDE 'intranet-bottom.inc' %]