Bug 36233: Use select2 to load vendors on invoice search
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / acqui / invoices.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE AuthorisedValues %]
4 [% USE KohaDates %]
5 [% USE Branches %]
6 [% SET footerjs = 1 %]
7 [% PROCESS 'i18n.inc' %]
8 [% INCLUDE 'doc-head-open.inc' %]
9 <title>[% FILTER collapse %]
10     [% t("Invoices") | html %] &rsaquo;
11     [% t("Acquisitions") | html %] &rsaquo;
12     [% t("Koha") | html %]
13 [% END %]</title>
14 [% INCLUDE 'doc-head-close.inc' %]
15
16 </head>
17
18 <body id="acq_invoices" class="acq">
19 [% WRAPPER 'header.inc' %]
20     [% INCLUDE 'acquisitions-search.inc' %]
21 [% END %]
22
23 [% WRAPPER 'sub-header.inc' %]
24     [% WRAPPER breadcrumbs %]
25         [% WRAPPER breadcrumb_item %]
26             <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a>
27         [% END %]
28         [% WRAPPER breadcrumb_item bc_active= 1 %]
29             <span>Invoices</span>
30         [% END %]
31     [% END #/ WRAPPER breadcrumbs %]
32 [% END #/ WRAPPER sub-header.inc %]
33
34 <div class="main container-fluid">
35     <div class="row">
36         <div class="col-sm-10 col-sm-push-2">
37             <main>
38                 [% INCLUDE 'messages.inc' %]
39
40                 <h1>Invoices</h1>
41                 [% IF ( do_search ) %]
42                     [% IF invoices %]
43                         [% BLOCK invoices_table %]
44                             [% IF closed %]
45                                 [% SET tab = 'closed' %]
46                             [% ELSE %]
47                                 [% SET tab = 'opened' %]
48                             [% END %]
49                             <input type="checkbox" style="vertical-align: middle;" id="show_only_subscription_[% tab | html %]" class="show_only_subscription" data-tableid="[% tab | html %]resultst"/>
50                             <label for="show_only_subscription_[% tab | html %]">
51                                 Show only subscriptions
52                             </label>
53                             <p><a id="CheckAll[% tab | html %]table" data-cb="[% tab | html %]" class="checkall" href="#"><i class="fa fa-check"></i> Select all</a> | <a id="UncheckAll[% tab | html %]table" data-cb="[% tab | html %]" class="uncheckall" href="#"><i class="fa fa-times"></i> Clear all</a></p>
54                             <table id="[% tab | html %]resultst" class="result">
55                                 <thead>
56                                     <tr>
57                                         [% IF CAN_user_acquisition_merge_invoices %]
58                                             <th>&nbsp;</th>
59                                         [% END %]
60                                         <th>&nbsp;</th>
61                                         <th>Invoice number</th>
62                                         <th>Vendor</th>
63                                         <th>Shipment date</th>
64                                         <th>Billing date</th>
65                                         <th>Received bibliographic records</th>
66                                         <th>Received items</th>
67                                         <th>Status</th>
68                                         <th>&nbsp;</th>
69                                     </tr>
70                                 </thead>
71                                 <tbody>
72                                     [% FOREACH invoice IN invoices %]
73                                         <tr data-invoiceid="[% invoice.invoiceid | html %]" data-booksellerid="[% invoice.booksellerid | html %]" data-shipmentdate="[% invoice.shipmentdate | $KohaDates %]" data-billingdate="[% invoice.billingdate | $KohaDates %]" data-shipmentcost="[% invoice.shipmentcost | html %]" data-shipment_budgetid="[% invoice.shipmentcost_budgetid | html %]" data-closedate="[% invoice.closedate | $KohaDates %]">
74                                             [% IF CAN_user_acquisition_merge_invoices %]
75                                                 <td>[% invoice.is_linked_to_subscriptions | html %]</td>
76                                             [% END %]
77                                             <td><input type="checkbox" class="select-invoice" value="[% invoice.invoiceid | html %]" /></td>
78                                             <td><a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% invoice.invoiceid | uri %]">[% invoice.invoicenumber | html %]</a></td>
79                                             <td><a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% invoice.booksellerid | uri %]">[% invoice.suppliername | html %]</a></td>
80                                             <td data-order="[% invoice.shipmentdate | html %]">
81                                                 [% invoice.shipmentdate | $KohaDates %]
82                                             </td>
83                                             <td data-order="[% invoice.billingdate | html %]">
84                                                 [% invoice.billingdate | $KohaDates %]
85                                             </td>
86                                             <td>[% invoice.receivedbiblios | html %]</td>
87                                             <td>[% invoice.receiveditems | html %]</td>
88                                             <td>
89                                                 [% IF invoice.closedate %]
90                                                     <span>Closed on [% invoice.closedate | $KohaDates %]</span>
91                                                 [% ELSE %]
92                                                     <span>Open</span>
93                                                 [% END %]
94                                             </td>
95                                             <td>
96
97                                                 <div class="btn-group dropup">
98                                                     <a class="btn btn-default btn-xs dropdown-toggle" id="invoiceactions[% invoice.invoiceid | html %]" role="button" data-toggle="dropdown" href="#">
99                                                         Actions <b class="caret"></b>
100                                                     </a>
101                                                     <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="invoiceactions[% invoice.invoiceid | html %]">
102                                                         <li><a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% invoice.invoiceid | uri %]"><i class="fa fa-search"></i> Details</a></li>
103                                                         [% IF invoice.closedate %]
104                                                             [% IF CAN_user_acquisition_reopen_closed_invoices %]
105                                                                 <li><a href="invoice.pl?op=reopen&amp;invoiceid=[% invoice.invoiceid | uri %]&amp;referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber | uri %]%26supplier=[% booksellerid | uri %]%26shipmentdatefrom=[% shipmentdatefrom | $KohaDates %]%26shipmentdateto=[% shipmentdateto | $KohaDates %]%26billingdatefrom=[% billingdatefrom | $KohaDates %]%26billingdateto=[% billingdateto | $KohaDates %]%26isbneanissn=[% isbneanissn | uri %]%26title=[% title | uri %]%26author=[% author | uri %]%26publisher=[% publisher | uri %]%26publicationyear=[% publicationyear | uri %]%26branch=[% branch | uri %]"><i class="fa-solid fa-rotate"></i> Reopen</a></li>
106                                                             [% END %]
107                                                         [% ELSE %]
108                                                             [% IF CAN_user_acquisition_edit_invoices %]
109                                                                 <li><a href="invoice.pl?op=close&amp;invoiceid=[% invoice.invoiceid | uri %]&amp;referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber | uri %]%26supplier=[% booksellerid | uri %]%26shipmentdatefrom=[% shipmentdatefrom | $KohaDates %]%26shipmentdateto=[% shipmentdateto | $KohaDates %]%26billingdatefrom=[% billingdatefrom | $KohaDates %]%26billingdateto=[% billingdateto | $KohaDates %]%26isbneanissn=[% isbneanissn | uri %]%26title=[% title | uri %]%26author=[% author | uri %]%26publisher=[% publisher | uri %]%26publicationyear=[% publicationyear | uri %]%26branch=[% branch | uri %]"><i class="fa fa-times-circle"></i> Close</a></li>
110                                                             [% END %]
111                                                         [% END # /IF invoice.closedate %]
112                                                         [% UNLESS invoice.receivedbiblios || invoice.receiveditems %]
113                                                             [% IF CAN_user_acquisition_delete_invoices %]
114                                                                 <li><a href="invoice.pl?op=delete&amp;invoiceid=[% invoice.invoiceid | uri %]&amp;referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber | uri %]%26supplier=[% booksellerid | uri %]%26shipmentdatefrom=[% shipmentdatefrom | $KohaDates %]%26shipmentdateto=[% shipmentdateto | $KohaDates %]%26billingdatefrom=[% billingdatefrom | $KohaDates %]%26billingdateto=[% billingdateto | $KohaDates %]%26isbneanissn=[% isbneanissn | uri %]%26title=[% title | uri %]%26author=[% author | uri %]%26publisher=[% publisher | uri %]%26publicationyear=[% publicationyear | uri %]%26branch=[% branch | uri %]" class="delete_invoice"><i class="fa fa-trash-can"></i> Delete</a></li>
115                                                             [% END %]
116                                                         [% END %]
117                                                     </ul>
118                                                 </div> <!-- /.btn-group dropup -->
119                                             </td>
120                                         </tr>
121                                     [% END # /FOREACH invoice %]
122                                 </tbody>
123                             </table> <!-- /#[% tab | html %]resultst -->
124
125                             [% IF CAN_user_acquisition_merge_invoices %]
126                                 [% IF tab == 'closed' %]
127                                     <a class="btn btn-default merge" id="merge_closed" href="#merge_invoices" data-table="closedresultst"><i class="fa fa-compress"></i> Merge selected invoices</a>
128                                     <a class="btn btn-default" id="open_sel" href="#reopen_selected" data-table="closedresultst" data-op="reopen" data-referer="referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber | uri %]%26supplier=[% booksellerid | uri %]%26shipmentdatefrom=[% shipmentdatefrom | $KohaDates %]%26shipmentdateto=[% shipmentdateto | $KohaDates %]%26billingdatefrom=[% billingdatefrom | $KohaDates %]%26billingdateto=[% billingdateto | $KohaDates %]%26isbneanissn=[% isbneanissn | uri %]%26title=[% title | uri %]%26author=[% author | uri %]%26publisher=[% publisher | uri %]%26publicationyear=[% publicationyear | uri %]%26branch=[% branch | uri %]"><i class="fa-solid fa-rotate"></i> Reopen selected invoices</a>
129                                 [% ELSE  %]
130                                     <a class="btn btn-default merge" id="merge_open" href="#merge_invoices" data-table="openedresultst"><i class="fa fa-compress"></i> Merge selected invoices</a>
131                                     <a class="btn btn-default" id="close_sel" href="#close_selected" data-table="openedresultst" data-op="close" data-referer="referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber | uri %]%26supplier=[% booksellerid | uri %]%26shipmentdatefrom=[% shipmentdatefrom | $KohaDates %]%26shipmentdateto=[% shipmentdateto | $KohaDates %]%26billingdatefrom=[% billingdatefrom | $KohaDates %]%26billingdateto=[% billingdateto | $KohaDates %]%26isbneanissn=[% isbneanissn | uri %]%26title=[% title | uri %]%26author=[% author | uri %]%26publisher=[% publisher | uri %]%26publicationyear=[% publicationyear | uri %]%26branch=[% branch | uri %]"><i class="fa fa-times-circle"></i> Close selected invoices</a>
132                                 [% END # /IF tab == 'closed' %]
133                             [% END # /IF CAN_user_acquisition_merge_invoices %]
134                         [% END # /BLOCK invoices_table %]
135
136                         [% WRAPPER tabs id= "invoicestabs" %]
137                             [% WRAPPER tabs_nav %]
138                                 [% WRAPPER tab_item tabname= "opened" bt_active= 1 %]
139                                     <span>Open invoices</span> ([% openedinvoices.size || 0 | html %])
140                                 [% END %]
141                                 [% WRAPPER tab_item tabname= "closed" %]
142                                     <span>Closed invoices</span> ([% closedinvoices.size || 0 | html %])
143                                 [% END %]
144                             [% END %]
145                             [% WRAPPER tab_panels %]
146                                 [% WRAPPER tab_panel tabname="opened" bt_active= 1 %]
147                                     [% IF openedinvoices %]
148                                         [% INCLUDE invoices_table invoices = openedinvoices %]
149                                     [% ELSE %]
150                                         <div class="dialog message">
151                                             <p>Your search returned no open invoices.</p>
152                                         </div>
153                                     [% END %]
154                                 [% END # /#opened %]
155
156                                 [% WRAPPER tab_panel tabname="closed" %]
157                                     [% IF closedinvoices %]
158                                         [% INCLUDE invoices_table invoices = closedinvoices closed = 1 %]
159                                     [% ELSE %]
160                                         <div class="dialog message">
161                                             <p>Your search returned no closed invoices.</p>
162                                         </div>
163                                     [% END %]
164                                 [% END # /#closed %]
165                             [% END # /tab_panels %]
166                         [% END # /#invoicestabs %]
167
168                         <div id="merge_invoices">
169                             <form id="merge_invoice_form" class="validated" action="/cgi-bin/koha/acqui/invoice.pl" method="post">
170                                 [% INCLUDE 'csrf-token.inc' %]
171                                 <fieldset class="rows">
172                                     <ol>
173                                         <li><h2>Merge invoices</h2></li>
174                                         <li>
175                                             <table id="merge_table">
176                                                 <thead>
177                                                     <tr>
178                                                         <th>Invoice number</th>
179                                                         <th>Shipment date</th>
180                                                         <th>Billing date</th>
181                                                         <th>Shipment cost</th>
182                                                     </tr>
183                                                 </thead>
184                                                 <tbody>
185                                                 </tbody>
186                                             </table>
187                                         </li>
188
189
190                                         <li>
191                                             <label for="merge_invoicenumber" class="required">Invoice number:</label>
192                                             <input type="text" size="10" id="merge_invoicenumber" name="invoicenumber" value="" class="required" required="required" />
193                                             <span class="required">Required</span>
194                                         </li>
195
196                                         <li>
197                                             <label for="merge_shipmentdate">Shipment date:</label>
198                                             <input type="text" size="10" id="merge_shipmentdate" name="shipmentdate" value="" class="flatpickr" />
199                                             <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
200                                         </li>
201
202                                         <li>
203                                             <label for="merge_billingdate">Billing date:</label>
204                                             <input type="text" size="10" id="merge_billingdate" name="billingdate" value="" class="flatpickr" />
205                                             <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
206                                         </li>
207
208                                         <li>
209                                             <label for="merge_shipmentcost">Shipment cost:</label>
210                                             <input class="decimal" type="text" size="10" id="merge_shipmentcost" name="shipmentcost" value="" />
211                                         </li>
212                                         <li>
213                                             <label for="merge_shipment_budgetid">Fund:</label>
214                                             <select id="merge_shipment_budgetid" name="shipment_budget_id">
215                                                 <option value="">No fund</option>
216                                                 [% FOREACH budget IN budgets_loop %]
217                                                     <option value="[% budget.budget_id | html %]">[% budget.budget_name | html %]</option>
218                                                 [% END %]
219                                             </select>
220                                         </li>
221
222                                         <li>
223                                             <span class="label">Status:</span> <span id="merge_status"></span>
224                                         </li>
225                                         <li>
226                                             <input type="submit" class="btn btn-primary" value="Merge" />
227                                         </li>
228                                     </ol>
229                                     <input type="hidden" name="op" value="cud-mod" />
230                                     <input type="hidden" id="merge_invoiceid" name="invoiceid" value="" />
231                                 </fieldset> <!-- /.rows -->
232                             </form> <!-- /#merge_invoice_form -->
233                         </div> <!-- /#merge_invoices -->
234                     [% ELSE # IF invoices %]
235                         <p>Sorry, but there are no results for your search.</p>
236                         <p>Search was:
237                             <ul>
238                                 [% IF ( invoicenumber ) %]
239                                     <li>Invoice number: [% invoicenumber | html %]</li>
240                                 [% END %]
241                                 [% IF booksellerid %]
242                                     <li>Vendor: [% suppliername | html %]</li>
243                                 [% END %]
244                                 [% IF shipmentdatefrom %]
245                                     <li>
246                                         <span>Shipment date:</span>
247                                         [% IF shipmentdateto %]
248                                             <span>From [% shipmentdatefrom | $KohaDates %]</span>
249                                             <span>To [% shipmentdateto | $KohaDates %]</span>
250                                         [% ELSE %]
251                                             <span>All since [% shipmentdatefrom | $KohaDates %]</span>
252                                         [% END %]
253                                     </li>
254                                 [% ELSE %]
255                                     [% IF shipmentdateto %]
256                                         <li>
257                                             Shipment date:
258                                             All until [% shipmentdateto | $KohaDates %]
259                                         </li>
260                                     [% END %]
261                                 [% END %]
262                                 [% IF billingdatefrom %]
263                                     <li>
264                                         <span>Billing date:</span>
265                                         [% IF billingdateto %]
266                                             <span>From [% billingdatefrom | $KohaDates %]</span>
267                                             <span>To [% billingdateto | $KohaDates %]</span>
268                                         [% ELSE %]
269                                             <span>All since [% billingdatefrom | $KohaDates %]</span>
270                                         [% END %]
271                                     </li>
272                                 [% ELSE %]
273                                     [% IF billingdateto %]
274                                         <li>
275                                             Billing date:
276                                             All until [% billingdateto | $KohaDates %]
277                                         </li>
278                                     [% END %]
279                                 [% END %]
280                                 [% IF ( isbneanissn ) %]
281                                     <li>ISBN/EAN/ISSN: [% isbneanissn | html %]</li>
282                                 [% END %]
283                                 [% IF ( title ) %]
284                                     <li>Title: [% title | html %]</li>
285                                 [% END %]
286                                 [% IF ( author ) %]
287                                     <li>Author: [% author | html %]</li>
288                                 [% END %]
289                                 [% IF ( publisher ) %]
290                                     <li>Publisher: [% publisher | html %]</li>
291                                 [% END %]
292                                 [% IF ( publicationyear ) %]
293                                     <li>Publication year: [% publicationyear | html %]</li>
294                                 [% END %]
295                                 [% IF ( branch ) %]
296                                     <li>Library: [% Branches.GetName( branch ) | html %]</li>
297                                 [% END %]
298                             </ul>
299                         </p>
300                     [% END # /IF invoices %]
301                 [% ELSE %]
302                     <p>Use the search form on the left to find invoices.</p>
303                 [% END %]<!-- do_search -->
304             </main>
305         </div> <!-- /.col-sm-10.col-sm-push-2 -->
306
307         <div class="col-sm-2 col-sm-pull-10">
308             <aside>
309                 <form action="" method="get">
310                     <fieldset class="sidebar brief">
311                         <h3>Search filters</h3>
312                         <ol>
313                             <li>
314                                 <label for="invoicenumber">Invoice number</label>
315                                 <input type="text" id="invoicenumber" name="invoicenumber" value="[% invoicenumber | html %]"
316                                     class="focus" />
317                             </li>
318                             <li>
319                                 <label for="supplier">Vendor:</label>
320                                 <select id="supplierid" name="supplierid">
321                                     [% IF ( supplier ) %]
322                                         <option selected="selected" value="[% supplier.id | html %]">[% supplier.name | html %]</option>
323                                     [% END %]
324                                 </select>
325                             </li>
326                             <li>
327                                 <fieldset class="brief">
328                                     <legend>Shipment date</legend>
329                                     <ol>
330                                         <li>
331                                             <label for="shipmentdatefrom">From:</label>
332                                             <input type="text" id="shipmentdatefrom" name="shipmentdatefrom" size="10" value="[% shipmentdatefrom | html %]" class="flatpickr" data-date_to="shipmentdateto" />
333                                             <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
334                                         </li>
335                                         <li>
336                                             <label for="shipmentdateto">To:</label>
337                                             <input type="text" id="shipmentdateto" name="shipmentdateto" size="10" value="[% shipmentdateto | html %]" class="flatpickr" />
338                                             <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
339                                         </li>
340                                     </ol>
341                                 </fieldset>
342                             </li>
343                             <li>
344                                 <fieldset class="brief">
345                                     <legend>Billing date</legend>
346                                     <ol>
347                                         <li>
348                                             <label for="billingdatefrom">From:</label>
349                                             <input type="text" id="billingdatefrom" name="billingdatefrom" size="10" value="[% billingdatefrom | html %]" class="flatpickr" data-date_to="billingdateto" />
350                                             <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
351                                         </li>
352                                         <li>
353                                             <label for="billingdateto">To:</label>
354                                             <input type="text" id="billingdateto" name="billingdateto" size="10" value="[% billingdateto | html %]" class="flatpickr" />
355                                             <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
356                                         </li>
357                                     </ol>
358                                 </fieldset>
359                             </li>
360                             <li>
361                                 <label for="isbneanissn">ISBN / EAN / ISSN:</label>
362                                 <input type="text" id="isbneanissn" name="isbneanissn" value="[% isbneanissn | html %]" />
363                             </li>
364                             <li>
365                                 <label for="title">Title:</label>
366                                 <input type="text" id="title" name="title" value="[% title | html %]" />
367                             </li>
368                             <li>
369                                 <label for="author">Author:</label>
370                                 <input type="text" id="author" name="author" value="[% author | html %]" />
371                             </li>
372                             <li>
373                                 <label for="publisher">Publisher:</label>
374                                 <input type="text" id="publisher" name="publisher" value="[% publisher | html %]" />
375                             </li>
376                             <li>
377                                 <label for="publicationyear">Publication year:</label>
378                                 <input type="text" id="publicationyear" name="publicationyear" value="[% publicationyear | html %]" />
379                             </li>
380                             <li>
381                                 <label for="branch">Library:</label>
382                                 <select id="branch" name="branch">
383                                     <option value="">All</option>
384                                     [%# FIXME Should not we filter the libraries %]
385                                     [% PROCESS options_for_libraries libraries => Branches.all( selected => branch, unfiltered => 1 ) %]
386                                 </select>
387                             </li>
388                         [% FOR field IN additional_fields_for_invoice %]
389                             <li>
390                                 <label for="additional_field_[% field.id | html %]ID"> [% field.name | html %]: </label>
391                                 [% IF field.authorised_value_category %]
392                                     <select id="additional_field_[% field.id | html %]" name="additional_field_[% field.id | html %]">
393                                         <option value="">All</option>
394                                         [% FOREACH av IN AuthorisedValues.GetAuthValueDropbox(field.authorised_value_category) %]
395                                             [% IF av.authorised_value == additional_field_filters.${field.id} %]
396                                                 <option value="[% av.authorised_value | html %]" selected="selected">[% av.lib | html %]</option>
397                                             [% ELSE %]
398                                                 <option value="[% av.authorised_value | html %]">[% av.lib | html %]</option>
399                                             [% END %]
400                                         [% END %]
401                                     </select>
402                                 [% ELSE %]
403                                     <input id="additional_field_[% field.id | html %]" type="text" value="[% additional_field_filters.${field.id} | html %]" name="additional_field_[% field.id | html %]" />
404                                 [% END %]
405                             </li>
406                         [% END %]
407                         </ol>
408                     </fieldset> <!-- /.sidebar.brief -->
409                     <fieldset class="action">
410                         <input type="submit" class="btn btn-primary" value="Search" />
411                     </fieldset>
412                     <input type="hidden" name="op" id="op" value="do_search" />
413                 </form>
414                 [% INCLUDE 'acquisitions-menu.inc' %]
415             </aside>
416         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
417     </div> <!-- /.row -->
418
419 [% MACRO jsinclude BLOCK %]
420     [% Asset.js("js/acquisitions-menu.js") | $raw %]
421     [% INCLUDE 'datatables.inc' %]
422     [% INCLUDE 'calendar.inc' %]
423     [% INCLUDE 'select2.inc' %]
424     <script>
425         $(document).ready(function() {
426             $('[id^="CheckAll"]').click( function() {
427                 var table_id = "#" + $(this).attr('data-cb') + "resultst";
428                 $(table_id).find('.select-invoice[type="checkbox"]').each( function() {
429                     $(this).prop("checked" , true );
430                 });
431             });
432             $('[id^="UncheckAll"]').click( function() {
433                 var table_id = "#" + $(this).attr('data-cb') + "resultst";
434                 $(table_id).find('.select-invoice[type="checkbox"]').each( function() {
435                     $(this).prop("checked" , false );
436                 });
437             });
438
439             $(".delete_invoice").click(function(){
440                 return confirmDelete(_("Are you sure you want to delete this invoice?"));
441             });
442             var resultst = $("table.result").dataTable($.extend(true, {}, dataTablesDefaults, {
443                 "paging": false,
444                 "columnDefs": [
445                     { "orderable": false, "targets": [1, -1] },
446                     { "visible": false, "targets": [0] }
447                 ],
448                 autoWidth: false
449             }));
450
451             $(".show_only_subscription").prop("checked", false);
452
453             $(".show_only_subscription").click(function(){
454                 var table_id = $(this).attr("data-tableid");
455                 if ( $(this).prop("checked") ) {
456                     $('#'+table_id).dataTable().fnFilter( "1", 0, true );
457                 } else {
458                     $('#'+table_id).dataTable().fnFilter( '', 0 );
459                 }
460             });
461
462             $('#open_sel,#close_sel').click(function () {
463                 var referer = $(this).attr("data-referer");
464                 var op = $(this).attr("data-op");
465                 var table = $(this).data('table');
466                 var invoice_link = "invoice.pl?op="+op;
467                 if ($('#' + table + ' .select-invoice:checked').length) {
468                     $('#' + table + ' .select-invoice:checked').each(function () {
469                             var row = $(this).parents('tr');
470                             invoice_link = invoice_link + "&amp;invoiceid="+$(row).attr('data-invoiceid');
471                     });
472                     window.location.href =invoice_link +"&amp;"+referer;
473                 } else {
474                     alert ("Please select at least one invoice." );
475                 }
476             });
477
478             $('.merge').click(function (ev) {
479                 var booksellerid;
480                 var mismatch;
481                 var invoices = [ ];
482                 var table = $(this).data('table');
483                 if ($('#' + table + ' .select-invoice:checked').size() < 2) {
484                     alert(_("You must select at least two invoices to merge."));
485                     return false;
486                 }
487                 $('#' + table + ' .select-invoice:checked').each(function () {
488                     var row = $(this).parents('tr');
489                     booksellerid = booksellerid || $(row).attr('data-booksellerid');
490                     if (booksellerid !== $(row).attr('data-booksellerid')) {
491                         mismatch = true;
492                     }
493                     invoices.push({ 'invoiceid': $(row).attr('data-invoiceid'),
494                                     'invoicenumber': $(row).find('td:nth-child(2) a').text(),
495                                     'shipmentdate': $(row).attr('data-shipmentdate'),
496                                     'billingdate': $(row).attr('data-billingdate'),
497                                     'shipmentcost': $(row).attr('data-shipmentcost'),
498                                     'shipment_budgetid': $(row).attr('data-shipment_budgetid'),
499                                     'closedate': $(row).attr('data-closedate'), });
500                     $('#merge_invoice_form').append('<input type="hidden" name="merge" value="' + $(row).attr('data-invoiceid') + '" />');
501                 });
502                 if (mismatch) {
503                     alert(_("All invoices for merging must be from the same vendor"));
504                 } else {
505                     $('#merge_table tbody').empty();
506                     $.each(invoices, function (idx, invoice) {
507                         var row = $('<tr data-invoiceid="' + invoice.invoiceid + '"><td>' + invoice.invoicenumber + '</td><td>' + invoice.shipmentdate + '</td><td>' + invoice.billingdate + '</td><td>' + invoice.shipmentcost + '</td></tr>');
508                         $(row).appendTo('#merge_table tbody');
509                         $(row).click(function () {
510                             $('#merge_table tbody tr').removeClass('active');
511                             $(this).addClass('active');
512                             $.each(['invoiceid', 'shipmentdate', 'billingdate', 'shipmentcost', 'shipment_budgetid', 'invoicenumber'], function (idx, prop) {
513                                 $('#merge_' + prop).val(invoice[prop]);
514                             });
515                             if (invoice.closedate) {
516                                 $('#merge_status').text(_("Closed on %s").format(invoice.closedate));
517                             } else {
518                                 $('#merge_status').text(_("Open"));
519                             }
520                         });
521                     });
522                     $('#merge_table tbody tr:first').click();
523                     $('#merge_invoices').show();
524                 }
525             });
526
527             function display_vendor(vendor) {
528                 var $text;
529                 $text = $('<span>'+vendor.text+'</span>');
530                 return $text;
531             }
532
533             $("#supplierid").kohaSelect({
534                 width: '50%',
535                 allowClear: false,
536                 ajax: {
537                     url: '/api/v1/acquisitions/vendors',
538                     delay: 300, // wait 300 milliseconds before triggering the request
539                     cache: true,
540                     dataType: 'json',
541                     data: function (params) {
542                         var search_term = (params.term === undefined) ? '' : params.term;
543                         var query = {
544                             "q": JSON.stringify({"name":{"-like":'%'+search_term+'%'}}),
545                             "_order_by": "name",
546                             "_page": params.page
547                         };
548
549                         return query;
550                     },
551                     processResults: function (data) {
552                         var results = [];
553                         data.results.forEach( function ( vendor ) {
554                             results.push(
555                                 {
556                                     "id": vendor.id,
557                                     "text": vendor.name.escapeHtml()
558                                 }
559                             );
560                         });
561                         return { "results": results, "pagination": { "more": data.pagination.more } };
562                     }
563                 },
564                 templateResult: display_vendor,
565                 templateSelection: display_vendor
566             });
567
568
569
570         });
571     </script>
572 [% END %]
573
574 [% INCLUDE 'intranet-bottom.inc' %]