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

(-)a/C4/Circulation.pm (-14 / +19 lines)
Lines 753-759 sub CanBookBeIssued { Link Here
753
    unless ( $duedate ) {
753
    unless ( $duedate ) {
754
        my $issuedate = $now->clone();
754
        my $issuedate = $now->clone();
755
755
756
        $duedate = CalcDateDue( $issuedate, $effective_itemtype, $circ_library->branchcode, $patron_unblessed );
756
        $duedate = CalcDateDue( $issuedate, $effective_itemtype, $circ_library->branchcode, $patron_unblessed, $onsite_checkout );
757
757
758
        # Offline circ calls AddIssue directly, doesn't run through here
758
        # Offline circ calls AddIssue directly, doesn't run through here
759
        #  So issuingimpossible should be ok.
759
        #  So issuingimpossible should be ok.
Lines 1316-1322 sub checkHighHolds { Link Here
1316
        );
1316
        );
1317
        my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode );
1317
        my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode );
1318
1318
1319
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1319
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $borrower, 0 );
1320
1320
1321
        my $decreaseLoanHighHoldsDuration = C4::Context->preference('decreaseLoanHighHoldsDuration');
1321
        my $decreaseLoanHighHoldsDuration = C4::Context->preference('decreaseLoanHighHoldsDuration');
