Bug 20212: Search on fund's name instead of id
[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 [% 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                 <tr>
122                     <th><div class="input-group input-group-sm"><input id="basket_name_column_search" type="text" class="form-control column-filter" data-search-fields='["basket.name"]'></div></th>
123                     <th><div class="input-group input-group-sm"><input type="text" class="form-control column-filter" data-search-fields='["basket.basket_group.name"]'></div></th>
124                     <th><div class="input-group input-group-sm"><input type="text" class="form-control column-filter" data-search-fields='["me.order_id"]'></div></th>
125                     <th class="hidden">&nbsp;</th>
126                     <th class="hidden">&nbsp;</th>
127                     <th class="hidden">&nbsp;</th>
128                     <th><div class="input-group input-group-sm"><input type="text" class="form-control column-filter" data-search-fields='["me.internal_note","me.vendor_note","biblio.title","biblio.author","biblio.isbn","biblio.publisher","biblio.publication_year","biblio.copyright_date","biblio.suggestions.suggester.surname","biblio.suggestions.suggester.firstname"]'></div></th>
129                     <th>&nbsp;</th>
130                     <th><div class="input-group input-group-sm"><input type="text" class="form-control column-filter" data-search-fields='["me.replacement_price"]'></div></th>
131                     <th><div class="input-group input-group-sm"><input type="text" class="form-control column-filter" data-search-fields='["me.quantity"]'></div></th>
132                     <th><div class="input-group input-group-sm"><input type="text" class="form-control column-filter" data-search-fields='["me.ecost"]'></div></th>
133                     <th>&nbsp;</th>
134                     <!--th><div class="input-group input-group-sm"><input type="text" class="form-control column-filter" data-search-fields='["order_cost"]'></div></th-->
135                     <th><div class="input-group input-group-sm"><input type="text" class="form-control column-filter" data-search-fields='["fund.name"]'></div></th>
136                     <th>&nbsp;</th>
137                     <th>&nbsp;</th>
138                 </tr>
139             </thead>
140         </table>
141     </div>
142 [% ELSE %]
143     <p>
144         Invoice is closed, so you can't receive orders anymore.
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">
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><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% order.biblionumber | uri %]">[% order.title | html %]</a>
238                 [% IF ( order.author ) %] / [% order.author | html %][% END %]
239                 [% IF ( order.isbn ) %] - [% order.isbn | html %][% END %]
240                 [% IF ( order.publishercode ) %]
241                     <br />Publisher: [% order.publishercode | html %]
242                     [%- IF    ( order.publicationyear > 0) -%], [% order.publicationyear | html %]
243                     [%- ELSIF ( order.copyrightdate   > 0) -%] [% order.copyrightdate | html %]
244                     [% END %]
245                 [% END %]
246                 [% IF ( order.suggestionid ) %]
247                     <br/>
248                     Suggested by: [% order.surnamesuggestedby | html %][% IF ( order.firstnamesuggestedby ) %], [% order.firstnamesuggestedby | html %] [% END %]
249                     (<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid=[% order.suggestionid | uri %]&amp;op=show">suggestion #[% order.suggestionid | html %]</a>)
250                 [% END %]
251                 <br />
252                 [% IF ( order.order_internalnote ) %]
253                     <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>
254                 [% ELSE %]
255                     [<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>]
256                 [% END %]
257                 [% IF ( order.order_vendornote ) %]
258                     <p class="ordernote"><strong>Vendor note: </strong>[% order.order_vendornote | html %]</p>
259                 [% ELSE %]
260                     [<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>]
261                 [% END %]
262                 </td>
263                 <td>
264                   <a href="/cgi-bin/koha/acqui/showorder.pl?ordernumber=[% order.ordernumber | uri %]" class="previewData">[% tp('noun', 'Order') | html %]</a><br>
265                   <a href="/cgi-bin/koha/catalogue/showmarc.pl?id=[% order.biblionumber | uri %]" class="previewData">MARC</a><br>
266                   <a href="/cgi-bin/koha/catalogue/showmarc.pl?viewas=card&amp;id=[% order.biblionumber | uri %]" class="previewData">Card</a>
267                 </td>
268                 <td>[% order.replacementprice | $Price %]</td>
269                 <td>[% order.quantityreceived | html %]</td>
270                 <td>[% order.budget.budget_name | html %]</td>
271                 <td>[% order.ecost | $Price %]</td>
272                 <td>[% order.unitprice | $Price %]</td>
273                 <td>[% order.total | $Price %]</td>
274                 <td>
275                     [% IF loop_receive.cannot_cancel or ( order.basket.effective_create_items == "receiving" and loop_receive.holds > 0 ) %]
276                       [% IF loop_receive.cannot_cancel %]
277                         [% span_title = BLOCK %]
278                             Cannot cancel receipt of this order line because it
279                             was created from a partial receipt of order line no.
280                             [% order.parent_ordernumber | html %], which is
281                             already received. Try cancelling this one first and
282                             retry.
283                         [% END %]
284                       [% ELSE %]
285                         [%# FIXME Here we block the cancellation if holds exist. Actually it could be possible if items will be exist after the deletion %]
286                         [%# Some additional checks should be added in the pl file %]
287                         [% span_title = BLOCK %]
288                           Cannot cancel receipt of this order line because at least one reservation exists on the records.
289                         [% END %]
290                       [% END %]
291                       <span title="[% span_title | collapse | html %]">
292                           Can't cancel receipt
293                       </span>
294                     [% ELSE %]
295                         <a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid | uri %]&op=cancelreceipt&ordernumber=[% order.ordernumber | uri %]">Cancel receipt</a>
296                     [% END %]
297                 </td>
298             </tr>
299         [% END %]
300     </tbody>
301     </table>
302     </form>
303
304     [% ELSE %]There are no received orders.[% END %]
305 </div>
306
307 <div id="dataPreview" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="dataPreviewLabel" aria-hidden="true">
308     <div class="modal-dialog">
309     <div class="modal-content">
310     <div class="modal-header">
311         <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
312         <h3 id="dataPreviewLabel">MARC preview</h3>
313     </div>
314     <div class="modal-body">
315         <div id="loading"> <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading </div>
316     </div>
317     <div class="modal-footer">
318         <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
319     </div>
320     </div>
321     </div>
322 </div>
323
324 [% IF (invoiceclosedate) %]
325     <a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% invoiceid | uri %]">View invoice</a>
326 [% ELSE %]
327     <form action="/cgi-bin/koha/acqui/invoice.pl" method="get">
328         <input type="hidden" name="invoiceid" value="[% invoiceid | html %]" />
329         <fieldset class="action">
330             <input type="submit" value="Finish receiving" />
331         </fieldset>
332     </form>
333 [% END %]
334
335 [% END %]
336
337 </main>
338 </div> <!-- /.col-sm-10.col-sm-push-2 -->
339
340 <div class="col-sm-2 col-sm-pull-10">
341 <aside>
342
343 <form action="/cgi-bin/koha/acqui/parcel.pl" id="filterform" method="post">
344   <fieldset class="brief">
345     <h4>Filter</h4>
346     <ol>
347       <li>
348         <label for="summaryfilter">ISBN, author or title:</label>
349         <input type="text" name="summaryfilter" id="summaryfilter" value="[% summaryfilter | html %]"/>
350       </li>
351       <li>
352         <label for="basketfilter">Basket name:</label>
353         <input type="text" name="basketfilter" id="basketfilter" value="[% basketfilter | html %]"/>
354       </li>
355       <li>
356           <label for="basketgroupnamefilter">Basket group name:</label>
357           <input type="text" name="basketgroupnamefilter" id="basketgroupnamefilter" value="[% basketgroupnamefilter | html %]" />
358       </li>
359       <li>
360         <label for="orderfilter">Order line:</label>
361         <input type="text" name="orderfilter" id="orderfilter" value="[% orderfilter | html %]"/>
362       </li>
363       [% IF (UNIMARC) %]
364         <li>
365           <label for="eanfilter">EAN:</label>
366           <input type="text" name="eanfilter" id="eanfilter" value="[% eanfilter | html %]"/>
367         </li>
368       [% END %]
369     </ol>
370     <fieldset class="action">
371       <input type="hidden" value="search" name="op" />
372       <input type="hidden" value="[% invoiceid | html %]" name="invoiceid" />
373       <input type="submit" value="Filter" />
374       <a href="#" id="clear_form_filters">Clear</a>
375     </fieldset>
376   </fieldset>
377 </form>
378 [% INCLUDE 'acquisitions-menu.inc' %]
379     </aside>
380 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
381 </div> <!-- /.row -->
382
383 [% MACRO jsinclude BLOCK %]
384     [% Asset.js("js/acquisitions-menu.js") | $raw %]
385     [% INCLUDE 'datatables.inc' %]
386     [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %]
387     [% Asset.js("lib/jquery/plugins/jquery.cookie.min.js") | $raw %]
388     <style>#dataPreview { width : 80%; } @media (max-width: 767px) { #dataPreview { margin: 0; width : auto; } }</style>
389     <script>
390         dt_overwrite_html_sorting_localeCompare();
391         var sticky_filters = [% sticky_filters | html %];
392         var columns_filter = {};
393
394         function query_from_filters( base_query ) {
395
396             var query_and = [];
397
398             var summary      = $("#summaryfilter").val();
399             var basket_group = $("#basketgroupnamefilter").val();
400             var basket_name  = $("#basketfilter").val();
401             var order_id     = $("#orderfilter").val();
402             var ean          = $("#eanfilter").val();
403
404             // ean == undefined if the HTML doesn't have it
405             ean = (ean === undefined) ? '' : ean;
406
407             if ( basket_name != "" ) {
408                 query_and.push( { "basket.name": { "like": '%'+basket_name+'%' } } );
409             }
410             if (basket_group != "") {
411                 query_and.push( { "basket.basket_group.name": { "like": '%'+basket_group+'%' } } );
412             }
413             if (summary != "") {
414                 query_and.push( { "-or": [{"biblio.title":  { "like": '%'+summary+'%' } },
415                             {"biblio.author": { "like": '%'+summary+'%' } },
416                             {"biblio.isbn":   { "like": '%'+summary+'%' } } ] } );
417             }
418             if (ean != "") {
419                 query_and.push( { "biblio.ean": ean } );
420             }
421
422             $(".column-filter").each(function () {
423                 var search_fields = $(this).data('search-fields');
424                 var value = this.value;
425
426                 if ( value != '' &&
427                      value != undefined ) { // skip if empty
428
429                     var columns_filters = [];
430
431                     search_fields.forEach( function (item) {
432                         if ( item === "me.order_id" ||
433                              item === "me.replacement_price" ||
434                              item === "me.quantity" ||
435                              item === "me.ecost" ) {
436                             // For numbers, we do 'starts with'
437                             var object = {};
438                             object[item] = { "like": value+'%' };
439                             columns_filters.push( object );
440                         }
441                         else {
442                             var object = {};
443                             object[item] = { "like": '%'+value+'%' };
444                             columns_filters.push( object );
445                         }
446                     });
447
448                     if ( columns_filters.length > 1 ) {
449                         query_and.push( { "-or": columns_filters } );
450                     }
451                     else if ( columns_filters.length > 0 ) {
452                         query_and.push( columns_filters[0] );
453                     }
454                 }
455             });
456
457             var query_params = [];
458
459             if ( query_and.length > 0 ) {
460                 query_and.push(base_query);
461                 query_params.push('q=' + encodeURIComponent(JSON.stringify({ "-and": query_and })));
462             }
463
464             if ( order_id != "" ) {
465                 query_params.push("order_id="+order_id);
466             }
467
468             return query_params;
469         }
470
471         function _escape_str(s){
472             return s != null ? s.escapeHtml() : "";
473         }
474         function _escape_price(p){
475             return p != null ? p.escapeHtml().format_price() : "";
476         }
477
478         $(document).ready(function(){
479
480             if ( $("#receivedt").length ) {
481                 var receivedt = $("#receivedt").dataTable($.extend(true, {}, dataTablesDefaults, {
482                     "bStateSave": true,
483                     "iCookieDuration": 60*60*24*1000, // 1000 days
484                     "iDisplayLength": 10,
485                     "aLengthMenu": [[5, 10, 20, 50, 100, -1], [5, 10, 20, 50, 100, _("All")]],
486                     "aoColumnDefs": [
487                         { "aTargets": [ 5, -1 ], "bSortable": false, "bSearchable": false },
488                     ],
489                     "aoColumns": [
490                         { "sType": "html" },
491                         { "sType": "html" },
492                         { "sType": "html" },
493                         { "sType": "num-html" },
494                         { "sType": "anti-the" },
495                         null,
496                         null,
497                         null,
498                         null,
499                         null,
500                         null,
501                         null,
502                         null
503                     ],
504                     "sPaginationType": "full"
505                 }));
506             }
507
508             var base_query   = { "basket.vendor_id": [% booksellerid | html %]  };
509             var query_params = query_from_filters( base_query );
510
511             var THE_query = query_params.join("&");
512
513             var pending_orders_url = '/api/v1/acquisitions/orders?only_active=1';
514             var pending_orders_table = $("#pending_orders").api({
515                 "ajax": {
516                     "url": pending_orders_url + '&' + THE_query
517                 },
518                 "header_filter": true,
519                 "embed": [
520                     "basket.basket_group",
521                     "biblio.active_orders+count",
522                     "biblio.holds+count",
523                     "biblio.items+count",
524                     "biblio.suggestions.suggester",
525                     "fund",
526                     "current_item_level_holds+count",
527                     "items"
528                 ],
529                 "stateSave": true, // remember state on page reload
530                 "orderCellsTop": true, // tell the datatable sorting is done on the top row
531                 "fixedHeader": true,
532                 'dom': 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
533                 "drawCallback": function (settings) {
534                     $(".previewData").on("click", function(e){
535                         e.preventDefault();
536                         var ltitle = $(this).text();
537                         var page = $(this).attr("href");
538                         $("#dataPreviewLabel").text(ltitle);
539                         $("#dataPreview .modal-body").load(page + " div");
540                         $('#dataPreview').modal({show:true});
541                     });
542                 },
543                 "columnDefs": [ {
544                     "targets": [3,4,5,9],
545                     "render": function (data, type, row, meta) {
546                         return _escape_str(data);
547                     }
548                 },
549                 {
550                     "targets": [8,10],
551                     "render": function (data, type, row, meta) {
552                         return _escape_price(data);
553                     }
554                 } ],
555                 "columns": [
556                     { "data": "basket.name",
557                       "orderable": true,
558                       "render": function(data, type, row, meta) {
559                         if (type != 'display') return _escape_str(data);
560                         return "<a href=\"/cgi-bin/koha/acqui/basket.pl?basketno=" + encodeURIComponent(row.basket.basket_id) + "\">" + data.escapeHtml() + " (" + row.basket.basket_id.escapeHtml() + ")</a>";
561                       }
562                     },
563                     { "data": "basket.basket_group.name",
564                       "orderable": true,
565                       "render": function(data, type, row, meta) {
566                         if ( type != 'display' ) {
567                             return _escape_str(data);
568                         }
569                         if ( row.basket.basket_group_id == null ) {
570                             return _("No basket group");
571                         }
572                         else {
573                             return "<a href=\"/cgi-bin/koha/acqui/basketgroup.pl?op=add&amp;booksellerid="
574                                     + encodeURIComponent(row.basket.vendor_id) + "&amp;basketgroupid="
575                                     + encodeURIComponent(row.basket.basket_group_id) + "\">"
576                                     + row.basket.basket_group.name.escapeHtml() + " (" + row.basket.basket_group_id.escapeHtml() + ")</a>";
577                         }
578                       }
579                     },
580                     {
581                         "data": "order_id",
582                         "render": function(data, type, row, meta) {
583                             if (type != 'display') return _escape_str(data);
584                             return "<a href=\"neworderempty.pl?ordernumber="+encodeURIComponent(data)+"&amp;booksellerid="+encodeURIComponent(row.basket.vendor_id)+"\">"+data.escapeHtml()+"</a>";
585                         }
586                     },
587                     {
588                         "data": "biblio.author",
589                         "visible": false,
590                         "searchable": true,
591                         "orderable": false
592                     },
593                     {
594                         "data": "biblio.title",
595                         "visible": false,
596                         "searchable": true,
597                         "orderable": false
598                     },
599                     {
600                         "data": "biblio.isbn",
601                         "visible": false,
602                         "searchable": true,
603                         "orderable": false
604                     },
605                     {
606                         "data": function(row, type, val, meta) {
607                             var result = '';
608                             if ( row.biblio_id != null ) {
609                                 result = "<p><a href=\"/cgi-bin/koha/catalogue/detail.pl?biblionumber="+encodeURIComponent(row.biblio_id)+"\">"+row.biblio.title.escapeHtml()+"</a>";
610                                 if ( row.biblio.author != null )
611                                     result += _(" by ") + row.biblio.author.escapeHtml();
612                                 if ( row.biblio.isbn != null )
613                                     result += " &ndash; " + row.biblio.isbn.escapeHtml();
614                                 if ( row.biblio.publisher != null ) {
615                                     result += "<br/>" + _("Publisher: ") + row.biblio.publisher.escapeHtml();
616                                     if ( row.biblio.publication_year != null ) {
617                                         result += ", " + row.biblio.publication_year.escapeHtml();
618                                     }
619                                     else if ( row.biblio.copyright_date != null ) {
620                                         result += row.biblio.copyright_date.escapeHtml();
621                                     }
622                                 }
623                                 var suggestions = row.biblio.suggestions;
624                                 if ( suggestions != null && suggestions.length > 0 ) {
625                                     var suggestion = suggestions[0];
626                                     if ( suggestion.suggester != null ) {
627                                         var suggester = suggestion.suggester;
628                                         var suggested_by = [];
629                                         if ( suggester.surname != null ) {
630                                             suggested_by.push(suggester.surname.escapeHtml());
631                                         }
632                                         if ( suggester.firstname != null ) {
633                                             suggested_by.push(suggester.firstname.escapeHtml());
634                                         }
635
636                                             result += "<br/>" + _("Suggested by: ") +
637                                                         '<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid='
638                                                             + encodeURIComponent(suggestion.suggestionid)
639                                                             + '&amp;op=show">'
640                                                             + suggested_by.join(", ")
641                                                             + " (#" + suggestions[0].suggestionid.escapeHtml() + ")</a>"; // FIXME: could be changed if we allow matching multiple suggestions
642                                     }
643                                 }
644                                 result += '</p>';
645                             }
646
647                             var internal_note = row.internal_note;
648                             if ( internal_note != null && internal_note != '' ) {
649                                 result += '<p class="ordernote"><strong>'
650                                             + _("Internal note: ")
651                                             + '</strong>' + internal_note.escapeHtml()
652                                             + ' [<a href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber='
653                                             + encodeURIComponent(row.order_id) + '&amp;referrer=/cgi-bin/koha/acqui/parcel.pl%3Finvoiceid=[% invoiceid | uri %]'
654                                             + '&type=internal">' + _("Change internal note") + '</a>]</p>';
655                             }
656                             else {
657                                 result += ' [<a href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber='
658                                             + encodeURIComponent(row.order_id) + '&amp;referrer=/cgi-bin/koha/acqui/parcel.pl%3Finvoiceid=[% invoiceid | uri %]'
659                                             + '&type=internal">' + _("Add internal note") + '</a>]';
660                             }
661
662                             var vendor_note = row.vendor_note;
663                             if ( vendor_note != null && vendor_note != '' ) {
664                                 result += '<p class="ordernote"><strong>'
665                                             + _("Vendor note: ")
666                                             + '</strong>' + vendor_note.escapeHtml() + '</p>';
667                             }
668                             else {
669                                 result += ' [<a href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber='
670                                             + encodeURIComponent(row.order_id) + '&amp;referrer=/cgi-bin/koha/acqui/parcel.pl%3Finvoiceid=[% invoiceid | uri %]'
671                                             + '&type=vendor">' + _("Add vendor note") + '</a>]';
672                             }
673
674                             return result;
675                         },
676                         "orderable": false
677                     },
678                     {
679                         "data": function( row, type, val, meta) {
680                             var result = '<a href="/cgi-bin/koha/acqui/showorder.pl?ordernumber=' + encodeURIComponent(row.order_id) + '" class="previewData">' + _("Order") + '</a><br>'
681                                 + '<a href="/cgi-bin/koha/catalogue/showmarc.pl?id=' + encodeURIComponent(row.biblio_id) + '" class="previewData">' + _("MARC") + '</a><br>'
682                                 + '<a href="/cgi-bin/koha/catalogue/showmarc.pl?viewas=card&amp;id=' + encodeURIComponent(row.biblio_id) + '" class="previewData">' + _("Card") + '</a>';
683                             return result;
684                         },
685                         "orderable": false
686                     },
687                     {
688                         "data": "replacement_price"
689                     },
690                     {
691                         "data": "quantity",
692                         "orderable": true
693                     },
694                     {
695                         "data": "ecost"
696                     },
697                     {
698                         "data": function ( row, type, val, meta ) {
699                             return (row.quantity * row.ecost).format_price();
700                         },
701                         "orderable": false // FIXME: How can we do it in DBIC?
702                     },
703                     {
704                         "data": "fund.name",
705                         "render": function(data, type, row, meta) {
706                             if (type != 'display') return data.escapeHtml();
707                             return row.fund.name.escapeHtml();
708                         }
709                     },
710                     {
711                         "data": function( row, type, val, meta ) {
712                             return '<a href="orderreceive.pl?ordernumber='
713                                     + encodeURIComponent(row.order_id) + '&amp;invoiceid=[% invoiceid | uri %]' + '">'
714                                     + _("Receive") + '</a><br/>'
715                                     + '<a href="#" onclick="transfer_order_popup(' + row.order_id.escapeHtml() + '); return false;">'
716                                     + _("Transfer") + '</a>';
717                         },
718                         "orderable": false
719                     },
720                     {
721                         "data": function( row, type, val, meta ) {
722                             var result = "";
723
724                             if ( row.current_holds_count > 0 ) {
725                                 result += '<span class="button" title="'
726                                         + _("Can't cancel order, (%s) holds are linked with this order. Cancel holds first").format( row.holds_count.escapeHtml() ) + '">'
727                                         + _("Can't cancel order") + '</span><br/>';
728                             }
729                             else {
730                                 result += '<a href="/cgi-bin/koha/acqui/cancelorder.pl?ordernumber='
731                                             + encodeURIComponent(row.order_id)
732                                             + '&biblionumber=' + encodeURIComponent(row.biblio_id)
733                                             + '&referrer=/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid | uri %]">'
734                                             + _("Cancel order") + '</a><br/>';
735                             }
736
737                             if ( row.biblio != null ) {
738                                 if ( row.biblio.items_count - row.items.length > 0 ||
739                                     row.biblio.active_orders_count > 1 ||
740                                     row.biblio.subscriptions_count > 0 ||
741                                     row.biblio.holds_count > 0 ) { // biblio can be deleted
742                                     result += '<span class="button" title="'
743                                             + _("Can't delete catalog record, see constraints below") + '">'
744                                             + _("Can't cancel order and delete catalog record") + '</span><br>';
745                                 }
746                                 else {
747                                     result += '<a href="/cgi-bin/koha/acqui/cancelorder.pl?ordernumber='
748                                             + encodeURIComponent(row.order_id) + '&biblionumber=' + encodeURIComponent(row.biblio_id)
749                                             + '&del_biblio=1&referrer="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[$ invoiceid | uri ]">'
750                                             + _("Cancel order and catalog record") + '</a><br/>';
751                                 }
752
753                                 if ( row.biblio.items_count - row.items.length > 0 ) {
754                                     result += '<strong title="'
755                                             + _("Can't delete catalog record, because of %s existing item(s)").format(row.items.length)
756                                             +'">' + (row.biblio.items_count - row.items.length) + _(" item(s) left") + '</strong><br/>';
757                                 }
758
759                                 if ( row.biblio.active_orders_count > 1 ) {
760                                     result += '<strong title="'
761                                             + _("Can't delete catalog record, delete other orders linked to it first") + '">'
762                                             + (row.biblio.active_orders_count - 1) + _(" order(s) left") + '</strong><br/>';
763                                 }
764
765                                 if ( row.biblio.subscriptions_count > 0 ) {
766                                     result += '<strong title="' + _("Can't delete catalog record, delete subscriptions first") + '">'
767                                             + _("%s subscription(s) left").format(row.biblio.subscriptions_count)
768                                             + '</strong><br>';
769                                 }
770
771                                 if ( row.biblio.holds_count > 0 ) {
772                                     result += '<strong title="' + _("Can't delete catalog record or order, cancel holds first") + '">'
773                                             + _("%s hold(s) left").format(row.biblio.holds_count) + '</strong>';
774                                 }
775                             }
776
777                             return result;
778                         },
779                         "orderable": false
780                     }
781                 ]
782             });
783
784             // column filter events handling
785             $(".column-filter").each(function () {
786                 $(this).on( 'keyup change', function () {
787                     // recalculate the query
788                     var query_params = query_from_filters( base_query );
789                     // refresh the datatable as appropriate
790                     if ( query_params.length > 0 ) {
791                         pending_orders_table.api().ajax.url( pending_orders_url + '&' + query_params.join("&") );
792                     }
793                     else {
794                         pending_orders_table.api().ajax.url( pending_orders_url + '&q=' + encodeURI(JSON.stringify(base_query)) );
795                     }
796                     pending_orders_table.api().ajax.reload( null, false );
797                 });
798             });
799
800             $("#filterform").on("submit", function(e) {
801                 e.preventDefault();
802
803                 // Save the filters in the cookie
804                 $.cookie("filter_parcel_summary", $("#summaryfilter").val());
805                 $.cookie("filter_parcel_basketname", $("#basketfilter").val());
806                 $.cookie("filter_parcel_orderno", $("#orderfilter").val());
807                 $.cookie("filter_parcel_basketgroupname", $("#basketgroupnamefilter").val());
808                 $.cookie("filter_parcel_ean", $("#eanfilter").val());
809
810                 var query_params = query_from_filters( base_query );
811
812                 if ( query_params.length > 0 ) {
813                     pending_orders_table.api().ajax.url( pending_orders_url + '&' + query_params.join("&") );
814                 }
815                 else {
816                     pending_orders_table.api().ajax.url( pending_orders_url + '&q=' + encodeURI(JSON.stringify(base_query)) );
817                 }
818                 pending_orders_table.api().ajax.reload( null, false );
819             });
820
821             $('#clear_form_filters').on("click", function(){
822                 $(this).closest('form').find("input[type=text], textarea").val("");
823                 pending_orders_table.api().ajax.url(pending_orders_url + '&q=' + encodeURI(JSON.stringify(base_query))).draw();
824             });
825
826             $(".previewData").on("click", function(e){
827                 e.preventDefault();
828                 var ltitle = $(this).text();
829                 var page = $(this).attr("href");
830                 $("#dataPreviewLabel").text(ltitle);
831                 $("#dataPreview .modal-body").load(page + " div");
832                 $('#dataPreview').modal({show:true});
833             });
834
835             $("#dataPreview").on("hidden.bs.modal", function(){
836                 $("#dataPreviewLabel").html("");
837                 $("#dataPreview .modal-body").html("<div id=\"loading\"><img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> "+_("Loading")+"</div>");
838             });
839         });
840
841         // Case-insensitive version of jquery's contains function
842         jQuery.extend(jQuery.expr[':'], {
843             icontains : "jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0"
844         });
845
846         // Contains exactly function
847         jQuery.extend(jQuery.expr[':'], {
848             containsExactly: "$(a).text() == m[3]"
849         });
850
851         function transfer_order_popup(ordernumber) {
852         var url = "/cgi-bin/koha/acqui/transferorder.pl?"
853             + "ordernumber=" + ordernumber
854             window.open(url, 'TransferOrder');
855         }
856     </script>
857 [% END %]
858
859 [% INCLUDE 'intranet-bottom.inc' %]