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
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>.
39 use Koha
::BiblioFrameworks
;
46 my $item = $input->param('itemnumber');
47 my $borrowernumber = $input->param('borrowernumber');
48 my $fbr = $input->param('fbr') || '';
49 my $tbr = $input->param('tbr') || '';
50 my $all_branches = $input->param('allbranches') || '';
51 my $cancelall = $input->param('cancelall');
52 my $tab = $input->param('tab');
54 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user
(
56 template_name
=> "circ/waitingreserves.tt",
60 flagsrequired
=> { circulate
=> "circulate_remaining_permissions" },
65 my $default = C4
::Context
->userenv->{'branch'};
67 my $transfer_when_cancel_all = C4
::Context
->preference('TransferWhenCancelAllWaitingHolds');
68 $template->param( TransferWhenCancelAllWaitingHolds
=> 1 ) if $transfer_when_cancel_all;
71 # if we have a return from the form we launch the subroutine CancelReserve
73 my $res = cancel
( $item, $borrowernumber, $fbr, $tbr );
74 push @cancel_result, $res if $res;
77 if ( C4
::Context
->preference('IndependentBranches') ) {
80 $template->param( all_branches_link
=> '/cgi-bin/koha/circ/waitingreserves.pl' . '?allbranches=1' )
83 $template->param( all_branches
=> 1 ) if $all_branches;
85 my (@reservloop, @overloop);
86 my ($reservcount, $overcount);
87 my @getreserves = $all_branches ? GetReservesForBranch
() : GetReservesForBranch
($default);
88 # get reserves for the branch we are logged into, or for all branches
90 my $today = Date_to_Days
(&Today
);
91 my $max_pickup_delay = C4
::Context
->preference('ReservesMaxPickUpDelay');
93 foreach my $num (@getreserves) {
94 next unless ($num->{'waitingdate'} && $num->{'waitingdate'} ne '0000-00-00');
96 my $itemnumber = $num->{'itemnumber'};
97 my $item = Koha
::Items
->find( $itemnumber );
98 my $biblio = $item->biblio;
99 my $borrowernum = $num->{'borrowernumber'};
100 my $holdingbranch = $item->holdingbranch;
101 my $homebranch = $item->homebranch;
104 itemnumber
=> $itemnumber,
105 borrowernum
=> $borrowernum,
108 my $patron = Koha
::Patrons
->find( $num->{borrowernumber
} );
109 my $itemtype = Koha
::ItemTypes
->find( $item->effective_itemtype );
110 $getreserv{'waitingdate'} = $num->{'waitingdate'};
111 my ( $expire_year, $expire_month, $expire_day ) = split (/-/, $num->{'expirationdate'});
112 my $calcDate = Date_to_Days
( $expire_year, $expire_month, $expire_day );
114 $getreserv{'itemtype'} = $itemtype->description; # FIXME Should not it be translated_description?
115 $getreserv{'title'} = $biblio->title;
116 $getreserv{'subtitle'} = GetRecordValue
('subtitle', GetMarcBiblio
($biblio->biblionumber), $biblio->frameworkcode);
117 $getreserv{'biblionumber'} = $biblio->biblionumber;
118 $getreserv{'barcode'} = $item->barcode;
119 $getreserv{'homebranch'} = $homebranch;
120 $getreserv{'holdingbranch'} = $item->holdingbranch;
121 $getreserv{'itemcallnumber'} = $item->itemcallnumber;
122 $getreserv{'enumchron'} = $item->enumchron;
123 $getreserv{'copynumber'} = $item->copynumber;
124 if ( $homebranch ne $holdingbranch ) {
125 $getreserv{'dotransfer'} = 1;
127 $getreserv{'borrowername'} = $patron->surname;
128 $getreserv{'borrowerfirstname'} = $patron->firstname;
129 $getreserv{'borrowerphone'} = $patron->phone;
131 my $borEmail = GetFirstValidEmailAddress
( $borrowernum );
134 $getreserv{'borrowermail'} = $borEmail;
137 if ($today > $calcDate) {
139 my $res = cancel
( $itemnumber, $borrowernum, $holdingbranch, $homebranch, !$transfer_when_cancel_all );
140 push @cancel_result, $res if $res;
143 push @overloop, \
%getreserv;
147 push @reservloop, \
%getreserv;
153 $template->param(cancel_result
=> \
@cancel_result) if @cancel_result;
155 reserveloop
=> \
@reservloop,
156 reservecount
=> $reservcount,
157 overloop
=> \
@overloop,
158 overcount
=> $overcount,
159 show_date
=> output_pref
({ dt
=> dt_from_string
, dateformat
=> 'iso', dateonly
=> 1 }),
160 ReservesMaxPickUpDelay
=> $max_pickup_delay,
164 # Checking if there is a Fast Cataloging Framework
165 $template->param( fast_cataloging
=> 1 ) if Koha
::BiblioFrameworks
->find( 'FA' );
167 if ($item && $tab eq 'holdsover' && !@cancel_result) {
168 print $input->redirect("/cgi-bin/koha/circ/waitingreserves.pl#holdsover");
169 } elsif ($cancelall) {
170 print $input->redirect("/cgi-bin/koha/circ/waitingreserves.pl");
172 output_html_with_http_headers
$input, $cookie, $template->output;
178 my ($item, $borrowernumber, $fbr, $tbr, $skip_transfers ) = @_;
180 my $transfer = $fbr ne $tbr; # XXX && !$nextreservinfo;
182 return if $transfer && $skip_transfers;
184 my ( $messages, $nextreservinfo ) = ModReserveCancelAll
( $item, $borrowernumber );
186 # if the document is not in his homebranch location and there is not reservation after, we transfer it
187 if ($transfer && !$nextreservinfo) {
188 ModItemTransfer
( $item, $fbr, $tbr );
190 # if we have a result
191 if ($nextreservinfo) {
193 my $patron = Koha
::Patrons
->find( $nextreservinfo );
194 my $title = Koha
::Items
->find( $item )->biblio->title;
195 if ( $messages->{'transfert'} ) {
196 $res{messagetransfert
} = $messages->{'transfert'};
197 $res{branchcode
} = $messages->{'transfert'};
201 $res{nextreservnumber
} = $nextreservinfo;
202 $res{nextreservsurname
} = $patron->surname;
203 $res{nextreservfirstname
} = $patron->firstname;
204 $res{nextreservitem
} = $item;
205 $res{nextreservtitle
} = $title;
206 $res{waiting
} = $messages->{'waiting'} ?
1 : 0;