Bug 28591: Don't pass debug to get_template_and_user
[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 Modern::Perl;
22 use CGI qw ( -utf8 );
23 use C4::Context;
24 use C4::Output;
25 use C4::Auth;
26 use C4::Biblio;
27 use C4::Circulation;
28 use C4::Members;
29 use Date::Calc qw(
30   Today
31   Add_Delta_Days
32   Date_to_Days
33 );
34
35 use C4::Koha;
36 use C4::Reserves;
37 use Koha::Items;
38 use Koha::ItemTypes;
39 use Koha::Libraries;
40 use Koha::DateUtils;
41 use Koha::BiblioFrameworks;
42 use Koha::Patrons;
43
44 my $input = CGI->new;
45 my $itemnumber = $input->param('itemnumber');
46
47 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
48     {
49         template_name   => "circ/transferstoreceive.tt",
50         query           => $input,
51         type            => "intranet",
52         flagsrequired   => { circulate => "circulate_remaining_permissions" },
53     }
54 );
55
56 # set the userenv branch
57 my $default = C4::Context->userenv->{'branch'};
58
59 # get the all the branches for reference
60 my $libraries = Koha::Libraries->search({}, { order_by => 'branchname' });
61 my @branchesloop;
62 my $latetransfers;
63 while ( my $library = $libraries->next ) {
64     my @transferloop;
65     my %branchloop;
66     my @gettransfers =
67       GetTransfersFromTo( $library->branchcode, $default );
68
69     if (@gettransfers) {
70         $branchloop{'branchname'} = $library->branchname;
71         $branchloop{'branchcode'} = $library->branchcode;
72         foreach my $num (@gettransfers) {
73             my %getransf;
74
75             my ( $sent_year, $sent_month, $sent_day ) = split "-",
76               $num->{'datesent'};
77             $sent_day = ( split " ", $sent_day )[0];
78             ( $sent_year, $sent_month, $sent_day ) =
79               Add_Delta_Days( $sent_year, $sent_month, $sent_day,
80                 C4::Context->preference('TransfersMaxDaysWarning'));
81             my $calcDate = Date_to_Days( $sent_year, $sent_month, $sent_day );
82             my $today    = Date_to_Days(&Today);
83                         my $diff = $today - $calcDate;
84
85             if ($today > $calcDate) {
86                                 $latetransfers = 1;
87                 $getransf{'messcompa'} = 1;
88                                 $getransf{'diff'} = $diff;
89             }
90
91             my $item = Koha::Items->find( $num->{itemnumber} );
92             my $biblio = $item->biblio;
93             my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype );
94
95             $getransf{'datetransfer'} = $num->{'datesent'};
96             $getransf{'itemtype'} = $itemtype->description; # FIXME Should not it be translated_description?
97             %getransf = (
98                 %getransf,
99                 title          => $biblio->title,
100                 subtitle       => $biblio->subtitle,
101                 medium         => $biblio->medium,
102                 part_number    => $biblio->part_number,
103                 part_name      => $biblio->part_name,
104                 author         => $biblio->author,
105                 biblionumber   => $biblio->biblionumber,
106                 itemnumber     => $item->itemnumber,
107                 barcode        => $item->barcode,
108                 homebranch     => $item->homebranch,
109                 holdingbranch  => $item->holdingbranch,
110                 itemcallnumber => $item->itemcallnumber,
111             );
112
113             # we check if we have a reserv for this transfer
114             my $holds = $item->current_holds;
115             if ( my $first_hold = $holds->next ) {
116                 $getransf{patron} = Koha::Patrons->find( $first_hold->borrowernumber );
117             }
118             push( @transferloop, \%getransf );
119         }
120
121       #                 If we have a return of reservloop we put it in the branchloop sequence
122         $branchloop{'reserv'} = \@transferloop;
123     }
124     push( @branchesloop, \%branchloop ) if %branchloop;
125 }
126
127 $template->param(
128     branchesloop => \@branchesloop,
129     show_date    => output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }),
130     TransfersMaxDaysWarning => C4::Context->preference('TransfersMaxDaysWarning'),
131     latetransfers => $latetransfers ? 1 : 0,
132 );
133
134 # Checking if there is a Fast Cataloging Framework
135 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
136
137 output_html_with_http_headers $input, $cookie, $template->output;
138