Bug 16166: Improve L1 cache performance and safety
[koha.git] / circ / transferstoreceive.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
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21 use strict;
22 use warnings;
23 use CGI qw ( -utf8 );
24 use C4::Context;
25 use C4::Output;
26 use C4::Branch;     # GetBranches
27 use C4::Auth;
28 use Koha::DateUtils;
29 use C4::Biblio;
30 use C4::Circulation;
31 use C4::Members;
32 use Date::Calc qw(
33   Today
34   Add_Delta_Days
35   Date_to_Days
36 );
37
38 use C4::Koha;
39 use C4::Reserves;
40
41 my $input = new CGI;
42 my $itemnumber = $input->param('itemnumber');
43
44 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
45     {
46         template_name   => "circ/transferstoreceive.tt",
47         query           => $input,
48         type            => "intranet",
49         authnotrequired => 0,
50         flagsrequired   => { circulate => "circulate_remaining_permissions" },
51         debug           => 1,
52     }
53 );
54
55 # set the userenv branch
56 my $default = C4::Context->userenv->{'branch'};
57
58 # get the all the branches for reference
59 my $branches = GetBranches();
60 my @branchesloop;
61 my $latetransfers;
62 foreach my $br ( keys %$branches ) {
63     my @transferloop;
64     my %branchloop;
65     my @gettransfers =
66       GetTransfersFromTo( $branches->{$br}->{'branchcode'}, $default );
67
68     if (@gettransfers) {
69         $branchloop{'branchname'} = $branches->{$br}->{'branchname'};
70         $branchloop{'branchcode'} = $branches->{$br}->{'branchcode'};
71         foreach my $num (@gettransfers) {
72             my %getransf;
73
74             my ( $sent_year, $sent_month, $sent_day ) = split "-",
75               $num->{'datesent'};
76             $sent_day = ( split " ", $sent_day )[0];
77             ( $sent_year, $sent_month, $sent_day ) =
78               Add_Delta_Days( $sent_year, $sent_month, $sent_day,
79                 C4::Context->preference('TransfersMaxDaysWarning'));
80             my $calcDate = Date_to_Days( $sent_year, $sent_month, $sent_day );
81             my $today    = Date_to_Days(&Today);
82                         my $diff = $today - $calcDate;
83
84             if ($today > $calcDate) {
85                                 $latetransfers = 1;
86                 $getransf{'messcompa'} = 1;
87                                 $getransf{'diff'} = $diff;
88             }
89             my $gettitle     = GetBiblioFromItemNumber( $num->{'itemnumber'} );
90             my $itemtypeinfo = getitemtypeinfo( (C4::Context->preference('item-level_itypes')) ? $gettitle->{'itype'} : $gettitle->{'itemtype'} );
91
92             $getransf{'datetransfer'} = $num->{'datesent'};
93             $getransf{'itemtype'} = $itemtypeinfo ->{'description'};
94                         foreach (qw(title author biblionumber itemnumber barcode homebranch holdingbranch itemcallnumber)) {
95                 $getransf{$_} = $gettitle->{$_};
96                         }
97
98             my $record = GetMarcBiblio($gettitle->{'biblionumber'});
99             $getransf{'subtitle'} = GetRecordValue('subtitle', $record, GetFrameworkCode($gettitle->{'biblionumber'}));
100
101             # we check if we have a reserv for this transfer
102             my @checkreserv = GetReservesFromItemnumber($num->{'itemnumber'});
103             if ( $checkreserv[0] ) {
104                 my $getborrower = C4::Members::GetMember( borrowernumber => $checkreserv[1] );
105                 $getransf{'borrowernum'}       = $getborrower->{'borrowernumber'};
106                 $getransf{'borrowername'}      = $getborrower->{'surname'};
107                 $getransf{'borrowerfirstname'} = $getborrower->{'firstname'};
108                 $getransf{'borrowermail'}      = $getborrower->{'email'} if $getborrower->{'email'};
109                 $getransf{'borrowerphone'}     = $getborrower->{'phone'};
110             }
111             push( @transferloop, \%getransf );
112         }
113
114       #                 If we have a return of reservloop we put it in the branchloop sequence
115         $branchloop{'reserv'} = \@transferloop;
116     }
117     push( @branchesloop, \%branchloop ) if %branchloop;
118 }
119
120 $template->param(
121     branchesloop => \@branchesloop,
122     show_date    => output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }),
123         TransfersMaxDaysWarning => C4::Context->preference('TransfersMaxDaysWarning'),
124         latetransfers => $latetransfers ? 1 : 0,
125 );
126
127 output_html_with_http_headers $input, $cookie, $template->output;
128