Bug 24157: New permission - reopen_closed_invoices
[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>Koha &rsaquo; Acquisitions &rsaquo; Invoices</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 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a> &rsaquo; Invoices</div>
17
18 <div class="main container-fluid">
19     <div class="row">
20         <div class="col-sm-10 col-sm-push-2">
21             <main>
22
23       <h1>Invoices</h1>
24       [% IF ( do_search ) %]
25         [% IF invoices %]
26           <label for="show_only_subscription">
27             <input type="checkbox" style="vertical-align: middle;" id="show_only_subscription" />
28             Show only subscriptions
29           </label>
30           <table id="resultst">
31             <thead>
32               <tr>
33                 <th>&nbsp;</th>
34                 <th>&nbsp;</th>
35                 <th>Invoice no.</th>
36                 <th>Vendor</th>
37                 <th class="title-string">Shipment date</th>
38                 <th class="title-string">Billing date</th>
39                 <th>Received bibliographic records</th>
40                 <th>Received items</th>
41                 <th>Status</th>
42                 <th>&nbsp;</th>
43               </tr>
44             </thead>
45             <tbody>
46               [% FOREACH invoice IN invoices %]
47                 <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 %]">
48                   <td>[% invoice.is_linked_to_subscriptions | html %]</td>
49                   <td><input type="checkbox" class="select-invoice" value="[% invoice.invoiceid | html %]" /></td>
50                   <td><a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% invoice.invoiceid | uri %]">[% invoice.invoicenumber | html %]</a></td>
51                   <td><a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% invoice.booksellerid | uri %]">[% invoice.suppliername | html %]</a></td>
52                   <td>
53                     [% IF invoice.shipmentdate %]
54                       <span title="[% invoice.shipmentdate | html %]">[% invoice.shipmentdate | $KohaDates %]</span>
55                     [% ELSE %]
56                       <span title="0000-00-00"></span>
57                     [% END %]
58                   </td>
59                   <td>
60                     [% IF invoice.billingdate %]
61                       <span title="[% invoice.billingdate | html %]">[% invoice.billingdate | $KohaDates %]</span>
62                     [% ELSE %]
63                       <span title="0000-00-00"></span>
64                     [% END %]
65                   </td>
66                   <td>[% invoice.receivedbiblios | html %]</td>
67                   <td>[% invoice.receiveditems | html %]</td>
68                   <td>
69                     [% IF invoice.closedate %]
70                       Closed on [% invoice.closedate | $KohaDates %]
71                     [% ELSE %]
72                       Open
73                     [% END %]
74                   </td>
75                   <td>
76
77                       <div class="btn-group dropup">
78                           <a class="btn btn-default btn-xs dropdown-toggle" id="invoiceactions[% invoice.invoiceid | html %]" role="button" data-toggle="dropdown" href="#">
79                              Actions <b class="caret"></b>
80                           </a>
81                           <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="invoiceactions[% invoice.invoiceid | html %]">
82                               <li><a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% invoice.invoiceid | uri %]"><i class="fa fa-search"></i> Details</a></li>
83                             [% IF invoice.closedate %]
84                                 [% IF CAN_user_acquisition_reopen_closed_invoices %]
85                                     <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>
86                                 [% END %]
87                             [% ELSE %]
88                                 <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>
89                             [% END %]
90                             [% UNLESS invoice.receivedbiblios || invoice.receiveditems %]
91                                 <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>
92                             [% END %]
93                           </ul>
94                       </div>
95                   </td>
96                 </tr>
97               [% END %]
98             </tbody>
99           </table>
100           <a class="submit" id="merge" href="#merge_invoices">Merge selected invoices</a>
101             <div id="merge_invoices">
102                 <form id="merge_invoice_form" action="/cgi-bin/koha/acqui/invoice.pl" method="post">
103                 <fieldset class="rows">
104                     <ol>
105                     <li><h2>Merge invoices</h2></li>
106                     <li><table id="merge_table">
107                         <thead><tr><th>Invoice no.</th><th>Shipment date</th><th>Billing date</th><th>Shipment cost</th></tr></thead>
108                         <tbody>
109                         </tbody>
110                     </table></li>
111                     <li><label for="merge_invoicenumber" class="required">Invoice number:</label>
112                             <input type="text" size="10" id="merge_invoicenumber" name="invoicenumber" value="" class="required" required="required" />
113                             <span class="required">Required</span>
114                             </li>
115                     <li><label for="merge_shipmentdate">Shipment date:</label>
116                             <input type="text" size="10" id="merge_shipmentdate" name="shipmentdate" value="" class="datepicker" /></li>
117
118                     <li><label for="merge_billingdate">Billing date:</label>
119                             <input type="text" size="10" id="merge_billingdate" name="billingdate" value="" class="datepicker" /></li>
120
121                     <li><label for="merge_shipmentcost">Shipment cost:</label>
122                             <input type="text" size="10" id="merge_shipmentcost" name="shipmentcost" value="" /></li>
123                     <li><label for="merge_shipment_budgetid">Fund:</label>
124                             <select id="merge_shipment_budgetid" name="shipment_budget_id">
125                                 <option value="">No fund</option>
126                               [% FOREACH budget IN budgets_loop %]
127                                   <option value="[% budget.budget_id | html %]">[% budget.budget_name | html %]
128                                   </option>
129                               [% END %]
130                             </select></li>
131
132                     <li><span class="label">Status:</span> <span id="merge_status"></span></li>
133                     <li><input type="submit" value="Merge" /></li>
134                     </ol>
135                     <input type="hidden" name="op" value="mod" />
136                     <input type="hidden" id="merge_invoiceid" name="invoiceid" value="" />
137                 </fieldset>
138                 </form>
139             </div>
140         [% ELSE %]
141           <p>Sorry, but there are no results for your search.</p>
142           <p>Search was:
143             <ul>
144               [% IF ( invoicenumber ) %]
145                 <li>Invoice no.: [% invoicenumber | html %]</li>
146               [% END %]
147               [% IF booksellerid %]
148                 <li>Vendor: [% suppliername | html %]</li>
149               [% END %]
150               [% IF shipmentdatefrom %]
151                 <li>Shipment date:
152                 [% IF shipmentdateto %]
153                   From [% shipmentdatefrom | $KohaDates %]
154                   To [% shipmentdateto | $KohaDates %]
155                 [% ELSE %]
156                   All since [% shipmentdatefrom | $KohaDates %]
157                 [% END %]
158                 </li>
159               [% ELSE %]
160                 [% IF shipmentdateto %]
161                   <li>Shipment date:
162                     All until [% shipmentdateto | $KohaDates %]
163                   </li>
164                 [% END %]
165               [% END %]
166               [% IF billingdatefrom %]
167                 <li>Billing date:
168                 [% IF billingdateto %]
169                   From [% billingdatefrom | $KohaDates %]
170                   To [% billingdateto | $KohaDates %]
171                 [% ELSE %]
172                   All since [% billingdatefrom | $KohaDates %]
173                 [% END %]
174                 </li>
175               [% ELSE %]
176                 [% IF billingdateto %]
177                   <li>Billing date:
178                     All until [% billingdateto | $KohaDates %]
179                   </li>
180                 [% END %]
181               [% END %]
182               [% IF ( isbneanissn ) %]
183                 <li>ISBN/EAN/ISSN: [% isbneanissn | html %]</li>
184               [% END %]
185               [% IF ( title ) %]
186                 <li>Title: [% title | html %]</li>
187               [% END %]
188               [% IF ( author ) %]
189                 <li>Author: [% author | html %]</li>
190               [% END %]
191               [% IF ( publisher ) %]
192                 <li>Publisher: [% publisher | html %]</li>
193               [% END %]
194               [% IF ( publicationyear ) %]
195                 <li>Publication year: [% publicationyear | html %]</li>
196               [% END %]
197               [% IF ( branch ) %]
198                 <li>Library: [% Branches.GetName( branch ) | html %]</li>
199               [% END %]
200             </ul>
201           </p>
202         [% END %]<!-- invoices -->
203       [% ELSE %]
204         <p>Use the search form on the left to find invoices.</p>
205       [% END %]<!-- do_search -->
206     </main>
207 </div> <!-- /.col-sm-10.col-sm-push-2 -->
208
209 <div class="col-sm-2 col-sm-pull-10">
210 <aside>
211     <form action="" method="get">
212       <fieldset class="sidebar brief">
213         <h3>Search filters</h3>
214         <ol>
215           <li>
216             <label for="invoicenumber">Invoice no:</label>
217             <input type="text" id="invoicenumber" name="invoicenumber" value="[% invoicenumber | html %]" class="focus" />
218           </li>
219           <li>
220             <label for="supplier">Vendor:</label>
221             <select id="supplier" name="supplierid">
222               <option value="">All</option>
223               [% FOREACH supplier IN suppliers_loop %]
224                 [% IF ( supplier.selected ) %]
225                   <option selected="selected" value="[% supplier.booksellerid | html %]">[% supplier.suppliername | html %]</option>
226                 [% ELSE %]
227                   <option value="[% supplier.booksellerid | html %]">[% supplier.suppliername | html %]</option>
228                 [% END %]
229               [% END %]
230             </select>
231           </li>
232           <li>
233             <fieldset class="brief">
234               <legend>Shipment date</legend>
235               <ol>
236                 <li>
237                   <label for="shipmentdatefrom">From:</label>
238                   <input type="text" id="shipmentdatefrom" name="shipmentdatefrom" size="10" value="[% shipmentdatefrom | $KohaDates %]" class="datepicker" />
239                 </li>
240                 <li>
241                   <label for="shipmentdateto">To:</label>
242                   <input type="text" id="shipmentdateto" name="shipmentdateto" size="10" value="[% shipmentdateto | $KohaDates %]" class="datepicker" />
243                 </li>
244               </ol>
245             </fieldset>
246           </li>
247           <li>
248             <fieldset class="brief">
249               <legend>Billing date</legend>
250               <ol>
251                 <li>
252                   <label for="billingdatefrom">From:</label>
253                   <input type="text" id="billingdatefrom" name="billingdatefrom" size="10" value="[% billingdatefrom | $KohaDates %]" class="datepicker" />
254                 </li>
255                 <li>
256                   <label for="billingdateto">To:</label>
257                   <input type="text" id="billingdateto" name="billingdateto" size="10" value="[% billingdateto | $KohaDates %]" class="datepicker" />
258                 </li>
259               </ol>
260             </fieldset>
261           </li>
262           <li>
263             <label for="isbneanissn">ISBN / EAN / ISSN:</label>
264             <input type="text" id="isbneanissn" name="isbneanissn" value="[% isbneanissn | html %]" />
265           </li>
266           <li>
267             <label for="title">Title:</label>
268             <input type="text" id="title" name="title" value="[% title | html %]" />
269           </li>
270           <li>
271             <label for="author">Author:</label>
272             <input type="text" id="author" name="author" value="[% author | html %]" />
273           </li>
274           <li>
275             <label for="publisher">Publisher:</label>
276             <input type="text" id="publisher" name="publisher" value="[% publisher | html %]" />
277           </li>
278           <li>
279             <label for="publicationyear">Publication year:</label>
280             <input type="text" id="publicationyear" name="publicationyear" value="[% publicationyear | html %]" />
281           </li>
282           <li>
283             <label for="branch">Library:</label>
284             <select id="branch" name="branch">
285               <option value="">All</option>
286               [%# FIXME Should not we filter the libraries %]
287               [% PROCESS options_for_libraries libraries => Branches.all( selected => branch, unfiltered => 1 ) %]
288             </select>
289           </li>
290         </ol>
291         <fieldset class="action">
292           <input type="submit" value="Search" />
293         </fieldset>
294       </fieldset>
295       <input type="hidden" name="op" id="op" value="do_search" />
296     </form>
297     [% INCLUDE 'acquisitions-menu.inc' %]
298   </aside>
299 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
300 </div> <!-- /.row -->
301
302 [% MACRO jsinclude BLOCK %]
303     [% Asset.js("js/acquisitions-menu.js") | $raw %]
304     [% INCLUDE 'datatables.inc' %]
305     [% INCLUDE 'calendar.inc' %]
306     <script>
307         $(document).ready(function() {
308             $(".delete_invoice").click(function(){
309                 return confirmDelete(_("Are you sure you want to delete this invoice?"));
310             });
311             var resultst = $("#resultst").dataTable($.extend(true, {}, dataTablesDefaults, {
312                 bPaginate: false,
313                 aoColumnDefs: [
314                     { "bSortable": false, "aTargets": [1, -1] },
315                     { "bVisible": false, "aTargets": [0] },
316                     { "sType": "title-string", "aTargets" : [ "title-string" ] }
317                 ]
318             }));
319
320             $("#show_only_subscription").prop("checked", false);
321
322             $("#show_only_subscription").click(function(){
323                 if ( $(this).prop("checked") ) {
324                     resultst.fnFilter( "1", 0, true );
325                 } else {
326                     resultst.fnFilter( '', 0 );
327                 }
328             });
329
330             $('#merge').click(function (ev) {
331                 var booksellerid;
332                 var mismatch;
333                 var invoices = [ ];
334                 if ($('.select-invoice:checked').size() < 2) {
335                     alert(_("You must select at least two invoices to merge."));
336                     return false;
337                 }
338                 $('.select-invoice:checked').each(function () {
339                     var row = $(this).parents('tr');
340                     booksellerid = booksellerid || $(row).attr('data-booksellerid');
341                     if (booksellerid !== $(row).attr('data-booksellerid')) {
342                         mismatch = true;
343                     }
344                     invoices.push({ 'invoiceid': $(row).attr('data-invoiceid'),
345                                     'invoicenumber': $(row).find('td:nth-child(2) a').text(),
346                                     'shipmentdate': $(row).attr('data-shipmentdate'),
347                                     'billingdate': $(row).attr('data-billingdate'),
348                                     'shipmentcost': $(row).attr('data-shipmentcost'),
349                                     'shipment_budgetid': $(row).attr('data-shipment_budgetid'),
350                                     'closedate': $(row).attr('data-closedate'), });
351                     $('#merge_invoice_form').append('<input type="hidden" name="merge" value="' + $(row).attr('data-invoiceid') + '" />');
352                 });
353                 if (mismatch) {
354                     alert(_("All invoices for merging must be from the same vendor"));
355                 } else {
356                     $('#merge_table tbody').empty();
357                     $.each(invoices, function (idx, invoice) {
358                         var row = $('<tr data-invoiceid="' + invoice.invoiceid + '"><td>' + invoice.invoicenumber + '</td><td>' + invoice.shipmentdate + '</td><td>' + invoice.billingdate + '</td><td>' + invoice.shipmentcost + '</td></tr>');
359                         $(row).appendTo('#merge_table tbody');
360                         $(row).click(function () {
361                             $('#merge_table tbody tr').removeClass('active');
362                             $(this).addClass('active');
363                             $.each(['invoiceid', 'shipmentdate', 'billingdate', 'shipmentcost', 'shipment_budgetid', 'invoicenumber'], function (idx, prop) {
364                                 $('#merge_' + prop).val(invoice[prop]);
365                             });
366                             if (invoice.closedate) {
367                                 $('#merge_status').text(_("Closed on %s").format(invoice.closedate));
368                             } else {
369                                 $('#merge_status').text(_("Open"));
370                             }
371                         });
372                     });
373                     $('#merge_table tbody tr:first').click();
374                     $('#merge_invoices').show();
375                 }
376             });
377         });
378     </script>
379 [% END %]
380
381 [% INCLUDE 'intranet-bottom.inc' %]