Bug 5949 : Popup alert when deleting items from basket, also change planning value...
[koha.git] / circ / waitingreserves.pl
blob9850114a24bace24046397eb0c0e49f8cd512543
1 #!/usr/bin/perl
3 # Copyright 2000-2002 Katipo Communications
4 # parts copyright 2010 BibLibre
6 # This file is part of Koha.
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.
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.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 use strict;
22 use warnings;
23 use CGI;
24 use C4::Context;
25 use C4::Output;
26 use C4::Branch; # GetBranchName
27 use C4::Auth;
28 use C4::Dates qw/format_date/;
29 use C4::Circulation;
30 use C4::Members;
31 use C4::Biblio;
32 use C4::Items;
34 use Date::Calc qw(
35 Today
36 Add_Delta_Days
37 Date_to_Days
39 use C4::Reserves;
40 use C4::Koha;
42 my $input = new CGI;
44 my $item = $input->param('itemnumber');
45 my $borrowernumber = $input->param('borrowernumber');
46 my $fbr = $input->param('fbr') || '';
47 my $tbr = $input->param('tbr') || '';
48 my $all_branches = $input->param('allbranches') || '';
50 my $cancel;
52 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
54 template_name => "circ/waitingreserves.tmpl",
55 query => $input,
56 type => "intranet",
57 authnotrequired => 0,
58 flagsrequired => { circulate => "circulate_remaining_permissions" },
59 debug => 1,
63 my $default = C4::Context->userenv->{'branch'};
65 # if we have a return from the form we launch the subroutine CancelReserve
66 if ($item) {
67 my ( $messages, $nextreservinfo ) = ModReserveCancelAll( $item, $borrowernumber );
68 # if we have a result
69 if ($nextreservinfo) {
70 my $borrowerinfo = GetMemberDetails( $nextreservinfo );
71 my $iteminfo = GetBiblioFromItemNumber($item);
72 if ( $messages->{'transfert'} ) {
73 $template->param(
74 messagetransfert => $messages->{'transfert'},
75 branchname => GetBranchName($messages->{'transfert'}),
79 $template->param(
80 message => 1,
81 nextreservnumber => $nextreservinfo,
82 nextreservsurname => $borrowerinfo->{'surname'},
83 nextreservfirstname => $borrowerinfo->{'firstname'},
84 nextreservitem => $item,
85 nextreservtitle => $iteminfo->{'title'},
86 waiting => ($messages->{'waiting'}) ? 1 : 0,
90 # if the document is not in his homebranch location and there is not reservation after, we transfer it
91 if ($fbr ne $tbr and not $nextreservinfo) {
92 ModItemTransfer( $item, $fbr, $tbr );
95 if ( C4::Context->preference('IndependantBranches') ) {
96 undef $all_branches;
97 } else {
98 $template->param( all_branches_link => $input->url . '?allbranches=1&' . $input->query_string )
99 unless $all_branches;
102 my (@reservloop, @overloop);
103 my ($reservcount, $overcount);
104 my @getreserves = $all_branches ? GetReservesForBranch() : GetReservesForBranch($default);
105 # get reserves for the branch we are logged into, or for all branches
107 my $today = Date_to_Days(&Today);
108 foreach my $num (@getreserves) {
109 next unless ($num->{'waitingdate'} && $num->{'waitingdate'} ne '0000-00-00');
110 my %getreserv;
111 my $gettitle = GetBiblioFromItemNumber( $num->{'itemnumber'} );
112 # fix up item type for display
113 $gettitle->{'itemtype'} = C4::Context->preference('item-level_itypes') ? $gettitle->{'itype'} : $gettitle->{'itemtype'};
114 my $getborrower = GetMemberDetails( $num->{'borrowernumber'} );
115 my $itemtypeinfo = getitemtypeinfo( $gettitle->{'itemtype'} ); # using the fixed up itype/itemtype
116 $getreserv{'waitingdate'} = format_date( $num->{'waitingdate'} );
118 my ( $waiting_year, $waiting_month, $waiting_day ) = split (/-/, $num->{'waitingdate'});
119 ( $waiting_year, $waiting_month, $waiting_day ) =
120 Add_Delta_Days( $waiting_year, $waiting_month, $waiting_day,
121 C4::Context->preference('ReservesMaxPickUpDelay'));
122 my $calcDate = Date_to_Days( $waiting_year, $waiting_month, $waiting_day );
124 $getreserv{'itemtype'} = $itemtypeinfo->{'description'};
125 $getreserv{'title'} = $gettitle->{'title'};
126 $getreserv{'itemnumber'} = $gettitle->{'itemnumber'};
127 $getreserv{'biblionumber'} = $gettitle->{'biblionumber'};
128 $getreserv{'barcode'} = $gettitle->{'barcode'};
129 $getreserv{'homebranch'} = GetBranchName($gettitle->{'homebranch'});
130 $getreserv{'holdingbranch'} = $gettitle->{'holdingbranch'};
131 $getreserv{'itemcallnumber'} = $gettitle->{'itemcallnumber'};
132 if ( $gettitle->{'homebranch'} ne $gettitle->{'holdingbranch'} ) {
133 $getreserv{'dotransfer'} = 1;
135 $getreserv{'borrowernum'} = $getborrower->{'borrowernumber'};
136 $getreserv{'borrowername'} = $getborrower->{'surname'};
137 $getreserv{'borrowerfirstname'} = $getborrower->{'firstname'};
138 $getreserv{'borrowerphone'} = $getborrower->{'phone'};
139 if ( $getborrower->{'emailaddress'} ) {
140 $getreserv{'borrowermail'} = $getborrower->{'emailaddress'};
143 if ($today > $calcDate) {
144 push @overloop, \%getreserv;
145 $overcount++;
146 }else{
147 push @reservloop, \%getreserv;
148 $reservcount++;
153 $template->param(
154 reserveloop => \@reservloop,
155 reservecount => $reservcount,
156 overloop => \@overloop,
157 overcount => $overcount,
158 show_date => format_date(C4::Dates->today('iso')),
159 dateformat => C4::Context->preference("dateformat"),
160 ReservesMaxPickUpDelay => C4::Context->preference('ReservesMaxPickUpDelay')
163 output_html_with_http_headers $input, $cookie, $template->output;