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

(-)a/C4/Circulation.pm (-25 / +23 lines)
Lines 1374-1391 sub AddIssue { Link Here
1374
1374
1375
            ## If item was lost, it has now been found, reverse any list item charges if necessary.
1375
            ## If item was lost, it has now been found, reverse any list item charges if necessary.
1376
            if ( $item->{'itemlost'} ) {
1376
            if ( $item->{'itemlost'} ) {
1377
                if (
1377
                my $should_refund = Koha::RefundLostItemFeeRules->should_refund(
1378
                    Koha::RefundLostItemFeeRules->should_refund(
1378
                    {
1379
                        {
1379
                        current_branch      => C4::Context->userenv->{branch},
1380
                            current_branch      => C4::Context->userenv->{branch},
1380
                        item_home_branch    => $item->{homebranch},
1381
                            item_home_branch    => $item->{homebranch},
1381
                        item_holding_branch => $item->{holdingbranch}
1382
                            item_holding_branch => $item->{holdingbranch}
1382
                    }
1383
                        }
1383
                );
1384
                    )
1384
1385
                  )
1385
                if ($should_refund) {
1386
                {
1386
                    _FixAccountForLostAndReturned( $item->{'itemnumber'}, undef, $item->{'barcode'}, $should_refund eq '2' );
1387
                    _FixAccountForLostAndReturned( $item->{'itemnumber'}, undef,
1388
                        $item->{'barcode'} );
1389
                }
1387
                }
1390
            }
1388
            }
1391
1389
Lines 1961-1978 sub AddReturn { Link Here
1961
    if ( $item->{'itemlost'} ) {
1959
    if ( $item->{'itemlost'} ) {
1962
        $messages->{'WasLost'} = 1;
1960
        $messages->{'WasLost'} = 1;
1963
        unless ( C4::Context->preference("BlockReturnOfLostItems") ) {
1961
        unless ( C4::Context->preference("BlockReturnOfLostItems") ) {
1964
            if (
1962
            my $should_refund = Koha::RefundLostItemFeeRules->should_refund(
1965
                Koha::RefundLostItemFeeRules->should_refund(
1963
                {
1966
                    {
1964
                    current_branch      => C4::Context->userenv->{branch},
1967
                        current_branch      => C4::Context->userenv->{branch},
1965
                    item_home_branch    => $item->{homebranch},
1968
                        item_home_branch    => $item->{homebranch},
1966
                    item_holding_branch => $item_holding_branch
1969
                        item_holding_branch => $item_holding_branch
1967
                }
1970
                    }
1968
            );
1971
                )
1969
1972
              )
1970
            if ($should_refund) {
1973
            {
1971
                _FixAccountForLostAndReturned( $item->{itemnumber}, $borrowernumber, $barcode, $should_refund eq '2' );
1974
                _FixAccountForLostAndReturned( $item->{'itemnumber'},
1975
                    $borrowernumber, $barcode );
1976
                $messages->{'LostItemFeeRefunded'} = 1;
1972
                $messages->{'LostItemFeeRefunded'} = 1;
1977
            }
1973
            }
1978
        }
1974
        }
Lines 2384-2389 sub _FixAccountForLostAndReturned { Link Here
2384
    my $itemnumber     = shift or return;
2380
    my $itemnumber     = shift or return;
2385
    my $borrowernumber = @_ ? shift : undef;
2381
    my $borrowernumber = @_ ? shift : undef;
2386
    my $item_id        = @_ ? shift : $itemnumber;  # Send the barcode if you want that logged in the description
2382
    my $item_id        = @_ ? shift : $itemnumber;  # Send the barcode if you want that logged in the description
2383
    my $skip_paid      = @_ ? shift : 0;
2387
2384
2388
    # check for charge made for lost book
2385
    # check for charge made for lost book
2389
    my $accountline = Koha::Account::Lines->search(
2386
    my $accountline = Koha::Account::Lines->search(
Lines 2398-2403 sub _FixAccountForLostAndReturned { Link Here
2398
2395
2399
    return unless $accountline;
2396
    return unless $accountline;
2400
    return if $accountline->accounttype eq 'W';    # Written off
2397
    return if $accountline->accounttype eq 'W';    # Written off
2398
    return if $skip_paid && $accountline->amountoutstanding <= 0;
2401
2399
2402
    $accountline->accounttype('LR');
2400
    $accountline->accounttype('LR');
2403
    $accountline->store();
2401
    $accountline->store();
Lines 2405-2411 sub _FixAccountForLostAndReturned { Link Here
2405
    my $account = Koha::Account->new( { patron_id => $accountline->borrowernumber } );
2403
    my $account = Koha::Account->new( { patron_id => $accountline->borrowernumber } );
2406
    my $credit_id = $account->pay(
2404
    my $credit_id = $account->pay(
2407
        {
2405
        {
2408
            amount       => $accountline->amount,
2406
            amount       => $skip_paid ? $accountline->amountoutstanding : $accountline->amount,
2409
            description  => "Item Returned " . $item_id,
2407
            description  => "Item Returned " . $item_id,
2410
            account_type => 'CR',
2408
            account_type => 'CR',
2411
            offset_type  => 'Lost Item Return',
2409
            offset_type  => 'Lost Item Return',
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-5 / +26 lines)
Lines 554-573 Link Here
554
                        <select name="refund">
554
                        <select name="refund">
555
                          [#% Default branch %#]
555
                          [#% Default branch %#]
556
                          [% IF ( current_branch == '*' ) %]
556
                          [% IF ( current_branch == '*' ) %]
557
                            [% IF ( refundLostItemFeeRule.refund ) %]
557
                            [% IF ( refundLostItemFeeRule.refund == 1 ) %]
558
                            <option value="1" selected="selected">
558
                            <option value="1" selected="selected">
559
                            [% ELSE %]
559
                            [% ELSE %]
560
                            <option value="1">
560
                            <option value="1">
561
                            [% END %]
561
                            [% END %]
562
                                Yes
562
                                Yes
563
                            </option>
563
                            </option>
564
                            [% IF ( not refundLostItemFeeRule.refund ) %]
564
565
                            [% IF ( refundLostItemFeeRule.refund == 0 ) %]
565
                            <option value="0" selected="selected">
566
                            <option value="0" selected="selected">
566
                            [% ELSE %]
567
                            [% ELSE %]
567
                            <option value="0">
568
                            <option value="0">
568
                            [% END %]
569
                            [% END %]
569
                                No
570
                                No
570
                            </option>
571
                            </option>
572
573
                            [% IF ( refundLostItemFeeRule.refund == 2 ) %]
574
                            <option value="2" selected="selected">
575
                            [% ELSE %]
576
                            <option value="2">
577
                            [% END %]
578
                                Only if unpaid
579
                            </option>
571
                          [% ELSE %]
580
                          [% ELSE %]
572
                          [#% Branch-specific %#]
581
                          [#% Branch-specific %#]
573
                            [% IF ( not refundLostItemFeeRule ) %]
582
                            [% IF ( not refundLostItemFeeRule ) %]
Lines 575-582 Link Here
575
                            [% ELSE %]
584
                            [% ELSE %]
576
                                <option value="*">
585
                                <option value="*">
577
                            [% END %]
586
                            [% END %]
578
                              [% IF defaultRefundRule %]
587
                              [% IF defaultRefundRule == 1 %]
579
                                Use default (Yes)
588
                                Use default (Yes)
589
                              [% ELSIF defaultRefundRule == 2 %]
590
                                Use default (Only if unpaid)
580
                              [% ELSE %]
591
                              [% ELSE %]
581
                                Use default (No)
592
                                Use default (No)
582
                              [% END %]
593
                              [% END %]
Lines 584-604 Link Here
584
                            [% IF ( not refundLostItemFeeRule ) %]
595
                            [% IF ( not refundLostItemFeeRule ) %]
585
                                <option value="1">Yes</option>
596
                                <option value="1">Yes</option>
586
                                <option value="0">No</option>
597
                                <option value="0">No</option>
598
                                <option value="2">Only if unpaid</option>
587
                            [% ELSE %]
599
                            [% ELSE %]
588
                                [% IF ( refundLostItemFeeRule.refund ) %]
600
                                [% IF ( refundLostItemFeeRule.refund == 1 ) %]
589
                                <option value="1" selected="selected">
601
                                <option value="1" selected="selected">
590
                                [% ELSE %]
602
                                [% ELSE %]
591
                                <option value="1">
603
                                <option value="1">
592
                                [% END %]
604
                                [% END %]
593
                                    Yes
605
                                    Yes
594
                                </option>
606
                                </option>
595
                                [% IF ( not refundLostItemFeeRule.refund ) %]
607
608
                                [% IF ( refundLostItemFeeRule.refund == 0 ) %]
596
                                <option value="0" selected="selected">
609
                                <option value="0" selected="selected">
597
                                [% ELSE %]
610
                                [% ELSE %]
598
                                <option value="0">
611
                                <option value="0">
599
                                [% END %]
612
                                [% END %]
600
                                    No
613
                                    No
601
                                </option>
614
                                </option>
615
616
                                [% IF ( refundLostItemFeeRule.refund == 3 ) %]
617
                                <option value="3" selected="selected">
618
                                [% ELSE %]
619
                                <option value="3">
620
                                [% END %]
621
                                    Only if unpaid
622
                                </option>
602
                            [% END %]
623
                            [% END %]
603
                          [% END %]
624
                          [% END %]
604
                        </select>
625
                        </select>
(-)a/t/db_dependent/Circulation.t (-5 / +66 lines)
Lines 1972-1978 subtest 'AddReturn | is_overdue' => sub { Link Here
1972
};
1972
};
1973
1973
1974
subtest '_FixAccountForLostAndReturned' => sub {
1974
subtest '_FixAccountForLostAndReturned' => sub {
1975
    plan tests => 2;
1975
    plan tests => 11;
1976
1976
1977
    # Generate test biblio
1977
    # Generate test biblio
1978
    my $title  = 'Koha for Dummies';
1978
    my $title  = 'Koha for Dummies';
Lines 1992-2002 subtest '_FixAccountForLostAndReturned' => sub { Link Here
1992
        $biblionumber
1992
        $biblionumber
1993
    );
1993
    );
1994
1994
1995
    my $patron = $builder->build( { source => 'Borrower' } );
1995
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
1996
1996
1997
    my $accountline = Koha::Account::Line->new(
1997
    my $accountline = Koha::Account::Line->new(
1998
        {
1998
        {
1999
            borrowernumber => $patron->{borrowernumber},
1999
            borrowernumber => $patron->borrowernumber,
2000
            accounttype    => 'L',
2000
            accounttype    => 'L',
2001
            itemnumber     => $itemnumber,
2001
            itemnumber     => $itemnumber,
2002
            amount => 99.00,
2002
            amount => 99.00,
Lines 2004-2015 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2004
        }
2004
        }
2005
    )->store();
2005
    )->store();
2006
2006
2007
    C4::Circulation::_FixAccountForLostAndReturned( $itemnumber, $patron->{borrowernumber} );
2007
    C4::Circulation::_FixAccountForLostAndReturned( $itemnumber, $patron->borrowernumber );
2008
2008
2009
    $accountline->_result()->discard_changes();
2009
    $accountline->_result()->discard_changes();
2010
2010
2011
    is( $accountline->amountoutstanding, '0.000000', 'Lost fee has no outstanding amount' );
2011
    is( $accountline->amountoutstanding, '0.000000', 'Lost fee has no outstanding amount' );
2012
    is( $accountline->accounttype, 'LR', 'Lost fee now has account type of LR ( Lost Returned )');
2012
    is( $accountline->accounttype, 'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2013
    is( $patron->account->balance, 0, 'Account balance should be 0 after return of lost item' );
2014
2015
    # Tests for only if unpaid
2016
    ## Unpaid
2017
    $accountline->delete();
2018
    $accountline = Koha::Account::Line->new(
2019
        {
2020
            borrowernumber => $patron->borrowernumber,
2021
            accounttype    => 'L',
2022
            itemnumber     => $itemnumber,
2023
            amount => 99.00,
2024
            amountoutstanding => 99.00,
2025
        }
2026
    )->store();
2027
2028
    C4::Circulation::_FixAccountForLostAndReturned( $itemnumber, $patron->borrowernumber, undef, 1 );
2029
2030
    $accountline->_result()->discard_changes();
2031
2032
    is( $accountline->amountoutstanding, '0.000000', 'Lost fee has no outstanding amount, with skip_paid = 1 and unpaid' );
2033
    is( $accountline->accounttype, 'LR', 'Lost fee now has account type of LR ( Lost Returned ), with skip_paid = 1 and unpaid');
2034
    is( $patron->account->balance, 0, 'Account balance should be 0 after return of unpaid lost item' );
2035
2036
    ## Paid
2037
    $accountline->delete();
2038
    $accountline = Koha::Account::Line->new(
2039
        {
2040
            borrowernumber => $patron->borrowernumber,
2041
            accounttype    => 'L',
2042
            itemnumber     => $itemnumber,
2043
            amount => 99.00,
2044
            amountoutstanding => 0.00,
2045
        }
2046
    )->store();
2047
2048
    C4::Circulation::_FixAccountForLostAndReturned( $itemnumber, $patron->borrowernumber, undef, 1 );
2049
2050
    $accountline->_result()->discard_changes();
2051
2052
    is( $accountline->amountoutstanding, '0.000000', 'Lost fee still has outstanding amount of 0, with skip_paid = 1 and already paid' );
2053
    is( $accountline->accounttype, 'L', 'Lost fee now has account type of L ( Lost ), with skip_paid = 1 and already paid');
2054
    is( $patron->account->balance, 0, 'Account balance should be 0 after return of partially paid lost item' );
2055
2056
    ## Partially paid
2057
    $accountline->delete();
2058
    $accountline = Koha::Account::Line->new(
2059
        {
2060
            borrowernumber => $patron->borrowernumber,
2061
            accounttype    => 'L',
2062
            itemnumber     => $itemnumber,
2063
            amount => 99.00,
2064
            amountoutstanding => 33.00,
2065
        }
2066
    )->store();
2067
2068
    C4::Circulation::_FixAccountForLostAndReturned( $itemnumber, $patron->borrowernumber, undef, 1 );
2069
2070
    $accountline->_result()->discard_changes();
2071
2072
    is( $accountline->amountoutstanding, '0.000000', 'Lost fee has no outstanding amount, with skip_paid = 1 and partially paid' );
2073
    is( $accountline->accounttype, 'LR', 'Lost fee now has account type of L ( Lost ), with skip_paid = 1 and partially paid');
2013
};
2074
};
2014
2075
2015
subtest '_FixOverduesOnReturn' => sub {
2076
subtest '_FixOverduesOnReturn' => sub {
(-)a/t/db_dependent/RefundLostItemFeeRule.t (-5 / +4 lines)
Lines 130-136 subtest 'Koha::RefundLostItemFeeRules::_effective_branch_rule() tests' => sub { Link Here
130
        source => 'RefundLostItemFeeRule',
130
        source => 'RefundLostItemFeeRule',
131
        value  => {
131
        value  => {
132
            branchcode => '*',
132
            branchcode => '*',
133
            refund     => 1
133
            refund     => 2
134
        }
134
        }
135
    });
135
    });
136
    my $specific_rule_false = $builder->build({
136
    my $specific_rule_false = $builder->build({
Lines 153-159 subtest 'Koha::RefundLostItemFeeRules::_effective_branch_rule() tests' => sub { Link Here
153
    # Delete specific rules
153
    # Delete specific rules
154
    Koha::RefundLostItemFeeRules->find({ branchcode => $specific_rule_false->{ branchcode } })->delete;
154
    Koha::RefundLostItemFeeRules->find({ branchcode => $specific_rule_false->{ branchcode } })->delete;
155
    is( Koha::RefundLostItemFeeRules->_effective_branch_rule( $specific_rule_false->{ branchcode } ),
155
    is( Koha::RefundLostItemFeeRules->_effective_branch_rule( $specific_rule_false->{ branchcode } ),
156
          1,'No specific rule defined, fallback to global (true)');
156
          2,'No specific rule defined, fallback to global (true)');
157
157
158
    # Rollback transaction
158
    # Rollback transaction
159
    $schema->storage->txn_rollback;
159
    $schema->storage->txn_rollback;
Lines 243-249 subtest 'Koha::RefundLostItemFeeRules::should_refund() tests' => sub { Link Here
243
    my $specific_rule_true = $builder->build({
243
    my $specific_rule_true = $builder->build({
244
        source => 'RefundLostItemFeeRule',
244
        source => 'RefundLostItemFeeRule',
245
        value  => {
245
        value  => {
246
            refund => 1
246
            refund => 2
247
        }
247
        }
248
    });
248
    });
249
    # Make sure we have an unused branchcode
249
    # Make sure we have an unused branchcode
Lines 264-270 subtest 'Koha::RefundLostItemFeeRules::should_refund() tests' => sub { Link Here
264
264
265
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
265
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
266
    is( Koha::RefundLostItemFeeRules->should_refund( $params ),
266
    is( Koha::RefundLostItemFeeRules->should_refund( $params ),
267
          1,'Specific rule is applied (true)');
267
          2,'Specific rule is applied (true)');
268
268
269
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHomeBranch' );
269
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHomeBranch' );
270
    is( Koha::RefundLostItemFeeRules->should_refund( $params ),
270
    is( Koha::RefundLostItemFeeRules->should_refund( $params ),
271
- 

Return to bug 20262