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