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