merging katipo changes...
[koha.git] / circ / currenttransfers.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::Search;
33 use C4::Reserves2;
34
35 my $input = new CGI;
36
37 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
38 my $itemnumber = $input->param('itemnumber');
39 # if we have a resturn of the form to delete the transfer, we launch the subrroutine
40 if ($itemnumber){
41         C4::Circulation::Circ2::DeleteTransfer($itemnumber);
42 }
43
44 my ($template, $loggedinuser, $cookie)
45       = get_template_and_user({template_name => "circ/currenttransfers.tmpl",
46                                          query => $input,
47                                          type => "intranet",
48                                          authnotrequired => 0,
49                                          flagsrequired => {borrowers => 1},
50                                          debug => 1,
51                                          });
52
53
54 # set the userenv branch
55 my $default = C4::Context->userenv->{'branch'};
56
57
58 my @datearr = localtime(time());
59 my $todaysdate = (1900+$datearr[5]).'-'.sprintf ("%0.2d", ($datearr[4]+1)).'-'.sprintf ("%0.2d", $datearr[3]);
60
61 # get the all the branches for reference
62 my $branches = getbranches();
63 my @branchesloop;
64 foreach my $br (keys %$branches) {
65         my @transferloop;
66         my %branchloop;
67         $branchloop{'branchname'} = $branches->{$br}->{'branchname'};
68         $branchloop{'branchcode'} = $branches->{$br}->{'branchcode'};
69         # # # # # # # # # # # # # # # # # # # # # # 
70         my @gettransfers = GetTransfersFromBib($branches->{$br}->{'branchcode'},$default);
71                 if (@gettransfers){
72                 foreach my $num (@gettransfers) {
73                         my %getransf;
74                         my %env;
75                         my $calcDate=DateCalc($num->{'datesent'},"+".C4::Context->preference('TransfersMaxDaysWarning')."  days");
76                         my $warning=Date_Cmp(ParseDate("today"),$calcDate);
77                         if ($warning>0){
78                                 $getransf{'messcompa'} = 1;
79                         }
80                         my $gettitle = getiteminformation(\%env,$num->{'itemnumber'});
81                         my $itemtypeinfo = getitemtypeinfo($gettitle->{'itemtype'});
82                         
83                                 $getransf{'title'} = $gettitle->{'title'};
84                                 $getransf{'datetransfer'} = format_date($num->{'datesent'});
85                                 $getransf{'biblionumber'} = $gettitle->{'biblionumber'};
86                                 $getransf{'itemnumber'} = $gettitle->{'itemnumber'};
87                                 $getransf{'barcode'} = $gettitle->{'barcode'};
88                                 $getransf{'itemtype'} = $itemtypeinfo->{'description'};
89                                 $getransf{'homebranch'} = $gettitle->{'homebranch'};
90                                 $getransf{'holdingbranch'} = $gettitle->{'holdingbranch'};
91                                 $getransf{'itemcallnumber'} = $gettitle->{'itemcallnumber'};
92
93 #                               we check if we have a reserv for this transfer
94                                 my @checkreserv = FastFindReserves($num->{'itemnumber'});
95                                 if (@checkreserv[0]){
96                                         my $getborrower = getpatroninformation (\%env,$checkreserv[1]);
97                                         $getransf{'borrowernum'} = $getborrower->{'borrowernumber'};
98                                         $getransf{'borrowername'} = $getborrower->{'surname'};
99                                         $getransf{'borrowerfirstname'} =  $getborrower->{'firstname'};
100                                                 if ($getborrower->{'emailaddress'}){
101                                                         $getransf{'borrowermail'} =  $getborrower->{'emailaddress'} ;
102                                                 }
103                                         $getransf{'borrowerphone'} = $getborrower->{'phone'};   
104
105                                 }
106                                 push(@transferloop, \%getransf);
107                         }
108 #               If we have a return of reservloop we put it in the branchloop sequence
109                 $branchloop{'reserv'} = \@transferloop ;
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         $template->param( branchesloop  => \@branchesloop,
119                         show_date       => format_date($todaysdate)     
120                          );
121         
122         print "Content-Type: text/html\n\n", $template->output;
123
124
125