Fix for bug 1400, some variables not being passed to the branch transfers
[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 # strip whitespace
124 $barcode =~ s/\s*//g;
125
126 my $year           = $query->param('year');
127 my $month          = $query->param('month');
128 my $day            = $query->param('day');
129 my $stickyduedate  = $query->param('stickyduedate');
130 my $duedatespec    = $query->param('duedatespec');
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
137 #set up cookie.....
138 # my $branchcookie;
139 # my $printercookie;
140 # if ($query->param('setcookies')) {
141 #     $branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
142 #     $printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
143 # }
144 #
145
146 my ($datedue,$invalidduedate);
147 if ($duedatespec) {
148         $datedue =  C4::Dates->new($duedatespec);
149         $invalidduedate=1 unless $datedue;
150 }
151
152 #if (defined($year)) {
153 #        $duedatespec = "$year-$month-$day";
154 #} else {
155 #        ($year, $month, $day) = ($duedatespec) ? split /-/, $duedatespec : (0,0,0);
156 #}
157
158 my @datearr = localtime();
159
160 # FIXME - Could just use POSIX::strftime("%Y%m%d", localtime);
161 my $todaysdate =
162     ( 1900 + $datearr[5] )
163   . sprintf( "%0.2d", ( $datearr[4] + 1 ) )
164   . sprintf( "%0.2d", ( $datearr[3] ) );
165
166 # check and see if we should print
167 if ( $barcode eq '' && $print eq 'maybe' ) {
168     $print = 'yes';
169 }
170
171 my $inprocess = ($barcode eq '') ? '' : $query->param('inprocess');
172
173 if ( $barcode eq '' && $query->param('charges') eq 'yes' ) {
174     $template->param(
175         PAYCHARGES     => 'yes',
176         borrowernumber => $borrowernumber
177     );
178 }
179
180 if ( $print eq 'yes' && $borrowernumber ne '' ) {
181     printslip( $borrowernumber );
182     $query->param( 'borrowernumber', '' );
183     $borrowernumber = '';
184 }
185
186 #
187 # STEP 2 : FIND BORROWER
188 # if there is a list of find borrowers....
189 #
190 my $borrowerslist;
191 my $message;
192 if ($findborrower) {
193     my ( $count, $borrowers ) =
194       SearchMember($findborrower, 'cardnumber', 'web' );
195     my @borrowers = @$borrowers;
196     if ( $#borrowers == -1 ) {
197         $query->param( 'findborrower', '' );
198         $message = "'$findborrower'";
199     }
200     elsif ( $#borrowers == 0 ) {
201         $query->param( 'borrowernumber', $borrowers[0]->{'borrowernumber'} );
202         $query->param( 'barcode',           '' );
203         $borrowernumber = $borrowers[0]->{'borrowernumber'};
204     }
205     else {
206         $borrowerslist = \@borrowers;
207     }
208 }
209
210 # get the borrower information.....
211 my $borrower;
212 my @lines;
213 if ($borrowernumber) {
214     $borrower = GetMemberDetails( $borrowernumber, 0 );
215     my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrowernumber );
216
217     # Warningdate is the date that the warning starts appearing
218     my ( $today_year,   $today_month,   $today_day )   = Today();
219     my ( $warning_year, $warning_month, $warning_day ) = split /-/,
220       $borrower->{'dateexpiry'};
221     my ( $enrol_year, $enrol_month, $enrol_day ) = split /-/,
222       $borrower->{'dateenrolled'};
223     # Renew day is calculated by adding the enrolment period to today
224     my ( $renew_year, $renew_month, $renew_day ) =
225       Add_Delta_YM( $enrol_year, $enrol_month, $enrol_day,
226         0 , $borrower->{'enrolmentperiod'}) if ($enrol_year*$enrol_month*$enrol_day>0);
227     # if the expiry date is before today ie they have expired
228     if ( $warning_year*$warning_month*$warning_day==0 
229       || Date_to_Days( $today_year, $today_month, $today_day ) 
230          > Date_to_Days( $warning_year, $warning_month, $warning_day ) )
231     {
232         #borrowercard expired, no issues
233         $template->param(
234                         flagged => "1",
235             noissues       => "1",
236             expired => format_date($borrower->{dateexpiry}),
237             renewaldate   => format_date("$renew_year-$renew_month-$renew_day")
238         );
239     }
240     # check for NotifyBorrowerDeparture
241         elsif ( C4::Context->preference('NotifyBorrowerDeparture') &&
242                 Date_to_Days(Add_Delta_Days($warning_year,$warning_month,$warning_day,- C4::Context->preference('NotifyBorrowerDeparture'))) <
243                 Date_to_Days( $today_year, $today_month, $today_day ) ) 
244         {
245                 # borrower card soon to expire warn librarian
246                 $template->param("warndeparture" => format_date($borrower->{dateexpiry}),
247                         flagged       => "1",);
248         }
249     $template->param(
250         overduecount => $od,
251         issuecount   => $issue,
252         finetotal    => $fines
253     );
254 }
255
256 #
257 # STEP 3 : ISSUING
258 #
259 #
260
261 if ($barcode) {
262    # $barcode = cuecatbarcodedecode($barcode);
263     
264         if ($issueconfirmed) {
265         AddIssue( $borrower, $barcode, $datedue, $cancelreserve );
266         $inprocess = 1;
267     }
268     else {
269         my ( $error, $question ) =
270           CanBookBeIssued( $borrower, $barcode, $datedue , $inprocess );
271         my $noerror    = 1;
272         my $noquestion = 1;
273 #         Get the item title for more information
274         my $getmessageiteminfo  = GetBiblioFromItemNumber(undef,$barcode);
275     
276         foreach my $impossible ( keys %$error ) {
277             $template->param(
278                 $impossible => $$error{$impossible},
279                 IMPOSSIBLE  => 1
280             );
281             $noerror = 0;
282         }
283         foreach my $needsconfirmation ( keys %$question ) {
284             $template->param(
285                 $needsconfirmation => $$question{$needsconfirmation},
286                 getTitleMessageIteminfo => $getmessageiteminfo->{'title'},
287                 NEEDSCONFIRMATION  => 1
288             );
289             $noquestion = 0;
290         }
291         $template->param(
292                          itemhomebranch => $getmessageiteminfo->{'homebranch'} ,                     
293                          duedatespec => $duedatespec,
294         );
295         if ( $noerror && ( $noquestion || $issueconfirmed ) ) {
296             AddIssue( $borrower, $barcode, $datedue );
297             $inprocess = 1;
298         }
299     }
300     
301 # FIXME If the issue is confirmed, we launch another time borrdata2, now display the issue count after issue 
302         my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrowernumber );
303         $template->param(
304         issuecount   => $issue,
305         );
306 }
307
308 # reload the borrower info for the sake of reseting the flags.....
309 if ($borrowernumber) {
310     $borrower = GetMemberDetails( $borrowernumber, 0 );
311 }
312
313 ##################################################################################
314 # BUILD HTML
315 # show all reserves of this borrower, and the position of the reservation ....
316 if ($borrowernumber) {
317
318     # new op dev
319     # now we show the status of the borrower's reservations
320     my @borrowerreserv = GetReservesFromBorrowernumber($borrowernumber );
321     my @reservloop;
322     my @WaitingReserveLoop;
323     
324     foreach my $num_res (@borrowerreserv) {
325         my %getreserv;
326         my %getWaitingReserveInfo;
327         my $getiteminfo  = GetBiblioFromItemNumber( $num_res->{'itemnumber'} );
328         my $itemtypeinfo = getitemtypeinfo( (C4::Context->preference('item-level_itype')) ? $getiteminfo->{'itype'} : $getiteminfo->{'itemtype'} );
329         my ( $transfertwhen, $transfertfrom, $transfertto ) =
330           GetTransfers( $num_res->{'itemnumber'} );
331
332         $getreserv{waiting}       = 0;
333         $getreserv{transfered}    = 0;
334         $getreserv{nottransfered} = 0;
335
336         $getreserv{reservedate}    = format_date( $num_res->{'reservedate'} );
337         $getreserv{title}          = $getiteminfo->{'title'};
338         $getreserv{itemtype}       = $itemtypeinfo->{'description'};
339         $getreserv{author}         = $getiteminfo->{'author'};
340         $getreserv{barcodereserv}  = $getiteminfo->{'barcode'};
341         $getreserv{itemcallnumber} = $getiteminfo->{'itemcallnumber'};
342                 $getreserv{biblionumber}   = $getiteminfo->{'biblionumber'};
343
344         #         check if we have a waiting status for reservations
345         if ( $num_res->{'found'} eq 'W' ) {
346             $getreserv{color}   = 'reserved';
347             $getreserv{waiting} = 1;
348 #     genarate information displaying only waiting reserves
349         $getWaitingReserveInfo{title}        = $getiteminfo->{'title'};
350         $getWaitingReserveInfo{biblionumber}   = $getiteminfo->{'biblionumber'};
351         $getWaitingReserveInfo{itemtype}    = $itemtypeinfo->{'description'};
352         $getWaitingReserveInfo{author}        = $getiteminfo->{'author'};
353         $getWaitingReserveInfo{reservedate}    = format_date( $num_res->{'reservedate'} );
354         if ($getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'} ) {
355         $getWaitingReserveInfo{waitingat}    = GetBranchName( $num_res->{'branchcode'} );
356         }
357     
358         }
359         #         check transfers with the itemnumber foud in th reservation loop
360         if ($transfertwhen) {
361             $getreserv{color}      = 'transfered';
362             $getreserv{transfered} = 1;
363             $getreserv{datesent}   = format_date($transfertwhen);
364             $getreserv{frombranch} = GetBranchName($transfertfrom);
365         }
366
367         if ( ( $getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'} )
368             and not $transfertwhen )
369         {
370             $getreserv{nottransfered}   = 1;
371             $getreserv{nottransferedby} =
372               GetBranchName( $getiteminfo->{'holdingbranch'} );
373         }
374
375 #         if we don't have a reserv on item, we put the biblio infos and the waiting position
376         if ( $getiteminfo->{'title'} eq '' ) {
377             my $getbibinfo = GetBiblioData( $num_res->{'biblionumber'} );
378             my $getbibtype = getitemtypeinfo( $getbibinfo->{'itemtype'} );  # fixme - we should have item-level reserves here ?
379             $getreserv{color}           = 'inwait';
380             $getreserv{title}           = $getbibinfo->{'title'};
381             $getreserv{waitingposition} = $num_res->{'priority'};
382             $getreserv{nottransfered}   = 0;
383             $getreserv{itemtype}        = $getbibtype->{'description'};
384             $getreserv{author}          = $getbibinfo->{'author'};
385             $getreserv{itemcallnumber}  = '----------';
386                 $getreserv{biblionumber}    = $num_res->{'biblionumber'};
387         }
388         push( @reservloop, \%getreserv );
389
390 #         if we have a reserve waiting, initiate waitingreserveloop
391         if ($getreserv{waiting} eq 1) {
392         push (@WaitingReserveLoop, \%getWaitingReserveInfo)
393         }
394       
395     }
396
397     # return result to the template
398     $template->param( 
399         countreserv => scalar @reservloop,
400         reservloop  => \@reservloop ,
401         WaitingReserveLoop  => \@WaitingReserveLoop,
402     );
403 }
404
405 # make the issued books table.
406 my $todaysissues = '';
407 my $previssues   = '';
408 my @todaysissues;
409 my @previousissues;
410 my $allowborrow;
411 ## ADDED BY JF: new itemtype issuingrules counter stuff
412 my $issued_itemtypes_loop;
413 my $issued_itemtypes_count;
414 my $issued_itemtypes_allowed_count;    # hashref with total allowed by itemtype
415 my $issued_itemtypes_remaining;        # hashref with remaining
416 my $issued_itemtypes_flags;            #hashref that stores flags
417 my @issued_itemtypes_count_loop;
418
419 if ($borrower) {
420
421 # get each issue of the borrower & separate them in todayissues & previous issues
422     my ($countissues,$issueslist) = GetPendingIssues($borrower->{'borrowernumber'});
423
424     # split in 2 arrays for today & previous
425     foreach my $it ( @$issueslist ) {
426         my $issuedate = $it->{'issuedate'};
427         $issuedate =~ s/-//g;
428         $issuedate = substr( $issuedate, 0, 8 );
429                 ($it->{'charge'}, $it->{'itemtype_charge'}) = GetIssuingCharges(
430                                                 $it->{'itemnumber'}, $borrower->{'borrowernumber'}
431                 );
432                 $it->{'charge'} = sprintf("%.2f", $it->{'charge'});
433         ($it->{'can_renew'}, $it->{'can_renew_error'}) = CanBookBeRenewed( 
434                                                 $borrower->{'borrowernumber'},$it->{'itemnumber'}
435                 );
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     printer                     => $printer,
656     printername                 => $printer,
657     firstname                   => $borrower->{'firstname'},
658     surname                     => $borrower->{'surname'},
659         dateexpiry => format_date($newexpiry),
660     expiry                      =>
661       $borrower->{'dateexpiry'},    #format_date($borrower->{'dateexpiry'}),
662     categorycode      => $borrower->{'categorycode'},
663     address     => $borrower->{'address'},
664     address2     => $borrower->{'address2'},
665     email      => $borrower->{'email'},
666         emailpro           => $borrower->{'emailpro'},
667     borrowernotes     => $borrower->{'borrowernotes'},
668     city              => $borrower->{'city'},
669     phone             => $borrower->{'phone'} || $borrower->{'mobile'},
670     cardnumber        => $borrower->{'cardnumber'},
671     amountold         => $amountold,
672     barcode           => $barcode,
673     stickyduedate     => $stickyduedate,
674     message           => $message,
675     CGIselectborrower => $CGIselectborrower,
676     todayissues       => \@todaysissues,
677     previssues        => \@previousissues,
678     inprocess         => $inprocess,
679     memberofinstution => $member_of_institution,
680     CGIorganisations  => $CGIorganisations,
681         circview => 1,
682         
683 );
684
685 # set return date if stickyduedate
686 if ($stickyduedate) {
687     $template->param(
688         duedatespec => $duedatespec,
689     );
690 }
691
692 #if ($branchcookie) {
693 #$cookie=[$cookie, $branchcookie, $printercookie];
694 #}
695
696 $template->param(
697     SpecifyDueDate           => C4::Context->preference("SpecifyDueDate"),
698     CircAutocompl            => C4::Context->preference("CircAutocompl") ,
699     DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
700 );
701 output_html_with_http_headers $query, $cookie, $template->output;