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