(bug #3353) permit librarians to cancel orders
[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 under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA  02111-1307 USA
20
21 use strict;
22 use warnings;
23 use CGI;
24 use C4::Context;
25 use C4::Output;
26 use C4::Branch;     # GetBranches
27 use C4::Auth;
28 use C4::Dates qw/format_date/;
29 use C4::Biblio;
30 use C4::Circulation;
31 use C4::Members;
32 use Date::Calc qw(
33   Today
34   Add_Delta_Days
35   Date_to_Days
36 );
37
38 use C4::Koha;
39 use C4::Reserves;
40
41 my $input = new CGI;
42 my $itemnumber = $input->param('itemnumber');
43
44 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
45     {
46         template_name   => "circ/transferstoreceive.tmpl",
47         query           => $input,
48         type            => "intranet",
49         authnotrequired => 0,
50         flagsrequired   => { circulate => "circulate_remaining_permissions" },
51         debug           => 1,
52     }
53 );
54
55 # set the userenv branch
56 my $default = C4::Context->userenv->{'branch'};
57
58 # get the all the branches for reference
59 my $branches = GetBranches();
60 my @branchesloop;
61 foreach my $br ( keys %$branches ) {
62     my @transferloop;
63     my %branchloop;
64     my @gettransfers =
65       GetTransfersFromTo( $branches->{$br}->{'branchcode'}, $default );
66
67     if (@gettransfers) {
68         $branchloop{'branchname'} = $branches->{$br}->{'branchname'};
69         $branchloop{'branchcode'} = $branches->{$br}->{'branchcode'};
70         foreach my $num (@gettransfers) {
71             my %getransf;
72
73             my ( $sent_year, $sent_month, $sent_day ) = split "-",
74               $num->{'datesent'};
75             $sent_day = ( split " ", $sent_day )[0];
76             ( $sent_year, $sent_month, $sent_day ) =
77               Add_Delta_Days( $sent_year, $sent_month, $sent_day,
78                 C4::Context->preference('TransfersMaxDaysWarning'));
79             my $calcDate = Date_to_Days( $sent_year, $sent_month, $sent_day );
80             my $today    = Date_to_Days(&Today);
81
82             if ($today > $calcDate) {
83                 $getransf{'messcompa'} = 1;
84             }
85             my $gettitle     = GetBiblioFromItemNumber( $num->{'itemnumber'} );
86             my $itemtypeinfo = getitemtypeinfo( $gettitle->{'itemtype'} );
87
88             $getransf{'datetransfer'} = format_date( $num->{'datesent'} );
89             $getransf{'itemtype'} = $itemtypeinfo->{'description'};
90                         foreach (qw(title biblionumber itemnumber barcode homebranch holdingbranch itemcallnumber)) {
91                 $getransf{$_} = $gettitle->{$_};
92                         }
93
94             # we check if we have a reserv for this transfer
95             my @checkreserv = GetReservesFromItemnumber($num->{'itemnumber'} );
96             if ( $checkreserv[0] ) {
97                 my $getborrower = GetMemberDetails( $checkreserv[1] );
98                 $getransf{'borrowernum'}       = $getborrower->{'borrowernumber'};
99                 $getransf{'borrowername'}      = $getborrower->{'surname'};
100                 $getransf{'borrowerfirstname'} = $getborrower->{'firstname'};
101                 $getransf{'borrowermail'}      = $getborrower->{'emailaddress'} if $getborrower->{'emailaddress'};
102                 $getransf{'borrowerphone'}     = $getborrower->{'phone'};
103             }
104             push( @transferloop, \%getransf );
105         }
106
107       #                 If we have a return of reservloop we put it in the branchloop sequence
108         $branchloop{'reserv'} = \@transferloop;
109     }
110     push( @branchesloop, \%branchloop ) if %branchloop;
111 }
112
113 $template->param(
114     branchesloop => \@branchesloop,
115     show_date    => format_date(C4::Dates->today('iso')),
116         'dateformat_' . (C4::Context->preference("dateformat") || '') => 1,
117 );
118
119 output_html_with_http_headers $input, $cookie, $template->output;
120