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

(-)a/C4/Circulation.pm (-13 / +13 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 == 2 );
1387
                    _FixAccountForLostAndReturned( $item->{'itemnumber'}, undef,
1388
                        $item->{'barcode'} );
1389
                }
1387
                }
1390
            }
1388
            }
1391
1389
Lines 2366-2371 sub _FixAccountForLostAndReturned { Link Here
2366
    my $itemnumber     = shift or return;
2364
    my $itemnumber     = shift or return;
2367
    my $borrowernumber = @_ ? shift : undef;
2365
    my $borrowernumber = @_ ? shift : undef;
2368
    my $item_id        = @_ ? shift : $itemnumber;  # Send the barcode if you want that logged in the description
2366
    my $item_id        = @_ ? shift : $itemnumber;  # Send the barcode if you want that logged in the description
2367
    my $skip_paid      = @_ ? shift : 0;
2369
2368
2370
    # check for charge made for lost book
2369
    # check for charge made for lost book
2371
    my $accountline = Koha::Account::Lines->search(
2370
    my $accountline = Koha::Account::Lines->search(
Lines 2380-2385 sub _FixAccountForLostAndReturned { Link Here
2380
2379
2381
    return unless $accountline;
2380
    return unless $accountline;
2382
    return if $accountline->accounttype eq 'W';    # Written off
2381
    return if $accountline->accounttype eq 'W';    # Written off
2382
    return if $skip_paid && $accountline->amountoutstanding <= 0;
2383
2383
2384
    $accountline->accounttype('LR');
2384
    $accountline->accounttype('LR');
2385
    $accountline->store();
2385
    $accountline->store();
Lines 2387-2393 sub _FixAccountForLostAndReturned { Link Here
2387
    my $account = Koha::Account->new( { patron_id => $accountline->borrowernumber } );
2387
    my $account = Koha::Account->new( { patron_id => $accountline->borrowernumber } );
2388
    my $credit_id = $account->pay(
2388
    my $credit_id = $account->pay(
2389
        {
2389
        {
2390
            amount       => $accountline->amount,
2390
            amount       => $skip_paid ? $accountline->amountoutstanding : $accountline->amount,
2391
            description  => "Item Returned " . $item_id,
2391
            description  => "Item Returned " . $item_id,
2392
            account_type => 'CR',
2392
            account_type => 'CR',
2393
            offset_type  => 'Lost Item Return',
2393
            offset_type  => 'Lost Item Return',
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-5 / +26 lines)
Lines 534-553 Link Here
534
                        <select name="refund">
534
                        <select name="refund">
535
                          [#% Default branch %#]
535
                          [#% Default branch %#]
536
                          [% IF ( current_branch == '*' ) %]
536
                          [% IF ( current_branch == '*' ) %]
537
                            [% IF ( refundLostItemFeeRule.refund ) %]
537
                            [% IF ( refundLostItemFeeRule.refund == 1 ) %]
538
                            <option value="1" selected="selected">
538
                            <option value="1" selected="selected">
539
                            [% ELSE %]
539
                            [% ELSE %]
540
                            <option value="1">
540
                            <option value="1">
541
                            [% END %]
541
                            [% END %]
542
                                Yes
542
                                Yes
543
                            </option>
543
                            </option>
544
                            [% IF ( not refundLostItemFeeRule.refund ) %]
544
545
                            [% IF ( refundLostItemFeeRule.refund == 0 ) %]
545
                            <option value="0" selected="selected">
546
                            <option value="0" selected="selected">
546
                            [% ELSE %]
547
                            [% ELSE %]
547
                            <option value="0">
548
                            <option value="0">
548
                            [% END %]
549
                            [% END %]
549
                                No
550
                                No
550
                            </option>
551
                            </option>
552
553
                            [% IF ( refundLostItemFeeRule.refund == 2 ) %]
554
                            <option value="2" selected="selected">
555
                            [% ELSE %]
556
                            <option value="2">
557
                            [% END %]
558
                                Only if unpaid
559
                            </option>
551
                          [% ELSE %]
560
                          [% ELSE %]
552
                          [#% Branch-specific %#]
561
                          [#% Branch-specific %#]
553
                            [% IF ( not refundLostItemFeeRule ) %]
562
                            [% IF ( not refundLostItemFeeRule ) %]
Lines 555-562 Link Here
555
                            [% ELSE %]
564
                            [% ELSE %]
556
                                <option value="*">
565
                                <option value="*">
557
                            [% END %]
566
                            [% END %]
558
                              [% IF defaultRefundRule %]
567
                              [% IF defaultRefundRule == 1 %]
559
                                Use default (Yes)
568
                                Use default (Yes)
569
                              [% ELSIF defaultRefundRule == 2 %]
570
                                Use default (Only if unpaid)
560
                              [% ELSE %]
571
                              [% ELSE %]
561
                                Use default (No)
572
                                Use default (No)
562
                              [% END %]
573
                              [% END %]
Lines 564-584 Link Here
564
                            [% IF ( not refundLostItemFeeRule ) %]
575
                            [% IF ( not refundLostItemFeeRule ) %]
565
                                <option value="1">Yes</option>
576
                                <option value="1">Yes</option>
566
                                <option value="0">No</option>
577
                                <option value="0">No</option>
578
                                <option value="2">Only if unpaid</option>
567
                            [% ELSE %]
579
                            [% ELSE %]
568
                                [% IF ( refundLostItemFeeRule.refund ) %]
580
                                [% IF ( refundLostItemFeeRule.refund == 1 ) %]
569
                                <option value="1" selected="selected">
581
                                <option value="1" selected="selected">
570
                                [% ELSE %]
582
                                [% ELSE %]
571
                                <option value="1">
583
                                <option value="1">
572
                                [% END %]
584
                                [% END %]
573
                                    Yes
585
                                    Yes
574
                                </option>
586
                                </option>
575
                                [% IF ( not refundLostItemFeeRule.refund ) %]
587
588
                                [% IF ( refundLostItemFeeRule.refund == 0 ) %]
576
                                <option value="0" selected="selected">
589
                                <option value="0" selected="selected">
577
                                [% ELSE %]
590
                                [% ELSE %]
578
                                <option value="0">
591
                                <option value="0">
579
                                [% END %]
592
                                [% END %]
580
                                    No
593
                                    No
581
                                </option>
594
                                </option>
595
596
                                [% IF ( refundLostItemFeeRule.refund == 3 ) %]
597
                                <option value="3" selected="selected">
598
                                [% ELSE %]
599
                                <option value="3">
600
                                [% END %]
601
                                    Only if unpaid
602
                                </option>
582
                            [% END %]
603
                            [% END %]
583
                          [% END %]
604
                          [% END %]
584
                        </select>
605
                        </select>
(-)a/t/db_dependent/Circulation.t (-1 / +59 lines)
Lines 1827-1833 subtest 'AddReturn | is_overdue' => sub { Link Here
1827
};
1827
};
1828
1828
1829
subtest '_FixAccountForLostAndReturned' => sub {
1829
subtest '_FixAccountForLostAndReturned' => sub {
1830
    plan tests => 2;
1830
    plan tests => 8;
1831
1831
1832
    # Generate test biblio
1832
    # Generate test biblio
1833
    my $title  = 'Koha for Dummies';
1833
    my $title  = 'Koha for Dummies';
Lines 1865-1870 subtest '_FixAccountForLostAndReturned' => sub { Link Here
1865
1865
1866
    is( $accountline->amountoutstanding, '0.000000', 'Lost fee has no outstanding amount' );
1866
    is( $accountline->amountoutstanding, '0.000000', 'Lost fee has no outstanding amount' );
1867
    is( $accountline->accounttype, 'LR', 'Lost fee now has account type of LR ( Lost Returned )');
1867
    is( $accountline->accounttype, 'LR', 'Lost fee now has account type of LR ( Lost Returned )');
1868
1869
    # Tests for only if unpaid
1870
    ## Unpaid
1871
    $accountline->delete();
1872
    $accountline = Koha::Account::Line->new(
1873
        {
1874
            borrowernumber => $patron->{borrowernumber},
1875
            accounttype    => 'L',
1876
            itemnumber     => $itemnumber,
1877
            amount => 99.00,
1878
            amountoutstanding => 99.00,
1879
        }
1880
    )->store();
1881
1882
    C4::Circulation::_FixAccountForLostAndReturned( $itemnumber, $patron->{borrowernumber}, undef, 1 );
1883
1884
    $accountline->_result()->discard_changes();
1885
1886
    is( $accountline->amountoutstanding, '0.000000', 'Lost fee has no outstanding amount, with skip_paid = 1 and unpaid' );
1887
    is( $accountline->accounttype, 'LR', 'Lost fee now has account type of LR ( Lost Returned ), with skip_paid = 1 and unpaid');
1888
1889
    ## Paid
1890
    $accountline->delete();
1891
    $accountline = Koha::Account::Line->new(
1892
        {
1893
            borrowernumber => $patron->{borrowernumber},
1894
            accounttype    => 'L',
1895
            itemnumber     => $itemnumber,
1896
            amount => 99.00,
1897
            amountoutstanding => 0.00,
1898
        }
1899
    )->store();
1900
1901
    C4::Circulation::_FixAccountForLostAndReturned( $itemnumber, $patron->{borrowernumber}, undef, 1 );
1902
1903
    $accountline->_result()->discard_changes();
1904
1905
    is( $accountline->amountoutstanding, '0.000000', 'Lost fee still has outstanding amount of 0, with skip_paid = 1 and already paid' );
1906
    is( $accountline->accounttype, 'L', 'Lost fee now has account type of L ( Lost ), with skip_paid = 1 and already paid');
1907
1908
    ## Partially paid
1909
    $accountline->delete();
1910
    $accountline = Koha::Account::Line->new(
1911
        {
1912
            borrowernumber => $patron->{borrowernumber},
1913
            accounttype    => 'L',
1914
            itemnumber     => $itemnumber,
1915
            amount => 99.00,
1916
            amountoutstanding => 33.00,
1917
        }
1918
    )->store();
1919
1920
    C4::Circulation::_FixAccountForLostAndReturned( $itemnumber, $patron->{borrowernumber}, undef, 1 );
1921
1922
    $accountline->_result()->discard_changes();
1923
1924
    is( $accountline->amountoutstanding, '0.000000', 'Lost fee has no outstanding amount, with skip_paid = 1 and partially paid' );
1925
    is( $accountline->accounttype, 'LR', 'Lost fee now has account type of L ( Lost ), with skip_paid = 1 and partially paid');
1868
};
1926
};
1869
1927
1870
subtest '_FixOverduesOnReturn' => sub {
1928
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