Bug 17843: Replace C4::Koha::getitemtypeinfo with Koha::ItemTypes
[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::Auth;
27 use C4::Biblio;
28 use C4::Circulation;
29 use C4::Members;
30 use Date::Calc qw(
31   Today
32   Add_Delta_Days
33   Date_to_Days
34 );
35
36 use C4::Koha;
37 use C4::Reserves;
38 use Koha::Items;
39 use Koha::ItemTypes;
40 use Koha::Libraries;
41 use Koha::DateUtils;
42 use Koha::BiblioFrameworks;
43
44 my $input = new CGI;
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         authnotrequired => 0,
53         flagsrequired   => { circulate => "circulate_remaining_permissions" },
54         debug           => 1,
55     }
56 );
57
58 # set the userenv branch
59 my $default = C4::Context->userenv->{'branch'};
60
61 # get the all the branches for reference
62 my $libraries = Koha::Libraries->search({}, { order_by => 'branchname' });
63 my @branchesloop;
64 my $latetransfers;
65 while ( my $library = $libraries->next ) {
66     my @transferloop;
67     my %branchloop;
68     my @gettransfers =
69       GetTransfersFromTo( $library->branchcode, $default );
70
71     if (@gettransfers) {
72         $branchloop{'branchname'} = $library->branchname;
73         $branchloop{'branchcode'} = $library->branchcode;
74         foreach my $num (@gettransfers) {
75             my %getransf;
76
77             my ( $sent_year, $sent_month, $sent_day ) = split "-",
78               $num->{'datesent'};
79             $sent_day = ( split " ", $sent_day )[0];
80             ( $sent_year, $sent_month, $sent_day ) =
81               Add_Delta_Days( $sent_year, $sent_month, $sent_day,
82                 C4::Context->preference('TransfersMaxDaysWarning'));
83             my $calcDate = Date_to_Days( $sent_year, $sent_month, $sent_day );
84             my $today    = Date_to_Days(&Today);
85                         my $diff = $today - $calcDate;
86
87             if ($today > $calcDate) {
88                                 $latetransfers = 1;
89                 $getransf{'messcompa'} = 1;
90                                 $getransf{'diff'} = $diff;
91             }
92             my $gettitle     = GetBiblioFromItemNumber( $num->{'itemnumber'} );
93             my $itemtype = Koha::ItemTypes->find( (C4::Context->preference('item-level_itypes')) ? $gettitle->{'itype'} : $gettitle->{'itemtype'} );
94
95             $getransf{'datetransfer'} = $num->{'datesent'};
96             $getransf{'itemtype'} = $itemtype->description; # FIXME Should not it be translated_description?
97                         foreach (qw(title author biblionumber itemnumber barcode homebranch holdingbranch itemcallnumber)) {
98                 $getransf{$_} = $gettitle->{$_};
99                         }
100
101             my $record = GetMarcBiblio($gettitle->{'biblionumber'});
102             $getransf{'subtitle'} = GetRecordValue('subtitle', $record, GetFrameworkCode($gettitle->{'biblionumber'}));
103
104             # we check if we have a reserv for this transfer
105             my $item = Koha::Items->find( $num->{itemnumber} );
106             my $holds = $item->current_holds;
107             if ( my $first_hold = $holds->next ) {
108                 my $getborrower = C4::Members::GetMember( borrowernumber => $first_hold->borrowernumber );
109                 $getransf{'borrowernum'}       = $getborrower->{'borrowernumber'};
110                 $getransf{'borrowername'}      = $getborrower->{'surname'};
111                 $getransf{'borrowerfirstname'} = $getborrower->{'firstname'};
112                 $getransf{'borrowermail'}      = $getborrower->{'email'} if $getborrower->{'email'};
113                 $getransf{'borrowerphone'}     = $getborrower->{'phone'};
114             }
115             push( @transferloop, \%getransf );
116         }
117
118       #                 If we have a return of reservloop we put it in the branchloop sequence
119         $branchloop{'reserv'} = \@transferloop;
120     }
121     push( @branchesloop, \%branchloop ) if %branchloop;
122 }
123
124 $template->param(
125     branchesloop => \@branchesloop,
126     show_date    => output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }),
127         TransfersMaxDaysWarning => C4::Context->preference('TransfersMaxDaysWarning'),
128         latetransfers => $latetransfers ? 1 : 0,
129 );
130
131 # Checking if there is a Fast Cataloging Framework
132 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
133
134 output_html_with_http_headers $input, $cookie, $template->output;
135