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