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