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 cancel the holds
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 # FIXME - Is priority => 0 useful? If yes it must be moved to waiting, otherwise we need to remove it from here.
88 my $holds = Koha
::Holds
->waiting->search({ priority
=> 0, ( $all_branches ?
() : ( branchcode
=> $default ) ) }, { order_by
=> ['waitingdate'] });
89 # get reserves for the branch we are logged into, or for all branches
91 my $today = Date_to_Days
(&Today
);
92 my $max_pickup_delay = C4
::Context
->preference('ReservesMaxPickUpDelay');
94 while ( my $hold = $holds->next ) {
95 next unless ($hold->waitingdate && $hold->waitingdate ne '0000-00-00');
97 my $item = $hold->item;
98 my $patron = $hold->borrower;
99 my $biblio = $item->biblio;
100 my $holdingbranch = $item->holdingbranch;
101 my $homebranch = $item->homebranch;
104 title
=> $biblio->title,
105 itemnumber
=> $item->itemnumber,
106 waitingdate
=> $hold->waitingdate,
107 reservedate
=> $hold->reservedate,
108 borrowernum
=> $patron->borrowernumber,
109 biblionumber
=> $biblio->biblionumber,
110 barcode
=> $item->barcode,
111 homebranch
=> $homebranch,
112 holdingbranch
=> $item->holdingbranch,
113 itemcallnumber
=> $item->itemcallnumber,
114 enumchron
=> $item->enumchron,
115 copynumber
=> $item->copynumber,
116 borrowername
=> $patron->surname, # FIXME Let's send $patron to the template
117 borrowerfirstname
=> $patron->firstname,
118 borrowerphone
=> $patron->phone,
121 my $itemtype = Koha
::ItemTypes
->find( $item->effective_itemtype );
122 my ( $expire_year, $expire_month, $expire_day ) = split (/-/, $hold->expirationdate);
123 my $calcDate = Date_to_Days
( $expire_year, $expire_month, $expire_day );
125 $getreserv{'itemtype'} = $itemtype->description; # FIXME Should not it be translated_description?
126 $getreserv{'subtitle'} = GetRecordValue
(
128 GetMarcBiblio
({ biblionumber
=> $biblio->biblionumber }),
129 $biblio->frameworkcode);
130 if ( $homebranch ne $holdingbranch ) {
131 $getreserv{'dotransfer'} = 1;
134 my $borEmail = $patron->first_valid_email_address;
137 $getreserv{'borrowermail'} = $borEmail;
140 if ($today > $calcDate) {
142 my $res = cancel
( $item->itemnumber, $patron->borrowernumber, $holdingbranch, $homebranch, !$transfer_when_cancel_all );
143 push @cancel_result, $res if $res;
146 push @overloop, \
%getreserv;
150 push @reservloop, \
%getreserv;
156 $template->param(cancel_result
=> \
@cancel_result) if @cancel_result;
158 reserveloop
=> \
@reservloop,
159 reservecount
=> $reservcount,
160 overloop
=> \
@overloop,
161 overcount
=> $overcount,
162 show_date
=> output_pref
({ dt
=> dt_from_string
, dateformat
=> 'iso', dateonly
=> 1 }),
163 ReservesMaxPickUpDelay
=> $max_pickup_delay,
167 # Checking if there is a Fast Cataloging Framework
168 $template->param( fast_cataloging
=> 1 ) if Koha
::BiblioFrameworks
->find( 'FA' );
170 if ($item && $tab eq 'holdsover' && !@cancel_result) {
171 print $input->redirect("/cgi-bin/koha/circ/waitingreserves.pl#holdsover");
172 } elsif ($cancelall) {
173 print $input->redirect("/cgi-bin/koha/circ/waitingreserves.pl");
175 output_html_with_http_headers
$input, $cookie, $template->output;
181 my ($item, $borrowernumber, $fbr, $tbr, $skip_transfers ) = @_;
183 my $transfer = $fbr ne $tbr; # XXX && !$nextreservinfo;
185 return if $transfer && $skip_transfers;
187 my ( $messages, $nextreservinfo ) = ModReserveCancelAll
( $item, $borrowernumber );
189 # if the document is not in his homebranch location and there is not reservation after, we transfer it
190 if ($transfer && !$nextreservinfo) {
191 ModItemTransfer
( $item, $fbr, $tbr );
193 # if we have a result
194 if ($nextreservinfo) {
196 my $patron = Koha
::Patrons
->find( $nextreservinfo );
197 my $title = Koha
::Items
->find( $item )->biblio->title;
198 if ( $messages->{'transfert'} ) {
199 $res{messagetransfert
} = $messages->{'transfert'};
200 $res{branchcode
} = $messages->{'transfert'};
204 $res{nextreservnumber
} = $nextreservinfo;
205 $res{nextreservsurname
} = $patron->surname;
206 $res{nextreservfirstname
} = $patron->firstname;
207 $res{nextreservitem
} = $item;
208 $res{nextreservtitle
} = $title;
209 $res{waiting
} = $messages->{'waiting'} ?
1 : 0;