Bug 35329: Fix conflict with 33457
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / aqbudgets.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE AuthorisedValues %]
4 [% USE Branches %]
5 [% USE Price %]
6 [% PROCESS 'i18n.inc' %]
7 [% PROCESS 'patron-search.inc' %]
8 [% SET footerjs = 1 %]
9 [% INCLUDE 'doc-head-open.inc' %]
10
11 <title>[% FILTER collapse %]
12     [% IF op == 'add_form' %]
13         [% IF ( budget_id ) %]
14             [% IF ( budget_name ) %]
15                 [% tx("Modify fund '{fund_name}'", { fund_name = budget_name }) | html %]
16             [% ELSE %]
17                 [% t("Modify fund") | html %]
18             [% END %]
19         [% ELSE %]
20             [% IF ( budget_parent_name ) %]
21                 [% tx("Add fund to '{fund_parent}'", {fund_parent = budget_parent_name}) %]
22             [% ELSE %]
23                 [% t("New fund") | html %]
24             [% END %]
25         [% END %] &rsaquo;
26     [% END %]
27     [% IF op == 'list' || op == 'add_form' %]
28         [% IF budget_period_id %]
29             [% tx("Funds for budget '{budget}'", { budget = budget_period_description }) %]
30         [% ELSE %]
31             [% t("Funds") | html %]
32         [% END %] &rsaquo;
33     [% END %]
34     [% IF op == 'delete_confirm' %]
35         [% tx("Confirm deletion of fund '{fund}'", {fund = budget_name}) %] &rsaquo;
36     [% END %]
37     [% t("Funds") | html %] &rsaquo;
38     [% t("Budgets") | html %] &rsaquo;
39     [% t("Administration") | html %] &rsaquo;
40     [% t("Koha") | html %]
41 [% END %]</title>
42 [% Asset.css("lib/jquery/plugins/treetable/stylesheets/jquery.treetable.css") | $raw %]
43 [% INCLUDE 'doc-head-close.inc' %]
44 </head>
45
46 <body id="admin_aqbudgets" class="admin">
47 [% WRAPPER 'header.inc' %]
48     [% INCLUDE 'budgets-admin-search.inc' %]
49 [% END %]
50
51 [% WRAPPER 'sub-header.inc' %]
52     [% WRAPPER breadcrumbs %]
53         [% WRAPPER breadcrumb_item %]
54             <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
55         [% END %]
56         [% WRAPPER breadcrumb_item %]
57             <a href="/cgi-bin/koha/admin/aqbudgetperiods.pl">Budgets</a>
58         [% END %]
59
60         [% IF op == 'list' %]
61             [% IF budget_period_id %]
62                 [% WRAPPER breadcrumb_item %]
63                     <a href="/cgi-bin/koha/admin/aqbudgets.pl">Funds</a>
64                 [% END %]
65                 [% WRAPPER breadcrumb_item bc_active= 1 %]
66                     [% tx("Funds for budget '{budget}'", { budget = budget_period_description }) %]
67                 [% END %]
68             [% ELSE %]
69                 [% WRAPPER breadcrumb_item bc_active= 1 %]
70                     <span>Funds</span>
71                 [% END %]
72             [% END %]
73         [% END %]
74
75         [% IF op == 'add_form' %]
76             [% WRAPPER breadcrumb_item %]
77                 <a href="/cgi-bin/koha/admin/aqbudgets.pl">Funds</a>
78             [% END %]
79             [% IF ( budget_period_id ) %]
80                 [% WRAPPER breadcrumb_item %]
81                     <a href="/cgi-bin/koha/admin/aqbudgets.pl?budget_period_id=[% budget_period_id | uri %]">[% tx("Funds for '{budget}'", { budget = budget_period_description }) %]</a>
82                 [% END %]
83             [% END %]
84             [% IF ( budget_id ) %]
85                 [% WRAPPER breadcrumb_item bc_active= 1 %]
86                     [% IF ( budget_name ) %]
87                         [% tx("Modify fund '{fund_name}'", { fund_name = budget_name }) | html %]
88                     [% ELSE %]
89                         <span>Modify fund</span>
90                     [% END %]
91                 [% END %]
92             [% ELSE %]
93                 [% WRAPPER breadcrumb_item bc_active= 1 %]
94                     [% IF ( budget_parent_name ) %]
95                         [% tx("Add fund to '{fund_parent}'", {fund_parent = budget_parent_name}) %]
96                     [% ELSE %]
97                         <span>New fund</span>
98                     [% END %]
99                 [% END %]
100             [% END %]
101         [% END %]
102
103         [% IF op == 'delete_confirm' %]
104             [% WRAPPER breadcrumb_item %]
105                 <a href="/cgi-bin/koha/admin/aqbudgets.pl">Funds</a>
106             [% END %]
107             [% WRAPPER breadcrumb_item bc_active= 1 %]
108                 [% tx("Confirm deletion of fund '{fund}'", {fund = budget_name}) %]
109             [% END %]
110         [% END %]
111     [% END #/ WRAPPER breadcrumbs %]
112 [% END #/ WRAPPER sub-header.inc %]
113
114 <div class="main container-fluid">
115     <div class="row">
116         <div class="col-sm-10 col-sm-push-2">
117             <main>
118                 [% INCLUDE 'messages.inc' %]
119
120 [% UNLESS op == 'delete_confirm' %][% INCLUDE 'budgets-admin-toolbar.inc' %][% END %]
121
122 [% IF (error_not_authorised_to_modify) %]
123     <div class="dialog alert">
124         <p>You are not authorized to modify this fund</p>
125     </div>
126 [% END %]
127
128 [% IF op == 'list' %]
129
130 <h1>
131     [% IF budget_period_id %]
132         [% tx("Funds for budget '{budget}'", {budget = budget_period_description}) %]
133     [% ELSE %]
134         <span>Funds</span>
135     [% END %]
136 </h1>
137
138 [% INCLUDE 'budgets-active-currency.inc' %]
139
140 [% IF budgets %]
141
142     [% UNLESS budget_period_id %]
143         <div class="toolbar btn-toolbar">
144             <span class="actions">
145                 <a href="#" id="expand_all">Expand all</a> |
146                 <a href="#" id="collapse_all">Collapse all</a> |
147                 <a href="#" id="hide_inactive">Hide inactive budgets</a> |
148                 <a href="#" id="show_inactive">Show inactive budgets</a>
149             </span>
150         </div>
151     [% END %]
152 <div class="page-section">
153 <table id="budgeth" class="group">
154     <thead>
155         <tr>
156             <th>Active</th>
157             <th>Budget period description</th>
158             <th>Fund code</th>
159             <th>Fund name</th>
160             <th>Base-level allocated</th>
161             <th>Base-level ordered</th>
162             <th>Total ordered</th>
163             <th>Base-level spent</th>
164             <th>Total spent</th>
165             <th>Base-level available</th>
166             <th>Total available</th>
167             <th class="noExport">Actions</th>
168         </tr>
169     </thead>
170     <tfoot>
171     <tr>
172     <th></th>
173     <th></th>
174     <th colspan="2" style="text-align: left;" nowrap="nowrap">Period allocated [% IF budget_period_total %][% budget_period_total | $Price %][% END %]  </th>
175     <th nowrap="nowrap" class="data"> [% period_alloc_total | $Price %]</th>
176     <th></th>
177     <th class="data">[% ordered_total | $Price %]</th>
178     <th></th>
179     <th class="data">[% spent_total | $Price %]</th>
180     <th></th>
181     <th class="data">[% available_total | $Price %]</th>
182     <th></th>
183     </tr>
184     </tfoot>
185     <tbody>
186     [% FOREACH budget IN budgets %]
187     [% IF budget.budget_parent_id %]
188       <tr data-tt-id="[% budget.budget_id | html %]" data-tt-parent-id="[% budget.budget_parent_id | html %]">
189     [% ELSE %]
190       <tr data-tt-id="[% budget.budget_id | html %]">
191     [% END %]
192     <td>[% budget.budget_period_active | html %]</td>
193     <td>Budget [% budget.budget_period_description | html %] [id=[% budget.budget_period_id | html %]][% UNLESS budget.budget_period_active %] (inactive)[% END %]</td>
194     <td>[% budget.budget_code | html %]</td>
195     <td>[% budget.budget_name | html %]</td>
196     <td class="data">
197         <span class="total_amount" data-parent_id="[% budget.budget_parent_id | html %]" data-self_id="[% budget.budget_id | html %]">[% budget.budget_amount | $Price %]</span>
198     </td>
199     <td class="data">
200       [% IF budget.budget_parent_id %]
201         <span class="child_fund_amount">[% budget.budget_ordered | $Price %]</span>
202       [% ELSE %]
203         <span class="total_amount">[% budget.budget_ordered | $Price %]</span>
204       [% END %]
205     </td>
206     <td class="data">
207       [% IF budget.budget_parent_id %]
208         <span class="child_fund_amount">[% budget.total_ordered | $Price %]</span>
209       [% ELSE %]
210         <span class="total_amount">[% budget.total_ordered | $Price %]</span>
211       [% END %]
212     </td>
213     <td class="data">
214       [% IF budget.budget_parent_id %]
215         <span class="child_fund_amount">[% budget.budget_spent | $Price %]</span>
216       [% ELSE %]
217         <span class="total_amount">[% budget.budget_spent | $Price %]</span>
218       [% END %]
219     </td>
220     <td class="data">
221       [% IF budget.budget_parent_id %]
222         <span class="child_fund_amount">[% budget.total_spent | $Price %]</span>
223       [% ELSE %]
224         <span class="total_amount">[% budget.total_spent | $Price %]</span>
225       [% END %]
226     </td>
227
228
229     [% BLOCK colorcellvalue %]
230         [% IF (value > 0) %]
231             <span class="total_amount" data-parent_id="[% budget.budget_parent_id | html %]" data-self_id="[% budget.budget_id | html %]" style="color: green;">
232         [% ELSIF (value < 0) %]
233             <span class="total_amount" data-parent_id="[% budget.budget_parent_id | html %]" data-self_id="[% budget.budget_id | html %]" style="color: red;">
234         [% ELSE %]
235             <span class="totalamount">
236         [% END %]
237         [% value | $Price %]
238         </span>
239     [% END %]
240     <td class="data">
241         [% INCLUDE colorcellvalue value=budget.budget_remaining parent=budget.budget_parent_id %]
242     </td>
243     <td class="data">
244         [% INCLUDE colorcellvalue value=budget.total_remaining parent=budget.budget_parent_id %]
245     </td>
246     [% IF ( budget.budget_lock ) %]
247         <td> <span></span> </td>
248     [% ELSE %]
249         <td>
250             <div class="btn-group dropup">
251                 <a class="btn btn-default btn-xs dropdown-toggle" id="budgetactions[% budget.budget_id | html %]_[% budget.budget_period_id | html %]" role="button" data-toggle="dropdown" href="#">
252                    Actions <b class="caret"></b>
253                 </a>
254                 <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="budgetactions[% budget.budget_id | html %]_[% budget.budget_period_id | html %]">
255                     <li><a href="/cgi-bin/koha/admin/aqbudgets.pl?op=add_form&amp;budget_id=[% budget.budget_id | uri %]&amp;budget_period_id=[% budget.budget_period_id | uri %]"><i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit</a></li>
256                     [% IF budget.budget_has_children %]
257                         <li class="disabled"><a href="#" class="deletefund-disabled" data-toggle="tooltip" data-placement="left" title="This fund has sub funds."><i class="fa fa-trash-can"></i> Delete</a></li>
258                     [% ELSE %]
259                         <li><a href="/cgi-bin/koha/admin/aqbudgets.pl?op=delete_confirm&amp;budget_id=[% budget.budget_id | uri %]&amp;budget_period_id=[% budget.budget_period_id | uri %]"><i class="fa fa-trash-can"></i> Delete</a></li>
260                     [% END %]
261                     <li><a href="/cgi-bin/koha/admin/aqbudgets.pl?op=add_form&amp;budget_parent_id=[% budget.budget_id | uri %]&amp;budget_period_id=[% budget.budget_period_id | uri %]"><i class="fa fa-plus"></i> Add sub fund</a></li>
262                 </ul>
263             </div>
264         </td>
265     [% END %]
266     </tr>
267     [% END %]
268     </tbody>
269 </table>
270 </div> <!-- /.page-section -->
271
272 [% ELSE %]
273     <div class="dialog message">No fund found</div>
274 [% END %]
275
276 [% END %] <!-- list -->
277
278 <!-- ********************************************************************************************** -->
279 <!-- create add/mod entry form -->
280 [% IF op == 'add_form' && !error_not_authorised_to_modify %]
281 <form action="/cgi-bin/koha/admin/aqbudgets.pl" id="edit_fund" name="Aform" method="post">
282     [% INCLUDE 'csrf-token.inc' %]
283     <h1>
284         [% IF ( budget_id ) %]
285             [% IF ( budget_period_description ) %]
286                 [% tx("Modify fund '{fund_name}' for budget '{budget}'", { fund_name = budget_name, budget = budget_period_description }) | html %]
287             [% ELSE %]
288                 [% tx("Modify fund '{fund_name}'", { fund_name = budget_name }) | html %]
289             [% END %]
290         [% ELSE %]
291             [% IF ( budget_parent_name ) %]
292                 [% tx("Add fund to '{fund_parent}'", {fund_parent = budget_parent_name}) %]
293             [% ELSE %]
294                 [% t("New fund") | html %]
295             [% END %]
296         [% END %]
297     </h1>
298     <fieldset class="rows">
299         <legend class="sr-only">Fund details</legend>
300
301     <input type="hidden" name="op" value="cud-add_validate" />
302     <input type="hidden" name="checked" value="0" />
303     <ol>
304     [% IF ( budget_parent_id ) %]
305     <li>
306         <span class="label">Fund parent: </span>
307         [% budget_parent_name | html %]
308         [% budget_parent_id | html %] - [% budget_parent_name | html %]
309         <input type="hidden" name="budget_parent_id" value="[% budget_parent_id | html %]" />
310     </li>
311     [% END %]
312     <li>
313     <label class="required" for="budget_code">Fund code: </label>
314     <input type="text" name="budget_code" id="budget_code" class="focus" value="[% budget_code | html %]" size="30" />
315     </li>
316
317     <li>
318     <label class="required" for="budget_name">Fund name: </label>
319     <input type="text" name="budget_name" id="budget_name" value="[% budget_name | html %]" size="60" />
320     </li>
321
322     <li>
323     <label for="budget_amount" class="required">Amount: </label>
324     <input type="text" name="budget_amount" id="budget_amount" value="[% budget_amount | $Price on_editing => 1 %]" size="8" />
325     </li>
326
327     <li>
328       <label for="budget_encumb">Warning at (%): </label>
329       <input type="text" name="budget_encumb" id="budget_encumb" value="[% budget_encumb | html %]" size="10" />
330       <span class="hint">0 to disable</span>
331     </li>
332
333     <li>
334       <label for="budget_expend">Warning at (amount): </label>
335       <input type="text" name="budget_expend" id="budget_expend" value="[% budget_expend | $Price on_editing => 1 %]" size="10" />
336       <span class="hint">0 to disable</span>
337     </li>
338
339     <li>
340         <span class="label">Owner: </span>
341         [% IF  budget_owner %]
342             <span  id="budget_owner_name">
343                 <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% budget_owner.borrowernumber | uri %]">
344                     [% budget_owner.firstname | html %] [% budget_owner.surname | html %]
345                 </a> |
346             </span>
347         [% ELSE %]
348             <span  id="budget_owner_name"></span>
349         [% END %]
350         <a id="edit_owner" href="#patron_search_modal_owner" data-toggle="modal"><i class="fa fa-search"></i> Select owner</a>
351         <a id="remove_owner" href="#"><i class="fa fa-trash-can"></i> Remove owner</a>
352         <input type="hidden" name="budget_owner_id" id="budget_owner_id"
353             value="[% budget_owner.borrowernumber | html %]" />
354     </li>
355
356
357     [% IF budget_has_children %]
358         <li class="radio">
359             <label>
360                 <input type="checkbox" id="set_owner_to_children" name="set_owner_to_children" value="1" />
361                 <span>Update all sub funds with this owner</span>
362             </label>
363             <span class="hint">Selecting this option will overwrite existing fund owners, if any</span>
364         </li>
365     [% END %]
366
367     <li>
368         <span class="label">Users:</span>
369         <ul style="float:left;" id="budget_users">
370             [% FOREACH user IN budget_users %]
371                 <li id="user_[% user.borrowernumber | html %]">
372                     <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% user.borrowernumber | uri %]">
373                         [% user.firstname | html %] [% user.surname | html %]
374                     </a>
375                     &bull; <a href="#" class="del_user" data-borrowernumber="[% user.borrowernumber | html %]"><i class="fa fa-trash-can"></i> Remove</a>
376                 </li>
377             [% END %]
378             <li><a href="#patron_search_modal_users" id="add_user_button" data-toggle="modal"><i class="fa fa-plus"></i> Add users</a></li>
379         </ul>
380         <input type="hidden" name="budget_users_ids" id="budget_users_id" value="[% budget_users_ids | html %]" />
381     </li>
382     <li>
383     <label for="budget_branchcode">Library: </label>
384     <select name="budget_branchcode" id="budget_branchcode">
385         <option value=""></option>
386         [% PROCESS options_for_libraries libraries => Branches.all( selected => budget_branchcode, unfiltered => 1 ) %]
387     </select>
388     </li>
389
390     <li>
391     <label for="budget_permission">Restrict access to: </label>
392     <select name="budget_permission" id="budget_permission">
393         [% IF ( budget_perm_0 ) %]
394             <option value="0" selected="selected">
395         [% ELSE %]
396             <option value="0">
397         [% END %]
398             None
399         </option>
400
401         [% IF ( budget_perm_1 ) %]
402             <option value="1" selected="selected">
403         [% ELSE %]
404             <option value="1">
405         [% END %]
406             Owner
407         </option>
408
409         [% IF ( budget_perm_3) %]
410             <option value="3" selected="selected">
411         [% ELSE %]
412             <option value="3">
413         [% END %]
414             Owner and users
415         </option>
416
417         [% IF ( budget_perm_2 ) %]
418             <option value="2" selected="selected">
419         [% ELSE %]
420             <option value="2">
421         [% END %]
422             Owner, users and library
423         </option>
424     </select>
425     </li>
426
427     <li>
428     <label for="budget_notes">Notes: </label>
429     <textarea name="budget_notes" id="budget_notes"  cols="80" rows="6">[% budget_notes | html %]</textarea>
430     </li>
431
432     <li>
433     <label  for="authorised_value_category1">Statistic 1 done on: </label>
434         <select name="sort1_authcat" id="authorised_value_category1">
435             <option value=""></option>
436             [% PROCESS options_for_authorised_value_categories authorised_value_categories => AuthorisedValues.GetCategories( selected => sort1_authcat ) %]
437         </select>
438     </li>
439     <li>
440     <label  for="authorised_value_category2">Statistic 2 done on: </label>
441         <select name="sort2_authcat" id="authorised_value_category2">
442             <option value=""></option>
443             [% PROCESS options_for_authorised_value_categories authorised_value_categories => AuthorisedValues.GetCategories( selected => sort2_authcat ) %]
444         </select>
445     </li>
446     </ol>
447
448     [% IF ( budget_id ) %]
449         <input type="hidden" name="budget_id" value="[% budget_id | html %]" />
450     [% END %]
451     </fieldset>
452
453     <fieldset class="action">
454         <input type="submit" class="btn btn-primary" value="Submit" /> <a class="cancel" href="/cgi-bin/koha/admin/aqbudgets.pl">Cancel</a>
455         <input type="hidden" name="budget_period_id" value="[% budget_period_id | html %]" />
456     </fieldset>
457 </form>
458
459 [% END %] <!-- add_form -->
460
461 [% IF op == 'delete_confirm' %]
462     <div class="dialog alert">
463         <h1>[% tx("Confirm deletion of fund '{fund}'?", {fund = budget_name}) %]</h1>
464         <p>If you delete this fund, all orders linked to this fund will be deleted!</p>
465         <table>
466             <tr>
467             <th scope="row">Fund amount:</th>
468             <td>[% budget_amount | $Price %]</td>
469             </tr>
470         </table>
471
472         <form action="/cgi-bin/koha/admin/aqbudgets.pl" method="post">
473             [% INCLUDE 'csrf-token.inc' %]
474             <input type="hidden" name="op" value="cud-delete_confirmed" />
475             <input type="hidden" name="budget_id" value="[% budget_id | html %]" />
476             <input type="hidden" name="budget_period_id" value="[% budget_period_id | html %]" />
477             <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete this fund</button>
478         </form>
479         <form action="/cgi-bin/koha/admin/aqbudgets.pl" method="get">
480             <button type="submit" class="deny"><i class="fa fa-fw fa-times"></i> No, do not delete</button>
481         </form>
482     </div>
483 [% END %]
484
485             </main>
486         </div> <!-- /.col-sm-10.col-sm-push-2 -->
487
488         <div class="col-sm-2 col-sm-pull-10">
489             <aside>
490
491 [% IF op == 'list' %]
492   <form action="/cgi-bin/koha/admin/aqbudgets.pl" method="get">
493     <fieldset class="brief" id="fundfilters">
494     <h4>Fund filters</h4>
495         <ol>
496         <li>
497             <label for="filter_budgetbranch2">Library: </label>
498             <select name="filter_budgetbranch" id="filter_budgetbranch2">
499                 <option value=""></option>
500                 [% PROCESS options_for_libraries libraries => Branches.all( selected => selected_branchcode, unfiltered => 1 ) %]
501             </select>
502         </li>
503
504         [% IF periods %]
505           <li>
506             <label for="periods">Budget:</label>
507             <select id="periods" name="budget_period_id">
508               <option value="">All budgets</option>
509               [% FOR period IN periods %]
510                 [% IF budget_period_id && period.budget_period_id == budget_period_id %]
511                   <option value="[% period.budget_period_id | html %]" selected="selected">[% period.budget_period_description | html %]</option>
512                 [% ELSE %]
513                   <option value="[% period.budget_period_id | html %]">[% period.budget_period_description | html %]</option>
514                 [% END %]
515               [% END %]
516             </select>
517           </li>
518         [% END %]
519         <li class="radio">
520
521         <label for="show_mine">Show my funds only:</label>
522             [% IF ( show_mine ) %]
523                 <input type="checkbox" id="show_mine"  name="show_mine" value="1" checked="checked" />
524             [% ELSE %]
525                 <input type="checkbox" id="show_mine"  name="show_mine" value="1" />
526         [% END %]
527         </li>
528         </ol>
529     </fieldset>
530     <fieldset class="action">
531         <input type="hidden" name="op" value="list" />
532         <input type="submit" class="submit" name="filter" value="Go" />
533     </fieldset>
534 </form>[% END %]
535
536                 [% INCLUDE 'acquisitions-menu.inc' %]
537             </aside>
538         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
539      </div> <!-- /.row -->
540
541 [% MACRO jsinclude BLOCK %]
542     [% Asset.js("js/acq.js") | $raw %]
543     [% IF op == 'add_form' %]
544         [% INCLUDE 'js-patron-format.inc' %]
545         <script>
546         //<![CDATA[
547
548             function select_user(borrowernumber, borrower) {
549                 ownerRemove();
550                 if (borrowernumber) {
551                     var ownerlink = $patron_to_html( borrower, { display_cardnumber: false, url: true } );
552                     $('#budget_owner_name').html(ownerlink);
553                     $('#budget_owner_id').val(borrowernumber);
554                 }
555             }
556
557             function ownerRemove() {
558                 $('#budget_owner_name').empty();
559                 $('#budget_owner_id').val('');
560             }
561
562             function add_user(borrowernumber, borrowername) {
563                 var ids = $("#budget_users_id").val().split(':');
564                 if(borrowernumber && ids.indexOf(borrowernumber.toString()) == -1) {
565                     var li = '<li id="user_' + borrowernumber + '">'
566                         + '<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber='
567                         + borrowernumber + '">' + borrowername + '</a> '
568                         + ' &bull; <a data-borrowernumber="' + borrowernumber + '" class="del_user" href="#"><i class="fa fa-trash-can"></i> '+_("Remove")+'</a> '
569                         + '</li>';
570                     $("#budget_users").prepend(li);
571                     ids.push(borrowernumber);
572                     $("#budget_users_id").val(ids.join(':'));
573                 } else {
574                     return -1;
575                 }
576                 return 0;
577             }
578
579             function del_user(borrowernumber) {
580                 var ids = $("#budget_users_id").val().split(':');
581                 if (borrowernumber) {
582                     var idx = ids.indexOf(borrowernumber+'');
583                     if (idx != -1) {
584                         ids.splice(idx, 1);
585                         $("#budget_users_id").val(ids.join(':'));
586                         $("li#user_" + borrowernumber).remove();
587                     }
588                 }
589             }
590
591             function Check(f) {
592                 var ok=1;
593                 var _alertString="";
594                 var alertString2;
595
596                 if (!(isNotNull(f.budget_code,1))) {
597                     _alertString += _("- Budget code cannot be blank") + "\n";
598                 }
599
600                 if (!(isNotNull(f.budget_name,1))) {
601                     _alertString += _("- Budget name cannot be blank") + "\n";
602                 }
603
604                 if (!(isNotNull(f.budget_amount,1))) {
605                     _alertString += _("- Budget amount cannot be blank") + "\n";
606                 }
607
608                 var budgetId;
609                 if   (typeof(f.budget_id ) != "undefined")  {
610                     budgetId = f.budget_id.value
611                 }
612
613                 var newBudgetParent;
614
615         //  hack to test if selected parent_id in scrolling-list...
616         //  if value == 'undef' its got a selected_parent :/
617                 if(f.budget_parent_id){
618                     var chkAdd   =  f.budget_parent_id.value ;
619                     if  (     typeof(chkAdd ) != "undefined") {
620                         newBudgetParent  =  f.budget_parent_id.value
621                     } else {
622                         newBudgetParent  =  f.budget_parent_id.item(0).value
623                     }
624
625                     if   (budgetId  > 0)  {  ; //its a mod ...
626                         // if parent == curent-budget, fail...
627                         if ( newBudgetParent  ==  budgetId     ) {
628                                 _alertString += _("- Budget parent is current budget") + "\n";
629                         }
630
631                         else if (newBudgetParent) {
632                             var result = checkBudgetParent(  budgetId , newBudgetParent   );
633                             if (result) {
634                                 _alertString += result;
635                             }
636                         }
637                     }
638                 }
639
640                  // else do lookup
641                 var budgetTotal = Math.abs(f.budget_amount.value);
642                 var result =   budgetExceedsParent  (budgetTotal, budgetId, newBudgetParent, f.budget_period_id.value)
643                 if (result) {
644                     _alertString += result;
645                 }
646
647                 if (_alertString.length==0) {
648                     document.Aform.submit();
649                 } else {
650                     alertString2 = _("Form not submitted because of the following problem(s)");
651                     alertString2 += "\n------------------------------------------------------------------------------------\n\n";
652                     alertString2 += _alertString;
653                     alert(alertString2);
654                 }
655             }
656             $(document).ready(function(){
657                 $("#remove_owner").on("click",function(e){
658                     e.preventDefault();
659                     ownerRemove();
660                 });
661                 $("body").on("click",".del_user",function(e){
662                     e.preventDefault();
663                     var borrowernumber = $(this).data("borrowernumber");
664                     del_user(borrowernumber);
665                 });
666                 $("#edit_fund").on("submit",function(e){
667                     e.preventDefault();
668                     Check(this);
669                 });
670             });
671         //]]>
672         </script>
673
674         [% INCLUDE 'select2.inc' %]
675         [% SET columns = ['cardnumber','name','category','branch','action'] %]
676         [% SET filter = 'funds_users' %]
677         [% PROCESS patron_search_modal columns => columns, modal_title => t("Add users"), patron_search_modal_id => 'patron_search_modal_users', table_id => 'patron_search_modal_users_table' %]
678         [% PROCESS patron_search_js columns => columns, actions => ["add"], preview_on_name_click => 1, table_id => 'patron_search_modal_users_table' %]
679         [% SET filter = 'funds_owners' %]
680         [% PROCESS patron_search_modal columns => columns, modal_title => t("Select owner"), patron_search_modal_id => 'patron_search_modal_owner', table_id => 'patron_search_modal_owner_table' %]
681         [% PROCESS patron_search_js columns => columns, actions => ["select"], preview_on_name_click => 1, table_id => 'patron_search_modal_owner_table' %]
682
683     [% ELSIF op == 'list' %]
684         [% INCLUDE 'datatables.inc' %]
685         [% INCLUDE 'columns_settings.inc' %]
686         [% Asset.js("lib/jquery/plugins/treetable/jquery.treetable.js") | $raw %]
687
688         <script>
689             $(document).ready(function() {
690                 [% IF budgets %]
691                     var oTable = KohaTable("budgeth", {
692                         "drawCallback": function ( oSettings ) {
693                             if ( oSettings.aiDisplay.length == 0 )
694                             {
695                                 return;
696                             }
697
698                             var nTrs = $('#budgeth tbody tr');
699                             var iColspan = nTrs[0].getElementsByTagName('td').length;
700                             var sLastGroup = "";
701                             for ( var i=0 ; i<nTrs.length ; i++ )
702                             {
703                                 var iDisplayIndex = oSettings._iDisplayStart + i;
704                                 var sGroup = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex] ]._aData[1];
705                                 if ( sGroup != sLastGroup )
706                                 {
707                                     var nGroup = document.createElement( 'tr' );
708                                     var nCell = document.createElement( 'td' );
709                                     nCell.colSpan = iColspan;
710                                     nCell.className = "group";
711                                     nCell.innerHTML = sGroup;
712                                     nGroup.appendChild( nCell );
713                                     nTrs[i].parentNode.insertBefore( nGroup, nTrs[i] );
714                                     sLastGroup = sGroup;
715                                 }
716                             }
717                         },
718                         "footerCallback": function ( row, data, start, end, display ) {
719                             var api = this.api(), data;
720                             footer_column_sum( api, [ 4, 6, 8, 10 ], 2 );
721                         },
722                         "columnDefs": [
723                             { "visible": false, "targets": [ 0, 1 ] },
724                             { "orderable": false, "targets": ["_all"] }
725                         ],
726                         "ordering": true,
727                         "orderFixed": [[ 1, 'asc' ]],
728                         "paginate": false,
729                         "autoWidth": false
730                     });
731
732                     $(oTable).treetable({
733                         expandable: true
734                     });
735                     $(oTable).treetable('expandAll');
736                     $("#expand_all").click(function(e){
737                         e.preventDefault();
738                         $(oTable).treetable('expandAll');
739                     });
740                     $("#collapse_all").click(function(e){
741                         e.preventDefault();
742                         $(oTable).treetable('collapseAll');
743                     });
744
745                     [% UNLESS budget_period_id %]
746                       $("#hide_inactive").click(function(e){
747                         e.preventDefault();
748                         oTable.fnFilter( 1, 0 ); // Show only active=1
749                       });
750                       $("#show_inactive").click(function(e){
751                         e.preventDefault();
752                         oTable.fnFilter( '', 0 );
753                       });
754                       $("#hide_inactive").click();
755                     [% END %]
756                     oTable.fnAddFilters("filter", 750);
757                 [% END %]
758
759                 $(".deletefund-disabled").tooltip().on("click", function(e){
760                     e.preventDefault();
761                     alert(_("This fund has sub funds. It cannot be deleted."));
762                 });
763
764                 $('[data-toggle="tooltip"]').tooltip();
765             });
766         </script>
767     [% END %]
768 [% END %]
769 [% INCLUDE 'intranet-bottom.inc' %]