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

(-)a/C4/Circulation.pm (-17 / +28 lines)
Lines 765-770 sub CanBookBeIssued { Link Here
765
    my %needsconfirmation;    # filled with problems that needs confirmations
765
    my %needsconfirmation;    # filled with problems that needs confirmations
766
    my %issuingimpossible;    # filled with problems that causes the issue to be IMPOSSIBLE
766
    my %issuingimpossible;    # filled with problems that causes the issue to be IMPOSSIBLE
767
    my %alerts;               # filled with messages that shouldn't stop issuing, but the librarian should be aware of.
767
    my %alerts;               # filled with messages that shouldn't stop issuing, but the librarian should be aware of.
768
    my %messages;             # filled with information messages that should be displayed.
768
769
769
    my $onsite_checkout     = $params->{onsite_checkout}     || 0;
770
    my $onsite_checkout     = $params->{onsite_checkout}     || 0;
770
    my $override_high_holds = $params->{override_high_holds} || 0;
771
    my $override_high_holds = $params->{override_high_holds} || 0;
Lines 1033-1055 sub CanBookBeIssued { Link Here
1033
    #
1034
    #
1034
    if ( $issue->{borrowernumber} && $issue->{borrowernumber} eq $borrower->{'borrowernumber'} ){
1035
    if ( $issue->{borrowernumber} && $issue->{borrowernumber} eq $borrower->{'borrowernumber'} ){
1035
1036
1036
        # Already issued to current borrower. Ask whether the loan should
1037
        # Already issued to current borrower.
1037
        # be renewed.
1038
        # If it is an on-site checkout if it can be switched to a normal checkout
1038
        my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
1039
        # or ask whether the loan should be renewed
1039
            $borrower->{'borrowernumber'},
1040
1040
            $item->{'itemnumber'}
1041
        if ( $issue->{onsite_checkout}
1041
        );
1042
                and C4::Context->preference('SwitchOnSiteCheckouts') ) {
1042
        if ( $CanBookBeRenewed == 0 ) {    # no more renewals allowed
1043
            $messages{ONSITE_CHECKOUT_WILL_BE_SWITCHED} = 1;
1043
            if ( $renewerror eq 'onsite_checkout' ) {
1044
        } else {
1044
                $issuingimpossible{NO_RENEWAL_FOR_ONSITE_CHECKOUTS} = 1;
1045
            my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
1046
                $borrower->{'borrowernumber'},
1047
                $item->{'itemnumber'},
1048
            );
1049
            if ( $CanBookBeRenewed == 0 ) {    # no more renewals allowed
1050
                if ( $renewerror eq 'onsite_checkout' ) {
1051
                    $issuingimpossible{NO_RENEWAL_FOR_ONSITE_CHECKOUTS} = 1;
1052
                }
1053
                else {
1054
                    $issuingimpossible{NO_MORE_RENEWALS} = 1;
1055
                }
1045
            }
1056
            }
1046
            else {
1057
            else {
1047
                $issuingimpossible{NO_MORE_RENEWALS} = 1;
1058
                $needsconfirmation{RENEW_ISSUE} = 1;
1048
            }
1059
            }
1049
        }
1060
        }
1050
        else {
1051
            $needsconfirmation{RENEW_ISSUE} = 1;
1052
        }
1053
    }
1061
    }
1054
    elsif ($issue->{borrowernumber}) {
1062
    elsif ($issue->{borrowernumber}) {
1055
1063
Lines 1165-1171 sub CanBookBeIssued { Link Here
1165
        }
1173
        }
1166
    }
1174
    }
1167
1175
1168
    return ( \%issuingimpossible, \%needsconfirmation, \%alerts );
1176
    return ( \%issuingimpossible, \%needsconfirmation, \%alerts, \%messages, );
