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