C4/External/BakerTaylor.pm - Back end for B&T content.
[koha.git] / circ / circulation.pl
1 #!/usr/bin/perl
2
3 # Please use 8-character tabs for this file (indents are every 4 characters)
4
5 # written 8/5/2002 by Finlay
6 # script to execute issuing of books
7
8 # Copyright 2000-2002 Katipo Communications
9 #
10 # This file is part of Koha.
11 #
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
15 # version.
16 #
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA  02111-1307 USA
24
25 use strict;
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::Members;
35 use C4::Biblio;
36 use C4::Reserves;
37 use C4::Context;
38 use CGI::Session;
39
40 use Date::Calc qw(
41   Today
42   Today_and_Now
43   Add_Delta_YM
44   Add_Delta_Days
45   Date_to_Days
46 );
47
48
49 #
50 # PARAMETERS READING
51 #
52 my $query = new CGI;
53
54 # new op dev the branch and the printer are now defined by the userenv
55 # but first we have to check if someone has tried to change them
56
57 my $branch = $query->param('branch');
58 if ($branch){
59     # update our session so the userenv is updated
60     my $dbh=C4::Context->dbh;
61     my $sessionID = $query->cookie("CGISESSID") ;
62     my $session = get_session($sessionID);
63     $session->param('branch',$branch);
64     my $branchname = GetBranchName($branch);
65     $session->param('branchname',$branchname);
66 }
67
68 my $printer = $query->param('printer');
69 if ($printer){
70     # update our session so the userenv is updated
71         my $dbh=C4::Context->dbh;
72         my $sessionID = $query->cookie("CGISESSID") ;
73         my $session = get_session($sessionID);
74         $session->param('branchprinter',$printer);
75
76 }
77 if (!C4::Context->userenv && !$branch){
78         my $sessionID = $query->cookie("CGISESSID") ;
79         my $session = get_session($sessionID);
80         if ($session->param('branch') eq 'NO_LIBRARY_SET'){
81                 # no branch set we can't issue
82                 print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
83                 exit;
84         }
85 }
86
87 my ( $template, $loggedinuser, $cookie ) = get_template_and_user (
88     {
89         template_name   => 'circ/circulation.tmpl',
90         query           => $query,
91         type            => "intranet",
92         authnotrequired => 0,
93         flagsrequired   => { circulate => 1 },
94     }
95 );
96 my $branches = GetBranches();
97
98 my $printers = GetPrinters();
99
100 my @failedrenews = $query->param('failedrenew');
101 my @renew_failed;
102 for (@failedrenews) { $renew_failed[$_] = 1; } 
103
104 my $findborrower = $query->param('findborrower');
105 $findborrower =~ s|,| |g;
106 #$findborrower =~ s|'| |g;
107 my $borrowernumber = $query->param('borrowernumber');
108
109 $branch  = C4::Context->userenv->{'branch'};    
110 $printer = C4::Context->userenv->{'branchprinter'};
111
112
113 # If Autolocated is not activated, we show the Circulation Parameters to chage settings of librarian
114     if (C4::Context->preference("AutoLocation") ne 1)
115         {
116             $template->param(
117             ManualLocation => 1,
118             );
119         }
120
121 my $barcode        = $query->param('barcode') || '';
122
123 $barcode = barcodedecode($barcode) if(C4::Context->preference('itemBarcodeInputFilter'));
124 my $year           = $query->param('year');
125 my $month          = $query->param('month');
126 my $day            = $query->param('day');
127 my $stickyduedate  = $query->param('stickyduedate');
128 my $duedatespec    = $query->param('duedatespec');
129 my $issueconfirmed = $query->param('issueconfirmed');
130 my $cancelreserve  = $query->param('cancelreserve');
131 my $organisation   = $query->param('organisations');
132 my $print          = $query->param('print');
133 my $newexpiry = $query->param('dateexpiry');
134
135 #set up cookie.....
136 # my $branchcookie;
137 # my $printercookie;
138 # if ($query->param('setcookies')) {
139 #     $branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
140 #     $printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
141 # }
142 #
143
144 my ($datedue,$invalidduedate);
145 if ($duedatespec) {
146         $datedue =  C4::Dates->new($duedatespec);
147         $invalidduedate=1 unless $datedue;
148 }
149
150 #if (defined($year)) {
151 #        $duedatespec = "$year-$month-$day";
152 #} else {
153 #        ($year, $month, $day) = ($duedatespec) ? split /-/, $duedatespec : (0,0,0);
154 #}
155
156 my $todaysdate     = sprintf("%-04.4d%-02.2d%-02.2d", Today());
157
158 # check and see if we should print
159 if ( $barcode eq '' && $print eq 'maybe' ) {
160     $print = 'yes';
161 }
162
163 my $inprocess = ($barcode eq '') ? '' : $query->param('inprocess');
164
165 if ( $barcode eq '' && $query->param('charges') eq 'yes' ) {
166     $template->param(
167         PAYCHARGES     => 'yes',
168         borrowernumber => $borrowernumber
169     );
170 }
171
172 if ( $print eq 'yes' && $borrowernumber ne '' ) {
173     printslip( $borrowernumber );
174     $query->param( 'borrowernumber', '' );
175     $borrowernumber = '';
176 }
177
178 #
179 # STEP 2 : FIND BORROWER
180 # if there is a list of find borrowers....
181 #
182 my $borrowerslist;
183 my $message;
184 if ($findborrower) {
185     my ( $count, $borrowers ) =
186       SearchMember($findborrower, 'cardnumber', 'web' );
187     my @borrowers = @$borrowers;
188     if ( $#borrowers == -1 ) {
189         $query->param( 'findborrower', '' );
190         $message = "'$findborrower'";
191     }
192     elsif ( $#borrowers == 0 ) {
193         $query->param( 'borrowernumber', $borrowers[0]->{'borrowernumber'} );
194         $query->param( 'barcode',           '' );
195         $borrowernumber = $borrowers[0]->{'borrowernumber'};
196     }
197     else {
198         $borrowerslist = \@borrowers;
199     }
200 }
201
202 # get the borrower information.....
203 my $borrower;
204 my @lines;
205 if ($borrowernumber) {
206     $borrower = GetMemberDetails( $borrowernumber, 0 );
207     my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrowernumber );
208
209     # Warningdate is the date that the warning starts appearing
210     my ( $today_year,   $today_month,   $today_day )   = Today();
211     my ( $warning_year, $warning_month, $warning_day ) = split /-/,
212       $borrower->{'dateexpiry'};
213     my ( $enrol_year, $enrol_month, $enrol_day ) = split /-/,
214       $borrower->{'dateenrolled'};
215     # Renew day is calculated by adding the enrolment period to today
216     my ( $renew_year, $renew_month, $renew_day ) =
217       Add_Delta_YM( $enrol_year, $enrol_month, $enrol_day,
218         0 , $borrower->{'enrolmentperiod'}) if ($enrol_year*$enrol_month*$enrol_day>0);
219     # if the expiry date is before today ie they have expired
220     if ( $warning_year*$warning_month*$warning_day==0 
221       || Date_to_Days( $today_year, $today_month, $today_day ) 
222          > Date_to_Days( $warning_year, $warning_month, $warning_day ) )
223     {
224         #borrowercard expired, no issues
225         $template->param(
226                         flagged => "1",
227             noissues       => "1",
228             expired => format_date($borrower->{dateexpiry}),
229             renewaldate   => format_date("$renew_year-$renew_month-$renew_day")
230         );
231     }
232     # check for NotifyBorrowerDeparture
233         elsif ( C4::Context->preference('NotifyBorrowerDeparture') &&
234                 Date_to_Days(Add_Delta_Days($warning_year,$warning_month,$warning_day,- C4::Context->preference('NotifyBorrowerDeparture'))) <
235                 Date_to_Days( $today_year, $today_month, $today_day ) ) 
236         {
237                 # borrower card soon to expire warn librarian
238                 $template->param("warndeparture" => format_date($borrower->{dateexpiry}),
239                         flagged       => "1",);
240                 if ( C4::Context->preference('ReturnBeforeExpiry')){
241                         $template->param("returnbeforeexpiry" => 1);
242                 }
243         }
244     $template->param(
245         overduecount => $od,
246         issuecount   => $issue,
247         finetotal    => $fines
248     );
249 }
250
251 #
252 # STEP 3 : ISSUING
253 #
254 #
255
256 if ($barcode) {
257         # always check for blockers on issuing
258         my ( $error, $question ) =
259           CanBookBeIssued( $borrower, $barcode, $datedue , $inprocess );
260         my $noerror    = 1;
261         foreach my $impossible ( keys %$error ) {
262             $template->param(
263                 $impossible => $$error{$impossible},
264                 IMPOSSIBLE  => 1
265             );
266             $noerror = 0;
267         }
268     
269         if ($issueconfirmed && $noerror) {
270                 # we have no blockers for issuing and any issues needing confirmation have been resolved
271         AddIssue( $borrower, $barcode, $datedue, $cancelreserve );
272         $inprocess = 1;
273     }
274         elsif ($issueconfirmed){
275         }
276     else {
277         my $noquestion = 1;
278 #         Get the item title for more information
279         my $getmessageiteminfo  = GetBiblioFromItemNumber(undef,$barcode);
280     
281         foreach my $needsconfirmation ( keys %$question ) {
282             $template->param(
283                 $needsconfirmation => $$question{$needsconfirmation},
284                 getTitleMessageIteminfo => $getmessageiteminfo->{'title'},
285                 NEEDSCONFIRMATION  => 1
286             );
287             $noquestion = 0;
288         }
289         $template->param(
290                          itemhomebranch => $getmessageiteminfo->{'homebranch'} ,                     
291                          duedatespec => $duedatespec,
292         );
293         if ( $noerror && ( $noquestion || $issueconfirmed ) ) {
294             AddIssue( $borrower, $barcode, $datedue );
295             $inprocess = 1;
296         }
297     }
298     
299 # FIXME If the issue is confirmed, we launch another time borrdata2, now display the issue count after issue 
300         my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrowernumber );
301         $template->param(
302         issuecount   => $issue,
303         );
304 }
305
306 # reload the borrower info for the sake of reseting the flags.....
307 if ($borrowernumber) {
308     $borrower = GetMemberDetails( $borrowernumber, 0 );
309 }
310
311 ##################################################################################
312 # BUILD HTML
313 # show all reserves of this borrower, and the position of the reservation ....
314 if ($borrowernumber) {
315
316     # new op dev
317     # now we show the status of the borrower's reservations
318     my @borrowerreserv = GetReservesFromBorrowernumber($borrowernumber );
319     my @reservloop;
320     my @WaitingReserveLoop;
321     
322     foreach my $num_res (@borrowerreserv) {
323         my %getreserv;
324         my %getWaitingReserveInfo;
325         my $getiteminfo  = GetBiblioFromItemNumber( $num_res->{'itemnumber'} );
326         my $itemtypeinfo = getitemtypeinfo( (C4::Context->preference('item-level_itypes')) ? $getiteminfo->{'itype'} : $getiteminfo->{'itemtype'} );
327         my ( $transfertwhen, $transfertfrom, $transfertto ) =
328           GetTransfers( $num_res->{'itemnumber'} );
329
330         $getreserv{waiting}       = 0;
331         $getreserv{transfered}    = 0;
332         $getreserv{nottransfered} = 0;
333
334         $getreserv{reservedate}    = format_date( $num_res->{'reservedate'} );
335         $getreserv{title}          = $getiteminfo->{'title'};
336         $getreserv{itemtype}       = $itemtypeinfo->{'description'};
337         $getreserv{author}         = $getiteminfo->{'author'};
338         $getreserv{barcodereserv}  = $getiteminfo->{'barcode'};
339         $getreserv{itemcallnumber} = $getiteminfo->{'itemcallnumber'};
340                 $getreserv{biblionumber}   = $getiteminfo->{'biblionumber'};
341                 $getreserv{waitingat}    = GetBranchName( $num_res->{'branchcode'} );
342         #         check if we have a waiting status for reservations
343         if ( $num_res->{'found'} eq 'W' ) {
344             $getreserv{color}   = 'reserved';
345             $getreserv{waiting} = 1;
346 #     genarate information displaying only waiting reserves
347         $getWaitingReserveInfo{title}        = $getiteminfo->{'title'};
348         $getWaitingReserveInfo{biblionumber}   = $getiteminfo->{'biblionumber'};
349         $getWaitingReserveInfo{itemtype}    = $itemtypeinfo->{'description'};
350         $getWaitingReserveInfo{author}        = $getiteminfo->{'author'};
351         $getWaitingReserveInfo{reservedate}    = format_date( $num_res->{'reservedate'} );
352         $getWaitingReserveInfo{waitingat}    = GetBranchName( $num_res->{'branchcode'} );
353         if($num_res->{'branchcode'} eq $branch){ $getWaitingReserveInfo{waitinghere} = 1; }
354         }
355         #         check transfers with the itemnumber foud in th reservation loop
356         if ($transfertwhen) {
357             $getreserv{color}      = 'transfered';
358             $getreserv{transfered} = 1;
359             $getreserv{datesent}   = format_date($transfertwhen);
360             $getreserv{frombranch} = GetBranchName($transfertfrom);
361         }
362
363         if ( ( $getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'} )
364             and not $transfertwhen )
365         {
366             $getreserv{nottransfered}   = 1;
367             $getreserv{nottransferedby} =
368               GetBranchName( $getiteminfo->{'holdingbranch'} );
369         }
370
371 #         if we don't have a reserv on item, we put the biblio infos and the waiting position
372         if ( $getiteminfo->{'title'} eq '' ) {
373             my $getbibinfo = GetBiblioData( $num_res->{'biblionumber'} );
374             my $getbibtype = getitemtypeinfo( $getbibinfo->{'itemtype'} );  # fixme - we should have item-level reserves here ?
375             $getreserv{color}           = 'inwait';
376             $getreserv{title}           = $getbibinfo->{'title'};
377             $getreserv{waitingposition} = $num_res->{'priority'};
378             $getreserv{nottransfered}   = 0;
379             $getreserv{itemtype}        = $getbibtype->{'description'};
380             $getreserv{author}          = $getbibinfo->{'author'};
381                 $getreserv{biblionumber}    = $num_res->{'biblionumber'};
382         }
383         push( @reservloop, \%getreserv );
384
385 #         if we have a reserve waiting, initiate waitingreserveloop
386         if ($getreserv{waiting} eq 1) {
387         push (@WaitingReserveLoop, \%getWaitingReserveInfo)
388         }
389       
390     }
391
392     # return result to the template
393     $template->param( 
394         countreserv => scalar @reservloop,
395         reservloop  => \@reservloop ,
396         WaitingReserveLoop  => \@WaitingReserveLoop,
397     );
398 }
399
400 # make the issued books table.
401 my $todaysissues = '';
402 my $previssues   = '';
403 my @todaysissues;
404 my @previousissues;
405 my $allowborrow;
406 ## ADDED BY JF: new itemtype issuingrules counter stuff
407 my $issued_itemtypes_loop;
408 my $issued_itemtypes_count;
409 my $issued_itemtypes_allowed_count;    # hashref with total allowed by itemtype
410 my $issued_itemtypes_remaining;        # hashref with remaining
411 my $issued_itemtypes_flags;            #hashref that stores flags
412 my @issued_itemtypes_count_loop;
413
414 if ($borrower) {
415
416 # get each issue of the borrower & separate them in todayissues & previous issues
417     my ($countissues,$issueslist) = GetPendingIssues($borrower->{'borrowernumber'});
418
419     # split in 2 arrays for today & previous
420     foreach my $it ( @$issueslist ) {
421         # set itemtype per item-level_itype syspref - FIXME this is an ugly hack
422         $it->{'itemtype'} = (C4::Context->preference('item-level_itypes')) ? $it->{'itype'} : $it->{'itemtype'};
423
424         my $issuedate = $it->{'issuedate'};
425         $issuedate =~ s/-//g;
426         $issuedate = substr( $issuedate, 0, 8 );
427                 ($it->{'charge'}, $it->{'itemtype_charge'}) = GetIssuingCharges(
428                                                 $it->{'itemnumber'}, $borrower->{'borrowernumber'}
429                 );
430                 $it->{'charge'} = sprintf("%.2f", $it->{'charge'});
431         my $can_renew_error;
432         ($it->{'can_renew'}, $can_renew_error) = CanBookBeRenewed( 
433                                                 $borrower->{'borrowernumber'},$it->{'itemnumber'}
434                 );
435         $it->{"renew_error_${can_renew_error}"} = 1 if defined $can_renew_error;
436                 my ($restype, $reserves) = CheckReserves($it->{'itemnumber'});
437                 ($restype) and $it->{'can_renew'} = 0;
438
439                 $it->{'dd'} = format_date($it->{'date_due'});
440         my $datedue = $it->{'date_due'};
441         $datedue =~ s/-//g;
442                 $it->{'od'} = ($datedue < $todaysdate) ? 1 : 0 ;
443         ($it->{'author'} eq '') and $it->{'author'} = ' ';
444         $it->{'renew_failed'} = $renew_failed[$it->{'itemnumber'}];
445         # ADDED BY JF: NEW ITEMTYPE COUNT DISPLAY
446         $issued_itemtypes_count->{ $it->{'itemtype'} }++;
447
448         if ( $todaysdate == $issuedate ) {
449             push @todaysissues, $it;
450         } else {
451             push @previousissues, $it;
452         }
453     }
454         if (C4::Context->preference("todaysIssuesDefaultSortOrder") eq 'asc'){
455                 @todaysissues   = sort { $a->{'timestamp'} cmp $b->{'timestamp'} } @todaysissues;
456         }
457         else {
458                 @todaysissues   = sort { $b->{'timestamp'} cmp $a->{'timestamp'} } @todaysissues;
459         }
460         if (C4::Context->preference("previousIssuesDefaultSortOrder") eq 'asc'){
461                 @previousissues = sort { $a->{'date_due' } cmp $b->{'date_due' } } @previousissues;
462         }
463         else {
464                 @previousissues = sort { $b->{'date_due' } cmp $a->{'date_due' } } @previousissues;
465         }
466     my $i = 1;
467         foreach my $book (@todaysissues) {
468         $book->{'togglecolor'} = (++$i % 2) ? 0 : 1 ;
469     }
470     $i = 1;
471         foreach my $book (@previousissues) {
472         $book->{'togglecolor'} = (++$i % 2) ? 0 : 1 ;
473     }
474 }
475
476 #### ADDED BY JF FOR COUNTS BY ITEMTYPE RULES
477 # FIXME: This should utilize all the issuingrules options rather than just the defaults
478 # and it should be moved to a module
479 my $dbh = C4::Context->dbh;
480
481 # how many of each is allowed?
482 my $issueqty_sth = $dbh->prepare( "
483 SELECT itemtypes.description AS description,issuingrules.itemtype,maxissueqty
484 FROM issuingrules
485   LEFT JOIN itemtypes ON (itemtypes.itemtype=issuingrules.itemtype)
486   WHERE categorycode=?
487 " );
488 #my @issued_itemtypes_count;  # huh?
489 $issueqty_sth->execute("*");
490
491 while ( my $data = $issueqty_sth->fetchrow_hashref() ) {
492
493     # subtract how many of each this borrower has
494     $data->{'count'} = $issued_itemtypes_count->{ $data->{'description'} };  
495     $data->{'left'}  =
496       ( $data->{'maxissueqty'} -
497           $issued_itemtypes_count->{ $data->{'description'} } );
498
499     # can't have a negative number of remaining
500     if ( $data->{'left'} < 0 ) { $data->{'left'} = "0" }
501     $data->{'flag'} = 1 unless ( $data->{'maxissueqty'} > $data->{'count'} );
502     unless ( ( $data->{'maxissueqty'} < 1 )
503         || ( $data->{'itemtype'} eq "*" )
504         || ( $data->{'itemtype'} eq "CIRC" ) )
505     {
506         push @issued_itemtypes_count_loop, $data;
507     }
508 }
509 $issued_itemtypes_loop = \@issued_itemtypes_count_loop;
510
511 #### / JF
512
513 my @values;
514 my %labels;
515 my $CGIselectborrower;
516 if ($borrowerslist) {
517     foreach (
518         sort {
519                 lc $a->{'surname'}
520               . lc $a->{'firstname'} cmp lc $b->{'surname'}
521               . lc $b->{'firstname'}
522         } @$borrowerslist
523       )
524     {
525         push @values, $_->{'borrowernumber'};
526         $labels{ $_->{'borrowernumber'} } =
527 "$_->{'surname'}, $_->{'firstname'} ... ($_->{'cardnumber'} - $_->{'categorycode'}) ...  $_->{'address'} ";
528     }
529     $CGIselectborrower = CGI::scrolling_list(
530         -name     => 'borrowernumber',
531                 -class     => 'focus',
532                 -id          => 'borrowernumber',
533         -values   => \@values,
534         -labels   => \%labels,
535         -size     => 7,
536         -tabindex => '',
537         -multiple => 0
538     );
539 }
540
541 #title
542 my $flags = $borrower->{'flags'};
543 my $flag;
544
545 foreach $flag ( sort keys %$flags ) {
546     $template->param( flagged=> 1);
547     $flags->{$flag}->{'message'} =~ s/\n/<br>/g;
548     if ( $flags->{$flag}->{'noissues'} ) {
549         $template->param(
550             flagged  => 1,
551             noissues => 'true',
552         );
553         if ( $flag eq 'GNA' ) {
554             $template->param( gna => 'true' );
555         }
556         if ( $flag eq 'LOST' ) {
557             $template->param( lost => 'true' );
558         }
559         if ( $flag eq 'DBARRED' ) {
560             $template->param( dbarred => 'true' );
561         }
562         if ( $flag eq 'CHARGES' ) {
563             $template->param(
564                 charges    => 'true',
565                 chargesmsg => $flags->{'CHARGES'}->{'message'}
566             );
567         }
568         if ( $flag eq 'CREDITS' ) {
569             $template->param(
570                 credits    => 'true',
571                 creditsmsg => $flags->{'CREDITS'}->{'message'}
572             );
573         }
574     }
575     else {
576         if ( $flag eq 'CHARGES' ) {
577             $template->param(
578                 charges    => 'true',
579                 flagged    => 1,
580                 chargesmsg => $flags->{'CHARGES'}->{'message'}
581             );
582         }
583         if ( $flag eq 'CREDITS' ) {
584             $template->param(
585                 credits    => 'true',
586                 creditsmsg => $flags->{'CREDITS'}->{'message'}
587             );
588         }
589         if ( $flag eq 'ODUES' ) {
590             $template->param(
591                 odues    => 'true',
592                 flagged  => 1,
593                 oduesmsg => $flags->{'ODUES'}->{'message'}
594             );
595
596             my $items = $flags->{$flag}->{'itemlist'};
597 # useless ???
598 #             {
599 #                 my @itemswaiting;
600 #                 foreach my $item (@$items) {
601 #                     my ($iteminformation) =
602 #                         getiteminformation( $item->{'itemnumber'}, 0 );
603 #                     push @itemswaiting, $iteminformation;
604 #                 }
605 #             }
606             if ( $query->param('module') ne 'returns' ) {
607                 $template->param( nonreturns => 'true' );
608             }
609         }
610         if ( $flag eq 'NOTES' ) {
611             $template->param(
612                 notes    => 'true',
613                 flagged  => 1,
614                 notesmsg => $flags->{'NOTES'}->{'message'}
615             );
616         }
617     }
618 }
619
620 my $amountold = $borrower->{flags}->{'CHARGES'}->{'message'} || 0;
621 my @temp = split( /\$/, $amountold );
622
623 my $CGIorganisations;
624 my $member_of_institution;
625 if ( C4::Context->preference("memberofinstitution") ) {
626     my $organisations = get_institutions();
627     my @orgs;
628     my %org_labels;
629     foreach my $organisation ( keys %$organisations ) {
630         push @orgs, $organisation;
631         $org_labels{$organisation} =
632           $organisations->{$organisation}->{'surname'};
633     }
634     $member_of_institution = 1;
635     $CGIorganisations      = CGI::popup_menu(
636         -id     => 'organisations',
637         -name   => 'organisations',
638         -labels => \%org_labels,
639         -values => \@orgs,
640     );
641 }
642
643 $amountold = $temp[1];
644
645 my $borrowercategory = GetBorrowercategory( $borrower->{'categorycode'} );
646 my $category_type = $borrowercategory->{'category_type'};
647 ( $template->param( adultborrower => 1 ) ) if ( $category_type eq 'A' );
648
649 $template->param(
650     issued_itemtypes_count_loop => $issued_itemtypes_loop,
651     findborrower                => $findborrower,
652     borrower                    => $borrower,
653     borrowernumber              => $borrowernumber,
654     branch                      => $branch,
655     branchname                  => GetBranchName($branch),
656     printer                     => $printer,
657     printername                 => $printer,
658     firstname                   => $borrower->{'firstname'},
659     surname                     => $borrower->{'surname'},
660         dateexpiry => format_date($newexpiry),
661     expiry                      => format_date($borrower->{'dateexpiry'}),
662     categorycode      => $borrower->{'categorycode'},
663     categoryname      => $borrowercategory->{description},
664     address     => $borrower->{'address'},
665     address2     => $borrower->{'address2'},
666     email      => $borrower->{'email'},
667         emailpro           => $borrower->{'emailpro'},
668     borrowernotes     => $borrower->{'borrowernotes'},
669     city              => $borrower->{'city'},
670     phone             => $borrower->{'phone'} || $borrower->{'mobile'},
671     cardnumber        => $borrower->{'cardnumber'},
672     amountold         => $amountold,
673     barcode           => $barcode,
674     stickyduedate     => $stickyduedate,
675     message           => $message,
676     CGIselectborrower => $CGIselectborrower,
677     todayissues       => \@todaysissues,
678     previssues        => \@previousissues,
679     inprocess         => $inprocess,
680     memberofinstution => $member_of_institution,
681     CGIorganisations  => $CGIorganisations,
682         circview => 1,
683         
684 );
685
686 # set return date if stickyduedate
687 if ($stickyduedate) {
688     $template->param(
689         duedatespec => $duedatespec,
690     );
691 }
692
693 #if ($branchcookie) {
694 #$cookie=[$cookie, $branchcookie, $printercookie];
695 #}
696
697 my ($picture, $dberror) = GetPatronImage($borrower->{'cardnumber'});
698 $template->param( picture => 1 ) if $picture;
699
700
701 $template->param(
702     SpecifyDueDate           => C4::Context->preference("SpecifyDueDate"),
703     CircAutocompl            => C4::Context->preference("CircAutocompl") ,
704     DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
705 );
706 output_html_with_http_headers $query, $cookie, $template->output;