1169
}
1177
}
1170
1178
1171
=head2 CanBookBeReturned
1179
=head2 CanBookBeReturned
Lines 1350-1355 sub AddIssue { Link Here
1350
    my ( $borrower, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode, $params ) = @_;
1358
    my ( $borrower, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode, $params ) = @_;
1351
1359
1352
    my $onsite_checkout = $params && $params->{onsite_checkout} ? 1 : 0;
1360
    my $onsite_checkout = $params && $params->{onsite_checkout} ? 1 : 0;
1361
    my $switch_onsite_checkout = $params && $params->{switch_onsite_checkout};
1353
    my $auto_renew = $params && $params->{auto_renew};
1362
    my $auto_renew = $params && $params->{auto_renew};
1354
    my $dbh          = C4::Context->dbh;
1363
    my $dbh          = C4::Context->dbh;
1355
    my $barcodecheck = CheckValidBarcode($barcode);
1364
    my $barcodecheck = CheckValidBarcode($barcode);
Lines 1386-1392 sub AddIssue { Link Here
1386
        my $biblio = GetBiblioFromItemNumber( $item->{itemnumber} );
1395
        my $biblio = GetBiblioFromItemNumber( $item->{itemnumber} );
1387
1396
1388
        # check if we just renew the issue.
1397
        # check if we just renew the issue.
1389
        if ( $actualissue->{borrowernumber} eq $borrower->{'borrowernumber'} ) {
1398
        if ( $actualissue->{borrowernumber} eq $borrower->{'borrowernumber'}
1399
                and not $switch_onsite_checkout ) {
1390
            $datedue = AddRenewal(
1400
            $datedue = AddRenewal(
1391
                $borrower->{'borrowernumber'},
1401
                $borrower->{'borrowernumber'},
1392
                $item->{'itemnumber'},
1402
                $item->{'itemnumber'},
Lines 1397-1403 sub AddIssue { Link Here
1397
        }
1407
        }
1398
        else {
1408
        else {
1399
            # it's NOT a renewal
1409
            # it's NOT a renewal
1400
            if ( $actualissue->{borrowernumber} ) {
1410
            if ( $actualissue->{borrowernumber}
1411
                    and not $switch_onsite_checkout ) {
1401
                # This book is currently on loan, but not to the person
1412
                # This book is currently on loan, but not to the person
1402
                # who wants to borrow it now. mark it returned before issuing to the new borrower
1413
                # who wants to borrow it now. mark it returned before issuing to the new borrower
1403
                my ( $allowed, $message ) = CanBookBeReturned( $item, C4::Context->userenv->{branch} );
1414
                my ( $allowed, $message ) = CanBookBeReturned( $item, C4::Context->userenv->{branch} );
Lines 1439-1445 sub AddIssue { Link Here
1439
            }
1450
            }
1440
            $datedue->truncate( to => 'minute' );
1451
            $datedue->truncate( to => 'minute' );
1441
1452
1442
            $issue = Koha::Database->new()->schema()->resultset('Issue')->create(
1453
            $issue = Koha::Database->new()->schema()->resultset('Issue')->update_or_create(
1443
                {
1454
                {
1444
                    borrowernumber => $borrower->{'borrowernumber'},
1455
                    borrowernumber => $borrower->{'borrowernumber'},
1445
                    itemnumber     => $item->{'itemnumber'},
1456
                    itemnumber     => $item->{'itemnumber'},
(-)a/circ/circulation.pl (-2 / +4 lines)
Lines 319-325 if (@$barcodes) { Link Here
319
  for my $barcode ( @$barcodes ) {
319
  for my $barcode ( @$barcodes ) {
320
    my $template_params = { barcode => $barcode };
320
    my $template_params = { barcode => $barcode };
321
    # always check for blockers on issuing
321
    # always check for blockers on issuing
322
    my ( $error, $question, $alerts ) = CanBookBeIssued(
322
    my ( $error, $question, $alerts, $messages ) = CanBookBeIssued(
323
        $borrower,
323
        $borrower,
324
        $barcode, $datedue,
324
        $barcode, $datedue,
325
        $inprocess,
325
        $inprocess,
Lines 333-338 if (@$barcodes) { Link Here
333
    my $blocker = $invalidduedate ? 1 : 0;
333
    my $blocker = $invalidduedate ? 1 : 0;
334
334
335
    $template_params->{alert} = $alerts;
335
    $template_params->{alert} = $alerts;
336
    $template_params->{messages} = $messages;
336
337
337
    #  Get the item title for more information
338
    #  Get the item title for more information
338
    my $getmessageiteminfo = GetBiblioFromItemNumber(undef,$barcode);
339
    my $getmessageiteminfo = GetBiblioFromItemNumber(undef,$barcode);
Lines 404-410 if (@$barcodes) { Link Here
404
            }
405
            }
405
        }
406
        }
406
        unless($confirm_required) {
407
        unless($confirm_required) {
407
            my $issue = AddIssue( $borrower, $barcode, $datedue, $cancelreserve, undef, undef, { onsite_checkout => $onsite_checkout, auto_renew => $session->param('auto_renew') } );
408
            my $switch_onsite_checkout = exists $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED};
409
            my $issue = AddIssue( $borrower, $barcode, $datedue, $cancelreserve, undef, undef, { onsite_checkout => $onsite_checkout, auto_renew => $session->param('auto_renew'), switch_onsite_checkout => $switch_onsite_checkout, } );
408
            $template_params->{issue} = $issue;
410
            $template_params->{issue} = $issue;
409
            $session->clear('auto_renew');
411
            $session->clear('auto_renew');
410
            $inprocess = 1;
412
            $inprocess = 1;
(-)a/installer/data/mysql/atomicupdate/bug_bulac1.sql (+1 lines)
Line 0 Link Here
1
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES ('SwitchOnSiteCheckouts', '0', 'Automatically switch an on-site checkout to a normal checkout', NULL, 'YesNo');
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 476-481 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
476
('SuspendHoldsIntranet','1','Allow holds to be suspended from the intranet.',NULL,'YesNo'),
476
('SuspendHoldsIntranet','1','Allow holds to be suspended from the intranet.',NULL,'YesNo'),
477
('SuspendHoldsOpac','1','Allow holds to be suspended from the OPAC.',NULL,'YesNo'),
477
('SuspendHoldsOpac','1','Allow holds to be suspended from the OPAC.',NULL,'YesNo'),
478
('SvcMaxReportRows','10',NULL,'Maximum number of rows to return via the report web service.','Integer'),
478
('SvcMaxReportRows','10',NULL,'Maximum number of rows to return via the report web service.','Integer'),
479
('SwitchOnSiteCheckouts','0',NULL,'Automatically switch an on-site checkout to a normal checkout','YesNo');
479
('SyndeticsAuthorNotes','0','','Display Notes about the Author on OPAC from Syndetics','YesNo'),
480
('SyndeticsAuthorNotes','0','','Display Notes about the Author on OPAC from Syndetics','YesNo'),
480
('SyndeticsAwards','0','','Display Awards on OPAC from Syndetics','YesNo'),
481
('SyndeticsAwards','0','','Display Awards on OPAC from Syndetics','YesNo'),
481
('SyndeticsClientCode','0','','Client Code for using Syndetics Solutions content','free'),
482
('SyndeticsClientCode','0','','Client Code for using Syndetics Solutions content','free'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (+6 lines)
Lines 412-417 Circulation: Link Here
412
            - If enabled, the number of checkouts allowed will be normal checkouts + on-site checkouts.
412
            - If enabled, the number of checkouts allowed will be normal checkouts + on-site checkouts.
413
            - If disabled, both values will be checked separately.
413
            - If disabled, both values will be checked separately.
414
        -
414
        -
415
            - pref: SwitchOnSiteCheckouts
416
              choices:
417
                  yes: Switch
418
                  no: "Don't switch"
419
            - on-site checkouts to normal checkouts when checked out.
420
        -
415
            - When a patron's checked out item is overdue,
421
            - When a patron's checked out item is overdue,
416
            - pref: OverduesBlockRenewing
422
            - pref: OverduesBlockRenewing
417
              type: choice
423
              type: choice
(-)a/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t (-1 / +110 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, see <http://www.gnu.org/licenses>.
16
17
use Modern::Perl;
18
use Test::More tests => 4;
19
use C4::Context;
20
21
use C4::Biblio;
22
use C4::Members;
23
use C4::Branch;
24
use C4::Circulation;
25
use C4::Items;
26
use C4::Context;
27
28
use Koha::DateUtils qw( dt_from_string );
29
use Koha::Database;
30
31
use t::lib::TestBuilder;
32
use t::lib::Mocks;
33
34
my $schema = Koha::Database->new->schema;
35
$schema->storage->txn_begin;
36
37
our $dbh = C4::Context->dbh;
38
39
$dbh->do(q|DELETE FROM branch_item_rules|);
40
$dbh->do(q|DELETE FROM issues|);
41
$dbh->do(q|DELETE FROM branch_borrower_circ_rules|);
42
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
43
$dbh->do(q|DELETE FROM default_circ_rules|);
44
$dbh->do(q|DELETE FROM default_branch_item_rules|);
45
$dbh->do(q|DELETE FROM issuingrules|);
46
47
my $builder = t::lib::TestBuilder->new();
48
49
my $branch = $builder->build({
50
    source => 'Branch',
51
});
52
53
my $patron = $builder->build({
54
    source => 'Borrower',
55
    value => {
56
        branchcode => $branch->{branchcode},
57
    },
58
});
59
60
my $biblio = $builder->build({
61
    source => 'Biblio',
62
    value => {
63
        branchcode => $branch->{branchcode},
64
    },
65
});
66
my $item = $builder->build({
67
    source => 'Item',
68
    value => {
69
        biblionumber => $biblio->{biblionumber},
70
        homebranch => $branch->{branchcode},
71
        holdingbranch => $branch->{branchcode},
72
    },
73
});
74
75
my $issuingrule = $builder->build({
76
    source => 'Issuingrule',
77
    value => {
78
        branchcode         => $branch->{branchcode},
79
        categorycode       => '*',
80
        itemtype           => '*',
81
        maxissueqty        => 2,
82
        maxonsiteissueqty  => 1,
83
        lengthunit         => 'days',
84
        issuelength        => 5,
85
    },
86
});
87
88
C4::Context->_new_userenv ('DUMMY_SESSION_ID');
89
C4::Context->set_userenv($patron->{borrowernumber}, $patron->{userid}, 'usercnum', 'First name', 'Surname', $branch->{branchcode}, 'My Library', 0);
90
91
# Add onsite checkout
92
C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string, undef, dt_from_string, undef, { onsite_checkout => 1 } );
93
94
my ( $impossible, $messages );
95
t::lib::Mocks::mock_preference('SwitchOnSiteCheckouts', 0);
96
( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
97
is( $impossible->{NO_RENEWAL_FOR_ONSITE_CHECKOUTS}, 1, '' );
98
99
t::lib::Mocks::mock_preference('SwitchOnSiteCheckouts', 1);
100
( undef, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
101
is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, '' );
102
C4::Circulation::AddIssue( $patron, $item->{barcode}, undef, undef, undef, undef, { switch_onsite_checkout => 1 } );
103
my $issue = C4::Circulation::GetItemIssue( $item->{itemnumber} );
104
is( $issue->{onsite_checkout}, 0, '' );
105
my $five_days_after = dt_from_string->add( days => 5 )->set( hour => 23, minute => 59, second => 0 );
106
is( $issue->{date_due}, $five_days_after );
107
108
$schema->storage->txn_rollback;
109
110
1;

Return to bug 16272