Markup corrections. Tweaking holds interface.
[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 @datearr = localtime();
157
158 # FIXME - Could just use POSIX::strftime("%Y%m%d", localtime);
159 my $todaysdate =
160     ( 1900 + $datearr[5] )
161   . sprintf( "%0.2d", ( $datearr[4] + 1 ) )
162   . sprintf( "%0.2d", ( $datearr[3] ) );
163
164 # check and see if we should print
165 if ( $barcode eq '' && $print eq 'maybe' ) {
166     $print = 'yes';
167 }
168
169 my $inprocess = ($barcode eq '') ? '' : $query->param('inprocess');
170
171 if ( $barcode eq '' && $query->param('charges') eq 'yes' ) {
172     $template->param(
173         PAYCHARGES     => 'yes',
174         borrowernumber => $borrowernumber
175     );
176 }
177
178 if ( $print eq 'yes' && $borrowernumber ne '' ) {
179     printslip( $borrowernumber );
180     $query->param( 'borrowernumber', '' );
181     $borrowernumber = '';
182 }
183
184 #
185 # STEP 2 : FIND BORROWER
186 # if there is a list of find borrowers....
187 #
188 my $borrowerslist;
189 my $message;
190 if ($findborrower) {
191     my ( $count, $borrowers ) =
192       SearchMember($findborrower, 'cardnumber', 'web' );
193     my @borrowers = @$borrowers;
194     if ( $#borrowers == -1 ) {
195         $query->param( 'findborrower', '' );
196         $message = "'$findborrower'";
197     }
198     elsif ( $#borrowers == 0 ) {
199         $query->param( 'borrowernumber', $borrowers[0]->{'borrowernumber'} );
200         $query->param( 'barcode',           '' );
201         $borrowernumber = $borrowers[0]->{'borrowernumber'};
202     }
203     else {
204         $borrowerslist = \@borrowers;
205     }
206 }
207
208 # get the borrower information.....
209 my $borrower;
210 my @lines;
211 if ($borrowernumber) {
212     $borrower = GetMemberDetails( $borrowernumber, 0 );
213     my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrowernumber );
214
215     # Warningdate is the date that the warning starts appearing
216     my ( $today_year,   $today_month,   $today_day )   = Today();
217     my ( $warning_year, $warning_month, $warning_day ) = split /-/,
218       $borrower->{'dateexpiry'};
219     my ( $enrol_year, $enrol_month, $enrol_day ) = split /-/,
220       $borrower->{'dateenrolled'};
221     # Renew day is calculated by adding the enrolment period to today
222     my ( $renew_year, $renew_month, $renew_day ) =
223       Add_Delta_YM( $enrol_year, $enrol_month, $enrol_day,
224         0 , $borrower->{'enrolmentperiod'}) if ($enrol_year*$enrol_month*$enrol_day>0);
225     # if the expiry date is before today ie they have expired
226     if ( $warning_year*$warning_month*$warning_day==0 
227       || Date_to_Days( $today_year, $today_month, $today_day ) 
228          > Date_to_Days( $warning_year, $warning_month, $warning_day ) )
229     {
230         #borrowercard expired, no issues
231         $template->param(
232                         flagged => "1",
233             noissues       => "1",
234             expired => format_date($borrower->{dateexpiry}),
235             renewaldate   => format_date("$renew_year-$renew_month-$renew_day")
236         );
237     }
238     # check for NotifyBorrowerDeparture
239         elsif ( C4::Context->preference('NotifyBorrowerDeparture') &&
240                 Date_to_Days(Add_Delta_Days($warning_year,$warning_month,$warning_day,- C4::Context->preference('NotifyBorrowerDeparture'))) <
241                 Date_to_Days( $today_year, $today_month, $today_day ) ) 
242         {
243                 # borrower card soon to expire warn librarian
244                 $template->param("warndeparture" => format_date($borrower->{dateexpiry}),
245                         flagged       => "1",);
246                 if ( C4::Context->preference('ReturnBeforeExpiry')){
247                         $template->param("returnbeforeexpiry" => 1);
248                 }
249         }
250     $template->param(
251         overduecount => $od,
252         issuecount   => $issue,
253         finetotal    => $fines
254     );
255 }
256
257 #
258 # STEP 3 : ISSUING
259 #
260 #
261
262 if ($barcode) {
263         # always check for blockers on issuing
264         my ( $error, $question ) =
265           CanBookBeIssued( $borrower, $barcode, $datedue , $inprocess );
266         my $noerror    = 1;
267         foreach my $impossible ( keys %$error ) {
268             $template->param(
269                 $impossible => $$error{$impossible},
270                 IMPOSSIBLE  => 1
271             );
272             $noerror = 0;
273         }
274     
275         if ($issueconfirmed && $noerror) {
276                 # we have no blockers for issuing and any issues needing confirmation have been resolved
277         AddIssue( $borrower, $barcode, $datedue, $cancelreserve );
278         $inprocess = 1;
279     }
280         elsif ($issueconfirmed){
281         }
282     else {
283         my $noquestion = 1;
284 #         Get the item title for more information
285         my $getmessageiteminfo  = GetBiblioFromItemNumber(undef,$barcode);
286     
287         foreach my $needsconfirmation ( keys %$question ) {
288             $template->param(
289                 $needsconfirmation => $$question{$needsconfirmation},
290                 getTitleMessageIteminfo => $getmessageiteminfo->{'title'},
291                 NEEDSCONFIRMATION  => 1
292             );
293             $noquestion = 0;
294         }
295         $template->param(
296                          itemhomebranch => $getmessageiteminfo->{'homebranch'} ,                     
297                          duedatespec => $duedatespec,
298         );
299         if ( $noerror && ( $noquestion || $issueconfirmed ) ) {
300             AddIssue( $borrower, $barcode, $datedue );
301             $inprocess = 1;
302         }
303     }
304     
305 # FIXME If the issue is confirmed, we launch another time borrdata2, now display the issue count after issue 
306         my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrowernumber );
307         $template->param(
308         issuecount   => $issue,
309         );
310 }
311
312 # reload the borrower info for the sake of reseting the flags.....
313 if ($borrowernumber) {
314     $borrower = GetMemberDetails( $borrowernumber, 0 );
315 }
316
317 ##################################################################################
318 # BUILD HTML
319 # show all reserves of this borrower, and the position of the reservation ....
320 if ($borrowernumber) {
321
322     # new op dev
323     # now we show the status of the borrower's reservations
324     my @borrowerreserv = GetReservesFromBorrowernumber($borrowernumber );
325     my @reservloop;
326     my @WaitingReserveLoop;
327     
328     foreach my $num_res (@borrowerreserv) {
329         my %getreserv;
330         my %getWaitingReserveInfo;
331         my $getiteminfo  = GetBiblioFromItemNumber( $num_res->{'itemnumber'} );
332         my $itemtypeinfo = getitemtypeinfo( (C4::Context->preference('item-level_itypes')) ? $getiteminfo->{'itype'} : $getiteminfo->{'itemtype'} );
333         my ( $transfertwhen, $transfertfrom, $transfertto ) =
334           GetTransfers( $num_res->{'itemnumber'} );
335
336         $getreserv{waiting}       = 0;
337         $getreserv{transfered}    = 0;
338         $getreserv{nottransfered} = 0;
339
340         $getreserv{reservedate}    = format_date( $num_res->{'reservedate'} );
341         $getreserv{title}          = $getiteminfo->{'title'};
342         $getreserv{itemtype}       = $itemtypeinfo->{'description'};
343         $getreserv{author}         = $getiteminfo->{'author'};
344         $getreserv{barcodereserv}  = $getiteminfo->{'barcode'};
345         $getreserv{itemcallnumber} = $getiteminfo->{'itemcallnumber'};
346                 $getreserv{biblionumber}   = $getiteminfo->{'biblionumber'};
347
348         #         check if we have a waiting status for reservations
349         if ( $num_res->{'found'} eq 'W' ) {
350             $getreserv{color}   = 'reserved';
351             $getreserv{waiting} = 1;
352 #     genarate information displaying only waiting reserves
353         $getWaitingReserveInfo{title}        = $getiteminfo->{'title'};
354         $getWaitingReserveInfo{biblionumber}   = $getiteminfo->{'biblionumber'};
355         $getWaitingReserveInfo{itemtype}    = $itemtypeinfo->{'description'};
356         $getWaitingReserveInfo{author}        = $getiteminfo->{'author'};
357         $getWaitingReserveInfo{reservedate}    = format_date( $num_res->{'reservedate'} );
358         if ($getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'} ) {
359         $getWaitingReserveInfo{waitingat}    = GetBranchName( $num_res->{'branchcode'} );
360         }
361     
362         }
363         #         check transfers with the itemnumber foud in th reservation loop
364         if ($transfertwhen) {
365             $getreserv{color}      = 'transfered';
366             $getreserv{transfered} = 1;
367             $getreserv{datesent}   = format_date($transfertwhen);
368             $getreserv{frombranch} = GetBranchName($transfertfrom);
369         }
370
371         if ( ( $getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'} )
372             and not $transfertwhen )
373         {
374             $getreserv{nottransfered}   = 1;
375             $getreserv{nottransferedby} =
376               GetBranchName( $getiteminfo->{'holdingbranch'} );
377         }
378
379 #         if we don't have a reserv on item, we put the biblio infos and the waiting position
380         if ( $getiteminfo->{'title'} eq '' ) {
381             my $getbibinfo = GetBiblioData( $num_res->{'biblionumber'} );
382             my $getbibtype = getitemtypeinfo( $getbibinfo->{'itemtype'} );  # fixme - we should have item-level reserves here ?
383             $getreserv{color}           = 'inwait';
384             $getreserv{title}           = $getbibinfo->{'title'};
385             $getreserv{waitingposition} = $num_res->{'priority'};
386             $getreserv{nottransfered}   = 0;
387             $getreserv{itemtype}        = $getbibtype->{'description'};
388             $getreserv{author}          = $getbibinfo->{'author'};
389                 $getreserv{biblionumber}    = $num_res->{'biblionumber'};
390         }
391         push( @reservloop, \%getreserv );
392
393 #         if we have a reserve waiting, initiate waitingreserveloop
394         if ($getreserv{waiting} eq 1) {
395         push (@WaitingReserveLoop, \%getWaitingReserveInfo)
396         }
397       
398     }
399
400     # return result to the template
401     $template->param( 
402         countreserv => scalar @reservloop,
403         reservloop  => \@reservloop ,
404         WaitingReserveLoop  => \@WaitingReserveLoop,
405     );
406 }
407
408 # make the issued books table.
409 my $todaysissues = '';
410 my $previssues   = '';
411 my @todaysissues;
412 my @previousissues;
413 my $allowborrow;
414 ## ADDED BY JF: new itemtype issuingrules counter stuff
415 my $issued_itemtypes_loop;
416 my $issued_itemtypes_count;
417 my $issued_itemtypes_allowed_count;    # hashref with total allowed by itemtype
418 my $issued_itemtypes_remaining;        # hashref with remaining
419 my $issued_itemtypes_flags;            #hashref that stores flags
420 my @issued_itemtypes_count_loop;
421
422 if ($borrower) {
423
424 # get each issue of the borrower & separate them in todayissues & previous issues
425     my ($countissues,$issueslist) = GetPendingIssues($borrower->{'borrowernumber'});
426
427     # split in 2 arrays for today & previous
428     foreach my $it ( @$issueslist ) {
429         # set itemtype per item-level_itype syspref - FIXME this is an ugly hack
430         $it->{'itemtype'} = (C4::Context->preference('item-level_itypes')) ? $it->{'itype'} : $it->{'itemtype'};
431
432         my $issuedate = $it->{'issuedate'};
433         $issuedate =~ s/-//g;
434         $issuedate = substr( $issuedate, 0, 8 );
435                 ($it->{'charge'}, $it->{'itemtype_charge'}) = GetIssuingCharges(
436                                                 $it->{'itemnumber'}, $borrower->{'borrowernumber'}
437                 );
438                 $it->{'charge'} = sprintf("%.2f", $it->{'charge'});
439         my $can_renew_error;
440         ($it->{'can_renew'}, $can_renew_error) = CanBookBeRenewed( 
441                                                 $borrower->{'borrowernumber'},$it->{'itemnumber'}
442                 );
443         $it->{"renew_error_${can_renew_error}"} = 1 if defined $can_renew_error;
444                 my ($restype, $reserves) = CheckReserves($it->{'itemnumber'});
445                 ($restype) and $it->{'can_renew'} = 0;
446
447                 $it->{'dd'} = format_date($it->{'date_due'});
448         my $datedue = $it->{'date_due'};
449         $datedue =~ s/-//g;
450                 $it->{'od'} = ($datedue < $todaysdate) ? 1 : 0 ;
451         ($it->{'author'} eq '') and $it->{'author'} = ' ';
452         $it->{'renew_failed'} = $renew_failed[$it->{'itemnumber'}];
453         # ADDED BY JF: NEW ITEMTYPE COUNT DISPLAY
454         $issued_itemtypes_count->{ $it->{'itemtype'} }++;
455
456         if ( $todaysdate == $issuedate ) {
457             push @todaysissues, $it;
458         } else {
459             push @previousissues, $it;
460         }
461     }
462         if (C4::Context->preference("todaysIssuesDefaultSortOrder") eq 'asc'){
463                 @todaysissues   = sort { $a->{'timestamp'} cmp $b->{'timestamp'} } @todaysissues;
464         }
465         else {
466                 @todaysissues   = sort { $b->{'timestamp'} cmp $a->{'timestamp'} } @todaysissues;
467         }
468         if (C4::Context->preference("previousIssuesDefaultSortOrder") eq 'asc'){
469                 @previousissues = sort { $a->{'date_due' } cmp $b->{'date_due' } } @previousissues;
470         }
471         else {
472                 @previousissues = sort { $b->{'date_due' } cmp $a->{'date_due' } } @previousissues;
473         }
474     my $i = 1;
475         foreach my $book (@todaysissues) {
476         $book->{'togglecolor'} = (++$i % 2) ? 0 : 1 ;
477     }
478     $i = 1;
479         foreach my $book (@previousissues) {
480         $book->{'togglecolor'} = (++$i % 2) ? 0 : 1 ;
481     }
482 }
483
484 #### ADDED BY JF FOR COUNTS BY ITEMTYPE RULES
485 # FIXME: This should utilize all the issuingrules options rather than just the defaults
486 # and it should be moved to a module
487 my $dbh = C4::Context->dbh;
488
489 # how many of each is allowed?
490 my $issueqty_sth = $dbh->prepare( "
491 SELECT itemtypes.description AS description,issuingrules.itemtype,maxissueqty
492 FROM issuingrules
493   LEFT JOIN itemtypes ON (itemtypes.itemtype=issuingrules.itemtype)
494   WHERE categorycode=?
495 " );
496 #my @issued_itemtypes_count;  # huh?
497 $issueqty_sth->execute("*");
498
499 while ( my $data = $issueqty_sth->fetchrow_hashref() ) {
500
501     # subtract how many of each this borrower has
502     $data->{'count'} = $issued_itemtypes_count->{ $data->{'description'} };  
503     $data->{'left'}  =
504       ( $data->{'maxissueqty'} -
505           $issued_itemtypes_count->{ $data->{'description'} } );
506
507     # can't have a negative number of remaining
508     if ( $data->{'left'} < 0 ) { $data->{'left'} = "0" }
509     $data->{'flag'} = 1 unless ( $data->{'maxissueqty'} > $data->{'count'} );
510     unless ( ( $data->{'maxissueqty'} < 1 )
511         || ( $data->{'itemtype'} eq "*" )
512         || ( $data->{'itemtype'} eq "CIRC" ) )
513     {
514         push @issued_itemtypes_count_loop, $data;
515     }
516 }
517 $issued_itemtypes_loop = \@issued_itemtypes_count_loop;
518
519 #### / JF
520
521 my @values;
522 my %labels;
523 my $CGIselectborrower;
524 if ($borrowerslist) {
525     foreach (
526         sort {
527                 lc $a->{'surname'}
528               . lc $a->{'firstname'} cmp lc $b->{'surname'}
529               . lc $b->{'firstname'}
530         } @$borrowerslist
531       )
532     {
533         push @values, $_->{'borrowernumber'};
534         $labels{ $_->{'borrowernumber'} } =
535 "$_->{'surname'}, $_->{'firstname'} ... ($_->{'cardnumber'} - $_->{'categorycode'}) ...  $_->{'address'} ";
536     }
537     $CGIselectborrower = CGI::scrolling_list(
538         -name     => 'borrowernumber',
539                 -class     => 'focus',
540                 -id          => 'borrowernumber',
541         -values   => \@values,
542         -labels   => \%labels,
543         -size     => 7,
544         -tabindex => '',
545         -multiple => 0
546     );
547 }
548
549 #title
550 my $flags = $borrower->{'flags'};
551 my $flag;
552
553 foreach $flag ( sort keys %$flags ) {
554     $template->param( flagged=> 1);
555     $flags->{$flag}->{'message'} =~ s/\n/<br>/g;
556     if ( $flags->{$flag}->{'noissues'} ) {
557         $template->param(
558             flagged  => 1,
559             noissues => 'true',
560         );
561         if ( $flag eq 'GNA' ) {
562             $template->param( gna => 'true' );
563         }
564         if ( $flag eq 'LOST' ) {
565             $template->param( lost => 'true' );
566         }
567         if ( $flag eq 'DBARRED' ) {
568             $template->param( dbarred => 'true' );
569         }
570         if ( $flag eq 'CHARGES' ) {
571             $template->param(
572                 charges    => 'true',
573                 chargesmsg => $flags->{'CHARGES'}->{'message'}
574             );
575         }
576         if ( $flag eq 'CREDITS' ) {
577             $template->param(
578                 credits    => 'true',
579                 creditsmsg => $flags->{'CREDITS'}->{'message'}
580             );
581         }
582     }
583     else {
584         if ( $flag eq 'CHARGES' ) {
585             $template->param(
586                 charges    => 'true',
587                 flagged    => 1,
588                 chargesmsg => $flags->{'CHARGES'}->{'message'}
589             );
590         }
591         if ( $flag eq 'CREDITS' ) {
592             $template->param(
593                 credits    => 'true',
594                 creditsmsg => $flags->{'CREDITS'}->{'message'}
595             );
596         }
597         if ( $flag eq 'ODUES' ) {
598             $template->param(
599                 odues    => 'true',
600                 flagged  => 1,
601                 oduesmsg => $flags->{'ODUES'}->{'message'}
602             );
603
604             my $items = $flags->{$flag}->{'itemlist'};
605 # useless ???
606 #             {
607 #                 my @itemswaiting;
608 #                 foreach my $item (@$items) {
609 #                     my ($iteminformation) =
610 #                         getiteminformation( $item->{'itemnumber'}, 0 );
611 #                     push @itemswaiting, $iteminformation;
612 #                 }
613 #             }
614             if ( $query->param('module') ne 'returns' ) {
615                 $template->param( nonreturns => 'true' );
616             }
617         }
618         if ( $flag eq 'NOTES' ) {
619             $template->param(
620                 notes    => 'true',
621                 flagged  => 1,
622                 notesmsg => $flags->{'NOTES'}->{'message'}
623             );
624         }
625     }
626 }
627
628 my $amountold = $borrower->{flags}->{'CHARGES'}->{'message'} || 0;
629 my @temp = split( /\$/, $amountold );
630
631 my $CGIorganisations;
632 my $member_of_institution;
633 if ( C4::Context->preference("memberofinstitution") ) {
634     my $organisations = get_institutions();
635     my @orgs;
636     my %org_labels;
637     foreach my $organisation ( keys %$organisations ) {
638         push @orgs, $organisation;
639         $org_labels{$organisation} =
640           $organisations->{$organisation}->{'surname'};
641     }
642     $member_of_institution = 1;
643     $CGIorganisations      = CGI::popup_menu(
644         -id     => 'organisations',
645         -name   => 'organisations',
646         -labels => \%org_labels,
647         -values => \@orgs,
648     );
649 }
650
651 $amountold = $temp[1];
652
653 my $borrowercategory = GetBorrowercategory( $borrower->{'categorycode'} );
654 my $category_type = $borrowercategory->{'category_type'};
655 ( $template->param( adultborrower => 1 ) ) if ( $category_type eq 'A' );
656
657 $template->param(
658     issued_itemtypes_count_loop => $issued_itemtypes_loop,
659     findborrower                => $findborrower,
660     borrower                    => $borrower,
661     borrowernumber              => $borrowernumber,
662     branch                      => $branch,
663     printer                     => $printer,
664     printername                 => $printer,
665     firstname                   => $borrower->{'firstname'},
666     surname                     => $borrower->{'surname'},
667         dateexpiry => format_date($newexpiry),
668     expiry                      =>
669       $borrower->{'dateexpiry'},    #format_date($borrower->{'dateexpiry'}),
670     categorycode      => $borrower->{'categorycode'},
671     address     => $borrower->{'address'},
672     address2     => $borrower->{'address2'},
673     email      => $borrower->{'email'},
674         emailpro           => $borrower->{'emailpro'},
675     borrowernotes     => $borrower->{'borrowernotes'},
676     city              => $borrower->{'city'},
677     phone             => $borrower->{'phone'} || $borrower->{'mobile'},
678     cardnumber        => $borrower->{'cardnumber'},
679     amountold         => $amountold,
680     barcode           => $barcode,
681     stickyduedate     => $stickyduedate,
682     message           => $message,
683     CGIselectborrower => $CGIselectborrower,
684     todayissues       => \@todaysissues,
685     previssues        => \@previousissues,
686     inprocess         => $inprocess,
687     memberofinstution => $member_of_institution,
688     CGIorganisations  => $CGIorganisations,
689         circview => 1,
690         
691 );
692
693 # set return date if stickyduedate
694 if ($stickyduedate) {
695     $template->param(
696         duedatespec => $duedatespec,
697     );
698 }
699
700 #if ($branchcookie) {
701 #$cookie=[$cookie, $branchcookie, $printercookie];
702 #}
703
704 my ($picture, $dberror) = GetPatronImage($borrower->{'cardnumber'});
705 $template->param( picture => 1 ) if $picture;
706
707
708 $template->param(
709     SpecifyDueDate           => C4::Context->preference("SpecifyDueDate"),
710     CircAutocompl            => C4::Context->preference("CircAutocompl") ,
711     DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
712 );
713 output_html_with_http_headers $query, $cookie, $template->output;