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

(-)a/C4/Circulation.pm (-22 / +23 lines)
Lines 1436-1454 sub AddIssue { Link Here
1436
1436
1437
            ## If item was lost, it has now been found, reverse any list item charges if necessary.
1437
            ## If item was lost, it has now been found, reverse any list item charges if necessary.
1438
            if ( $item_object->itemlost ) {
1438
            if ( $item_object->itemlost ) {
1439
                if (
1439
                    my $should_refund = Koha::RefundLostItemFeeRules->should_refund(
1440
                    Koha::RefundLostItemFeeRules->should_refund(
1441
                        {
1440
                        {
1442
                            current_branch      => C4::Context->userenv->{branch},
1441
                            current_branch   => C4::Context->userenv->{branch},
1443
                            item_home_branch    => $item_object->homebranch,
1442
                            item_home_branch => $item_object->homebranch,
1444
                            item_holding_branch => $item_object->holdingbranch,
1443
                            item_holding_branch => $item_object->holdingbranch,
1445
                        }
1444
                        }
1446
                    )
1445
                    );
1447
                  )
1446
1448
                {
1447
                    if ($should_refund) {
1449
                    _FixAccountForLostAndReturned( $item_object->itemnumber, undef,
1448
                        _FixAccountForLostAndReturned( $item_object->itemnumber,
1450
                        $item_object->barcode );
1449
                            undef , $item_object->barcode, $should_refund eq '2' );
1451
                }
1450
                    }
1452
            }
1451
            }
1453
1452
1454
            ModItem(
1453
            ModItem(
Lines 2008-2025 sub AddReturn { Link Here
2008
    if ( $item->itemlost ) {
2007
    if ( $item->itemlost ) {
2009
        $messages->{'WasLost'} = 1;
2008
        $messages->{'WasLost'} = 1;
2010
        unless ( C4::Context->preference("BlockReturnOfLostItems") ) {
2009
        unless ( C4::Context->preference("BlockReturnOfLostItems") ) {
2011
            if (
2010
            my $should_refund = Koha::RefundLostItemFeeRules->should_refund(
2012
                Koha::RefundLostItemFeeRules->should_refund(
2011
                {
2013
                    {
2012
                    current_branch      => C4::Context->userenv->{branch},
2014
                        current_branch      => C4::Context->userenv->{branch},
2013
                    item_home_branch    => $item->homebranch,
2015
                        item_home_branch    => $item->homebranch,
2014
                    item_holding_branch => $item_holding_branch
2016
                        item_holding_branch => $item_holding_branch
2015
                }
2017
                    }
2016
            );
2018
                )
2017
2019
              )
2018
            if ($should_refund) {
2020
            {
2021
                _FixAccountForLostAndReturned( $item->itemnumber,
2019
                _FixAccountForLostAndReturned( $item->itemnumber,
2022
                    $borrowernumber, $barcode );
2020
                    $borrowernumber, $barcode, $should_refund eq '2' );
2023
                $messages->{'LostItemFeeRefunded'} = 1;
2021
                $messages->{'LostItemFeeRefunded'} = 1;
2024
            }
2022
            }
2025
        }
2023
        }
Lines 2405-2410 sub _FixAccountForLostAndReturned { Link Here
2405
    my $itemnumber     = shift or return;
2403
    my $itemnumber     = shift or return;
2406
    my $borrowernumber = @_ ? shift : undef;
2404
    my $borrowernumber = @_ ? shift : undef;
2407
    my $item_id        = @_ ? shift : $itemnumber;  # Send the barcode if you want that logged in the description
2405
    my $item_id        = @_ ? shift : $itemnumber;  # Send the barcode if you want that logged in the description
2406
    my $skip_paid      = @_ ? shift : 0;
2408
2407
2409
    my $credit;
2408
    my $credit;
2410
2409
Lines 2424-2429 sub _FixAccountForLostAndReturned { Link Here
2424
    my $accountline     = $accountlines->next;
2423
    my $accountline     = $accountlines->next;
2425
    my $total_to_refund = 0;
2424
    my $total_to_refund = 0;
2426
2425
2426
    return if $skip_paid && $accountline->amountoutstanding <= 0;
2427
2427
    return unless $accountline->borrowernumber;
2428
    return unless $accountline->borrowernumber;
2428
    my $patron = Koha::Patrons->find( $accountline->borrowernumber );
2429
    my $patron = Koha::Patrons->find( $accountline->borrowernumber );
2429
    return unless $patron; # Patron has been deleted, nobody to credit the return to
2430
    return unless $patron; # Patron has been deleted, nobody to credit the return to
Lines 2447-2453 sub _FixAccountForLostAndReturned { Link Here
2447
                            : 0;
2448
                            : 0;
2448
    }
2449
    }
2449
2450
2450
    my $credit_total = $accountline->amountoutstanding + $total_to_refund;
2451
    my $credit_total = $accountline->amountoutstanding + ( $skip_paid ? 0 : $total_to_refund );
2451
2452
2452
    if ( $credit_total > 0 ) {
2453
    if ( $credit_total > 0 ) {
2453
        my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
2454
        my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-5 / +24 lines)
Lines 639-658 Link Here
639
                        <select name="refund">
639
                        <select name="refund">
640
                          [#% Default branch %#]
640
                          [#% Default branch %#]
641
                          [% IF ( current_branch == '*' ) %]
641
                          [% IF ( current_branch == '*' ) %]
642
                            [% IF ( defaultRefundRule ) %]
642
                            [% IF ( defaultRefundRule == 1 ) %]
643
                            <option value="1" selected="selected">
643
                            <option value="1" selected="selected">
644
                            [% ELSE %]
644
                            [% ELSE %]
645
                            <option value="1">
645
                            <option value="1">
646
                            [% END %]
646
                            [% END %]
647
                                Yes
647
                                Yes
648
                            </option>
648
                            </option>
649
                            [% IF ( not defaultRefundRule ) %]
649
                            [% IF ( defaultRefundRule == 0 ) %]
650
                            <option value="0" selected="selected">
650
                            <option value="0" selected="selected">
651
                            [% ELSE %]
651
                            [% ELSE %]
652
                            <option value="0">
652
                            <option value="0">
653
                            [% END %]
653
                            [% END %]
654
                                No
654
                                No
655
                            </option>
655
                            </option>
656
657
                            [% IF ( defaultRefundRule == 2 ) %]
658
                            <option value="2" selected="selected">
659
                            [% ELSE %]
660
                            <option value="2">
661
                            [% END %]
662
                                Only if unpaid
663
                            </option>
656
                          [% ELSE %]
664
                          [% ELSE %]
657
                          [#% Branch-specific %#]
665
                          [#% Branch-specific %#]
658
                            [% IF ( not refundLostItemFeeRule ) %]
666
                            [% IF ( not refundLostItemFeeRule ) %]
Lines 660-667 Link Here
660
                            [% ELSE %]
668
                            [% ELSE %]
661
                                <option value="*">
669
                                <option value="*">
662
                            [% END %]
670
                            [% END %]
663
                              [% IF defaultRefundRule %]
671
                              [% IF defaultRefundRule == 1 %]
664
                                Use default (Yes)
672
                                Use default (Yes)
673
                              [% ELSIF defaultRefundRule == 2 %]
674
                                Use default (Only if unpaid)
665
                              [% ELSE %]
675
                              [% ELSE %]
666
                                Use default (No)
676
                                Use default (No)
667
                              [% END %]
677
                              [% END %]
Lines 669-689 Link Here
669
                            [% IF ( not refundLostItemFeeRule ) %]
679
                            [% IF ( not refundLostItemFeeRule ) %]
670
                                <option value="1">Yes</option>
680
                                <option value="1">Yes</option>
671
                                <option value="0">No</option>
681
                                <option value="0">No</option>
682
                                <option value="2">Only if unpaid</option>
672
                            [% ELSE %]
683
                            [% ELSE %]
673
                                [% IF ( refundLostItemFeeRule.rule_value ) %]
684
                                [% IF ( refundLostItemFeeRule.rule_value == 1 ) %]
674
                                <option value="1" selected="selected">
685
                                <option value="1" selected="selected">
675
                                [% ELSE %]
686
                                [% ELSE %]
676
                                <option value="1">
687
                                <option value="1">
677
                                [% END %]
688
                                [% END %]
678
                                    Yes
689
                                    Yes
679
                                </option>
690
                                </option>
680
                                [% IF ( not refundLostItemFeeRule.rule_value ) %]
691
                                [% IF ( refundLostItemFeeRule.rule_value == 0 ) %]
681
                                <option value="0" selected="selected">
692
                                <option value="0" selected="selected">
682
                                [% ELSE %]
693
                                [% ELSE %]
683
                                <option value="0">
694
                                <option value="0">
684
                                [% END %]
695
                                [% END %]
685
                                    No
696
                                    No
686
                                </option>
697
                                </option>
698
699
                                [% IF ( refundLostItemFeeRule.rule_value == 3 ) %]
700
                                <option value="3" selected="selected">
701
                                [% ELSE %]
702
                                <option value="3">
703
                                [% END %]
704
                                    Only if unpaid
705
                                </option>
687
                            [% END %]
706
                            [% END %]
688
                          [% END %]
707
                          [% END %]
689
                        </select>
708
                        </select>
(-)a/t/db_dependent/Circulation.t (-1 / +66 lines)
Lines 2078-2084 subtest 'AddReturn | is_overdue' => sub { Link Here
2078
2078
2079
subtest '_FixAccountForLostAndReturned' => sub {
2079
subtest '_FixAccountForLostAndReturned' => sub {
2080
2080
2081
    plan tests => 5;
2081
    plan tests => 14;
2082
2082
2083
    t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 );
2083
    t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 );
2084
    t::lib::Mocks::mock_preference( 'WhenLostForgiveFine',          0 );
2084
    t::lib::Mocks::mock_preference( 'WhenLostForgiveFine',          0 );
Lines 2464-2469 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2464
        my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, accounttype => 'OVERDUE', status => 'UNRETURNED' })->next;
2464
        my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, accounttype => 'OVERDUE', status => 'UNRETURNED' })->next;
2465
        is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' );
2465
        is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' );
2466
    };
2466
    };
2467
2468
2469
    is( $accountline->amountoutstanding, '0.000000', 'Lost fee has no outstanding amount' );
2470
    is( $accountline->accounttype, 'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2471
    is( $patron->account->balance, 0, 'Account balance should be 0 after return of lost item' );
2472
2473
    # Tests for only if unpaid
2474
    ## Unpaid
2475
    $accountline->delete();
2476
    $accountline = Koha::Account::Line->new(
2477
        {
2478
            borrowernumber => $patron->borrowernumber,
2479
            accounttype    => 'L',
2480
            itemnumber     => $itemnumber,
2481
            amount => 99.00,
2482
            amountoutstanding => 99.00,
2483
        }
2484
    )->store();
2485
2486
    C4::Circulation::_FixAccountForLostAndReturned( $itemnumber, $patron->borrowernumber, undef, 1 );
2487
2488
    $accountline->_result()->discard_changes();
2489
2490
    is( $accountline->amountoutstanding, '0.000000', 'Lost fee has no outstanding amount, with skip_paid = 1 and unpaid' );
2491
    is( $accountline->accounttype, 'LR', 'Lost fee now has account type of LR ( Lost Returned ), with skip_paid = 1 and unpaid');
2492
    is( $patron->account->balance, 0, 'Account balance should be 0 after return of unpaid lost item' );
2493
2494
    ## Paid
2495
    $accountline->delete();
2496
    $accountline = Koha::Account::Line->new(
2497
        {
2498
            borrowernumber => $patron->borrowernumber,
2499
            accounttype    => 'L',
2500
            itemnumber     => $itemnumber,
2501
            amount => 99.00,
2502
            amountoutstanding => 0.00,
2503
        }
2504
    )->store();
2505
2506
    C4::Circulation::_FixAccountForLostAndReturned( $itemnumber, $patron->borrowernumber, undef, 1 );
2507
2508
    $accountline->_result()->discard_changes();
2509
2510
    is( $accountline->amountoutstanding, '0.000000', 'Lost fee still has outstanding amount of 0, with skip_paid = 1 and already paid' );
2511
    is( $accountline->accounttype, 'L', 'Lost fee now has account type of L ( Lost ), with skip_paid = 1 and already paid');
2512
    is( $patron->account->balance, 0, 'Account balance should be 0 after return of partially paid lost item' );
2513
2514
    ## Partially paid
2515
    $accountline->delete();
2516
    $accountline = Koha::Account::Line->new(
2517
        {
2518
            borrowernumber => $patron->borrowernumber,
2519
            accounttype    => 'L',
2520
            itemnumber     => $itemnumber,
2521
            amount => 99.00,
2522
            amountoutstanding => 33.00,
2523
        }
2524
    )->store();
2525
2526
    C4::Circulation::_FixAccountForLostAndReturned( $itemnumber, $patron->borrowernumber, undef, 1 );
2527
2528
    $accountline->_result()->discard_changes();
2529
2530
    is( $accountline->amountoutstanding, '0.000000', 'Lost fee has no outstanding amount, with skip_paid = 1 and partially paid' );
2531
    is( $accountline->accounttype, 'LR', 'Lost fee now has account type of L ( Lost ), with skip_paid = 1 and partially paid');
2467
};
2532
};
2468
2533
2469
subtest '_FixOverduesOnReturn' => sub {
2534
subtest '_FixOverduesOnReturn' => sub {
(-)a/t/db_dependent/RefundLostItemFeeRule.t (-5 / +4 lines)
Lines 181-187 subtest 'Koha::RefundLostItemFeeRules::_effective_branch_rule() tests' => sub { Link Here
181
                categorycode => undef,
181
                categorycode => undef,
182
                itemtype     => undef,
182
                itemtype     => undef,
183
                rule_name    => 'refund',
183
                rule_name    => 'refund',
184
                rule_value   => 1,
184
                rule_value   => 2,
185
            }
185
            }
186
        }
186
        }
187
    );
187
    );
Lines 215-221 subtest 'Koha::RefundLostItemFeeRules::_effective_branch_rule() tests' => sub { Link Here
215
    # Delete specific rules
215
    # Delete specific rules
216
    Koha::RefundLostItemFeeRules->find({ branchcode => $specific_rule_false->{ branchcode } })->delete;
216
    Koha::RefundLostItemFeeRules->find({ branchcode => $specific_rule_false->{ branchcode } })->delete;
217
    is( Koha::RefundLostItemFeeRules->_effective_branch_rule( $specific_rule_false->{ branchcode } ),
217
    is( Koha::RefundLostItemFeeRules->_effective_branch_rule( $specific_rule_false->{ branchcode } ),
218
          1,'No specific rule defined, fallback to global (true)');
218
          2,'No specific rule defined, fallback to global (true)');
219
219
220
    # Rollback transaction
220
    # Rollback transaction
221
    $schema->storage->txn_rollback;
221
    $schema->storage->txn_rollback;
Lines 319-325 subtest 'Koha::RefundLostItemFeeRules::should_refund() tests' => sub { Link Here
319
                categorycode => undef,
319
                categorycode => undef,
320
                itemtype     => undef,
320
                itemtype     => undef,
321
                rule_name    => 'refund',
321
                rule_name    => 'refund',
322
                rule_value   => 1
322
                rule_value   => 2
323
            }
323
            }
324
        }
324
        }
325
    );
325
    );
Lines 356-362 subtest 'Koha::RefundLostItemFeeRules::should_refund() tests' => sub { Link Here
356
356
357
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
357
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
358
    is( Koha::RefundLostItemFeeRules->should_refund( $params ),
358
    is( Koha::RefundLostItemFeeRules->should_refund( $params ),
359
          1,'Specific rule is applied (true)');
359
          2,'Specific rule is applied (true)');
360
360
361
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHomeBranch' );
361
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHomeBranch' );
362
    is( Koha::RefundLostItemFeeRules->should_refund( $params ),
362
    is( Koha::RefundLostItemFeeRules->should_refund( $params ),
363
- 

Return to bug 20262