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

(-)a/C4/Circulation.pm (-11 / +13 lines)
Lines 1454-1460 sub AddIssue { Link Here
1454
                    )
1454
                    )
1455
                  )
1455
                  )
1456
                {
1456
                {
1457
                    _FixAccountForLostAndReturned( $item_object->itemnumber, undef,
1457
                    _FixAccountForLostAndFound( $item_object->itemnumber, undef,
1458
                        $item_object->barcode );
1458
                        $item_object->barcode );
1459
                }
1459
                }
1460
            }
1460
            }
Lines 2024-2030 sub AddReturn { Link Here
2024
                )
2024
                )
2025
              )
2025
              )
2026
            {
2026
            {
2027
                _FixAccountForLostAndReturned( $item->itemnumber,
2027
                _FixAccountForLostAndFound( $item->itemnumber,
2028
                    $borrowernumber, $barcode );
2028
                    $borrowernumber, $barcode );
2029
                $messages->{'LostItemFeeRefunded'} = 1;
2029
                $messages->{'LostItemFeeRefunded'} = 1;
2030
            }
2030
            }
Lines 2439-2447 sub _FixOverduesOnReturn { Link Here
2439
    return $result;
2439
    return $result;
2440
}
2440
}
2441
2441
2442
=head2 _FixAccountForLostAndReturned
2442
=head2 _FixAccountForLostAndFound
2443
2443
2444
  &_FixAccountForLostAndReturned($itemnumber, [$borrowernumber, $barcode]);
2444
  &_FixAccountForLostAndFound($itemnumber, [$borrowernumber, $barcode]);
