Markup corrections and standardizations.
[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::Dates qw/format_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 use C4::Items;
39
40 my $input = new CGI;
41
42 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
43     {
44         template_name   => "circ/transferstodo.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 $item = $input->param('itemnumber');
57 my $fbr  = $input->param('fbr');
58 my $tbr  = $input->param('tbr');
59
60 # If we have a return of the form dotransfer, we launch the subroutine dotransfer
61 if ($item) {
62     C4::Circulation::Circ2::ModItemTransfer( $item, $fbr, $tbr );
63 }
64
65 # get the all the branches for reference
66 my $branches = GetBranches();
67
68 my @branchesloop;
69 foreach my $br ( keys %$branches ) {
70     my @reservloop;
71     my %branchloop;
72     my @getreserves =
73       GetReservesToBranch( $branches->{$br}->{'branchcode'} );
74     if (@getreserves) {
75         $branchloop{'branchname'} = $branches->{$br}->{'branchname'};
76         $branchloop{'branchcode'} = $branches->{$br}->{'branchcode'};
77         foreach my $num (@getreserves) {
78             my %getreserv;
79             my $gettitle     = GetBiblioFromItemNumber( $num->{'itemnumber'} );
80 #             use Data::Dumper;
81 #             warn Dumper($gettitle);
82             my $itemtypeinfo = getitemtypeinfo( $gettitle->{'itemtype'} );
83             if ( $gettitle->{'holdingbranch'} eq $default ) {
84                 my $getborrower =
85                   GetMemberDetails( $num->{'borrowernumber'} );
86                 $getreserv{'reservedate'} =
87                   format_date( $num->{'reservedate'} );
88                 my ( $reserve_year, $reserve_month, $reserve_day ) = split /-/,
89                   $num->{'reservedate'};
90                 ( $reserve_year, $reserve_month, $reserve_day ) =
91                   Add_Delta_Days( $reserve_year, $reserve_month, $reserve_day,
92                     C4::Context->preference('ReservesMaxPickUpDelay'));
93                 my $calcDate =
94                   Date_to_Days( $reserve_year, $reserve_month, $reserve_day );
95                 my $today   = Date_to_Days(&Today);
96                 my $warning = ( $today > $calcDate );
97
98                 if ( $warning > 0 ) {
99                     $getreserv{'messcompa'} = 1;
100                 }
101                 $getreserv{'title'}          = $gettitle->{'title'};
102                 $getreserv{'biblionumber'}   = $gettitle->{'biblionumber'};
103                 $getreserv{'itemnumber'}     = $gettitle->{'itemnumber'};
104                 $getreserv{'barcode'}        = $gettitle->{'barcode'};
105                 $getreserv{'itemtype'}       = $itemtypeinfo->{'description'};
106                 $getreserv{'holdingbranch'}  = $gettitle->{'holdingbranch'};
107                 $getreserv{'itemcallnumber'} = $gettitle->{'itemcallnumber'};
108                 $getreserv{'borrowernum'}    = $getborrower->{'borrowernumber'};
109                 $getreserv{'borrowername'}   = $getborrower->{'surname'};
110                 $getreserv{'borrowerfirstname'} = $getborrower->{'firstname'};
111                 $getreserv{'borrowermail'} = $getborrower->{'emailaddress'};
112                 $getreserv{'borrowerphone'} = $getborrower->{'phone'};
113                 push( @reservloop, \%getreserv );
114             }
115         }
116
117       #                 If we have a return of reservloop we put it in the branchloop sequence
118         if (@reservloop) {
119             $branchloop{'reserv'} = \@reservloop;
120         }
121         #               else, we unset the value of the branchcode .
122         else {
123             $branchloop{'branchcode'} = 0;
124         }
125     }
126     push( @branchesloop, \%branchloop ) if %branchloop;
127 }
128
129 $template->param(
130     branchesloop => \@branchesloop,
131     show_date    => format_date(C4::Dates->today('iso')),
132 );
133
134 output_html_with_http_headers $input, $cookie, $template->output;