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