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