Bug 18910: Revert "Bug 18152: Add tests"
[koha.git] / circ / transferstoreceive.pl
blobbf1a756e2904de60dfcbf62ec97a652bff6eab22
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::Items;
39 use Koha::Libraries;
40 use Koha::DateUtils;
41 use Koha::BiblioFrameworks;
43 my $input = new CGI;
44 my $itemnumber = $input->param('itemnumber');
46 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
48 template_name => "circ/transferstoreceive.tt",
49 query => $input,
50 type => "intranet",
51 authnotrequired => 0,
52 flagsrequired => { circulate => "circulate_remaining_permissions" },
53 debug => 1,
57 # set the userenv branch
58 my $default = C4::Context->userenv->{'branch'};
60 # get the all the branches for reference
61 my $libraries = Koha::Libraries->search({}, { order_by => 'branchname' });
62 my @branchesloop;
63 my $latetransfers;
64 while ( my $library = $libraries->next ) {
65 my @transferloop;
66 my %branchloop;
67 my @gettransfers =
68 GetTransfersFromTo( $library->branchcode, $default );
70 if (@gettransfers) {
71 $branchloop{'branchname'} = $library->branchname;
72 $branchloop{'branchcode'} = $library->branchcode;
73 foreach my $num (@gettransfers) {
74 my %getransf;
76 my ( $sent_year, $sent_month, $sent_day ) = split "-",
77 $num->{'datesent'};
78 $sent_day = ( split " ", $sent_day )[0];
79 ( $sent_year, $sent_month, $sent_day ) =
80 Add_Delta_Days( $sent_year, $sent_month, $sent_day,
81 C4::Context->preference('TransfersMaxDaysWarning'));
82 my $calcDate = Date_to_Days( $sent_year, $sent_month, $sent_day );
83 my $today = Date_to_Days(&Today);
84 my $diff = $today - $calcDate;
86 if ($today > $calcDate) {
87 $latetransfers = 1;
88 $getransf{'messcompa'} = 1;
89 $getransf{'diff'} = $diff;
91 my $gettitle = GetBiblioFromItemNumber( $num->{'itemnumber'} );
92 my $itemtypeinfo = getitemtypeinfo( (C4::Context->preference('item-level_itypes')) ? $gettitle->{'itype'} : $gettitle->{'itemtype'} );
94 $getransf{'datetransfer'} = $num->{'datesent'};
95 $getransf{'itemtype'} = $itemtypeinfo ->{'description'};
96 foreach (qw(title author biblionumber itemnumber barcode homebranch holdingbranch itemcallnumber)) {
97 $getransf{$_} = $gettitle->{$_};
100 my $record = GetMarcBiblio($gettitle->{'biblionumber'});
101 $getransf{'subtitle'} = GetRecordValue('subtitle', $record, GetFrameworkCode($gettitle->{'biblionumber'}));
103 # we check if we have a reserv for this transfer
104 my $item = Koha::Items->find( $num->{itemnumber} );
105 my $holds = $item->current_holds;
106 if ( my $first_hold = $holds->next ) {
107 my $getborrower = C4::Members::GetMember( borrowernumber => $first_hold->borrowernumber );
108 $getransf{'borrowernum'} = $getborrower->{'borrowernumber'};
109 $getransf{'borrowername'} = $getborrower->{'surname'};
110 $getransf{'borrowerfirstname'} = $getborrower->{'firstname'};
111 $getransf{'borrowermail'} = $getborrower->{'email'} if $getborrower->{'email'};
112 $getransf{'borrowerphone'} = $getborrower->{'phone'};
114 push( @transferloop, \%getransf );
117 # If we have a return of reservloop we put it in the branchloop sequence
118 $branchloop{'reserv'} = \@transferloop;
120 push( @branchesloop, \%branchloop ) if %branchloop;
123 $template->param(
124 branchesloop => \@branchesloop,
125 show_date => output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }),
126 TransfersMaxDaysWarning => C4::Context->preference('TransfersMaxDaysWarning'),
127 latetransfers => $latetransfers ? 1 : 0,
130 # Checking if there is a Fast Cataloging Framework
131 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
133 output_html_with_http_headers $input, $cookie, $template->output;