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