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

(-)a/C4/Circulation.pm (-14 / +19 lines)
Lines 752-758 sub CanBookBeIssued { Link Here
752
    unless ( $duedate ) {
752
    unless ( $duedate ) {
753
        my $issuedate = $now->clone();
753
        my $issuedate = $now->clone();
754
754
755
        $duedate = CalcDateDue( $issuedate, $effective_itemtype, $circ_library->branchcode, $patron_unblessed );
755
        $duedate = CalcDateDue( $issuedate, $effective_itemtype, $circ_library->branchcode, $patron_unblessed, $onsite_checkout );
756
756
757
        # Offline circ calls AddIssue directly, doesn't run through here
757
        # Offline circ calls AddIssue directly, doesn't run through here
758
        #  So issuingimpossible should be ok.
758
        #  So issuingimpossible should be ok.
Lines 1315-1321 sub checkHighHolds { Link Here
1315
        );
1315
        );
1316
        my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode );
1316
        my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode );
1317
1317
1318
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1318
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $borrower, 0 );
1319
1319
1320
        my $decreaseLoanHighHoldsDuration = C4::Context->preference('decreaseLoanHighHoldsDuration');
1320
        my $decreaseLoanHighHoldsDuration = C4::Context->preference('decreaseLoanHighHoldsDuration');
1321
1321
Lines 1424-1430 sub AddIssue { Link Here
1424
        else {
1424
        else {
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, $onsite_checkout );
1428
1428
1429
            }
1429
            }
1430
            $datedue->truncate( to => 'minute' );
1430
            $datedue->truncate( to => 'minute' );
Lines 1489-1495 sub AddIssue { Link Here
1489
            # Record in the database the fact that the book was issued.
1489
            # Record in the database the fact that the book was issued.
1490
            unless ($datedue) {
1490
            unless ($datedue) {
1491
                my $itype = $item_object->effective_itemtype;
1491
                my $itype = $item_object->effective_itemtype;
1492
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1492
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower, $onsite_checkout );
1493
1493
1494
            }
1494
            }
1495
            $datedue->truncate( to => 'minute' );
1495
            $datedue->truncate( to => 'minute' );
