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>.
26 use C4
::Branch
; # GetBranchName
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 ) = 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 foreach my $num (@getreserves) {
89 next unless ($num->{'waitingdate'} && $num->{'waitingdate'} ne '0000-00-00');
91 my $itemnumber = $num->{'itemnumber'};
92 my $gettitle = GetBiblioFromItemNumber
( $itemnumber );
93 my $borrowernum = $num->{'borrowernumber'};
94 my $holdingbranch = $gettitle->{'holdingbranch'};
95 my $homebranch = $gettitle->{'homebranch'};
98 itemnumber
=> $itemnumber,
99 borrowernum
=> $borrowernum,
102 # fix up item type for display
103 $gettitle->{'itemtype'} = C4
::Context
->preference('item-level_itypes') ?
$gettitle->{'itype'} : $gettitle->{'itemtype'};
104 my $getborrower = GetMember
(borrowernumber
=> $num->{'borrowernumber'});
105 my $itemtypeinfo = getitemtypeinfo
( $gettitle->{'itemtype'} ); # using the fixed up itype/itemtype
106 $getreserv{'waitingdate'} = $num->{'waitingdate'};
107 my ( $waiting_year, $waiting_month, $waiting_day ) = split (/-/, $num->{'waitingdate'});
108 ( $waiting_year, $waiting_month, $waiting_day ) =
109 Add_Delta_Days
( $waiting_year, $waiting_month, $waiting_day,
110 C4
::Context
->preference('ReservesMaxPickUpDelay'));
111 my $calcDate = Date_to_Days
( $waiting_year, $waiting_month, $waiting_day );
113 $getreserv{'itemtype'} = $itemtypeinfo->{'description'};
114 $getreserv{'title'} = $gettitle->{'title'};
115 $getreserv{'subtitle'} = GetRecordValue
('subtitle', GetMarcBiblio
($gettitle->{'biblionumber'}), GetFrameworkCode
($gettitle->{'biblionumber'}));
116 $getreserv{'biblionumber'} = $gettitle->{'biblionumber'};
117 $getreserv{'barcode'} = $gettitle->{'barcode'};
118 $getreserv{'branchname'} = GetBranchName
($gettitle->{'homebranch'});
119 $getreserv{'homebranch'} = $gettitle->{'homebranch'};
120 $getreserv{'holdingbranch'} = $gettitle->{'holdingbranch'};
121 $getreserv{'itemcallnumber'} = $gettitle->{'itemcallnumber'};
122 $getreserv{'enumchron'} = $gettitle->{'enumchron'};
123 $getreserv{'copynumber'} = $gettitle->{'copynumber'};
124 if ( $homebranch ne $holdingbranch ) {
125 $getreserv{'dotransfer'} = 1;
127 $getreserv{'borrowername'} = $getborrower->{'surname'};
128 $getreserv{'borrowerfirstname'} = $getborrower->{'firstname'};
129 $getreserv{'borrowerphone'} = $getborrower->{'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
=> C4
::Context
->preference('ReservesMaxPickUpDelay')
163 if ($item && $tab eq 'holdsover') {
164 print $input->redirect("/cgi-bin/koha/circ/waitingreserves.pl#holdsover");
165 } elsif ($cancelall) {
166 print $input->redirect("/cgi-bin/koha/circ/waitingreserves.pl");
168 output_html_with_http_headers
$input, $cookie, $template->output;
174 my ($item, $borrowernumber, $fbr, $tbr, $skip_transfers ) = @_;
176 my $transfer = $fbr ne $tbr; # XXX && !$nextreservinfo;
178 return if $transfer && $skip_transfers;
180 my ( $messages, $nextreservinfo ) = ModReserveCancelAll
( $item, $borrowernumber );
182 # if the document is not in his homebranch location and there is not reservation after, we transfer it
183 if ($transfer && !$nextreservinfo) {
184 ModItemTransfer
( $item, $fbr, $tbr );
186 # if we have a result
187 if ($nextreservinfo) {
189 my $borrowerinfo = C4
::Members
::GetMember
( borrowernumber
=> $nextreservinfo );
190 my $iteminfo = GetBiblioFromItemNumber
($item);
191 if ( $messages->{'transfert'} ) {
192 $res{messagetransfert
} = $messages->{'transfert'};
193 $res{branchname
} = GetBranchName
($messages->{'transfert'});
197 $res{nextreservnumber
} = $nextreservinfo;
198 $res{nextreservsurname
} = $borrowerinfo->{'surname'};
199 $res{nextreservfirstname
} = $borrowerinfo->{'firstname'};
200 $res{nextreservitem
} = $item;
201 $res{nextreservtitle
} = $iteminfo->{'title'};
202 $res{waiting
} = $messages->{'waiting'} ?
1 : 0;