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>.
38 use Koha
::BiblioFrameworks
;
45 my $item = $input->param('itemnumber');
46 my $borrowernumber = $input->param('borrowernumber');
47 my $fbr = $input->param('fbr') || '';
48 my $tbr = $input->param('tbr') || '';
49 my $all_branches = $input->param('allbranches') || '';
50 my $cancelall = $input->param('cancelall');
51 my $tab = $input->param('tab');
53 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user
(
55 template_name
=> "circ/waitingreserves.tt",
59 flagsrequired
=> { circulate
=> "circulate_remaining_permissions" },
64 my $default = C4
::Context
->userenv->{'branch'};
66 my $transfer_when_cancel_all = C4
::Context
->preference('TransferWhenCancelAllWaitingHolds');
67 $template->param( TransferWhenCancelAllWaitingHolds
=> 1 ) if $transfer_when_cancel_all;
70 # if we have a return from the form we cancel the holds
72 my $res = cancel
( $item, $borrowernumber, $fbr, $tbr );
73 push @cancel_result, $res if $res;
76 if ( C4
::Context
->preference('IndependentBranches') ) {
79 $template->param( all_branches_link
=> '/cgi-bin/koha/circ/waitingreserves.pl' . '?allbranches=1' )
82 $template->param( all_branches
=> 1 ) if $all_branches;
84 my (@reserve_loop, @over_loop);
85 # FIXME - Is priority => 0 useful? If yes it must be moved to waiting, otherwise we need to remove it from here.
86 my $holds = Koha
::Holds
->waiting->search({ priority
=> 0, ( $all_branches ?
() : ( branchcode
=> $default ) ) }, { order_by
=> ['waitingdate'] });
88 # get reserves for the branch we are logged into, or for all branches
90 my $today = Date_to_Days
(&Today
);
92 while ( my $hold = $holds->next ) {
93 next unless ($hold->waitingdate && $hold->waitingdate ne '0000-00-00');
95 my ( $expire_year, $expire_month, $expire_day ) = split (/-/, $hold->expirationdate);
96 my $calcDate = Date_to_Days
( $expire_year, $expire_month, $expire_day );
98 if ($today > $calcDate) {
100 my $res = cancel
( $hold->item->itemnumber, $hold->borrowernumber, $hold->item->holdingbranch, $hold->item->homebranch, !$transfer_when_cancel_all );
101 push @cancel_result, $res if $res;
104 push @over_loop, $hold;
107 push @reserve_loop, $hold;
112 $template->param(cancel_result
=> \
@cancel_result) if @cancel_result;
115 reserveloop
=> \
@reserve_loop,
116 reservecount
=> scalar @reserve_loop,
117 overloop
=> \
@over_loop,
118 overcount
=> scalar @over_loop,
119 show_date
=> output_pref
({ dt
=> dt_from_string
, dateformat
=> 'iso', dateonly
=> 1 }),
123 # Checking if there is a Fast Cataloging Framework
124 $template->param( fast_cataloging
=> 1 ) if Koha
::BiblioFrameworks
->find( 'FA' );
126 if ($item && $tab eq 'holdsover' && !@cancel_result) {
127 print $input->redirect("/cgi-bin/koha/circ/waitingreserves.pl#holdsover");
128 } elsif ($cancelall) {
129 print $input->redirect("/cgi-bin/koha/circ/waitingreserves.pl");
131 output_html_with_http_headers
$input, $cookie, $template->output;
137 my ($item, $borrowernumber, $fbr, $tbr, $skip_transfers ) = @_;
139 my $transfer = $fbr ne $tbr; # XXX && !$nextreservinfo;
141 return if $transfer && $skip_transfers;
143 my ( $messages, $nextreservinfo ) = ModReserveCancelAll
( $item, $borrowernumber );
145 # if the document is not in his homebranch location and there is not reservation after, we transfer it
146 if ($transfer && !$nextreservinfo) {
147 ModItemTransfer
( $item, $fbr, $tbr, 'CancelReserve' );
149 # if we have a result
150 if ($nextreservinfo) {
152 my $patron = Koha
::Patrons
->find( $nextreservinfo );
153 my $title = Koha
::Items
->find( $item )->biblio->title;
154 if ( $messages->{'transfert'} ) {
155 $res{messagetransfert
} = $messages->{'transfert'};
156 $res{branchcode
} = $messages->{'transfert'};
160 $res{nextreservnumber
} = $nextreservinfo;
161 $res{nextreservsurname
} = $patron->surname;
162 $res{nextreservfirstname
} = $patron->firstname;
163 $res{nextreservitem
} = $item;
164 $res{nextreservtitle
} = $title;
165 $res{waiting
} = $messages->{'waiting'} ?
1 : 0;