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

(-)a/C4/Circulation.pm (-17 / +28 lines)
Lines 763-768 sub CanBookBeIssued { Link Here
763
    my %needsconfirmation;    # filled with problems that needs confirmations
763
    my %needsconfirmation;    # filled with problems that needs confirmations
764
    my %issuingimpossible;    # filled with problems that causes the issue to be IMPOSSIBLE
764
    my %issuingimpossible;    # filled with problems that causes the issue to be IMPOSSIBLE
765
    my %alerts;               # filled with messages that shouldn't stop issuing, but the librarian should be aware of.
765
    my %alerts;               # filled with messages that shouldn't stop issuing, but the librarian should be aware of.
766
    my %messages;             # filled with information messages that should be displayed.
766
767
767
    my $onsite_checkout     = $params->{onsite_checkout}     || 0;
768
    my $onsite_checkout     = $params->{onsite_checkout}     || 0;
768
    my $override_high_holds = $params->{override_high_holds} || 0;
769
    my $override_high_holds = $params->{override_high_holds} || 0;
Lines 1023-1045 sub CanBookBeIssued { Link Here
1023
    #
1024
    #
1024
    if ( $issue->{borrowernumber} && $issue->{borrowernumber} eq $borrower->{'borrowernumber'} ){
1025
    if ( $issue->{borrowernumber} && $issue->{borrowernumber} eq $borrower->{'borrowernumber'} ){
1025
1026
1026
        # Already issued to current borrower. Ask whether the loan should
1027
        # Already issued to current borrower.
1027
        # be renewed.
1028
        # If it is an on-site checkout if it can be switched to a normal checkout
1028
        my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
1029
        # or ask whether the loan should be renewed
1029
            $borrower->{'borrowernumber'},
1030
1030
            $item->{'itemnumber'}
1031
        if ( $issue->{onsite_checkout}
1031
        );
1032
                and C4::Context->preference('SwitchOnSiteCheckouts') ) {
1032
        if ( $CanBookBeRenewed == 0 ) {    # no more renewals allowed
1033
            $messages{ONSITE_CHECKOUT_WILL_BE_SWITCHED} = 1;
1033
            if ( $renewerror eq 'onsite_checkout' ) {
1034
        } else {
1034
                $issuingimpossible{NO_RENEWAL_FOR_ONSITE_CHECKOUTS} = 1;
1035
            my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
1036
                $borrower->{'borrowernumber'},
1037
                $item->{'itemnumber'},
1038
            );
1039
            if ( $CanBookBeRenewed == 0 ) {    # no more renewals allowed
1040
                if ( $renewerror eq 'onsite_checkout' ) {
1041
                    $issuingimpossible{NO_RENEWAL_FOR_ONSITE_CHECKOUTS} = 1;
1042
                }
1043
                else {
1044
                    $issuingimpossible{NO_MORE_RENEWALS} = 1;
1045
                }
1035
            }
1046
            }
1036
            else {
1047
            else {
1037
                $issuingimpossible{NO_MORE_RENEWALS} = 1;
1048
                $needsconfirmation{RENEW_ISSUE} = 1;
1038
            }
1049
            }
1039
        }
1050
        }
1040
        else {
1041
            $needsconfirmation{RENEW_ISSUE} = 1;
1042
        }
1043
    }
1051
    }
1044
    elsif ($issue->{borrowernumber}) {
1052
    elsif ($issue->{borrowernumber}) {
1045
1053
Lines 1148-1154 sub CanBookBeIssued { Link Here
1148
        }
1156
        }
1149
    }
1157
    }
1150
1158
1151
    return ( \%issuingimpossible, \%needsconfirmation, \%alerts );
1159
    return ( \%issuingimpossible, \%needsconfirmation, \%alerts, \%messages, );
