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
;
43 my $item = $input->param('itemnumber');
44 my $borrowernumber = $input->param('borrowernumber');
45 my $fbr = $input->param('fbr') || '';
46 my $tbr = $input->param('tbr') || '';
47 my $all_branches = $input->param('allbranches') || '';
48 my $cancelall = $input->param('cancelall');
49 my $tab = $input->param('tab');
51 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user
(
53 template_name
=> "circ/waitingreserves.tt",
57 flagsrequired
=> { circulate
=> "circulate_remaining_permissions" },
62 my $default = C4
::Context
->userenv->{'branch'};
64 my $transfer_when_cancel_all = C4
::Context
->preference('TransferWhenCancelAllWaitingHolds');
65 $template->param( TransferWhenCancelAllWaitingHolds
=> 1 ) if $transfer_when_cancel_all;
68 # if we have a return from the form we launch the subroutine CancelReserve
70 my $res = cancel
( $item, $borrowernumber, $fbr, $tbr );
71 push @cancel_result, $res if $res;
74 if ( C4
::Context
->preference('IndependentBranches') ) {
77 $template->param( all_branches_link
=> '/cgi-bin/koha/circ/waitingreserves.pl' . '?allbranches=1' )
80 $template->param( all_branches
=> 1 ) if $all_branches;
82 my (@reservloop, @overloop);
83 my ($reservcount, $overcount);
84 my @getreserves = $all_branches ? GetReservesForBranch
() : GetReservesForBranch
($default);
85 # get reserves for the branch we are logged into, or for all branches
87 my $today = Date_to_Days
(&Today
);
88 my $max_pickup_delay = C4
::Context
->preference('ReservesMaxPickUpDelay');
90 foreach my $num (@getreserves) {
91 next unless ($num->{'waitingdate'} && $num->{'waitingdate'} ne '0000-00-00');
93 my $itemnumber = $num->{'itemnumber'};
94 my $gettitle = GetBiblioFromItemNumber
( $itemnumber );
95 my $borrowernum = $num->{'borrowernumber'};
96 my $holdingbranch = $gettitle->{'holdingbranch'};
97 my $homebranch = $gettitle->{'homebranch'};
100 itemnumber
=> $itemnumber,
101 borrowernum
=> $borrowernum,
104 # fix up item type for display
105 $gettitle->{'itemtype'} = C4
::Context
->preference('item-level_itypes') ?
$gettitle->{'itype'} : $gettitle->{'itemtype'};
106 my $getborrower = GetMember
(borrowernumber
=> $num->{'borrowernumber'});
107 my $itemtypeinfo = getitemtypeinfo
( $gettitle->{'itemtype'} ); # using the fixed up itype/itemtype
108 $getreserv{'waitingdate'} = $num->{'waitingdate'};
109 my ( $expire_year, $expire_month, $expire_day ) = split (/-/, $num->{'expirationdate'});
110 my $calcDate = Date_to_Days
( $expire_year, $expire_month, $expire_day );
112 $getreserv{'itemtype'} = $itemtypeinfo->{'description'};
113 $getreserv{'title'} = $gettitle->{'title'};
114 $getreserv{'subtitle'} = GetRecordValue
('subtitle', GetMarcBiblio
($gettitle->{'biblionumber'}), GetFrameworkCode
($gettitle->{'biblionumber'}));
115 $getreserv{'biblionumber'} = $gettitle->{'biblionumber'};
116 $getreserv{'barcode'} = $gettitle->{'barcode'};
117 $getreserv{'homebranch'} = $gettitle->{'homebranch'};
118 $getreserv{'holdingbranch'} = $gettitle->{'holdingbranch'};
119 $getreserv{'itemcallnumber'} = $gettitle->{'itemcallnumber'};
120 $getreserv{'enumchron'} = $gettitle->{'enumchron'};
121 $getreserv{'copynumber'} = $gettitle->{'copynumber'};
122 if ( $homebranch ne $holdingbranch ) {
123 $getreserv{'dotransfer'} = 1;
125 $getreserv{'borrowername'} = $getborrower->{'surname'};
126 $getreserv{'borrowerfirstname'} = $getborrower->{'firstname'};
127 $getreserv{'borrowerphone'} = $getborrower->{'phone'};
129 my $borEmail = GetFirstValidEmailAddress
( $borrowernum );
132 $getreserv{'borrowermail'} = $borEmail;
135 if ($today > $calcDate) {
137 my $res = cancel
( $itemnumber, $borrowernum, $holdingbranch, $homebranch, !$transfer_when_cancel_all );
138 push @cancel_result, $res if $res;
141 push @overloop, \
%getreserv;
145 push @reservloop, \
%getreserv;
151 $template->param(cancel_result
=> \
@cancel_result) if @cancel_result;
153 reserveloop
=> \
@reservloop,
154 reservecount
=> $reservcount,
155 overloop
=> \
@overloop,
156 overcount
=> $overcount,
157 show_date
=> output_pref
({ dt
=> dt_from_string
, dateformat
=> 'iso', dateonly
=> 1 }),
158 ReservesMaxPickUpDelay
=> $max_pickup_delay,
162 # Checking if there is a Fast Cataloging Framework
163 $template->param( fast_cataloging
=> 1 ) if Koha
::BiblioFrameworks
->find( 'FA' );
165 if ($item && $tab eq 'holdsover' && !@cancel_result) {
166 print $input->redirect("/cgi-bin/koha/circ/waitingreserves.pl#holdsover");
167 } elsif ($cancelall) {
168 print $input->redirect("/cgi-bin/koha/circ/waitingreserves.pl");
170 output_html_with_http_headers
$input, $cookie, $template->output;
176 my ($item, $borrowernumber, $fbr, $tbr, $skip_transfers ) = @_;
178 my $transfer = $fbr ne $tbr; # XXX && !$nextreservinfo;
180 return if $transfer && $skip_transfers;
182 my ( $messages, $nextreservinfo ) = ModReserveCancelAll
( $item, $borrowernumber );
184 # if the document is not in his homebranch location and there is not reservation after, we transfer it
185 if ($transfer && !$nextreservinfo) {
186 ModItemTransfer
( $item, $fbr, $tbr );
188 # if we have a result
189 if ($nextreservinfo) {
191 my $borrowerinfo = C4
::Members
::GetMember
( borrowernumber
=> $nextreservinfo );
192 my $iteminfo = GetBiblioFromItemNumber
($item);
193 if ( $messages->{'transfert'} ) {
194 $res{messagetransfert
} = $messages->{'transfert'};
195 $res{branchcode
} = $messages->{'transfert'};
199 $res{nextreservnumber
} = $nextreservinfo;
200 $res{nextreservsurname
} = $borrowerinfo->{'surname'};
201 $res{nextreservfirstname
} = $borrowerinfo->{'firstname'};
202 $res{nextreservitem
} = $item;
203 $res{nextreservtitle
} = $iteminfo->{'title'};
204 $res{waiting
} = $messages->{'waiting'} ?
1 : 0;