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

(-)a/C4/Circulation.pm (-11 / +13 lines)
Lines 1455-1461 sub AddIssue { Link Here
1455
                    )
1455
                    )
1456
                  )
1456
                  )
1457
                {
1457
                {
1458
                    _FixAccountForLostAndReturned( $item_object->itemnumber, undef,
1458
                    _FixAccountForLostAndFound( $item_object->itemnumber, undef,
1459
                        $item_object->barcode );
1459
                        $item_object->barcode );
1460
                }
1460
                }
1461
            }
1461
            }
Lines 2037-2043 sub AddReturn { Link Here
2037
                )
2037
                )
2038
              )
2038
              )
2039
            {
2039
            {
2040
                _FixAccountForLostAndReturned( $item->itemnumber,
2040
                _FixAccountForLostAndFound( $item->itemnumber,
2041
                    $borrowernumber, $barcode );
2041
                    $borrowernumber, $barcode );
2042
                $messages->{'LostItemFeeRefunded'} = 1;
2042
                $messages->{'LostItemFeeRefunded'} = 1;
2043
            }
2043
            }
Lines 2443-2451 sub _FixOverduesOnReturn { Link Here
2443
    return $result;
2443
    return $result;
2444
}
2444
}
2445
2445
2446
=head2 _FixAccountForLostAndReturned
2446
=head2 _FixAccountForLostAndFound
2447
2447
2448
  &_FixAccountForLostAndReturned($itemnumber, [$borrowernumber, $barcode]);
2448
  &_FixAccountForLostAndFound($itemnumber, [$borrowernumber, $barcode]);
