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 1249-1255 sub checkHighHolds { Link Here
1249
        );
1249
        );
1250
        my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode );
1250
        my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode );
1251
1251
1252
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1252
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $borrower, $Koha::Checkouts::type->{checkout} );
1253
1253
1254
        my $decreaseLoanHighHoldsDuration = C4::Context->preference('decreaseLoanHighHoldsDuration');
1254
        my $decreaseLoanHighHoldsDuration = C4::Context->preference('decreaseLoanHighHoldsDuration');
1255
1255
Lines 1363-1369 sub AddIssue { Link Here
1363
        else {
1363
        else {
1364
            unless ($datedue) {
1364
            unless ($datedue) {
1365
                my $itype = $item_object->effective_itemtype;
1365
                my $itype = $item_object->effective_itemtype;
1366
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1366
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower, $checkout_type );
1367
1367
1368
            }
1368
            }
1369
            $datedue->truncate( to => 'minute' );
1369
            $datedue->truncate( to => 'minute' );
Lines 1424-1430 sub AddIssue { Link Here
1424
            # Record in the database the fact that the book was issued.
1424
            # Record in the database the fact that the book was issued.
1425
            unless ($datedue) {
1425
            unless ($datedue) {
1426
                my $itype = $item_object->effective_itemtype;
1426
                my $itype = $item_object->effective_itemtype;
1427
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1427
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower, $checkout_type );
1428
1428
1429
            }
1429
            }
1430
            $datedue->truncate( to => 'minute' );
1430
            $datedue->truncate( to => 'minute' );
Lines 1559-1572 sub AddIssue { Link Here
1559
1559
1560
=head2 GetLoanLength
1560
=head2 GetLoanLength
1561
1561
1562
  my $loanlength = &GetLoanLength($borrowertype,$itemtype,branchcode)
1562
  my $loanlength = &GetLoanLength($borrowertype,$itemtype,branchcode,$checkout_type)
1563
1563
1564
Get loan length for an itemtype, a borrower type and a branch
1564
Get loan length for an itemtype, a borrower type and a branch
1565
1565
1566
=cut
1566
=cut
1567
1567
1568
sub GetLoanLength {
1568
sub GetLoanLength {
1569
    my ( $categorycode, $itemtype, $branchcode ) = @_;
1569
    my ( $categorycode, $itemtype, $branchcode, $checkout_type ) = @_;
1570
1570
1571
    # Initialize default values
1571
    # Initialize default values
1572
    my $rules = {
1572
    my $rules = {
Lines 1579-1584 sub GetLoanLength { Link Here
1579
        branchcode => $branchcode,
1579
        branchcode => $branchcode,
1580
        categorycode => $categorycode,
1580
        categorycode => $categorycode,
1581
        itemtype => $itemtype,
1581
        itemtype => $itemtype,
1582
        checkout_type => $checkout_type,
1582
        rules => [
1583
        rules => [
1583
            'issuelength',
1584
            'issuelength',
1584
            'renewalperiod',
1585
            'renewalperiod',
Lines 1597-1616 sub GetLoanLength { Link Here
1597
1598
1598
=head2 GetHardDueDate
1599
=head2 GetHardDueDate
1599
1600
1600
  my ($hardduedate,$hardduedatecompare) = &GetHardDueDate($borrowertype,$itemtype,branchcode)
1601
  my ($hardduedate,$hardduedatecompare) = &GetHardDueDate($borrowertype,$itemtype,branchcode,$checkout_type)
1601
1602
1602
Get the Hard Due Date and it's comparison for an itemtype, a borrower type and a branch
1603
Get the Hard Due Date and it's comparison for an itemtype, a borrower type and a branch
1603
1604
1604
=cut
1605
=cut
1605
1606
1606
sub GetHardDueDate {
1607
sub GetHardDueDate {
1607
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1608
    my ( $borrowertype, $itemtype, $branchcode, $checkout_type ) = @_;
1608
1609
1609
    my $rules = Koha::CirculationRules->get_effective_rules(
1610
    my $rules = Koha::CirculationRules->get_effective_rules(
1610
        {
1611
        {
1611
            categorycode => $borrowertype,
1612
            categorycode => $borrowertype,
1612
            itemtype     => $itemtype,
1613
            itemtype     => $itemtype,
1613
            branchcode   => $branchcode,
1614
            branchcode   => $branchcode,
1615
            checkout_type => $checkout_type,
1614
            rules        => [ 'hardduedate', 'hardduedatecompare' ],
1616
            rules        => [ 'hardduedate', 'hardduedatecompare' ],
1615
        }
1617
        }
1616
    );
1618
    );
Lines 2729-2734 sub CanBookBeRenewed { Link Here
2729
                categorycode => $patron->categorycode,
2731
                categorycode => $patron->categorycode,
2730
                itemtype     => $item->effective_itemtype,
2732
                itemtype     => $item->effective_itemtype,
2731
                branchcode   => $branchcode,
2733
                branchcode   => $branchcode,
2734
                checkout_type => $issue->checkout_type,
2732
                rules => [
2735
                rules => [
2733
                    'renewalsallowed',
2736
                    'renewalsallowed',
2734
                    'no_auto_renewal_after',
2737
                    'no_auto_renewal_after',
Lines 2976-2982 sub AddRenewal { Link Here
2976
            $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2979
            $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2977
                                            dt_from_string( $issue->date_due, 'sql' ) :
2980
                                            dt_from_string( $issue->date_due, 'sql' ) :
2978
                                            dt_from_string();
2981
                                            dt_from_string();
2979
            $datedue =  CalcDateDue($datedue, $itemtype, $circ_library->branchcode, $patron_unblessed, 'is a renewal');
2982
            $datedue =  CalcDateDue($datedue, $itemtype, $circ_library->branchcode, $patron_unblessed, $issue->checkout_type, 'is a renewal');
2980
        }
2983
        }
2981
2984
2982
        my $fees = Koha::Charges::Fees->new(
2985
        my $fees = Koha::Charges::Fees->new(
Lines 3154-3159 sub GetSoonestRenewDate { Link Here
3154
        {   categorycode => $patron->categorycode,
3157
        {   categorycode => $patron->categorycode,
3155
            itemtype     => $item->effective_itemtype,
3158
            itemtype     => $item->effective_itemtype,
3156
            branchcode   => $branchcode,
3159
            branchcode   => $branchcode,
3160
            checkout_type => $itemissue->checkout_type,
3157
            rules => [
3161
            rules => [
3158
                'norenewalbefore',
3162
                'norenewalbefore',
3159
                'lengthunit',
3163
                'lengthunit',
Lines 3218-3223 sub GetLatestAutoRenewDate { Link Here
3218
            categorycode => $patron->categorycode,
3222
            categorycode => $patron->categorycode,
3219
            itemtype     => $item->effective_itemtype,
3223
            itemtype     => $item->effective_itemtype,
3220
            branchcode   => $branchcode,
3224
            branchcode   => $branchcode,
3225
            checkout_type => $itemissue->checkout_type,
3221
            rules => [
3226
            rules => [
3222
                'no_auto_renewal_after',
3227
                'no_auto_renewal_after',
3223
                'no_auto_renewal_after_hard_limit',
3228
                'no_auto_renewal_after_hard_limit',
Lines 3568-3574 sub updateWrongTransfer { Link Here
3568
3573
3569
=head2 CalcDateDue
3574
=head2 CalcDateDue
3570
3575
3571
$newdatedue = CalcDateDue($startdate,$itemtype,$branchcode,$borrower);
3576
$newdatedue = CalcDateDue($startdate,$itemtype,$branchcode,$borrower,$checkout_type);
3572
3577
3573
this function calculates the due date given the start date and configured circulation rules,
3578
this function calculates the due date given the start date and configured circulation rules,
3574
checking against the holidays calendar as per the daysmode circulation rule.
3579
checking against the holidays calendar as per the daysmode circulation rule.
Lines 3581-3593 C<$isrenewal> = Boolean: is true if we want to calculate the date due for a rene Link Here
3581
=cut
3586
=cut
3582
3587
3583
sub CalcDateDue {
3588
sub CalcDateDue {
3584
    my ( $startdate, $itemtype, $branch, $borrower, $isrenewal ) = @_;
3589
    my ( $startdate, $itemtype, $branch, $borrower, $checkout_type, $isrenewal ) = @_;
3585
3590
3586
    $isrenewal ||= 0;
3591
    $isrenewal ||= 0;
3587
3592
3588
    # loanlength now a href
3593
    # loanlength now a href
3589
    my $loanlength =
3594
    my $loanlength =
3590
            GetLoanLength( $borrower->{'categorycode'}, $itemtype, $branch );
3595
            GetLoanLength( $borrower->{'categorycode'}, $itemtype, $branch, $checkout_type );
3591
3596
3592
    my $length_key = ( $isrenewal and defined $loanlength->{renewalperiod} )
3597
    my $length_key = ( $isrenewal and defined $loanlength->{renewalperiod} )
3593
            ? qq{renewalperiod}
3598
            ? qq{renewalperiod}
Lines 3641-3647 sub CalcDateDue { Link Here
3641
3646
3642
    # if Hard Due Dates are used, retrieve them and apply as necessary
3647
    # if Hard Due Dates are used, retrieve them and apply as necessary
3643
    my ( $hardduedate, $hardduedatecompare ) =
3648
    my ( $hardduedate, $hardduedatecompare ) =
3644
      GetHardDueDate( $borrower->{'categorycode'}, $itemtype, $branch );
3649
      GetHardDueDate( $borrower->{'categorycode'}, $itemtype, $branch, $checkout_type );
3645
    if ($hardduedate) {    # hardduedates are currently dates
3650
    if ($hardduedate) {    # hardduedates are currently dates
3646
        $hardduedate->truncate( to => 'minute' );
3651
        $hardduedate->truncate( to => 'minute' );
3647
        $hardduedate->set_hour(23);
3652
        $hardduedate->set_hour(23);
Lines 4225-4231 sub _CalculateAndUpdateFine { Link Here
4225
    my $date_returned = $return_date ? $return_date : dt_from_string();
4230
    my $date_returned = $return_date ? $return_date : dt_from_string();
4226
4231
4227
    my ( $amount, $unitcounttotal, $unitcount  ) =
4232
    my ( $amount, $unitcounttotal, $unitcount  ) =
4228
      C4::Overdues::CalcFine( $item, $borrower->{categorycode}, $control_branchcode, $datedue, $date_returned );
4233
      C4::Overdues::CalcFine( $item, $borrower->{categorycode}, $control_branchcode, $issue->{checkout_type}, $datedue, $date_returned );
4229
4234
4230
    if ( C4::Context->preference('finesMode') eq 'production' ) {
4235
    if ( C4::Context->preference('finesMode') eq 'production' ) {
4231
        if ( $amount > 0 ) {
4236
        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 547-553 subtest "CanBookBeRenewed tests" => sub { Link Here
547
    my $passeddatedue1 = AddIssue($renewing_borrower, $item_7->barcode, $five_weeks_ago);
547
    my $passeddatedue1 = AddIssue($renewing_borrower, $item_7->barcode, $five_weeks_ago);
548
    is (defined $passeddatedue1, 1, "Item with passed date due checked out, due date: " . $passeddatedue1->date_due);
548
    is (defined $passeddatedue1, 1, "Item with passed date due checked out, due date: " . $passeddatedue1->date_due);
549
549
550
    my ( $fine ) = CalcFine( $item_7->unblessed, $renewing_borrower->{categorycode}, $branch, $five_weeks_ago, $now );
550
    my ( $fine ) = CalcFine( $item_7->unblessed, $renewing_borrower->{categorycode}, $branch, undef, $five_weeks_ago, $now );
551
    C4::Overdues::UpdateFine(
551
    C4::Overdues::UpdateFine(
552
        {
552
        {
553
            issue_id       => $passeddatedue1->id(),
553
            issue_id       => $passeddatedue1->id(),
Lines 2454-2460 subtest 'AddReturn | is_overdue' => sub { Link Here
2454
2454
2455
        # Fake fines cronjob on this checkout
2455
        # Fake fines cronjob on this checkout
2456
        my ($fine) =
2456
        my ($fine) =
2457
          CalcFine( $item, $patron->categorycode, $library->{branchcode},
2457
          CalcFine( $item, $patron->categorycode, $library->{branchcode}, undef,
2458
            $ten_days_ago, $now );
2458
            $ten_days_ago, $now );
2459
        UpdateFine(
2459
        UpdateFine(
2460
            {
2460
            {
(-)a/t/db_dependent/Circulation/CalcDateDue.t (-18 / +18 lines)
Lines 54-62 my $dateexpiry = '2013-01-01'; Link Here
54
54
55
my $borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
55
my $borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
56
my $start_date = DateTime->new({year => 2013, month => 2, day => 9});
56
my $start_date = DateTime->new({year => 2013, month => 2, day => 9});
57
my $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
57
my $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type );
58
is($date, $dateexpiry . 'T23:59:00', 'date expiry');
58
is($date, $dateexpiry . 'T23:59:00', 'date expiry');
59
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
59
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type, 1 );
60
60
61
61
62
#Set syspref ReturnBeforeExpiry = 1 and useDaysMode != 'Days'
62
#Set syspref ReturnBeforeExpiry = 1 and useDaysMode != 'Days'
Lines 65-71 t::lib::Mocks::mock_preference('useDaysMode', 'noDays'); Link Here
65
65
66
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
66
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
67
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
67
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
68
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
68
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type );
69
is($date, $dateexpiry . 'T23:59:00', 'date expiry with useDaysMode to noDays');
69
is($date, $dateexpiry . 'T23:59:00', 'date expiry with useDaysMode to noDays');
70
70
71
# Let's add a special holiday on 2013-01-01. With ReturnBeforeExpiry and
71
# Let's add a special holiday on 2013-01-01. With ReturnBeforeExpiry and
Lines 78-84 $calendar->insert_single_holiday( Link Here
78
    title           =>'holidayTest',
78
    title           =>'holidayTest',
79
    description     => 'holidayDesc'
79
    description     => 'holidayDesc'
80
);
80
);
81
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
81
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type );
82
is($date, '2012-12-31T23:59:00', 'date expiry should be 2013-01-01 -1 day');
82
is($date, '2012-12-31T23:59:00', 'date expiry should be 2013-01-01 -1 day');
83
$calendar->insert_single_holiday(
83
$calendar->insert_single_holiday(
84
    day             => 31,
84
    day             => 31,
Lines 87-97 $calendar->insert_single_holiday( Link Here
87
    title           =>'holidayTest',
87
    title           =>'holidayTest',
88
    description     => 'holidayDesc'
88
    description     => 'holidayDesc'
89
);
89
);
90
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
90
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type );
91
is($date, '2012-12-30T23:59:00', 'date expiry should be 2013-01-01 -2 day');
91
is($date, '2012-12-30T23:59:00', 'date expiry should be 2013-01-01 -2 day');
92
92
93
93
94
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
94
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type, 1 );
95
95
96
96
97
#Set syspref ReturnBeforeExpiry = 0 and useDaysMode = 'Days'
97
#Set syspref ReturnBeforeExpiry = 0 and useDaysMode = 'Days'
Lines 100-109 t::lib::Mocks::mock_preference('useDaysMode', 'Days'); Link Here
100
100
101
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
101
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
102
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
102
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
103
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
103
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type );
104
is($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "date expiry ( 9 + $issuelength )");
104
is($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "date expiry ( 9 + $issuelength )");
105
105
106
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
106
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type, 1 );
107
is($date, '2013-02-' . (9 + $renewalperiod) . 'T23:59:00', "date expiry ( 9 + $renewalperiod )");
107
is($date, '2013-02-' . (9 + $renewalperiod) . 'T23:59:00', "date expiry ( 9 + $renewalperiod )");
108
108
109
109
Lines 117-126 t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 0); Link Here
117
t::lib::Mocks::mock_preference('useDaysMode', 'Dayweek');
117
t::lib::Mocks::mock_preference('useDaysMode', 'Dayweek');
118
118
119
# No closed day interfering, so we should get the regular due date
119
# No closed day interfering, so we should get the regular due date
120
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
120
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type );
121
is($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "useDaysMode = Dayweek, no closed days, issue date expiry ( start + $issuelength )");
121
is($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "useDaysMode = Dayweek, no closed days, issue date expiry ( start + $issuelength )");
122
122
123
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
123
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type, 1 );
124
is($date, '2013-02-' . (9 + $renewalperiod) . 'T23:59:00', "useDaysMode = Dayweek, no closed days, renewal date expiry ( start + $renewalperiod )");
124
is($date, '2013-02-' . (9 + $renewalperiod) . 'T23:59:00', "useDaysMode = Dayweek, no closed days, renewal date expiry ( start + $renewalperiod )");
125
125
126
# Now let's add a closed day on the expected renewal date, it should
126
# Now let's add a closed day on the expected renewal date, it should
Lines 133-139 $calendar->insert_single_holiday( Link Here
133
    title           =>'DayweekTest1',
133
    title           =>'DayweekTest1',
134
    description     => 'DayweekTest1'
134
    description     => 'DayweekTest1'
135
);
135
);
136
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
136
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type );
137
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
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 )");
138
# Remove the holiday we just created
138
# Remove the holiday we just created
139
$calendar->delete_holiday(
139
$calendar->delete_holiday(
Lines 150-156 $calendar->insert_single_holiday( Link Here
150
    title           =>'DayweekTest2',
150
    title           =>'DayweekTest2',
151
    description     => 'DayweekTest2'
151
    description     => 'DayweekTest2'
152
);
152
);
153
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
153
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, $checkout_type, 1 );
154
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
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 )");
155
# Remove the holiday we just created
155
# Remove the holiday we just created
156
$calendar->delete_holiday(
156
$calendar->delete_holiday(
Lines 193-199 $calendar->insert_single_holiday( Link Here
193
    title           =>'DayweekTest3',
193
    title           =>'DayweekTest3',
194
    description     => 'DayweekTest3'
194
    description     => 'DayweekTest3'
195
);
195
);
196
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower );
196
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower, $checkout_type );
197
my $issue_should_add = $dayweek_issuelength + 7;
197
my $issue_should_add = $dayweek_issuelength + 7;
198
my $dayweek_issue_expected = $start_date->add( days => $issue_should_add );
198
my $dayweek_issue_expected = $start_date->add( days => $issue_should_add );
199
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 )");
199
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 213-219 $calendar->insert_single_holiday( Link Here
213
    title           => 'DayweekTest4',
213
    title           => 'DayweekTest4',
214
    description     => 'DayweekTest4'
214
    description     => 'DayweekTest4'
215
);
215
);
216
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower, 1 );
216
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower, $checkout_type, 1 );
217
my $renewal_should_add = $dayweek_renewalperiod + 7;
217
my $renewal_should_add = $dayweek_renewalperiod + 7;
218
my $dayweek_renewal_expected = $start_date->add( days => $renewal_should_add );
218
my $dayweek_renewal_expected = $start_date->add( days => $renewal_should_add );
219
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 )");
219
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 254-265 $calendar->insert_single_holiday( Link Here
254
    description     => 'DayweekTest7'
254
    description     => 'DayweekTest7'
255
);
255
);
256
# For issues...
256
# For issues...
257
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower );
257
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower, $checkout_type );
258
$dayweek_issue_expected = $start_date->add( days => $issue_should_add );
258
$dayweek_issue_expected = $start_date->add( days => $issue_should_add );
259
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
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 )");
260
# ...and for renewals...
260
# ...and for renewals...
261
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
261
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
262
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower, 1 );
262
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower, $checkout_type, 1 );
263
$dayweek_issue_expected = $start_date->add( days => $renewal_should_add );
263
$dayweek_issue_expected = $start_date->add( days => $renewal_should_add );
264
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
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 )");
265
# Remove the holidays we just created
265
# Remove the holidays we just created
Lines 294-305 $calendar->insert_week_day_holiday( Link Here
294
    description => "Closed on Saturdays"
294
    description => "Closed on Saturdays"
295
);
295
);
296
# For issues...
296
# For issues...
297
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower );
297
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower, $checkout_type );
298
$dayweek_issue_expected = $start_date->add( days => $dayweek_issuelength + 1 );
298
$dayweek_issue_expected = $start_date->add( days => $dayweek_issuelength + 1 );
299
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
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 )");
300
# ...and for renewals...
300
# ...and for renewals...
301
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
301
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
302
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower, 1 );
302
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower, $checkout_type, 1 );
303
$dayweek_renewal_expected = $start_date->add( days => $dayweek_renewalperiod + 1 );
303
$dayweek_renewal_expected = $start_date->add( days => $dayweek_renewalperiod + 1 );
304
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
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 )");
305
# Remove the holiday we just created
305
# 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