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