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

(-)a/C4/Circulation.pm (-17 / +28 lines)
Lines 756-761 sub CanBookBeIssued { Link Here
756
    my %needsconfirmation;    # filled with problems that needs confirmations
756
    my %needsconfirmation;    # filled with problems that needs confirmations
757
    my %issuingimpossible;    # filled with problems that causes the issue to be IMPOSSIBLE
757
    my %issuingimpossible;    # filled with problems that causes the issue to be IMPOSSIBLE
758
    my %alerts;               # filled with messages that shouldn't stop issuing, but the librarian should be aware of.
758
    my %alerts;               # filled with messages that shouldn't stop issuing, but the librarian should be aware of.
759
    my %messages;             # filled with information messages that should be displayed.
759
760
760
    my $onsite_checkout = $params->{onsite_checkout} || 0;
761
    my $onsite_checkout = $params->{onsite_checkout} || 0;
761
762
Lines 991-1013 sub CanBookBeIssued { Link Here
991
    #
992
    #
992
    if ( $issue->{borrowernumber} && $issue->{borrowernumber} eq $borrower->{'borrowernumber'} ){
993
    if ( $issue->{borrowernumber} && $issue->{borrowernumber} eq $borrower->{'borrowernumber'} ){
993
994
994
        # Already issued to current borrower. Ask whether the loan should
995
        # Already issued to current borrower.
995
        # be renewed.
996
        # If it is an on-site checkout if it can be switched to a normal checkout
996
        my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
997
        # or ask whether the loan should be renewed
997
            $borrower->{'borrowernumber'},
998
998
            $item->{'itemnumber'}
999
        if ( $issue->{onsite_checkout}
999
        );
1000
                and C4::Context->preference('SwitchOnSiteCheckouts') ) {
1000
        if ( $CanBookBeRenewed == 0 ) {    # no more renewals allowed
1001
            $messages{ONSITE_CHECKOUT_WILL_BE_SWITCHED} = 1;
1001
            if ( $renewerror eq 'onsite_checkout' ) {
1002
        } else {
1002
                $issuingimpossible{NO_RENEWAL_FOR_ONSITE_CHECKOUTS} = 1;
1003
            my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
1004
                $borrower->{'borrowernumber'},
1005
                $item->{'itemnumber'},
1006
            );
1007
            if ( $CanBookBeRenewed == 0 ) {    # no more renewals allowed
1008
                if ( $renewerror eq 'onsite_checkout' ) {
1009
                    $issuingimpossible{NO_RENEWAL_FOR_ONSITE_CHECKOUTS} = 1;
1010
                }
1011
                else {
1012
                    $issuingimpossible{NO_MORE_RENEWALS} = 1;
1013
                }
1003
            }
1014
            }
1004
            else {
1015
            else {
1005
                $issuingimpossible{NO_MORE_RENEWALS} = 1;
1016
                $needsconfirmation{RENEW_ISSUE} = 1;
1006
            }
1017
            }
1007
        }
1018
        }
1008
        else {
1009
            $needsconfirmation{RENEW_ISSUE} = 1;
1010
        }
1011
    }
1019
    }
1012
    elsif ($issue->{borrowernumber}) {
1020
    elsif ($issue->{borrowernumber}) {
1013
1021
Lines 1107-1113 sub CanBookBeIssued { Link Here
1107
        }
1115
        }
1108
    }
1116
    }
1109
1117
1110
    return ( \%issuingimpossible, \%needsconfirmation, \%alerts );
1118
    return ( \%issuingimpossible, \%needsconfirmation, \%alerts, \%messages, );
