Bug 15238: Better translatability for Installer Step 1
[koha.git] / circ / waitingreserves.pl
blob57f23a93feda064e93f098f2ce5aff3deea4a1a2
1 #!/usr/bin/perl
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>.
21 use strict;
22 use warnings;
23 use CGI qw ( -utf8 );
24 use C4::Context;
25 use C4::Output;
26 use C4::Branch; # GetBranchName
27 use C4::Auth;
28 use C4::Circulation;
29 use C4::Members;
30 use C4::Biblio;
31 use C4::Items;
32 use Koha::DateUtils;
33 use Date::Calc qw(
34 Today
35 Add_Delta_Days
36 Date_to_Days
38 use C4::Reserves;
39 use C4::Koha;
41 my $input = new CGI;
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 $cancel;
53 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
55 template_name => "circ/waitingreserves.tt",
56 query => $input,
57 type => "intranet",
58 authnotrequired => 0,
59 flagsrequired => { circulate => "circulate_remaining_permissions" },
60 debug => 1,
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;
69 my @cancel_result;
70 # if we have a return from the form we launch the subroutine CancelReserve
71 if ($item) {
72 my $res = cancel( $item, $borrowernumber, $fbr, $tbr );
73 push @cancel_result, $res if $res;
76 if ( C4::Context->preference('IndependentBranches') ) {
77 undef $all_branches;
78 } else {
79 $template->param( all_branches_link => '/cgi-bin/koha/circ/waitingreserves.pl' . '?allbranches=1' )
80 unless $all_branches;
82 $template->param( all_branches => 1 ) if $all_branches;
84 my (@reservloop, @overloop);
85 my ($reservcount, $overcount);
86 my @getreserves = $all_branches ? GetReservesForBranch() : GetReservesForBranch($default);
87 # get reserves for the branch we are logged into, or for all branches
89 my $today = Date_to_Days(&Today);
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'};
99 my %getreserv = (
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 ( $waiting_year, $waiting_month, $waiting_day ) = split (/-/, $num->{'waitingdate'});
110 ( $waiting_year, $waiting_month, $waiting_day ) =
111 Add_Delta_Days( $waiting_year, $waiting_month, $waiting_day,
112 C4::Context->preference('ReservesMaxPickUpDelay'));
113 my $calcDate = Date_to_Days( $waiting_year, $waiting_month, $waiting_day );
115 $getreserv{'itemtype'} = $itemtypeinfo->{'description'};
116 $getreserv{'title'} = $gettitle->{'title'};
117 $getreserv{'subtitle'} = GetRecordValue('subtitle', GetMarcBiblio($gettitle->{'biblionumber'}), GetFrameworkCode($gettitle->{'biblionumber'}));
118 $getreserv{'biblionumber'} = $gettitle->{'biblionumber'};
119 $getreserv{'barcode'} = $gettitle->{'barcode'};
120 $getreserv{'branchname'} = GetBranchName($gettitle->{'homebranch'});
121 $getreserv{'homebranch'} = $gettitle->{'homebranch'};
122 $getreserv{'holdingbranch'} = $gettitle->{'holdingbranch'};
123 $getreserv{'itemcallnumber'} = $gettitle->{'itemcallnumber'};
124 $getreserv{'enumchron'} = $gettitle->{'enumchron'};
125 $getreserv{'copynumber'} = $gettitle->{'copynumber'};
126 if ( $homebranch ne $holdingbranch ) {
127 $getreserv{'dotransfer'} = 1;
129 $getreserv{'borrowername'} = $getborrower->{'surname'};
130 $getreserv{'borrowerfirstname'} = $getborrower->{'firstname'};
131 $getreserv{'borrowerphone'} = $getborrower->{'phone'};
133 my $borEmail = GetFirstValidEmailAddress( $borrowernum );
135 if ( $borEmail ) {
136 $getreserv{'borrowermail'} = $borEmail;
139 if ($today > $calcDate) {
140 if ($cancelall) {
141 my $res = cancel( $itemnumber, $borrowernum, $holdingbranch, $homebranch, !$transfer_when_cancel_all );
142 push @cancel_result, $res if $res;
143 next;
144 } else {
145 push @overloop, \%getreserv;
146 $overcount++;
148 }else{
149 push @reservloop, \%getreserv;
150 $reservcount++;
155 $template->param(cancel_result => \@cancel_result) if @cancel_result;
156 $template->param(
157 reserveloop => \@reservloop,
158 reservecount => $reservcount,
159 overloop => \@overloop,
160 overcount => $overcount,
161 show_date => output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }),
162 ReservesMaxPickUpDelay => C4::Context->preference('ReservesMaxPickUpDelay')
165 if ($item && $tab eq 'holdsover') {
166 print $input->redirect("/cgi-bin/koha/circ/waitingreserves.pl#holdsover");
167 } elsif ($cancelall) {
168 print $input->redirect("/cgi-bin/koha/circ/waitingreserves.pl");
169 } else {
170 output_html_with_http_headers $input, $cookie, $template->output;
173 exit;
175 sub cancel {
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) {
190 my %res;
191 my $borrowerinfo = GetMemberDetails( $nextreservinfo );
192 my $iteminfo = GetBiblioFromItemNumber($item);
193 if ( $messages->{'transfert'} ) {
194 $res{messagetransfert} = $messages->{'transfert'};
195 $res{branchname} = GetBranchName($messages->{'transfert'});
198 $res{message} = 1;
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;
206 return \%res;
209 return;