1152
}
1160
}
1153
1161
1154
=head2 CanBookBeReturned
1162
=head2 CanBookBeReturned
Lines 1332-1337 AddIssue does the following things : Link Here
1332
sub AddIssue {
1340
sub AddIssue {
1333
    my ( $borrower, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode, $params ) = @_;
1341
    my ( $borrower, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode, $params ) = @_;
1334
    my $onsite_checkout = $params && $params->{onsite_checkout} ? 1 : 0;
1342
    my $onsite_checkout = $params && $params->{onsite_checkout} ? 1 : 0;
1343
    my $switch_onsite_checkout = $params && $params->{switch_onsite_checkout};
1335
    my $auto_renew = $params && $params->{auto_renew};
1344
    my $auto_renew = $params && $params->{auto_renew};
1336
    my $dbh = C4::Context->dbh;
1345
    my $dbh = C4::Context->dbh;
1337
    my $barcodecheck=CheckValidBarcode($barcode);
1346
    my $barcodecheck=CheckValidBarcode($barcode);
Lines 1365-1371 sub AddIssue { Link Here
1365
		#
1374
		#
1366
		# check if we just renew the issue.
1375
		# check if we just renew the issue.
1367
		#
1376
		#
1368
		if ($actualissue->{borrowernumber} eq $borrower->{'borrowernumber'}) {
1377
        if ( $actualissue->{borrowernumber} eq $borrower->{'borrowernumber'}
1378
                and not $switch_onsite_checkout ) {
1369
		    $datedue = AddRenewal(
1379
		    $datedue = AddRenewal(
1370
			$borrower->{'borrowernumber'},
1380
			$borrower->{'borrowernumber'},
1371
			$item->{'itemnumber'},
1381
			$item->{'itemnumber'},
Lines 1376-1382 sub AddIssue { Link Here
1376
		}
1386
		}
1377
		else {
1387
		else {
1378
        # it's NOT a renewal
1388
        # it's NOT a renewal
1379
			if ( $actualissue->{borrowernumber}) {
1389
            if ( $actualissue->{borrowernumber}
1390
                    and not $switch_onsite_checkout ) {
1380
				# This book is currently on loan, but not to the person
1391
				# This book is currently on loan, but not to the person
1381
				# who wants to borrow it now. mark it returned before issuing to the new borrower
1392
				# who wants to borrow it now. mark it returned before issuing to the new borrower
1382
				AddReturn(
1393
				AddReturn(
Lines 1415-1421 sub AddIssue { Link Here
1415
        }
1426
        }
1416
        $datedue->truncate( to => 'minute');
1427
        $datedue->truncate( to => 'minute');
1417
1428
1418
        $issue = Koha::Database->new()->schema()->resultset('Issue')->create(
1429
        $issue = Koha::Database->new()->schema()->resultset('Issue')->update_or_create(
1419
            {
1430
            {
1420
                borrowernumber  => $borrower->{'borrowernumber'},
1431
                borrowernumber  => $borrower->{'borrowernumber'},
1421
                itemnumber      => $item->{'itemnumber'},
1432
                itemnumber      => $item->{'itemnumber'},
(-)a/circ/circulation.pl (-2 / +4 lines)
Lines 321-327 if (@$barcodes) { Link Here
321
  for my $barcode ( @$barcodes ) {
321
  for my $barcode ( @$barcodes ) {
322
    my $template_params = { barcode => $barcode };
322
    my $template_params = { barcode => $barcode };
323
    # always check for blockers on issuing
323
    # always check for blockers on issuing
324
    my ( $error, $question, $alerts ) = CanBookBeIssued(
324
    my ( $error, $question, $alerts, $messages ) = CanBookBeIssued(
325
        $borrower,
325
        $borrower,
326
        $barcode, $datedue,
326
        $barcode, $datedue,
327
        $inprocess,
327
        $inprocess,
Lines 335-340 if (@$barcodes) { Link Here
335
    my $blocker = $invalidduedate ? 1 : 0;
335
    my $blocker = $invalidduedate ? 1 : 0;
336
336
337
    $template_params->{alert} = $alerts;
337
    $template_params->{alert} = $alerts;
338
    $template_params->{messages} = $messages;
338
339
339
    #  Get the item title for more information
340
    #  Get the item title for more information
340
    my $getmessageiteminfo = GetBiblioFromItemNumber(undef,$barcode);
341
    my $getmessageiteminfo = GetBiblioFromItemNumber(undef,$barcode);
Lines 406-412 if (@$barcodes) { Link Here
406
            }
407
            }
407
        }
408
        }
408
        unless($confirm_required) {
409
        unless($confirm_required) {
409
            my $issue = AddIssue( $borrower, $barcode, $datedue, $cancelreserve, undef, undef, { onsite_checkout => $onsite_checkout, auto_renew => $session->param('auto_renew') } );
410
	    my $switch_onsite_checkout = exists $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED};
411
            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, } );
410
            $template_params->{issue} = $issue;
412
            $template_params->{issue} = $issue;
411
            $session->clear('auto_renew');
413
            $session->clear('auto_renew');
412
            $inprocess = 1;
414
            $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 468-473 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
468
('SuspendHoldsIntranet','1','Allow holds to be suspended from the intranet.',NULL,'YesNo'),
468
('SuspendHoldsIntranet','1','Allow holds to be suspended from the intranet.',NULL,'YesNo'),
469
('SuspendHoldsOpac','1','Allow holds to be suspended from the OPAC.',NULL,'YesNo'),
469
('SuspendHoldsOpac','1','Allow holds to be suspended from the OPAC.',NULL,'YesNo'),
470
('SvcMaxReportRows','10',NULL,'Maximum number of rows to return via the report web service.','Integer'),
470
('SvcMaxReportRows','10',NULL,'Maximum number of rows to return via the report web service.','Integer'),
471
('SwitchOnSiteCheckouts','0',NULL,'Automatically switch an on-site checkout to a normal checkout','YesNo');
471
('SyndeticsAuthorNotes','0','','Display Notes about the Author on OPAC from Syndetics','YesNo'),
472
('SyndeticsAuthorNotes','0','','Display Notes about the Author on OPAC from Syndetics','YesNo'),
472
('SyndeticsAwards','0','','Display Awards on OPAC from Syndetics','YesNo'),
473
('SyndeticsAwards','0','','Display Awards on OPAC from Syndetics','YesNo'),
473
('SyndeticsClientCode','0','','Client Code for using Syndetics Solutions content','free'),
474
('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