1111
}
1119
}
1112
1120
1113
=head2 CanBookBeReturned
1121
=head2 CanBookBeReturned
Lines 1291-1296 AddIssue does the following things : Link Here
1291
sub AddIssue {
1299
sub AddIssue {
1292
    my ( $borrower, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode, $params ) = @_;
1300
    my ( $borrower, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode, $params ) = @_;
1293
    my $onsite_checkout = $params && $params->{onsite_checkout} ? 1 : 0;
1301
    my $onsite_checkout = $params && $params->{onsite_checkout} ? 1 : 0;
1302
    my $switch_onsite_checkout = $params && $params->{switch_onsite_checkout};
1294
    my $auto_renew = $params && $params->{auto_renew};
1303
    my $auto_renew = $params && $params->{auto_renew};
1295
    my $dbh = C4::Context->dbh;
1304
    my $dbh = C4::Context->dbh;
1296
    my $barcodecheck=CheckValidBarcode($barcode);
1305
    my $barcodecheck=CheckValidBarcode($barcode);
Lines 1324-1330 sub AddIssue { Link Here
1324
		#
1333
		#
1325
		# check if we just renew the issue.
1334
		# check if we just renew the issue.
1326
		#
1335
		#
1327
		if ($actualissue->{borrowernumber} eq $borrower->{'borrowernumber'}) {
1336
        if ( $actualissue->{borrowernumber} eq $borrower->{'borrowernumber'}
1337
                and not $switch_onsite_checkout ) {
1328
		    $datedue = AddRenewal(
1338
		    $datedue = AddRenewal(
1329
			$borrower->{'borrowernumber'},
1339
			$borrower->{'borrowernumber'},
1330
			$item->{'itemnumber'},
1340
			$item->{'itemnumber'},
Lines 1335-1341 sub AddIssue { Link Here
1335
		}
1345
		}
1336
		else {
1346
		else {
1337
        # it's NOT a renewal
1347
        # it's NOT a renewal
1338
			if ( $actualissue->{borrowernumber}) {
1348
            if ( $actualissue->{borrowernumber}
1349
                    and not $switch_onsite_checkout ) {
1339
				# This book is currently on loan, but not to the person
1350
				# This book is currently on loan, but not to the person
1340
				# who wants to borrow it now. mark it returned before issuing to the new borrower
1351
				# who wants to borrow it now. mark it returned before issuing to the new borrower
1341
				AddReturn(
1352
				AddReturn(
Lines 1374-1380 sub AddIssue { Link Here
1374
        }
1385
        }
1375
        $datedue->truncate( to => 'minute');
1386
        $datedue->truncate( to => 'minute');
1376
1387
1377
        $issue = Koha::Database->new()->schema()->resultset('Issue')->create(
1388
        $issue = Koha::Database->new()->schema()->resultset('Issue')->update_or_create(
1378
            {
1389
            {
1379
                borrowernumber  => $borrower->{'borrowernumber'},
1390
                borrowernumber  => $borrower->{'borrowernumber'},
1380
                itemnumber      => $item->{'itemnumber'},
1391
                itemnumber      => $item->{'itemnumber'},
(-)a/circ/circulation.pl (-2 / +4 lines)
Lines 333-343 if (@$barcodes) { Link Here
333
  for my $barcode ( @$barcodes ) {
333
  for my $barcode ( @$barcodes ) {
334
    my $template_params = { barcode => $barcode };
334
    my $template_params = { barcode => $barcode };
335
    # always check for blockers on issuing
335
    # always check for blockers on issuing
336
    my ( $error, $question, $alerts ) =
336
    my ( $error, $question, $alerts, $messages ) =
337
    CanBookBeIssued( $borrower, $barcode, $datedue , $inprocess, undef, { onsite_checkout => $onsite_checkout } );
337
    CanBookBeIssued( $borrower, $barcode, $datedue , $inprocess, undef, { onsite_checkout => $onsite_checkout } );
338
    my $blocker = $invalidduedate ? 1 : 0;
338
    my $blocker = $invalidduedate ? 1 : 0;
339
339
340
    $template_params->{alert} = $alerts;
340
    $template_params->{alert} = $alerts;
341
    $template_params->{messages} = $messages;
341
342
342
    #  Get the item title for more information
343
    #  Get the item title for more information
343
    my $getmessageiteminfo = GetBiblioFromItemNumber(undef,$barcode);
344
    my $getmessageiteminfo = GetBiblioFromItemNumber(undef,$barcode);
Lines 408-414 if (@$barcodes) { Link Here
408
            }
409
            }
409
        }
410
        }
410
        unless($confirm_required) {
411
        unless($confirm_required) {
411
            my $issue = AddIssue( $borrower, $barcode, $datedue, $cancelreserve, undef, undef, { onsite_checkout => $onsite_checkout, auto_renew => $session->param('auto_renew') } );
412
            my $switch_onsite_checkout = exists $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED};
413
            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, } );
412
            $template->param( issue => $issue );
414
            $template->param( issue => $issue );
413
            $session->clear('auto_renew');
415
            $session->clear('auto_renew');
414
            $inprocess = 1;
416
            $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 465-470 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
465
('SuspendHoldsIntranet','1','Allow holds to be suspended from the intranet.',NULL,'YesNo'),
465
('SuspendHoldsIntranet','1','Allow holds to be suspended from the intranet.',NULL,'YesNo'),
466
('SuspendHoldsOpac','1','Allow holds to be suspended from the OPAC.',NULL,'YesNo'),
466
('SuspendHoldsOpac','1','Allow holds to be suspended from the OPAC.',NULL,'YesNo'),
467
('SvcMaxReportRows','10',NULL,'Maximum number of rows to return via the report web service.','Integer'),
467
('SvcMaxReportRows','10',NULL,'Maximum number of rows to return via the report web service.','Integer'),
468
('SwitchOnSiteCheckouts','0',NULL,'Automatically switch an on-site checkout to a normal checkout','YesNo');
468
('SyndeticsAuthorNotes','0','','Display Notes about the Author on OPAC from Syndetics','YesNo'),
469
('SyndeticsAuthorNotes','0','','Display Notes about the Author on OPAC from Syndetics','YesNo'),
469
('SyndeticsAwards','0','','Display Awards on OPAC from Syndetics','YesNo'),
470
('SyndeticsAwards','0','','Display Awards on OPAC from Syndetics','YesNo'),
470
('SyndeticsClientCode','0','','Client Code for using Syndetics Solutions content','free'),
471
('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 407-412 Circulation: Link Here
407
            - If enabled, the number of checkouts allowed will be normal checkouts + on-site checkouts.
407
            - If enabled, the number of checkouts allowed will be normal checkouts + on-site checkouts.
408
            - If disabled, both values will be checked separately.
408
            - If disabled, both values will be checked separately.
409
        -
409
        -
410
            - pref: SwitchOnSiteCheckouts
411
              choices:
412
                  yes: Switch
413
                  no: "Don't switch"
414
            - on-site checkouts to normal checkouts when checked out.
415
        -
410
            - When a patron's checked out item is overdue,
416
            - When a patron's checked out item is overdue,
411
            - pref: OverduesBlockRenewing
417
            - pref: OverduesBlockRenewing
412
              type: choice
418
              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