2445
2445
2446
Finds the most recent lost item charge for this item and refunds the borrower
2446
Finds the most recent lost item charge for this item and refunds the borrower
2447
appropriatly, taking into account any payments or writeoffs already applied
2447
appropriatly, taking into account any payments or writeoffs already applied
Lines 2451-2457 Internal function, not exported, called only by AddReturn. Link Here
2451
2451
2452
=cut
2452
=cut
2453
2453
2454
sub _FixAccountForLostAndReturned {
2454
sub _FixAccountForLostAndFound {
2455
    my $itemnumber     = shift or return;
2455
    my $itemnumber     = shift or return;
2456
    my $borrowernumber = @_ ? shift : undef;
2456
    my $borrowernumber = @_ ? shift : undef;
2457
    my $item_id        = @_ ? shift : $itemnumber;  # Send the barcode if you want that logged in the description
2457
    my $item_id        = @_ ? shift : $itemnumber;  # Send the barcode if you want that logged in the description
Lines 2463-2469 sub _FixAccountForLostAndReturned { Link Here
2463
        {
2463
        {
2464
            itemnumber      => $itemnumber,
2464
            itemnumber      => $itemnumber,
2465
            debit_type_code => 'LOST',
2465
            debit_type_code => 'LOST',
2466
            status          => [ undef, { '<>' => 'RETURNED' } ]
2466
            status          => [ undef, { '<>' => 'FOUND' } ]
2467
        },
2467
        },
2468
        {
2468
        {
2469
            order_by => { -desc => [ 'date', 'accountlines_id' ] }
2469
            order_by => { -desc => [ 'date', 'accountlines_id' ] }
Lines 2502-2512 sub _FixAccountForLostAndReturned { Link Here
2502
    if ( $credit_total > 0 ) {
2502
    if ( $credit_total > 0 ) {
2503
        my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
2503
        my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
2504
        $credit = $account->add_credit(
2504
        $credit = $account->add_credit(
2505
            {   amount      => $credit_total,
2505
            {
2506
                description => 'Item Returned ' . $item_id,
2506
                amount      => $credit_total,
2507
                type        => 'LOST_RETURN',
2507
                description => 'Item found ' . $item_id,
2508
                type        => 'LOST_FOUND',
2508
                interface   => C4::Context->interface,
2509
                interface   => C4::Context->interface,
2509
                library_id  => $branchcode
2510
                library_id  => $branchcode,
2511
                item_id     => $itemnumber
2510
            }
2512
            }
2511
        );
2513
        );
2512
2514
Lines 2514-2520 sub _FixAccountForLostAndReturned { Link Here
2514
    }
2516
    }
2515
2517
2516
    # Update the account status
2518
    # Update the account status
2517
    $accountline->discard_changes->status('RETURNED');
2519
    $accountline->discard_changes->status('FOUND');
2518
    $accountline->store;
2520
    $accountline->store;
2519
2521
2520
    if ( defined $account and C4::Context->preference('AccountAutoReconcile') ) {
2522
    if ( defined $account and C4::Context->preference('AccountAutoReconcile') ) {
(-)a/Koha/Account.pm (-2 / +2 lines)
Lines 326-332 $credit_type can be any of: Link Here
326
  - 'CREDIT'
326
  - 'CREDIT'
327
  - 'PAYMENT'
327
  - 'PAYMENT'
328
  - 'FORGIVEN'
328
  - 'FORGIVEN'
329
  - 'LOST_RETURN'
329
  - 'LOST_FOUND'
330
  - 'WRITEOFF'
330
  - 'WRITEOFF'
331
331
332
=cut
332
=cut
Lines 741-747 sub reconcile_balance { Link Here
741
our $offset_type = {
741
our $offset_type = {
742
    'CREDIT'           => 'Manual Credit',
742
    'CREDIT'           => 'Manual Credit',
743
    'FORGIVEN'         => 'Writeoff',
743
    'FORGIVEN'         => 'Writeoff',
744
    'LOST_RETURN'      => 'Lost Item',
744
    'LOST_FOUND'       => 'Lost Item Found',
745
    'PAYMENT'          => 'Payment',
745
    'PAYMENT'          => 'Payment',
746
    'WRITEOFF'         => 'Writeoff',
746
    'WRITEOFF'         => 'Writeoff',
747
    'ACCOUNT'          => 'Account Fee',
747
    'ACCOUNT'          => 'Account Fee',
(-)a/api/v1/swagger/definitions/patron_account_credit.json (-1 / +1 lines)
Lines 3-9 Link Here
3
  "properties": {
3
  "properties": {
4
    "credit_type": {
4
    "credit_type": {
5
      "type": "string",
5
      "type": "string",
6
      "description": "Type of credit ('CREDIT', 'FORGIVEN', 'LOST_RETURN', 'PAYMENT', 'WRITEOFF' )"
6
      "description": "Type of credit ('CREDIT', 'FORGIVEN', 'LOST_FOUND', 'PAYMENT', 'WRITEOFF' )"
7
    },
7
    },
8
    "amount": {
8
    "amount": {
9
      "type": "number",
9
      "type": "number",
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/accounts.inc (-1 / +1 lines)
Lines 6-12 Link Here
6
            [%- CASE 'WRITEOFF'         -%]Writeoff
6
            [%- CASE 'WRITEOFF'         -%]Writeoff
7
            [%- CASE 'FORGIVEN'         -%]Forgiven
7
            [%- CASE 'FORGIVEN'         -%]Forgiven
8
            [%- CASE 'CREDIT'           -%]Credit
8
            [%- CASE 'CREDIT'           -%]Credit
9
            [%- CASE 'LOST_RETURN'      -%]Lost item fee refund
9
            [%- CASE 'LOST_FOUND'       -%]Lost item fee refund
10
            [%- CASE                    -%][% account.credit_type.description | html %]
10
            [%- CASE                    -%][% account.credit_type.description | html %]
11
        [%- END -%]
11
        [%- END -%]
12
    [%- ELSIF account.debit_type_code -%]
12
    [%- ELSIF account.debit_type_code -%]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/account-table.inc (-1 / +1 lines)
Lines 175-181 Link Here
175
            [%- CASE 'WRITEOFF'         -%]Writeoff
175
            [%- CASE 'WRITEOFF'         -%]Writeoff
176
            [%- CASE 'FORGIVEN'         -%]Forgiven
176
            [%- CASE 'FORGIVEN'         -%]Forgiven
177
            [%- CASE 'CREDIT'           -%]Credit
177
            [%- CASE 'CREDIT'           -%]Credit
178
            [%- CASE 'LOST_RETURN'      -%]Lost item fee refund
178
            [%- CASE 'LOST_FOUND'       -%]Lost item fee refund
179
            [%- CASE                    -%][% account.credit_type.description | html %]
179
            [%- CASE                    -%][% account.credit_type.description | html %]
180
        [%- END -%]
180
        [%- END -%]
181
    [%- ELSIF account.debit_type_code -%]
181
    [%- ELSIF account.debit_type_code -%]
(-)a/t/db_dependent/Circulation.t (-26 / +25 lines)
Lines 2172-2178 subtest 'AddReturn | is_overdue' => sub { Link Here
2172
    };
2172
    };
2173
};
2173
};
2174
2174
2175
subtest '_FixAccountForLostAndReturned' => sub {
2175
subtest '_FixAccountForLostAndFound' => sub {
2176
2176
2177
    plan tests => 5;
2177
    plan tests => 5;
2178
2178
Lines 2250-2263 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2250
        );
2250
        );
2251
        $credit->apply( { debits => [ $debts->as_list ], offset_type => 'Writeoff' } );
2251
        $credit->apply( { debits => [ $debts->as_list ], offset_type => 'Writeoff' } );
2252
2252
2253
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2253
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndFound( $item->itemnumber, $patron->id );
2254
        is( $credit_return_id, undef, 'No LOST_RETURN account line added' );
2254
        is( $credit_return_id, undef, 'No LOST_FOUND account line added' );
2255
2255
2256
        $lost_fee_line->discard_changes; # reload from DB
2256
        $lost_fee_line->discard_changes; # reload from DB
2257
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2257
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2258
        is( $lost_fee_line->debit_type_code,
2258
        is( $lost_fee_line->debit_type_code,
2259
            'LOST', 'Lost fee now still has account type of LOST' );
2259
            'LOST', 'Lost fee now still has account type of LOST' );
2260
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2260
        is( $lost_fee_line->status, 'FOUND', "Lost fee now has account status of FOUND");
2261
2261
2262
        is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' );
2262
        is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' );
2263
    };
2263
    };
Lines 2312-2331 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2312
        );
2312
        );
2313
        $credit->apply( { debits => [ $debts->as_list ], offset_type => 'Payment' } );
2313
        $credit->apply( { debits => [ $debts->as_list ], offset_type => 'Payment' } );
2314
2314
2315
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2315
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndFound( $item->itemnumber, $patron->id );
2316
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2316
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2317
2317
2318
        is( $credit_return->credit_type_code, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' );
2318
        is( $credit_return->credit_type_code, 'LOST_FOUND', 'An account line of type LOST_FOUND is added' );
2319
        is( $credit_return->amount + 0,
2319
        is( $credit_return->amount + 0,
2320
            -99.00, 'The account line of type LOST_RETURN has an amount of -99' );
2320
            -99.00, 'The account line of type LOST_FOUND has an amount of -99' );
2321
        is( $credit_return->amountoutstanding + 0,
2321
        is( $credit_return->amountoutstanding + 0,
2322
            -99.00, 'The account line of type LOST_RETURN has an amountoutstanding of -99' );
2322
            -99.00, 'The account line of type LOST_FOUND has an amountoutstanding of -99' );
2323
2323
2324
        $lost_fee_line->discard_changes;
2324
        $lost_fee_line->discard_changes;
2325
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2325
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2326
        is( $lost_fee_line->debit_type_code,
2326
        is( $lost_fee_line->debit_type_code,
2327
            'LOST', 'Lost fee now still has account type of LOST' );
2327
            'LOST', 'Lost fee now still has account type of LOST' );
2328
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2328
        is( $lost_fee_line->status, 'FOUND', "Lost fee now has account status of FOUND");
2329
2329
2330
        is( $patron->account->balance,
2330
        is( $patron->account->balance,
2331
            -99, 'The patron balance is -99, a credit that equals the lost fee payment' );
2331
            -99, 'The patron balance is -99, a credit that equals the lost fee payment' );
Lines 2370-2387 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2370
        is( $lost_fee_line->amountoutstanding + 0,
2370
        is( $lost_fee_line->amountoutstanding + 0,
2371
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2371
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2372
2372
2373
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2373
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndFound( $item->itemnumber, $patron->id );
2374
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2374
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2375
2375
2376
        is( $credit_return->credit_type_code, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' );
2376
        is( $credit_return->credit_type_code, 'LOST_FOUND', 'An account line of type LOST_FOUND is added' );
2377
        is( $credit_return->amount + 0, -99.00, 'The account line of type LOST_RETURN has an amount of -99' );
2377
        is( $credit_return->amount + 0, -99.00, 'The account line of type LOST_FOUND has an amount of -99' );
2378
        is( $credit_return->amountoutstanding + 0, 0, 'The account line of type LOST_RETURN has an amountoutstanding of 0' );
2378
        is( $credit_return->amountoutstanding + 0, 0, 'The account line of type LOST_FOUND has an amountoutstanding of 0' );
2379
2379
2380
        $lost_fee_line->discard_changes;
2380
        $lost_fee_line->discard_changes;
2381
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2381
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2382
        is( $lost_fee_line->debit_type_code,
2382
        is( $lost_fee_line->debit_type_code,
2383
            'LOST', 'Lost fee now still has account type of LOST' );
2383
            'LOST', 'Lost fee now still has account type of LOST' );
2384
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2384
        is( $lost_fee_line->status, 'FOUND', "Lost fee now has account status of FOUND");
2385
2385
2386
        is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' );
2386
        is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' );
2387
    };
2387
    };
Lines 2456-2480 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2456
        $lost_fee_line->discard_changes;
2456
        $lost_fee_line->discard_changes;
2457
        my $outstanding = $lost_fee_line->amountoutstanding;
2457
        my $outstanding = $lost_fee_line->amountoutstanding;
2458
2458
2459
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2459
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndFound( $item->itemnumber, $patron->id );
2460
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2460
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2461
2461
2462
        is( $account->balance, $processfee_amount - $payment_amount, 'Balance is PROCESSING - PAYMENT (LOST_RETURN)' );
2462
        is( $account->balance, $processfee_amount - $payment_amount, 'Balance is PROCESSING - PAYMENT (LOST_FOUND)' );
2463
2463
2464
        $lost_fee_line->discard_changes;
2464
        $lost_fee_line->discard_changes;
2465
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2465
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2466
        is( $lost_fee_line->debit_type_code,
2466
        is( $lost_fee_line->debit_type_code,
2467
            'LOST', 'Lost fee now still has account type of LOST' );
2467
            'LOST', 'Lost fee now still has account type of LOST' );
2468
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2468
        is( $lost_fee_line->status, 'FOUND', "Lost fee now has account status of FOUND");
2469
2469
2470
        is( $credit_return->credit_type_code, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' );
2470
        is( $credit_return->credit_type_code, 'LOST_FOUND', 'An account line of type LOST_FOUND is added' );
2471
        is( $credit_return->amount + 0,
2471
        is( $credit_return->amount + 0,
2472
            ($payment_amount + $outstanding ) * -1,
2472
            ($payment_amount + $outstanding ) * -1,
2473
            'The account line of type LOST_RETURN has an amount equal to the payment + outstanding'
2473
            'The account line of type LOST_FOUND has an amount equal to the payment + outstanding'
2474
        );
2474
        );
2475
        is( $credit_return->amountoutstanding + 0,
2475
        is( $credit_return->amountoutstanding + 0,
2476
            $payment_amount * -1,
2476
            $payment_amount * -1,
2477
            'The account line of type LOST_RETURN has an amountoutstanding equal to the payment'
2477
            'The account line of type LOST_FOUND has an amountoutstanding equal to the payment'
2478
        );
2478
        );
2479
2479
2480
        is( $account->balance,
2480
        is( $account->balance,
Lines 2552-2561 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2552
2552
2553
        t::lib::Mocks::mock_preference( 'AccountAutoReconcile', 1 );
2553
        t::lib::Mocks::mock_preference( 'AccountAutoReconcile', 1 );
2554
2554
2555
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item_id, $patron->id );
2555
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndFound( $item_id, $patron->id );
2556
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2556
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2557
2557
2558
        is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PROCESSING - payment (LOST_RETURN)' );
2558
        is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PROCESSING - payment (LOST_FOUND)' );
2559
2559
2560
        my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, debit_type_code => 'OVERDUE', status => 'UNRETURNED' })->next;
2560
        my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, debit_type_code => 'OVERDUE', status => 'UNRETURNED' })->next;
2561
        is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' );
2561
        is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' );
Lines 2647-2653 subtest '_FixOverduesOnReturn' => sub { Link Here
2647
    is( $accountline->status, 'RETURNED', 'Passed status has been used to set as RETURNED )');
2647
    is( $accountline->status, 'RETURNED', 'Passed status has been used to set as RETURNED )');
2648
};
2648
};
2649
2649
2650
subtest '_FixAccountForLostAndReturned returns undef if patron is deleted' => sub {
2650
subtest '_FixAccountForLostAndFound returns undef if patron is deleted' => sub {
2651
    plan tests => 1;
2651
    plan tests => 1;
2652
2652
2653
    my $manager = $builder->build_object({ class => "Koha::Patrons" });
2653
    my $manager = $builder->build_object({ class => "Koha::Patrons" });
Lines 2683-2691 subtest '_FixAccountForLostAndReturned returns undef if patron is deleted' => su Link Here
2683
2683
2684
    $patron->delete();
2684
    $patron->delete();
2685
2685
2686
    my $return_value = C4::Circulation::_FixAccountForLostAndReturned( $patron->id, $item->itemnumber );
2686
    my $return_value = C4::Circulation::_FixAccountForLostAndFound( $patron->id, $item->itemnumber );
2687
2687
2688
    is( $return_value, undef, "_FixAccountForLostAndReturned returns undef if patron is deleted" );
2688
    is( $return_value, undef, "_FixAccountForLostAndFound returns undef if patron is deleted" );
2689
2689
2690
};
2690
};
2691
2691
2692
- 

Return to bug 22750