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

(-)a/C4/Circulation.pm (-14 / +19 lines)
Lines 708-714 sub CanBookBeIssued { Link Here
708
    unless ( $duedate ) {
708
    unless ( $duedate ) {
709
        my $issuedate = $now->clone();
709
        my $issuedate = $now->clone();
710
710
711
        $duedate = CalcDateDue( $issuedate, $effective_itemtype, $circ_library->branchcode, $patron_unblessed );
711
        $duedate = CalcDateDue( $issuedate, $effective_itemtype, $circ_library->branchcode, $patron_unblessed, $checkout_type );
712
712
713
        # Offline circ calls AddIssue directly, doesn't run through here
713
        # Offline circ calls AddIssue directly, doesn't run through here
714
        #  So issuingimpossible should be ok.
714
        #  So issuingimpossible should be ok.
Lines 1240-1246 sub checkHighHolds { Link Here
1240
        my $calendar = Koha::Calendar->new( branchcode => $branchcode );
1240
        my $calendar = Koha::Calendar->new( branchcode => $branchcode );
1241
1241
1242
        my $itype = $item_object->effective_itemtype;
1242
        my $itype = $item_object->effective_itemtype;
1243
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1243
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $borrower, $Koha::Checkouts::type->{checkout}, undef );
1244
1244
1245
        my $decreaseLoanHighHoldsDuration = C4::Context->preference('decreaseLoanHighHoldsDuration');
1245
        my $decreaseLoanHighHoldsDuration = C4::Context->preference('decreaseLoanHighHoldsDuration');
1246
1246
Lines 1354-1360 sub AddIssue { Link Here
1354
        else {
1354
        else {
1355
            unless ($datedue) {
1355
            unless ($datedue) {
1356
                my $itype = $item_object->effective_itemtype;
1356
                my $itype = $item_object->effective_itemtype;
1357
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1357
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower, $checkout_type );
1358
1358
1359
            }
1359
            }
1360
            $datedue->truncate( to => 'minute' );
1360
            $datedue->truncate( to => 'minute' );
Lines 1415-1421 sub AddIssue { Link Here
1415
            # Record in the database the fact that the book was issued.
1415
            # Record in the database the fact that the book was issued.
1416
            unless ($datedue) {
1416
            unless ($datedue) {
1417
                my $itype = $item_object->effective_itemtype;
1417
                my $itype = $item_object->effective_itemtype;
1418
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1418
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower, $checkout_type );
1419
1419
1420
            }
1420
            }
1421
            $datedue->truncate( to => 'minute' );
1421
            $datedue->truncate( to => 'minute' );
Lines 1537-1550 sub AddIssue { Link Here
1537
1537
1538
=head2 GetLoanLength
1538
=head2 GetLoanLength
1539
1539
1540
  my $loanlength = &GetLoanLength($borrowertype,$itemtype,branchcode)
1540
  my $loanlength = &GetLoanLength($borrowertype,$itemtype,branchcode,$checkout_type)
1541
1541
1542
Get loan length for an itemtype, a borrower type and a branch
1542
Get loan length for an itemtype, a borrower type and a branch
1543
1543
1544
=cut
1544
=cut
1545
1545
1546
sub GetLoanLength {
1546
sub GetLoanLength {
1547
    my ( $categorycode, $itemtype, $branchcode ) = @_;
1547
    my ( $categorycode, $itemtype, $branchcode, $checkout_type ) = @_;
1548
1548
1549
    # Initialize default values
1549
    # Initialize default values
1550
    my $rules = {
1550
    my $rules = {
Lines 1557-1562 sub GetLoanLength { Link Here
1557
        branchcode => $branchcode,
1557
        branchcode => $branchcode,
1558
        categorycode => $categorycode,
1558
        categorycode => $categorycode,
1559
        itemtype => $itemtype,
1559
        itemtype => $itemtype,
1560
        checkout_type => $checkout_type,
1560
        rules => [
1561
        rules => [
1561
            'issuelength',
1562
            'issuelength',
1562
            'renewalperiod',
1563
            'renewalperiod',
Lines 1575-1594 sub GetLoanLength { Link Here
1575
1576
1576
=head2 GetHardDueDate
1577
=head2 GetHardDueDate
1577
1578
1578
  my ($hardduedate,$hardduedatecompare) = &GetHardDueDate($borrowertype,$itemtype,branchcode)
1579
  my ($hardduedate,$hardduedatecompare) = &GetHardDueDate($borrowertype,$itemtype,branchcode,$checkout_type)
1579
1580
1580
Get the Hard Due Date and it's comparison for an itemtype, a borrower type and a branch
1581
Get the Hard Due Date and it's comparison for an itemtype, a borrower type and a branch
1581
1582
1582
=cut
1583
=cut
1583
1584
1584
sub GetHardDueDate {
1585
sub GetHardDueDate {
1585
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1586
    my ( $borrowertype, $itemtype, $branchcode, $checkout_type ) = @_;
1586
1587
1587
    my $rules = Koha::CirculationRules->get_effective_rules(
1588
    my $rules = Koha::CirculationRules->get_effective_rules(
1588
        {
1589
        {
1589
            categorycode => $borrowertype,
1590
            categorycode => $borrowertype,
1590
            itemtype     => $itemtype,
1591
            itemtype     => $itemtype,
1591
            branchcode   => $branchcode,
1592
            branchcode   => $branchcode,
1593
            checkout_type => $checkout_type,
1592
            rules        => [ 'hardduedate', 'hardduedatecompare' ],
1594
            rules        => [ 'hardduedate', 'hardduedatecompare' ],
1593
        }
1595
        }
1594
    );
1596
    );
Lines 2682-2687 sub CanBookBeRenewed { Link Here
2682
                categorycode => $patron->categorycode,
2684
                categorycode => $patron->categorycode,
2683
                itemtype     => $item->effective_itemtype,
2685
                itemtype     => $item->effective_itemtype,
2684
                branchcode   => $branchcode,
2686
                branchcode   => $branchcode,
2687
                checkout_type => $issue->checkout_type,
2685
                rules => [
2688
                rules => [
2686
                    'renewalsallowed',
2689
                    'renewalsallowed',
2687
                    'no_auto_renewal_after',
2690
                    'no_auto_renewal_after',
Lines 2929-2935 sub AddRenewal { Link Here
2929
            $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2932
            $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2930
                                            dt_from_string( $issue->date_due, 'sql' ) :
2933
                                            dt_from_string( $issue->date_due, 'sql' ) :
2931
                                            dt_from_string();
2934
                                            dt_from_string();
2932
            $datedue =  CalcDateDue($datedue, $itemtype, $circ_library->branchcode, $patron_unblessed, 'is a renewal');
2935
            $datedue =  CalcDateDue($datedue, $itemtype, $circ_library->branchcode, $patron_unblessed, $issue->checkout_type, 'is a renewal');
2933
        }
2936
        }
2934
2937
2935
        my $fees = Koha::Charges::Fees->new(
2938
        my $fees = Koha::Charges::Fees->new(
Lines 3107-3112 sub GetSoonestRenewDate { Link Here
3107
        {   categorycode => $patron->categorycode,
3110
        {   categorycode => $patron->categorycode,
3108
            itemtype     => $item->effective_itemtype,
3111
            itemtype     => $item->effective_itemtype,
3109
            branchcode   => $branchcode,
3112
            branchcode   => $branchcode,
3113
            checkout_type => $itemissue->checkout_type,
3110
            rules => [
3114
            rules => [
3111
                'norenewalbefore',
3115
                'norenewalbefore',
3112
                'lengthunit',
3116
                'lengthunit',
Lines 3171-3176 sub GetLatestAutoRenewDate { Link Here
3171
            categorycode => $patron->categorycode,
3175
            categorycode => $patron->categorycode,
3172
            itemtype     => $item->effective_itemtype,
3176
            itemtype     => $item->effective_itemtype,
3173
            branchcode   => $branchcode,
3177
            branchcode   => $branchcode,
3178
            checkout_type => $itemissue->checkout_type,
3174
            rules => [
3179
            rules => [
3175
                'no_auto_renewal_after',
3180
                'no_auto_renewal_after',
3176
                'no_auto_renewal_after_hard_limit',
3181
                'no_auto_renewal_after_hard_limit',
Lines 3521-3527 sub updateWrongTransfer { Link Here
3521
3526
3522
=head2 CalcDateDue
3527
=head2 CalcDateDue
3523
3528
3524
$newdatedue = CalcDateDue($startdate,$itemtype,$branchcode,$borrower);
3529
$newdatedue = CalcDateDue($startdate,$itemtype,$branchcode,$borrower,$checkout_type);
3525
3530
3526
this function calculates the due date given the start date and configured circulation rules,
3531
this function calculates the due date given the start date and configured circulation rules,
3527
checking against the holidays calendar as per the 'useDaysMode' syspref.
3532
checking against the holidays calendar as per the 'useDaysMode' syspref.
Lines 3534-3546 C<$isrenewal> = Boolean: is true if we want to calculate the date due for a rene Link Here
3534
=cut
3539
=cut
3535
3540
3536
sub CalcDateDue {
3541
sub CalcDateDue {
3537
    my ( $startdate, $itemtype, $branch, $borrower, $isrenewal ) = @_;
3542
    my ( $startdate, $itemtype, $branch, $borrower, $checkout_type, $isrenewal ) = @_;
3538
3543
3539
    $isrenewal ||= 0;
3544
    $isrenewal ||= 0;
3540
3545
3541
    # loanlength now a href
3546
    # loanlength now a href
3542
    my $loanlength =
3547
    my $loanlength =
3543
            GetLoanLength( $borrower->{'categorycode'}, $itemtype, $branch );
3548
            GetLoanLength( $borrower->{'categorycode'}, $itemtype, $branch, $checkout_type );
3544
3549
3545
    my $length_key = ( $isrenewal and defined $loanlength->{renewalperiod} )
3550
    my $length_key = ( $isrenewal and defined $loanlength->{renewalperiod} )
3546
            ? qq{renewalperiod}
3551
            ? qq{renewalperiod}
Lines 3586-3592 sub CalcDateDue { Link Here
3586
3591
3587
    # if Hard Due Dates are used, retrieve them and apply as necessary
3592
    # if Hard Due Dates are used, retrieve them and apply as necessary
3588
    my ( $hardduedate, $hardduedatecompare ) =
3593
    my ( $hardduedate, $hardduedatecompare ) =
3589
      GetHardDueDate( $borrower->{'categorycode'}, $itemtype, $branch );
3594
      GetHardDueDate( $borrower->{'categorycode'}, $itemtype, $branch, $checkout_type );
3590
    if ($hardduedate) {    # hardduedates are currently dates
3595
    if ($hardduedate) {    # hardduedates are currently dates
3591
        $hardduedate->truncate( to => 'minute' );
3596
        $hardduedate->truncate( to => 'minute' );
3592
        $hardduedate->set_hour(23);
3597
        $hardduedate->set_hour(23);
Lines 4168-4174 sub _CalculateAndUpdateFine { Link Here
4168
    my $date_returned = $return_date ? $return_date : dt_from_string();
4173
    my $date_returned = $return_date ? $return_date : dt_from_string();
4169
4174
4170
    my ( $amount, $unitcounttotal, $unitcount  ) =
4175
    my ( $amount, $unitcounttotal, $unitcount  ) =
4171
      C4::Overdues::CalcFine( $item, $borrower->{categorycode}, $control_branchcode, $datedue, $date_returned );
4176
      C4::Overdues::CalcFine( $item, $borrower->{categorycode}, $control_branchcode, $issue->{checkout_type}, $datedue, $date_returned );
4172
4177
4173
    if ( C4::Context->preference('finesMode') eq 'production' ) {
4178
    if ( C4::Context->preference('finesMode') eq 'production' ) {
4174
        if ( $amount > 0 ) {
4179
        if ( $amount > 0 ) {
(-)a/C4/Overdues.pm (-1 / +2 lines)
Lines 222-228 or "Final Notice". But CalcFine never defined any value. Link Here
222
=cut
222
=cut
223
223
224
sub CalcFine {
224
sub CalcFine {
225
    my ( $item, $bortype, $branchcode, $due_dt, $end_date  ) = @_;
225
    my ( $item, $bortype, $branchcode, $checkout_type, $due_dt, $end_date  ) = @_;
226
226
227
    # Skip calculations if item is not overdue
227
    # Skip calculations if item is not overdue
228
    return ( 0, 0, 0 ) unless (DateTime->compare( $due_dt, $end_date ) == -1);
228
    return ( 0, 0, 0 ) unless (DateTime->compare( $due_dt, $end_date ) == -1);
Lines 235-240 sub CalcFine { Link Here
235
            categorycode => $bortype,
235
            categorycode => $bortype,
236
            itemtype     => $itemtype,
236
            itemtype     => $itemtype,
237
            branchcode   => $branchcode,
237
            branchcode   => $branchcode,
238
            checkout_type => $checkout_type,
238
            rules => [
239
            rules => [
239
                'lengthunit',
240
                'lengthunit',
240
                'firstremind',
241
                'firstremind',
(-)a/t/db_dependent/Circulation.t (-2 / +2 lines)
Lines 541-547 subtest "CanBookBeRenewed tests" => sub { Link Here
541
    my $passeddatedue1 = AddIssue($renewing_borrower, $item_7->barcode, $five_weeks_ago);
541
    my $passeddatedue1 = AddIssue($renewing_borrower, $item_7->barcode, $five_weeks_ago);
542
    is (defined $passeddatedue1, 1, "Item with passed date due checked out, due date: " . $passeddatedue1->date_due);
542
    is (defined $passeddatedue1, 1, "Item with passed date due checked out, due date: " . $passeddatedue1->date_due);
543
543
544
    my ( $fine ) = CalcFine( $item_7->unblessed, $renewing_borrower->{categorycode}, $branch, $five_weeks_ago, $now );
544
    my ( $fine ) = CalcFine( $item_7->unblessed, $renewing_borrower->{categorycode}, $branch, undef, $five_weeks_ago, $now );
545
    C4::Overdues::UpdateFine(
545
    C4::Overdues::UpdateFine(
546
        {
546
        {
547
            issue_id       => $passeddatedue1->id(),
547
            issue_id       => $passeddatedue1->id(),
Lines 2435-2441 subtest 'AddReturn | is_overdue' => sub { Link Here
2435
2435
2436
        # Fake fines cronjob on this checkout
2436
        # Fake fines cronjob on this checkout
2437
        my ($fine) =
2437
        my ($fine) =
2438
          CalcFine( $item, $patron->categorycode, $library->{branchcode},
2438
          CalcFine( $item, $patron->categorycode, $library->{branchcode}, undef,
2439
            $ten_days_ago, $now );
2439
            $ten_days_ago, $now );
2440
        UpdateFine(
2440
        UpdateFine(
2441
            {
2441
            {
(-)a/t/db_dependent/Circulation/CalcDateDue.t (-18 / +18 lines)
Lines 53-61 my $dateexpiry = '2013-01-01'; Link Here
53
53
54
my $borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
54
my $borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
55
my $start_date = DateTime->new({year => 2013, month => 2, day => 9});
55
my $start_date = DateTime->new({year => 2013, month => 2, day => 9});
56
my $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
56
my $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type );
57
is($date, $dateexpiry . 'T23:59:00', 'date expiry');
57
is($date, $dateexpiry . 'T23:59:00', 'date expiry');
58
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
58
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type, 1 );
59
59
60
60
61
#Set syspref ReturnBeforeExpiry = 1 and useDaysMode != 'Days'
61
#Set syspref ReturnBeforeExpiry = 1 and useDaysMode != 'Days'
Lines 64-70 t::lib::Mocks::mock_preference('useDaysMode', 'noDays'); Link Here
64
64
65
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
65
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
66
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
66
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
67
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
67
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type );
68
is($date, $dateexpiry . 'T23:59:00', 'date expiry with useDaysMode to noDays');
68
is($date, $dateexpiry . 'T23:59:00', 'date expiry with useDaysMode to noDays');
69
69
70
# Let's add a special holiday on 2013-01-01. With ReturnBeforeExpiry and
70
# Let's add a special holiday on 2013-01-01. With ReturnBeforeExpiry and
Lines 77-83 $calendar->insert_single_holiday( Link Here
77
    title           =>'holidayTest',
77
    title           =>'holidayTest',
78
    description     => 'holidayDesc'
78
    description     => 'holidayDesc'
79
);
79
);
80
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
80
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type );
81
is($date, '2012-12-31T23:59:00', 'date expiry should be 2013-01-01 -1 day');
81
is($date, '2012-12-31T23:59:00', 'date expiry should be 2013-01-01 -1 day');
82
$calendar->insert_single_holiday(
82
$calendar->insert_single_holiday(
83
    day             => 31,
83
    day             => 31,
Lines 86-96 $calendar->insert_single_holiday( Link Here
86
    title           =>'holidayTest',
86
    title           =>'holidayTest',
87
    description     => 'holidayDesc'
87
    description     => 'holidayDesc'
88
);
88
);
89
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
89
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type );
90
is($date, '2012-12-30T23:59:00', 'date expiry should be 2013-01-01 -2 day');
90
is($date, '2012-12-30T23:59:00', 'date expiry should be 2013-01-01 -2 day');
91
91
92
92
93
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
93
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type, 1 );
94
94
95
95
96
#Set syspref ReturnBeforeExpiry = 0 and useDaysMode = 'Days'
96
#Set syspref ReturnBeforeExpiry = 0 and useDaysMode = 'Days'
Lines 99-108 t::lib::Mocks::mock_preference('useDaysMode', 'Days'); Link Here
99
99
100
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
100
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
101
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
101
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
102
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
102
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type );
103
is($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "date expiry ( 9 + $issuelength )");
103
is($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "date expiry ( 9 + $issuelength )");
104
104
105
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
105
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type, 1 );
106
is($date, '2013-02-' . (9 + $renewalperiod) . 'T23:59:00', "date expiry ( 9 + $renewalperiod )");
106
is($date, '2013-02-' . (9 + $renewalperiod) . 'T23:59:00', "date expiry ( 9 + $renewalperiod )");
107
107
108
108
Lines 116-125 t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 0); Link Here
116
t::lib::Mocks::mock_preference('useDaysMode', 'Dayweek');
116
t::lib::Mocks::mock_preference('useDaysMode', 'Dayweek');
117
117
118
# No closed day interfering, so we should get the regular due date
118
# No closed day interfering, so we should get the regular due date
119
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
119
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type );
120
is($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "useDaysMode = Dayweek, no closed days, issue date expiry ( start + $issuelength )");
120
is($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "useDaysMode = Dayweek, no closed days, issue date expiry ( start + $issuelength )");
121
121
122
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
122
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type, 1 );
123
is($date, '2013-02-' . (9 + $renewalperiod) . 'T23:59:00', "useDaysMode = Dayweek, no closed days, renewal date expiry ( start + $renewalperiod )");
123
is($date, '2013-02-' . (9 + $renewalperiod) . 'T23:59:00', "useDaysMode = Dayweek, no closed days, renewal date expiry ( start + $renewalperiod )");
124
124
125
# Now let's add a closed day on the expected renewal date, it should
125
# Now let's add a closed day on the expected renewal date, it should
Lines 132-138 $calendar->insert_single_holiday( Link Here
132
    title           =>'DayweekTest1',
132
    title           =>'DayweekTest1',
133
    description     => 'DayweekTest1'
133
    description     => 'DayweekTest1'
134
);
134
);
135
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
135
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type );
136
is($date, '2013-02-' . (9 + $issuelength + 1) . 'T23:59:00', "useDaysMode = Dayweek, closed on due date, 10 day loan (should not trigger 7 day roll forward), issue date expiry ( start + $issuelength  + 1 )");
136
is($date, '2013-02-' . (9 + $issuelength + 1) . 'T23:59:00', "useDaysMode = Dayweek, closed on due date, 10 day loan (should not trigger 7 day roll forward), issue date expiry ( start + $issuelength  + 1 )");
137
# Remove the holiday we just created
137
# Remove the holiday we just created
138
$calendar->delete_holiday(
138
$calendar->delete_holiday(
Lines 149-155 $calendar->insert_single_holiday( Link Here
149
    title           =>'DayweekTest2',
149
    title           =>'DayweekTest2',
150
    description     => 'DayweekTest2'
150
    description     => 'DayweekTest2'
151
);
151
);
152
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
152
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type, 1 );
153
is($date, '2013-02-' . (9 + $renewalperiod + 1) . 'T23:59:00', "useDaysMode = Dayweek, closed on due date, 5 day renewal (should not trigger 7 day roll forward), renewal date expiry ( start + $renewalperiod  + 1 )");
153
is($date, '2013-02-' . (9 + $renewalperiod + 1) . 'T23:59:00', "useDaysMode = Dayweek, closed on due date, 5 day renewal (should not trigger 7 day roll forward), renewal date expiry ( start + $renewalperiod  + 1 )");
154
# Remove the holiday we just created
154
# Remove the holiday we just created
155
$calendar->delete_holiday(
155
$calendar->delete_holiday(
Lines 192-198 $calendar->insert_single_holiday( Link Here
192
    title           =>'DayweekTest3',
192
    title           =>'DayweekTest3',
193
    description     => 'DayweekTest3'
193
    description     => 'DayweekTest3'
194
);
194
);
195
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower );
195
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower, $checkout_type );
196
my $issue_should_add = $dayweek_issuelength + 7;
196
my $issue_should_add = $dayweek_issuelength + 7;
197
my $dayweek_issue_expected = $start_date->add( days => $issue_should_add );
197
my $dayweek_issue_expected = $start_date->add( days => $issue_should_add );
198
is($date, $dayweek_issue_expected->strftime('%F') . 'T23:59:00', "useDaysMode = Dayweek, closed on due date, 14 day loan (should trigger 7 day roll forward), issue date expiry ( start + $issue_should_add )");
198
is($date, $dayweek_issue_expected->strftime('%F') . 'T23:59:00', "useDaysMode = Dayweek, closed on due date, 14 day loan (should trigger 7 day roll forward), issue date expiry ( start + $issue_should_add )");
Lines 212-218 $calendar->insert_single_holiday( Link Here
212
    title           => 'DayweekTest4',
212
    title           => 'DayweekTest4',
213
    description     => 'DayweekTest4'
213
    description     => 'DayweekTest4'
214
);
214
);
215
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower, 1 );
215
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower, $checkout_type, 1 );
216
my $renewal_should_add = $dayweek_renewalperiod + 7;
216
my $renewal_should_add = $dayweek_renewalperiod + 7;
217
my $dayweek_renewal_expected = $start_date->add( days => $renewal_should_add );
217
my $dayweek_renewal_expected = $start_date->add( days => $renewal_should_add );
218
is($date, $dayweek_renewal_expected->strftime('%F') . 'T23:59:00', "useDaysMode = Dayweek, closed on due date, 7 day renewal (should trigger 7 day roll forward), renewal date expiry ( start + $renewal_should_add )");
218
is($date, $dayweek_renewal_expected->strftime('%F') . 'T23:59:00', "useDaysMode = Dayweek, closed on due date, 7 day renewal (should trigger 7 day roll forward), renewal date expiry ( start + $renewal_should_add )");
Lines 253-264 $calendar->insert_single_holiday( Link Here
253
    description     => 'DayweekTest7'
253
    description     => 'DayweekTest7'
254
);
254
);
255
# For issues...
255
# For issues...
256
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower );
256
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower, $checkout_type );
257
$dayweek_issue_expected = $start_date->add( days => $issue_should_add );
257
$dayweek_issue_expected = $start_date->add( days => $issue_should_add );
258
is($date, $expected_rolled_date->strftime('%F') . 'T23:59:00', "useDaysMode = Dayweek, closed on due date and two subequent due dates, 14 day loan (should trigger 2 x 7 day roll forward), issue date expiry ( start + 28 )");
258
is($date, $expected_rolled_date->strftime('%F') . 'T23:59:00', "useDaysMode = Dayweek, closed on due date and two subequent due dates, 14 day loan (should trigger 2 x 7 day roll forward), issue date expiry ( start + 28 )");
259
# ...and for renewals...
259
# ...and for renewals...
260
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
260
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
261
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower, 1 );
261
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower, $checkout_type, 1 );
262
$dayweek_issue_expected = $start_date->add( days => $renewal_should_add );
262
$dayweek_issue_expected = $start_date->add( days => $renewal_should_add );
263
is($date, $expected_rolled_date->strftime('%F') . 'T23:59:00', "useDaysMode = Dayweek, closed on due date and three subsequent due dates, 7 day renewal (should trigger 3 x 7 day roll forward), issue date expiry ( start + 28 )");
263
is($date, $expected_rolled_date->strftime('%F') . 'T23:59:00', "useDaysMode = Dayweek, closed on due date and three subsequent due dates, 7 day renewal (should trigger 3 x 7 day roll forward), issue date expiry ( start + 28 )");
264
# Remove the holidays we just created
264
# Remove the holidays we just created
Lines 293-304 $calendar->insert_week_day_holiday( Link Here
293
    description => "Closed on Saturdays"
293
    description => "Closed on Saturdays"
294
);
294
);
295
# For issues...
295
# For issues...
296
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower );
296
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower, $checkout_type );
297
$dayweek_issue_expected = $start_date->add( days => $dayweek_issuelength + 1 );
297
$dayweek_issue_expected = $start_date->add( days => $dayweek_issuelength + 1 );
298
is($date, $dayweek_issue_expected->strftime('%F') . 'T23:59:00', "useDaysMode = Dayweek, due on Saturday, closed on Saturdays, 14 day loan (should trigger 1 day roll forward), issue date expiry ( start + 15 )");
298
is($date, $dayweek_issue_expected->strftime('%F') . 'T23:59:00', "useDaysMode = Dayweek, due on Saturday, closed on Saturdays, 14 day loan (should trigger 1 day roll forward), issue date expiry ( start + 15 )");
299
# ...and for renewals...
299
# ...and for renewals...
300
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
300
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
301
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower, 1 );
301
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower, $checkout_type, 1 );
302
$dayweek_renewal_expected = $start_date->add( days => $dayweek_renewalperiod + 1 );
302
$dayweek_renewal_expected = $start_date->add( days => $dayweek_renewalperiod + 1 );
303
is($date, $dayweek_renewal_expected->strftime('%F') . 'T23:59:00', "useDaysMode = Dayweek, due on Saturday, closed on Saturdays, 7 day renewal (should trigger 1 day roll forward), issue date expiry ( start + 8 )");
303
is($date, $dayweek_renewal_expected->strftime('%F') . 'T23:59:00', "useDaysMode = Dayweek, due on Saturday, closed on Saturdays, 7 day renewal (should trigger 1 day roll forward), issue date expiry ( start + 8 )");
304
# Remove the holiday we just created
304
# Remove the holiday we just created
(-)a/t/db_dependent/Circulation/CalcFine.t (-5 / +5 lines)
Lines 108-114 subtest 'Test basic functionality' => sub { Link Here
108
        day        => 30,
108
        day        => 30,
109
    );
109
    );
110
110
111
    my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
111
    my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, undef, $start_dt, $end_dt );
112
112
113
    is( $amount, 29, 'Amount is calculated correctly' );
113
    is( $amount, 29, 'Amount is calculated correctly' );
114
114
Lines 149-155 subtest 'Test cap_fine_to_replacement_price' => sub { Link Here
149
        day        => 30,
149
        day        => 30,
150
    );
150
    );
151
151
152
    my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
152
    my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, undef, $start_dt, $end_dt );
153
153
154
    is( int($amount), 5, 'Amount is calculated correctly' );
154
    is( int($amount), 5, 'Amount is calculated correctly' );
155
155
Lines 157-163 subtest 'Test cap_fine_to_replacement_price' => sub { Link Here
157
    # Use default replacement cost (useDefaultReplacementCost) is item's replacement price is 0
157
    # Use default replacement cost (useDefaultReplacementCost) is item's replacement price is 0
158
    my $item_obj = Koha::Items->find($item->{itemnumber});
158
    my $item_obj = Koha::Items->find($item->{itemnumber});
159
    $item_obj->replacementprice(0)->store;
159
    $item_obj->replacementprice(0)->store;
160
    ($amount) = CalcFine( $item_obj->unblessed, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
160
    ($amount) = CalcFine( $item_obj->unblessed, $patron->{categorycode}, $branch->{branchcode}, undef, $start_dt, $end_dt );
161
    is( int($amount), 6, 'Amount is calculated correctly' );
161
    is( int($amount), 6, 'Amount is calculated correctly' );
162
162
163
    teardown();
163
    teardown();
Lines 197-207 subtest 'Test cap_fine_to_replacement_pricew with overduefinescap' => sub { Link Here
197
        day        => 30,
197
        day        => 30,
198
    );
198
    );
199
199
200
    my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
200
    my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, undef, $start_dt, $end_dt );
201
    is( int($amount), 3, 'Got the lesser of overduefinescap and replacement price where overduefinescap < replacement price' );
201
    is( int($amount), 3, 'Got the lesser of overduefinescap and replacement price where overduefinescap < replacement price' );
202
202
203
    Koha::CirculationRules->set_rule({ rule_name => 'overduefinescap', rule_value => 6, branchcode => undef, categorycode => undef, itemtype => undef, checkout_type => undef });
203
    Koha::CirculationRules->set_rule({ rule_name => 'overduefinescap', rule_value => 6, branchcode => undef, categorycode => undef, itemtype => undef, checkout_type => undef });
204
    ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
204
    ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, undef, $start_dt, $end_dt );
205
    is( int($amount), 5, 'Get the lesser of overduefinescap and replacement price where overduefinescap > replacement price' );
205
    is( int($amount), 5, 'Get the lesser of overduefinescap and replacement price where overduefinescap > replacement price' );
206
206
207
    teardown();
207
    teardown();
(-)a/t/db_dependent/Circulation/GetHardDueDate.t (-3 / +8 lines)
Lines 11-17 use Koha::Library; Link Here
11
11
12
use t::lib::TestBuilder;
12
use t::lib::TestBuilder;
13
13
14
use Test::More tests => 9;
14
use Test::More tests => 10;
15
15
16
BEGIN {
16
BEGIN {
17
    use_ok('C4::Circulation');
17
    use_ok('C4::Circulation');
Lines 220-226 Koha::CirculationRules->set_rules( $sampleissuingrule3 ); Link Here
220
is_deeply(
220
is_deeply(
221
    C4::Circulation::GetLoanLength(
221
    C4::Circulation::GetLoanLength(
222
        $samplecat->{categorycode},
222
        $samplecat->{categorycode},
223
        $sampleitemtype1, $samplebranch1->{branchcode}
223
        $sampleitemtype1, $samplebranch1->{branchcode}, $Koha::Checkouts::type->{checkout}
224
    ),
224
    ),
225
    { issuelength => 5, lengthunit => 'days', renewalperiod => 5 },
225
    { issuelength => 5, lengthunit => 'days', renewalperiod => 5 },
226
    "GetLoanLength"
226
    "GetLoanLength"
Lines 248-253 is_deeply( Link Here
248
);    #NOTE : is that really what is expected?
248
);    #NOTE : is that really what is expected?
249
is_deeply(
249
is_deeply(
250
    C4::Circulation::GetLoanLength( $samplecat->{categorycode}, $sampleitemtype1, $samplebranch1->{branchcode} ),
250
    C4::Circulation::GetLoanLength( $samplecat->{categorycode}, $sampleitemtype1, $samplebranch1->{branchcode} ),
251
    $default,
252
    "With only three parameters, GetLoanLength returns hardcoded values"
253
);    #NOTE : is that really what is expected?
254
is_deeply(
255
    C4::Circulation::GetLoanLength( $samplecat->{categorycode}, $sampleitemtype1, $samplebranch1->{branchcode}, $Koha::Checkouts::type->{checkout} ),
251
    {
256
    {
252
        issuelength   => 5,
257
        issuelength   => 5,
253
        renewalperiod => 5,
258
        renewalperiod => 5,
Lines 258-264 is_deeply( Link Here
258
263
259
#Test GetHardDueDate
264
#Test GetHardDueDate
260
my @hardduedate = C4::Circulation::GetHardDueDate( $samplecat->{categorycode},
265
my @hardduedate = C4::Circulation::GetHardDueDate( $samplecat->{categorycode},
261
    $sampleitemtype1, $samplebranch1->{branchcode} );
266
    $sampleitemtype1, $samplebranch1->{branchcode}, $Koha::Checkouts::type->{checkout} );
262
is_deeply(
267
is_deeply(
263
    \@hardduedate,
268
    \@hardduedate,
264
    [
269
    [
(-)a/t/db_dependent/Fines.t (-5 / +4 lines)
Lines 37-47 ok( $issuingrule, 'Issuing rule created' ); Link Here
37
my $period_start = dt_from_string('2000-01-01');
37
my $period_start = dt_from_string('2000-01-01');
38
my $period_end = dt_from_string('2000-01-05');
38
my $period_end = dt_from_string('2000-01-05');
39
39
40
my ( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end  );
40
my ( $fine ) = CalcFine( {}, q{}, q{}, q{}, $period_start, $period_end  );
41
is( $fine, 0, '4 days overdue, charge period 7 days, charge at end of interval gives fine of $0' );
41
is( $fine, 0, '4 days overdue, charge period 7 days, charge at end of interval gives fine of $0' );
42
42
43
$period_end = dt_from_string('2000-01-10');
43
$period_end = dt_from_string('2000-01-10');
44
( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end  );
44
( $fine ) = CalcFine( {}, q{}, q{}, q{}, $period_start, $period_end  );
45
is( $fine, 1, '9 days overdue, charge period 7 days, charge at end of interval gives fine of $1' );
45
is( $fine, 1, '9 days overdue, charge period 7 days, charge at end of interval gives fine of $1' );
46
46
47
# Test charging fine at the *beginning* of each charge period
47
# Test charging fine at the *beginning* of each charge period
Lines 58-66 $issuingrule = Koha::CirculationRules->set_rules( Link Here
58
);
58
);
59
59
60
$period_end = dt_from_string('2000-01-05');
60
$period_end = dt_from_string('2000-01-05');
61
( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end  );
61
( $fine ) = CalcFine( {}, q{}, q{}, q{}, $period_start, $period_end  );
62
is( $fine, 1, '4 days overdue, charge period 7 days, charge at start of interval gives fine of $1' );
62
is( $fine, 1, '4 days overdue, charge period 7 days, charge at start of interval gives fine of $1' );
63
63
64
$period_end = dt_from_string('2000-01-10');
64
$period_end = dt_from_string('2000-01-10');
65
( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end  );
65
( $fine ) = CalcFine( {}, q{}, q{}, q{}, $period_start, $period_end  );
66
is( $fine, 2, '9 days overdue, charge period 7 days, charge at start of interval gives fine of $2' );
66
is( $fine, 2, '9 days overdue, charge period 7 days, charge at start of interval gives fine of $2' );
67
- 

Return to bug 25089