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