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