4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
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.
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.
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>.
24 use C4::Output qw( output_html_with_http_headers );
25 use C4::Auth qw( get_template_and_user );
26 use C4::Circulation qw( GetTransfersFromTo );
28 use Date::Calc qw( Add_Delta_Days Date_to_Days Today );
34 use Koha::DateUtils qw( dt_from_string );
35 use Koha::BiblioFrameworks;
39 my $itemnumber = $input->param('itemnumber');
41 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
43 template_name => "circ/transferstoreceive.tt",
46 flagsrequired => { circulate => "circulate_remaining_permissions" },
50 # set the userenv branch
51 my $default = C4::Context->userenv->{'branch'};
53 # get the all the branches for reference
54 my $libraries = Koha::Libraries->search({}, { order_by => 'branchname' });
57 while ( my $library = $libraries->next ) {
61 GetTransfersFromTo( $library->branchcode, $default );
64 $branchloop{'branchname'} = $library->branchname;
65 $branchloop{'branchcode'} = $library->branchcode;
66 foreach my $num (@gettransfers) {
69 my ( $sent_year, $sent_month, $sent_day ) = split "-",
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;
79 if ($today > $calcDate) {
81 $getransf{'messcompa'} = 1;
82 $getransf{'diff'} = $diff;
85 my $item = Koha::Items->find( $num->{itemnumber} );
86 my $biblio = $item->biblio;
87 my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype );
89 $getransf{'datetransfer'} = $num->{'datesent'};
90 $getransf{'itemtype'} = $itemtype->description; # FIXME Should not it be translated_description?
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,
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 );
113 # check for a recall for this transfer
114 if ( C4::Context->preference('UseRecalls') ) {
115 my $recall = $item->recall;
116 if ( defined $recall ) {
117 $getransf{recall} = $recall;
121 push( @transferloop, \%getransf );
124 # If we have a return of reservloop we put it in the branchloop sequence
125 $branchloop{'reserv'} = \@transferloop;
127 push( @branchesloop, \%branchloop ) if %branchloop;
131 branchesloop => \@branchesloop,
132 show_date => dt_from_string,
133 TransfersMaxDaysWarning => C4::Context->preference('TransfersMaxDaysWarning'),
134 latetransfers => $latetransfers ? 1 : 0,
137 # Checking if there is a Fast Cataloging Framework
138 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
140 output_html_with_http_headers $input, $cookie, $template->output;