new dev : create 3 new program for circulation :
[koha.git] / circ / waitingreservestransfers.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 # Copyright 2000-2002 Katipo Communications
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA  02111-1307 USA
21
22 use strict;
23 use C4::Context;
24 use C4::Output;
25 use CGI;
26 use HTML::Template;
27 use C4::Auth;
28 use C4::Date;
29 use C4::Circulation::Circ2;
30 use Date::Manip;
31 use C4::Koha;
32 use C4::Biblio;
33
34 my $input = new CGI;
35
36 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
37
38 my ($template, $loggedinuser, $cookie)
39       = get_template_and_user({template_name => "circ/waitingreservestransfers.tmpl",
40                                          query => $input,
41                                          type => "intranet",
42                                          authnotrequired => 0,
43                                          flagsrequired => {borrowers => 1},
44                                          debug => 1,
45                                          });
46
47
48 # set the userenv branch
49 my $default = C4::Context->userenv->{'branch'};
50
51
52 my @datearr = localtime(time());
53 my $todaysdate = (1900+$datearr[5]).'-'.sprintf ("%0.2d", ($datearr[4]+1)).'-'.sprintf ("%0.2d", $datearr[3]);
54
55 my $item=$input->param('itemnumber');
56 my $fbr=$input->param('fbr');
57 my $tbr=$input->param('tbr');
58 # If we have a return of the form dotransfer, we launch the subroutine dotransfer
59 if ($item){
60         C4::Circulation::Circ2::dotransfer($item,$fbr,$tbr);
61 }
62
63 # get the all the branches for reference
64 my $branches = getbranches();
65 my @branchesloop;
66 foreach my $br (keys %$branches) {
67         my @reservloop;
68         my %branchloop;
69         $branchloop{'branchname'} = $branches->{$br}->{'branchname'};
70         $branchloop{'branchcode'} = $branches->{$br}->{'branchcode'};
71         my @getreserves = GetReservesToBranch($branches->{$br}->{'branchcode'},$default);
72                 if (@getreserves){
73                 foreach my $num (@getreserves) {
74                         my %getreserv;
75                         my %env;
76                         my $gettitle = getiteminformation(\%env,$num->{'itemnumber'});
77                         if ($gettitle->{'holdingbranch'} eq $default){
78                                 my $getborrower = getpatroninformation (\%env,$num->{'borrowernumber'});
79                                 $getreserv{'reservedate'} = format_date($num->{'reservedate'});
80                                 my $calcDate=DateCalc($num->{'reservedate'},"+".C4::Context->preference('MaxDaysRecoveryReserves')."  days");
81                                 my $warning=Date_Cmp(ParseDate("today"),$calcDate);
82                                 if ($warning>0){
83                                         $getreserv{'messcompa'} = 1;
84                                 }
85                                 $getreserv{'title'} = $gettitle->{'title'};
86                                 $getreserv{'biblionumber'} = $gettitle->{'biblionumber'};
87                                 $getreserv{'itemnumber'} = $gettitle->{'itemnumber'};
88                                 $getreserv{'barcode'} = $gettitle->{'barcode'};
89 #                               $getreserv{'itemtype'} = get_iteminfos_of($gettitle->{'itemtype'}->{'description'});
90                                 $getreserv{'holdingbranch'} = $gettitle->{'holdingbranch'};
91                                 $getreserv{'itemcallnumber'} = $gettitle->{'itemcallnumber'};
92                                 $getreserv{'borrowernum'} = $getborrower->{'borrowernumber'};
93                                 $getreserv{'borrowername'} = $getborrower->{'surname'};
94                                 $getreserv{'borrowerfirstname'} =  $getborrower->{'firstname'} ;
95                                 if ($getborrower->{'emailaddress'}){
96                                         $getreserv{'borrowermail'} =  $getborrower->{'emailaddress'} ;
97                                 }
98                                 $getreserv{'borrowerphone'} = $getborrower->{'phone'};
99                                 push(@reservloop, \%getreserv);
100                         }
101                 }
102 #               If we have a return of reservloop we put it in the branchloop sequence
103                 if (@reservloop){
104                 $branchloop{'reserv'} = \@reservloop ;
105                 }
106 #               else, we unset the value of the branchcode .
107                 else{
108                 $branchloop{'branchcode'} = 0;
109                 }
110         }
111         else {
112 #       if we don't have a retrun from reservestobranch we unset branchname and branchcode
113         $branchloop{'branchname'} = 0;
114         $branchloop{'branchcode'} = 0;
115         }
116         push(@branchesloop, \%branchloop);
117 }
118
119         $template->param( branchesloop  => \@branchesloop,
120                         show_date       => format_date($todaysdate)     
121                          );
122         
123         print "Content-Type: text/html\n\n", $template->output;
124
125
126