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