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

(-)a/C4/Circulation.pm (-17 / +21 lines)
Lines 1335-1343 sub GetLoanLength { Link Here
1335
1335
1336
    # try to find issuelength & return the 1st available.
1336
    # try to find issuelength & return the 1st available.
1337
    # check with borrowertype, itemtype and branchcode, then without one of those parameters
1337
    # check with borrowertype, itemtype and branchcode, then without one of those parameters
1338
1339
    $sth->execute( $borrowertype, $itemtype, $branchcode );
1338
    $sth->execute( $borrowertype, $itemtype, $branchcode );
1340
    my $loanlength = $sth->fetchrow_hashref;
1339
    my $loanlength = $sth->fetchrow_hashref;
1340
1341
    return $loanlength
1341
    return $loanlength
1342
      if defined($loanlength) && $loanlength->{issuelength};
1342
      if defined($loanlength) && $loanlength->{issuelength};
1343
1343
Lines 2411-2418 END_SQL Link Here
2411
2411
2412
Find out whether a borrowed item may be renewed.
2412
Find out whether a borrowed item may be renewed.
2413
2413
2414
C<$dbh> is a DBI handle to the Koha database.
2415
2416
C<$borrowernumber> is the borrower number of the patron who currently
2414
C<$borrowernumber> is the borrower number of the patron who currently
2417
has the item on loan.
2415
has the item on loan.
2418
2416
Lines 2422-2428 C<$override_limit>, if supplied with a true value, causes Link Here
2422
the limit on the number of times that the loan can be renewed
2420
the limit on the number of times that the loan can be renewed
2423
(as controlled by the item type) to be ignored.
2421
(as controlled by the item type) to be ignored.
2424
2422
2425
C<$CanBookBeRenewed> returns a true value iff the item may be renewed. The
2423
C<$CanBookBeRenewed> returns a true value if the item may be renewed. The
2426
item must currently be on loan to the specified borrower; renewals
2424
item must currently be on loan to the specified borrower; renewals
2427
must be allowed for the item's type; and the borrower must not have
2425
must be allowed for the item's type; and the borrower must not have
2428
already renewed the loan. $error will contain the reason the renewal can not proceed
2426
already renewed the loan. $error will contain the reason the renewal can not proceed
Lines 2984-2989 C<$startdate> = C4::Dates object representing start date of loan period (assum Link Here
2984
C<$itemtype>  = itemtype code of item in question
2982
C<$itemtype>  = itemtype code of item in question
2985
C<$branch>  = location whose calendar to use
2983
C<$branch>  = location whose calendar to use
2986
C<$borrower> = Borrower object
2984
C<$borrower> = Borrower object
2985
C<$isrenewal> = Boolean: is true if we want to calculate the date due for a renewal. Else is false.
2987
2986
2988
=cut
2987
=cut
2989
2988
Lines 3001-3022 sub CalcDateDue { Link Here
3001
            : qq{issuelength};
3000
            : qq{issuelength};
3002
3001
3003
    my $datedue;
3002
    my $datedue;
3003
    if ( $startdate ) {
3004
        if (ref $startdate ne 'DateTime' ) {
3005
            $datedue = dt_from_string($datedue);
3006
        } else {
3007
            $datedue = $startdate->clone;
3008
        }
3009
    } else {
3010
        $datedue =
3011
          DateTime->now( time_zone => C4::Context->tz() )
3012
          ->truncate( to => 'minute' );
3013
    }
3014
3004
3015
3005
    # calculate the datedue as normal
3016
    # calculate the datedue as normal
3006
    if ( C4::Context->preference('useDaysMode') eq 'Days' )
3017
    if ( C4::Context->preference('useDaysMode') eq 'Days' )
3007
    {    # ignoring calendar
3018
    {    # ignoring calendar
3008
        my $dt =
3009
          DateTime->now( time_zone => C4::Context->tz() )
3010
          ->truncate( to => 'minute' );
3011
        if ( $loanlength->{lengthunit} eq 'hours' ) {
3019
        if ( $loanlength->{lengthunit} eq 'hours' ) {
3012
            $dt->add( hours => $loanlength->{$length_key} );
3020
            $datedue->add( hours => $loanlength->{$length_key} );
3013
        } else {    # days
3021
        } else {    # days
3014
            $dt->add( days => $loanlength->{$length_key} );
3022
            $datedue->add( days => $loanlength->{$length_key} );
3015
            $dt->set_hour(23);
3023
            $datedue->set_hour(23);
3016
            $dt->set_minute(59);
3024
            $datedue->set_minute(59);
3017
        }
3025
        }
3018
        # break
3019
        return $dt;
3020
    } else {
3026
    } else {
3021
        my $dur;
3027
        my $dur;
3022
        if ($loanlength->{lengthunit} eq 'hours') {
3028
        if ($loanlength->{lengthunit} eq 'hours') {
Lines 3025-3035 sub CalcDateDue { Link Here
3025
        else { # days
3031
        else { # days
3026
            $dur = DateTime::Duration->new( days => $loanlength->{$length_key});
3032
            $dur = DateTime::Duration->new( days => $loanlength->{$length_key});
3027
        }
3033
        }
3028
        if (ref $startdate ne 'DateTime' ) {
3029
            $startdate = dt_from_string($startdate);
3030
        }
3031
        my $calendar = Koha::Calendar->new( branchcode => $branch );
3034
        my $calendar = Koha::Calendar->new( branchcode => $branch );
3032
        $datedue = $calendar->addDate( $startdate, $dur, $loanlength->{lengthunit} );
3035
        $datedue = $calendar->addDate( $datedue, $dur, $loanlength->{lengthunit} );
3033
        if ($loanlength->{lengthunit} eq 'days') {
3036
        if ($loanlength->{lengthunit} eq 'days') {
3034
            $datedue->set_hour(23);
3037
            $datedue->set_hour(23);
3035
            $datedue->set_minute(59);
3038
            $datedue->set_minute(59);
Lines 3053-3058 sub CalcDateDue { Link Here
3053
        }
3056
        }
3054
3057
3055
        # in all other cases, keep the date due as it is
3058
        # in all other cases, keep the date due as it is
3059
3056
    }
3060
    }
3057
3061
3058
    # if ReturnBeforeExpiry ON the datedue can't be after borrower expirydate
3062
    # if ReturnBeforeExpiry ON the datedue can't be after borrower expirydate
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-1 / +1 lines)
Lines 75-81 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
75
                <th>Overdue Fines Cap ($)</th>
75
                <th>Overdue Fines Cap ($)</th>
76
                <th>Suspension in days (day)</th>
76
                <th>Suspension in days (day)</th>
77
                <th>Renewals allowed (count)</th>
77
                <th>Renewals allowed (count)</th>
78
                <th>Renewals period</th>
78
                <th>Renewal period</th>
79
                <th>Holds allowed (count)</th>
79
                <th>Holds allowed (count)</th>
80
		<th>Rental discount (%)</th>
80
		<th>Rental discount (%)</th>
81
				<th>&nbsp;</th>
81
				<th>&nbsp;</th>
(-)a/t/db_dependent/Circulation_issuingrules.t (-1 / +123 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use t::lib::Mocks::Context;
6
use Test::More tests => 7;
7
use Test::MockModule;
8
use DBI;
9
use DateTime;
10
11
my $contextmodule = new Test::MockModule('C4::Context');
12
$contextmodule->mock('_new_dbh', sub {
13
    my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
14
    || die "Cannot create handle: $DBI::errstr\n";
15
    return $dbh
16
});
17
18
use_ok('C4::Circulation');
19
20
my $dbh = C4::Context->dbh();
21
22
my $issuelength = 10;
23
my $renewalperiod = 5;
24
my $lengthunit = 'days';
25
26
my $expected = {
27
    issuelength => $issuelength,
28
    renewalperiod => $renewalperiod,
29
    lengthunit => $lengthunit
30
};
31
32
my $default = {
33
    issuelength => 21,
34
    renewalperiod => 21,
35
    lengthunit => 'days'
36
};
37
38
my $loanlength;
39
my $mock_undef = [
40
    []
41
];
42
43
my $mock_loan_length = [
44
    ['issuelength', 'renewalperiod', 'lengthunit'],
45
    [$issuelength, $renewalperiod, $lengthunit]
46
];
47
48
my $categorycode = 'B';
49
my $itemtype = 'MX';
50
my $branchcode = 'FPL';
51
52
#=== GetLoanLength
53
$dbh->{mock_add_resultset} = $mock_loan_length;
54
$loanlength = C4::Circulation::GetLoanLength($categorycode, $itemtype, $branchcode);
55
is_deeply($loanlength, $expected, 'first matches');
56
57
$dbh->{mock_add_resultset} = $mock_undef;
58
$loanlength = C4::Circulation::GetLoanLength($categorycode, $itemtype, $branchcode);
59
is_deeply($loanlength, $default, 'none matches');
60
61
#=== CalcDateDue
62
63
#Set syspref ReturnBeforeExpiry = 1 and useDaysMode = 'Days'
64
$contextmodule->mock('preference', sub {
65
    my ($self, $syspref) = @_;
66
    given ( $syspref ) {
67
        when ("ReturnBeforeExpiry"){ return 1; }
68
        when ("useDaysMode"){ return 'Days'; }
69
        default{ return; }
70
    }
71
});
72
73
my $dateexpiry = '2013-01-01';
74
75
my $borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
76
my $start_date = DateTime->new({year => 2013, month => 2, day => 9});
77
$dbh->{mock_add_resultset} = $mock_loan_length;
78
my $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
79
is($date, $dateexpiry . 'T23:59:00', 'date expiry');
80
81
$dbh->{mock_add_resultset} = $mock_loan_length;
82
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
83
84
85
#Set syspref ReturnBeforeExpiry = 1 and useDaysMode != 'Days'
86
$contextmodule->mock('preference', sub {
87
    my ($self, $syspref) = @_;
88
    given ( $syspref ) {
89
        when ("ReturnBeforeExpiry"){ return 1; }
90
        when ("useDaysMode"){ return 'noDays'; }
91
        default{ return; }
92
    }
93
});
94
95
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
96
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
97
$dbh->{mock_add_resultset} = $mock_loan_length;
98
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
99
is($date, $dateexpiry . 'T23:59:00', 'date expiry');
100
101
$dbh->{mock_add_resultset} = $mock_loan_length;
102
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
103
104
105
#Set syspref ReturnBeforeExpiry = 0 and useDaysMode = 'Days'
106
$contextmodule->mock('preference', sub {
107
    my ($self, $syspref) = @_;
108
    given ( $syspref ) {
109
        when ("ReturnBeforeExpiry"){ return 0; }
110
        when ("useDaysMode"){ return 'Days'; }
111
        default{ return; }
112
    }
113
});
114
115
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
116
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
117
$dbh->{mock_add_resultset} = $mock_loan_length;
118
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
119
is($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "date expiry ( 9 + $issuelength )");
120
121
$dbh->{mock_add_resultset} = $mock_loan_length;
122
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
123
is($date, '2013-02-' . (9 + $renewalperiod) . 'T23:59:00', "date expiry ( 9 + $renewalperiod )");

Return to bug 8365