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