View | Details | Raw Unified | Return to bug 14787
Collapse All | Expand All

(-)a/circ/circulation.pl (-218 / +229 lines)
Lines 25-43 Link Here
25
# FIXME There are too many calls to Koha::Patrons->find in this script
25
# FIXME There are too many calls to Koha::Patrons->find in this script
26
26
27
use Modern::Perl;
27
use Modern::Perl;
28
use CGI qw ( -utf8 );
28
use CGI         qw ( -utf8 );
29
use URI::Escape qw( uri_escape_utf8 );
29
use URI::Escape qw( uri_escape_utf8 );
30
use DateTime;
30
use DateTime;
31
use DateTime::Duration;
31
use DateTime::Duration;
32
use Scalar::Util qw( blessed looks_like_number );
32
use Scalar::Util qw( blessed looks_like_number );
33
use Try::Tiny;
33
use Try::Tiny;
34
use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers );
34
use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers );
35
use C4::Auth qw( get_session get_template_and_user );
35
use C4::Auth   qw( get_session get_template_and_user );
36
use C4::Koha;
36
use C4::Koha;
37
use C4::Circulation qw( barcodedecode CanBookBeIssued AddIssue AddReturn );
37
use C4::Circulation qw( barcodedecode CanBookBeIssued AddIssue AddReturn );
38
use C4::Members;
38
use C4::Members;
39
use C4::Biblio qw( TransformMarcToKoha );
39
use C4::Biblio   qw( TransformMarcToKoha );
40
use C4::Search qw( new_record_from_zebra );
40
use C4::Search   qw( new_record_from_zebra );
41
use C4::Reserves qw( ModReserveAffect );
41
use C4::Reserves qw( ModReserveAffect );
42
use Koha::Holds;
42
use Koha::Holds;
43
use C4::Context;
43
use C4::Context;
Lines 69-81 my $borrowernumber = $query->param('borrowernumber'); Link Here
69
my $barcodes       = [];
69
my $barcodes       = [];
70
my $barcode        = $query->param('barcode');
70
my $barcode        = $query->param('barcode');
71
71
72
73
# Barcode given by user could be '0'
72
# Barcode given by user could be '0'
74
if ( $barcode || ( defined($barcode) && $barcode eq '0' ) ) {
73
if ( $barcode || ( defined($barcode) && $barcode eq '0' ) ) {
75
    $barcodes = [ $barcode ];
74
    $barcodes = [$barcode];
76
} else {
75
} else {
77
    my $filefh = $query->upload('uploadfile');
76
    my $filefh = $query->upload('uploadfile');
78
    if ( $filefh ) {
77
    if ($filefh) {
79
        while ( my $content = <$filefh> ) {
78
        while ( my $content = <$filefh> ) {
80
            $content =~ s/[\r\n]*$//g;
79
            $content =~ s/[\r\n]*$//g;
81
            push @$barcodes, $content if $content;
80
            push @$barcodes, $content if $content;
Lines 90-102 if ( $barcode || ( defined($barcode) && $barcode eq '0' ) ) { Link Here
90
$barcodes = [ uniq @$barcodes ];
89
$barcodes = [ uniq @$barcodes ];
91
90
92
my $template_name = q|circ/circulation.tt|;
91
my $template_name = q|circ/circulation.tt|;
93
my $patron = $borrowernumber ? Koha::Patrons->find( $borrowernumber ) : undef;
92
my $patron        = $borrowernumber ? Koha::Patrons->find($borrowernumber) : undef;
94
my $batch = $query->param('batch');
93
my $batch         = $query->param('batch');
95
my $batch_allowed = 0;
94
my $batch_allowed = 0;
96
if ( $batch && C4::Context->preference('BatchCheckouts') ) {
95
if ( $batch && C4::Context->preference('BatchCheckouts') ) {
97
    $template_name = q|circ/circulation_batch_checkouts.tt|;
96
    $template_name = q|circ/circulation_batch_checkouts.tt|;
98
    my @batch_category_codes = split ',', C4::Context->preference('BatchCheckoutsValidCategories');
97
    my @batch_category_codes = split ',', C4::Context->preference('BatchCheckoutsValidCategories');
99
    my $categorycode = $patron->categorycode;
98
    my $categorycode         = $patron->categorycode;
100
    if ( $categorycode && grep { $_ eq $categorycode } @batch_category_codes ) {
99
    if ( $categorycode && grep { $_ eq $categorycode } @batch_category_codes ) {
101
        $batch_allowed = 1;
100
        $batch_allowed = 1;
102
    } else {
101
    } else {
Lines 104-115 if ( $batch && C4::Context->preference('BatchCheckouts') ) { Link Here
104
    }
103
    }
105
}
104
}
106
105
107
my ( $template, $loggedinuser, $cookie ) = get_template_and_user (
106
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
108
    {
107
    {
109
        template_name   => $template_name,
108
        template_name => $template_name,
110
        query           => $query,
109
        query         => $query,
111
        type            => "intranet",
110
        type          => "intranet",
112
        flagsrequired   => { circulate => 'circulate_remaining_permissions' },
111
        flagsrequired => { circulate => 'circulate_remaining_permissions' },
113
    }
112
    }
114
);
113
);
115
114
Lines 135-141 if ( C4::Context->preference("AutoSwitchPatron") && $barcode ) { Link Here
135
        undef $barcode;
134
        undef $barcode;
136
        undef $borrowernumber;
135
        undef $borrowernumber;
137
        undef $patron;
136
        undef $patron;
138
        $barcodes = [];
137
        $barcodes     = [];
139
        $autoswitched = 1;
138
        $autoswitched = 1;
140
    }
139
    }
141
}
140
}
Lines 154-170 if ( $op eq 'cud-confirm_hold' && $query->param('confirm_hold') ) { Link Here
154
    ModReserveAffect( $hold_itemnumber, $hold_borrowernumber, $diffBranchSend, $reserve_id, $desk_id );
153
    ModReserveAffect( $hold_itemnumber, $hold_borrowernumber, $diffBranchSend, $reserve_id, $desk_id );
155
}
154
}
156
155
157
156
my $logged_in_user = Koha::Patrons->find($loggedinuser);
158
my $logged_in_user = Koha::Patrons->find( $loggedinuser );
159
157
160
my $force_allow_issue = $query->param('forceallow') || 0;
158
my $force_allow_issue = $query->param('forceallow') || 0;
161
if (!C4::Auth::haspermission( $userenv->{id} , { circulate => 'force_checkout' } )) {
159
if ( !C4::Auth::haspermission( $userenv->{id}, { circulate => 'force_checkout' } ) ) {
162
    $force_allow_issue = 0;
160
    $force_allow_issue = 0;
163
}
161
}
164
my $onsite_checkout = $query->param('onsite_checkout');
162
my $onsite_checkout = $query->param('onsite_checkout');
165
163
166
if (C4::Context->preference("OnSiteCheckoutAutoCheck") && $onsite_checkout eq "on") {
164
if ( C4::Context->preference("OnSiteCheckoutAutoCheck") && $onsite_checkout eq "on" ) {
167
    $template->param(onsite_checkout => $onsite_checkout);
165
    $template->param( onsite_checkout => $onsite_checkout );
168
}
166
}
169
167
170
my @failedrenews = $query->multi_param('failedrenew');    # expected to be itemnumbers
168
my @failedrenews = $query->multi_param('failedrenew');    # expected to be itemnumbers
Lines 175-187 my @failedreturns = $query->multi_param('failedreturn'); Link Here
175
our %return_failed = ();
173
our %return_failed = ();
176
for (@failedreturns) { $return_failed{$_} = 1; }
174
for (@failedreturns) { $return_failed{$_} = 1; }
177
175
178
for my $barcode ( @$barcodes ) {
176
for my $barcode (@$barcodes) {
179
    $barcode = barcodedecode( $barcode ) if $barcode;
177
    $barcode = barcodedecode($barcode) if $barcode;
180
}
178
}
181
179
182
my $stickyduedate  = $query->param('stickyduedate') || $session->param('stickyduedate');
180
my $stickyduedate      = $query->param('stickyduedate')      || $session->param('stickyduedate');
183
my $duedatespec    = $query->param('duedatespec')   || $session->param('stickyduedate');
181
my $duedatespec        = $query->param('duedatespec')        || $session->param('stickyduedate');
184
my $restoreduedatespec  = $query->param('restoreduedatespec') || $duedatespec || $session->param('stickyduedate');
182
my $restoreduedatespec = $query->param('restoreduedatespec') || $duedatespec || $session->param('stickyduedate');
185
if ( $restoreduedatespec && $restoreduedatespec eq "highholds_empty" ) {
183
if ( $restoreduedatespec && $restoreduedatespec eq "highholds_empty" ) {
186
    undef $restoreduedatespec;
184
    undef $restoreduedatespec;
187
}
185
}
Lines 189-235 my $issueconfirmed = $query->param('issueconfirmed'); Link Here
189
my $cancelreserve  = $query->param('cancelreserve');
187
my $cancelreserve  = $query->param('cancelreserve');
190
my $cancel_recall  = $query->param('cancel_recall');
188
my $cancel_recall  = $query->param('cancel_recall');
191
my $recall_id      = $query->param('recall_id');
189
my $recall_id      = $query->param('recall_id');
192
my $debt_confirmed = $query->param('debt_confirmed') || 0; # Don't show the debt error dialog twice
190
my $debt_confirmed = $query->param('debt_confirmed') || 0;     # Don't show the debt error dialog twice
193
my $charges        = $query->param('charges') || q{};
191
my $charges        = $query->param('charges')        || q{};
194
192
195
# Check if stickyduedate is turned off
193
# Check if stickyduedate is turned off
196
if ( @$barcodes ) {
194
if (@$barcodes) {
195
197
    # was stickyduedate loaded from session?
196
    # was stickyduedate loaded from session?
198
    if ( $stickyduedate && ! $query->param("stickyduedate") ) {
197
    if ( $stickyduedate && !$query->param("stickyduedate") ) {
199
        $session->clear( 'stickyduedate' );
198
        $session->clear('stickyduedate');
200
        $stickyduedate  = $query->param('stickyduedate');
199
        $stickyduedate = $query->param('stickyduedate');
201
        $duedatespec    = $query->param('duedatespec');
200
        $duedatespec   = $query->param('duedatespec');
202
    }
201
    }
203
    $session->param('auto_renew', scalar $query->param('auto_renew'));
202
    $session->param( 'auto_renew', scalar $query->param('auto_renew') );
204
}
203
} else {
205
else {
206
    $session->clear('auto_renew');
204
    $session->clear('auto_renew');
207
}
205
}
208
206
209
$template->param( auto_renew => $session->param('auto_renew') );
207
$template->param( auto_renew => $session->param('auto_renew') );
210
208
211
my ($datedue,$invalidduedate);
209
my ( $datedue, $invalidduedate );
212
210
213
my $duedatespec_allow = C4::Context->preference('SpecifyDueDate');
211
my $duedatespec_allow = C4::Context->preference('SpecifyDueDate');
214
if( $onsite_checkout && !$duedatespec_allow ) {
212
if ( $onsite_checkout && !$duedatespec_allow ) {
215
    $datedue = dt_from_string()->truncate(to => 'day');
213
    $datedue = dt_from_string()->truncate( to => 'day' );
216
    $datedue->set_hour(23);
214
    $datedue->set_hour(23);
217
    $datedue->set_minute(59);
215
    $datedue->set_minute(59);
218
} elsif( $duedatespec_allow ) {
216
} elsif ($duedatespec_allow) {
219
    if ( $duedatespec ) {
217
    if ($duedatespec) {
220
        $datedue = eval { dt_from_string( $duedatespec ) };
218
        $datedue = eval { dt_from_string($duedatespec) };
221
        if (! $datedue ) {
219
        if ( !$datedue ) {
222
            $invalidduedate = 1;
220
            $invalidduedate = 1;
223
            $template->param( IMPOSSIBLE=>1, INVALID_DATE=>$duedatespec );
221
            $template->param( IMPOSSIBLE => 1, INVALID_DATE => $duedatespec );
224
        }
222
        }
225
    }
223
    }
226
}
224
}
227
my $reduced_datedue = $query->param('reduceddue');
225
my $reduced_datedue = $query->param('reduceddue');
228
if ( $reduced_datedue ) {
226
if ($reduced_datedue) {
229
    $datedue = dt_from_string( $reduced_datedue );
227
    $datedue = dt_from_string($reduced_datedue);
230
}
228
}
231
229
232
my $inprocess = (@$barcodes == 0) ? '' : $query->param('inprocess');
230
my $inprocess = ( @$barcodes == 0 ) ? '' : $query->param('inprocess');
233
if ( @$barcodes == 0 && $charges eq 'yes' ) {
231
if ( @$barcodes == 0 && $charges eq 'yes' ) {
234
    $template->param(
232
    $template->param(
235
        PAYCHARGES     => 'yes',
233
        PAYCHARGES     => 'yes',
Lines 245-287 my $message; Link Here
245
if ($findborrower) {
243
if ($findborrower) {
246
    Koha::Plugins->call( 'patron_barcode_transform', \$findborrower );
244
    Koha::Plugins->call( 'patron_barcode_transform', \$findborrower );
247
    my $patron = Koha::Patrons->find( { cardnumber => $findborrower } );
245
    my $patron = Koha::Patrons->find( { cardnumber => $findborrower } );
248
    if ( $patron ) {
246
    if ($patron) {
249
        $borrowernumber = $patron->borrowernumber;
247
        $borrowernumber = $patron->borrowernumber;
250
    } else {
248
    } else {
251
        print $query->redirect( "/cgi-bin/koha/members/member.pl?quicksearch=1&circsearch=1&searchmember=" . uri_escape_utf8($findborrower) );
249
        print $query->redirect( "/cgi-bin/koha/members/member.pl?quicksearch=1&circsearch=1&searchmember="
250
                . uri_escape_utf8($findborrower) );
252
        exit;
251
        exit;
253
    }
252
    }
254
}
253
}
255
254
256
# get the borrower information.....
255
# get the borrower information.....
257
my $balance = 0;
256
my $balance = 0;
258
$patron ||= Koha::Patrons->find( $borrowernumber ) if $borrowernumber;
257
$patron ||= Koha::Patrons->find($borrowernumber) if $borrowernumber;
259
if ($patron) {
258
if ($patron) {
260
259
261
    $template->param( borrowernumber => $patron->borrowernumber );
260
    $template->param( borrowernumber => $patron->borrowernumber );
262
    output_and_exit_if_error( $query, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
261
    output_and_exit_if_error(
262
        $query, $cookie, $template,
263
        { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron }
264
    );
263
265
264
    my $overdues = $patron->overdues;
266
    my $overdues = $patron->overdues;
265
    my $issues = $patron->checkouts;
267
    my $issues   = $patron->checkouts;
266
    $balance = $patron->account->balance;
268
    $balance = $patron->account->balance;
267
269
268
269
    # if the expiry date is before today ie they have expired
270
    # if the expiry date is before today ie they have expired
270
    if ( $patron->is_expired ) {
271
    if ( $patron->is_expired ) {
272
271
        #borrowercard expired, no issues
273
        #borrowercard expired, no issues
272
        $template->param(
274
        $template->param(
273
            noissues => ($force_allow_issue) ? 0 : "1",
275
            noissues   => ($force_allow_issue) ? 0 : "1",
274
            forceallow => $force_allow_issue,
276
            forceallow => $force_allow_issue,
275
            expired => "1",
277
            expired    => "1",
276
        );
278
        );
277
    }
279
    }
280
278
    # check for NotifyBorrowerDeparture
281
    # check for NotifyBorrowerDeparture
279
    elsif ( $patron->is_going_to_expire ) {
282
    elsif ( $patron->is_going_to_expire ) {
283
280
        # borrower card soon to expire warn librarian
284
        # borrower card soon to expire warn librarian
281
        $template->param( "warndeparture" => $patron->dateexpiry ,
285
        $template->param(
282
                        );
286
            "warndeparture" => $patron->dateexpiry,
283
        if (C4::Context->preference('ReturnBeforeExpiry')){
287
        );
284
            $template->param("returnbeforeexpiry" => 1);
288
        if ( C4::Context->preference('ReturnBeforeExpiry') ) {
289
            $template->param( "returnbeforeexpiry" => 1 );
285
        }
290
        }
286
    }
291
    }
287
    $template->param(
292
    $template->param(
Lines 305-312 if ($patron) { Link Here
305
    # Calculate and display patron's age
310
    # Calculate and display patron's age
306
    if ( !$patron->is_valid_age ) {
311
    if ( !$patron->is_valid_age ) {
307
        $template->param( age_limitations => 1 );
312
        $template->param( age_limitations => 1 );
308
        $template->param( age_low => $patron->category->dateofbirthrequired );
313
        $template->param( age_low         => $patron->category->dateofbirthrequired );
309
        $template->param( age_high => $patron->category->upperagelimit );
314
        $template->param( age_high        => $patron->category->upperagelimit );
310
    }
315
    }
311
316
312
    unless (
317
    unless (
Lines 320-328 if ($patron) { Link Here
320
# STEP 3 : ISSUING
325
# STEP 3 : ISSUING
321
#
326
#
322
#
327
#
323
if (@$barcodes && $op eq 'cud-checkout') {
328
if ( @$barcodes && $op eq 'cud-checkout' ) {
324
    my $checkout_infos;
329
    my $checkout_infos;
325
    for my $barcode ( @$barcodes ) {
330
    for my $barcode (@$barcodes) {
326
331
327
        my $template_params = {
332
        my $template_params = {
328
            barcode         => $barcode,
333
            barcode         => $barcode,
Lines 354-366 if (@$barcodes && $op eq 'cud-checkout') { Link Here
354
359
355
        my $blocker = $invalidduedate ? 1 : 0;
360
        my $blocker = $invalidduedate ? 1 : 0;
356
361
357
        $template_params->{alert} = $alerts;
362
        $template_params->{alert}    = $alerts;
358
        $template_params->{messages} = $messages;
363
        $template_params->{messages} = $messages;
359
364
360
        my $item = Koha::Items->find({ barcode => $barcode });
365
        my $item = Koha::Items->find( { barcode => $barcode } );
361
366
362
        my $biblio;
367
        my $biblio;
363
        if ( $item ) {
368
        if ($item) {
364
            $biblio = $item->biblio;
369
            $biblio = $item->biblio;
365
        }
370
        }
366
371
Lines 384-413 if (@$barcodes && $op eq 'cud-checkout') { Link Here
384
389
385
        # Fix for bug 7494: optional checkout-time fallback search for a book
390
        # Fix for bug 7494: optional checkout-time fallback search for a book
386
391
387
        if ( $issuingimpossible->{'UNKNOWN_BARCODE'}
392
        if (   $issuingimpossible->{'UNKNOWN_BARCODE'}
388
            && C4::Context->preference("itemBarcodeFallbackSearch")
393
            && C4::Context->preference("itemBarcodeFallbackSearch")
389
            && not $batch
394
            && not $batch )
390
        )
391
        {
395
        {
392
        $template_params->{FALLBACK} = 1;
396
            $template_params->{FALLBACK} = 1;
393
397
394
            my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
398
            my $searcher = Koha::SearchEngine::Search->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
395
            my $query = "kw=" . $barcode;
399
            my $query    = "kw=" . $barcode;
396
            my ( $searcherror, $results, $total_hits ) = $searcher->simple_search_compat($query, 0, 10);
400
            my ( $searcherror, $results, $total_hits ) = $searcher->simple_search_compat( $query, 0, 10 );
397
401
398
            # if multiple hits, offer options to librarian
402
            # if multiple hits, offer options to librarian
399
            if ( $total_hits > 0 ) {
403
            if ( $total_hits > 0 ) {
400
                my @barcodes;
404
                my @barcodes;
401
                foreach my $hit ( @{$results} ) {
405
                foreach my $hit ( @{$results} ) {
402
                    my $chosen = # Maybe easier to retrieve the itemnumber from $hit?
406
                    my $chosen =    # Maybe easier to retrieve the itemnumber from $hit?
403
                    TransformMarcToKoha({ record => C4::Search::new_record_from_zebra('biblioserver',$hit) });
407
                        TransformMarcToKoha( { record => C4::Search::new_record_from_zebra( 'biblioserver', $hit ) } );
404
408
405
                    # offer all barcodes individually
409
                    # offer all barcodes individually
406
                    if ( $chosen->{barcode} ) {
410
                    if ( $chosen->{barcode} ) {
407
                        push @barcodes, sort split(/\s*\|\s*/, $chosen->{barcode});
411
                        push @barcodes, sort split( /\s*\|\s*/, $chosen->{barcode} );
408
                    }
412
                    }
409
                }
413
                }
410
                my $items = Koha::Items->search({ barcode => {-in => \@barcodes}});
414
                my $items = Koha::Items->search( { barcode => { -in => \@barcodes } } );
411
                $template_params->{options} = $items;
415
                $template_params->{options} = $items;
412
            }
416
            }
413
        }
417
        }
Lines 425-432 if (@$barcodes && $op eq 'cud-checkout') { Link Here
425
            $blocker                              = 1;
429
            $blocker                              = 1;
426
        }
430
        }
427
431
428
        foreach my $code ( @blocking_error_codes ) {
432
        foreach my $code (@blocking_error_codes) {
429
            if ($issuingimpossible->{$code}) {
433
            if ( $issuingimpossible->{$code} ) {
430
                $template_params->{$code} = $issuingimpossible->{$code};
434
                $template_params->{$code} = $issuingimpossible->{$code};
431
435
432
                $template_params->{IMPOSSIBLE} = 1;
436
                $template_params->{IMPOSSIBLE} = 1;
Lines 442-448 if (@$barcodes && $op eq 'cud-checkout') { Link Here
442
            my $claims = Koha::Checkouts::ReturnClaims->search(
446
            my $claims = Koha::Checkouts::ReturnClaims->search(
443
                {
447
                {
444
                    itemnumber => $item->id,
448
                    itemnumber => $item->id,
445
                    resolution => undef,
446
                }
449
                }
447
            );
450
            );
448
            if ( $claims->count ) {
451
            if ( $claims->count ) {
Lines 463-527 if (@$barcodes && $op eq 'cud-checkout') { Link Here
463
            }
466
            }
464
        }
467
        }
465
468
466
    if( $item and ( !$blocker or $force_allow_issue ) ){
469
        if ( $item and ( !$blocker or $force_allow_issue ) ) {
467
        my $confirm_required = 0;
470
            my $confirm_required = 0;
468
        unless($issueconfirmed){
471
            unless ($issueconfirmed) {
469
            #  Get the item title for more information
472
470
            my $materials = $item->materials;
473
                #  Get the item title for more information
471
            my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $biblio->frameworkcode, kohafield => 'items.materials', authorised_value => $materials });
474
                my $materials    = $item->materials;
472
            $materials = $descriptions->{lib} // $materials;
475
                my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field(
473
            $template_params->{ADDITIONAL_MATERIALS} = $materials;
474
            $template_params->{itemhomebranch} = $item->homebranch;
475
476
            my $patron_session_confirmation = $query->cookie('patronSessionConfirmation') || undef;
477
            my ( $patron_for_session, $session_confirmations ) = split( /:/, $patron_session_confirmation, 2 );
478
            my $patron_match = $borrowernumber == $patron_for_session;
479
            my @conf_keys    = split( /\|/, $session_confirmations );
480
            $template_params->{sessionConfirmationKeys} = ();
481
482
            # pass needsconfirmation to template if issuing is possible and user hasn't yet confirmed.
483
            foreach my $needsconfirmation_key ( keys %$needsconfirmation ) {
484
                if ( $needsconfirmation_key eq 'BOOKED_TO_ANOTHER' ) {
485
                    my $rule = Koha::CirculationRules->get_effective_rule(
486
                        {
487
                            rule_name  => 'bookings_lead_period',
488
                            itemtype   => $item->effective_itemtype,
489
                            branchcode => "*"
490
                        }
491
                    );
492
                    my $preparation_period = $rule ? $rule->rule_value : 1;
493
                    my $reduceddue =
494
                        dt_from_string( $$needsconfirmation{$needsconfirmation_key}->start_date )
495
                        ->subtract( days => $preparation_period );
496
                    $template_params->{reduceddue} = $reduceddue;
497
                }
498
                next
499
                    if $patron_match
500
                    && scalar(@conf_keys) > 0
501
                    && grep( { $needsconfirmation_key eq $_ } @conf_keys );
502
503
                $template_params->{$needsconfirmation_key}    = $needsconfirmation->{$needsconfirmation_key};
504
                $template_params->{getTitleMessageIteminfo}   = $biblio->title;
505
                $template_params->{getBarcodeMessageIteminfo} = $item->barcode;
506
                $template_params->{NEEDSCONFIRMATION}         = 1;
507
                $confirm_required                             = 1;
508
                push( @{ $template_params->{sessionConfirmationKeys} }, $needsconfirmation_key );
509
            }
510
        }
511
        unless ($confirm_required) {
512
            my $switch_onsite_checkout = exists $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED};
513
            if ( C4::Context->preference('UseRecalls') && !$recall_id ) {
514
                my $recall = Koha::Recalls->find(
515
                    {
476
                    {
516
                        biblio_id => $item->biblionumber,
477
                        frameworkcode    => $biblio->frameworkcode, kohafield => 'items.materials',
517
                        item_id   => [ undef,       $item->itemnumber ],
478
                        authorised_value => $materials
518
                        status    => [ 'requested', 'waiting' ],
519
                        completed => 0,
520
                        patron_id => $patron->borrowernumber,
521
                    }
479
                    }
522
                );
480
                );
523
                $recall_id = ( $recall and $recall->id ) ? $recall->id : undef;
481
                $materials                               = $descriptions->{lib} // $materials;
482
                $template_params->{ADDITIONAL_MATERIALS} = $materials;
483
                $template_params->{itemhomebranch}       = $item->homebranch;
484
485
                my $patron_session_confirmation = $query->cookie('patronSessionConfirmation') || undef;
486
                my ( $patron_for_session, $session_confirmations ) = split( /:/, $patron_session_confirmation, 2 );
487
                my $patron_match = $borrowernumber == $patron_for_session;
488
                my @conf_keys    = split( /\|/, $session_confirmations );
489
                $template_params->{sessionConfirmationKeys} = ();
490
491
                # pass needsconfirmation to template if issuing is possible and user hasn't yet confirmed.
492
                foreach my $needsconfirmation_key ( keys %$needsconfirmation ) {
493
                    if ( $needsconfirmation_key eq 'BOOKED_TO_ANOTHER' ) {
494
                        my $rule = Koha::CirculationRules->get_effective_rule(
495
                            {
496
                                rule_name  => 'bookings_lead_period',
497
                                itemtype   => $item->effective_itemtype,
498
                                branchcode => "*"
499
                            }
500
                        );
501
                        my $preparation_period = $rule ? $rule->rule_value : 1;
502
                        my $reduceddue = dt_from_string( $$needsconfirmation{$needsconfirmation_key}->start_date )
503
504
                            ->subtract( days => $preparation_period );
505
                        $template_params->{reduceddue} = $reduceddue;
506
                    }
507
                    next
508
                        if $patron_match
509
                        && scalar(@conf_keys) > 0
510
                        && grep( { $needsconfirmation_key eq $_ } @conf_keys );
511
512
                    $template_params->{$needsconfirmation_key}    = $needsconfirmation->{$needsconfirmation_key};
513
                    $template_params->{getTitleMessageIteminfo}   = $biblio->title;
514
                    $template_params->{getBarcodeMessageIteminfo} = $item->barcode;
515
                    $template_params->{NEEDSCONFIRMATION}         = 1;
516
                    $confirm_required                             = 1;
517
                    push( @{ $template_params->{sessionConfirmationKeys} }, $needsconfirmation_key );
518
                }
524
            }
519
            }
520
            unless ($confirm_required) {
521
                my $switch_onsite_checkout = exists $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED};
522
                if ( C4::Context->preference('UseRecalls') && !$recall_id ) {
523
                    my $recall = Koha::Recalls->find(
524
                        {
525
                            biblio_id => $item->biblionumber,
526
                            item_id   => [ undef,       $item->itemnumber ],
527
                            status    => [ 'requested', 'waiting' ],
528
                            completed => 0,
529
                            patron_id => $patron->borrowernumber,
530
                        }
531
                    );
532
                    $recall_id = ( $recall and $recall->id ) ? $recall->id : undef;
533
                }
525
534
526
                # If booked (alerts or confirmation) update datedue to end of booking
535
                # If booked (alerts or confirmation) update datedue to end of booking
527
                if ( my $booked = $needsconfirmation->{BOOKED_EARLY} // $alerts->{BOOKED} ) {
536
                if ( my $booked = $needsconfirmation->{BOOKED_EARLY} // $alerts->{BOOKED} ) {
Lines 532-538 if (@$barcodes && $op eq 'cud-checkout') { Link Here
532
                    $cancelreserve,
541
                    $cancelreserve,
533
                    undef, undef,
542
                    undef, undef,
534
                    {
543
                    {
535
                        onsite_checkout        => $onsite_checkout,        auto_renew    => $session->param('auto_renew'),
544
                        onsite_checkout        => $onsite_checkout,        auto_renew => $session->param('auto_renew'),
536
                        switch_onsite_checkout => $switch_onsite_checkout, cancel_recall => $cancel_recall,
545
                        switch_onsite_checkout => $switch_onsite_checkout, cancel_recall => $cancel_recall,
537
                        recall_id              => $recall_id,
546
                        recall_id              => $recall_id,
538
                    }
547
                    }
Lines 543-569 if (@$barcodes && $op eq 'cud-checkout') { Link Here
543
            }
552
            }
544
        }
553
        }
545
554
546
        if ($needsconfirmation->{RESERVE_WAITING} or $needsconfirmation->{RESERVED} or $needsconfirmation->{TRANSFERRED} or $needsconfirmation->{PROCESSING}){
555
        if (   $needsconfirmation->{RESERVE_WAITING}
556
            or $needsconfirmation->{RESERVED}
557
            or $needsconfirmation->{TRANSFERRED}
558
            or $needsconfirmation->{PROCESSING} )
559
        {
547
            $template->param(
560
            $template->param(
548
                reserveborrowernumber => $needsconfirmation->{'resborrowernumber'},
561
                reserveborrowernumber => $needsconfirmation->{'resborrowernumber'},
549
                reserve_id => $needsconfirmation->{reserve_id},
562
                reserve_id            => $needsconfirmation->{reserve_id},
550
            );
563
            );
551
        }
564
        }
552
565
553
554
        # FIXME If the issue is confirmed, we launch another time checkouts->count, now display the issue count after issue
566
        # FIXME If the issue is confirmed, we launch another time checkouts->count, now display the issue count after issue
555
        $patron = Koha::Patrons->find( $borrowernumber );
567
        $patron = Koha::Patrons->find($borrowernumber);
556
        $template_params->{issuecount} = $patron->checkouts->count;
568
        $template_params->{issuecount} = $patron->checkouts->count;
557
569
558
        if ( $item ) {
570
        if ($item) {
559
            $template_params->{item} = $item;
571
            $template_params->{item}             = $item;
560
            $template_params->{biblio} = $biblio;
572
            $template_params->{biblio}           = $biblio;
561
            $template_params->{itembiblionumber} = $biblio->biblionumber;
573
            $template_params->{itembiblionumber} = $biblio->biblionumber;
562
        }
574
        }
563
        push @$checkout_infos, $template_params;
575
        push @$checkout_infos, $template_params;
564
    }
576
    }
565
    unless ( $batch ) {
577
    unless ($batch) {
566
        $template->param( %{$checkout_infos->[0]} );
578
        $template->param( %{ $checkout_infos->[0] } );
567
        $template->param( barcode => $barcodes->[0] );
579
        $template->param( barcode => $barcodes->[0] );
568
    } else {
580
    } else {
569
        my $confirmation_needed = grep { $_->{NEEDSCONFIRMATION} } @$checkout_infos;
581
        my $confirmation_needed = grep { $_->{NEEDSCONFIRMATION} } @$checkout_infos;
Lines 572-585 if (@$barcodes && $op eq 'cud-checkout') { Link Here
572
            onsite_checkout     => $onsite_checkout,
584
            onsite_checkout     => $onsite_checkout,
573
            confirmation_needed => $confirmation_needed,
585
            confirmation_needed => $confirmation_needed,
574
        );
586
        );
575
     }
587
    }
576
}
588
}
577
589
578
##################################################################################
590
##################################################################################
579
# BUILD HTML
591
# BUILD HTML
580
# show all reserves of this borrower, and the position of the reservation ....
592
# show all reserves of this borrower, and the position of the reservation ....
581
if ($patron) {
593
if ($patron) {
582
    my $holds = Koha::Holds->search( { borrowernumber => $borrowernumber } ); # FIXME must be Koha::Patron->holds
594
    my $holds = Koha::Holds->search( { borrowernumber => $borrowernumber } );    # FIXME must be Koha::Patron->holds
583
    my $waiting_holds = $holds->waiting;
595
    my $waiting_holds = $holds->waiting;
584
    $template->param(
596
    $template->param(
585
        holds_count  => $holds->count(),
597
        holds_count  => $holds->count(),
Lines 587-613 if ($patron) { Link Here
587
    );
599
    );
588
600
589
    if ( C4::Context->preference('UseRecalls') ) {
601
    if ( C4::Context->preference('UseRecalls') ) {
590
        my $waiting_recalls = $patron->recalls->search({ status => 'waiting' });
602
        my $waiting_recalls = $patron->recalls->search( { status => 'waiting' } );
591
        $template->param(
603
        $template->param(
592
            recalls => $patron->recalls->filter_by_current->search({},{ order_by => { -asc => 'created_date' } }),
604
            recalls => $patron->recalls->filter_by_current->search( {}, { order_by => { -asc => 'created_date' } } ),
593
            specific_patron => 1,
605
            specific_patron => 1,
594
            waiting_recalls => $waiting_recalls,
606
            waiting_recalls => $waiting_recalls,
595
        );
607
        );
596
    }
608
    }
597
}
609
}
598
610
599
if ( $patron ) {
611
if ($patron) {
600
    my $noissues;
612
    my $noissues;
601
    if ( $patron->gonenoaddress ) {
613
    if ( $patron->gonenoaddress ) {
602
        $template->param( gonenoaddress => 1 );
614
        $template->param( gonenoaddress => 1 );
603
        $noissues = 1;
615
        $noissues = 1;
604
    }
616
    }
605
    if ( $patron->lost ) {
617
    if ( $patron->lost ) {
606
        $template->param( lost=> 1 );
618
        $template->param( lost => 1 );
607
        $noissues = 1;
619
        $noissues = 1;
608
    }
620
    }
609
    if ( $patron->is_debarred ) {
621
    if ( $patron->is_debarred ) {
610
        $template->param( is_debarred=> 1 );
622
        $template->param( is_debarred => 1 );
611
        $noissues = 1;
623
        $noissues = 1;
612
    }
624
    }
613
    if ( $patron->borrowernumber eq C4::Context->preference("AnonymousPatron") ) {
625
    if ( $patron->borrowernumber eq C4::Context->preference("AnonymousPatron") ) {
Lines 615-630 if ( $patron ) { Link Here
615
        $noissues = 1;
627
        $noissues = 1;
616
    }
628
    }
617
    my $patron_charge_limits = $patron->is_patron_inside_charge_limits();
629
    my $patron_charge_limits = $patron->is_patron_inside_charge_limits();
618
    if( $patron_charge_limits->{noissuescharge}->{charge} > 0 ) {
630
    if ( $patron_charge_limits->{noissuescharge}->{charge} > 0 ) {
619
        my $noissuescharge = $patron_charge_limits->{noissuescharge}->{limit} || 5; # FIXME If noissuescharge == 0 then 5, why??
631
        my $noissuescharge =
620
        $noissues ||= ( not C4::Context->preference("AllowFineOverride") and $patron_charge_limits->{noissuescharge}->{overlimit} );
632
            $patron_charge_limits->{noissuescharge}->{limit} || 5;    # FIXME If noissuescharge == 0 then 5, why??
633
        $noissues ||= ( not C4::Context->preference("AllowFineOverride")
634
                and $patron_charge_limits->{noissuescharge}->{overlimit} );
621
        $template->param(
635
        $template->param(
622
            charges => 1,
636
            charges       => 1,
623
            chargesamount => $patron_charge_limits->{noissuescharge}->{charge},
637
            chargesamount => $patron_charge_limits->{noissuescharge}->{charge},
624
        )
638
        );
625
    } elsif ( $balance < 0 ) {
639
    } elsif ( $balance < 0 ) {
626
        $template->param(
640
        $template->param(
627
            credits => 1,
641
            credits       => 1,
628
            creditsamount => -$balance,
642
            creditsamount => -$balance,
629
        );
643
        );
630
    }
644
    }
Lines 633-641 if ( $patron ) { Link Here
633
    my $no_issues_charge_guarantors = $patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees}->{limit};
647
    my $no_issues_charge_guarantors = $patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees}->{limit};
634
    if ($no_issues_charge_guarantors) {
648
    if ($no_issues_charge_guarantors) {
635
        if ( $patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees}->{overlimit} ) {
649
        if ( $patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees}->{overlimit} ) {
636
            $template->param(
650
            $template->param( charges_guarantors_guarantees =>
637
                charges_guarantors_guarantees => $patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees}->{charge}
651
                    $patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees}->{charge} );
638
            );
639
            $noissues = 1 unless C4::Context->preference("allowfineoverride");
652
            $noissues = 1 unless C4::Context->preference("allowfineoverride");
640
        }
653
        }
641
    }
654
    }
Lines 644-650 if ( $patron ) { Link Here
644
    if ( defined $no_issues_charge_guarantees ) {
657
    if ( defined $no_issues_charge_guarantees ) {
645
        if ( $patron_charge_limits->{NoIssuesChargeGuarantees}->{overlimit} ) {
658
        if ( $patron_charge_limits->{NoIssuesChargeGuarantees}->{overlimit} ) {
646
            $template->param(
659
            $template->param(
647
                charges_guarantees    => 1,
660
                charges_guarantees       => 1,
648
                chargesamount_guarantees => $patron_charge_limits->{NoIssuesChargeGuarantees}->{charge},
661
                chargesamount_guarantees => $patron_charge_limits->{NoIssuesChargeGuarantees}->{charge},
649
            );
662
            );
650
            $noissues = 1 unless C4::Context->preference("allowfineoverride");
663
            $noissues = 1 unless C4::Context->preference("allowfineoverride");
Lines 659-672 if ( $patron ) { Link Here
659
        my $borrowernotes = $patron->borrowernotes;
672
        my $borrowernotes = $patron->borrowernotes;
660
        $borrowernotes =~ s#\n#<br />#g;
673
        $borrowernotes =~ s#\n#<br />#g;
661
        $template->param(
674
        $template->param(
662
            notes =>1,
675
            notes    => 1,
663
            notesmsg => $borrowernotes,
676
            notesmsg => $borrowernotes,
664
        )
677
        );
665
    }
678
    }
666
679
667
    if ( $noissues ) {
680
    if ($noissues) {
668
        $template->param(
681
        $template->param(
669
            noissues => ($force_allow_issue) ? 0 : 'true',
682
            noissues   => ($force_allow_issue) ? 0 : 'true',
670
            forceallow => $force_allow_issue,
683
            forceallow => $force_allow_issue,
671
        );
684
        );
672
    }
685
    }
Lines 674-682 if ( $patron ) { Link Here
674
    my $patron_messages = $patron->messages->search(
687
    my $patron_messages = $patron->messages->search(
675
        {},
688
        {},
676
        {
689
        {
677
           join => 'manager',
690
            join      => 'manager',
678
           '+select' => ['manager.surname', 'manager.firstname' ],
691
            '+select' => [ 'manager.surname', 'manager.firstname' ],
679
           '+as' => ['manager_surname', 'manager_firstname'],
692
            '+as'     => [ 'manager_surname', 'manager_firstname' ],
680
        }
693
        }
681
    );
694
    );
682
    $template->param( patron_messages => $patron_messages );
695
    $template->param( patron_messages => $patron_messages );
Lines 689-703 if ( $patron ) { Link Here
689
702
690
my $fast_cataloging = 0;
703
my $fast_cataloging = 0;
691
if ( Koha::BiblioFrameworks->find('FA') ) {
704
if ( Koha::BiblioFrameworks->find('FA') ) {
692
    $fast_cataloging = 1 
705
    $fast_cataloging = 1;
693
}
706
}
694
707
695
my $view = $batch
708
my $view =
696
    ?'batch_checkout_view'
709
    $batch
710
    ? 'batch_checkout_view'
697
    : 'circview';
711
    : 'circview';
698
712
699
my @relatives;
713
my @relatives;
700
if ( $patron ) {
714
if ($patron) {
701
    if ( my @guarantors = $patron->guarantor_relationships()->guarantors->as_list ) {
715
    if ( my @guarantors = $patron->guarantor_relationships()->guarantors->as_list ) {
702
        push( @relatives, $_->id ) for @guarantors;
716
        push( @relatives, $_->id ) for @guarantors;
703
        push( @relatives, $_->id ) for $patron->siblings->as_list;
717
        push( @relatives, $_->id ) for $patron->siblings->as_list;
Lines 706-780 if ( $patron ) { Link Here
706
    }
720
    }
707
}
721
}
708
my $relatives_issues_count =
722
my $relatives_issues_count =
709
  Koha::Database->new()->schema()->resultset('Issue')
723
    Koha::Database->new()->schema()->resultset('Issue')->count( { borrowernumber => \@relatives } );
710
  ->count( { borrowernumber => \@relatives } );
711
724
712
if ( $patron ) {
725
if ($patron) {
713
    my $av = Koha::AuthorisedValues->search({ category => 'ROADTYPE', authorised_value => $patron->streettype });
726
    my $av = Koha::AuthorisedValues->search( { category => 'ROADTYPE', authorised_value => $patron->streettype } );
714
    my $roadtype = $av->count ? $av->next->lib : '';
727
    my $roadtype = $av->count ? $av->next->lib : '';
715
    $template->param(
728
    $template->param(
716
        roadtype          => $roadtype,
729
        roadtype     => $roadtype,
717
        patron            => $patron,
730
        patron       => $patron,
718
        categoryname      => $patron->category->description,
731
        categoryname => $patron->category->description,
719
        expiry            => $patron->dateexpiry,
732
        expiry       => $patron->dateexpiry,
720
    );
733
    );
721
}
734
}
722
735
723
# Restore date if changed by holds and/or save stickyduedate to session
736
# Restore date if changed by holds and/or save stickyduedate to session
724
if ($restoreduedatespec || $stickyduedate) {
737
if ( $restoreduedatespec || $stickyduedate ) {
725
    $duedatespec = $restoreduedatespec || $duedatespec;
738
    $duedatespec = $restoreduedatespec || $duedatespec;
726
739
727
    if ($stickyduedate) {
740
    if ($stickyduedate) {
728
        $session->param( 'stickyduedate', $duedatespec );
741
        $session->param( 'stickyduedate', $duedatespec );
729
    }
742
    }
730
} elsif (defined($duedatespec) && !defined($restoreduedatespec)) {
743
} elsif ( defined($duedatespec) && !defined($restoreduedatespec) ) {
731
    undef $duedatespec;
744
    undef $duedatespec;
732
}
745
}
733
746
734
$template->param(
747
$template->param(
735
    borrowernumber    => $borrowernumber,
748
    borrowernumber            => $borrowernumber,
736
    branch            => $branch,
749
    branch                    => $branch,
737
    was_renewed       => scalar $query->param('was_renewed') ? 1 : 0,
750
    was_renewed               => scalar $query->param('was_renewed') ? 1 : 0,
738
    barcodes          => $barcodes,
751
    barcodes                  => $barcodes,
739
    stickyduedate     => $stickyduedate,
752
    stickyduedate             => $stickyduedate,
740
    duedatespec       => $duedatespec,
753
    duedatespec               => $duedatespec,
741
    restoreduedatespec => $restoreduedatespec,
754
    restoreduedatespec        => $restoreduedatespec,
742
    message           => $message,
755
    message                   => $message,
743
    totaldue          => sprintf('%.2f', $balance), # FIXME not used in template?
756
    totaldue                  => sprintf( '%.2f', $balance ),                         # FIXME not used in template?
744
    inprocess         => $inprocess,
757
    inprocess                 => $inprocess,
745
    $view             => 1,
758
    $view                     => 1,
746
    batch_allowed     => $batch_allowed,
759
    batch_allowed             => $batch_allowed,
747
    batch             => $batch,
760
    batch                     => $batch,
748
    AudioAlerts           => C4::Context->preference("AudioAlerts"),
761
    AudioAlerts               => C4::Context->preference("AudioAlerts"),
749
    fast_cataloging   => $fast_cataloging,
762
    fast_cataloging           => $fast_cataloging,
750
    CircAutoPrintQuickSlip   => C4::Context->preference("CircAutoPrintQuickSlip"),
763
    CircAutoPrintQuickSlip    => C4::Context->preference("CircAutoPrintQuickSlip"),
751
    RoutingSerials => C4::Context->preference('RoutingSerials'),
764
    RoutingSerials            => C4::Context->preference('RoutingSerials'),
752
    relatives_issues_count => $relatives_issues_count,
765
    relatives_issues_count    => $relatives_issues_count,
753
    relatives_borrowernumbers => \@relatives,
766
    relatives_borrowernumbers => \@relatives,
754
);
767
);
755
768
756
757
if ( C4::Context->preference("ExportCircHistory") ) {
769
if ( C4::Context->preference("ExportCircHistory") ) {
758
    $template->param(csv_profiles => Koha::CsvProfiles->search({ type => 'marc' }));
770
    $template->param( csv_profiles => Koha::CsvProfiles->search( { type => 'marc' } ) );
759
}
771
}
760
772
761
my ( $has_modifications, $patron_lists_count);
773
my ( $has_modifications, $patron_lists_count );
762
if ( $patron ) {
774
if ($patron) {
763
    $has_modifications = Koha::Patron::Modifications->search( { borrowernumber => $borrowernumber } )->count;
775
    $has_modifications  = Koha::Patron::Modifications->search( { borrowernumber => $borrowernumber } )->count;
764
    $patron_lists_count = $patron->get_lists_with_patron->count();
776
    $patron_lists_count = $patron->get_lists_with_patron->count();
765
}
777
}
766
$template->param(
778
$template->param(
767
    debt_confirmed            => $debt_confirmed,
779
    debt_confirmed          => $debt_confirmed,
768
    SpecifyDueDate            => $duedatespec_allow,
780
    SpecifyDueDate          => $duedatespec_allow,
769
    PatronAutoComplete        => C4::Context->preference("PatronAutoComplete"),
781
    PatronAutoComplete      => C4::Context->preference("PatronAutoComplete"),
770
    today_due_date_and_time   => dt_from_string()->set(hour => 23)->set(minute => 59),
782
    today_due_date_and_time => dt_from_string()->set( hour => 23 )->set( minute => 59 ),
771
    restriction_types         => scalar Koha::Patron::Restriction::Types->search(),
783
    restriction_types       => scalar Koha::Patron::Restriction::Types->search(),
772
    has_modifications         => $has_modifications,
784
    has_modifications       => $has_modifications,
773
    patron_lists_count        => $patron_lists_count,
785
    patron_lists_count      => $patron_lists_count,
774
    override_high_holds       => $override_high_holds,
786
    override_high_holds     => $override_high_holds,
775
    nopermission              => scalar $query->param('nopermission'),
787
    nopermission            => scalar $query->param('nopermission'),
776
    autoswitched              => $autoswitched,
788
    autoswitched            => $autoswitched,
777
    logged_in_user            => $logged_in_user,
789
    logged_in_user          => $logged_in_user,
778
);
790
);
779
791
780
output_html_with_http_headers $query, $cookie, $template->output;
792
output_html_with_http_headers $query, $cookie, $template->output;
781
- 

Return to bug 14787