circulation cleaning continued: bufixing
[koha-ffzg.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 CGI;
24 use C4::Context;
25 use C4::Output;
26 use C4::Branch;
27 use C4::Auth;
28 use C4::Date;
29 use C4::Biblio;
30 use C4::Circulation;
31 use C4::Members;
32 use C4::Interface::CGI::Output;
33 use Date::Calc qw(
34   Today
35   Add_Delta_Days
36   Date_to_Days
37 );
38
39 use C4::Koha;
40 use C4::Reserves2;
41
42 my $input = new CGI;
43
44 my $theme = $input->param('theme');    # only used if allowthemeoverride is set
45 my $itemnumber = $input->param('itemnumber');
46 my $todaysdate = join "-", &Today;
47
48 # if we have a resturn of the form to delete the transfer, we launch the subrroutine
49 if ($itemnumber) {
50     C4::Circulation::Circ2::DeleteTransfer($itemnumber);
51 }
52
53 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
54     {
55         template_name   => "circ/currenttransfers.tmpl",
56         query           => $input,
57         type            => "intranet",
58         authnotrequired => 0,
59         flagsrequired   => { circulate => 1 },
60         debug           => 1,
61     }
62 );
63
64 # set the userenv branch
65 my $default = C4::Context->userenv->{'branch'};
66
67 # get the all the branches for reference
68 my $branches = GetBranches();
69 my @branchesloop;
70 foreach my $br ( keys %$branches ) {
71     my @transferloop;
72     my %branchloop;
73     $branchloop{'branchname'} = $branches->{$br}->{'branchname'};
74     $branchloop{'branchcode'} = $branches->{$br}->{'branchcode'};
75     my @gettransfers =
76       GetTransfersFromTo( $branches->{$br}->{'branchcode'}, $default );
77
78     if (@gettransfers) {
79         foreach my $num (@gettransfers) {
80             my %getransf;
81             my %env;
82
83             my ( $sent_year, $sent_month, $sent_day ) = split "-",
84               $num->{'datesent'};
85             $sent_day = ( split " ", $sent_day )[0];
86             ( $sent_year, $sent_month, $sent_day ) =
87               Add_Delta_Days( $sent_year, $sent_month, $sent_day,
88                 C4::Context->preference('TransfersMaxDaysWarning'));
89             my $calcDate = Date_to_Days( $sent_year, $sent_month, $sent_day );
90             my $today    = Date_to_Days(&Today);
91             my $warning  = ( $today > $calcDate );
92
93             if ( $warning > 0 ) {
94                 $getransf{'messcompa'} = 1;
95             }
96             my $gettitle     = GetBiblioFromItemNumber( $num->{'itemnumber'} );
97             my $itemtypeinfo = getitemtypeinfo( $gettitle->{'itemtype'} );
98
99             $getransf{'title'}        = $gettitle->{'title'};
100             $getransf{'datetransfer'} = format_date( $num->{'datesent'} );
101             $getransf{'biblionumber'} = $gettitle->{'biblionumber'};
102             $getransf{'itemnumber'}   = $gettitle->{'itemnumber'};
103             $getransf{'barcode'}      = $gettitle->{'barcode'};
104             $getransf{'itemtype'}       = $itemtypeinfo->{'description'};
105             $getransf{'homebranch'}     = $gettitle->{'homebranch'};
106             $getransf{'holdingbranch'}  = $gettitle->{'holdingbranch'};
107             $getransf{'itemcallnumber'} = $gettitle->{'itemcallnumber'};
108
109             #                           we check if we have a reserv for this transfer
110             my @checkreserv = GetReservations( $num->{'itemnumber'} );
111             if ( $checkreserv[0] ) {
112                 my $getborrower =
113                   GetMemberDetails( $checkreserv[1] );
114                 $getransf{'borrowernum'}  = $getborrower->{'borrowernumber'};
115                 $getransf{'borrowername'} = $getborrower->{'surname'};
116                 $getransf{'borrowerfirstname'} = $getborrower->{'firstname'};
117                 if ( $getborrower->{'emailaddress'} ) {
118                     $getransf{'borrowermail'} = $getborrower->{'emailaddress'};
119                 }
120                 $getransf{'borrowerphone'} = $getborrower->{'phone'};
121
122             }
123             push( @transferloop, \%getransf );
124         }
125
126       #                 If we have a return of reservloop we put it in the branchloop sequence
127         $branchloop{'reserv'} = \@transferloop;
128     }
129     else {
130
131 #       if we don't have a retrun from reservestobranch we unset branchname and branchcode
132         $branchloop{'branchname'} = 0;
133         $branchloop{'branchcode'} = 0;
134     }
135     push( @branchesloop, \%branchloop );
136 }
137
138 $template->param(
139     branchesloop => \@branchesloop,
140     show_date    => format_date($todaysdate),
141 );
142
143 output_html_with_http_headers $input, $cookie, $template->output;
144