Bug 21928: (bug 18789 follow-up) Fix CircAutoPrintQuickSlip=clear
[koha.git] / circ / circulation.pl
1 #!/usr/bin/perl
2
3 # script to execute issuing of books
4
5 # Copyright 2000-2002 Katipo Communications
6 # copyright 2010 BibLibre
7 # Copyright 2011 PTFS-Europe Ltd.
8 # Copyright 2012 software.coop and MJ Ray
9 #
10 # This file is part of Koha.
11 #
12 # Koha is free software; you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 3 of the License, or
15 # (at your option) any later version.
16 #
17 # Koha is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24
25 # FIXME There are too many calls to Koha::Patrons->find in this script
26
27 use Modern::Perl;
28 use CGI qw ( -utf8 );
29 use DateTime;
30 use DateTime::Duration;
31 use Scalar::Util qw( looks_like_number );
32 use C4::Output;
33 use C4::Print;
34 use C4::Auth qw/:DEFAULT get_session haspermission/;
35 use C4::Koha;   # GetPrinter
36 use C4::Circulation;
37 use C4::Utils::DataTables::Members;
38 use C4::Members;
39 use C4::Biblio;
40 use C4::Search;
41 use MARC::Record;
42 use C4::Reserves;
43 use Koha::Holds;
44 use C4::Context;
45 use CGI::Session;
46 use C4::Members::Attributes qw(GetBorrowerAttributes);
47 use Koha::AuthorisedValues;
48 use Koha::CsvProfiles;
49 use Koha::Patrons;
50 use Koha::Patron::Debarments qw(GetDebarments);
51 use Koha::DateUtils;
52 use Koha::Database;
53 use Koha::BiblioFrameworks;
54 use Koha::Items;
55 use Koha::Patron::Messages;
56 use Koha::SearchEngine;
57 use Koha::SearchEngine::Search;
58 use Koha::Patron::Modifications;
59
60 use Date::Calc qw(
61   Today
62   Add_Delta_Days
63   Date_to_Days
64 );
65 use List::MoreUtils qw/uniq/;
66
67 #
68 # PARAMETERS READING
69 #
70 my $query = new CGI;
71
72 my $override_high_holds     = $query->param('override_high_holds');
73 my $override_high_holds_tmp = $query->param('override_high_holds_tmp');
74
75 my $sessionID = $query->cookie("CGISESSID") ;
76 my $session = get_session($sessionID);
77 if (!C4::Context->userenv){
78     if ($session->param('branch') eq 'NO_LIBRARY_SET'){
79         # no branch set we can't issue
80         print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
81         exit;
82     }
83 }
84
85 my $barcodes = [];
86 my $barcode =  $query->param('barcode');
87 my $findborrower;
88 my $autoswitched;
89 my $borrowernumber = $query->param('borrowernumber');
90
91 if (C4::Context->preference("AutoSwitchPatron") && $barcode) {
92     if (Koha::Patrons->search( { cardnumber => $barcode} )->count() > 0) {
93         $findborrower = $barcode;
94         undef $barcode;
95         undef $borrowernumber;
96         $autoswitched = 1;
97     }
98 }
99 $findborrower ||= $query->param('findborrower') || q{};
100 $findborrower =~ s|,| |g;
101
102 # Barcode given by user could be '0'
103 if ( $barcode || ( defined($barcode) && $barcode eq '0' ) ) {
104     $barcodes = [ $barcode ];
105 } else {
106     my $filefh = $query->upload('uploadfile');
107     if ( $filefh ) {
108         while ( my $content = <$filefh> ) {
109             $content =~ s/[\r\n]*$//g;
110             push @$barcodes, $content if $content;
111         }
112     } elsif ( my $list = $query->param('barcodelist') ) {
113         push @$barcodes, split( /\s\n/, $list );
114         $barcodes = [ map { $_ =~ /^\s*$/ ? () : $_ } @$barcodes ];
115     } else {
116         @$barcodes = $query->multi_param('barcodes');
117     }
118 }
119
120 $barcodes = [ uniq @$barcodes ];
121
122 my $template_name = q|circ/circulation.tt|;
123 my $patron = $borrowernumber ? Koha::Patrons->find( $borrowernumber ) : undef;
124 my $batch = $query->param('batch');
125 my $batch_allowed = 0;
126 if ( $batch && C4::Context->preference('BatchCheckouts') ) {
127     $template_name = q|circ/circulation_batch_checkouts.tt|;
128     my @batch_category_codes = split '\|', C4::Context->preference('BatchCheckoutsValidCategories');
129     my $categorycode = $patron->categorycode;
130     if ( $categorycode && grep {/^$categorycode$/} @batch_category_codes ) {
131         $batch_allowed = 1;
132     } else {
133         $barcodes = [];
134     }
135 }
136
137 my ( $template, $loggedinuser, $cookie ) = get_template_and_user (
138     {
139         template_name   => $template_name,
140         query           => $query,
141         type            => "intranet",
142         authnotrequired => 0,
143         flagsrequired   => { circulate => 'circulate_remaining_permissions' },
144     }
145 );
146 my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
147
148 my $force_allow_issue = $query->param('forceallow') || 0;
149 if (!C4::Auth::haspermission( C4::Context->userenv->{id} , { circulate => 'force_checkout' } )) {
150     $force_allow_issue = 0;
151 }
152
153 my $onsite_checkout = $query->param('onsite_checkout');
154
155 my @failedrenews = $query->multi_param('failedrenew');    # expected to be itemnumbers
156 our %renew_failed = ();
157 for (@failedrenews) { $renew_failed{$_} = 1; }
158
159 my @failedreturns = $query->multi_param('failedreturn');
160 our %return_failed = ();
161 for (@failedreturns) { $return_failed{$_} = 1; }
162
163 my $searchtype = $query->param('searchtype') || q{contain};
164
165 my $branch = C4::Context->userenv->{'branch'};
166
167 if (C4::Context->preference("DisplayClearScreenButton")) {
168     $template->param(DisplayClearScreenButton => 1);
169 }
170
171 for my $barcode ( @$barcodes ) {
172     $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
173     $barcode = barcodedecode($barcode)
174         if( $barcode && C4::Context->preference('itemBarcodeInputFilter'));
175 }
176
177 my $stickyduedate  = $query->param('stickyduedate') || $session->param('stickyduedate');
178 my $duedatespec    = $query->param('duedatespec')   || $session->param('stickyduedate');
179 $duedatespec = eval { output_pref( { dt => dt_from_string( $duedatespec ), dateformat => 'iso', timeformat => '24hr' }); }
180     if ( $duedatespec );
181 my $restoreduedatespec  = $query->param('restoreduedatespec') || $duedatespec || $session->param('stickyduedate');
182 if ( $restoreduedatespec && $restoreduedatespec eq "highholds_empty" ) {
183     undef $restoreduedatespec;
184 }
185 my $issueconfirmed = $query->param('issueconfirmed');
186 my $cancelreserve  = $query->param('cancelreserve');
187 my $print          = $query->param('print') || q{};
188 my $debt_confirmed = $query->param('debt_confirmed') || 0; # Don't show the debt error dialog twice
189 my $charges        = $query->param('charges') || q{};
190
191 # Check if stickyduedate is turned off
192 if ( @$barcodes ) {
193     # was stickyduedate loaded from session?
194     if ( $stickyduedate && ! $query->param("stickyduedate") ) {
195         $session->clear( 'stickyduedate' );
196         $stickyduedate  = $query->param('stickyduedate');
197         $duedatespec    = $query->param('duedatespec');
198     }
199     $session->param('auto_renew', scalar $query->param('auto_renew'));
200 }
201 else {
202     $session->clear('auto_renew');
203 }
204
205 my ($datedue,$invalidduedate);
206
207 my $duedatespec_allow = C4::Context->preference('SpecifyDueDate');
208 if( $onsite_checkout && !$duedatespec_allow ) {
209     $datedue = output_pref({ dt => dt_from_string, dateonly => 1, dateformat => 'iso' });
210     $datedue .= ' 23:59:00';
211 } elsif( $duedatespec_allow ) {
212     if ( $duedatespec ) {
213         $datedue = eval { dt_from_string( $duedatespec ) };
214         if (! $datedue ) {
215             $invalidduedate = 1;
216             $template->param( IMPOSSIBLE=>1, INVALID_DATE=>$duedatespec );
217         }
218     }
219 }
220
221 # check and see if we should print
222 if ( @$barcodes == 0 && $print eq 'maybe' ) {
223     $print = 'yes';
224 }
225
226 my $inprocess = (@$barcodes == 0) ? '' : $query->param('inprocess');
227 if ( @$barcodes == 0 && $charges eq 'yes' ) {
228     $template->param(
229         PAYCHARGES     => 'yes',
230         borrowernumber => $borrowernumber
231     );
232 }
233
234 if ( $print eq 'yes' && $borrowernumber ne '' ) {
235     if ( C4::Context->boolean_preference('printcirculationslips') ) {
236         my $letter = IssueSlip($branch, $borrowernumber, "QUICK");
237         NetworkPrint($letter->{content});
238     }
239     $query->param( 'borrowernumber', '' );
240     $borrowernumber = '';
241     undef $patron;
242 }
243
244 #
245 # STEP 2 : FIND BORROWER
246 # if there is a list of find borrowers....
247 #
248 my $message;
249 if ($findborrower) {
250     my $patron = Koha::Patrons->find( { cardnumber => $findborrower } );
251     if ( $patron ) {
252         $borrowernumber = $patron->borrowernumber;
253     } else {
254         my $dt_params = { iDisplayLength => -1 };
255         my $results = C4::Utils::DataTables::Members::search(
256             {
257                 searchmember => $findborrower,
258                 searchtype   => $searchtype,
259                 dt_params    => $dt_params,
260             }
261         );
262         my $borrowers = $results->{patrons};
263         if ( scalar @$borrowers == 1 ) {
264             $borrowernumber = $borrowers->[0]->{borrowernumber};
265             $query->param( 'borrowernumber', $borrowernumber );
266             $query->param( 'barcode',           '' );
267         } elsif ( @$borrowers ) {
268             $template->param( borrowers => $borrowers );
269         } else {
270             $query->param( 'findborrower', '' );
271             $message = "'$findborrower'";
272         }
273     }
274 }
275
276 # get the borrower information.....
277 my $balance = 0;
278 $patron ||= Koha::Patrons->find( $borrowernumber ) if $borrowernumber;
279 if ($patron) {
280
281     $template->param( borrowernumber => $patron->borrowernumber );
282     output_and_exit_if_error( $query, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
283
284     my $overdues = $patron->get_overdues;
285     my $issues = $patron->checkouts;
286     $balance = $patron->account->balance;
287
288
289     # if the expiry date is before today ie they have expired
290     if ( $patron->is_expired ) {
291         #borrowercard expired, no issues
292         $template->param(
293             noissues => ($force_allow_issue) ? 0 : "1",
294             forceallow => $force_allow_issue,
295             expired => "1",
296         );
297     }
298     # check for NotifyBorrowerDeparture
299     elsif ( $patron->is_going_to_expire ) {
300         # borrower card soon to expire warn librarian
301         $template->param( "warndeparture" => $patron->dateexpiry ,
302                         );
303         if (C4::Context->preference('ReturnBeforeExpiry')){
304             $template->param("returnbeforeexpiry" => 1);
305         }
306     }
307     $template->param(
308         overduecount => $overdues->count,
309         issuecount   => $issues->count,
310         finetotal    => $balance,
311     );
312
313     if ( $patron and $patron->is_debarred ) {
314         $template->param(
315             'userdebarred'    => $patron->debarred,
316             'debarredcomment' => $patron->debarredcomment,
317         );
318
319         if ( $patron->debarred ne "9999-12-31" ) {
320             $template->param( 'userdebarreddate' => $patron->debarred );
321         }
322     }
323
324 }
325
326 #
327 # STEP 3 : ISSUING
328 #
329 #
330 if (@$barcodes) {
331   my $checkout_infos;
332   for my $barcode ( @$barcodes ) {
333     my $template_params = { barcode => $barcode };
334     # always check for blockers on issuing
335     my ( $error, $question, $alerts, $messages ) = CanBookBeIssued(
336         $patron,
337         $barcode, $datedue,
338         $inprocess,
339         undef,
340         {
341             onsite_checkout     => $onsite_checkout,
342             override_high_holds => $override_high_holds || $override_high_holds_tmp || 0,
343         }
344     );
345
346     my $blocker = $invalidduedate ? 1 : 0;
347
348     $template_params->{alert} = $alerts;
349     $template_params->{messages} = $messages;
350
351     my $item = Koha::Items->find({ barcode => $barcode });
352     my ( $biblio, $mss );
353
354     if ( $item ) {
355         $biblio = $item->biblio;
356         my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $biblio->frameworkcode, kohafield => 'items.notforloan', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
357         $template_params->{authvalcode_notforloan} = $mss->count ? $mss->next->authorised_value : undef;
358     }
359
360     # Fix for bug 7494: optional checkout-time fallback search for a book
361
362     if ( $error->{'UNKNOWN_BARCODE'}
363         && C4::Context->preference("itemBarcodeFallbackSearch")
364         && not $batch
365     )
366     {
367      $template_params->{FALLBACK} = 1;
368
369         my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
370         my $query = "kw=" . $barcode;
371         my ( $searcherror, $results, $total_hits ) = $searcher->simple_search_compat($query, 0, 10);
372
373         # if multiple hits, offer options to librarian
374         if ( $total_hits > 0 ) {
375             my @options = ();
376             foreach my $hit ( @{$results} ) {
377                 my $chosen =
378                   TransformMarcToKoha( C4::Search::new_record_from_zebra('biblioserver',$hit) );
379
380                 # offer all barcodes individually
381                 if ( $chosen->{barcode} ) {
382                     foreach my $barcode ( sort split(/\s*\|\s*/, $chosen->{barcode}) ) {
383                         my %chosen_single = %{$chosen};
384                         $chosen_single{barcode} = $barcode;
385                         push( @options, \%chosen_single );
386                     }
387                 }
388             }
389             $template_params->{options} = \@options;
390         }
391     }
392
393     if ( $error->{UNKNOWN_BARCODE} or not $onsite_checkout or not C4::Context->preference("OnSiteCheckoutsForce") ) {
394         delete $question->{'DEBT'} if ($debt_confirmed);
395         foreach my $impossible ( keys %$error ) {
396             $template_params->{$impossible} = $$error{$impossible};
397             $template_params->{IMPOSSIBLE} = 1;
398             $blocker = 1;
399         }
400     }
401
402     if( $item and ( !$blocker or $force_allow_issue ) ){
403         my $confirm_required = 0;
404         unless($issueconfirmed){
405             #  Get the item title for more information
406             my $materials = $item->materials;
407             my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $biblio->frameworkcode, kohafield => 'items.materials', authorised_value => $materials });
408             $materials = $descriptions->{lib} // $materials;
409             $template_params->{additional_materials} = $materials;
410             $template_params->{itemhomebranch} = $item->homebranch;
411
412             # pass needsconfirmation to template if issuing is possible and user hasn't yet confirmed.
413             foreach my $needsconfirmation ( keys %$question ) {
414                 $template_params->{$needsconfirmation} = $$question{$needsconfirmation};
415                 $template_params->{getTitleMessageIteminfo} = $biblio->title;
416                 $template_params->{getBarcodeMessageIteminfo} = $item->barcode;
417                 $template_params->{NEEDSCONFIRMATION} = 1;
418                 $template_params->{onsite_checkout} = $onsite_checkout;
419                 $template_params->{auto_renew} = $session->param('auto_renew');
420                 $confirm_required = 1;
421             }
422         }
423         unless($confirm_required) {
424             my $switch_onsite_checkout = exists $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED};
425             my $issue = AddIssue( $patron->unblessed, $barcode, $datedue, $cancelreserve, undef, undef, { onsite_checkout => $onsite_checkout, auto_renew => $session->param('auto_renew'), switch_onsite_checkout => $switch_onsite_checkout, } );
426             $template_params->{issue} = $issue;
427             $session->clear('auto_renew');
428             $inprocess = 1;
429         }
430     }
431
432     if ($question->{RESERVE_WAITING} or $question->{RESERVED}){
433         $template->param(
434             reserveborrowernumber => $question->{'resborrowernumber'}
435         );
436     }
437
438
439     # FIXME If the issue is confirmed, we launch another time checkouts->count, now display the issue count after issue
440     $patron = Koha::Patrons->find( $borrowernumber );
441     $template_params->{issuecount} = $patron->checkouts->count;
442
443     if ( $item ) {
444         $template_params->{item} = $item;
445         $template_params->{biblio} = $biblio;
446         $template_params->{itembiblionumber} = $biblio->biblionumber;
447     }
448     push @$checkout_infos, $template_params;
449   }
450   unless ( $batch ) {
451     $template->param( %{$checkout_infos->[0]} );
452     $template->param( barcode => $barcodes->[0] );
453   } else {
454     my $confirmation_needed = grep { $_->{NEEDSCONFIRMATION} } @$checkout_infos;
455     $template->param(
456         checkout_infos => $checkout_infos,
457         confirmation_needed => $confirmation_needed,
458     );
459   }
460 }
461
462 ##################################################################################
463 # BUILD HTML
464 # show all reserves of this borrower, and the position of the reservation ....
465 if ($patron) {
466     my $holds = Koha::Holds->search( { borrowernumber => $borrowernumber } ); # FIXME must be Koha::Patron->holds
467     my $waiting_holds = $holds->waiting;
468     $template->param(
469         holds_count  => $holds->count(),
470         WaitingHolds => $waiting_holds,
471     );
472 }
473
474 if ( $patron ) {
475     my $noissues;
476     if ( $patron->gonenoaddress ) {
477         $template->param( gna => 1 );
478         $noissues = 1;
479     }
480     if ( $patron->lost ) {
481         $template->param( lost=> 1 );
482         $noissues = 1;
483     }
484     if ( $patron->is_debarred ) {
485         $template->param( dbarred=> 1 );
486         $noissues = 1;
487     }
488     my $account = $patron->account;
489     if( ( my $owing = $account->non_issues_charges ) > 0 ) {
490         my $noissuescharge = C4::Context->preference("noissuescharge") || 5; # FIXME If noissuescharge == 0 then 5, why??
491         $noissues ||= ( not C4::Context->preference("AllowFineOverride") and ( $owing > $noissuescharge ) );
492         $template->param(
493             charges => 1,
494             chargesamount => $owing,
495         )
496     } elsif ( $balance < 0 ) {
497         $template->param(
498             credits => 1,
499             creditsamount => -$balance,
500         );
501     }
502
503     my $no_issues_charge_guarantees = C4::Context->preference("NoIssuesChargeGuarantees");
504     $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
505     if ( defined $no_issues_charge_guarantees ) {
506         my $guarantees_non_issues_charges = 0;
507         my $guarantees = $patron->guarantees;
508         while ( my $g = $guarantees->next ) {
509             $guarantees_non_issues_charges += $g->account->non_issues_charges;
510         }
511         if ( $guarantees_non_issues_charges > $no_issues_charge_guarantees ) {
512             $template->param(
513                 charges_guarantees    => 1,
514                 chargesamount_guarantees => $guarantees_non_issues_charges,
515             );
516             $noissues = 1 unless C4::Context->preference("allowfineoverride");
517         }
518     }
519
520     if ( $patron->has_overdues ) {
521         $template->param( odues => 1 );
522     }
523
524     if ( $patron->borrowernotes ) {
525         my $borrowernotes = $patron->borrowernotes;
526         $borrowernotes =~ s#\n#<br />#g;
527         $template->param(
528             notes =>1,
529             notesmsg => $borrowernotes,
530         )
531     }
532
533     if ( $noissues ) {
534         $template->param(
535             noissues => ($force_allow_issue) ? 0 : 'true',
536             forceallow => $force_allow_issue,
537         );
538     }
539 }
540
541 if ( $patron && $patron->is_child) {
542     my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
543     $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
544     $template->param( 'catcode' => $patron_categories->next->categorycode )  if $patron_categories->count == 1;
545 }
546
547 my $messages = Koha::Patron::Messages->search(
548     {
549         'me.borrowernumber' => $borrowernumber,
550     },
551     {
552        join => 'manager',
553        '+select' => ['manager.surname', 'manager.firstname' ],
554        '+as' => ['manager_surname', 'manager_firstname'],
555     }
556 );
557
558 my $fast_cataloging = 0;
559 if ( Koha::BiblioFrameworks->find('FA') ) {
560     $fast_cataloging = 1 
561 }
562
563 if (C4::Context->preference('ExtendedPatronAttributes')) {
564     my $attributes = GetBorrowerAttributes($borrowernumber);
565     $template->param(
566         ExtendedPatronAttributes => 1,
567         extendedattributes => $attributes
568     );
569 }
570 my $view = $batch
571     ?'batch_checkout_view'
572     : 'circview';
573
574 my @relatives;
575 if ( $borrowernumber ) {
576     if ( $patron ) {
577         if ( my $guarantor = $patron->guarantor ) {
578             push @relatives, $guarantor->borrowernumber;
579             push @relatives, $_->borrowernumber for $patron->siblings;
580         } else {
581             push @relatives, $_->borrowernumber for $patron->guarantees;
582         }
583     }
584 }
585 my $relatives_issues_count =
586   Koha::Database->new()->schema()->resultset('Issue')
587   ->count( { borrowernumber => \@relatives } );
588
589 if ( $patron ) {
590     my $av = Koha::AuthorisedValues->search({ category => 'ROADTYPE', authorised_value => $patron->streettype });
591     my $roadtype = $av->count ? $av->next->lib : '';
592     $template->param(
593         roadtype          => $roadtype,
594         patron            => $patron,
595         categoryname      => $patron->category->description,
596         expiry            => $patron->dateexpiry,
597     );
598 }
599
600 # Restore date if changed by holds and/or save stickyduedate to session
601 if ($restoreduedatespec || $stickyduedate) {
602     $duedatespec = $restoreduedatespec || $duedatespec;
603
604     if ($stickyduedate) {
605         $session->param( 'stickyduedate', $duedatespec );
606     }
607 } elsif (defined($duedatespec) && !defined($restoreduedatespec)) {
608     undef $duedatespec;
609 }
610
611 $template->param(
612     messages           => $messages,
613     borrowernumber    => $borrowernumber,
614     branch            => $branch,
615     was_renewed       => scalar $query->param('was_renewed') ? 1 : 0,
616     barcodes          => $barcodes,
617     stickyduedate     => $stickyduedate,
618     duedatespec       => $duedatespec,
619     restoreduedatespec => $restoreduedatespec,
620     message           => $message,
621     totaldue          => sprintf('%.2f', $balance), # FIXME not used in template?
622     inprocess         => $inprocess,
623     $view             => 1,
624     batch_allowed     => $batch_allowed,
625     batch             => $batch,
626     AudioAlerts           => C4::Context->preference("AudioAlerts"),
627     fast_cataloging   => $fast_cataloging,
628     CircAutoPrintQuickSlip   => C4::Context->preference("CircAutoPrintQuickSlip"),
629     RoutingSerials => C4::Context->preference('RoutingSerials'),
630     relatives_issues_count => $relatives_issues_count,
631     relatives_borrowernumbers => \@relatives,
632 );
633
634
635 if ( C4::Context->preference("ExportCircHistory") ) {
636     $template->param(csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc' }) ]);
637 }
638
639 my $has_modifications = Koha::Patron::Modifications->search( { borrowernumber => $borrowernumber } )->count;
640 $template->param(
641     debt_confirmed            => $debt_confirmed,
642     SpecifyDueDate            => $duedatespec_allow,
643     CircAutocompl             => C4::Context->preference("CircAutocompl"),
644     debarments                => scalar GetDebarments({ borrowernumber => $borrowernumber }),
645     todaysdate                => output_pref( { dt => dt_from_string()->set(hour => 23)->set(minute => 59), dateformat => 'sql' } ),
646     has_modifications         => $has_modifications,
647     override_high_holds       => $override_high_holds,
648     nopermission              => scalar $query->param('nopermission'),
649     autoswitched              => $autoswitched,
650 );
651
652 output_html_with_http_headers $query, $cookie, $template->output;