Bug 28003: Invoice adjustments using inactive budgets do not indicate that status
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / acqui / invoice.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE KohaDates %]
5 [% USE Price %]
6 [% SET footerjs = 1 %]
7 [% USE AuthorisedValues %]
8
9 [% INCLUDE 'doc-head-open.inc' %]
10 <title>Koha &rsaquo; Acquisitions &rsaquo; Invoice</title>
11 [% INCLUDE 'doc-head-close.inc' %]
12 </head>
13
14 <body id="acq_invoice" class="acq">
15 [% INCLUDE 'header.inc' %]
16 [% INCLUDE 'acquisitions-search.inc' %]
17
18 [% SET readonly = NOT CAN_user_acquisition_edit_invoices %]
19
20 <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; <a href="/cgi-bin/koha/acqui/invoices.pl">Invoices</a> &rsaquo; <a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% invoiceid | html %]">[% invoicenumber | html %]</a></div>
21
22 <div class="main container-fluid">
23     <div class="row">
24         <div class="col-sm-10 col-sm-push-2">
25             <main>
26
27                 [% INCLUDE 'blocking_errors.inc' %]
28
29       [% IF ( modified ) %]
30         <div class="dialog message">
31           <p>Invoice has been modified</p>
32         </div>
33       [% END %]
34       <h1>Invoice: [% invoicenumber | html %]</h1>
35
36       <p>Vendor: <a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% booksellerid | uri %]">[% suppliername | html %]</a></p>
37         <form action="/cgi-bin/koha/acqui/invoice.pl" method="post" class="validated">
38         <fieldset class="rows">
39             <ol>
40             <li>
41                 [% IF readonly %]
42                     <label for="shipmentdate">Invoice number:</label>
43                     [% invoicenumber | html %]
44                 [% ELSE %]
45                     <label for="shipmentdate" class="required">Invoice number:</label>
46                     <input type="text" id="invoicenumber" name="invoicenumber" value="[% invoicenumber | html %]" class="required" required="required"/>
47                     <span class="required">Required</span>
48                 [% END %]
49             </li>
50
51             <li>
52                 <label for="shipmentdate">Shipment date:</label>
53                 [% IF readonly %]
54                     [% shipmentdate | $KohaDates %]
55                 [% ELSE %]
56                     <input type="text" size="10" id="shipmentdate" name="shipmentdate" value="[% shipmentdate | $KohaDates %]" class="datepicker" />
57                 [% END %]
58             </li>
59
60             <li>
61                 <label for="billingdate">Billing date:</label>
62                 [% IF readonly %]
63                     [% billingdate | $KohaDates %]
64                 [% ELSE %]
65                     <input type="text" size="10" id="billingdate" name="billingdate" value="[% billingdate | $KohaDates %]" class="datepicker" />
66                 [% END %]
67             </li>
68
69             <li>
70                 <label for="shipmentcost">Shipping cost:</label>
71                 [% IF readonly %]
72                     [% shipmentcost | $Price %]
73                 [% ELSE %]
74                     <input type="text" size="10" id="shipmentcost" name="shipmentcost" value="[% shipmentcost | $Price on_editing => 1 %]" />
75                 [% END %]
76             </li>
77             <li>
78                 <label for="shipment_budget_id">Shipping fund: </label>
79                 [% IF readonly %]
80                     [% budget.budget_name | html %]
81                 [% ELSE %]
82                     <select id="shipment_budget_id" name="shipment_budget_id">
83                         <option value="">No fund</option>
84                         [% FOREACH budget IN budgets %]
85                             [% IF ( budget.selected ) %]
86                                 <option value="[% budget.b_id | html %]" selected="selected">[% budget.b_txt | html %] [% IF ( !budget.b_active ) %](inactive)[% END %]</option>
87                             [% ELSIF ( budget.b_active ) %]
88                                 <option value="[% budget.b_id | html %]">[% budget.b_txt | html %]</option>
89                             [% ELSE %]
90                                 <option value="[% budget.b_id | html %]" class="b_inactive">[% budget.b_txt | html %] (inactive)</option>
91                             [% END %]
92                         [% END %]
93                     </select>
94                     <label for="showallfunds" style="float:none;width:auto;">&nbsp;Show inactive:</label>
95                     <input type="checkbox" id="showallfunds" />
96                 [% END %]
97             </li>
98
99             [% IF ( invoiceclosedate ) %]
100             <li><span class="label">Status:</span>
101                 Closed on [% invoiceclosedate | $KohaDates %]</li>
102
103                 [% IF CAN_user_acquisition_reopen_closed_invoices AND NOT readonly %]
104                     <li>
105                         <label for="reopen">Reopen: </label>
106                         <input type="checkbox" name="reopen" id="reopen" />
107                     </li>
108                 [% END %]
109             [% ELSE %]
110                 <li>
111                     <span class="label">Status:</span>
112                     Open
113                 </li>
114                 [% UNLESS ( readonly ) %]
115                     <li>
116                         <label for="close">Close: </label>
117                         <input type="checkbox" name="close" id="close" />
118                     </li>
119                 [% END %]
120             [% END %]
121             </ol>
122         [% UNLESS readonly %]
123           <input type="hidden" name="op" value="mod" />
124           <input type="hidden" name="invoiceid" value="[% invoiceid | html %]" />
125             <fieldset class="action">
126                 <input type="submit" value="Save" />
127                 [% IF CAN_user_acquisition_delete_invoices AND NOT orders_loop.size %]
128                 <a href="invoice.pl?op=delete&invoiceid=[% invoiceid | uri %]" id="delete">Delete</a>
129                 [% END %]
130             </fieldset>
131         [% END %]
132         </fieldset>
133       </form>
134
135       <hr />
136
137         <h3>Adjustments</h3>
138
139           <form action="/cgi-bin/koha/acqui/invoice.pl" method="post" class="validated">
140               <fieldset class="rows">
141                   <input type="hidden" name="invoiceid" value="[% invoiceid | html %]" />
142                   [% IF (adjustments && adjustments.count > 0) %]
143                       <table id="invoice_adj_table">
144                           <tr>
145                              <th>Id</th>
146                              <th>Amount</th>
147                              <th>Reason</th>
148                              <th>Note</th>
149                              <th>Fund</th>
150                              <th>Encumber while invoice open</th>
151                              [% UNLESS readonly %]<th>&nbsp</th>[% END %]
152                           </tr>
153                           [% total_adj = 0 %]
154                           [% FOREACH adjustment IN adjustments %]
155                               [% total_adj = total_adj + adjustment.adjustment %]
156                               <tr>
157                                   <td><input type="hidden" name="adjustment_id" value="[% adjustment.adjustment_id | html %]" />[% adjustment.adjustment_id | html %]</td>
158                                   <td>
159                                     [% IF readonly %]
160                                         [% adjustment.adjustment | $Price %]
161                                     [% ELSE %]
162                                         <input type="text" name="adjustment" id="adjustment_[% adjustment.adjustment_id | html %]" value="[% adjustment.adjustment | $Price on_editing => 1 %]" />
163                                     [% END %]
164                                   </td>
165                                   <td>
166                                       [% IF readonly %]
167                                           [% AuthorisedValues.GetByCode('ADJ_REASON', adjustment.reason) | html %]
168                                       [% ELSE %]
169                                           [% reasons = AuthorisedValues.Get("ADJ_REASON") %]
170                                           [% IF reasons.0 %]
171                                               <select id="reason_[% adjustment.adjustment_id | html %]" name="reason">
172                                                   <option value="">No reason</option>
173                                                   [% FOREACH reason IN reasons %]
174                                                       [% IF ( adjustment.reason == reason.authorised_value ) %]
175                                                           <option selected="selected" value="[% reason.authorised_value | html %]">
176                                                       [% ELSE %]
177                                                           <option value="[% reason.authorised_value | html %]">
178                                                       [% END %]
179                                                       [% reason.lib | html %]
180                                                       </option>
181                                                   [% END %]
182                                               </select>
183                                           [% ELSE %]
184                                               <p title="Define values in authorised value category ADJ_REASON to enable">None</p>
185                                               <input type="hidden" name="reason" id="reason_[% adjustment.adjustment_id | html %]" value="" />
186                                           [% END %]
187                                         [% END %]
188                                   </td>
189                                   <td>
190                                       [% IF readonly %]
191                                           [% adjustment.note | html %]
192                                       [% ELSE %]
193                                           <input type="text" name="note" id="note_new" value="[% adjustment.note | html %]"/>
194                                       [% END %]
195                                   </td>
196                                   <td>
197                                       [% IF readonly %]
198                                           [% adjustement.fund.budget_name | html %]
199                                       [% ELSE %]
200                                           <select id="budget_id_[% adjustment.adjustment_id | html %]" name="budget_id">
201                                               <option value="">No fund</option>
202                                               [% FOREACH budget IN budgets %]
203                                                   [% IF ( budget.b_id == adjustment.budget_id ) %]
204                                                       <option selected="selected" value="[% budget.b_id | html %]">
205                                                   [% ELSE %]
206                                                       <option value="[% budget.b_id | html %]">
207                                                   [% END %]
208                                                   [% IF budget.b_active %]
209                                                       [% budget.b_txt | html %]
210                                                   [% ELSE %]
211                                                       [% budget.b_txt | html %] (inactive)
212                                                   [% END %]
213                                                   </option>
214                                               [% END %]
215                                           </select>
216                                       [% END %]
217                                   </td>
218                                   [% IF adjustment.encumber_open %]
219                                       <td>
220                                         [% IF readonly %]
221                                           <input type="checkbox" checked="checked" readonly="readonly" />
222                                         [% ELSE %]
223                                           <input type="checkbox" name="encumber_open" id="encumber_[% adjustment.adjustment_id | html %]"  value="[% adjustment.adjustment_id | html %]" checked/>
224                                         [% END %]
225                                       </td>
226                                   [% ELSE %]
227                                       <td>
228                                         [% IF readonly %]
229                                           <input type="checkbox" disabled="disabled" />
230                                         [% ELSE %]
231                                           <input type="checkbox" name="encumber_open" id="encumber_[% adjustment.adjustment_id | html %]"  value="[% adjustment.adjustment_id | html %]" />
232                                         [% END %]
233                                       </td>
234                                   [% END %]
235                                   [% UNLESS readonly %]
236                                       <td>
237                                          <a class="btn btn-default btn-xs delete_adjustment" href="/cgi-bin/koha/acqui/invoice.pl?op=del_adj&adjustment_id=[% adjustment.adjustment_id | html %]&invoiceid=[% invoiceid | html %]"><i class="fa fa-trash"></i> Delete</a>
238                                       </td>
239                                   [% END %]
240                               </tr>
241                           [% END %]
242                       </table>
243                   [% END %]
244
245                   [% UNLESS readonly %]
246                       <p>
247                           <a href="#" id="show_invoice_adjustment" class="toggle_invoice_adjustment"><i class="fa fa-plus"></i> Add an adjustment</a>
248                       </p>
249
250                       <fieldset id="add_invoice_adjustment" style="display:none">
251                           <h4>Add an adjustment</h4>
252                           <input type="hidden" name="adjustment_id" value="new" />
253                               <ol>
254                                   <li>
255                                       <label for="adjustment_new">Amount: </label>
256                                       <input type="text" name="adjustment" id="adjustment_new" />
257                                   </li>
258                                   [% reasons = AuthorisedValues.Get("ADJ_REASON") %]
259                                   [% IF reasons.0 %]
260                                       <li>
261                                           <label for="reason_[% adjustment.adjustment_id | html %]">Reason: </label>
262                                           <select id="reason_[% adjustment.adjustment_id | html %]" name="reason">
263                                               <option value="">No reason</option>
264                                               [% FOREACH reason IN reasons %]
265                                                   <option value="[% reason.authorised_value | html %]">
266                                                       [% reason.lib | html %]
267                                                   </option>
268                                               [% END %]
269                                           </select>
270                                       </li>
271                                   [% ELSE %]
272                                       <li>
273                                           <span class="label">Reason: </span>
274                                           <span>None</span>
275                                           <div class="hint">Define values in authorised value category ADJ_REASON to enable</div>
276                                       </li>
277                                   [% END %]
278                                   <li>
279                                       <label for="note_new">Note: </label>
280                                       <input type="text" name="note" id="note_new" value=""/>
281                                   </li>
282                                   <li>
283                                       <label for="budget_id_new">Fund: </label>
284                                       <select id="budget_id_new" name="budget_id">
285                                           <option value="">No fund</option>
286                                           [% FOREACH budget IN budgets %]
287                                               [% IF ( budget.selected ) %]
288                                                   <option value="[% budget.b_id | html %]" selected="selected">[% budget.b_txt | html %] [% IF ( !budget.b_active ) %](inactive)[% END %]</option>
289                                               [% ELSIF ( budget.b_active ) %]
290                                                   <option value="[% budget.b_id | html %]">[% budget.b_txt | html %]</option>
291                                               [% ELSE %]
292                                                   <option value="[% budget.b_id | html %]" class="ab_inactive">[% budget.b_txt | html %] (inactive)</option>
293                                               [% END %]
294                                           [% END %]
295                                       </select>
296                                       <label for="showallfunds_adj" style="float:none;width:auto;">&nbsp;Show inactive:</label>
297                                       <input type="checkbox" id="showallfunds_adj" />
298                                   </li>
299                                   <li>
300                                       <label for="encumber_new">Encumber while invoice open? </label>
301                                       <input type="checkbox" name="encumber_open" id="encumber_new" value="new" />
302                                       <input type="hidden" name="delete" value="">
303                                   </li>
304                                   <li>
305                                       <span class="label">&nbsp;</span>
306                                       <a href="#" id="cancel_invoice_adjustment" class="toggle_invoice_adjustment" style="display:none"><i class="fa fa-remove"></i> Cancel</a>
307                                   </li>
308                               </ol>
309                           </fieldset>
310                           <fieldset class="action">
311                               <input type="hidden" name="op" value="mod_adj" />
312                               <input type="submit" value="Update adjustments" />
313                           </fieldset>
314                     [% END %]
315                   </fieldset>
316               </form>
317       <p>
318           <a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid | uri %]">Go to receipt page</a>
319           [% IF Koha.Preference('AcqEnableFiles') %]| <a href="/cgi-bin/koha/acqui/invoice-files.pl?invoiceid=[% invoiceid | uri %]">Manage invoice files</a>[% END %]
320       </p>
321       <h2>Invoice details</h2>
322       <fieldset>
323       [% IF orders_loop.size %]
324           <label for="show_all_details">
325             <input type="checkbox" style="vertical-align: middle;" id="show_all_details" />
326             Show all details
327           </label>
328           <table id="orderst">
329             <thead>
330               <tr>
331                 <th class="anti-the">Summary</th>
332                 <th>Library</th>
333                 <th class="tax_excluded">Actual cost tax exc.</th>
334                 <th class="tax_included">Actual cost tax inc.</th>
335                 <th class="replacementprice">Replacement price</th>
336                 <th>Qty.</th>
337                 <th class="tax_excluded">Total tax exc. ([% currency.symbol | html %])</th>
338                 <th class="tax_included">Total tax inc. ([% currency.symbol | html %])</th>
339                 <th>GST %</th>
340                 <th>GST</th>
341                 <th>Fund</th>
342               </tr>
343             </thead>
344             <tbody>
345               [% FOREACH order IN orders_loop %]
346                 <tr>
347                   <td>
348                     [% IF order.biblionumber %]
349                       <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% order.biblionumber | uri %]">[% order.title | html %]</a>
350                       [% IF ( order.author ) %]
351                         <br /><em>by</em> [% order.author | html %]
352                       [% END %]
353                     [% ELSE %]
354                       <em>Deleted bibliographic record, can't find title</em>
355                     [% END %]
356                     [% IF ( order.isbn ) %] &ndash; [% order.isbn | html %][% END %]
357                     [% IF ( order.publishercode ) %]
358                       <br/>[% order.publishercode | html %]
359                         [% IF order.publicationyear %], [% order.publicationyear | html %]
360                         [% ELSIF ( order.copyrightdate ) %][% order.copyrightdate | html %][% END %]
361                     [% END %]
362                   </td>
363                   <td><p>[% order.branchcode | html %]</p></td>
364                   <td class="number tax_excluded">[% order.unitprice_tax_excluded | $Price %]</td>
365                   <td class="number tax_included">[% order.unitprice_tax_included | $Price %]</td>
366                   <td class="number replacementprice">[% order.replacementprice | $Price %] [% IF ( order.uncertainprice ) %] (Uncertain) [% END %]</td>
367                   <td class="number">[% order.quantity | html %]</td>
368                   <td class="number tax_excluded">[% order.total_tax_excluded | $Price %]</td>
369                   <td class="number tax_included">[% order.total_tax_included | $Price %]</td>
370                   <td class="number">[% order.tax_rate * 100 | html %]</td>
371                   <td class="number">[% order.tax_value | $Price %]</td>
372                   <td>[% order.budget_name | html %]</td>
373                 </tr>
374               [% END %]
375             </tbody>
376             <tfoot>
377               [% FOR tf IN foot_loop %]
378                 <tr>
379                     <th colspan="2">Total (GST [% tf.tax_rate * 100 | html %] %)</th>
380                     <th class="tax_excluded"></th>
381                     <th class="tax_included"></th>
382                     <th class="replacementprice"/>
383                     <th>[% tf.quantity | html %]</th>
384                     <th class="tax_excluded">[% tf.total_tax_excluded | $Price %]</th>
385                     <th class="tax_included">[% tf.total_tax_included | $Price %]</th>
386                     <th>&nbsp;</th>
387                     <th>[% tf.tax_value | $Price %]</th>
388                     <th>&nbsp;</th>
389                 </tr>
390               [% END %]
391               <tr>
392                 <th colspan="2">Total ([% currency.symbol | html %])</th>
393                 <th class="tax_excluded"></th>
394                 <th class="tax_included"></th>
395                 <th class="replacementprice"/>
396                 <th>[% total_quantity | html %]</th>
397                 <th class="tax_excluded">[% total_tax_excluded | $Price %]</th>
398                 <th class="tax_included">[% total_tax_included | $Price %]</th>
399                 <th>&nbsp;</th>
400                 <th>[% total_tax_value | $Price %]</th>
401                 <th>&nbsp;</th>
402               </tr>
403               <tr>
404                 <th colspan="2">Total + adjustments + shipment cost ([% currency.symbol | html %])</th>
405                 <th class="tax_excluded"></th>
406                 <th class="tax_included"></th>
407                 <th class="replacementprice"/>
408                 <th>[% total_quantity | html %]</th>
409                 <th class="tax_excluded">[% total_tax_excluded_shipment + total_adj | $Price %]</th>
410                 <th class="tax_included">[% total_tax_included_shipment + total_adj | $Price %]</th>
411                 <th>&nbsp;</th>
412                 <th>[% total_tax_value | $Price %]</th>
413                 <th>&nbsp;</th>
414               </tr>
415             </tfoot>
416           </table>
417         [% ELSE %]
418             <div class="dialog message"><p>No orders yet</p>
419             [% IF adjustments && adjustments.count > 0 || shipmentcost && shipmentcost > 0 %]
420             <p>Adjustments plus shipping: [% total_adj + shipmentcost | $Price %]</p>
421             [% END %]
422             </div>
423         [% END %]
424         [% IF ( (Koha.Preference('AcqEnableFiles')) && files ) %]
425             <br />
426             <h2>Files attached to invoice</h2>
427             <table id="invoice_files_table">
428                 <thead>
429                     <tr>
430                         <th>Name</th>
431                         <th>Type</th>
432                         <th>Description</th>
433                         <th>Uploaded</th>
434                     </tr>
435                 </thead>
436                 <tbody>
437                 [% FOREACH f IN files %]
438                     <tr>
439                          <td><a href="/cgi-bin/koha/acqui/invoice-files.pl?invoiceid=[% invoiceid | uri %]&amp;op=download&amp;view=1&amp;file_id=[% f.file_id | uri %]">[% f.file_name | html %]</a></td>
440                          <td>[% f.file_type | html %]</td>
441                          <td>[% f.file_description | html %]</td>
442                          <td class="title-string">
443                            <span title="[% f.date_uploaded | html %]">[% f.date_uploaded | $KohaDates %]</span>
444                          </td>
445                     </tr>
446                 [% END %]
447                 </tbody>
448             </table>
449         [% END %]
450         </fieldset>
451     </main>
452   </div> <!-- /.col-sm-10.col-sm-push-2 -->
453
454     <aside>
455         <div class="col-sm-2 col-sm-pull-10">
456             [% INCLUDE 'acquisitions-menu.inc' %]
457         </div>
458     </aside>
459 </div> <!-- /.row -->
460
461 [% MACRO jsinclude BLOCK %]
462     [% Asset.js("js/acquisitions-menu.js") | $raw %]
463     [% INCLUDE 'calendar.inc' %]
464     [% INCLUDE 'datatables.inc' %]
465     <script>
466         function updateColumnsVisibility(visible) {
467             if ( visible ) {
468                 $("table .tax_excluded, .tax_included").show();
469             } else {
470                 [% IF ( invoiceincgst ) %]
471                     $("table .tax_excluded").hide();
472                 [% ELSE %]
473                     $("table .tax_included").hide();
474                 [% END %]
475             }
476         }
477
478         $(document).ready(function() {
479             $("#delete").click(function(){
480                 return confirmDelete(_("Are you sure you want to delete this invoice?"));
481             });
482             $("#orderst").dataTable($.extend(true, {}, dataTablesDefaults, {
483                 bInfo: false,
484                 bPaginate: false,
485                 bFilter: false,
486                 sDom: "t",
487                 "aoColumnDefs": [
488                     { "sType": "anti-the", "aTargets": [ "anti-the" ] }
489                 ]
490             }));
491             [% IF ( (Koha.Preference('AcqEnableFiles')) && files ) %]
492                 $("#invoice_files_table").dataTable($.extend(true, {}, dataTablesDefaults, {
493                     "aoColumnDefs": [
494                         { "aTargets": [ "title-string" ], "sType": "title-string" }
495                     ],
496                     bInfo: false,
497                     bPaginate: false,
498                     bFilter: false,
499                     sDom: "t"
500                 }));
501             [% END %]
502             $("#show_all_details").click(function(){
503                 updateColumnsVisibility( $(this).is(":checked") );
504             });
505
506             $("#show_all_details").prop('checked', false);
507             updateColumnsVisibility(false);
508             $(".toggle_invoice_adjustment").on("click", function(e){
509                 e.preventDefault();
510                 $("#show_invoice_adjustment, #cancel_invoice_adjustment, #add_invoice_adjustment").toggle();
511             });
512             $("a.delete_adjustment").click(function(){
513                 return ( confirm( _("Are you sure you want to delete this file ?") ) );
514             });
515
516             //keep a copy of all budgets before removing the inactives
517             var budgetId = $("#shipment_budget_id");
518             var disabledBudgetsCopy = budgetId.html();
519             $('.b_inactive').remove();
520
521             $('#showallfunds').click(function() {
522                 if ($(this).is(":checked")) {
523                     budgetId.html(disabledBudgetsCopy); //Puts back all the funds
524                 }
525                 else {
526                     $('.b_inactive').remove();
527                 }
528             });
529             // same effort for the adjustments
530             var adjBudgetId = $("#budget_id_new");
531             var disabledAdjBudgetsCopy = adjBudgetId.html();
532             $('.ab_inactive').remove();
533             $('#showallfunds_adj').click(function() {
534                 if ($(this).is(":checked")) {
535                     adjBudgetId.html(disabledAdjBudgetsCopy); //Puts back all the funds
536                 }
537                 else {
538                     $('.ab_inactive').remove();
539                 }
540             });
541         });
542     </script>
543 [% END %]
544
545 [% INCLUDE 'intranet-bottom.inc' %]