Bug 18936: Add missing filters
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / smart-rules.tt
blob71638e03066174835954f71a82f80db042acf09c
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE KohaDates %]
5 [% USE Branches %]
6 [% USE Categories %]
7 [% USE ItemTypes %]
8 [% USE CirculationRules %]
9 [% SET footerjs = 1 %]
11 [% SET branchcode = humanbranch || undef %]
13 [% SET categorycodes = [] %]
14 [% FOREACH pc IN patron_categories %]
15     [% categorycodes.push( pc.id ) %]
16 [% END %]
17 [% categorycodes.push(undef) %]
19 [% SET itemtypes = [] %]
20 [% FOREACH i IN itemtypeloop %]
21     [% itemtypes.push( i.itemtype ) %]
22 [% END %]
23 [% itemtypes.push(undef) %]
25 [% INCLUDE 'doc-head-open.inc' %]
26 <title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
27 [% INCLUDE 'doc-head-close.inc' %]
28 </head>
30 <body id="admin_smart-rules" class="admin">
31 [% INCLUDE 'header.inc' %]
32 [% INCLUDE 'prefs-admin-search.inc' %]
34 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; Circulation and fine rules</div>
36 <div class="main container-fluid">
37     <div class="row">
38         <div class="col-sm-10 col-sm-push-2">
39             <main>
41     <h1 class="parameters">
42         [% IF humanbranch %]
43             Defining circulation and fine rules for "[% Branches.GetName( humanbranch ) | html %]"
44         [% ELSE %]
45             Defining circulation and fine rules for all libraries
46         [% END %]
47     </h1>
48     <div class="help">
49         <p>The rules are applied from most specific to less specific, using the first found in this order:</p>
50         <ul>
51             <li>same library, same patron category, same item type</li>
52             <li>same library, same patron category, all item types</li>
53             <li>same library, all patron categories, same item type</li>
54             <li>same library, all patron categories, all item types</li>
55             <li>default (all libraries), same patron category, same item type</li>
56             <li>default (all libraries), same patron category, all item types</li>
57             <li>default (all libraries), all patron categories, same item type</li>
58             <li>default (all libraries), all patron categories, all item types</li>
59         </ul>
60         <p>To modify a rule, create a new one with the same patron category and item type.</p>
61     </div>
62     <div>
63         [% UNLESS restricted_to_own_library %]
64             <form method="get" action="/cgi-bin/koha/admin/smart-rules.pl" id="selectlibrary">
65             Select a library :
66                 <select name="branch" id="branch" style="width:20em;">
67                     <option value="*">Standard rules for all libraries</option>
68                     [% PROCESS options_for_libraries libraries => Branches.all( selected => current_branch, unfiltered => 1 ) %]
69                 </select>
70             </form>
71             [% IF ( definedbranch ) %]
72                 <form action="/cgi-bin/koha/admin/clone-rules.pl" method="post">
73                     <label for="tobranch"><strong>Clone these rules to:</strong></label>
74                     <input type="hidden" name="frombranch" value="[% current_branch | html %]" />
75                     <select name="tobranch" id="tobranch">
76                         [% PROCESS options_for_libraries libraries => Branches.all( unfiltered => 1 ) %]
77                     </select>
78                     <input type="submit" id="clone_rules" value="Clone" />
79                 </form>
80             [% END %]
81         [% END %]
83         <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
84             <input type="hidden" name="op" value="add" />
85             <input type="hidden" name="branch" value="[% current_branch | html %]"/>
86             <table id="default-circulation-rules">
87             <thead>
88             <tr>
89                 <th>Patron category</th>
90                 <th>Item type</th>
91                 <th>Actions</th>
92                 <th>Note</th>
93                 <th>Current checkouts allowed</th>
94                 <th>Current on-site checkouts allowed</th>
95                 <th>Loan period</th>
96                 <th>Unit</th>
97                 <th>Hard due date</th>
98                 <th>Fine amount</th>
99                 <th>Fine charging interval</th>
100                 <th>When to charge</th>
101                 <th>Fine grace period</th>
102                 <th>Overdue fines cap (amount)</th>
103                 <th>Cap fine at replacement price</th>
104                 <th>Suspension in days (day)</th>
105                 <th>Max. suspension duration (day)</th>
106                 <th>Suspension charging interval</th>
107                 <th>Renewals allowed (count)</th>
108                 <th>Renewal period</th>
109                 <th>No renewal before</th>
110                 <th>Automatic renewal</th>
111                 <th>No automatic renewal after</th>
112                 <th>No automatic renewal after (hard limit)</th>
113                 <th>Holds allowed (total)</th>
114                 <th>Holds allowed (daily)</th>
115                 <th>Holds per record (count)</th>
116                 <th>On shelf holds allowed</th>
117                 <th>OPAC item level holds</th>
118                 <th>Article requests</th>
119                 <th>Rental discount (%)</th>
120                 <th>Actions</th>
121             </tr>
122             </thead>
123             <tbody>
124                 [% SET row_count = 0 %]
125                 [% FOREACH c IN categorycodes %]
126                     [% FOREACH i IN itemtypes %]
127                         [% SET note = CirculationRules.Search( branchcode, c, i, 'note' ) %]
128                         [% SET maxissueqty = CirculationRules.Search( branchcode, c, i, 'maxissueqty' ) %]
129                         [% SET maxonsiteissueqty = CirculationRules.Search( branchcode, c, i, 'maxonsiteissueqty' ) %]
130                         [% SET issuelength = CirculationRules.Search( branchcode, c, i, 'issuelength' ) %]
131                         [% SET lengthunit = CirculationRules.Search( branchcode, c, i, 'lengthunit' ) %]
132                         [% SET hardduedate = CirculationRules.Search( branchcode, c, i, 'hardduedate' ) %]
133                         [% SET hardduedatecompare = CirculationRules.Search( branchcode, c, i, 'hardduedatecompare' ) %]
134                         [% SET fine = CirculationRules.Search( branchcode, c, i, 'fine' ) %]
135                         [% SET chargeperiod = CirculationRules.Search( branchcode, c, i, 'chargeperiod' ) %]
136                         [% SET chargeperiod_charge_at = CirculationRules.Search( branchcode, c, i, 'chargeperiod_charge_at' ) %]
137                         [% SET firstremind = CirculationRules.Search( branchcode, c, i, 'firstremind' ) %]
138                         [% SET overduefinescap = CirculationRules.Search( branchcode, c, i, 'overduefinescap' ) %]
139                         [% SET cap_fine_to_replacement_price = CirculationRules.Search( branchcode, c, i, 'cap_fine_to_replacement_price' ) %]
140                         [% SET finedays = CirculationRules.Search( branchcode, c, i, 'finedays' ) %]
141                         [% SET maxsuspensiondays = CirculationRules.Search( branchcode, c, i, 'maxsuspensiondays' ) %]
142                         [% SET suspension_chargeperiod = CirculationRules.Search( branchcode, c, i, 'suspension_chargeperiod' ) %]
143                         [% SET renewalsallowed = CirculationRules.Search( branchcode, c, i, 'renewalsallowed' ) %]
144                         [% SET renewalperiod = CirculationRules.Search( branchcode, c, i, 'renewalperiod' ) %]
145                         [% SET norenewalbefore = CirculationRules.Search( branchcode, c, i, 'norenewalbefore' ) %]
146                         [% SET auto_renew = CirculationRules.Search( branchcode, c, i, 'auto_renew' ) %]
147                         [% SET no_auto_renewal_after = CirculationRules.Search( branchcode, c, i, 'no_auto_renewal_after' ) %]
148                         [% SET no_auto_renewal_after_hard_limit = CirculationRules.Search( branchcode, c, i, 'no_auto_renewal_after_hard_limit' ) %]
149                         [% SET reservesallowed = CirculationRules.Search( branchcode, c, i, 'reservesallowed' ) %]
150                         [% SET holds_per_day = CirculationRules.Search( branchcode, c, i, 'holds_per_day' ) %]
151                         [% SET holds_per_record = CirculationRules.Search( branchcode, c, i, 'holds_per_record' ) %]
152                         [% SET onshelfholds = CirculationRules.Search( branchcode, c, i, 'onshelfholds' ) %]
153                         [% SET opacitemholds = CirculationRules.Search( branchcode, c, i, 'opacitemholds' ) %]
154                         [% SET article_requests = CirculationRules.Search( branchcode, c, i, 'article_requests' ) %]
155                         [% SET rentaldiscount = CirculationRules.Search( branchcode, c, i, 'rentaldiscount' ) %]
157                         [% SET show_rule = maxissueqty || maxonsiteissueqty || issuelength || lengthunit || hardduedate || hardduedatebefore || hardduedateexact || fine || chargeperiod || chargeperiod_charge_at || firstremind || overduefinescap || cap_fine_to_replacement_price || finedays || maxsuspensiondays || suspension_chargeperiod || renewalsallowed || renewalsallowed || norenewalbefore || auto_renew || no_auto_renewal_after || no_auto_renewal_after_hard_limit || reservesallowed || holds_per_day || holds_per_record || onshelfholds || opacitemholds || article_requests || article_requests %]
158                         [% IF show_rule %]
159                             [% SET row_count = row_count + 1 %]
160                             <tr row_countd="row_[% row_count | html %]">
161                                     <td>
162                                         [% IF c == undef %]
163                                             <em>All</em>
164                                         [% ELSE %]
165                                             [% Categories.GetName(c) | html %]
166                                         [% END %]
167                                     </td>
168                                     <td>
169                                         [% IF i == undef %]
170                                             <em>All</em>
171                                         [% ELSE %]
172                                             [% ItemTypes.GetDescription(i) | html %]
173                                         [% END %]
174                                     </td>
175                                     <td class="actions">
176                                       <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
177                                       <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype || '*' | html %]&amp;categorycode=[% rule.categorycode || '*' | html %]&amp;branch=[% current_branch | html %]"><i class="fa fa-trash"></i> Delete</a>
178                                     </td>
179                                     <td>
180                                         [% IF note.defined %]
181                                             <a name="viewnote" data-toggle="popover" title="Note" data-content="[% note | html %]" data-placement="top" data-trigger="hover">View note</a>
182                                         [% ELSE %]<span>&nbsp;</span>[% END %]
183                                     </td>
184                                     <td>
185                                         [% IF maxissueqty.defined && maxissueqty != '' %]
186                                             [% maxissueqty | html %]
187                                         [% ELSE %]
188                                             <span>Unlimited</span>
189                                         [% END %]
190                                     </td>
191                                     <td>
192                                         [% IF maxonsiteissueqty.defined && maxonsiteissueqty != ''  %]
193                                             [% maxonsiteissueqty | html %]
194                                         [% ELSE %]
195                                             <span>Unlimited</span>
196                                         [% END %]
197                                     </td>
198                                     <td>[% issuelength | html %]</td>
199                                     <td>
200                                         [% IF ( lengthunit == 'days' ) %]
201                                             Days
202                                         [% ELSIF ( lengthunit == 'hours') %]
203                                             Hours
204                                         [% ELSE %]
205                                             Undefined
206                                         [% END %]
207                                     </td>
208                                     <td>
209                                       [% IF ( hardduedate ) %]
210                                         [% IF ( hardduedatecompare == '-1' ) %]
211                                           before [% hardduedate | $KohaDates %]
212                                           <input type="hidden" name="hardduedatecomparebackup" value="-1" />
213                                         [% ELSIF ( hardduedatecompare == '0' ) %]
214                                           on [% hardduedate | $KohaDates %]
215                                           <input type="hidden" name="hardduedatecomparebackup" value="0" />
216                                         [% ELSIF ( hardduedatecompare == '1' ) %]
217                                           after [% hardduedate | $KohaDates %]
218                                           <input type="hidden" name="hardduedatecomparebackup" value="1" />
219                                         [% END %]
220                                       [% ELSE %]
221                                         <span>None defined</span>
222                                       [% END %]
223                                     </td>
224                                     <td>[% fine | html %]</td>
225                                     <td>[% chargeperiod | html %]</td>
226                                     <td>[% IF chargeperiod_charge_at %]Start of interval[% ELSE %]End of interval[% END %]</td>
227                                     <td>[% firstremind | html %]</td>
228                                     <td>[% overduefinescap FILTER format("%.2f") %]</td>
229                                     <td>
230                                         [% IF cap_fine_to_replacement_price %]
231                                             <input type="checkbox" checked="checked" disabled="disabled" />
232                                         [% ELSE %]
233                                             <input type="checkbox" disabled="disabled" />
234                                         [% END %]
235                                     </td>
236                                     <td>[% finedays | html %]</td>
237                                     <td>[% maxsuspensiondays | html %]</td>
238                                     <td>[% suspension_chargeperiod | html %]</td>
239                                     <td>[% renewalsallowed | html %]</td>
240                                     <td>[% renewalperiod | html %]</td>
241                                     <td>[% norenewalbefore | html %]</td>
242                                     <td>
243                                         [% IF auto_renew %]
244                                             <span>Yes</span>
245                                         [% ELSE %]
246                                             <span>No</span>
247                                         [% END %]
248                                     </td>
249                                     <td>[% no_auto_renewal_after | html %]</td>
250                                     <td>[% no_auto_renewal_after_hard_limit | html %]</td>
251                                     <td>[% reservesallowed | html %]</td>
252                                     <td>
253                                         [% IF holds_per_day.defined && holds != '' %]
254                                             [% holds_per_day | html %]
255                                         [% ELSE %]
256                                             <span>Unlimited</span>
257                                         [% END %]
258                                     </td>
259                                     <td>[% holds_per_record | html %]</td>
260                                     <td>
261                                         [% IF onshelfholds == 1 %]
262                                             <span>Yes</span>
263                                         [% ELSIF onshelfholds == 2 %]
264                                             <span>If all unavailable</span>
265                                         [% ELSE %]
266                                             <span>If any unavailable</span>
267                                         [% END %]
268                                     </td>
269                                     <td>
270                                         [% IF opacitemholds == 'F'%]
271                                             <span>Force</span>
272                                         [% ELSIF opacitemholds == 'Y'%]
273                                             <span>Allow</span>
274                                         [% ELSE %]
275                                             <span>Don't allow</span>
276                                         [% END %]
277                                     </td>
278                                     <td>
279                                         [% IF article_requests == 'no' %]
280                                             <span>No</span>
281                                         [% ELSIF article_requests == 'yes' %]
282                                             <span>Yes</span>
283                                         [% ELSIF article_requests == 'bib_only' %]
284                                             <span>Record only</span>
285                                         [% ELSIF article_requests == 'item_only' %]
286                                             <span>Item only</span>
287                                         [% END %]
288                                     </td>
289                                     <td>[% rentaldiscount | html %]</td>
290                                     <td class="actions">
291                                       <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
292                                       <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype || '*' | uri %]&amp;categorycode=[% rule.categorycode || '*' | uri %]&amp;branch=[% rule.current_branch | uri %]"><i class="fa fa-trash"></i> Delete</a>
293                                     </td>
294                             </tr>
295                         [% END %]
296                     [% END %]
297                 [% END %]
298                 <tr id="edit_row">
299                     <td>
300                         <select name="categorycode" id="categorycode">
301                             <option value="*">All</option>
302                         [% FOREACH patron_category IN patron_categories%]
303                             <option value="[% patron_category.categorycode | html %]">[% patron_category.description | html %]</option>
304                         [% END %]
305                         </select>
306                     </td>
307                     <td>
308                         <select name="itemtype" id="matrixitemtype" style="width:13em;">
309                             <option value="*">All</option>
310                         [% FOREACH itemtypeloo IN itemtypeloop %]
311                             <option value="[% itemtypeloo.itemtype | html %]">[% itemtypeloo.translated_description | html %]</option>
312                         [% END %]
313                         </select>
314                     </td>
315                     <td class="actions">
316                         <input type="hidden" name="branch" value="[% current_branch | html %]"/>
317                         <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
318                         <button name="cancel" class="clear_edit btn btn-default btn-xs"><i class="fa fa-undo"></i> Clear</button>
319                     </td>
320                     <td><input type="text" name="note" id="note" size="15" value="" maxlength="100"></td>
321                     <td><input type="text" name="maxissueqty" id="maxissueqty" size="3" /></td>
322                     <td><input type="text" name="maxonsiteissueqty" id="maxonsiteissueqty" size="3" /></td>
323                     <td><input type="text" name="issuelength" id="issuelength" size="3" /> </td>
324                     <td>
325                       <select name="lengthunit" id="lengthunit">
326                         <option value="days" selected="selected">Days</option>
327                         <option value="hours">Hours</option>
328                       </select>
329                     </td>
330                     <td>
331                         <select name="hardduedatecompare" id="hardduedatecompare">
332                            <option value="-1">Before</option>
333                            <option value="0">Exactly on</option>
334                            <option value="1">After</option>
335                         </select>
336                         <input type="text" size="10" id="hardduedate" name="hardduedate" value="[% hardduedate | html %]" class="datepicker" />
337                         <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
338                     </td>
339                     <td><input type="text" name="fine" id="fine" size="4" /></td>
340                     <td><input type="text" name="chargeperiod" id="chargeperiod" size="2" /></td>
341                     <td>
342                         <select name="chargeperiod_charge_at" id="chargeperiod_charge_at">
343                            <option value="0">End of interval</option>
344                            <option value="1">Start of interval</option>
345                         </select>
346                     </td>
347                     <td><input type="text" name="firstremind" id="firstremind" size="2" /> </td>
348                     <td><input type="text" name="overduefinescap" id="overduefinescap" size="6" /> </td>
349                     <td><input type="checkbox" name="cap_fine_to_replacement_price" id="cap_fine_to_replacement_price" /></td>
350                     <td><input type="text" name="finedays" id="fined" size="3" /> </td>
351                     <td><input type="text" name="maxsuspensiondays" id="maxsuspensiondays" size="3" /> </td>
352                     <td><input type="text" name="suspension_chargeperiod" id="suspension_chargeperiod" size="3" /> </td>
353                     <td><input type="text" name="renewalsallowed" id="renewalsallowed" size="2" /></td>
354                     <td><input type="text" name="renewalperiod" id="renewalperiod" size="3" /></td>
355                     <td><input type="text" name="norenewalbefore" id="norenewalbefore" size="3" /></td>
356                     <td>
357                         <select name="auto_renew" id="auto_renew">
358                             <option value="no" selected>No</option>
359                             <option value="yes">Yes</option>
360                         </select>
361                     </td>
362                     <td><input type="text" name="no_auto_renewal_after" id="no_auto_renewal_after" size="3" /></td>
363                     <td>
364                         <input type="text" size="10" name="no_auto_renewal_after_hard_limit" id="no_auto_renewal_after_hard_limit" value="[% no_auto_renewal_after_hard_limit | html %]" class="datepicker"/>
365                         <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
366                     </td>
367                     <td><input type="text" name="reservesallowed"  id="reservesallowed"  size="2" /></td>
368                     <td><input type="text" name="holds_per_day"    id="holds_per_day"    size="2" /></td>
369                     <td><input type="text" name="holds_per_record" id="holds_per_record" size="2" /></td>
370                     <td>
371                         <select name="onshelfholds" id="onshelfholds">
372                             <option value="1">Yes</option>
373                             <option value="0">If any unavailable</option>
374                             <option value="2">If all unavailable</option>
375                         </select>
376                     </td>
377                     <td>
378                         <select id="opacitemholds" name="opacitemholds">
379                             <option value="N">Don't allow</option>
380                             <option value="Y">Allow</option>
381                             <option value="F">Force</option>
382                         </select>
383                     </td>
384                     <td>
385                         <select id="article_requests" name="article_requests">
386                             <option value="no">No</option>
387                             <option value="yes">Yes</option>
388                             <option value="bib_only">Record only</option>
389                             <option value="item_only">Item only</option>
390                         </select>
391                     </td>
392                     <td><input type="text" name="rentaldiscount" id="rentaldiscount" size="2" /></td>
393                     <td class="actions">
394                         <input type="hidden" name="branch" value="[% current_branch | html %]"/>
395                         <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
396                         <button name="cancel" class="clear_edit btn btn-default btn-xs"><i class="fa fa-undo"></i> Clear</button>
397                     </td>
398                 </tr>
399                 <tfoot>
400                     <tr>
401                       <th>Patron category</th>
402                       <th>Item type</th>
403                       <th>&nbsp;</th>
404                       <th>Note</th>
405                       <th>Current checkouts allowed</th>
406                       <th>Current on-site checkouts allowed</th>
407                       <th>Loan period</th>
408                       <th>Unit</th>
409                       <th>Hard due date</th>
410                       <th>Fine amount</th>
411                       <th>Fine charging interval</th>
412                       <th>Charge when?</th>
413                       <th>Fine grace period</th>
414                       <th>Overdue fines cap (amount)</th>
415                       <th>Cap fine at replacement price</th>
416                       <th>Suspension in days (day)</th>
417                       <th>Max. suspension duration (day)</th>
418                       <th>Suspension charging interval</th>
419                       <th>Renewals allowed (count)</th>
420                       <th>Renewal period</th>
421                       <th>No renewal before</th>
422                       <th>Automatic renewal</th>
423                       <th>No automatic renewal after</th>
424                       <th>No automatic renewal after (hard limit)</th>
425                       <th>Holds allowed (total)</th>
426                       <th>Holds allowed (daily)</th>
427                       <th>Holds per record (count)</th>
428                       <th>On shelf holds allowed</th>
429                       <th>OPAC item level holds</th>
430                       <th>Article requests</th>
431                       <th>Rental discount (%)</th>
432                       <th>&nbsp;</th>
433                     </tr>
434                   </tfoot>
435                 </tbody>
436             </table>
437         </form>
438     </div>
439     <div id="defaults-for-this-library" class="container">
440     <h3>Default checkout, hold and return policy[% IF humanbranch %] for [% Branches.GetName( humanbranch ) | html %][% END %]</h3>
441         <p>You can set a default maximum number of checkouts, hold policy and return policy that will be used if none is defined below for a particular item type or category.</p>
442         <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
443             <input type="hidden" name="op" value="set-branch-defaults" />
444             <input type="hidden" name="branch" value="[% current_branch | html %]"/>
445             <table>
446                 <tr>
447                     <th>&nbsp;</th>
448                     <th>Total current checkouts allowed</th>
449                     <th>Total current on-site checkouts allowed</th>
450                     <th>Maximum total holds allowed (count)</th>
451                     <th>Hold policy</th>
452                     <th>Hold pickup library match</th>
453                     <th>Return policy</th>
454                     <th>Actions</th>
455                 </tr>
456                 <tr>
457                     <td><em>Defaults</em></td>
458                     <td>
459                         [% SET patron_maxissueqty = CirculationRules.Search( current_branch, undef, undef, 'patron_maxissueqty' ) %]
460                         <input type="text" name="patron_maxissueqty" size="3" value="[% patron_maxissueqty | html %]"/>
461                     </td>
462                     <td>
463                         [% SET patron_maxonsiteissueqty = CirculationRules.Search( current_branch, undef, undef, 'patron_maxonsiteissueqty' ) %]
464                         <input type="text" name="patron_maxonsiteissueqty" size="3" value="[% patron_maxonsiteissueqty | html %]"/>
465                     </td>
466                     <td>
467                         [% SET rule_value = CirculationRules.Search( current_branch, undef , undef, 'max_holds' ) %]
468                         <input name="max_holds" size="3" value="[% rule_value | html %]" />
469                     </td>
470                     <td>
471                         <select name="holdallowed">
472                             [% SET holdallowed = CirculationRules.Search( current_branch, undef, undef, 'holdallowed' ) %]
473                             <option value="">
474                                 Not set
475                             </option>
477                             [% IF holdallowed == 2 %]
478                                 <option value="2" selected="selected">
479                             [% ELSE %]
480                                 <option value="2">
481                             [% END %]
482                                 From any library
483                             </option>
485                             [% IF holdallowed == 3 %]
486                             <option value="3" selected="selected">
487                             [% ELSE %]
488                             <option value="3">
489                             [% END %]
490                                 From local hold group
491                             </option>
493                             [% IF holdallowed == 1 %]
494                                 <option value="1" selected="selected">
495                             [% ELSE %]
496                                 <option value="1">
497                             [% END %]
498                                 From home library
499                             </option>
501                             [% IF holdallowed == 0 %]
502                                 <option value="0" selected="selected">
503                             [% ELSE %]
504                                 <option value="0">
505                             [% END %]
506                                 No holds allowed
507                             </option>
508                         </select>
509                     </td>
510                     <td>
511                         <select name="hold_fulfillment_policy">
512                             [% SET hold_fulfillment_policy = CirculationRules.Search( current_branch, undef, undef, 'hold_fulfillment_policy' ) %]
514                             <option value="">
515                                 Not set
516                             </option>
518                             [% IF hold_fulfillment_policy == 'any' %]
519                                 <option value="any" selected="selected">
520                                     any library
521                                 </option>
522                             [% ELSE %]
523                                 <option value="any">
524                                     any library
525                                 </option>
526                             [% END %]
528                             [% IF hold_fulfillment_policy == 'holdgroup' %]
529                                 <option value="holdgroup" selected="selected">
530                                     item's hold group
531                                 </option>
532                             [% ELSE %]
533                                 <option value="holdgroup">
534                                     item's hold group
535                                 </option>
536                             [% END %]
538                             [% IF hold_fulfillment_policy == 'patrongroup' %]
539                                 <option value="patrongroup" selected="selected">
540                                     patron's hold group
541                                 </option>
542                             [% ELSE %]
543                                 <option value="patrongroup">
544                                     patron's hold group
545                                 </option>
546                             [% END %]
548                             [% IF hold_fulfillment_policy == 'homebranch' %]
549                                 <option value="homebranch" selected="selected">
550                                     item's home library
551                                 </option>
552                             [% ELSE %]
553                                 <option value="homebranch">
554                                     item's home library
555                                 </option>
556                             [% END %]
558                             [% IF hold_fulfillment_policy == 'holdingbranch' %]
559                                 <option value="holdingbranch" selected="selected">
560                                     item's holding library
561                                 </option>
562                             [% ELSE %]
563                                 <option value="holdingbranch">
564                                     item's holding library
565                                 </option>
566                             [% END %]
567                         </select>
568                     </td>
569                     <td>
570                         <select name="returnbranch">
571                             [% SET returnbranch = CirculationRules.Search( current_branch, undef, undef, 'returnbranch' ) %]
573                             <option value="">
574                                 Not set
575                             </option>
577                             [% IF returnbranch == 'homebranch' %]
578                             <option value="homebranch" selected="selected">
579                             [% ELSE %]
580                             <option value="homebranch">
581                             [% END %]
582                                 Item returns home
583                             </option>
584                             [% IF returnbranch == 'holdingbranch' %]
585                             <option value="holdingbranch" selected="selected">
586                             [% ELSE %]
587                             <option value="holdingbranch">
588                             [% END %]
589                                 Item returns to issuing library
590                             </option>
591                             [% IF returnbranch == 'noreturn' %]
592                             <option value="noreturn" selected="selected">
593                             [% ELSE %]
594                             <option value="noreturn">
595                             [% END %]
596                                 Item floats
597                             </option>
598                         </select>
599                     </td>
600                     <td class="actions">
601                         <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
602                         <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=*&amp;branch=[% current_branch | html %]" id="unset"><i class="fa fa-undo"></i> Unset</a>
603                     </td>
604                 </tr>
605             </table>
606         </form>
607     </div>
608     [% IF ( show_branch_cat_rule_form ) %]
609     <div id="holds-policy-by-patron-category" class="container">
610     <h3>[% IF humanbranch %]Checkout, hold policy by patron category for [% Branches.GetName( humanbranch ) | html %][% ELSE %]Default checkout, hold policy by patron category[% END %]</h3>
611         <p>For this library, you can specify the maximum number of loans that
612             a patron of a given category can make, regardless of the item type.
613         </p>
614         <p>If the total amount loanable for a given patron category is left blank,
615            no limit applies, except possibly for a limit you define for a specific item type.
616         </p>
617         <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
618             <input type="hidden" name="op" value="add-branch-cat" />
619             <input type="hidden" name="branch" value="[% current_branch | html %]"/>
620             <table>
621                 <tr>
622                     <th>Patron category</th>
623                     <th>Total current checkouts allowed</th>
624                     <th>Total current on-site checkouts allowed</th>
625                     <th>Total holds allowed</th>
626                     <th>&nbsp;</th>
627                 </tr>
628                 [% FOREACH c IN categorycodes %]
629                     [% NEXT UNLESS c %]
630                     [% SET patron_maxissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxissueqty' ) %]
631                     [% SET patron_maxonsiteissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxonsiteissueqty' ) %]
632                     [% SET max_holds = CirculationRules.Search( branchcode, c, undef, 'max_holds' ) %]
634                     [% IF  ( patron_maxissueqty.defined && patron_maxissueqty != '' ) || ( patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' ) || ( max_holds.defined && max_holds != '' ) %]
635                     <tr>
636                         <td>
637                             [% IF c == undef %]
638                                 <em>Default</em>
639                             [% ELSE %]
640                                 [% Categories.GetName(c) | html %]
641                             [% END %]
642                         </td>
643                         <td>
644                             [% IF patron_maxissueqty.defined && patron_maxissueqty != '' %]
645                                 [% patron_maxissueqty | html %]
646                             [% ELSE %]
647                                 <span>Unlimited</span>
648                             [% END %]
649                         </td>
650                         <td>
651                             [% IF patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' %]
652                                 [% patron_maxonsiteissueqty | html %]
653                             [% ELSE %]
654                                 <span>Unlimited</span>
655                             [% END %]
656                         </td>
657                         <td>
658                             [% IF max_holds.defined && max_holds != '' %]
659                                 [% max_holds | html %]
660                             [% ELSE %]
661                                 <span>Unlimited</span>
662                             [% END %]
663                         </td>
665                         <td class="actions">
666                             <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=[% c | html %]&amp;branch=[% current_branch | html %]"><i class="fa fa-trash"></i> Delete</a>
667                         </td>
668                     </tr>
669                     [% END %]
670                 [% END %]
671                 <tr>
672                     <td>
673                         <select name="categorycode">
674                         [% FOREACH patron_category IN patron_categories%]
675                             <option value="[% patron_category.categorycode | html %]">[% patron_category.description | html %]</option>
676                         [% END %]
677                         </select>
678                     </td>
679                     <td><input name="patron_maxissueqty" size="3" type="text" /></td>
680                     <td><input name="patron_maxonsiteissueqty" size="3" type="text" /></td>
681                     <td><input name="max_holds" size="3" type="text" /></td>
682                     <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</td>
683                 </tr>
684             </table>
685         </form>
686     </div>
687     [% END %]
689     <div id="refund-lost-item-fee-on-return" class="container">
690         [% IF current_branch == '*' %]
691             <h3>Default lost item fee refund on return policy</h3>
692         [% ELSE %]
693             <h3>Lost item fee refund on return policy for [% Branches.GetName(current_branch) | html %]</h3>
694         [% END %]
695         <p>Specify the default policy for lost item fees on return.
696         </p>
697         <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
698             <input type="hidden" name="op" value="mod-refund-lost-item-fee-rule" />
699             <input type="hidden" name="branch" value="[% current_branch | html %]" />
700             <table>
701                 <tr>
702                     <th>Refund lost item fee</th>
703                     <th>&nbsp;</th>
704                 </tr>
705                 <tr>
706                     <td>
707                         <select name="refund">
708                           [#% Default branch %#]
709                           [% IF ( current_branch == '*' ) %]
710                             [% IF ( defaultRefundRule ) %]
711                             <option value="1" selected="selected">
712                             [% ELSE %]
713                             <option value="1">
714                             [% END %]
715                                 Yes
716                             </option>
717                             [% IF ( not defaultRefundRule ) %]
718                             <option value="0" selected="selected">
719                             [% ELSE %]
720                             <option value="0">
721                             [% END %]
722                                 No
723                             </option>
724                           [% ELSE %]
725                           [#% Branch-specific %#]
726                             [% IF ( not refundLostItemFeeRule ) %]
727                                 <option value="*" selected="selected">
728                             [% ELSE %]
729                                 <option value="*">
730                             [% END %]
731                               [% IF defaultRefundRule %]
732                                 Use default (Yes)
733                               [% ELSE %]
734                                 Use default (No)
735                               [% END %]
736                                 </option>
737                             [% IF ( not refundLostItemFeeRule ) %]
738                                 <option value="1">Yes</option>
739                                 <option value="0">No</option>
740                             [% ELSE %]
741                                 [% IF ( refundLostItemFeeRule.rule_value ) %]
742                                 <option value="1" selected="selected">
743                                 [% ELSE %]
744                                 <option value="1">
745                                 [% END %]
746                                     Yes
747                                 </option>
748                                 [% IF ( not refundLostItemFeeRule.rule_value ) %]
749                                 <option value="0" selected="selected">
750                                 [% ELSE %]
751                                 <option value="0">
752                                 [% END %]
753                                     No
754                                 </option>
755                             [% END %]
756                           [% END %]
757                         </select>
758                     </td>
759                     <td class="actions">
760                         <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
761                     </td>
762                     </td>
763                 </tr>
764             </table>
765         </form>
766     </div>
768     <div id="holds-policy-by-item-type" class="container">
769     <h3>[% IF humanbranch %]Holds policy by item type for [% Branches.GetName( humanbranch ) | html %][% ELSE %]Default holds policy by item type[% END %]</h3>
770         <p>
771             For this library, you can edit rules for given itemtypes, regardless
772             of the patron's category.
773         </p>
774         <p>
775             Currently, this means hold policies.
776             The various policies have the following effects:
777         </p>
778         <ul>
779             <li><strong>From any library:</strong> Patrons from any library may put this item on hold. <cite>(default if none is defined)</cite></li>
780             <li><strong>From local hold group:</strong> Only patrons from libraries in the same item's home library hold groups may put this book on hold.</li>
781             <li><strong>From home library:</strong> Only patrons from the item's home library may put this book on hold.</li>
782             <li><strong>No holds allowed:</strong> No patron may put this book on hold.</li>
783         </ul>
784         <p><strong>Note: </strong>If the system preference 'AllowHoldPolicyOverride' is enabled, these policies can be overridden by your circulation staff.</br />
785             <strong>Important: </strong>The policies are applied based on the ReservesControlBranch system preference which is set to <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=ReservesControlBranch">[% Koha.Preference('ReservesControlBranch') | html %]</a>.
786         </p>
788         <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
789             <input type="hidden" name="op" value="add-branch-item" />
790             <input type="hidden" name="branch" value="[% current_branch | html %]"/>
791             <table>
792                 <tr>
793                     <th>Item type</th>
794                     <th>Hold policy</th>
795                     <th>Hold pickup library match</th>
796                     <th>Return policy</th>
797                     <th>&nbsp;</th>
798                 </tr>
799                 [% FOREACH i IN itemtypeloop %]
800                     [% SET holdallowed = CirculationRules.Search( branchcode, undef, i.itemtype, 'holdallowed' ) %]
801                     [% SET hold_fulfillment_policy = CirculationRules.Search( branchcode, undef, i.itemtype, 'hold_fulfillment_policy' ) %]
802                     [% SET returnbranch = CirculationRules.Search( branchcode, undef, i.itemtype, 'returnbranch' ) %]
804                     [% IF holdallowed || hold_fulfillment_policy || returnbranch %]
805                         <tr>
806                             <td>
807                                 [% i.translated_description | html %]
808                             </td>
809                             <td>
810                                 [% IF holdallowed == 2 %]
811                                     <span>From any library</span>
812                                 [% ELSIF holdallowed == 3 %]
813                                     <span>From local hold group</span>
814                                 [% ELSIF holdallowed == 1 %]
815                                     <span>From home library</span>
816                                 [% ELSE %]
817                                     <span>No holds allowed</span>
818                                 [% END %]
819                             </td>
820                             <td>
821                                 [% IF hold_fulfillment_policy == 'any' %]
822                                     <span>any library</span>
823                                 [% ELSIF hold_fulfillment_policy == 'homebranch' %]
824                                     <span>item's home library</span>
825                                 [% ELSIF hold_fulfillment_policy == 'holdgroup' %]
826                                     <span>item's hold group</span>
827                                 [% ELSIF hold_fulfillment_policy == 'patrongroup' %]
828                                     <span>patron's hold group</span>
829                                 [% ELSIF hold_fulfillment_policy == 'holdingbranch' %]
830                                     <span>item's holding library</span>
831                                 [% END %]
832                             </td>
833                             <td>
834                                 [% IF returnbranch == 'homebranch' %]
835                                     <span>Item returns home</span>
836                                 [% ELSIF returnbranch == 'holdingbranch' %]
837                                     <span>Item returns to issuing branch</span>
838                                 [% ELSIF returnbranch == 'noreturn' %]
839                                     <span>Item floats</span>
840                                 [% END %]
841                             </td>
842                             <td class="actions">
843                                 <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-item&amp;itemtype=[% i.itemtype | uri %]&amp;branch=[% current_branch | uri %]"><i class="fa fa-trash"></i> Delete</a>
844                             </td>
845                         </tr>
846                     [% END %]
847                 [% END %]
848                 <tr>
849                     <td>
850                         <select name="itemtype">
851                         [% FOREACH itemtypeloo IN itemtypeloop %]
852                             <option value="[% itemtypeloo.itemtype | html %]">[% itemtypeloo.translated_description | html %]</option>
853                         [% END %]
854                         </select>
855                     </td>
856                     <td>
857                         <select name="holdallowed">
858                             <option value="2">From any library</option>
859                             <option value="3">From local hold group</option>
860                             <option value="1">From home library</option>
861                             <option value="0">No holds allowed</option>
862                         </select>
863                     </td>
864                     <td>
865                         <select name="hold_fulfillment_policy">
866                             <option value="any">
867                                 any library
868                             </option>
870                             <option value="holdgroup">
871                                 item's hold group
872                             </option>
874                             <option value="patrongroup">
875                                 patron's hold group
876                             </option>
878                             <option value="homebranch">
879                                 item's home library
880                             </option>
882                             <option value="holdingbranch">
883                                 item's holding library
884                             </option>
885                         </select>
886                     </td>
887                     <td>
888                         <select name="returnbranch">
889                             <option value="homebranch">Item returns home</option>
890                             <option value="holdingbranch">Item returns to issuing library</option>
891                             <option value="noreturn">Item floats</option>
892                         </select>
893                     </td>
894                     <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</button></td>
895                 </tr>
896             </table>
897         </form>
898     </div>
899             </main>
900         </div> <!-- /.col-sm-10.col-sm-push-2 -->
902         <div class="col-sm-2 col-sm-pull-10">
903             <aside>
904                 [% INCLUDE 'admin-menu.inc' %]
905             </aside>
906         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
907      </div> <!-- /.row -->
909 [% MACRO jsinclude BLOCK %]
910     [% Asset.js("js/admin-menu.js") | $raw %]
911     [% INCLUDE 'calendar.inc' %]
912     <script>
914         function clear_edit(){
915             var cancel = confirm(_("Are you sure you want to cancel your changes?"));
916             if ( !cancel ) return;
917             $('#default-circulation-rules td').removeClass('highlighted-row');
918             var edit_row = $("#edit_row");
919             $(edit_row).find("input").each(function(){
920                 var type = $(this).attr("type");
921                 if (type != "button" && type != "submit" ) {
922                     $(this).val("");
923                     $(this).prop('disabled', false);
924                 }
925                 if ( type == "checkbox" ) {
926                     $(this).prop('checked', false);
927                 }
928             });
929             $(edit_row).find("select").prop('disabled', false);
930             $(edit_row).find("select option:first").attr("selected", "selected");
931             $(edit_row).find("td:last input[name='clear']").remove();
932         }
934         var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this rule? This cannot be undone.");
936         $(document).ready(function() {
937             $('[data-toggle="popover"]').popover();
939             $(".delete").on("click",function(){
940                 return confirmDelete(MSG_CONFIRM_DELETE);
941             });
943             $("#clone_rules").on("click",function(){
944                 var library_dropdown = document.getElementById("branch");
945                 var selected_library = library_dropdown.options[library_dropdown.selectedIndex].value;
946                 var selected_library_text = $("#branch option:selected").text();
947                 var to_library = $("#tobranch option:selected").text();
948                 var MSG_CONFIRM_CLONE;
949                 if (selected_library === "*") {
950                     MSG_CONFIRM_CLONE = _("Are you sure you want to clone this standard rule to %s library? This will override the existing rules in this library.").format(to_library);
951                     return confirmClone(MSG_CONFIRM_CLONE);
952                 } else {
953                     MSG_CONFIRM_CLONE = _("Are you sure you want to clone this circulation and fine rule from %s to %s library? This will override the existing rules in this library.").format(selected_library_text, to_library);
954                     return confirmClone(MSG_CONFIRM_CLONE);
955                 }
956             });
958             $('#selectlibrary').find("input:submit").hide();
959             $('#branch').change(function() {
960                     $('#selectlibrary').submit();
961             });
962             $(".editrule").click(function(){
963                 if ( $("#edit_row").find("input[type='text']").filter(function(){return this.value.length > 0 }).length > 0 ) {
964                     var edit = confirm(_("Are you sure you want to edit another rule?"));
965                     if (!edit) return false;
966                 }
967                 $('#default-circulation-rules td').removeClass('highlighted-row');
968                 $(this).parent().parent().find("td").each(function (i) {
969                     $(this).addClass('highlighted-row');
970                     itm = $(this).text();
971                     itm = itm.replace(/^\s*|\s*$/g,'');
972                     var current_column = $("#edit_row td:eq("+i+")");
973                     if ( i == 3 ) {
974                         // specific processing for the Note column
975                         var note = $(this).find("a[name='viewnote']").data("content");
976                         $(current_column).find("input[type='text']").val(note);
977                     } else if ( i == 8 ) {
978                         // specific processing for the Hard due date column
979                         var select_value = $(this).find("input[type='hidden'][name='hardduedatecomparebackup']").val();
980                         var input_value = '';
981                         if (typeof select_value === 'undefined'){
982                             select_value = '-1';
983                         }else {
984                             input_value = itm.split(' ')[1];
985                         }
986                         $(current_column).find("input[type='text']").val(input_value);
987                         $(current_column).find("select").val(select_value);
988                     } else if ( i == 14 ) {
989                         // specific processing for cap_fine_to_replacement_price
990                         var cap_fine_to_replacement_price = $(this).find("input[type='checkbox']");
991                         $('#cap_fine_to_replacement_price').prop('checked', cap_fine_to_replacement_price.is(':checked') );
992                         $('#overduefinescap').prop('disabled', cap_fine_to_replacement_price.is(':checked') );
993                     } else {
994                         $(current_column).find("input[type='text']").val(itm);
995                         // select the corresponding option
996                         $(current_column).find("select option").each(function(){
997                             opt = $(this).text().toLowerCase();
998                             opt = opt.replace(/^\s*|\s*$/g,'');
999                             if ( opt == itm.toLowerCase() ) {
1000                                 $(this).attr('selected', 'selected');
1001                             }
1002                         });
1003                         if ( i == 0 || i == 1 ) {
1004                             // Disable the 2 first columns, we cannot update them.
1005                             var val = $(current_column).find("select option:selected").val();
1006                             var name = "categorycode";
1007                             if ( i == 1 ) {
1008                                 name="itemtype";
1009                             }
1010                             // Remove potential previous input added
1011                             $(current_column).find("input").remove();
1012                             $(current_column).append("<input type='hidden' name='"+name+"' value='"+val+"' />");
1013                         } else if ( i == 4 || i == 5 || i == 25 ) {
1014                             // If the value is not an integer for
1015                             //     - "Current checkouts allowed"
1016                             //     - "Current on-site checkouts allowed"
1017                             //     - "Holds allowed (daily)"
1018                             // The value is "Unlimited" (or an equivalent translated string)
1019                             // an it should be set to an empty string
1020                             if( !((parseFloat(itm) == parseInt(itm)) && !isNaN(itm)) ) {
1021                                 $(current_column).find("input[type='text']").val("");
1022                             }
1023                         }
1024                     }
1025                 });
1026                 $("#default-circulation-rules tr:last td:eq(0) select").prop('disabled', true);
1027                 $("#default-circulation-rules tr:last td:eq(1) select").prop('disabled', true);
1028                 return false;
1029             });
1030             $(".clear_edit").on("click",function(e){
1031                 e.preventDefault();
1032                 clear_edit();
1033             });
1034         });
1035     </script>
1036 [% END %]
1037 [% INCLUDE 'intranet-bottom.inc' %]