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

(-)a/C4/Circulation.pm (-13 / +19 lines)
Lines 754-760 sub CanBookBeIssued { Link Here
754
    unless ( $duedate ) {
754
    unless ( $duedate ) {
755
        my $issuedate = $now->clone();
755
        my $issuedate = $now->clone();
756
756
757
        $duedate = CalcDateDue( $issuedate, $effective_itemtype, $circ_library->branchcode, $patron_unblessed );
757
        $duedate = CalcDateDue( $issuedate, $effective_itemtype, $circ_library->branchcode, $patron_unblessed, $onsite_checkout );
758
758
759
        # Offline circ calls AddIssue directly, doesn't run through here
759
        # Offline circ calls AddIssue directly, doesn't run through here
760
        #  So issuingimpossible should be ok.
760
        #  So issuingimpossible should be ok.
Lines 1317-1323 sub checkHighHolds { Link Here
1317
        );
1317
        );
1318
        my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode );
1318
        my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode );
1319
1319
1320
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1320
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $borrower, undef, );
1321
1321
1322
        my $rule = Koha::CirculationRules->get_effective_rule(
1322
        my $rule = Koha::CirculationRules->get_effective_rule(
1323
            {
1323
            {
Lines 1440-1446 sub AddIssue { Link Here
1440
        else {
1440
        else {
1441
            unless ($datedue) {
1441
            unless ($datedue) {
1442
                my $itype = $item_object->effective_itemtype;
1442
                my $itype = $item_object->effective_itemtype;
1443
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1443
                $datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower, $onsite_checkout );
1444
1444
1445
            }
1445
            }
1446
            $datedue->truncate( to => 'minute' );
1446
            $datedue->truncate( to => 'minute' );
Lines 1654-1667 sub AddIssue { Link Here
1654
1654
1655
=head2 GetLoanLength
1655
=head2 GetLoanLength
1656
1656
1657
  my $loanlength = &GetLoanLength($borrowertype,$itemtype,branchcode)
1657
  my $loanlength = &GetLoanLength($borrowertype,$itemtype,branchcode,$onsite_checkout)
1658
1658
1659
Get loan length for an itemtype, a borrower type and a branch
1659
Get loan length for an itemtype, a borrower type and a branch
1660
1660
1661
=cut
1661
=cut
1662
1662
1663
sub GetLoanLength {
1663
sub GetLoanLength {
1664
    my ( $categorycode, $itemtype, $branchcode ) = @_;
1664
    my ( $categorycode, $itemtype, $branchcode, $onsite_checkout ) = @_;
1665
1665
1666
    # Initialize default values
1666
    # Initialize default values
1667
    my $rules = {
1667
    my $rules = {
Lines 1674-1679 sub GetLoanLength { Link Here
1674
        branchcode => $branchcode,
1674
        branchcode => $branchcode,
1675
        categorycode => $categorycode,
1675
        categorycode => $categorycode,
1676
        itemtype => $itemtype,
1676
        itemtype => $itemtype,
1677
        onsite_checkout => $onsite_checkout,
1677
        rules => [
1678
        rules => [
1678
            'issuelength',
1679
            'issuelength',
1679
            'renewalperiod',
1680
            'renewalperiod',
Lines 1692-1711 sub GetLoanLength { Link Here
1692
1693
1693
=head2 GetHardDueDate
1694
=head2 GetHardDueDate
1694
1695
1695
  my ($hardduedate,$hardduedatecompare) = &GetHardDueDate($borrowertype,$itemtype,branchcode)
1696
  my ($hardduedate,$hardduedatecompare) = &GetHardDueDate($borrowertype,$itemtype,branchcode,$onsite_checkout)
1696
1697
1697
Get the Hard Due Date and it's comparison for an itemtype, a borrower type and a branch
1698
Get the Hard Due Date and it's comparison for an itemtype, a borrower type and a branch
1698
1699
1699
=cut
1700
=cut
1700
1701
1701
sub GetHardDueDate {
1702
sub GetHardDueDate {
1702
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1703
    my ( $borrowertype, $itemtype, $branchcode, $onsite_checkout ) = @_;
1703
1704
1704
    my $rules = Koha::CirculationRules->get_effective_rules(
1705
    my $rules = Koha::CirculationRules->get_effective_rules(
1705
        {
1706
        {
1706
            categorycode => $borrowertype,
1707
            categorycode => $borrowertype,
1707
            itemtype     => $itemtype,
1708
            itemtype     => $itemtype,
1708
            branchcode   => $branchcode,
1709
            branchcode   => $branchcode,
1710
            onsite_checkout => $onsite_checkout,
1709
            rules        => [ 'hardduedate', 'hardduedatecompare' ],
1711
            rules        => [ 'hardduedate', 'hardduedatecompare' ],
1710
        }
1712
        }
1711
    );
1713
    );
Lines 2753-2758 sub CanBookBeRenewed { Link Here
2753
                categorycode => $patron->categorycode,
2755
                categorycode => $patron->categorycode,
2754
                itemtype     => $item->effective_itemtype,
2756
                itemtype     => $item->effective_itemtype,
2755
                branchcode   => $branchcode,
2757
                branchcode   => $branchcode,
2758
                onsite_checkout => $issue->onsite_checkout,
2756
                rules => [
2759
                rules => [
2757
                    'renewalsallowed',
2760
                    'renewalsallowed',
2758
                    'no_auto_renewal_after',
2761
                    'no_auto_renewal_after',
Lines 3029-3035 sub AddRenewal { Link Here
3029
            $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
3032
            $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
3030
                                            dt_from_string( $issue->date_due, 'sql' ) :
3033
                                            dt_from_string( $issue->date_due, 'sql' ) :
3031
                                            dt_from_string();
3034
                                            dt_from_string();
3032
            $datedue =  CalcDateDue($datedue, $itemtype, $circ_library->branchcode, $patron_unblessed, 'is a renewal');
3035
            $datedue =  CalcDateDue($datedue, $itemtype, $circ_library->branchcode, $patron_unblessed, $issue->onsite_checkout, 'is a renewal');
3033
        }
3036
        }
3034
3037
3035
        my $fees = Koha::Charges::Fees->new(
3038
        my $fees = Koha::Charges::Fees->new(
Lines 3250-3255 sub GetSoonestRenewDate { Link Here
3250
        {   categorycode => $patron->categorycode,
3253
        {   categorycode => $patron->categorycode,
3251
            itemtype     => $item->effective_itemtype,
3254
            itemtype     => $item->effective_itemtype,
3252
            branchcode   => $branchcode,
3255
            branchcode   => $branchcode,
3256
            onsite_checkout => $itemissue->onsite_checkout,
3253
            rules => [
3257
            rules => [
3254
                'norenewalbefore',
3258
                'norenewalbefore',
3255
                'lengthunit',
3259
                'lengthunit',
Lines 3314-3319 sub GetLatestAutoRenewDate { Link Here
3314
            categorycode => $patron->categorycode,
3318
            categorycode => $patron->categorycode,
3315
            itemtype     => $item->effective_itemtype,
3319
            itemtype     => $item->effective_itemtype,
3316
            branchcode   => $branchcode,
3320
            branchcode   => $branchcode,
3321
            onsite_checkout => $itemissue->onsite_checkout,
3317
            rules => [
3322
            rules => [
3318
                'no_auto_renewal_after',
3323
                'no_auto_renewal_after',
3319
                'no_auto_renewal_after_hard_limit',
3324
                'no_auto_renewal_after_hard_limit',
Lines 3664-3670 sub updateWrongTransfer { Link Here
3664
3669
3665
=head2 CalcDateDue
3670
=head2 CalcDateDue
3666
3671
3667
$newdatedue = CalcDateDue($startdate,$itemtype,$branchcode,$borrower);
3672
$newdatedue = CalcDateDue($startdate,$itemtype,$branchcode,$borrower,$onsite_checkout);
3668
3673
3669
this function calculates the due date given the start date and configured circulation rules,
3674
this function calculates the due date given the start date and configured circulation rules,
3670
checking against the holidays calendar as per the daysmode circulation rule.
3675
checking against the holidays calendar as per the daysmode circulation rule.
Lines 3677-3689 C<$isrenewal> = Boolean: is true if we want to calculate the date due for a rene Link Here
3677
=cut
3682
=cut
3678
3683
3679
sub CalcDateDue {
3684
sub CalcDateDue {
3680
    my ( $startdate, $itemtype, $branch, $borrower, $isrenewal ) = @_;
3685
    my ( $startdate, $itemtype, $branch, $borrower, $onsite_checkout, $isrenewal ) = @_;
3681
3686
3682
    $isrenewal ||= 0;
3687
    $isrenewal ||= 0;
3683
3688
3684
    # loanlength now a href
3689
    # loanlength now a href
3685
    my $loanlength =
3690
    my $loanlength =
3686
            GetLoanLength( $borrower->{'categorycode'}, $itemtype, $branch );
3691
            GetLoanLength( $borrower->{'categorycode'}, $itemtype, $branch, $onsite_checkout );
3687
3692
3688
    my $length_key = ( $isrenewal and defined $loanlength->{renewalperiod} )
3693
    my $length_key = ( $isrenewal and defined $loanlength->{renewalperiod} )
3689
            ? qq{renewalperiod}
3694
            ? qq{renewalperiod}
Lines 3706-3711 sub CalcDateDue { Link Here
3706
            categorycode => $borrower->{categorycode},
3711
            categorycode => $borrower->{categorycode},
3707
            itemtype     => $itemtype,
3712
            itemtype     => $itemtype,
3708
            branchcode   => $branch,
3713
            branchcode   => $branch,
3714
            onsite_checkout => $onsite_checkout,
3709
        }
3715
        }
3710
    );
3716
    );
3711
3717
Lines 3737-3743 sub CalcDateDue { Link Here
3737
3743
3738
    # if Hard Due Dates are used, retrieve them and apply as necessary
3744
    # if Hard Due Dates are used, retrieve them and apply as necessary
3739
    my ( $hardduedate, $hardduedatecompare ) =
3745
    my ( $hardduedate, $hardduedatecompare ) =
3740
      GetHardDueDate( $borrower->{'categorycode'}, $itemtype, $branch );
3746
      GetHardDueDate( $borrower->{'categorycode'}, $itemtype, $branch, $onsite_checkout );
3741
    if ($hardduedate) {    # hardduedates are currently dates
3747
    if ($hardduedate) {    # hardduedates are currently dates
3742
        $hardduedate->truncate( to => 'minute' );
3748
        $hardduedate->truncate( to => 'minute' );
3743
        $hardduedate->set_hour(23);
3749
        $hardduedate->set_hour(23);
Lines 4339-4345 sub _CalculateAndUpdateFine { Link Here
4339
    my $date_returned = $return_date ? $return_date : dt_from_string();
4345
    my $date_returned = $return_date ? $return_date : dt_from_string();
4340
4346
4341
    my ( $amount, $unitcounttotal, $unitcount  ) =
4347
    my ( $amount, $unitcounttotal, $unitcount  ) =
4342
      C4::Overdues::CalcFine( $item, $borrower->{categorycode}, $control_branchcode, $datedue, $date_returned );
4348
      C4::Overdues::CalcFine( $item, $borrower->{categorycode}, $control_branchcode, $issue->onsite_checkout, $datedue, $date_returned );
4343
4349
4344
    if ( C4::Context->preference('finesMode') eq 'production' ) {
4350
    if ( C4::Context->preference('finesMode') eq 'production' ) {
4345
        if ( $amount > 0 ) {
4351
        if ( $amount > 0 ) {
(-)a/C4/Overdues.pm (-2 / +5 lines)
Lines 183-189 sub checkoverdues { Link Here
183
=head2 CalcFine
183
=head2 CalcFine
184
184
185
    ($amount, $units_minus_grace, $chargeable_units) = &CalcFine($item,
185
    ($amount, $units_minus_grace, $chargeable_units) = &CalcFine($item,
186
                                  $categorycode, $branch,
186
                                  $categorycode, $branch, $onsite_checkout,
187
                                  $start_dt, $end_dt );
187
                                  $start_dt, $end_dt );
188
188
189
Calculates the fine for a book.
189
Calculates the fine for a book.
Lines 202-207 the book. Link Here
202
202
203
C<$branchcode> is the library (string) whose issuingrules govern this transaction.
203
C<$branchcode> is the library (string) whose issuingrules govern this transaction.
204
204
205
C<$onsite_checkout> boolean value on checkout being onsite checkout.
206
205
C<$start_date> & C<$end_date> are DateTime objects
207
C<$start_date> & C<$end_date> are DateTime objects
206
defining the date range over which to determine the fine.
208
defining the date range over which to determine the fine.
207
209
Lines 222-228 or "Final Notice". But CalcFine never defined any value. Link Here
222
=cut
224
=cut
223
225
224
sub CalcFine {
226
sub CalcFine {
225
    my ( $item, $bortype, $branchcode, $due_dt, $end_date  ) = @_;
227
    my ( $item, $bortype, $branchcode, $onsite_checkout, $due_dt, $end_date  ) = @_;
226
228
227
    # Skip calculations if item is not overdue
229
    # Skip calculations if item is not overdue
228
    return ( 0, 0, 0 ) unless (DateTime->compare( $due_dt, $end_date ) == -1);
230
    return ( 0, 0, 0 ) unless (DateTime->compare( $due_dt, $end_date ) == -1);
Lines 235-240 sub CalcFine { Link Here
235
            categorycode => $bortype,
237
            categorycode => $bortype,
236
            itemtype     => $itemtype,
238
            itemtype     => $itemtype,
237
            branchcode   => $branchcode,
239
            branchcode   => $branchcode,
240
            onsite_checkout => $onsite_checkout,
238
            rules => [
241
            rules => [
239
                'lengthunit',
242
                'lengthunit',
240
                'firstremind',
243
                'firstremind',
(-)a/installer/data/mysql/fix_unclosed_nonaccruing_fines_bug17135.pl (-1 / +2 lines)
Lines 157-164 sub Bug_17135_fix { Link Here
157
             ( $control eq 'ItemHomeLibrary' ) ? $overdue->{homebranch}
157
             ( $control eq 'ItemHomeLibrary' ) ? $overdue->{homebranch}
158
             : ( $control eq 'PatronLibrary' )   ? $patron->branchcode
158
             : ( $control eq 'PatronLibrary' )   ? $patron->branchcode
159
             :                                     $overdue->{branchcode};
159
             :                                     $overdue->{branchcode};
160
            my $onsite_checkout = $overdue->{onsite_checkout};
160
161
161
            my ($amount) = CalcFine( $overdue, $patron->categorycode, $branchcode, $datedue, $today );
162
            my ($amount) = CalcFine( $overdue, $patron->categorycode, $branchcode, $onsite_checkout, $datedue, $today );
162
            ### Warn("CalcFine() returned '$amount'");
163
            ### Warn("CalcFine() returned '$amount'");
163
            last if ($amount > 0); ## accruing fine, skip closing
164
            last if ($amount > 0); ## accruing fine, skip closing
164
165
(-)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 (-9 / +9 lines)
Lines 564-570 subtest "CanBookBeRenewed tests" => sub { Link Here
564
    my $passeddatedue1 = AddIssue($renewing_borrower, $item_7->barcode, $five_weeks_ago);
564
    my $passeddatedue1 = AddIssue($renewing_borrower, $item_7->barcode, $five_weeks_ago);
565
    is (defined $passeddatedue1, 1, "Item with passed date due checked out, due date: " . $passeddatedue1->date_due);
565
    is (defined $passeddatedue1, 1, "Item with passed date due checked out, due date: " . $passeddatedue1->date_due);
566
566
567
    my ( $fine ) = CalcFine( $item_7->unblessed, $renewing_borrower->{categorycode}, $branch, $five_weeks_ago, $now );
567
    my ( $fine ) = CalcFine( $item_7->unblessed, $renewing_borrower->{categorycode}, $branch, undef, $five_weeks_ago, $now );
568
    C4::Overdues::UpdateFine(
568
    C4::Overdues::UpdateFine(
569
        {
569
        {
570
            issue_id       => $passeddatedue1->id(),
570
            issue_id       => $passeddatedue1->id(),
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
            $ten_days_ago, $now );
2541
            $ten_days_ago, $now );
2542
        UpdateFine(
2542
        UpdateFine(
2543
            {
2543
            {
Lines 2575-2581 subtest 'AddReturn | is_overdue' => sub { Link Here
2575
2575
2576
        # Fake fines cronjob on this checkout
2576
        # Fake fines cronjob on this checkout
2577
        my ($fine) =
2577
        my ($fine) =
2578
          CalcFine( $item, $patron->categorycode, $library->{branchcode},
2578
          CalcFine( $item, $patron->categorycode, $library->{branchcode}, undef,
2579
            $one_day_ago, $now );
2579
            $one_day_ago, $now );
2580
        UpdateFine(
2580
        UpdateFine(
2581
            {
2581
            {
Lines 2600-2606 subtest 'AddReturn | is_overdue' => sub { Link Here
2600
2600
2601
        # Fake fines cronjob on this checkout
2601
        # Fake fines cronjob on this checkout
2602
        ($fine) =
2602
        ($fine) =
2603
          CalcFine( $item, $patron->categorycode, $library->{branchcode},
2603
          CalcFine( $item, $patron->categorycode, $library->{branchcode}, undef,
2604
            $two_days_ago, $now );
2604
            $two_days_ago, $now );
2605
        UpdateFine(
2605
        UpdateFine(
2606
            {
2606
            {
Lines 2667-2673 subtest 'AddReturn | is_overdue' => sub { Link Here
2667
2667
2668
        # Fake fines cronjob on this checkout
2668
        # Fake fines cronjob on this checkout
2669
        my ($fine) =
2669
        my ($fine) =
2670
          CalcFine( $item, $patron->categorycode, $library->{branchcode},
2670
          CalcFine( $item, $patron->categorycode, $library->{branchcode}, undef,
2671
            $one_day_ago, $now );
2671
            $one_day_ago, $now );
2672
        UpdateFine(
2672
        UpdateFine(
2673
            {
2673
            {
Lines 2870-2876 subtest 'AddReturn | is_overdue' => sub { Link Here
2870
2870
2871
            # Fake fines cronjob on this checkout
2871
            # Fake fines cronjob on this checkout
2872
            my ($fine) =
2872
            my ($fine) =
2873
              CalcFine( $item, $patron->categorycode, $library->{branchcode},
2873
              CalcFine( $item, $patron->categorycode, $library->{branchcode}, $issue->onsite_checkout,
2874
                $ten_days_ago, $now );
2874
                $ten_days_ago, $now );
2875
            UpdateFine(
2875
            UpdateFine(
2876
                {
2876
                {
Lines 2953-2959 subtest 'AddReturn | is_overdue' => sub { Link Here
2953
2953
2954
            # Fake fines cronjob on this checkout
2954
            # Fake fines cronjob on this checkout
2955
            my ($fine) =
2955
            my ($fine) =
2956
              CalcFine( $item, $patron->categorycode, $library->{branchcode},
2956
              CalcFine( $item, $patron->categorycode, $library->{branchcode}, $issue->onsite_checkout,
2957
                $ten_days_ago, $now );
2957
                $ten_days_ago, $now );
2958
            UpdateFine(
2958
            UpdateFine(
2959
                {
2959
                {
Lines 3035-3041 subtest 'AddReturn | is_overdue' => sub { Link Here
3035
3035
3036
            # Fake fines cronjob on this checkout
3036
            # Fake fines cronjob on this checkout
3037
            my ($fine) =
3037
            my ($fine) =
3038
              CalcFine( $item, $patron->categorycode, $library->{branchcode},
3038
              CalcFine( $item, $patron->categorycode, $library->{branchcode}, $issue->onsite_checkout,
3039
                $ten_days_ago, $now );
3039
                $ten_days_ago, $now );
3040
            UpdateFine(
3040
            UpdateFine(
3041
                {
3041
                {
Lines 3133-3139 subtest 'AddReturn | is_overdue' => sub { Link Here
3133
3133
3134
            # Fake fines cronjob on this checkout
3134
            # Fake fines cronjob on this checkout
3135
            my ($fine) =
3135
            my ($fine) =
3136
              CalcFine( $item, $patron->categorycode, $library->{branchcode},
3136
              CalcFine( $item, $patron->categorycode, $library->{branchcode}, $issue->onsite_checkout,
3137
                $ten_days_ago, $now );
3137
                $ten_days_ago, $now );
3138
            UpdateFine(
3138
            UpdateFine(
3139
                {
3139
                {
(-)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