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