|
Lines 16-442
Link Here
|
| 16 |
# You should have received a copy of the GNU General Public License |
16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with Koha; if not, see <https://www.gnu.org/licenses>. |
17 |
# along with Koha; if not, see <https://www.gnu.org/licenses>. |
| 18 |
|
18 |
|
| 19 |
use Modern::Perl; |
19 |
use Modern::Perl; |
| 20 |
|
20 |
|
| 21 |
use CGI qw ( -utf8 ); |
21 |
use CGI qw ( -utf8 ); |
| 22 |
use URI; |
22 |
use URI; |
| 23 |
|
23 |
|
| 24 |
use C4::Auth qw( get_template_and_user ); |
24 |
use C4::Auth qw( get_template_and_user ); |
| 25 |
use C4::Koha qw( |
25 |
use C4::Koha qw( |
| 26 |
getitemtypeimagelocation |
26 |
getitemtypeimagelocation |
| 27 |
GetNormalizedISBN |
27 |
GetNormalizedISBN |
| 28 |
GetNormalizedUPC |
28 |
GetNormalizedUPC |
| 29 |
GetNormalizedOCLCNumber |
29 |
GetNormalizedOCLCNumber |
| 30 |
); |
30 |
); |
| 31 |
use C4::Circulation qw( CanBookBeRenewed GetRenewCount GetIssuingCharges ); |
31 |
use C4::Circulation qw( CanBookBeRenewed GetRenewCount GetIssuingCharges ); |
| 32 |
use C4::External::BakerTaylor qw( image_url link_url ); |
32 |
use C4::External::BakerTaylor qw( image_url link_url ); |
| 33 |
use C4::Reserves qw( GetReserveStatus ); |
33 |
use C4::Reserves qw( GetReserveStatus ); |
| 34 |
use C4::Members; |
34 |
use C4::Members; |
| 35 |
use C4::Output qw( output_html_with_http_headers ); |
35 |
use C4::Output qw( output_html_with_http_headers ); |
| 36 |
use Koha::Account::Lines; |
36 |
use Koha::Account::Lines; |
| 37 |
use Koha::Biblios; |
37 |
use Koha::Biblios; |
| 38 |
use Koha::Libraries; |
38 |
use Koha::Libraries; |
| 39 |
use Koha::DateUtils qw( output_pref ); |
39 |
use Koha::DateUtils qw( output_pref ); |
| 40 |
use Koha::Holds; |
40 |
use Koha::Holds; |
| 41 |
use Koha::Database; |
41 |
use Koha::Database; |
| 42 |
use Koha::ItemTypes; |
42 |
use Koha::ItemTypes; |
| 43 |
use Koha::Patron::Attribute::Types; |
43 |
use Koha::Patron::Attribute::Types; |
| 44 |
use Koha::Patrons; |
44 |
use Koha::Patrons; |
| 45 |
use Koha::Patron::Messages; |
45 |
use Koha::Patron::Messages; |
| 46 |
use Koha::Patron::Discharge; |
46 |
use Koha::Patron::Discharge; |
| 47 |
use Koha::Patrons; |
47 |
use Koha::Patrons; |
| 48 |
use Koha::Ratings; |
48 |
use Koha::Ratings; |
| 49 |
use Koha::Recalls; |
49 |
use Koha::Recalls; |
| 50 |
|
50 |
|
| 51 |
use constant ATTRIBUTE_SHOW_BARCODE => 'SHOW_BCODE'; |
51 |
use constant ATTRIBUTE_SHOW_BARCODE => 'SHOW_BCODE'; |
| 52 |
|
52 |
|
| 53 |
use Scalar::Util qw( looks_like_number ); |
53 |
use Scalar::Util qw( looks_like_number ); |
| 54 |
use Date::Calc qw( Date_to_Days Today ); |
54 |
use Date::Calc qw( Date_to_Days Today ); |
| 55 |
|
55 |
|
| 56 |
my $query = CGI->new; |
56 |
my $query = CGI->new; |
| 57 |
|
57 |
|
| 58 |
my $op = $query->param('op') || q{}; |
58 |
my $op = $query->param('op') || q{}; |
| 59 |
|
59 |
|
| 60 |
# CAS single logout handling |
60 |
# CAS single logout handling |
| 61 |
# Will print header and exit |
61 |
# Will print header and exit |
| 62 |
if ( C4::Context->preference('casAuthentication') ) { |
62 |
if ( C4::Context->preference('casAuthentication') ) { |
| 63 |
require C4::Auth_with_cas; |
63 |
require C4::Auth_with_cas; |
| 64 |
C4::Auth_with_cas::logout_if_required($query); |
64 |
C4::Auth_with_cas::logout_if_required($query); |
| 65 |
} |
65 |
} |
| 66 |
|
66 |
|
| 67 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
67 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
| 68 |
{ |
68 |
{ |
| 69 |
template_name => "opac-user.tt", |
69 |
template_name => "opac-user.tt", |
| 70 |
query => $query, |
70 |
query => $query, |
| 71 |
type => "opac", |
71 |
type => "opac", |
| 72 |
} |
72 |
} |
| 73 |
); |
73 |
); |
| 74 |
|
74 |
|
| 75 |
my %renewed = map { $_ => 1 } split( ':', $query->param('renewed') || '' ); |
75 |
my %renewed = map { $_ => 1 } split( ':', $query->param('renewed') || '' ); |
| 76 |
|
76 |
|
| 77 |
my $show_priority; |
77 |
my $show_priority; |
| 78 |
for ( C4::Context->preference("OPACShowHoldQueueDetails") ) { |
78 |
for ( C4::Context->preference("OPACShowHoldQueueDetails") ) { |
| 79 |
m/priority/ and $show_priority = 1; |
79 |
m/priority/ and $show_priority = 1; |
| 80 |
} |
80 |
} |
| 81 |
|
81 |
|
| 82 |
my $patronupdate = $query->param('patronupdate'); |
82 |
my $patronupdate = $query->param('patronupdate'); |
| 83 |
my $canrenew = 1; |
83 |
my $canrenew = 1; |
| 84 |
|
84 |
|
| 85 |
$template->param( shibbolethAuthentication => C4::Context->config('useshibboleth') ); |
85 |
$template->param( shibbolethAuthentication => C4::Context->config('useshibboleth') ); |
| 86 |
|
86 |
|
| 87 |
# get borrower information .... |
87 |
# get borrower information .... |
| 88 |
my $patron = Koha::Patrons->find($borrowernumber); |
88 |
my $patron = Koha::Patrons->find($borrowernumber); |
| 89 |
|
|
|
| 90 |
if ( $op eq 'cud-update_arc' && C4::Context->preference("AllowPatronToControlAutorenewal") ) { |
| 91 |
my $autorenew_checkouts = $query->param('borrower_autorenew_checkouts'); |
| 92 |
$patron->autorenew_checkouts($autorenew_checkouts)->store() if defined $autorenew_checkouts; |
| 93 |
} |
| 94 |
|
89 |
|
| 95 |
my $borr = $patron->unblessed; |
90 |
if ( $op eq 'cud-update_arc' && C4::Context->preference("AllowPatronToControlAutorenewal") ) { |
|
|
91 |
my $autorenew_checkouts = $query->param('borrower_autorenew_checkouts'); |
| 92 |
$patron->autorenew_checkouts($autorenew_checkouts)->store() if defined $autorenew_checkouts; |
| 93 |
} |
| 96 |
|
94 |
|
| 97 |
my ( $today_year, $today_month, $today_day ) = Today(); |
95 |
my $borr = $patron->unblessed; |
| 98 |
my ( $warning_year, $warning_month, $warning_day ) = split /-/, $borr->{'dateexpiry'}; |
|
|
| 99 |
|
96 |
|
| 100 |
my $debar = Koha::Patrons->find($borrowernumber)->is_debarred; |
97 |
my ( $today_year, $today_month, $today_day ) = Today(); |
| 101 |
my $userdebarred; |
98 |
my ( $warning_year, $warning_month, $warning_day ) = split /-/, $borr->{'dateexpiry'}; |
| 102 |
|
99 |
|
| 103 |
if ($debar) { |
100 |
my $debar = Koha::Patrons->find($borrowernumber)->is_debarred; |
| 104 |
$userdebarred = 1; |
101 |
my $userdebarred; |
| 105 |
$template->param( 'userdebarred' => $userdebarred ); |
|
|
| 106 |
if ( $debar ne "9999-12-31" ) { |
| 107 |
$borr->{'userdebarreddate'} = $debar; |
| 108 |
} |
| 109 |
|
102 |
|
| 110 |
# FIXME looks like $available is not needed |
103 |
if ($debar) { |
| 111 |
# If a user is discharged they have a validated discharge available |
104 |
$userdebarred = 1; |
| 112 |
my $available = Koha::Patron::Discharge::count( |
105 |
$template->param( 'userdebarred' => $userdebarred ); |
| 113 |
{ |
106 |
if ( $debar ne "9999-12-31" ) { |
| 114 |
borrowernumber => $borrowernumber, |
107 |
$borr->{'userdebarreddate'} = $debar; |
| 115 |
validated => 1, |
|
|
| 116 |
} |
| 117 |
); |
| 118 |
$template->param( 'discharge_available' => $available |
| 119 |
&& Koha::Patron::Discharge::is_discharged( { borrowernumber => $borrowernumber } ) ); |
| 120 |
} |
108 |
} |
| 121 |
|
109 |
|
| 122 |
if ( $userdebarred || $borr->{'gonenoaddress'} || $borr->{'lost'} ) { |
110 |
# FIXME looks like $available is not needed |
| 123 |
$borr->{'flagged'} = 1; |
111 |
# If a user is discharged they have a validated discharge available |
| 124 |
$canrenew = 0; |
112 |
my $available = Koha::Patron::Discharge::count( |
| 125 |
} |
113 |
{ |
|
|
114 |
borrowernumber => $borrowernumber, |
| 115 |
validated => 1, |
| 116 |
} |
| 117 |
); |
| 118 |
$template->param( 'discharge_available' => $available |
| 119 |
&& Koha::Patron::Discharge::is_discharged( { borrowernumber => $borrowernumber } ) ); |
| 120 |
} |
| 126 |
|
121 |
|
| 127 |
my $amountoutstanding = $patron->account->balance; |
122 |
if ( $userdebarred || $borr->{'gonenoaddress'} || $borr->{'lost'} ) { |
| 128 |
my $no_renewal_amt = C4::Context->preference('OPACFineNoRenewals'); |
123 |
$borr->{'flagged'} = 1; |
| 129 |
$no_renewal_amt = undef unless looks_like_number($no_renewal_amt); |
124 |
$canrenew = 0; |
| 130 |
my $amountoutstandingfornewal = |
125 |
} |
| 131 |
C4::Context->preference("OPACFineNoRenewalsIncludeCredits") |
|
|
| 132 |
? $amountoutstanding |
| 133 |
: $patron->account->outstanding_debits->total_outstanding; |
| 134 |
|
| 135 |
if ( C4::Context->preference('OpacRenewalAllowed') |
| 136 |
&& defined($no_renewal_amt) |
| 137 |
&& $amountoutstandingfornewal > $no_renewal_amt ) |
| 138 |
{ |
| 139 |
$borr->{'flagged'} = 1; |
| 140 |
$canrenew = 0; |
| 141 |
$template->param( |
| 142 |
renewal_blocked_fines => $no_renewal_amt, |
| 143 |
renewal_blocked_fines_amountoutstanding => $amountoutstandingfornewal, |
| 144 |
); |
| 145 |
} |
| 146 |
|
126 |
|
| 147 |
my $maxoutstanding = C4::Context->preference('maxoutstanding'); |
127 |
my $amountoutstanding = $patron->account->balance; |
| 148 |
if ( $amountoutstanding && ( $amountoutstanding > $maxoutstanding ) ) { |
128 |
my $no_renewal_amt = C4::Context->preference('OPACFineNoRenewals'); |
| 149 |
$borr->{blockedonfines} = 1; |
129 |
$no_renewal_amt = undef unless looks_like_number($no_renewal_amt); |
| 150 |
} |
130 |
my $amountoutstandingfornewal = |
|
|
131 |
C4::Context->preference("OPACFineNoRenewalsIncludeCredits") |
| 132 |
? $amountoutstanding |
| 133 |
: $patron->account->outstanding_debits->total_outstanding; |
| 134 |
|
| 135 |
if ( C4::Context->preference('OpacRenewalAllowed') |
| 136 |
&& defined($no_renewal_amt) |
| 137 |
&& $amountoutstandingfornewal > $no_renewal_amt ) |
| 138 |
{ |
| 139 |
$borr->{'flagged'} = 1; |
| 140 |
$canrenew = 0; |
| 141 |
$template->param( |
| 142 |
renewal_blocked_fines => $no_renewal_amt, |
| 143 |
renewal_blocked_fines_amountoutstanding => $amountoutstandingfornewal, |
| 144 |
); |
| 145 |
} |
| 146 |
|
| 147 |
my $maxoutstanding = C4::Context->preference('maxoutstanding'); |
| 148 |
if ( $amountoutstanding && ( $amountoutstanding > $maxoutstanding ) ) { |
| 149 |
$borr->{blockedonfines} = 1; |
| 150 |
} |
| 151 |
|
151 |
|
| 152 |
# Warningdate is the date that the warning starts appearing |
152 |
# Warningdate is the date that the warning starts appearing |
| 153 |
if ( $borr->{'dateexpiry'} && C4::Context->preference('NotifyBorrowerDeparture') ) { |
153 |
if ( $borr->{'dateexpiry'} && C4::Context->preference('NotifyBorrowerDeparture') ) { |
| 154 |
my $days_to_expiry = Date_to_Days( $warning_year, $warning_month, $warning_day ) - |
154 |
my $days_to_expiry = Date_to_Days( $warning_year, $warning_month, $warning_day ) - |
| 155 |
Date_to_Days( $today_year, $today_month, $today_day ); |
155 |
Date_to_Days( $today_year, $today_month, $today_day ); |
| 156 |
if ( $days_to_expiry < 0 ) { |
156 |
if ( $days_to_expiry < 0 ) { |
| 157 |
|
157 |
|
| 158 |
#borrower card has expired, warn the borrower |
158 |
#borrower card has expired, warn the borrower |
| 159 |
$borr->{'warnexpired'} = $borr->{'dateexpiry'}; |
159 |
$borr->{'warnexpired'} = $borr->{'dateexpiry'}; |
| 160 |
} elsif ( $days_to_expiry < C4::Context->preference('NotifyBorrowerDeparture') ) { |
160 |
} elsif ( $days_to_expiry < C4::Context->preference('NotifyBorrowerDeparture') ) { |
| 161 |
|
161 |
|
| 162 |
# borrower card soon to expire, warn the borrower |
162 |
# borrower card soon to expire, warn the borrower |
| 163 |
$borr->{'warndeparture'} = $borr->{dateexpiry}; |
163 |
$borr->{'warndeparture'} = $borr->{dateexpiry}; |
| 164 |
if ( C4::Context->preference('ReturnBeforeExpiry') ) { |
164 |
if ( C4::Context->preference('ReturnBeforeExpiry') ) { |
| 165 |
$borr->{'returnbeforeexpiry'} = 1; |
165 |
$borr->{'returnbeforeexpiry'} = 1; |
| 166 |
} |
|
|
| 167 |
} |
166 |
} |
| 168 |
} |
167 |
} |
|
|
168 |
} |
| 169 |
|
169 |
|
| 170 |
my $saving_display = C4::Context->preference('OPACShowSavings'); |
170 |
my $saving_display = C4::Context->preference('OPACShowSavings'); |
| 171 |
if ( $saving_display =~ /user/ ) { |
171 |
if ( $saving_display =~ /user/ ) { |
| 172 |
$template->param( savings => $patron->get_savings ); |
172 |
$template->param( savings => $patron->get_savings ); |
| 173 |
} |
173 |
} |
| 174 |
|
174 |
|
| 175 |
# pass on any renew errors to the template for displaying |
175 |
# pass on any renew errors to the template for displaying |
| 176 |
my $renew_error = $query->param('renew_error'); |
176 |
my $renew_error = $query->param('renew_error'); |
| 177 |
|
177 |
|
| 178 |
$template->param( |
178 |
$template->param( |
| 179 |
amountoutstanding => $amountoutstanding, |
179 |
amountoutstanding => $amountoutstanding, |
| 180 |
borrowernumber => $borrowernumber, |
180 |
borrowernumber => $borrowernumber, |
| 181 |
patron_flagged => $borr->{flagged}, |
181 |
patron_flagged => $borr->{flagged}, |
| 182 |
surname => $borr->{surname}, |
182 |
surname => $borr->{surname}, |
| 183 |
RENEW_ERROR => $renew_error, |
183 |
RENEW_ERROR => $renew_error, |
| 184 |
borrower => $borr, |
184 |
borrower => $borr, |
| 185 |
); |
185 |
); |
| 186 |
|
186 |
|
| 187 |
#get issued items .... |
187 |
#get issued items .... |
| 188 |
|
188 |
|
| 189 |
my $count = 0; |
189 |
my $count = 0; |
| 190 |
my $overdues_count = 0; |
190 |
my $overdues_count = 0; |
| 191 |
my @overdues; |
191 |
my @overdues; |
| 192 |
my @issuedat; |
192 |
my @issuedat; |
| 193 |
my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; |
193 |
my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; |
| 194 |
my $pending_checkouts = $patron->pending_checkouts->search( |
194 |
my $pending_checkouts = $patron->pending_checkouts->search( |
| 195 |
{}, |
195 |
{}, |
| 196 |
{ |
196 |
{ |
| 197 |
order_by => [ { -desc => 'date_due' }, { -asc => 'issue_id' } ], |
197 |
order_by => [ { -desc => 'date_due' }, { -asc => 'issue_id' } ], |
| 198 |
prefetch => 'item' |
198 |
prefetch => 'item' |
|
|
199 |
} |
| 200 |
); |
| 201 |
my $are_renewable_items = 0; |
| 202 |
if ( $pending_checkouts->count ) { # Useless test |
| 203 |
while ( my $c = $pending_checkouts->next ) { |
| 204 |
my $issue = $c->unblessed_all_relateds; |
| 205 |
|
| 206 |
# check for reserves |
| 207 |
my $restype = GetReserveStatus( $issue->{'itemnumber'} ); |
| 208 |
if ($restype) { |
| 209 |
$issue->{'reserved'} = 1; |
| 199 |
} |
210 |
} |
| 200 |
); |
|
|
| 201 |
my $are_renewable_items = 0; |
| 202 |
if ( $pending_checkouts->count ) { # Useless test |
| 203 |
while ( my $c = $pending_checkouts->next ) { |
| 204 |
my $issue = $c->unblessed_all_relateds; |
| 205 |
|
| 206 |
# check for reserves |
| 207 |
my $restype = GetReserveStatus( $issue->{'itemnumber'} ); |
| 208 |
if ($restype) { |
| 209 |
$issue->{'reserved'} = 1; |
| 210 |
} |
| 211 |
|
211 |
|
| 212 |
# Must be moved in a module if reused |
212 |
# Must be moved in a module if reused |
| 213 |
my $charges = Koha::Account::Lines->search( |
213 |
my $charges = Koha::Account::Lines->search( |
| 214 |
{ |
214 |
{ |
| 215 |
borrowernumber => $patron->borrowernumber, |
215 |
borrowernumber => $patron->borrowernumber, |
| 216 |
amountoutstanding => { '>' => 0 }, |
216 |
amountoutstanding => { '>' => 0 }, |
| 217 |
debit_type_code => [ 'OVERDUE', 'LOST' ], |
217 |
debit_type_code => [ 'OVERDUE', 'LOST' ], |
| 218 |
itemnumber => $issue->{itemnumber} |
218 |
itemnumber => $issue->{itemnumber} |
| 219 |
}, |
219 |
}, |
| 220 |
); |
220 |
); |
| 221 |
$issue->{charges} = $charges->total_outstanding; |
221 |
$issue->{charges} = $charges->total_outstanding; |
| 222 |
|
222 |
|
| 223 |
my $rental_fines = Koha::Account::Lines->search( |
223 |
my $rental_fines = Koha::Account::Lines->search( |
| 224 |
{ |
224 |
{ |
| 225 |
borrowernumber => $patron->borrowernumber, |
225 |
borrowernumber => $patron->borrowernumber, |
| 226 |
amountoutstanding => { '>' => 0 }, |
226 |
amountoutstanding => { '>' => 0 }, |
| 227 |
debit_type_code => { 'LIKE' => 'RENT_%' }, |
227 |
debit_type_code => { 'LIKE' => 'RENT_%' }, |
| 228 |
itemnumber => $issue->{itemnumber} |
228 |
itemnumber => $issue->{itemnumber} |
| 229 |
} |
|
|
| 230 |
); |
| 231 |
$issue->{rentalfines} = $rental_fines->total_outstanding; |
| 232 |
|
| 233 |
# check if item is renewable |
| 234 |
my ( $status, $renewerror, $info ) = CanBookBeRenewed( $patron, $c ); |
| 235 |
( |
| 236 |
$issue->{'renewcount'}, |
| 237 |
$issue->{'renewsallowed'}, |
| 238 |
$issue->{'renewsleft'}, |
| 239 |
$issue->{'unseencount'}, |
| 240 |
$issue->{'unseenallowed'}, |
| 241 |
$issue->{'unseenleft'} |
| 242 |
) = GetRenewCount( $patron, $c->item ); |
| 243 |
( $issue->{'renewalfee'}, $issue->{'renewalitemtype'} ) = |
| 244 |
GetIssuingCharges( $issue->{'itemnumber'}, $borrowernumber ); |
| 245 |
$issue->{itemtype_object} = Koha::ItemTypes->find( $c->item->effective_itemtype ); |
| 246 |
if ( $status && C4::Context->preference("OpacRenewalAllowed") ) { |
| 247 |
$are_renewable_items = 1; |
| 248 |
$issue->{'status'} = $status; |
| 249 |
} |
229 |
} |
|
|
230 |
); |
| 231 |
$issue->{rentalfines} = $rental_fines->total_outstanding; |
| 232 |
|
| 233 |
# check if item is renewable |
| 234 |
my ( $status, $renewerror, $info ) = CanBookBeRenewed( $patron, $c ); |
| 235 |
( |
| 236 |
$issue->{'renewcount'}, |
| 237 |
$issue->{'renewsallowed'}, |
| 238 |
$issue->{'renewsleft'}, |
| 239 |
$issue->{'unseencount'}, |
| 240 |
$issue->{'unseenallowed'}, |
| 241 |
$issue->{'unseenleft'} |
| 242 |
) = GetRenewCount( $patron, $c->item ); |
| 243 |
( $issue->{'renewalfee'}, $issue->{'renewalitemtype'} ) = |
| 244 |
GetIssuingCharges( $issue->{'itemnumber'}, $borrowernumber ); |
| 245 |
$issue->{itemtype_object} = Koha::ItemTypes->find( $c->item->effective_itemtype ); |
| 246 |
if ( $status && C4::Context->preference("OpacRenewalAllowed") ) { |
| 247 |
$are_renewable_items = 1; |
| 248 |
$issue->{'status'} = $status; |
| 249 |
} |
| 250 |
|
250 |
|
| 251 |
$issue->{'renewed'} = $renewed{ $issue->{'itemnumber'} }; |
251 |
$issue->{'renewed'} = $renewed{ $issue->{'itemnumber'} }; |
| 252 |
|
252 |
|
| 253 |
if ($renewerror) { |
253 |
if ($renewerror) { |
| 254 |
$issue->{'too_many'} = 1 if $renewerror eq 'too_many'; |
254 |
$issue->{'too_many'} = 1 if $renewerror eq 'too_many'; |
| 255 |
$issue->{'too_unseen'} = 1 if $renewerror eq 'too_unseen'; |
255 |
$issue->{'too_unseen'} = 1 if $renewerror eq 'too_unseen'; |
| 256 |
$issue->{'on_reserve'} = 1 if $renewerror eq 'on_reserve'; |
256 |
$issue->{'on_reserve'} = 1 if $renewerror eq 'on_reserve'; |
| 257 |
$issue->{'norenew_overdue'} = 1 if $renewerror eq 'overdue'; |
257 |
$issue->{'norenew_overdue'} = 1 if $renewerror eq 'overdue'; |
| 258 |
$issue->{'auto_renew'} = 1 if $renewerror eq 'auto_renew'; |
258 |
$issue->{'auto_renew'} = 1 if $renewerror eq 'auto_renew'; |
| 259 |
$issue->{'auto_too_soon'} = 1 if $renewerror eq 'auto_too_soon'; |
259 |
$issue->{'auto_too_soon'} = 1 if $renewerror eq 'auto_too_soon'; |
| 260 |
$issue->{'auto_too_late'} = 1 if $renewerror eq 'auto_too_late'; |
260 |
$issue->{'auto_too_late'} = 1 if $renewerror eq 'auto_too_late'; |
| 261 |
$issue->{'auto_too_much_oweing'} = 1 if $renewerror eq 'auto_too_much_oweing'; |
261 |
$issue->{'auto_too_much_oweing'} = 1 if $renewerror eq 'auto_too_much_oweing'; |
| 262 |
$issue->{'item_denied_renewal'} = 1 if $renewerror eq 'item_denied_renewal'; |
262 |
$issue->{'item_denied_renewal'} = 1 if $renewerror eq 'item_denied_renewal'; |
| 263 |
$issue->{'item_issued_to_other_patron'} = 1 if $renewerror eq 'item_issued_to_other_patron'; |
263 |
$issue->{'item_issued_to_other_patron'} = 1 if $renewerror eq 'item_issued_to_other_patron'; |
| 264 |
|
264 |
|
| 265 |
if ( $renewerror eq 'too_soon' ) { |
265 |
if ( $renewerror eq 'too_soon' ) { |
| 266 |
$issue->{'too_soon'} = 1; |
266 |
$issue->{'too_soon'} = 1; |
| 267 |
$issue->{'soonestrenewdate'} = $info->{soonest_renew_date}; |
267 |
$issue->{'soonestrenewdate'} = $info->{soonest_renew_date}; |
| 268 |
} |
|
|
| 269 |
} |
268 |
} |
|
|
269 |
} |
| 270 |
|
270 |
|
| 271 |
if ( $c->is_overdue ) { |
271 |
if ( $c->is_overdue ) { |
| 272 |
push @overdues, $issue; |
272 |
push @overdues, $issue; |
| 273 |
$overdues_count++; |
273 |
$overdues_count++; |
| 274 |
$issue->{'overdue'} = 1; |
274 |
$issue->{'overdue'} = 1; |
| 275 |
} else { |
275 |
} else { |
| 276 |
$issue->{'issued'} = 1; |
276 |
$issue->{'issued'} = 1; |
| 277 |
} |
277 |
} |
| 278 |
|
278 |
|
| 279 |
# imageurl: |
279 |
# imageurl: |
| 280 |
my $itemtype = $issue->{'itemtype'}; |
280 |
my $itemtype = $issue->{'itemtype'}; |
| 281 |
if ($itemtype) { |
281 |
if ($itemtype) { |
| 282 |
$issue->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} ); |
282 |
$issue->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} ); |
| 283 |
$issue->{'description'} = $itemtypes->{$itemtype}->{'description'}; |
283 |
$issue->{'description'} = $itemtypes->{$itemtype}->{'description'}; |
| 284 |
} |
284 |
} |
| 285 |
|
285 |
|
| 286 |
if ( C4::Context->preference('OpacStarRatings') eq 'all' ) { |
286 |
if ( C4::Context->preference('OpacStarRatings') eq 'all' ) { |
| 287 |
my $ratings = Koha::Ratings->search( { biblionumber => $issue->{biblionumber} } ); |
287 |
my $ratings = Koha::Ratings->search( { biblionumber => $issue->{biblionumber} } ); |
| 288 |
$issue->{ratings} = $ratings; |
288 |
$issue->{ratings} = $ratings; |
| 289 |
$issue->{my_rating} = |
289 |
$issue->{my_rating} = |
| 290 |
$borrowernumber ? $ratings->search( { borrowernumber => $borrowernumber } )->next : undef; |
290 |
$borrowernumber ? $ratings->search( { borrowernumber => $borrowernumber } )->next : undef; |
| 291 |
} |
291 |
} |
| 292 |
|
292 |
|
| 293 |
my $biblio_object = Koha::Biblios->find( $issue->{biblionumber} ); |
293 |
my $biblio_object = Koha::Biblios->find( $issue->{biblionumber} ); |
| 294 |
$issue->{biblio_object} = $biblio_object; |
294 |
$issue->{biblio_object} = $biblio_object; |
| 295 |
push @issuedat, $issue; |
295 |
push @issuedat, $issue; |
| 296 |
$count++; |
296 |
$count++; |
| 297 |
|
297 |
|
| 298 |
my $isbn = GetNormalizedISBN( $issue->{'isbn'} ); |
298 |
my $isbn = GetNormalizedISBN( $issue->{'isbn'} ); |
| 299 |
$issue->{normalized_isbn} = $isbn; |
299 |
$issue->{normalized_isbn} = $isbn; |
| 300 |
|
300 |
|
| 301 |
if ( C4::Context->preference('BakerTaylorEnabled') |
301 |
if ( C4::Context->preference('BakerTaylorEnabled') |
| 302 |
|| C4::Context->preference('SyndeticsEnabled') |
302 |
|| C4::Context->preference('SyndeticsEnabled') |
| 303 |
|| C4::Context->preference('SyndeticsCoverImages') ) |
303 |
|| C4::Context->preference('SyndeticsCoverImages') ) |
| 304 |
{ |
304 |
{ |
| 305 |
my $marcrecord = $biblio_object->metadata_record( |
305 |
my $marcrecord = $biblio_object->metadata_record( |
| 306 |
{ |
306 |
{ |
| 307 |
embed_items => 1, |
307 |
embed_items => 1, |
| 308 |
interface => 'opac', |
308 |
interface => 'opac', |
| 309 |
patron => $patron |
309 |
patron => $patron |
| 310 |
} |
310 |
} |
| 311 |
); |
311 |
); |
| 312 |
$issue->{normalized_upc} = GetNormalizedUPC( $marcrecord, C4::Context->preference('marcflavour') ); |
312 |
$issue->{normalized_upc} = GetNormalizedUPC( $marcrecord, C4::Context->preference('marcflavour') ); |
| 313 |
$issue->{normalized_oclc} = GetNormalizedOCLCNumber( $marcrecord, C4::Context->preference('marcflavour') ); |
313 |
$issue->{normalized_oclc} = GetNormalizedOCLCNumber( $marcrecord, C4::Context->preference('marcflavour') ); |
| 314 |
} |
314 |
} |
| 315 |
|
315 |
|
| 316 |
if ( C4::Context->preference('UseRecalls') ) { |
316 |
if ( C4::Context->preference('UseRecalls') ) { |
| 317 |
my $maybe_recalls = Koha::Recalls->search( |
317 |
my $maybe_recalls = Koha::Recalls->search( |
| 318 |
{ biblio_id => $issue->{biblionumber}, item_id => [ undef, $issue->{itemnumber} ], completed => 0 } ); |
318 |
{ biblio_id => $issue->{biblionumber}, item_id => [ undef, $issue->{itemnumber} ], completed => 0 } ); |
| 319 |
while ( my $recall = $maybe_recalls->next ) { |
319 |
while ( my $recall = $maybe_recalls->next ) { |
| 320 |
if ( $recall->checkout and $recall->checkout->issue_id == $issue->{issue_id} ) { |
320 |
if ( $recall->checkout and $recall->checkout->issue_id == $issue->{issue_id} ) { |
| 321 |
$issue->{recall} = 1; |
321 |
$issue->{recall} = 1; |
| 322 |
last; |
322 |
last; |
| 323 |
} |
|
|
| 324 |
} |
323 |
} |
| 325 |
} |
324 |
} |
| 326 |
} |
325 |
} |
| 327 |
} |
326 |
} |
| 328 |
my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); |
327 |
} |
| 329 |
$canrenew = 0 if ( $overduesblockrenewing ne 'allow' and $overdues_count == $count ) || !$are_renewable_items; |
328 |
my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); |
| 330 |
|
329 |
$canrenew = 0 if ( $overduesblockrenewing ne 'allow' and $overdues_count == $count ) || !$are_renewable_items; |
| 331 |
$template->param( ISSUES => \@issuedat ); |
330 |
|
| 332 |
$template->param( issues_count => $count ); |
331 |
$template->param( ISSUES => \@issuedat ); |
| 333 |
$template->param( canrenew => $canrenew ); |
332 |
$template->param( issues_count => $count ); |
| 334 |
$template->param( OVERDUES => \@overdues ); |
333 |
$template->param( canrenew => $canrenew ); |
| 335 |
$template->param( overdues_count => $overdues_count ); |
334 |
$template->param( OVERDUES => \@overdues ); |
| 336 |
|
335 |
$template->param( overdues_count => $overdues_count ); |
| 337 |
my $show_barcode = Koha::Patron::Attribute::Types->search( # FIXME we should not need this search |
336 |
|
| 338 |
{ code => ATTRIBUTE_SHOW_BARCODE } |
337 |
my $show_barcode = Koha::Patron::Attribute::Types->search( # FIXME we should not need this search |
| 339 |
)->count; |
338 |
{ code => ATTRIBUTE_SHOW_BARCODE } |
| 340 |
if ($show_barcode) { |
339 |
)->count; |
| 341 |
my $patron_show_barcode = $patron->get_extended_attribute(ATTRIBUTE_SHOW_BARCODE); |
340 |
if ($show_barcode) { |
| 342 |
undef $show_barcode if $patron_show_barcode and not $patron_show_barcode->attribute; |
341 |
my $patron_show_barcode = $patron->get_extended_attribute(ATTRIBUTE_SHOW_BARCODE); |
| 343 |
} |
342 |
undef $show_barcode if $patron_show_barcode and not $patron_show_barcode->attribute; |
| 344 |
$template->param( show_barcode => 1 ) if $show_barcode; |
343 |
} |
|
|
344 |
$template->param( show_barcode => 1 ) if $show_barcode; |
| 345 |
|
345 |
|
| 346 |
# now the reserved items.... |
346 |
# now the reserved items.... |
| 347 |
my $reserves = $patron->holds->filter_out_has_cancellation_requests; |
347 |
my $reserves = $patron->holds->filter_out_has_cancellation_requests; |
| 348 |
|
|
|
| 349 |
$template->param( |
| 350 |
RESERVES => $reserves, |
| 351 |
reserves_count => $reserves->count_holds, |
| 352 |
showpriority => $show_priority, |
| 353 |
); |
| 354 |
|
| 355 |
if ( C4::Context->preference('UseRecalls') ) { |
| 356 |
my $recalls = Koha::Recalls->search( { patron_id => $borrowernumber, completed => 0 } ); |
| 357 |
$template->param( RECALLS => $recalls ); |
| 358 |
} |
| 359 |
|
348 |
|
| 360 |
if ( C4::Context->preference('BakerTaylorEnabled') ) { |
349 |
$template->param( |
| 361 |
$template->param( |
350 |
RESERVES => $reserves, |
| 362 |
BakerTaylorEnabled => 1, |
351 |
reserves_count => $reserves->count_holds, |
| 363 |
BakerTaylorImageURL => &image_url(), |
352 |
showpriority => $show_priority, |
| 364 |
BakerTaylorLinkURL => &link_url(), |
353 |
); |
| 365 |
BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'), |
|
|
| 366 |
); |
| 367 |
} |
| 368 |
|
354 |
|
| 369 |
if ( C4::Context->preference("OPACAmazonCoverImages") |
355 |
if ( C4::Context->preference('UseRecalls') ) { |
| 370 |
or C4::Context->preference("GoogleJackets") |
356 |
my $recalls = Koha::Recalls->search( { patron_id => $borrowernumber, completed => 0 } ); |
| 371 |
or C4::Context->preference("BakerTaylorEnabled") |
357 |
$template->param( RECALLS => $recalls ); |
| 372 |
or C4::Context->preference("SyndeticsCoverImages") |
358 |
} |
| 373 |
or ( C4::Context->preference('OPACCustomCoverImages') and C4::Context->preference('CustomCoverImagesURL') ) ) |
|
|
| 374 |
{ |
| 375 |
$template->param( JacketImages => 1 ); |
| 376 |
} |
| 377 |
|
359 |
|
|
|
360 |
if ( C4::Context->preference('BakerTaylorEnabled') ) { |
| 378 |
$template->param( |
361 |
$template->param( |
| 379 |
overdrive_error => scalar $query->param('overdrive_error') || undef, |
362 |
BakerTaylorEnabled => 1, |
| 380 |
overdrive_tab => scalar $query->param('overdrive_tab') || 0, |
363 |
BakerTaylorImageURL => &image_url(), |
|
|
364 |
BakerTaylorLinkURL => &link_url(), |
| 365 |
BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'), |
| 381 |
); |
366 |
); |
|
|
367 |
} |
| 382 |
|
368 |
|
| 383 |
my $patron_messages = Koha::Patron::Messages->search( |
369 |
if ( C4::Context->preference("OPACAmazonCoverImages") |
| 384 |
{ |
370 |
or C4::Context->preference("GoogleJackets") |
| 385 |
borrowernumber => $borrowernumber, |
371 |
or C4::Context->preference("BakerTaylorEnabled") |
| 386 |
message_type => 'B', |
372 |
or C4::Context->preference("SyndeticsCoverImages") |
| 387 |
} |
373 |
or ( C4::Context->preference('OPACCustomCoverImages') and C4::Context->preference('CustomCoverImagesURL') ) ) |
| 388 |
); |
374 |
{ |
|
|
375 |
$template->param( JacketImages => 1 ); |
| 376 |
} |
| 389 |
|
377 |
|
| 390 |
if ( C4::Context->preference('AllowPatronToSetCheckoutsVisibilityForGuarantor') |
378 |
$template->param( |
| 391 |
|| C4::Context->preference('AllowStaffToSetCheckoutsVisibilityForGuarantor') ) |
379 |
overdrive_error => scalar $query->param('overdrive_error') || undef, |
| 392 |
{ |
380 |
overdrive_tab => scalar $query->param('overdrive_tab') || 0, |
| 393 |
my @relatives; |
381 |
); |
| 394 |
|
382 |
|
| 395 |
# Filter out guarantees that don't want guarantor to see checkouts |
383 |
my $patron_messages = Koha::Patron::Messages->search( |
| 396 |
foreach my $gr ( $patron->guarantee_relationships->as_list ) { |
384 |
{ |
| 397 |
my $g = $gr->guarantee; |
385 |
borrowernumber => $borrowernumber, |
| 398 |
push( @relatives, $g ) if $g->privacy_guarantor_checkouts; |
386 |
message_type => 'B', |
| 399 |
} |
|
|
| 400 |
$template->param( relatives => \@relatives ); |
| 401 |
} |
387 |
} |
|
|
388 |
); |
| 402 |
|
389 |
|
| 403 |
if ( C4::Context->preference('AllowPatronToSetFinesVisibilityForGuarantor') |
390 |
if ( C4::Context->preference('AllowPatronToSetCheckoutsVisibilityForGuarantor') |
| 404 |
|| C4::Context->preference('AllowStaffToSetFinesVisibilityForGuarantor') ) |
391 |
|| C4::Context->preference('AllowStaffToSetCheckoutsVisibilityForGuarantor') ) |
| 405 |
{ |
392 |
{ |
| 406 |
my @relatives_with_fines; |
393 |
my @relatives; |
| 407 |
|
394 |
|
| 408 |
# Filter out guarantees that don't want guarantor to see checkouts |
395 |
# Filter out guarantees that don't want guarantor to see checkouts |
| 409 |
foreach my $gr ( $patron->guarantee_relationships->as_list ) { |
396 |
foreach my $gr ( $patron->guarantee_relationships->as_list ) { |
| 410 |
my $g = $gr->guarantee; |
397 |
my $g = $gr->guarantee; |
| 411 |
push( @relatives_with_fines, $g ) if $g->privacy_guarantor_fines; |
398 |
push( @relatives, $g ) if $g->privacy_guarantor_checkouts; |
| 412 |
} |
|
|
| 413 |
$template->param( relatives_with_fines => \@relatives_with_fines ); |
| 414 |
} |
399 |
} |
|
|
400 |
$template->param( relatives => \@relatives ); |
| 401 |
} |
| 415 |
|
402 |
|
| 416 |
if ( C4::Context->preference("ArticleRequests") ) { |
403 |
if ( C4::Context->preference('AllowPatronToSetFinesVisibilityForGuarantor') |
| 417 |
$template->param( |
404 |
|| C4::Context->preference('AllowStaffToSetFinesVisibilityForGuarantor') ) |
| 418 |
current_article_requests => [ $patron->article_requests->filter_by_current->as_list ], |
405 |
{ |
| 419 |
); |
406 |
my @relatives_with_fines; |
| 420 |
} |
|
|
| 421 |
|
407 |
|
| 422 |
my $self_renewal_available = $patron->is_eligible_for_self_renewal(); |
408 |
# Filter out guarantees that don't want guarantor to see checkouts |
| 423 |
my $self_renewal_alert; |
409 |
foreach my $gr ( $patron->guarantee_relationships->as_list ) { |
| 424 |
my $self_renewal_success = $query->param('self_renewal_success'); |
410 |
my $g = $gr->guarantee; |
| 425 |
$self_renewal_alert = $patron->category->self_renewal_failure_message |
411 |
push( @relatives_with_fines, $g ) if $g->privacy_guarantor_fines; |
| 426 |
if defined $self_renewal_success && !$self_renewal_success; |
412 |
} |
| 427 |
my $self_renewal_confirmation_sent = $query->param('confirmation_sent'); |
413 |
$template->param( relatives_with_fines => \@relatives_with_fines ); |
|
|
414 |
} |
| 428 |
|
415 |
|
|
|
416 |
if ( C4::Context->preference("ArticleRequests") ) { |
| 429 |
$template->param( |
417 |
$template->param( |
| 430 |
patron_messages => $patron_messages, |
418 |
current_article_requests => [ $patron->article_requests->filter_by_current->as_list ], |
| 431 |
opacnote => $borr->{opacnote}, |
419 |
); |
| 432 |
patronupdate => $patronupdate, |
420 |
} |
| 433 |
OpacRenewalAllowed => C4::Context->preference("OpacRenewalAllowed"), |
421 |
|
| 434 |
userview => 1, |
422 |
my $self_renewal_available = $patron->is_eligible_for_self_renewal(); |
| 435 |
tab => scalar $query->param('tab') || q{}, |
423 |
my $self_renewal_alert; |
| 436 |
SuspendHoldsOpac => C4::Context->preference('SuspendHoldsOpac'), |
424 |
my $self_renewal_success = $query->param('self_renewal_success'); |
| 437 |
AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'), |
425 |
$self_renewal_alert = $patron->category->self_renewal_failure_message |
| 438 |
OpacHoldNotes => C4::Context->preference('OpacHoldNotes'), |
426 |
if defined $self_renewal_success && !$self_renewal_success; |
| 439 |
failed_holds => scalar $query->param('failed_holds'), |
427 |
my $self_renewal_confirmation_sent = $query->param('confirmation_sent'); |
|
|
428 |
|
| 429 |
$template->param( |
| 430 |
patron_messages => $patron_messages, |
| 431 |
opacnote => $borr->{opacnote}, |
| 432 |
patronupdate => $patronupdate, |
| 433 |
OpacRenewalAllowed => C4::Context->preference("OpacRenewalAllowed"), |
| 434 |
userview => 1, |
| 435 |
tab => scalar $query->param('tab') || q{}, |
| 436 |
SuspendHoldsOpac => C4::Context->preference('SuspendHoldsOpac'), |
| 437 |
AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'), |
| 438 |
OpacHoldNotes => C4::Context->preference('OpacHoldNotes'), |
| 439 |
failed_holds => scalar $query->param('failed_holds'), |
| 440 |
self_renewal_available => $self_renewal_available, |
440 |
self_renewal_available => $self_renewal_available, |
| 441 |
self_renewal_success => $self_renewal_success, |
441 |
self_renewal_success => $self_renewal_success, |
| 442 |
self_renewal_alert => $self_renewal_alert, |
442 |
self_renewal_alert => $self_renewal_alert, |