2449
2449
2450
Finds the most recent lost item charge for this item and refunds the borrower
2450
Finds the most recent lost item charge for this item and refunds the borrower
2451
appropriatly, taking into account any payments or writeoffs already applied
2451
appropriatly, taking into account any payments or writeoffs already applied
Lines 2455-2461 Internal function, not exported, called only by AddReturn. Link Here
2455
2455
2456
=cut
2456
=cut
2457
2457
2458
sub _FixAccountForLostAndReturned {
2458
sub _FixAccountForLostAndFound {
2459
    my $itemnumber     = shift or return;
2459
    my $itemnumber     = shift or return;
2460
    my $borrowernumber = @_ ? shift : undef;
2460
    my $borrowernumber = @_ ? shift : undef;
2461
    my $item_id        = @_ ? shift : $itemnumber;  # Send the barcode if you want that logged in the description
2461
    my $item_id        = @_ ? shift : $itemnumber;  # Send the barcode if you want that logged in the description
Lines 2467-2473 sub _FixAccountForLostAndReturned { Link Here
2467
        {
2467
        {
2468
            itemnumber      => $itemnumber,
2468
            itemnumber      => $itemnumber,
2469
            debit_type_code => 'LOST',
2469
            debit_type_code => 'LOST',
2470
            status          => [ undef, { '<>' => 'RETURNED' } ]
2470
            status          => [ undef, { '<>' => 'FOUND' } ]
2471
        },
2471
        },
2472
        {
2472
        {
2473
            order_by => { -desc => [ 'date', 'accountlines_id' ] }
2473
            order_by => { -desc => [ 'date', 'accountlines_id' ] }
Lines 2506-2516 sub _FixAccountForLostAndReturned { Link Here
2506
    if ( $credit_total > 0 ) {
2506
    if ( $credit_total > 0 ) {
2507
        my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
2507
        my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
2508
        $credit = $account->add_credit(
2508
        $credit = $account->add_credit(
2509
            {   amount      => $credit_total,
2509
            {
2510
                description => 'Item Returned ' . $item_id,
2510
                amount      => $credit_total,
2511
                type        => 'LOST_RETURN',
2511
                description => 'Item found ' . $item_id,
2512
                type        => 'LOST_FOUND',
2512
                interface   => C4::Context->interface,
2513
                interface   => C4::Context->interface,
2513
                library_id  => $branchcode
2514
                library_id  => $branchcode,
2515
                itemnumber  => $itemnumber
2514
            }
2516
            }
2515
        );
2517
        );
2516
2518
Lines 2518-2524 sub _FixAccountForLostAndReturned { Link Here
2518
    }
2520
    }
2519
2521
2520
    # Update the account status
2522
    # Update the account status
2521
    $accountline->discard_changes->status('RETURNED');
2523
    $accountline->discard_changes->status('FOUND');
2522
    $accountline->store;
2524
    $accountline->store;
2523
2525
2524
    if ( defined $account and C4::Context->preference('AccountAutoReconcile') ) {
2526
    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 'Refund'           -%]Refund
10
            [%- CASE 'Refund'           -%]Refund
11
            [%- CASE                    -%][% account.credit_type.description | html %]
11
            [%- CASE                    -%][% account.credit_type.description | html %]
12
        [%- END -%]
12
        [%- END -%]
(-)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 (-13 / +12 lines)
Lines 2425-2431 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2425
        $credit->apply( { debits => [ $debts->as_list ], offset_type => 'Writeoff' } );
2425
        $credit->apply( { debits => [ $debts->as_list ], offset_type => 'Writeoff' } );
2426
2426
2427
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2427
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2428
        is( $credit_return_id, undef, 'No LOST_RETURN account line added' );
2428
        is( $credit_return_id, undef, 'No LOST_FOUND account line added' );
2429
2429
2430
        $lost_fee_line->discard_changes; # reload from DB
2430
        $lost_fee_line->discard_changes; # reload from DB
2431
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2431
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
Lines 2489-2499 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2489
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2489
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2490
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2490
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2491
2491
2492
        is( $credit_return->credit_type_code, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' );
2492
        is( $credit_return->credit_type_code, 'LOST_FOUND', 'An account line of type LOST_FOUND is added' );
2493
        is( $credit_return->amount + 0,
2493
        is( $credit_return->amount + 0,
2494
            -99.00, 'The account line of type LOST_RETURN has an amount of -99' );
2494
            -99.00, 'The account line of type LOST_FOUND has an amount of -99' );
2495
        is( $credit_return->amountoutstanding + 0,
2495
        is( $credit_return->amountoutstanding + 0,
2496
            -99.00, 'The account line of type LOST_RETURN has an amountoutstanding of -99' );
2496
            -99.00, 'The account line of type LOST_FOUND has an amountoutstanding of -99' );
2497
2497
2498
        $lost_fee_line->discard_changes;
2498
        $lost_fee_line->discard_changes;
2499
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2499
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
Lines 2547-2555 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2547
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2547
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2548
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2548
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2549
2549
2550
        is( $credit_return->credit_type_code, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' );
2550
        is( $credit_return->credit_type_code, 'LOST_FOUND', 'An account line of type LOST_FOUND is added' );
2551
        is( $credit_return->amount + 0, -99.00, 'The account line of type LOST_RETURN has an amount of -99' );
2551
        is( $credit_return->amount + 0, -99.00, 'The account line of type LOST_FOUND has an amount of -99' );
2552
        is( $credit_return->amountoutstanding + 0, 0, 'The account line of type LOST_RETURN has an amountoutstanding of 0' );
2552
        is( $credit_return->amountoutstanding + 0, 0, 'The account line of type LOST_FOUND has an amountoutstanding of 0' );
2553
2553
2554
        $lost_fee_line->discard_changes;
2554
        $lost_fee_line->discard_changes;
2555
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2555
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
Lines 2633-2639 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2633
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2633
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2634
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2634
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2635
2635
2636
        is( $account->balance, $processfee_amount - $payment_amount, 'Balance is PROCESSING - PAYMENT (LOST_RETURN)' );
2636
        is( $account->balance, $processfee_amount - $payment_amount, 'Balance is PROCESSING - PAYMENT (LOST_FOUND)' );
2637
2637
2638
        $lost_fee_line->discard_changes;
2638
        $lost_fee_line->discard_changes;
2639
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2639
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
Lines 2641-2654 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2641
            'LOST', 'Lost fee now still has account type of LOST' );
2641
            'LOST', 'Lost fee now still has account type of LOST' );
2642
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2642
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2643
2643
2644
        is( $credit_return->credit_type_code, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' );
2644
        is( $credit_return->credit_type_code, 'LOST_FOUND', 'An account line of type LOST_FOUND is added' );
2645
        is( $credit_return->amount + 0,
2645
        is( $credit_return->amount + 0,
2646
            ($payment_amount + $outstanding ) * -1,
2646
            ($payment_amount + $outstanding ) * -1,
2647
            'The account line of type LOST_RETURN has an amount equal to the payment + outstanding'
2647
            'The account line of type LOST_FOUND has an amount equal to the payment + outstanding'
2648
        );
2648
        );
2649
        is( $credit_return->amountoutstanding + 0,
2649
        is( $credit_return->amountoutstanding + 0,
2650
            $payment_amount * -1,
2650
            $payment_amount * -1,
2651
            'The account line of type LOST_RETURN has an amountoutstanding equal to the payment'
2651
            'The account line of type LOST_FOUND has an amountoutstanding equal to the payment'
2652
        );
2652
        );
2653
2653
2654
        is( $account->balance,
2654
        is( $account->balance,
Lines 2729-2735 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2729
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item_id, $patron->id );
2729
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item_id, $patron->id );
2730
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2730
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2731
2731
2732
        is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PROCESSING - payment (LOST_RETURN)' );
2732
        is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PROCESSING - payment (LOST_FOUND)' );
2733
2733
2734
        my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, debit_type_code => 'OVERDUE', status => 'UNRETURNED' })->next;
2734
        my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, debit_type_code => 'OVERDUE', status => 'UNRETURNED' })->next;
2735
        is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' );
2735
        is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' );
2736
- 

Return to bug 24592