Bug 33001: Use template wrapper for breadcrumbs: Acquisitions part 2
[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     <label for="[% form_name | html %]">Fund: </label>
11     <select id="[% form_id | html %]" name="[% form_name | html %]" class="fund_dropdown" data-selected="[% selected | html %]">
12     </select>
13     <label for="showallfunds">&nbsp;Show inactive:</label>
14     <input type="checkbox" class="showallfunds" />
15 [% END %]
16
17 [% INCLUDE 'doc-head-open.inc' %]
18 <title>Invoice &rsaquo; Acquisitions &rsaquo; Koha</title>
19 [% INCLUDE 'doc-head-close.inc' %]
20 [% Asset.css("css/humanmsg.css") | $raw %]
21 </head>
22
23 <body id="acq_invoice" class="acq">
24 [% WRAPPER 'header.inc' %]
25     [% INCLUDE 'acquisitions-search.inc' %]
26 [% END %]
27
28 [% SET readonly = NOT CAN_user_acquisition_edit_invoices %]
29
30 [% WRAPPER 'sub-header.inc' %]
31     [% WRAPPER breadcrumbs %]
32         [% WRAPPER breadcrumb_item %]
33             <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a>
34         [% END %]
35         [% WRAPPER breadcrumb_item %]
36             <a href="/cgi-bin/koha/acqui/invoices.pl">Invoices</a>
37         [% END %]
38         [% WRAPPER breadcrumb_item bc_active=1 %]
39             [% invoicenumber | html %]
40         [% END %]
41     [% END #/ WRAPPER breadcrumbs %]
42 [% END #/ WRAPPER sub-header.inc %]
43
44 <div class="main container-fluid">
45     <div class="row">
46         <div class="col-sm-10 col-sm-push-2">
47             <main>
48
49                 <h1>Invoice: [% invoicenumber | html %]</h1>
50                 [% INCLUDE 'blocking_errors.inc' %]
51
52                 [% IF ( modified ) %]
53                     <div class="dialog message">
54                         <p>Invoice has been modified</p>
55                     </div>
56                 [% END %]
57
58                 <p>Vendor: <a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% booksellerid | uri %]">[% suppliername | html %]</a></p>
59
60                 <form action="/cgi-bin/koha/acqui/invoice.pl" method="post" class="validated">
61                     <fieldset class="rows">
62                         <ol>
63                             <li>
64                                 [% IF readonly %]
65                                     <label for="shipmentdate">Invoice number:</label>
66                                     [% invoicenumber | html %]
67                                 [% ELSE %]
68                                     <label for="shipmentdate" class="required">Invoice number:</label>
69                                     <input type="text" id="invoicenumber" name="invoicenumber" value="[% invoicenumber | html %]" class="required" required="required"/>
70                                     <span class="required">Required</span>
71                                 [% END %]
72                             </li>
73                             <li>
74                                 <label for="shipmentdate">Shipment date:</label>
75                                 [% IF readonly %]
76                                     [% shipmentdate | $KohaDates %]
77                                 [% ELSE %]
78                                     <input type="text" size="10" id="shipmentdate" name="shipmentdate" value="[% shipmentdate | html %]" class="flatpickr" />
79                                     <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
80                                 [% END %]
81                             </li>
82                             <li>
83                                 <label for="billingdate">Billing date:</label>
84                                 [% IF readonly %]
85                                     [% billingdate | $KohaDates %]
86                                 [% ELSE %]
87                                     <input type="text" size="10" id="billingdate" name="billingdate" value="[% billingdate | html %]" class="flatpickr" />
88                                     <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
89                                 [% END %]
90                             </li>
91                             <li>
92                                 <label for="shipmentcost">Shipping cost:</label>
93                                 [% IF readonly %]
94                                     [% shipmentcost | $Price %]
95                                 [% ELSE %]
96                                     <input type="text" size="10" id="shipmentcost" name="shipmentcost" value="[% shipmentcost | $Price on_editing => 1 %]" />
97                                 [% END %]
98                             </li>
99                             <li>
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 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"></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 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                                         [% PROCESS fund_dropdown form_id => "budget_id_new" form_name => 'budget_id' selected => "" %]
276                                     </li>
277                                     <li>
278                                         <label for="encumber_new">Encumber while invoice open? </label>
279                                         <input type="checkbox" name="encumber_open" id="encumber_new" value="new" />
280                                         <input type="hidden" name="delete" value="">
281                                     </li>
282                                 </ol>
283                             </fieldset> <!-- /#add_invoice_adjustment -->
284                         [% END #/UNLESS readonly %]
285                     </fieldset>
286                     [% UNLESS readonly %]
287                         <fieldset class="action" id="submit_invoice_adjustment" style="display:none">
288                             <input type="hidden" name="op" value="mod_adj" />
289                             <input type="submit" class="btn btn-primary" value="Update adjustments" />
290                             <a href="#" id="cancel_invoice_adjustment" class="toggle_invoice_adjustment cancel" style="display:none"><i class="fa fa-remove"></i> Cancel</a>
291                         </fieldset>
292                     [% END #/UNLESS readonly %]
293                 </form>
294
295                 <p>
296                     <a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid | uri %]">Go to receipt page</a>
297                     [% IF Koha.Preference('AcqEnableFiles') %]| <a href="/cgi-bin/koha/acqui/invoice-files.pl?invoiceid=[% invoiceid | uri %]">Manage invoice files</a>[% END %]
298                 </p>
299
300                 <fieldset>
301                     <legend>Invoice details</legend>
302                     [% IF orders_loop.size %]
303                         <label for="show_all_details">
304                             <input type="checkbox" style="vertical-align: middle;" id="show_all_details" />
305                             Show all details
306                         </label>
307                         <table id="orderst">
308                             <thead>
309                                 <tr>
310                                     <th class="anti-the">Summary</th>
311                                     <th>Library</th>
312                                     [% IF has_invoice_unitprice %]
313                                         <th>Invoice price</th>
314                                     [% END %]
315                                     <th class="tax_excluded">Actual cost tax exc.</th>
316                                     <th class="tax_included">Actual cost tax inc.</th>
317                                     <th class="replacementprice">Replacement price</th>
318                                     <th>Qty.</th>
319                                     <th class="tax_excluded">Total tax exc. ([% currency.symbol | html %])</th>
320                                     <th class="tax_included">Total tax inc. ([% currency.symbol | html %])</th>
321                                     <th>GST %</th>
322                                     <th>GST</th>
323                                     <th>Fund</th>
324                                 </tr>
325                             </thead>
326                             <tbody>
327                                 [% FOREACH order IN orders_loop %]
328                                     <tr>
329                                         <td>
330                                             [% IF order.biblionumber %]
331                                                 [% INCLUDE 'biblio-title.inc' biblio=order link = 1 %]
332                                                 [% IF ( order.author ) %]
333                                                     <br /><em>by</em> [% order.author | html %]
334                                                 [% END %]
335                                             [% ELSE %]
336                                                 <em>Deleted bibliographic record, can't find title</em>
337                                             [% END %]
338                                             [% IF ( order.isbn ) %] &ndash; [% order.isbn | html %][% END %]
339                                             [% IF ( order.publishercode ) %]
340                                                 <br/>[% order.publishercode | html %]
341                                                 [% IF order.publicationyear %], [% order.publicationyear | html %]
342                                                 [% ELSIF ( order.copyrightdate ) %][% order.copyrightdate | html %][% END %]
343                                             [% END %]
344                                         </td>
345                                         <td>
346                                             <p>[% order.branchcode | html %]</p>
347                                             [% IF has_invoice_unitprice %]
348                                                 <td>
349                                                     [% IF order.invoice_unitprice %]
350                                                         [% order.invoice_unitprice | $Price %] [% order.invoice_currency | html %]
351                                                     [% END %]
352                                                 </td>
353                                             [% END %]
354                                         </td>
355                                         <td class="number tax_excluded">
356                                             [% order.unitprice_tax_excluded | $Price %]
357                                         </td>
358                                         <td class="number tax_included">
359                                             [% order.unitprice_tax_included | $Price %]
360                                         </td>
361                                         <td class="number replacementprice">
362                                             [% order.replacementprice | $Price %]
363                                             [% IF ( order.uncertainprice ) %]
364                                                 <span>(Uncertain)</span>
365                                             [% END %]
366                                         </td>
367                                         <td class="number">
368                                             [% order.quantity | html %]
369                                         </td>
370                                         <td class="number tax_excluded">
371                                             [% order.total_tax_excluded | $Price %]
372                                         </td>
373                                         <td class="number tax_included">
374                                             [% order.total_tax_included | $Price %]
375                                         </td>
376                                         <td class="number">
377                                             [% order.tax_rate * 100 | html %]
378                                         </td>
379                                         <td class="number">
380                                             [% order.tax_value | $Price %]
381                                         </td>
382                                         <td>
383                                             <span class="order_name" data-order_id="[% order.ordernumber | html %]">[% order.budget_name | html %]</span></br>
384                                             <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>
385                                         </td>
386                                     </tr>
387                                 [% END # /FOREACH order %]
388                             </tbody>
389                             <tfoot>
390                                 [% FOR tf IN foot_loop %]
391                                     <tr>
392                                         <th colspan="2">Total (GST [% tf.tax_rate * 100 | html %] %)</th>
393                                         [% IF has_invoice_unitprice %]
394                                             <th></th>
395                                         [% END %]
396                                         <th class="tax_excluded"></th>
397                                         <th class="tax_included"></th>
398                                         <th class="replacementprice"/>
399                                         <th>[% tf.quantity | html %]</th>
400                                         <th class="tax_excluded">[% tf.total_tax_excluded | $Price %]</th>
401                                         <th class="tax_included">[% tf.total_tax_included | $Price %]</th>
402                                         <th>&nbsp;</th>
403                                         <th>[% tf.tax_value | $Price %]</th>
404                                         <th>&nbsp;</th>
405                                     </tr>
406                                 [% END # /FOR tf %]
407                                 <tr>
408                                     <th colspan="2">Total ([% currency.symbol | html %])</th>
409                                     [% IF has_invoice_unitprice %]
410                                         <th></th>
411                                     [% END %]
412                                     <th class="tax_excluded"></th>
413                                     <th class="tax_included"></th>
414                                     <th class="replacementprice"/>
415                                     <th>[% total_quantity | html %]</th>
416                                     <th class="tax_excluded">[% total_tax_excluded | $Price %]</th>
417                                     <th class="tax_included">[% total_tax_included | $Price %]</th>
418                                     <th>&nbsp;</th>
419                                     <th>[% total_tax_value | $Price %]</th>
420                                     <th>&nbsp;</th>
421                                 </tr>
422                                 <tr>
423                                     <th colspan="2">Total + adjustments + shipment cost ([% currency.symbol | html %])</th>
424                                     [% IF has_invoice_unitprice %]
425                                         <th></th>
426                                     [% END %]
427                                     <th class="tax_excluded"></th>
428                                     <th class="tax_included"></th>
429                                     <th class="replacementprice"/>
430                                     <th>[% total_quantity | html %]</th>
431                                     <th class="tax_excluded">[% total_tax_excluded_shipment + total_adj | $Price %]</th>
432                                     <th class="tax_included">[% total_tax_included_shipment + total_adj | $Price %]</th>
433                                     <th>&nbsp;</th>
434                                     <th>[% total_tax_value | $Price %]</th>
435                                     <th>&nbsp;</th>
436                                 </tr>
437                             </tfoot>
438                         </table> <!-- /#orderst -->
439                     [% ELSE %]
440                         <div class="dialog message">
441                             <p>No orders yet</p>
442                             [% IF adjustments && adjustments.count > 0 || shipmentcost && shipmentcost > 0 %]
443                                 <p>Adjustments plus shipping: [% total_adj + shipmentcost | $Price %]</p>
444                             [% END %]
445                         </div>
446                     [% END # /IF orders_loop.size %]
447                 </fieldset>
448
449                 [% IF ( (Koha.Preference('AcqEnableFiles')) && files ) %]
450                     <div class="page-section">
451                         <h2>Files attached to invoice</h2>
452                         <table id="invoice_files_table">
453                             <thead>
454                                 <tr>
455                                     <th>Name</th>
456                                     <th>Type</th>
457                                     <th>Description</th>
458                                     <th>Uploaded</th>
459                                 </tr>
460                             </thead>
461                             <tbody>
462                                 [% FOREACH f IN files %]
463                                     <tr>
464                                         <td>
465                                             <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>
466                                         </td>
467                                         <td>[% f.file_type | html %]</td>
468                                         <td>[% f.file_description | html %]</td>
469                                         <td data-order="[% f.date_uploaded | html %]">
470                                             [% f.date_uploaded | $KohaDates %]
471                                         </td>
472                                     </tr>
473                                 [% END %]
474                             </tbody>
475                         </table> <!-- /#invoice_files_table -->
476                     </div>
477                 [% END # /IF AcqEnableFiles %]
478             </main>
479         </div> <!-- /.col-sm-10.col-sm-push-2 -->
480
481         <aside>
482             <div class="col-sm-2 col-sm-pull-10">
483                 [% INCLUDE 'acquisitions-menu.inc' %]
484             </div>
485         </aside>
486     </div> <!-- /.row -->
487
488 <div id="updateFund" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="updateReceivedFund" aria-hidden="true">
489     <div class="modal-dialog">
490         <div class="modal-content">
491             <div class="modal-header">
492                 <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
493                 <h3 id="updateReceivedFund">Update received fund</h3>
494             </div>
495             <div class="modal-body">
496                 <p>Updating the fund may change available statistics for the order, please check values before submitting.</p>
497                 <fieldset class="rows">
498                     <ol>
499                         <li>
500                             [% PROCESS fund_dropdown form_id => 'modify_budget_id' form_name => 'modify_budget_id' selected => "" %]
501                         </li>
502                         <li>
503                             <label for="sort1">Statistic 1: </label>
504                             <input type="text" name="sort1" />
505                         </li>
506                         <li>
507                             <label for="sort2">Statistic 2: </label>
508                             <input type="text" name="sort2" />
509                         </li>
510                     </ol>
511                 </fieldset>
512                 <a id="update_fund" class="btn btn-default">Update fund</a>
513             </div>
514             <div class="modal-footer">
515                 <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
516             </div> <!-- /.modal-footer -->
517         </div> <!-- /.modal-content -->
518     </div> <!-- /.modal-dialog -->
519 </div> <!-- /#updateFund.modal -->
520
521 <span style="display:none;" id="all_fund_dropdown">
522     [% FOREACH budget IN budgets %]
523         [% IF ( budget.b_active ) %]
524             <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>
525         [% ELSE %]
526             <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>
527         [% END %]
528     [% END # /FOREACH budget %]
529 </span> <!-- /#all_fund_dropdown -->
530
531 [% MACRO jsinclude BLOCK %]
532     [% Asset.js("js/acquisitions-menu.js") | $raw %]
533     [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
534     [% Asset.js("js/acq.js") | $raw %]
535     [% INCLUDE 'calendar.inc' %]
536     [% INCLUDE 'datatables.inc' %]
537     <script>
538         function updateColumnsVisibility(visible) {
539             if ( visible ) {
540                 $("table .tax_excluded, .tax_included").show();
541             } else {
542                 [% IF ( invoiceincgst ) %]
543                     $("table .tax_excluded").hide();
544                 [% ELSE %]
545                     $("table .tax_included").hide();
546                 [% END %]
547             }
548         }
549
550         $(document).ready(function() {
551             $("#delete").click(function(){
552                 return confirmDelete(_("Are you sure you want to delete this invoice?"));
553             });
554             $("#orderst").dataTable($.extend(true, {}, dataTablesDefaults, {
555                 bInfo: false,
556                 bPaginate: false,
557                 bFilter: false,
558                 sDom: "t",
559                 "aoColumnDefs": [
560                     { "sType": "anti-the", "aTargets": [ "anti-the" ] }
561                 ]
562             }));
563             [% IF ( (Koha.Preference('AcqEnableFiles')) && files ) %]
564                 $("#invoice_files_table").dataTable($.extend(true, {}, dataTablesDefaults, {
565                     bInfo: false,
566                     bPaginate: false,
567                     bFilter: false,
568                     sDom: "t"
569                 }));
570             [% END %]
571             $("#show_all_details").click(function(){
572                 updateColumnsVisibility( $(this).is(":checked") );
573             });
574
575             $("#show_all_details").prop('checked', false);
576             updateColumnsVisibility(false);
577             $(".toggle_invoice_adjustment").on("click", function(e){
578                 e.preventDefault();
579                 $("#show_invoice_adjustment, #cancel_invoice_adjustment, #add_invoice_adjustment, #submit_invoice_adjustment").toggle();
580             });
581             $("a.delete_adjustment").click(function(){
582                 return ( confirm( _("Are you sure you want to delete this file ?") ) );
583             });
584
585             //keep a copy of all budgets before removing the inactives
586             var disabledBudgetsCopy = $("#all_fund_dropdown").html();
587             $(".fund_dropdown").each(function(){
588                 $(this).html( disabledBudgetsCopy);
589                 var selected = $(this).data('selected');
590                 $(this).find('option[value="'+selected+'"]').removeClass('b_inactive');
591                 $(this).val( selected );
592             });
593
594             $('.b_inactive').remove();
595
596             $('.showallfunds').click(function() {
597                 var the_dropdown = $(this).siblings('.fund_dropdown');
598                 var selected = the_dropdown.val();
599                 if ($(this).is(":checked")) {
600                     the_dropdown.html(disabledBudgetsCopy).val(selected);
601                 }
602                 else {
603                     the_dropdown.find('option[value="'+selected+'"]').removeClass('b_inactive');
604                     $(this).siblings().find('.b_inactive').remove();
605                 }
606             });
607
608             $(".modify_fund").on('click',function(e){
609                 e.preventDefault();
610                 var selected = $(this).data('budget_id');
611                 var sort1 = $(this).data('sort1');
612                 var sort2 = $(this).data('sort2');
613                 $("#update_fund").data('order_id',$(this).data('order_id'));
614                 $("#modify_budget_id").html(disabledBudgetsCopy);
615                 $("#modify_budget_id").val(selected).find('option[value="'+selected+'"]').removeClass('b_inactive');
616                 $("#sort1").val(sort1);
617                 $("#sort2").val(sort2);
618                 $("#modify_budget_id").find('.b_inactive').remove();
619                 $("#modify_budget_id").change();
620                 $("#updateFund").modal('show');
621             });
622             $("#update_fund").on('click',function(){
623                 var new_fund = $("#modify_budget_id").val();
624                 var sort1 = $("#sort1").val();
625                 var sort2 = $("#sort2").val();
626                 var new_fund_name = $('#modify_budget_id option[value="'+new_fund+'"]').text();
627                 var order_id = $(this).data('order_id');
628                 let options = {
629                     url: "/api/v1/acquisitions/orders/" + order_id,
630                     method: 'PUT',
631                     contentType: 'application/json',
632                     data: JSON.stringify({
633                         fund_id: new_fund,
634                         statistics_1: sort1,
635                         statistics_2: sort2
636                     })
637                 };
638                 $.ajax(options)
639                     .then(function(thing,result){
640                         $("#updateFund").modal('hide');
641                         $('#updateFund .showallfunds').prop('checked',false);
642                         $('.modify_fund[data-order_id="'+order_id+'"]').data('budget_id',new_fund);
643                         $('.order_name[data-order_id="'+order_id+'"]').text(new_fund_name);
644                         humanMsg.displayAlert( _("Order updated"), { className: 'humanError' } );
645                     })
646                     .fail(function(err){
647                         humanMsg.displayAlert( _("Failed to update order:") + err.responseText, { className: 'humanError' } );
648                     });
649             });
650             $("#modify_budget_id").change(function(){
651                 var destination_sort1 = $(this).parents('.modal-body').find('input[name="sort1"]');
652                 var sort1_authcat = $(this).find("option:selected").attr('data-sort1-authcat');
653                 var sort1 = $(destination_sort1).val() || "";
654                 if ( destination_sort1.length < 1 ) {
655                     destination_sort1 = $(this).parents('.modal-body').find('select[name="sort1"]');
656                 }
657                 var destination_sort2 = $(this).parents('.modal-body').find('input[name="sort2"]');
658                 var sort2_authcat = $(this).find("option:selected").attr('data-sort2-authcat');
659                 var sort2 = $(destination_sort2).val() || "";
660                 if ( destination_sort2.length < 1 ) {
661                     destination_sort2 = $(this).parents('.modal-body').find('select[name="sort2"]');
662                 }
663                 getAuthValueDropbox( 'sort1', sort1_authcat, destination_sort1, sort1 );
664                 getAuthValueDropbox( 'sort2', sort2_authcat, destination_sort2, sort2 );
665             });
666             // same effort for the adjustments
667             var adjBudgetId = $("#budget_id_new");
668             var disabledAdjBudgetsCopy = adjBudgetId.html();
669             $('.ab_inactive').remove();
670             $('#showallfunds_adj').click(function() {
671                 if ($(this).is(":checked")) {
672                     adjBudgetId.html(disabledAdjBudgetsCopy); //Puts back all the funds
673                 }
674                 else {
675                     $('.ab_inactive').remove();
676                 }
677             });
678         });
679     </script>
680 [% END %]
681
682 [% INCLUDE 'intranet-bottom.inc' %]