removing all useless %env / $env
[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 C4::Branch; # GetBranches
27 use C4::Auth;
28 use C4::Date;
29 use C4::Circulation;
30 use C4::Reserves2;
31 use C4::Members;
32 use Date::Calc qw(
33   Today
34   Add_Delta_Days
35   Date_to_Days
36 );
37 use C4::Koha;
38 use C4::Biblio;
39
40 my $input = new CGI;
41
42 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
43     {
44         template_name   => "circ/waitingreservestransfers.tmpl",
45         query           => $input,
46         type            => "intranet",
47         authnotrequired => 0,
48         flagsrequired   => { circulate => 1 },
49         debug           => 1,
50     }
51 );
52
53 # set the userenv branch
54 my $default = C4::Context->userenv->{'branch'};
55
56 my @datearr    = localtime( time() );
57 my $todaysdate =
58     ( 1900 + $datearr[5] ) . '-'
59   . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) . '-'
60   . sprintf( "%0.2d", $datearr[3] );
61
62 my $item = $input->param('itemnumber');
63 my $fbr  = $input->param('fbr');
64 my $tbr  = $input->param('tbr');
65
66 # If we have a return of the form dotransfer, we launch the subroutine dotransfer
67 if ($item) {
68     C4::Circulation::Circ2::dotransfer( $item, $fbr, $tbr );
69 }
70
71 # get the all the branches for reference
72 my $branches = GetBranches();
73
74 my @branchesloop;
75 foreach my $br ( keys %$branches ) {
76     my @reservloop;
77     my %branchloop;
78     $branchloop{'branchname'} = $branches->{$br}->{'branchname'};
79     $branchloop{'branchcode'} = $branches->{$br}->{'branchcode'};
80     my @getreserves =
81       GetReservesToBranch( $branches->{$br}->{'branchcode'} );
82     if (@getreserves) {
83         foreach my $num (@getreserves) {
84             my %getreserv;
85             my $gettitle     = GetBiblioFromItemNumber( $num->{'itemnumber'} );
86 #             use Data::Dumper;
87 #             warn Dumper($gettitle);
88             warn "ITEM : ".$gettitle->{'title'};
89             my $itemtypeinfo = getitemtypeinfo( $gettitle->{'itemtype'} );
90             if ( $gettitle->{'holdingbranch'} eq $default ) {
91                 my $getborrower =
92                   GetMemberDetails( $num->{'borrowernumber'} );
93                 $getreserv{'reservedate'} =
94                   format_date( $num->{'reservedate'} );
95                 my ( $reserve_year, $reserve_month, $reserve_day ) = split /-/,
96                   $num->{'reservedate'};
97                 ( $reserve_year, $reserve_month, $reserve_day ) =
98                   Add_Delta_Days( $reserve_year, $reserve_month, $reserve_day,
99                     C4::Context->preference('ReservesMaxPickUpDelay'));
100                 my $calcDate =
101                   Date_to_Days( $reserve_year, $reserve_month, $reserve_day );
102                 my $today   = Date_to_Days(&Today);
103                 my $warning = ( $today > $calcDate );
104
105                 if ( $warning > 0 ) {
106                     $getreserv{'messcompa'} = 1;
107                 }
108                 $getreserv{'title'}          = $gettitle->{'title'};
109                 $getreserv{'biblionumber'}   = $gettitle->{'biblionumber'};
110                 $getreserv{'itemnumber'}     = $gettitle->{'itemnumber'};
111                 $getreserv{'barcode'}        = $gettitle->{'barcode'};
112                 $getreserv{'itemtype'}       = $itemtypeinfo->{'description'};
113                 $getreserv{'holdingbranch'}  = $gettitle->{'holdingbranch'};
114                 $getreserv{'itemcallnumber'} = $gettitle->{'itemcallnumber'};
115                 $getreserv{'borrowernum'}    = $getborrower->{'borrowernumber'};
116                 $getreserv{'borrowername'}   = $getborrower->{'surname'};
117                 $getreserv{'borrowerfirstname'} = $getborrower->{'firstname'};
118                 $getreserv{'borrowermail'} = $getborrower->{'emailaddress'};
119                 $getreserv{'borrowerphone'} = $getborrower->{'phone'};
120                 push( @reservloop, \%getreserv );
121                 warn "=".$getreserv{'title'}.">>".$gettitle->{'title'};
122             }
123         }
124
125       #                 If we have a return of reservloop we put it in the branchloop sequence
126         if (@reservloop) {
127             $branchloop{'reserv'} = \@reservloop;
128         }
129
130         #               else, we unset the value of the branchcode .
131         else {
132             $branchloop{'branchcode'} = 0;
133         }
134     }
135     else {
136
137 #       if we don't have a retrun from reservestobranch we unset branchname and branchcode
138         $branchloop{'branchname'} = 0;
139         $branchloop{'branchcode'} = 0;
140     }
141     push( @branchesloop, \%branchloop );
142 }
143
144 $template->param(
145     branchesloop => \@branchesloop,
146     show_date    => format_date($todaysdate)
147 );
148
149 print "Content-Type: text/html\n\n", $template->output;
150