Bug 6679 - [SIGNED-OFF] fix 2 perlcritic violations in C4/Installer/PerlModules.pm
[koha.git] / circ / circulation.pl
blobf15d4cea94e67e74b6c87ccbef50d0c572b658d1
1 #!/usr/bin/perl
3 # script to execute issuing of books
5 # Copyright 2000-2002 Katipo Communications
6 # copyright 2010 BibLibre
7 # Copyright 2011 PTFS-Europe Ltd.
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along
21 # with Koha; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 use strict;
25 use warnings;
26 use CGI;
27 use C4::Output;
28 use C4::Print;
29 use C4::Auth qw/:DEFAULT get_session/;
30 use C4::Dates qw/format_date/;
31 use C4::Branch; # GetBranches
32 use C4::Koha; # GetPrinter
33 use C4::Circulation;
34 use C4::Overdues qw/CheckBorrowerDebarred/;
35 use C4::Members;
36 use C4::Biblio;
37 use C4::Reserves;
38 use C4::Context;
39 use CGI::Session;
40 use C4::Members::Attributes qw(GetBorrowerAttributes);
41 use Koha::DateUtils;
43 use Date::Calc qw(
44 Today
45 Add_Delta_YM
46 Add_Delta_Days
47 Date_to_Days
49 use List::MoreUtils qw/uniq/;
53 # PARAMETERS READING
55 my $query = new CGI;
57 my $sessionID = $query->cookie("CGISESSID") ;
58 my $session = get_session($sessionID);
60 # branch and printer are now defined by the userenv
61 # but first we have to check if someone has tried to change them
63 my $branch = $query->param('branch');
64 if ($branch){
65 # update our session so the userenv is updated
66 $session->param('branch', $branch);
67 $session->param('branchname', GetBranchName($branch));
70 my $printer = $query->param('printer');
71 if ($printer){
72 # update our session so the userenv is updated
73 $session->param('branchprinter', $printer);
76 if (!C4::Context->userenv && !$branch){
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;
84 my ( $template, $loggedinuser, $cookie ) = get_template_and_user (
86 template_name => 'circ/circulation.tmpl',
87 query => $query,
88 type => "intranet",
89 authnotrequired => 0,
90 flagsrequired => { circulate => 'circulate_remaining_permissions' },
94 my $branches = GetBranches();
96 my @failedrenews = $query->param('failedrenew'); # expected to be itemnumbers
97 our %renew_failed = {};
98 for (@failedrenews) { $renew_failed{$_} = 1; }
100 my @failedreturns = $query->param('failedreturn');
101 our %return_failed = {};
102 for (@failedreturns) { $return_failed{$_} = 1; }
104 my $findborrower = $query->param('findborrower');
105 $findborrower =~ s|,| |g;
106 my $borrowernumber = $query->param('borrowernumber');
108 $branch = C4::Context->userenv->{'branch'};
109 $printer = C4::Context->userenv->{'branchprinter'};
112 # If AutoLocation is not activated, we show the Circulation Parameters to chage settings of librarian
113 if (C4::Context->preference("AutoLocation") != 1) {
114 $template->param(ManualLocation => 1);
117 if (C4::Context->preference("DisplayClearScreenButton")) {
118 $template->param(DisplayClearScreenButton => 1);
121 if (C4::Context->preference("UseTablesortForCirc")) {
122 $template->param(UseTablesortForCirc => 1);
125 my $barcode = $query->param('barcode') || '';
126 $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
128 $barcode = barcodedecode($barcode) if( $barcode && C4::Context->preference('itemBarcodeInputFilter'));
129 my $stickyduedate = $query->param('stickyduedate') || $session->param('stickyduedate');
130 my $duedatespec = $query->param('duedatespec') || $session->param('stickyduedate');
131 my $issueconfirmed = $query->param('issueconfirmed');
132 my $cancelreserve = $query->param('cancelreserve');
133 my $organisation = $query->param('organisations');
134 my $print = $query->param('print');
135 my $newexpiry = $query->param('dateexpiry');
136 my $debt_confirmed = $query->param('debt_confirmed') || 0; # Don't show the debt error dialog twice
138 # Check if stickyduedate is turned off
139 if ( $barcode ) {
140 # was stickyduedate loaded from session?
141 if ( $stickyduedate && ! $query->param("stickyduedate") ) {
142 $session->clear( 'stickyduedate' );
143 $stickyduedate = $query->param('stickyduedate');
144 $duedatespec = $query->param('duedatespec');
148 my ($datedue,$invalidduedate);
150 my $duedatespec_allow = C4::Context->preference('SpecifyDueDate');
151 if($duedatespec_allow){
152 if ($duedatespec) {
153 if ($duedatespec =~ C4::Dates->regexp('syspref')) {
154 $datedue = dt_from_string($duedatespec);
155 } else {
156 $invalidduedate = 1;
157 $template->param(IMPOSSIBLE=>1, INVALID_DATE=>$duedatespec);
162 our $todaysdate = C4::Dates->new->output('iso');
164 # check and see if we should print
165 if ( $barcode eq '' && $print eq 'maybe' ) {
166 $print = 'yes';
169 my $inprocess = ($barcode eq '') ? '' : $query->param('inprocess');
170 if ( $barcode eq '' && $query->param('charges') eq 'yes' ) {
171 $template->param(
172 PAYCHARGES => 'yes',
173 borrowernumber => $borrowernumber
177 if ( $print eq 'yes' && $borrowernumber ne '' ) {
178 if ( C4::Context->boolean_preference('printcirculationslips') ) {
179 my $letter = IssueSlip($branch, $borrowernumber, "QUICK");
180 NetworkPrint($letter->{content});
182 $query->param( 'borrowernumber', '' );
183 $borrowernumber = '';
187 # STEP 2 : FIND BORROWER
188 # if there is a list of find borrowers....
190 my $borrowerslist;
191 my $message;
192 if ($findborrower) {
193 my $borrowers = Search($findborrower, 'cardnumber');
194 my @borrowers = @$borrowers;
195 if (C4::Context->preference("AddPatronLists")) {
196 $template->param(
197 "AddPatronLists_".C4::Context->preference("AddPatronLists")=> "1",
199 if (C4::Context->preference("AddPatronLists")=~/code/){
200 my $categories = GetBorrowercategoryList;
201 $categories->[0]->{'first'} = 1;
202 $template->param(categories=>$categories);
205 if ( $#borrowers == -1 ) {
206 $query->param( 'findborrower', '' );
207 $message = "'$findborrower'";
209 elsif ( $#borrowers == 0 ) {
210 $query->param( 'borrowernumber', $borrowers[0]->{'borrowernumber'} );
211 $query->param( 'barcode', '' );
212 $borrowernumber = $borrowers[0]->{'borrowernumber'};
214 else {
215 $borrowerslist = \@borrowers;
219 # get the borrower information.....
220 my $borrower;
221 if ($borrowernumber) {
222 $borrower = GetMemberDetails( $borrowernumber, 0 );
223 my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrowernumber );
225 # Warningdate is the date that the warning starts appearing
226 my ( $today_year, $today_month, $today_day) = Today();
227 my ($warning_year, $warning_month, $warning_day) = split /-/, $borrower->{'dateexpiry'};
228 my ( $enrol_year, $enrol_month, $enrol_day) = split /-/, $borrower->{'dateenrolled'};
229 # Renew day is calculated by adding the enrolment period to today
230 my ( $renew_year, $renew_month, $renew_day);
231 if ($enrol_year*$enrol_month*$enrol_day>0) {
232 ( $renew_year, $renew_month, $renew_day) =
233 Add_Delta_YM( $enrol_year, $enrol_month, $enrol_day,
234 0 , $borrower->{'enrolmentperiod'});
236 # if the expiry date is before today ie they have expired
237 if ( !$borrower->{'dateexpiry'} || $warning_year*$warning_month*$warning_day==0
238 || Date_to_Days($today_year, $today_month, $today_day )
239 > Date_to_Days($warning_year, $warning_month, $warning_day) )
241 #borrowercard expired, no issues
242 $template->param(
243 flagged => "1",
244 noissues => "1",
245 expired => "1",
246 renewaldate => format_date("$renew_year-$renew_month-$renew_day")
249 # check for NotifyBorrowerDeparture
250 elsif ( C4::Context->preference('NotifyBorrowerDeparture') &&
251 Date_to_Days(Add_Delta_Days($warning_year,$warning_month,$warning_day,- C4::Context->preference('NotifyBorrowerDeparture'))) <
252 Date_to_Days( $today_year, $today_month, $today_day ) )
254 # borrower card soon to expire warn librarian
255 $template->param("warndeparture" => format_date($borrower->{dateexpiry}),
256 flagged => "1",);
257 if (C4::Context->preference('ReturnBeforeExpiry')){
258 $template->param("returnbeforeexpiry" => 1);
261 $template->param(
262 overduecount => $od,
263 issuecount => $issue,
264 finetotal => $fines
267 my $debar = CheckBorrowerDebarred($borrowernumber);
268 if ($debar) {
269 $template->param( 'userdebarred' => 1 );
270 $template->param( 'debarredcomment' => $borrower->{debarredcomment} );
271 if ( $debar ne "9999-12-31" ) {
272 $template->param( 'userdebarreddate' => C4::Dates::format_date($debar) );
279 # STEP 3 : ISSUING
282 if ($barcode) {
283 # always check for blockers on issuing
284 my ( $error, $question, $alerts ) =
285 CanBookBeIssued( $borrower, $barcode, $datedue , $inprocess );
286 my $blocker = $invalidduedate ? 1 : 0;
288 $template->param( alert => $alerts );
290 delete $question->{'DEBT'} if ($debt_confirmed);
291 foreach my $impossible ( keys %$error ) {
292 $template->param(
293 $impossible => $$error{$impossible},
294 IMPOSSIBLE => 1
296 $blocker = 1;
298 if( !$blocker ){
299 my $confirm_required = 0;
300 unless($issueconfirmed){
301 # Get the item title for more information
302 my $getmessageiteminfo = GetBiblioFromItemNumber(undef,$barcode);
303 $template->{VARS}->{'additional_materials'} = $getmessageiteminfo->{'materials'};
304 $template->param( itemhomebranch => $getmessageiteminfo->{'homebranch'} );
306 # pass needsconfirmation to template if issuing is possible and user hasn't yet confirmed.
307 foreach my $needsconfirmation ( keys %$question ) {
308 $template->param(
309 $needsconfirmation => $$question{$needsconfirmation},
310 getTitleMessageIteminfo => $getmessageiteminfo->{'title'},
311 getBarcodeMessageIteminfo => $getmessageiteminfo->{'barcode'},
312 NEEDSCONFIRMATION => 1
314 $confirm_required = 1;
317 unless($confirm_required) {
318 AddIssue( $borrower, $barcode, $datedue, $cancelreserve );
319 $inprocess = 1;
323 # FIXME If the issue is confirmed, we launch another time GetMemberIssuesAndFines, now display the issue count after issue
324 my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrowernumber );
325 $template->param( issuecount => $issue );
328 # reload the borrower info for the sake of reseting the flags.....
329 if ($borrowernumber) {
330 $borrower = GetMemberDetails( $borrowernumber, 0 );
333 ##################################################################################
334 # BUILD HTML
335 # show all reserves of this borrower, and the position of the reservation ....
336 if ($borrowernumber) {
338 # new op dev
339 # now we show the status of the borrower's reservations
340 my @borrowerreserv = GetReservesFromBorrowernumber($borrowernumber );
341 my @reservloop;
342 my @WaitingReserveLoop;
344 foreach my $num_res (@borrowerreserv) {
345 my %getreserv;
346 my %getWaitingReserveInfo;
347 my $getiteminfo = GetBiblioFromItemNumber( $num_res->{'itemnumber'} );
348 my $itemtypeinfo = getitemtypeinfo( (C4::Context->preference('item-level_itypes')) ? $getiteminfo->{'itype'} : $getiteminfo->{'itemtype'} );
349 my ( $transfertwhen, $transfertfrom, $transfertto ) =
350 GetTransfers( $num_res->{'itemnumber'} );
352 $getreserv{waiting} = 0;
353 $getreserv{transfered} = 0;
354 $getreserv{nottransfered} = 0;
356 $getreserv{reservedate} = format_date( $num_res->{'reservedate'} );
357 $getreserv{reservenumber} = $num_res->{'reservenumber'};
358 $getreserv{title} = $getiteminfo->{'title'};
359 $getreserv{itemtype} = $itemtypeinfo->{'description'};
360 $getreserv{author} = $getiteminfo->{'author'};
361 $getreserv{barcodereserv} = $getiteminfo->{'barcode'};
362 $getreserv{itemcallnumber} = $getiteminfo->{'itemcallnumber'};
363 $getreserv{biblionumber} = $getiteminfo->{'biblionumber'};
364 $getreserv{waitingat} = GetBranchName( $num_res->{'branchcode'} );
365 $getreserv{suspend} = $num_res->{'suspend'};
366 $getreserv{suspend_until} = $num_res->{'suspend_until'};
367 # check if we have a waiting status for reservations
368 if ( $num_res->{'found'} eq 'W' ) {
369 $getreserv{color} = 'reserved';
370 $getreserv{waiting} = 1;
371 # genarate information displaying only waiting reserves
372 $getWaitingReserveInfo{title} = $getiteminfo->{'title'};
373 $getWaitingReserveInfo{biblionumber} = $getiteminfo->{'biblionumber'};
374 $getWaitingReserveInfo{itemtype} = $itemtypeinfo->{'description'};
375 $getWaitingReserveInfo{author} = $getiteminfo->{'author'};
376 $getWaitingReserveInfo{reservedate} = format_date( $num_res->{'reservedate'} );
377 $getWaitingReserveInfo{waitingat} = GetBranchName( $num_res->{'branchcode'} );
378 $getWaitingReserveInfo{waitinghere} = 1 if $num_res->{'branchcode'} eq $branch;
380 # check transfers with the itemnumber foud in th reservation loop
381 if ($transfertwhen) {
382 $getreserv{color} = 'transfered';
383 $getreserv{transfered} = 1;
384 $getreserv{datesent} = format_date($transfertwhen);
385 $getreserv{frombranch} = GetBranchName($transfertfrom);
386 } elsif ($getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'}) {
387 $getreserv{nottransfered} = 1;
388 $getreserv{nottransferedby} = GetBranchName( $getiteminfo->{'holdingbranch'} );
391 # if we don't have a reserv on item, we put the biblio infos and the waiting position
392 if ( $getiteminfo->{'title'} eq '' ) {
393 my $getbibinfo = GetBiblioData( $num_res->{'biblionumber'} );
395 $getreserv{color} = 'inwait';
396 $getreserv{title} = $getbibinfo->{'title'};
397 $getreserv{nottransfered} = 0;
398 $getreserv{itemtype} = $itemtypeinfo->{'description'};
399 $getreserv{author} = $getbibinfo->{'author'};
400 $getreserv{biblionumber} = $num_res->{'biblionumber'};
402 $getreserv{waitingposition} = $num_res->{'priority'};
403 push( @reservloop, \%getreserv );
405 # if we have a reserve waiting, initiate waitingreserveloop
406 if ($getreserv{waiting} == 1) {
407 push (@WaitingReserveLoop, \%getWaitingReserveInfo)
412 # return result to the template
413 $template->param(
414 countreserv => scalar @reservloop,
415 reservloop => \@reservloop ,
416 WaitingReserveLoop => \@WaitingReserveLoop,
418 $template->param( adultborrower => 1 ) if ( $borrower->{'category_type'} eq 'A' );
421 # make the issued books table.
422 my $todaysissues = '';
423 my $previssues = '';
424 our @todaysissues = ();
425 our @previousissues = ();
426 our @relissues = ();
427 our @relprevissues = ();
428 my $displayrelissues;
430 our $totalprice = 0;
432 sub build_issue_data {
433 my $issueslist = shift;
434 my $relatives = shift;
436 # split in 2 arrays for today & previous
437 foreach my $it ( @$issueslist ) {
438 my $itemtypeinfo = getitemtypeinfo( (C4::Context->preference('item-level_itypes')) ? $it->{'itype'} : $it->{'itemtype'} );
440 # set itemtype per item-level_itype syspref - FIXME this is an ugly hack
441 $it->{'itemtype'} = ( C4::Context->preference( 'item-level_itypes' ) ) ? $it->{'itype'} : $it->{'itemtype'};
443 ($it->{'charge'}, $it->{'itemtype_charge'}) = GetIssuingCharges(
444 $it->{'itemnumber'}, $it->{'borrowernumber'}
446 $it->{'charge'} = sprintf("%.2f", $it->{'charge'});
447 my ($can_renew, $can_renew_error) = CanBookBeRenewed(
448 $it->{'borrowernumber'},$it->{'itemnumber'}
450 $it->{"renew_error_${can_renew_error}"} = 1 if defined $can_renew_error;
451 my ( $restype, $reserves, undef ) = CheckReserves( $it->{'itemnumber'} );
452 $it->{'can_renew'} = $can_renew;
453 $it->{'can_confirm'} = !$can_renew && !$restype;
454 $it->{'renew_error'} = $restype;
455 $it->{'checkoutdate'} = C4::Dates->new($it->{'issuedate'},'iso')->output('syspref');
456 $it->{'issuingbranchname'} = GetBranchName($it->{'branchcode'});
458 $totalprice += $it->{'replacementprice'};
459 $it->{'itemtype'} = $itemtypeinfo->{'description'};
460 $it->{'itemtype_image'} = $itemtypeinfo->{'imageurl'};
461 $it->{'dd'} = output_pref($it->{'date_due'});
462 $it->{'displaydate'} = output_pref($it->{'issuedate'});
463 #$it->{'od'} = ( $it->{'date_due'} lt $todaysdate ) ? 1 : 0 ;
464 $it->{'od'} = $it->{'overdue'};
465 ($it->{'author'} eq '') and $it->{'author'} = ' ';
466 $it->{'renew_failed'} = $renew_failed{$it->{'itemnumber'}};
467 $it->{'return_failed'} = $return_failed{$it->{'barcode'}};
469 if ( $it->{'issuedate'} gt $todaysdate or $it->{'lastreneweddate'} gt $todaysdate ) {
470 (!$relatives) ? push @todaysissues, $it : push @relissues, $it;
471 } else {
472 (!$relatives) ? push @previousissues, $it : push @relprevissues, $it;
477 if ($borrower) {
479 # Getting borrower relatives
480 my @relborrowernumbers = GetMemberRelatives($borrower->{'borrowernumber'});
481 #push @borrowernumbers, $borrower->{'borrowernumber'};
483 # get each issue of the borrower & separate them in todayissues & previous issues
484 my $issueslist = GetPendingIssues($borrower->{'borrowernumber'});
485 my $relissueslist = [];
486 if ( @relborrowernumbers ) {
487 $relissueslist = GetPendingIssues(@relborrowernumbers);
490 build_issue_data($issueslist, 0);
491 build_issue_data($relissueslist, 1);
493 $displayrelissues = scalar($relissueslist);
495 if ( C4::Context->preference( "todaysIssuesDefaultSortOrder" ) eq 'asc' ) {
496 @todaysissues = sort { $a->{'timestamp'} cmp $b->{'timestamp'} } @todaysissues;
498 else {
499 @todaysissues = sort { $b->{'timestamp'} cmp $a->{'timestamp'} } @todaysissues;
502 if ( C4::Context->preference( "previousIssuesDefaultSortOrder" ) eq 'asc' ){
503 @previousissues = sort { $a->{'date_due'} cmp $b->{'date_due'} } @previousissues;
505 else {
506 @previousissues = sort { $b->{'date_due'} cmp $a->{'date_due'} } @previousissues;
511 my @values;
512 my %labels;
513 my $CGIselectborrower;
514 if ($borrowerslist) {
515 foreach (
516 sort {(lc $a->{'surname'} cmp lc $b->{'surname'} || lc $a->{'firstname'} cmp lc $b->{'firstname'})
517 } @$borrowerslist
520 push @values, $_->{'borrowernumber'};
521 $labels{ $_->{'borrowernumber'} } =
522 "$_->{'surname'}, $_->{'firstname'} ... ($_->{'cardnumber'} - $_->{'categorycode'} - $_->{'branchcode'}) ... $_->{'address'} ";
524 $CGIselectborrower = CGI::scrolling_list(
525 -name => 'borrowernumber',
526 -class => 'focus',
527 -id => 'borrowernumber',
528 -values => \@values,
529 -labels => \%labels,
530 -ondblclick => 'document.forms[\'mainform\'].submit()',
531 -size => 7,
532 -tabindex => '',
533 -multiple => 0
537 #title
538 my $flags = $borrower->{'flags'};
539 foreach my $flag ( sort keys %$flags ) {
540 $template->param( flagged=> 1);
541 $flags->{$flag}->{'message'} =~ s#\n#<br />#g;
542 if ( $flags->{$flag}->{'noissues'} ) {
543 $template->param(
544 flagged => 1,
545 noissues => 'true',
547 if ( $flag eq 'GNA' ) {
548 $template->param( gna => 'true' );
550 elsif ( $flag eq 'LOST' ) {
551 $template->param( lost => 'true' );
553 elsif ( $flag eq 'DBARRED' ) {
554 $template->param( dbarred => 'true' );
556 elsif ( $flag eq 'CHARGES' ) {
557 $template->param(
558 charges => 'true',
559 chargesmsg => $flags->{'CHARGES'}->{'message'},
560 chargesamount => $flags->{'CHARGES'}->{'amount'},
561 charges_is_blocker => 1
564 elsif ( $flag eq 'CREDITS' ) {
565 $template->param(
566 credits => 'true',
567 creditsmsg => $flags->{'CREDITS'}->{'message'},
568 creditsamount => sprintf("%.02f", -($flags->{'CREDITS'}->{'amount'})), # from patron's pov
572 else {
573 if ( $flag eq 'CHARGES' ) {
574 $template->param(
575 charges => 'true',
576 flagged => 1,
577 chargesmsg => $flags->{'CHARGES'}->{'message'},
578 chargesamount => $flags->{'CHARGES'}->{'amount'},
581 elsif ( $flag eq 'CREDITS' ) {
582 $template->param(
583 credits => 'true',
584 creditsmsg => $flags->{'CREDITS'}->{'message'},
585 creditsamount => sprintf("%.02f", -($flags->{'CREDITS'}->{'amount'})), # from patron's pov
588 elsif ( $flag eq 'ODUES' ) {
589 $template->param(
590 odues => 'true',
591 flagged => 1,
592 oduesmsg => $flags->{'ODUES'}->{'message'}
595 my $items = $flags->{$flag}->{'itemlist'};
596 if ( ! $query->param('module') || $query->param('module') ne 'returns' ) {
597 $template->param( nonreturns => 'true' );
600 elsif ( $flag eq 'NOTES' ) {
601 $template->param(
602 notes => 'true',
603 flagged => 1,
604 notesmsg => $flags->{'NOTES'}->{'message'}
610 my $amountold = $borrower->{flags}->{'CHARGES'}->{'message'} || 0;
611 $amountold =~ s/^.*\$//; # remove upto the $, if any
613 my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
615 if ( $borrower->{'category_type'} eq 'C') {
616 my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
617 my $cnt = scalar(@$catcodes);
618 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
619 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
622 my $CGIorganisations;
623 my $member_of_institution;
624 if ( C4::Context->preference("memberofinstitution") ) {
625 my $organisations = get_institutions();
626 my @orgs;
627 my %org_labels;
628 foreach my $organisation ( keys %$organisations ) {
629 push @orgs, $organisation;
630 $org_labels{$organisation} = $organisations->{$organisation}->{'surname'};
632 $member_of_institution = 1;
633 $CGIorganisations = CGI::popup_menu(
634 -id => 'organisations',
635 -name => 'organisations',
636 -labels => \%org_labels,
637 -values => \@orgs,
641 my $lib_messages_loop = GetMessages( $borrowernumber, 'L', $branch );
642 if($lib_messages_loop){ $template->param(flagged => 1 ); }
644 my $bor_messages_loop = GetMessages( $borrowernumber, 'B', $branch );
645 if($bor_messages_loop){ $template->param(flagged => 1 ); }
647 # Computes full borrower address
648 my (undef, $roadttype_hashref) = &GetRoadTypes();
649 my $address = $borrower->{'streetnumber'}.' '.$roadttype_hashref->{$borrower->{'streettype'}}.' '.$borrower->{'address'};
651 my $fast_cataloging = 0;
652 if (defined getframeworkinfo('FA')) {
653 $fast_cataloging = 1
656 if (C4::Context->preference('ExtendedPatronAttributes')) {
657 my $attributes = GetBorrowerAttributes($borrowernumber);
658 $template->param(
659 ExtendedPatronAttributes => 1,
660 extendedattributes => $attributes
664 $template->param(
665 lib_messages_loop => $lib_messages_loop,
666 bor_messages_loop => $bor_messages_loop,
667 all_messages_del => C4::Context->preference('AllowAllMessageDeletion'),
668 findborrower => $findborrower,
669 borrower => $borrower,
670 borrowernumber => $borrowernumber,
671 branch => $branch,
672 branchname => GetBranchName($borrower->{'branchcode'}),
673 printer => $printer,
674 printername => $printer,
675 firstname => $borrower->{'firstname'},
676 surname => $borrower->{'surname'},
677 showname => $borrower->{'showname'},
678 category_type => $borrower->{'category_type'},
679 dateexpiry => format_date($newexpiry),
680 expiry => format_date($borrower->{'dateexpiry'}),
681 categorycode => $borrower->{'categorycode'},
682 categoryname => $borrower->{description},
683 address => $address,
684 address2 => $borrower->{'address2'},
685 email => $borrower->{'email'},
686 emailpro => $borrower->{'emailpro'},
687 borrowernotes => $borrower->{'borrowernotes'},
688 city => $borrower->{'city'},
689 state => $borrower->{'state'},
690 zipcode => $borrower->{'zipcode'},
691 country => $borrower->{'country'},
692 phone => $borrower->{'phone'} || $borrower->{'mobile'},
693 cardnumber => $borrower->{'cardnumber'},
694 othernames => $borrower->{'othernames'},
695 amountold => $amountold,
696 barcode => $barcode,
697 stickyduedate => $stickyduedate,
698 duedatespec => $duedatespec,
699 message => $message,
700 CGIselectborrower => $CGIselectborrower,
701 totalprice => sprintf('%.2f', $totalprice),
702 totaldue => sprintf('%.2f', $total),
703 todayissues => \@todaysissues,
704 previssues => \@previousissues,
705 relissues => \@relissues,
706 relprevissues => \@relprevissues,
707 displayrelissues => $displayrelissues,
708 inprocess => $inprocess,
709 memberofinstution => $member_of_institution,
710 CGIorganisations => $CGIorganisations,
711 is_child => ($borrower->{'category_type'} eq 'C'),
712 circview => 1,
713 soundon => C4::Context->preference("SoundOn"),
714 fast_cataloging => $fast_cataloging,
715 CircAutoPrintQuickSlip => C4::Context->preference("CircAutoPrintQuickSlip"),
716 activeBorrowerRelationship => (C4::Context->preference('borrowerRelationship') ne ''),
717 SuspendHoldsIntranet => C4::Context->preference('SuspendHoldsIntranet'),
718 AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
721 # save stickyduedate to session
722 if ($stickyduedate) {
723 $session->param( 'stickyduedate', $duedatespec );
726 my ($picture, $dberror) = GetPatronImage($borrower->{'cardnumber'});
727 $template->param( picture => 1 ) if $picture;
729 # get authorised values with type of BOR_NOTES
731 my $canned_notes = GetAuthorisedValues("BOR_NOTES");
733 $template->param(
734 debt_confirmed => $debt_confirmed,
735 SpecifyDueDate => $duedatespec_allow,
736 CircAutocompl => C4::Context->preference("CircAutocompl"),
737 AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"),
738 dateformat => C4::Context->preference("dateformat"),
739 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
740 export_remove_fields => C4::Context->preference("ExportRemoveFields"),
741 export_with_csv_profile => C4::Context->preference("ExportWithCsvProfile"),
742 canned_bor_notes_loop => $canned_notes,
745 output_html_with_http_headers $query, $cookie, $template->output;