Bug 34452: Restore fund label and 'Update adjustments' button
[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 [% BLOCK fund_dropdown %]
10     <select id="[% form_id | html %]" name="[% form_name | html %]" class="fund_dropdown" data-selected="[% selected | html %]">
11     </select>
12     <label for="showallfunds" style="float:none;width:auto;">&nbsp;Show inactive:</label>
13     <input type="checkbox" class="showallfunds" />
14 [% END %]
15
16 [% INCLUDE 'doc-head-open.inc' %]
17 <title>Invoice &rsaquo; Acquisitions &rsaquo; Koha</title>
18 [% INCLUDE 'doc-head-close.inc' %]
19 [% Asset.css("css/humanmsg.css") | $raw %]
20 </head>
21
22 <body id="acq_invoice" class="acq">
23 [% WRAPPER 'header.inc' %]
24     [% INCLUDE 'acquisitions-search.inc' %]
25 [% END %]
26
27 [% SET readonly = NOT CAN_user_acquisition_edit_invoices %]
28
29 [% WRAPPER 'sub-header.inc' %]
30     [% WRAPPER breadcrumbs %]
31         [% WRAPPER breadcrumb_item %]
32             <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a>
33         [% END %]
34         [% WRAPPER breadcrumb_item %]
35             <a href="/cgi-bin/koha/acqui/invoices.pl">Invoices</a>
36         [% END %]
37         [% WRAPPER breadcrumb_item bc_active=1 %]
38             [% invoicenumber | html %]
39         [% END %]
40     [% END #/ WRAPPER breadcrumbs %]
41 [% END #/ WRAPPER sub-header.inc %]
42
43 <div class="main container-fluid">
44     <div class="row">
45         <div class="col-sm-10 col-sm-push-2">
46             <main>
47
48                 <h1>Invoice: [% invoicenumber | html %]</h1>
49                 [% INCLUDE 'blocking_errors.inc' %]
50
51                 [% IF ( modified ) %]
52                     <div class="dialog message">
53                         <p>Invoice has been modified</p>
54                     </div>
55                 [% END %]
56
57                 <p>Vendor: <a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% booksellerid | uri %]">[% suppliername | html %]</a></p>
58
59                 <form action="/cgi-bin/koha/acqui/invoice.pl" method="post" class="validated">
60                     <fieldset class="rows">
61                         <ol>
62                             <li>
63                                 [% IF readonly %]
64                                     <label for="shipmentdate">Invoice number:</label>
65                                     [% invoicenumber | html %]
66                                 [% ELSE %]
67                                     <label for="shipmentdate" class="required">Invoice number:</label>
68                                     <input type="text" id="invoicenumber" name="invoicenumber" value="[% invoicenumber | html %]" class="required" required="required"/>
69                                     <span class="required">Required</span>
70                                 [% END %]
71                             </li>
72                             <li>
73                                 <label for="shipmentdate">Shipment date:</label>
74                                 [% IF readonly %]
75                                     [% shipmentdate | $KohaDates %]
76                                 [% ELSE %]
77                                     <input type="text" size="10" id="shipmentdate" name="shipmentdate" value="[% shipmentdate | html %]" class="flatpickr" />
78                                     <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
79                                 [% END %]
80                             </li>
81                             <li>
82                                 <label for="billingdate">Billing date:</label>
83                                 [% IF readonly %]
84                                     [% billingdate | $KohaDates %]
85                                 [% ELSE %]
86                                     <input type="text" size="10" id="billingdate" name="billingdate" value="[% billingdate | html %]" class="flatpickr" />
87                                     <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
88                                 [% END %]
89                             </li>
90                             <li>
91                                 <label for="shipmentcost">Shipping cost:</label>
92                                 [% IF readonly %]
93                                     [% shipmentcost | $Price %]
94                                 [% ELSE %]
95                                     <input class="decimal" type="text" size="10" id="shipmentcost" name="shipmentcost" value="[% shipmentcost | $Price on_editing => 1 %]" />
96                                 [% END %]
97                             </li>
98                             <li>
99                                 <label for="shipment_budget_id">Shipping fund: </label>
100                                 [% PROCESS fund_dropdown form_id => 'shipment_budget_id' form_name => 'shipment_budget_id' selected => shipment_budget_id %]
101                             </li>
102
103                             [% IF ( invoiceclosedate ) %]
104                                 <li>
105                                     <span class="label">Status:</span>
106                                     Closed on [% invoiceclosedate | $KohaDates %]
107                                 </li>
108                                 [% IF CAN_user_acquisition_reopen_closed_invoices AND NOT readonly %]
109                                     <li>
110                                         <label for="reopen">Reopen: </label>
111                                         <input type="checkbox" name="reopen" id="reopen" />
112                                     </li>
113                                 [% END %]
114                             [% ELSE %]
115                                 <li>
116                                     <span class="label">Status:</span>
117                                     Open
118                                 </li>
119                                 [% UNLESS ( readonly ) %]
120                                     <li>
121                                         <label for="close">Close: </label>
122                                         <input type="checkbox" name="close" id="close" />
123                                     </li>
124                                 [% END %]
125                             [% END # /IF ( invoiceclosedate ) %]
126                         </ol>
127
128                         [% IF available_additional_fields.count %]
129                             [% INCLUDE 'additional-fields-entry.inc' available=available_additional_fields values=additional_field_values %]
130                         [% END %]
131
132                     </fieldset>
133                     [% UNLESS readonly %]
134                         <fieldset class="action">
135                             <input type="hidden" name="op" value="mod" />
136                             <input type="hidden" name="invoiceid" value="[% invoiceid | html %]" />
137                             <input type="submit" class="btn btn-primary" value="Save" />
138                             [% IF CAN_user_acquisition_delete_invoices AND NOT orders_loop.size %]
139                                 <a href="invoice.pl?op=delete&invoiceid=[% invoiceid | uri %]" id="delete">Delete</a>
140                             [% END %]
141                         </fieldset>
142                     [% END %]
143                 </form>
144
145                 <form action="/cgi-bin/koha/acqui/invoice.pl" method="post" class="validated">
146                     <fieldset class="rows">
147                         <input type="hidden" name="invoiceid" value="[% invoiceid | html %]" />
148                         <h3>Adjustments</h3>
149                         [% IF (adjustments && adjustments.count > 0) %]
150                             <table id="invoice_adj_table">
151                                 <tr>
152                                     <th>Id</th>
153                                     <th>Amount</th>
154                                     <th>Reason</th>
155                                     <th>Note</th>
156                                     <th>Fund</th>
157                                     <th>Encumber while invoice open</th>
158                                     [% UNLESS readonly %]<th>&nbsp;</th>[% END %]
159                                 </tr>
160                                 [% total_adj = 0 %]
161                                 [% FOREACH adjustment IN adjustments %]
162                                     [% total_adj = total_adj + adjustment.adjustment %]
163                                     <tr>
164                                         <td>
165                                             <input type="hidden" name="adjustment_id" value="[% adjustment.adjustment_id | html %]" />[% adjustment.adjustment_id | html %]
166                                         </td>
167                                         <td>
168                                             [% IF readonly %]
169                                                 [% adjustment.adjustment | $Price %]
170                                             [% ELSE %]
171                                                 <input class="decimal" type="text" name="adjustment" id="adjustment_[% adjustment.adjustment_id | html %]" value="[% adjustment.adjustment | $Price on_editing => 1 %]" />
172                                             [% END %]
173                                         </td>
174                                         <td>
175                                             [% IF readonly %]
176                                                 [% AuthorisedValues.GetByCode('ADJ_REASON', adjustment.reason) | html %]
177                                             [% ELSE %]
178                                                 [% reasons = AuthorisedValues.Get("ADJ_REASON") %]
179                                                 [% IF reasons.0 %]
180                                                     <select id="reason_[% adjustment.adjustment_id | html %]" name="reason">
181                                                         <option value="">No reason</option>
182                                                         [% FOREACH reason IN reasons %]
183                                                             [% IF ( adjustment.reason == reason.authorised_value ) %]
184                                                                 <option selected="selected" value="[% reason.authorised_value | html %]">
185                                                             [% ELSE %]
186                                                                 <option value="[% reason.authorised_value | html %]">
187                                                             [% END %]
188                                                                 [% reason.lib | html %]
189                                                                 </option>
190                                                         [% END %]
191                                                     </select>
192                                                 [% ELSE %]
193                                                     <p title="Define values in authorised value category ADJ_REASON to enable">None</p>
194                                                     <input type="hidden" name="reason" id="reason_[% adjustment.adjustment_id | html %]" value="" />
195                                                 [% END # /IF reasons.0 %]
196                                             [% END # /IF readonly %]
197                                         </td>
198                                         <td>
199                                             [% IF readonly %]
200                                                 [% adjustment.note | html %]
201                                             [% ELSE %]
202                                                 <input type="text" name="note" id="note_new" value="[% adjustment.note | html %]"/>
203                                             [% END %]
204                                         </td>
205                                         <td>
206                                             [% PROCESS fund_dropdown form_id => "budget_id_" _ adjustment.adjustment_id form_name => 'budget_id' selected => adjustment.budget_id %]
207                                         </td>
208                                         [% IF adjustment.encumber_open %]
209                                             <td>
210                                                 [% IF readonly %]
211                                                     <input type="checkbox" checked="checked" readonly="readonly" />
212                                                 [% ELSE %]
213                                                     <input type="checkbox" name="encumber_open" id="encumber_[% adjustment.adjustment_id | html %]"  value="[% adjustment.adjustment_id | html %]" checked/>
214                                                 [% END %]
215                                             </td>
216                                         [% ELSE %]
217                                             <td>
218                                                 [% IF readonly %]
219                                                     <input type="checkbox" disabled="disabled" />
220                                                 [% ELSE %]
221                                                     <input type="checkbox" name="encumber_open" id="encumber_[% adjustment.adjustment_id | html %]"  value="[% adjustment.adjustment_id | html %]" />
222                                                 [% END %]
223                                             </td>
224                                         [% END # /IF adjustment.encumber_open  %]
225                                         [% UNLESS readonly %]
226                                             <td>
227                                                 <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-can"></i> Delete</a>
228                                             </td>
229                                         [% END %]
230                                     </tr>
231                                 [% END # /FOREACH adjustment %]
232                             </table> <!-- /#invoice_adj_table -->
233                         [% END # /IF adjustments %]
234
235                         [% UNLESS readonly %]
236                             <div id="show_invoice_adjustment">
237                                 <p>
238                                     <a href="#" class="toggle_invoice_adjustment"><i class="fa fa-plus"></i> Add an adjustment</a>
239                                 </p>
240                             </div>
241
242                             <fieldset id="add_invoice_adjustment" style="display:none">
243                                 <h4>Add an adjustment</h4>
244                                 <input type="hidden" name="adjustment_id" value="new" />
245                                 <ol>
246                                     <li>
247                                         <label for="adjustment_new">Amount: </label>
248                                         <input class="decimal" type="text" name="adjustment" id="adjustment_new" />
249                                     </li>
250                                     [% reasons = AuthorisedValues.Get("ADJ_REASON") %]
251                                     [% IF reasons.0 %]
252                                         <li>
253                                             <label for="reason_[% adjustment.adjustment_id | html %]">Reason: </label>
254                                             <select id="reason_[% adjustment.adjustment_id | html %]" name="reason">
255                                                 <option value="">No reason</option>
256                                                 [% FOREACH reason IN reasons %]
257                                                     <option value="[% reason.authorised_value | html %]">
258                                                         [% reason.lib | html %]
259                                                     </option>
260                                                 [% END %]
261                                             </select>
262                                         </li>
263                                     [% ELSE %]
264                                         <li>
265                                             <span class="label">Reason: </span>
266                                             <span>None</span>
267                                             <div class="hint">Define values in authorised value category ADJ_REASON to enable</div>
268                                         </li>
269                                     [% END # /IF reasons.0 %]
270                                     <li>
271                                         <label for="note_new">Note: </label>
272                                         <input type="text" name="note" id="note_new" value=""/>
273                                     </li>
274                                     <li>
275                                         <label for="budget_id_new">Fund: </label>
276                                         [% PROCESS fund_dropdown form_id => "budget_id_new" form_name => 'budget_id' selected => "" %]
277                                     </li>
278                                     <li>
279                                         <label for="encumber_new">Encumber while invoice open? </label>
280                                         <input type="checkbox" name="encumber_open" id="encumber_new" value="new" />
281                                         <input type="hidden" name="delete" value="">
282                                     </li>
283                                 </ol>
284                             </fieldset> <!-- /#add_invoice_adjustment -->
285                         [% END #/UNLESS readonly %]
286                     </fieldset>
287                     [% UNLESS readonly %]
288                         <fieldset class="action" id="submit_invoice_adjustment">
289                             <input type="hidden" name="op" value="mod_adj" />
290                             <input type="submit" class="btn btn-primary" value="Update adjustments" />
291                             <a href="#" id="cancel_invoice_adjustment" class="toggle_invoice_adjustment cancel" style="display:none"><i class="fa fa-times"></i> Cancel</a>
292                         </fieldset>
293                     [% END #/UNLESS readonly %]
294                 </form>
295
296                 <p>
297                     <a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid | uri %]">Go to receipt page</a>
298                     [% IF Koha.Preference('AcqEnableFiles') %]| <a href="/cgi-bin/koha/acqui/invoice-files.pl?invoiceid=[% invoiceid | uri %]">Manage invoice files</a>[% END %]
299                 </p>
300
301                 <fieldset>
302                     <legend>Invoice details</legend>
303                     [% IF orders_loop.size %]
304                         <label for="show_all_details">
305                             <input type="checkbox" style="vertical-align: middle;" id="show_all_details" />
306                             Show all details
307                         </label>
308                         <table id="orderst">
309                             <thead>
310                                 <tr>
311                                     <th class="anti-the">Summary</th>
312                                     <th>Library</th>
313                                     [% IF has_invoice_unitprice %]
314                                         <th>Invoice price</th>
315                                     [% END %]
316                                     <th class="tax_excluded">Actual cost tax exc.</th>
317                                     <th class="tax_included">Actual cost tax inc.</th>
318                                     <th class="replacementprice">Replacement price</th>
319                                     <th>Qty.</th>
320                                     <th class="tax_excluded">Total tax exc. ([% currency.symbol | html %])</th>
321                                     <th class="tax_included">Total tax inc. ([% currency.symbol | html %])</th>
322                                     <th>GST %</th>
323                                     <th>GST</th>
324                                     <th>Fund</th>
325                                 </tr>
326                             </thead>
327                             <tbody>
328                                 [% FOREACH order IN orders_loop %]
329                                     <tr>
330                                         <td>
331                                             [% IF order.biblionumber %]
332                                                 [% INCLUDE 'biblio-title.inc' biblio=order link = 1 %]
333                                                 [% IF ( order.author ) %]
334                                                     <br /><em>by</em> [% order.author | html %]
335                                                 [% END %]
336                                             [% ELSE %]
337                                                 <em>Deleted bibliographic record, can't find title</em>
338                                             [% END %]
339                                             [% IF ( order.isbn ) %] &ndash; [% order.isbn | html %][% END %]
340                                             [% IF ( order.publishercode ) %]
341                                                 <br/>[% order.publishercode | html %]
342                                                 [% IF order.publicationyear %], [% order.publicationyear | html %]
343                                                 [% ELSIF ( order.copyrightdate ) %][% order.copyrightdate | html %][% END %]
344                                             [% END %]
345                                         </td>
346                                         <td>
347                                             <p>[% order.branchcode | html %]</p>
348                                             [% IF has_invoice_unitprice %]
349                                                 <td>
350                                                     [% IF order.invoice_unitprice %]
351                                                         [% order.invoice_unitprice | $Price %] [% order.invoice_currency | html %]
352                                                     [% END %]
353                                                 </td>
354                                             [% END %]
355                                         </td>
356                                         <td class="number tax_excluded">
357                                             [% order.unitprice_tax_excluded | $Price %]
358                                         </td>
359                                         <td class="number tax_included">
360                                             [% order.unitprice_tax_included | $Price %]
361                                         </td>
362                                         <td class="number replacementprice">
363                                             [% order.replacementprice | $Price %]
364                                             [% IF ( order.uncertainprice ) %]
365                                                 <span>(Uncertain)</span>
366                                             [% END %]
367                                         </td>
368                                         <td class="number">
369                                             [% order.quantity | html %]
370                                         </td>
371                                         <td class="number tax_excluded">
372                                             [% order.total_tax_excluded | $Price %]
373                                         </td>
374                                         <td class="number tax_included">
375                                             [% order.total_tax_included | $Price %]
376                                         </td>
377                                         <td class="number">
378                                             [% order.tax_rate * 100 | html %]
379                                         </td>
380                                         <td class="number">
381                                             [% order.tax_value | $Price %]
382                                         </td>
383                                         <td>
384                                             <span class="order_name" data-order_id="[% order.ordernumber | html %]">[% order.budget_name | html %]</span></br>
385                                             <a href="#" class="modify_fund" data-order_id="[% order.ordernumber | html %]" data-budget_id="[% order.budget_id | html %]" data-sort_1="[% order.sort1 | html %]" data-sort_2="[% order.sort2 | html %]" data-sort1="[% order.sort1 | html %]" data-sort2="[% order.sort2 | html %]">Modify fund</a>
386                                         </td>
387                                     </tr>
388                                 [% END # /FOREACH order %]
389                             </tbody>
390                             <tfoot>
391                                 [% FOR tf IN foot_loop %]
392                                     <tr>
393                                         <th colspan="2">Total (GST [% tf.tax_rate * 100 | html %] %)</th>
394                                         [% IF has_invoice_unitprice %]
395                                             <th></th>
396                                         [% END %]
397                                         <th class="tax_excluded"></th>
398                                         <th class="tax_included"></th>
399                                         <th class="replacementprice"/>
400                                         <th>[% tf.quantity | html %]</th>
401                                         <th class="tax_excluded">[% tf.total_tax_excluded | $Price %]</th>
402                                         <th class="tax_included">[% tf.total_tax_included | $Price %]</th>
403                                         <th>&nbsp;</th>
404                                         <th>[% tf.tax_value | $Price %]</th>
405                                         <th>&nbsp;</th>
406                                     </tr>
407                                 [% END # /FOR tf %]
408                                 <tr>
409                                     <th colspan="2">Total ([% currency.symbol | html %])</th>
410                                     [% IF has_invoice_unitprice %]
411                                         <th></th>
412                                     [% END %]
413                                     <th class="tax_excluded"></th>
414                                     <th class="tax_included"></th>
415                                     <th class="replacementprice"/>
416                                     <th>[% total_quantity | html %]</th>
417                                     <th class="tax_excluded">[% total_tax_excluded | $Price %]</th>
418                                     <th class="tax_included">[% total_tax_included | $Price %]</th>
419                                     <th>&nbsp;</th>
420                                     <th>[% total_tax_value | $Price %]</th>
421                                     <th>&nbsp;</th>
422                                 </tr>
423                                 <tr>
424                                     <th colspan="2">Total + adjustments + shipment cost ([% currency.symbol | html %])</th>
425                                     [% IF has_invoice_unitprice %]
426                                         <th></th>
427                                     [% END %]
428                                     <th class="tax_excluded"></th>
429                                     <th class="tax_included"></th>
430                                     <th class="replacementprice"/>
431                                     <th>[% total_quantity | html %]</th>
432                                     <th class="tax_excluded">[% total_tax_excluded_shipment + total_adj | $Price %]</th>
433                                     <th class="tax_included">[% total_tax_included_shipment + total_adj | $Price %]</th>
434                                     <th>&nbsp;</th>
435                                     <th>[% total_tax_value | $Price %]</th>
436                                     <th>&nbsp;</th>
437                                 </tr>
438                             </tfoot>
439                         </table> <!-- /#orderst -->
440                     [% ELSE %]
441                         <div class="dialog message">
442                             <p>No orders yet</p>
443                             [% IF adjustments && adjustments.count > 0 || shipmentcost && shipmentcost > 0 %]
444                                 <p>Adjustments plus shipping: [% total_adj + shipmentcost | $Price %]</p>
445                             [% END %]
446                         </div>
447                     [% END # /IF orders_loop.size %]
448                 </fieldset>
449
450                 [% IF ( (Koha.Preference('AcqEnableFiles')) && files ) %]
451                     <div class="page-section">
452                         <h2>Files attached to invoice</h2>
453                         <table id="invoice_files_table">
454                             <thead>
455                                 <tr>
456                                     <th>Name</th>
457                                     <th>Type</th>
458                                     <th>Description</th>
459                                     <th>Uploaded</th>
460                                 </tr>
461                             </thead>
462                             <tbody>
463                                 [% FOREACH f IN files %]
464                                     <tr>
465                                         <td>
466                                             <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>
467                                         </td>
468                                         <td>[% f.file_type | html %]</td>
469                                         <td>[% f.file_description | html %]</td>
470                                         <td data-order="[% f.date_uploaded | html %]">
471                                             [% f.date_uploaded | $KohaDates %]
472                                         </td>
473                                     </tr>
474                                 [% END %]
475                             </tbody>
476                         </table> <!-- /#invoice_files_table -->
477                     </div>
478                 [% END # /IF AcqEnableFiles %]
479             </main>
480         </div> <!-- /.col-sm-10.col-sm-push-2 -->
481
482         <aside>
483             <div class="col-sm-2 col-sm-pull-10">
484                 [% INCLUDE 'acquisitions-menu.inc' %]
485             </div>
486         </aside>
487     </div> <!-- /.row -->
488
489 <div id="updateFund" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="updateReceivedFund" aria-hidden="true">
490     <div class="modal-dialog">
491         <div class="modal-content">
492             <div class="modal-header">
493                 <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
494                 <h3 id="updateReceivedFund">Update received fund</h3>
495             </div>
496             <div class="modal-body">
497                 <p>Updating the fund may change available statistics for the order, please check values before submitting.</p>
498                 <fieldset class="rows">
499                     <ol>
500                         <li>
501                             [% PROCESS fund_dropdown form_id => 'modify_budget_id' form_name => 'modify_budget_id' selected => "" %]
502                         </li>
503                         <li>
504                             <label for="sort1">Statistic 1: </label>
505                             <input type="text" name="sort1" />
506                         </li>
507                         <li>
508                             <label for="sort2">Statistic 2: </label>
509                             <input type="text" name="sort2" />
510                         </li>
511                     </ol>
512                 </fieldset>
513                 <a id="update_fund" class="btn btn-default">Update fund</a>
514             </div>
515             <div class="modal-footer">
516                 <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
517             </div> <!-- /.modal-footer -->
518         </div> <!-- /.modal-content -->
519     </div> <!-- /.modal-dialog -->
520 </div> <!-- /#updateFund.modal -->
521
522 <span style="display:none;" id="all_fund_dropdown">
523     [% FOREACH budget IN budgets %]
524         [% IF ( budget.b_active ) %]
525             <option value="[% budget.b_id | html %]" data-sort1-authcat="[% budget.b_sort1_authcat | html %]" data-sort2-authcat="[% budget.b_sort2_authcat | html %]">[% budget.b_txt | html %]</option>
526         [% ELSE %]
527             <option value="[% budget.b_id | html %]" class="b_inactive" data-sort1-authcat="[% budget.b_sort1_authcat | html %]" data-sort2-authcat="[% budget.b_sort2_authcat |html %]">[% budget.b_txt | html %] (inactive)</option>
528         [% END %]
529     [% END # /FOREACH budget %]
530 </span> <!-- /#all_fund_dropdown -->
531
532 [% MACRO jsinclude BLOCK %]
533     [% Asset.js("js/acquisitions-menu.js") | $raw %]
534     [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
535     [% Asset.js("js/acq.js") | $raw %]
536     [% INCLUDE 'calendar.inc' %]
537     [% INCLUDE 'datatables.inc' %]
538     <script>
539         function updateColumnsVisibility(visible) {
540             if ( visible ) {
541                 $("table .tax_excluded, .tax_included").show();
542             } else {
543                 [% IF ( invoiceincgst ) %]
544                     $("table .tax_excluded").hide();
545                 [% ELSE %]
546                     $("table .tax_included").hide();
547                 [% END %]
548             }
549         }
550
551         $(document).ready(function() {
552             $("#delete").click(function(){
553                 return confirmDelete(_("Are you sure you want to delete this invoice?"));
554             });
555             $("#orderst").dataTable($.extend(true, {}, dataTablesDefaults, {
556                 bInfo: false,
557                 bPaginate: false,
558                 bFilter: false,
559                 sDom: "t",
560                 "aoColumnDefs": [
561                     { "sType": "anti-the", "aTargets": [ "anti-the" ] }
562                 ]
563             }));
564             [% IF ( (Koha.Preference('AcqEnableFiles')) && files ) %]
565                 $("#invoice_files_table").dataTable($.extend(true, {}, dataTablesDefaults, {
566                     bInfo: false,
567                     bPaginate: false,
568                     bFilter: false,
569                     sDom: "t"
570                 }));
571             [% END %]
572             $("#show_all_details").click(function(){
573                 updateColumnsVisibility( $(this).is(":checked") );
574             });
575
576             $("#show_all_details").prop('checked', false);
577             updateColumnsVisibility(false);
578             $(".toggle_invoice_adjustment").on("click", function(e){
579                 e.preventDefault();
580                 $("#show_invoice_adjustment, #cancel_invoice_adjustment, #add_invoice_adjustment").toggle();
581             });
582             $("a.delete_adjustment").click(function(){
583                 return ( confirm( _("Are you sure you want to delete this file ?") ) );
584             });
585
586             //keep a copy of all budgets before removing the inactives
587             var disabledBudgetsCopy = $("#all_fund_dropdown").html();
588             $(".fund_dropdown").each(function(){
589                 $(this).html( disabledBudgetsCopy);
590                 var selected = $(this).data('selected');
591                 $(this).find('option[value="'+selected+'"]').removeClass('b_inactive');
592                 $(this).val( selected );
593             });
594
595             $('.b_inactive').remove();
596
597             $('.showallfunds').click(function() {
598                 var the_dropdown = $(this).siblings('.fund_dropdown');
599                 var selected = the_dropdown.val();
600                 if ($(this).is(":checked")) {
601                     the_dropdown.html(disabledBudgetsCopy).val(selected);
602                 }
603                 else {
604                     the_dropdown.find('option[value="'+selected+'"]').removeClass('b_inactive');
605                     $(this).siblings().find('.b_inactive').remove();
606                 }
607             });
608
609             $(".modify_fund").on('click',function(e){
610                 e.preventDefault();
611                 var selected = $(this).data('budget_id');
612                 var sort1 = $(this).data('sort1');
613                 var sort2 = $(this).data('sort2');
614                 $("#update_fund").data('order_id',$(this).data('order_id'));
615                 $("#modify_budget_id").html(disabledBudgetsCopy);
616                 $("#modify_budget_id").val(selected).find('option[value="'+selected+'"]').removeClass('b_inactive');
617                 $("#sort1").val(sort1);
618                 $("#sort2").val(sort2);
619                 $("#modify_budget_id").find('.b_inactive').remove();
620                 $("#modify_budget_id").change();
621                 $("#updateFund").modal('show');
622             });
623             $("#update_fund").on('click',function(){
624                 var new_fund = $("#modify_budget_id").val();
625                 var sort1 = $("#sort1").val();
626                 var sort2 = $("#sort2").val();
627                 var new_fund_name = $('#modify_budget_id option[value="'+new_fund+'"]').text();
628                 var order_id = $(this).data('order_id');
629                 let options = {
630                     url: "/api/v1/acquisitions/orders/" + order_id,
631                     method: 'PUT',
632                     contentType: 'application/json',
633                     data: JSON.stringify({
634                         fund_id: new_fund,
635                         statistics_1: sort1,
636                         statistics_2: sort2
637                     })
638                 };
639                 $.ajax(options)
640                     .then(function(thing,result){
641                         $("#updateFund").modal('hide');
642                         $('#updateFund .showallfunds').prop('checked',false);
643                         $('.modify_fund[data-order_id="'+order_id+'"]').data('budget_id',new_fund);
644                         $('.order_name[data-order_id="'+order_id+'"]').text(new_fund_name);
645                         humanMsg.displayAlert( _("Order updated"), { className: 'humanError' } );
646                     })
647                     .fail(function(err){
648                         humanMsg.displayAlert( _("Failed to update order:") + err.responseText, { className: 'humanError' } );
649                     });
650             });
651             $("#modify_budget_id").change(function(){
652                 var destination_sort1 = $(this).parents('.modal-body').find('input[name="sort1"]');
653                 var sort1_authcat = $(this).find("option:selected").attr('data-sort1-authcat');
654                 var sort1 = $(destination_sort1).val() || "";
655                 if ( destination_sort1.length < 1 ) {
656                     destination_sort1 = $(this).parents('.modal-body').find('select[name="sort1"]');
657                 }
658                 var destination_sort2 = $(this).parents('.modal-body').find('input[name="sort2"]');
659                 var sort2_authcat = $(this).find("option:selected").attr('data-sort2-authcat');
660                 var sort2 = $(destination_sort2).val() || "";
661                 if ( destination_sort2.length < 1 ) {
662                     destination_sort2 = $(this).parents('.modal-body').find('select[name="sort2"]');
663                 }
664                 getAuthValueDropbox( 'sort1', sort1_authcat, destination_sort1, sort1 );
665                 getAuthValueDropbox( 'sort2', sort2_authcat, destination_sort2, sort2 );
666             });
667             // same effort for the adjustments
668             var adjBudgetId = $("#budget_id_new");
669             var disabledAdjBudgetsCopy = adjBudgetId.html();
670             $('.ab_inactive').remove();
671             $('#showallfunds_adj').click(function() {
672                 if ($(this).is(":checked")) {
673                     adjBudgetId.html(disabledAdjBudgetsCopy); //Puts back all the funds
674                 }
675                 else {
676                     $('.ab_inactive').remove();
677                 }
678             });
679         });
680     </script>
681 [% END %]
682
683 [% INCLUDE 'intranet-bottom.inc' %]