Lines 1602-1615 sub AddIssue { Link Here
1602
1602
1603
=head2 GetLoanLength
1603
=head2 GetLoanLength
1604
1604
1605
  my $loanlength = &GetLoanLength($borrowertype,$itemtype,branchcode)
1605
  my $loanlength = &GetLoanLength($borrowertype,$itemtype,branchcode,$onsite_checkout)
1606
1606
1607
Get loan length for an itemtype, a borrower type and a branch
1607
Get loan length for an itemtype, a borrower type and a branch
1608
1608
1609
=cut
1609
=cut
1610
1610
1611
sub GetLoanLength {
1611
sub GetLoanLength {
1612
    my ( $categorycode, $itemtype, $branchcode ) = @_;
1612
    my ( $categorycode, $itemtype, $branchcode, $onsite_checkout ) = @_;
1613
1613
1614
    # Initialize default values
1614
    # Initialize default values
1615
    my $rules = {
1615
    my $rules = {
Lines 1622-1627 sub GetLoanLength { Link Here
1622
        branchcode => $branchcode,
1622
        branchcode => $branchcode,
1623
        categorycode => $categorycode,
1623
        categorycode => $categorycode,
1624
        itemtype => $itemtype,
1624
        itemtype => $itemtype,
1625
        onsite_checkout => $onsite_checkout,
1625
        rules => [
1626
        rules => [
1626
            'issuelength',
1627
            'issuelength',
1627
            'renewalperiod',
1628
            'renewalperiod',
Lines 1640-1659 sub GetLoanLength { Link Here
1640
1641
1641
=head2 GetHardDueDate
1642
=head2 GetHardDueDate
1642
1643
1643
  my ($hardduedate,$hardduedatecompare) = &GetHardDueDate($borrowertype,$itemtype,branchcode)
1644
  my ($hardduedate,$hardduedatecompare) = &GetHardDueDate($borrowertype,$itemtype,branchcode,$onsite_checkout)
1644
1645
1645
Get the Hard Due Date and it's comparison for an itemtype, a borrower type and a branch
1646
Get the Hard Due Date and it's comparison for an itemtype, a borrower type and a branch
1646
1647
1647
=cut
1648
=cut
1648
1649
1649
sub GetHardDueDate {
1650
sub GetHardDueDate {
1650
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1651
    my ( $borrowertype, $itemtype, $branchcode, $onsite_checkout ) = @_;
1651
1652
1652
    my $rules = Koha::CirculationRules->get_effective_rules(
1653
    my $rules = Koha::CirculationRules->get_effective_rules(
1653
        {
1654
        {
1654
            categorycode => $borrowertype,
1655
            categorycode => $borrowertype,
1655
            itemtype     => $itemtype,
1656
            itemtype     => $itemtype,
1656
            branchcode   => $branchcode,
1657
            branchcode   => $branchcode,
1658
            onsite_checkout => $onsite_checkout,
1657
            rules        => [ 'hardduedate', 'hardduedatecompare' ],
1659
            rules        => [ 'hardduedate', 'hardduedatecompare' ],
1658
        }
1660
        }
1659
    );
1661
    );
Lines 2671-2676 sub CanBookBeRenewed { Link Here
2671
                categorycode => $patron->categorycode,
2673
                categorycode => $patron->categorycode,
2672
                itemtype     => $item->effective_itemtype,
2674
                itemtype     => $item->effective_itemtype,
2673
                branchcode   => $branchcode,
2675
                branchcode   => $branchcode,
2676
                onsite_checkout => $issue->onsite_checkout,
2674
                rules => [
2677
                rules => [
2675
                    'renewalsallowed',
2678
                    'renewalsallowed',
2676
                    'no_auto_renewal_after',
2679
                    'no_auto_renewal_after',
Lines 2933-2939 sub AddRenewal { Link Here
2933
            $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2936
            $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2934
                                            dt_from_string( $issue->date_due, 'sql' ) :
2937
                                            dt_from_string( $issue->date_due, 'sql' ) :
2935
                                            dt_from_string();
2938
                                            dt_from_string();
2936
            $datedue =  CalcDateDue($datedue, $itemtype, $circ_library->branchcode, $patron_unblessed, 'is a renewal');
2939
            $datedue =  CalcDateDue($datedue, $itemtype, $circ_library->branchcode, $patron_unblessed, $issue->onsite_checkout, 'is a renewal');
2937
        }
2940
        }
2938
2941
2939
        my $fees = Koha::Charges::Fees->new(
2942
        my $fees = Koha::Charges::Fees->new(
Lines 3118-3123 sub GetSoonestRenewDate { Link Here
3118
        {   categorycode => $patron->categorycode,
3121
        {   categorycode => $patron->categorycode,
3119
            itemtype     => $item->effective_itemtype,
3122
            itemtype     => $item->effective_itemtype,
3120
            branchcode   => $branchcode,
3123
            branchcode   => $branchcode,
3124
            onsite_checkout => $itemissue->onsite_checkout,
3121
            rules => [
3125
            rules => [
3122
                'norenewalbefore',
3126
                'norenewalbefore',
3123
                'lengthunit',
3127
                'lengthunit',
Lines 3182-3187 sub GetLatestAutoRenewDate { Link Here
3182
            categorycode => $patron->categorycode,
3186
            categorycode => $patron->categorycode,
3183
            itemtype     => $item->effective_itemtype,
3187
            itemtype     => $item->effective_itemtype,
3184
            branchcode   => $branchcode,
3188
            branchcode   => $branchcode,
3189
            onsite_checkout => $itemissue->onsite_checkout,
3185
            rules => [
3190
            rules => [
3186
                'no_auto_renewal_after',
3191
                'no_auto_renewal_after',
3187
                'no_auto_renewal_after_hard_limit',
3192
                'no_auto_renewal_after_hard_limit',
Lines 3532-3538 sub updateWrongTransfer { Link Here
3532
3537
3533
=head2 CalcDateDue
3538
=head2 CalcDateDue
3534
3539
3535
$newdatedue = CalcDateDue($startdate,$itemtype,$branchcode,$borrower);
3540
$newdatedue = CalcDateDue($startdate,$itemtype,$branchcode,$borrower,$onsite_checkout);
3536
3541
3537
this function calculates the due date given the start date and configured circulation rules,
3542
this function calculates the due date given the start date and configured circulation rules,
3538
checking against the holidays calendar as per the daysmode circulation rule.
3543
checking against the holidays calendar as per the daysmode circulation rule.
Lines 3545-3557 C<$isrenewal> = Boolean: is true if we want to calculate the date due for a rene Link Here
3545
=cut
3550
=cut
3546
3551
3547
sub CalcDateDue {
3552
sub CalcDateDue {
3548
    my ( $startdate, $itemtype, $branch, $borrower, $isrenewal ) = @_;
3553
    my ( $startdate, $itemtype, $branch, $borrower, $onsite_checkout, $isrenewal ) = @_;
3549
3554
3550
    $isrenewal ||= 0;
3555
    $isrenewal ||= 0;
3551
3556
3552
    # loanlength now a href
3557
    # loanlength now a href
3553
    my $loanlength =
3558
    my $loanlength =
3554
            GetLoanLength( $borrower->{'categorycode'}, $itemtype, $branch );
3559
            GetLoanLength( $borrower->{'categorycode'}, $itemtype, $branch, $onsite_checkout );
3555
3560
3556
    my $length_key = ( $isrenewal and defined $loanlength->{renewalperiod} )
3561
    my $length_key = ( $isrenewal and defined $loanlength->{renewalperiod} )
3557
            ? qq{renewalperiod}
3562
            ? qq{renewalperiod}
Lines 3605-3611 sub CalcDateDue { Link Here
3605
3610
3606
    # if Hard Due Dates are used, retrieve them and apply as necessary
3611
    # if Hard Due Dates are used, retrieve them and apply as necessary
3607
    my ( $hardduedate, $hardduedatecompare ) =
3612
    my ( $hardduedate, $hardduedatecompare ) =
3608
      GetHardDueDate( $borrower->{'categorycode'}, $itemtype, $branch );
3613
      GetHardDueDate( $borrower->{'categorycode'}, $itemtype, $branch, $onsite_checkout );
3609
    if ($hardduedate) {    # hardduedates are currently dates
3614
    if ($hardduedate) {    # hardduedates are currently dates
3610
        $hardduedate->truncate( to => 'minute' );
3615
        $hardduedate->truncate( to => 'minute' );
3611
        $hardduedate->set_hour(23);
3616
        $hardduedate->set_hour(23);
Lines 4207-4213 sub _CalculateAndUpdateFine { Link Here
4207
    my $date_returned = $return_date ? $return_date : dt_from_string();
4212
    my $date_returned = $return_date ? $return_date : dt_from_string();
4208
4213
4209
    my ( $amount, $unitcounttotal, $unitcount  ) =
4214
    my ( $amount, $unitcounttotal, $unitcount  ) =
4210
      C4::Overdues::CalcFine( $item, $borrower->{categorycode}, $control_branchcode, $datedue, $date_returned );
4215
      C4::Overdues::CalcFine( $item, $borrower->{categorycode}, $control_branchcode, $issue->{onsite_checkout}, $datedue, $date_returned );
4211
4216
4212
    if ( C4::Context->preference('finesMode') eq 'production' ) {
4217
    if ( C4::Context->preference('finesMode') eq 'production' ) {
4213
        if ( $amount > 0 ) {
4218
        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, $onsite_checkout, $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
            onsite_checkout => $onsite_checkout,
238
            rules => [
239
            rules => [
239
                'lengthunit',
240
                'lengthunit',
240
                'firstremind',
241
                'firstremind',
(-)a/misc/cronjobs/fines.pl (-1 / +1 lines)
Lines 145-151 for my $overdue ( @{$overdues} ) { Link Here
145
145
146
    my ( $amount, $unitcounttotal, $unitcount ) =
146
    my ( $amount, $unitcounttotal, $unitcount ) =
147
      CalcFine( $overdue, $patron->categorycode,
147
      CalcFine( $overdue, $patron->categorycode,
148
        $branchcode, $datedue, $today );
148
        $branchcode, $overdue->{onsite_checkout}, $datedue, $today );
149
149
150
    # Don't update the fine if today is a holiday.
150
    # Don't update the fine if today is a holiday.
151
    # This ensures that dropbox mode will remove the correct amount of fine.
151
    # This ensures that dropbox mode will remove the correct amount of fine.
(-)a/misc/cronjobs/staticfines.pl (+1 lines)
Lines 193-198 for ( my $i = 0 ; $i < scalar(@$data) ; $i++ ) { Link Here
193
        $data->[$i],
193
        $data->[$i],
194
        $patron->categorycode,
194
        $patron->categorycode,
195
        $branchcode,
195
        $branchcode,
196
        $data->[$i]->{onsite_checkout},
196
        $datedue,
197
        $datedue,
197
        $today,
198
        $today,
198
    );
199
    );
(-)a/t/db_dependent/Circulation.t (-5 / +5 lines)
Lines 558-564 subtest "CanBookBeRenewed tests" => sub { Link Here
558
    my $passeddatedue1 = AddIssue($renewing_borrower, $item_7->barcode, $five_weeks_ago);
558
    my $passeddatedue1 = AddIssue($renewing_borrower, $item_7->barcode, $five_weeks_ago);
559
    is (defined $passeddatedue1, 1, "Item with passed date due checked out, due date: " . $passeddatedue1->date_due);
559
    is (defined $passeddatedue1, 1, "Item with passed date due checked out, due date: " . $passeddatedue1->date_due);
560
560
561
    my ( $fine ) = CalcFine( $item_7->unblessed, $renewing_borrower->{categorycode}, $branch, $five_weeks_ago, $now );
561
    my ( $fine ) = CalcFine( $item_7->unblessed, $renewing_borrower->{categorycode}, $branch, undef, $five_weeks_ago, $now );
562
    C4::Overdues::UpdateFine(
562
    C4::Overdues::UpdateFine(
563
        {
563
        {
564
            issue_id       => $passeddatedue1->id(),
564
            issue_id       => $passeddatedue1->id(),
Lines 2466-2472 subtest 'AddReturn | is_overdue' => sub { Link Here
2466
2466
2467
        # Fake fines cronjob on this checkout
2467
        # Fake fines cronjob on this checkout
2468
        my ($fine) =
2468
        my ($fine) =
2469
          CalcFine( $item, $patron->categorycode, $library->{branchcode},
2469
          CalcFine( $item, $patron->categorycode, $library->{branchcode}, undef,
2470
            $ten_days_ago, $now );
2470
            $ten_days_ago, $now );
2471
        UpdateFine(
2471
        UpdateFine(
2472
            {
2472
            {
Lines 2504-2510 subtest 'AddReturn | is_overdue' => sub { Link Here
2504
2504
2505
        # Fake fines cronjob on this checkout
2505
        # Fake fines cronjob on this checkout
2506
        my ($fine) =
2506
        my ($fine) =
2507
          CalcFine( $item, $patron->categorycode, $library->{branchcode},
2507
          CalcFine( $item, $patron->categorycode, $library->{branchcode}, undef,
2508
            $one_day_ago, $now );
2508
            $one_day_ago, $now );
2509
        UpdateFine(
2509
        UpdateFine(
2510
            {
2510
            {
Lines 2529-2535 subtest 'AddReturn | is_overdue' => sub { Link Here
2529
2529
2530
        # Fake fines cronjob on this checkout
2530
        # Fake fines cronjob on this checkout
2531
        ($fine) =
2531
        ($fine) =
2532
          CalcFine( $item, $patron->categorycode, $library->{branchcode},
2532
          CalcFine( $item, $patron->categorycode, $library->{branchcode}, undef,
2533
            $two_days_ago, $now );
2533
            $two_days_ago, $now );
2534
        UpdateFine(
2534
        UpdateFine(
2535
            {
2535
            {
Lines 2596-2602 subtest 'AddReturn | is_overdue' => sub { Link Here
2596
2596
2597
        # Fake fines cronjob on this checkout
2597
        # Fake fines cronjob on this checkout
2598
        my ($fine) =
2598
        my ($fine) =
2599
          CalcFine( $item, $patron->categorycode, $library->{branchcode},
2599
          CalcFine( $item, $patron->categorycode, $library->{branchcode}, undef,
2600
            $one_day_ago, $now );
2600
            $one_day_ago, $now );
2601
        UpdateFine(
2601
        UpdateFine(
2602
            {
2602
            {
(-)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, $onsite_checkout );
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, $onsite_checkout, 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, $onsite_checkout );
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, $onsite_checkout );
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, $onsite_checkout );
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, $onsite_checkout, 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, $onsite_checkout );
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, $onsite_checkout, 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, $onsite_checkout );
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, $onsite_checkout, 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, $onsite_checkout );
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, $onsite_checkout, 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, $onsite_checkout );
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, $onsite_checkout, 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, $onsite_checkout );
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, $onsite_checkout, 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, $onsite_checkout );
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, $onsite_checkout, 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 94-100 subtest 'Test basic functionality' => sub { Link Here
94
        day        => 30,
94
        day        => 30,
95
    );
95
    );
96
96
97
    my ($amount) = CalcFine( $item->unblessed, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
97
    my ($amount) = CalcFine( $item->unblessed, $patron->{categorycode}, $branch->{branchcode}, undef, $start_dt, $end_dt );
98
98
99
    is( $amount, 29, 'Amount is calculated correctly' );
99
    is( $amount, 29, 'Amount is calculated correctly' );
100
100
Lines 143-155 subtest 'Test cap_fine_to_replacement_price' => sub { Link Here
143
        }
143
        }
144
    );
144
    );
145
145
146
    my ($amount) = CalcFine( $item->unblessed, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
146
    my ($amount) = CalcFine( $item->unblessed, $patron->{categorycode}, $branch->{branchcode}, undef, $start_dt, $end_dt );
147
147
148
    is( int($amount), 5, 'Amount is calculated correctly' );
148
    is( int($amount), 5, 'Amount is calculated correctly' );
149
149
150
    # Use default replacement cost (useDefaultReplacementCost) is item's replacement price is 0
150
    # Use default replacement cost (useDefaultReplacementCost) is item's replacement price is 0
151
    $item->replacementprice(0)->store;
151
    $item->replacementprice(0)->store;
152
    ($amount) = CalcFine( $item->unblessed, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
152
    ($amount) = CalcFine( $item->unblessed, $patron->{categorycode}, $branch->{branchcode}, undef, $start_dt, $end_dt );
153
    is( int($amount), 6, 'Amount is calculated correctly' );
153
    is( int($amount), 6, 'Amount is calculated correctly' );
154
154
155
    teardown();
155
    teardown();
Lines 189-199 subtest 'Test cap_fine_to_replacement_pricew with overduefinescap' => sub { Link Here
189
        day        => 30,
189
        day        => 30,
190
    );
190
    );
191
191
192
    my ($amount) = CalcFine( $item->unblessed, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
192
    my ($amount) = CalcFine( $item->unblessed, $patron->{categorycode}, $branch->{branchcode}, undef, $start_dt, $end_dt );
193
    is( int($amount), 3, 'Got the lesser of overduefinescap and replacement price where overduefinescap < replacement price' );
193
    is( int($amount), 3, 'Got the lesser of overduefinescap and replacement price where overduefinescap < replacement price' );
194
194
195
    Koha::CirculationRules->set_rule({ rule_name => 'overduefinescap', rule_value => 6, branchcode => undef, onsite_checkout => undef, categorycode => undef, itemtype => undef });
195
    Koha::CirculationRules->set_rule({ rule_name => 'overduefinescap', rule_value => 6, branchcode => undef, onsite_checkout => undef, categorycode => undef, itemtype => undef });
196
    ($amount) = CalcFine( $item->unblessed, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
196
    ($amount) = CalcFine( $item->unblessed, $patron->{categorycode}, $branch->{branchcode}, undef, $start_dt, $end_dt );
197
    is( int($amount), 5, 'Get the lesser of overduefinescap and replacement price where overduefinescap > replacement price' );
197
    is( int($amount), 5, 'Get the lesser of overduefinescap and replacement price where overduefinescap > replacement price' );
198
198
199
    teardown();
199
    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 241-247 Koha::CirculationRules->set_rules( $sampleissuingrule3_holds ); Link Here
241
is_deeply(
241
is_deeply(
242
    C4::Circulation::GetLoanLength(
242
    C4::Circulation::GetLoanLength(
243
        $samplecat->{categorycode},
243
        $samplecat->{categorycode},
244
        $sampleitemtype1, $samplebranch1->{branchcode}
244
        $sampleitemtype1, $samplebranch1->{branchcode}, 0
245
    ),
245
    ),
246
    { issuelength => 5, lengthunit => 'days', renewalperiod => 5 },
246
    { issuelength => 5, lengthunit => 'days', renewalperiod => 5 },
247
    "GetLoanLength"
247
    "GetLoanLength"
Lines 269-274 is_deeply( Link Here
269
);    #NOTE : is that really what is expected?
269
);    #NOTE : is that really what is expected?
270
is_deeply(
270
is_deeply(
271
    C4::Circulation::GetLoanLength( $samplecat->{categorycode}, $sampleitemtype1, $samplebranch1->{branchcode} ),
271
    C4::Circulation::GetLoanLength( $samplecat->{categorycode}, $sampleitemtype1, $samplebranch1->{branchcode} ),
272
    $default,
273
    "With only three parameters, GetLoanLength returns hardcoded values"
274
);    #NOTE : is that really what is expected?
275
is_deeply(
276
    C4::Circulation::GetLoanLength( $samplecat->{categorycode}, $sampleitemtype1, $samplebranch1->{branchcode}, 0 ),
272
    {
277
    {
273
        issuelength   => 5,
278
        issuelength   => 5,
274
        renewalperiod => 5,
279
        renewalperiod => 5,
Lines 279-285 is_deeply( Link Here
279
284
280
#Test GetHardDueDate
285
#Test GetHardDueDate
281
my @hardduedate = C4::Circulation::GetHardDueDate( $samplecat->{categorycode},
286
my @hardduedate = C4::Circulation::GetHardDueDate( $samplecat->{categorycode},
282
    $sampleitemtype1, $samplebranch1->{branchcode} );
287
    $sampleitemtype1, $samplebranch1->{branchcode}, 0 );
283
is_deeply(
288
is_deeply(
284
    \@hardduedate,
289
    \@hardduedate,
285
    [
290
    [
(-)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 26814