Bug 18150 - CanItemBeReserved doesn't work with (IndependentBranches AND ! canreserve...
[koha.git] / circ / transferstoreceive.pl
blob20f14d11a3265b320d72da7fa335c452252e7065
1 #!/usr/bin/perl
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>.
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
36 use C4::Koha;
37 use C4::Reserves;
38 use Koha::Libraries;
39 use Koha::DateUtils;
40 use Koha::BiblioFrameworks;
42 my $input = new CGI;
43 my $itemnumber = $input->param('itemnumber');
45 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
47 template_name => "circ/transferstoreceive.tt",
48 query => $input,
49 type => "intranet",
50 authnotrequired => 0,
51 flagsrequired => { circulate => "circulate_remaining_permissions" },
52 debug => 1,
56 # set the userenv branch
57 my $default = C4::Context->userenv->{'branch'};
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 );
69 if (@gettransfers) {
70 $branchloop{'branchname'} = $library->branchname;
71 $branchloop{'branchcode'} = $library->branchcode;
72 foreach my $num (@gettransfers) {
73 my %getransf;
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;
85 if ($today > $calcDate) {
86 $latetransfers = 1;
87 $getransf{'messcompa'} = 1;
88 $getransf{'diff'} = $diff;
90 my $gettitle = GetBiblioFromItemNumber( $num->{'itemnumber'} );
91 my $itemtypeinfo = getitemtypeinfo( (C4::Context->preference('item-level_itypes')) ? $gettitle->{'itype'} : $gettitle->{'itemtype'} );
93 $getransf{'datetransfer'} = $num->{'datesent'};
94 $getransf{'itemtype'} = $itemtypeinfo ->{'description'};
95 foreach (qw(title author biblionumber itemnumber barcode homebranch holdingbranch itemcallnumber)) {
96 $getransf{$_} = $gettitle->{$_};
99 my $record = GetMarcBiblio($gettitle->{'biblionumber'});
100 $getransf{'subtitle'} = GetRecordValue('subtitle', $record, GetFrameworkCode($gettitle->{'biblionumber'}));
102 # we check if we have a reserv for this transfer
103 my @checkreserv = GetReservesFromItemnumber($num->{'itemnumber'});
104 if ( $checkreserv[0] ) {
105 my $getborrower = C4::Members::GetMember( borrowernumber => $checkreserv[1] );
106 $getransf{'borrowernum'} = $getborrower->{'borrowernumber'};
107 $getransf{'borrowername'} = $getborrower->{'surname'};
108 $getransf{'borrowerfirstname'} = $getborrower->{'firstname'};
109 $getransf{'borrowermail'} = $getborrower->{'email'} if $getborrower->{'email'};
110 $getransf{'borrowerphone'} = $getborrower->{'phone'};
112 push( @transferloop, \%getransf );
115 # If we have a return of reservloop we put it in the branchloop sequence
116 $branchloop{'reserv'} = \@transferloop;
118 push( @branchesloop, \%branchloop ) if %branchloop;
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,
128 # Checking if there is a Fast Cataloging Framework
129 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
131 output_html_with_http_headers $input, $cookie, $template->output;