1322
1322
Lines 1425-1431 sub AddIssue { Link Here
1425
        else {
1425
        else {
1426
            unless ($datedue) {
1426
            unless ($datedue) {
1427
                my $itype = $item_object->effective_itemtype;
1427
                my $itype = $item_object->effective_itemtype;
1428
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1428
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower, $onsite_checkout );
1429
1429
1430
            }
1430
            }
1431
            $datedue->truncate( to => 'minute' );
1431
            $datedue->truncate( to => 'minute' );
Lines 1490-1496 sub AddIssue { Link Here
1490
            # Record in the database the fact that the book was issued.
1490
            # Record in the database the fact that the book was issued.
1491
            unless ($datedue) {
1491
            unless ($datedue) {
1492
                my $itype = $item_object->effective_itemtype;
1492
                my $itype = $item_object->effective_itemtype;
1493
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1493
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower, $onsite_checkout );
1494
1494
1495
            }
1495
            }
1496
            $datedue->truncate( to => 'minute' );
1496
            $datedue->truncate( to => 'minute' );
Lines 1603-1616 sub AddIssue { Link Here
1603
1603
1604
=head2 GetLoanLength
1604
=head2 GetLoanLength
1605
1605
1606
  my $loanlength = &GetLoanLength($borrowertype,$itemtype,branchcode)
1606
  my $loanlength = &GetLoanLength($borrowertype,$itemtype,branchcode,$onsite_checkout)
1607
1607
1608
Get loan length for an itemtype, a borrower type and a branch
1608
Get loan length for an itemtype, a borrower type and a branch
1609
1609
1610
=cut
1610
=cut
1611
1611
1612
sub GetLoanLength {
1612
sub GetLoanLength {
1613
    my ( $categorycode, $itemtype, $branchcode ) = @_;
1613
    my ( $categorycode, $itemtype, $branchcode, $onsite_checkout ) = @_;
1614
1614
1615
    # Initialize default values
1615
    # Initialize default values
1616
    my $rules = {
1616
    my $rules = {
Lines 1623-1628 sub GetLoanLength { Link Here
1623
        branchcode => $branchcode,
1623
        branchcode => $branchcode,
1624
        categorycode => $categorycode,
1624
        categorycode => $categorycode,
1625
        itemtype => $itemtype,
1625
        itemtype => $itemtype,
1626
        onsite_checkout => $onsite_checkout,
1626
        rules => [
1627
        rules => [
1627
            'issuelength',
1628
            'issuelength',
1628
            'renewalperiod',
1629
            'renewalperiod',
Lines 1641-1660 sub GetLoanLength { Link Here
1641
1642
1642
=head2 GetHardDueDate
1643
=head2 GetHardDueDate
1643
1644
1644
  my ($hardduedate,$hardduedatecompare) = &GetHardDueDate($borrowertype,$itemtype,branchcode)
1645
  my ($hardduedate,$hardduedatecompare) = &GetHardDueDate($borrowertype,$itemtype,branchcode,$onsite_checkout)
1645
1646
1646
Get the Hard Due Date and it's comparison for an itemtype, a borrower type and a branch
1647
Get the Hard Due Date and it's comparison for an itemtype, a borrower type and a branch
1647
1648
1648
=cut
1649
=cut
1649
1650
1650
sub GetHardDueDate {
1651
sub GetHardDueDate {
1651
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1652
    my ( $borrowertype, $itemtype, $branchcode, $onsite_checkout ) = @_;
1652
1653
1653
    my $rules = Koha::CirculationRules->get_effective_rules(
1654
    my $rules = Koha::CirculationRules->get_effective_rules(
1654
        {
1655
        {
1655
            categorycode => $borrowertype,
1656
            categorycode => $borrowertype,
1656
            itemtype     => $itemtype,
1657
            itemtype     => $itemtype,
1657
            branchcode   => $branchcode,
1658
            branchcode   => $branchcode,
1659
            onsite_checkout => $onsite_checkout,
1658
            rules        => [ 'hardduedate', 'hardduedatecompare' ],
1660
            rules        => [ 'hardduedate', 'hardduedatecompare' ],
1659
        }
1661
        }
1660
    );
1662
    );
Lines 2681-2686 sub CanBookBeRenewed { Link Here
2681
                categorycode => $patron->categorycode,
2683
                categorycode => $patron->categorycode,
2682
                itemtype     => $item->effective_itemtype,
2684
                itemtype     => $item->effective_itemtype,
2683
                branchcode   => $branchcode,
2685
                branchcode   => $branchcode,
2686
                onsite_checkout => $issue->onsite_checkout,
2684
                rules => [
2687
                rules => [
2685
                    'renewalsallowed',
2688
                    'renewalsallowed',
2686
                    'no_auto_renewal_after',
2689
                    'no_auto_renewal_after',
Lines 2943-2949 sub AddRenewal { Link Here
2943
            $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2946
            $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2944
                                            dt_from_string( $issue->date_due, 'sql' ) :
2947
                                            dt_from_string( $issue->date_due, 'sql' ) :
2945
                                            dt_from_string();
2948
                                            dt_from_string();
2946
            $datedue =  CalcDateDue($datedue, $itemtype, $circ_library->branchcode, $patron_unblessed, 'is a renewal');
2949
            $datedue =  CalcDateDue($datedue, $itemtype, $circ_library->branchcode, $patron_unblessed, $issue->onsite_checkout, 'is a renewal');
2947
        }
2950
        }
2948
2951
2949
        my $fees = Koha::Charges::Fees->new(
2952
        my $fees = Koha::Charges::Fees->new(
Lines 3128-3133 sub GetSoonestRenewDate { Link Here
3128
        {   categorycode => $patron->categorycode,
3131
        {   categorycode => $patron->categorycode,
3129
            itemtype     => $item->effective_itemtype,
3132
            itemtype     => $item->effective_itemtype,
3130
            branchcode   => $branchcode,
3133
            branchcode   => $branchcode,
3134
            onsite_checkout => $itemissue->onsite_checkout,
3131
            rules => [
3135
            rules => [
3132
                'norenewalbefore',
3136
                'norenewalbefore',
3133
                'lengthunit',
3137
                'lengthunit',
Lines 3192-3197 sub GetLatestAutoRenewDate { Link Here
3192
            categorycode => $patron->categorycode,
3196
            categorycode => $patron->categorycode,
3193
            itemtype     => $item->effective_itemtype,
3197
            itemtype     => $item->effective_itemtype,
3194
            branchcode   => $branchcode,
3198
            branchcode   => $branchcode,
3199
            onsite_checkout => $itemissue->onsite_checkout,
3195
            rules => [
3200
            rules => [
3196
                'no_auto_renewal_after',
3201
                'no_auto_renewal_after',
3197
                'no_auto_renewal_after_hard_limit',
3202
                'no_auto_renewal_after_hard_limit',
Lines 3542-3548 sub updateWrongTransfer { Link Here
3542
3547
3543
=head2 CalcDateDue
3548
=head2 CalcDateDue
3544
3549
3545
$newdatedue = CalcDateDue($startdate,$itemtype,$branchcode,$borrower);
3550
$newdatedue = CalcDateDue($startdate,$itemtype,$branchcode,$borrower,$onsite_checkout);
3546
3551
3547
this function calculates the due date given the start date and configured circulation rules,
3552
this function calculates the due date given the start date and configured circulation rules,
3548
checking against the holidays calendar as per the daysmode circulation rule.
3553
checking against the holidays calendar as per the daysmode circulation rule.
Lines 3555-3567 C<$isrenewal> = Boolean: is true if we want to calculate the date due for a rene Link Here
3555
=cut
3560
=cut
3556
3561
3557
sub CalcDateDue {
3562
sub CalcDateDue {
3558
    my ( $startdate, $itemtype, $branch, $borrower, $isrenewal ) = @_;
3563
    my ( $startdate, $itemtype, $branch, $borrower, $onsite_checkout, $isrenewal ) = @_;
3559
3564
3560
    $isrenewal ||= 0;
3565
    $isrenewal ||= 0;
3561
3566
3562
    # loanlength now a href
3567
    # loanlength now a href
3563
    my $loanlength =
3568
    my $loanlength =
3564
            GetLoanLength( $borrower->{'categorycode'}, $itemtype, $branch );
3569
            GetLoanLength( $borrower->{'categorycode'}, $itemtype, $branch, $onsite_checkout );
3565
3570
3566
    my $length_key = ( $isrenewal and defined $loanlength->{renewalperiod} )
3571
    my $length_key = ( $isrenewal and defined $loanlength->{renewalperiod} )
3567
            ? qq{renewalperiod}
3572
            ? qq{renewalperiod}
Lines 3615-3621 sub CalcDateDue { Link Here
3615
3620
3616
    # if Hard Due Dates are used, retrieve them and apply as necessary
3621
    # if Hard Due Dates are used, retrieve them and apply as necessary
3617
    my ( $hardduedate, $hardduedatecompare ) =
3622
    my ( $hardduedate, $hardduedatecompare ) =
3618
      GetHardDueDate( $borrower->{'categorycode'}, $itemtype, $branch );
3623
      GetHardDueDate( $borrower->{'categorycode'}, $itemtype, $branch, $onsite_checkout );
3619
    if ($hardduedate) {    # hardduedates are currently dates
3624
    if ($hardduedate) {    # hardduedates are currently dates
3620
        $hardduedate->truncate( to => 'minute' );
3625
        $hardduedate->truncate( to => 'minute' );
3621
        $hardduedate->set_hour(23);
3626
        $hardduedate->set_hour(23);
Lines 4217-4223 sub _CalculateAndUpdateFine { Link Here
4217
    my $date_returned = $return_date ? $return_date : dt_from_string();
4222
    my $date_returned = $return_date ? $return_date : dt_from_string();
4218
4223
4219
    my ( $amount, $unitcounttotal, $unitcount  ) =
4224
    my ( $amount, $unitcounttotal, $unitcount  ) =
4220
      C4::Overdues::CalcFine( $item, $borrower->{categorycode}, $control_branchcode, $datedue, $date_returned );
4225
      C4::Overdues::CalcFine( $item, $borrower->{categorycode}, $control_branchcode, $issue->{onsite_checkout}, $datedue, $date_returned );
4221
4226
4222
    if ( C4::Context->preference('finesMode') eq 'production' ) {
4227
    if ( C4::Context->preference('finesMode') eq 'production' ) {
4223
        if ( $amount > 0 ) {
4228
        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 2499-2505 subtest 'AddReturn | is_overdue' => sub { Link Here
2499
2499
2500
        # Fake fines cronjob on this checkout
2500
        # Fake fines cronjob on this checkout
2501
        my ($fine) =
2501
        my ($fine) =
2502
          CalcFine( $item, $patron->categorycode, $library->{branchcode},
2502
          CalcFine( $item, $patron->categorycode, $library->{branchcode}, undef,
2503
            $ten_days_ago, $now );
2503
            $ten_days_ago, $now );
2504
        UpdateFine(
2504
        UpdateFine(
2505
            {
2505
            {
Lines 2537-2543 subtest 'AddReturn | is_overdue' => sub { Link Here
2537
2537
2538
        # Fake fines cronjob on this checkout
2538
        # Fake fines cronjob on this checkout
2539
        my ($fine) =
2539
        my ($fine) =
2540
          CalcFine( $item, $patron->categorycode, $library->{branchcode},
2540
          CalcFine( $item, $patron->categorycode, $library->{branchcode}, undef,
2541
            $one_day_ago, $now );
2541
            $one_day_ago, $now );
2542
        UpdateFine(
2542
        UpdateFine(
2543
            {
2543
            {
Lines 2562-2568 subtest 'AddReturn | is_overdue' => sub { Link Here
2562
2562
2563
        # Fake fines cronjob on this checkout
2563
        # Fake fines cronjob on this checkout
2564
        ($fine) =
2564
        ($fine) =
2565
          CalcFine( $item, $patron->categorycode, $library->{branchcode},
2565
          CalcFine( $item, $patron->categorycode, $library->{branchcode}, undef,
2566
            $two_days_ago, $now );
2566
            $two_days_ago, $now );
2567
        UpdateFine(
2567
        UpdateFine(
2568
            {
2568
            {
Lines 2629-2635 subtest 'AddReturn | is_overdue' => sub { Link Here
2629
2629
2630
        # Fake fines cronjob on this checkout
2630
        # Fake fines cronjob on this checkout
2631
        my ($fine) =
2631
        my ($fine) =
2632
          CalcFine( $item, $patron->categorycode, $library->{branchcode},
2632
          CalcFine( $item, $patron->categorycode, $library->{branchcode}, undef,
2633
            $one_day_ago, $now );
2633
            $one_day_ago, $now );
2634
        UpdateFine(
2634
        UpdateFine(
2635
            {
2635
            {
(-)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