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

(-)a/C4/Circulation.pm (-6 / +143 lines)
Lines 1508-1513 sub AddIssue { Link Here
1508
                UpdateTotalIssues( $item_object->biblionumber, 1 );
1508
                UpdateTotalIssues( $item_object->biblionumber, 1 );
1509
            }
1509
            }
1510
1510
1511
            # Record if item was lost
1512
            my $was_lost = $item_object->itemlost;
1513
1511
            $item_object->issues( ( $item_object->issues || 0 ) + 1);
1514
            $item_object->issues( ( $item_object->issues || 0 ) + 1);
1512
            $item_object->holdingbranch(C4::Context->userenv->{'branch'});
1515
            $item_object->holdingbranch(C4::Context->userenv->{'branch'});
1513
            $item_object->itemlost(0);
1516
            $item_object->itemlost(0);
Lines 1516-1521 sub AddIssue { Link Here
1516
            $item_object->store({log_action => 0});
1519
            $item_object->store({log_action => 0});
1517
            ModDateLastSeen( $item_object->itemnumber );
1520
            ModDateLastSeen( $item_object->itemnumber );
1518
1521
1522
            # If the item was lost, it has now been found, restore/charge the overdue if necessary
1523
            if ($was_lost) {
1524
                my $lostreturn_policy =
1525
                  Koha::CirculationRules->get_lostreturn_policy(
1526
                    {
1527
                        return_branch => C4::Context->userenv->{branch},
1528
                        item          => $item_object
1529
                    }
1530
                  );
1531
1532
                if ($lostreturn_policy) {
1533
                    if ( $lostreturn_policy eq 'charge' ) {
1534
                        $actualissue //= Koha::Old::Checkouts->search(
1535
                            { itemnumber => $item_unblessed->{itemnumber} },
1536
                            {
1537
                                order_by => { '-desc' => 'returndate' },
1538
                                rows     => 1
1539
                            }
1540
                        )->single;
1541
                        unless ( exists( $borrower->{branchcode} ) ) {
1542
                            my $patron = $issue->patron;
1543
                            $borrower = $patron->unblessed;
1544
                        }
1545
                        _CalculateAndUpdateFine(
1546
                            {
1547
                                issue       => $actualissue,
1548
                                item        => $item_unblessed,
1549
                                borrower    => $borrower,
1550
                                return_date => $issuedate
1551
                            }
1552
                        );
1553
                        _FixOverduesOnReturn( $borrower->{borrowernumber},
1554
                            $item_object->itemnumber, undef, 'RENEWED' );
1555
                    }
1556
                    elsif ( $lostreturn_policy eq 'restore' ) {
1557
                        _RestoreOverdueForLostAndFound(
1558
                            $item_object->itemnumber );
1559
                    }
1560
                }
1561
1562
            }
1563
1519
            # If it costs to borrow this book, charge it to the patron's account.
1564
            # If it costs to borrow this book, charge it to the patron's account.
1520
            my ( $charge, $itemtype ) = GetIssuingCharges( $item_object->itemnumber, $borrower->{'borrowernumber'} );
1565
            my ( $charge, $itemtype ) = GetIssuingCharges( $item_object->itemnumber, $borrower->{'borrowernumber'} );
1521
            if ( $charge && $charge > 0 ) {
1566
            if ( $charge && $charge > 0 ) {
Lines 2021-2026 sub AddReturn { Link Here
2021
        $messages->{'WasLost'} = 1;
2066
        $messages->{'WasLost'} = 1;
2022
        unless ( C4::Context->preference("BlockReturnOfLostItems") ) {
2067
        unless ( C4::Context->preference("BlockReturnOfLostItems") ) {
2023
            $messages->{'LostItemFeeRefunded'} = $updated_item->{_refunded};
2068
            $messages->{'LostItemFeeRefunded'} = $updated_item->{_refunded};
2069
            
2070
            my $lostreturn_policy =
2071
              Koha::CirculationRules->get_lostreturn_policy(
2072
                {
2073
                    return_branch => C4::Context->userenv->{branch},
2074
                    item          => $updated_item
2075
                }
2076
              );
2077
2078
            if ($lostreturn_policy) {
2079
                if ( $lostreturn_policy eq 'charge' ) {
2080
                    $issue //= Koha::Old::Checkouts->search(
2081
                        { itemnumber => $item->itemnumber },
2082
                        { order_by   => { '-desc' => 'returndate' }, rows => 1 }
2083
                    )->single;
2084
                    unless (exists($patron_unblessed->{branchcode})) {
2085
                        my $patron = $issue->patron;
2086
                        $patron_unblessed = $patron->unblessed;
2087
                    }
2088
                    _CalculateAndUpdateFine(
2089
                        {
2090
                            issue       => $issue,
2091
                            item        => $item->unblessed,
2092
                            borrower    => $patron_unblessed,
2093
                            return_date => $return_date
2094
                        }
2095
                    );
2096
                    _FixOverduesOnReturn( $patron_unblessed->{borrowernumber},
2097
                        $item->itemnumber, undef, 'RETURNED' );
2098
                    $messages->{'LostItemFeeCharged'} = 1;
2099
                }
2100
                elsif ( $lostreturn_policy eq 'restore' ) {
2101
                    _RestoreOverdueForLostAndFound( $item->itemnumber );
2102
                    $messages->{'LostItemFeeRestored'} = 1;
2103
                }
2104
            }
2024
        }
2105
        }
2025
    }
2106
    }
2026
2107
Lines 2462-2475 sub _FixOverduesOnReturn { Link Here
2462
                if (C4::Context->preference("FinesLog")) {
2543
                if (C4::Context->preference("FinesLog")) {
2463
                    &logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item");
2544
                    &logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item");
2464
                }
2545
                }
2546
            }
2465
2547
2466
                $accountline->status('FORGIVEN');
2548
            $accountline->status($status);
2467
                $accountline->store();
2549
            return $accountline->store();
2468
            } else {
2550
        }
2469
                $accountline->status($status);
2551
    );
2470
                $accountline->store();
2471
2552
2472
            }
2553
    return $result;
2554
}
2555
2556
=head2 _RestoreOverdueForLostAndFound
2557
2558
   &_RestoreOverdueForLostAndFound( $itemnumber );
2559
2560
C<$itemnumber> itemnumber
2561
2562
Internal function
2563
2564
=cut
2565
2566
sub _RestoreOverdueForLostAndFound {
2567
    my ( $item ) = @_;
2568
2569
    unless( $item ) {
2570
        warn "_RestoreOverdueForLostAndFound() not supplied valid itemnumber";
2571
        return;
2572
    }
2573
2574
    my $schema = Koha::Database->schema;
2575
2576
    my $result = $schema->txn_do(
2577
        sub {
2578
            # check for lost overdue fine
2579
            my $accountlines = Koha::Account::Lines->search(
2580
                {
2581
                    itemnumber      => $item,
2582
                    debit_type_code => 'OVERDUE',
2583
                    status          => 'LOST'
2584
                },
2585
                {
2586
                    order_by => { '-desc' => 'date' },
2587
                    rows     => 1
2588
                }
2589
            );
2590
            return 0 unless $accountlines->count; # no warning, there's just nothing to fix
2591
2592
            # Update status of fine
2593
            my $overdue = $accountlines->next;
2594
            $overdue->status('RETURNED')->store();
2595
2596
            # Find related forgive credit
2597
            my $refunds = $overdue->credits(
2598
                {
2599
                    credit_type_code => 'FORGIVEN',
2600
                    itemnumber       => $item,
2601
                    status           => [ { '!=' => 'VOID' }, undef ]
2602
                },
2603
                { order_by => { '-desc' => 'date' }, rows => 1 }
2604
            );
2605
            return 0 unless $refunds->count; # no warning, there's just nothing to fix
2606
2607
            # Revert the forgive credit
2608
            my $refund = $refunds->next;
2609
            return $refund->void();
2473
        }
2610
        }
2474
    );
2611
    );
2475
2612
(-)a/Koha/CirculationRules.pm (-4 / +15 lines)
Lines 46-52 Any attempt to set a rule with a nonsensical scope (for instance, setting the C< Link Here
46
=cut
46
=cut
47
47
48
our $RULE_KINDS = {
48
our $RULE_KINDS = {
49
    refund => {
49
    lostreturn => {
50
        scope => [ 'branchcode' ],
50
        scope => [ 'branchcode' ],
51
    },
51
    },
52
52
Lines 428-434 sub get_onshelfholds_policy { Link Here
428
428
429
=head3 get_lostreturn_policy
429
=head3 get_lostreturn_policy
430
430
431
  my $refund = Koha::CirculationRules->get_lostreturn_policy( { return_branch => $return_branch, item => $item } );
431
  my $lostrefund_policy = Koha::CirculationRules->get_lostreturn_policy( { return_branch => $return_branch, item => $item } );
432
433
Return values are:
434
435
=over 2
436
437
=item 0 - Do not refund
438
=item refund - Refund the lost item charge
439
=item restore - Refund the lost item charge and restore the original overdue fine
440
=item charge - Refund the lost item charge and charge a new overdue fine
441
442
=back
432
443
433
=cut
444
=cut
434
445
Lines 449-459 sub get_lostreturn_policy { Link Here
449
    my $rule = Koha::CirculationRules->get_effective_rule(
460
    my $rule = Koha::CirculationRules->get_effective_rule(
450
        {
461
        {
451
            branchcode => $branch,
462
            branchcode => $branch,
452
            rule_name  => 'refund',
463
            rule_name  => 'lostreturn',
453
        }
464
        }
454
    );
465
    );
455
466
456
    return $rule ? $rule->rule_value : 1;
467
    return $rule ? $rule->rule_value : 'refund';
457
}
468
}
458
469
459
=head3 article_requestable_rules
470
=head3 article_requestable_rules
(-)a/admin/smart-rules.pl (-8 / +8 lines)
Lines 523-538 elsif ($op eq "add-branch-item") { Link Here
523
}
523
}
524
elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) {
524
elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) {
525
525
526
    my $refund = $input->param('refund');
526
    my $lostreturn = $input->param('lostreturn');
527
527
528
    if ( $refund eq '*' ) {
528
    if ( $lostreturn eq '*' ) {
529
        if ( $branch ne '*' ) {
529
        if ( $branch ne '*' ) {
530
            # only do something for $refund eq '*' if branch-specific
530
            # only do something for $lostreturn eq '*' if branch-specific
531
            Koha::CirculationRules->set_rules(
531
            Koha::CirculationRules->set_rules(
532
                {
532
                {
533
                    branchcode   => $branch,
533
                    branchcode   => $branch,
534
                    rules        => {
534
                    rules        => {
535
                        refund => undef
535
                        lostreturn => undef
536
                    }
536
                    }
537
                }
537
                }
538
            );
538
            );
Lines 542-559 elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) { Link Here
542
            {
542
            {
543
                branchcode   => $branch,
543
                branchcode   => $branch,
544
                rules        => {
544
                rules        => {
545
                    refund => $refund
545
                    lostreturn => $lostreturn
546
                }
546
                }
547
            }
547
            }
548
        );
548
        );
549
    }
549
    }
550
}
550
}
551
551
552
my $refundLostItemFeeRule = Koha::CirculationRules->find({ branchcode => ($branch eq '*') ? undef : $branch, rule_name => 'refund' });
552
my $refundLostItemFeeRule = Koha::CirculationRules->find({ branchcode => ($branch eq '*') ? undef : $branch, rule_name => 'lostreturn' });
553
my $defaultLostItemFeeRule = Koha::CirculationRules->find({ branchcode => undef, rule_name => 'refund' });
553
my $defaultLostItemFeeRule = Koha::CirculationRules->find({ branchcode => undef, rule_name => 'lostreturn' });
554
$template->param(
554
$template->param(
555
    refundLostItemFeeRule => $refundLostItemFeeRule,
555
    refundLostItemFeeRule => $refundLostItemFeeRule,
556
    defaultRefundRule     => $defaultLostItemFeeRule ? $defaultLostItemFeeRule->rule_value : 1
556
    defaultRefundRule     => $defaultLostItemFeeRule ? $defaultLostItemFeeRule->rule_value : 'refund'
557
);
557
);
558
558
559
my $patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description'] });
559
my $patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description'] });
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-32 / +56 lines)
Lines 762-784 Link Here
762
                </tr>
762
                </tr>
763
                <tr>
763
                <tr>
764
                    <td>
764
                    <td>
765
                        <select name="refund">
765
                        <select name="lostreturn">
766
                          [%# Default branch %]
766
                          [%# Default branch %]
767
                          [% IF ( current_branch == '*' ) %]
767
                          [% IF ( current_branch == '*' ) %]
768
                            [% IF ( defaultRefundRule ) %]
768
                            [% IF ( defaultRefundRule == 'refund' ) %]
769
                            <option value="1" selected="selected">
769
                            <option value="refund" selected="selected">Refund lost item charge</option>
770
                            <option value="charge">Refund lost item charge and charge new overdue fine</option>
771
                            <option value="restore">Refund lost item charge and restore overdue fine</option>
772
                            <option value="0">Leave lost item charge</option>
773
                            [% ELSIF ( defaultRefundRule == 'charge' ) %]
774
                            <option value="refund">Refund lost item charge</option>
775
                            <option value="charge" selected="selected">Refund lost item charge and charge new overdue fine</option>
776
                            <option value="restore">Refund lost item charge and restore overdue fine</option>
777
                            <option value="0">Leave lost item charge</option>
778
                            [% ELSIF ( defaultRefundRule == 'restore' ) %]
779
                            <option value="refund">Refund lost item charge</option>
780
                            <option value="charge">Refund lost item charge and charge new overdue fine</option>
781
                            <option value="restore" selected="selected">Refund lost item charge and restore overdue fine</option>
782
                            <option value="0">Leave lost item charge</option>
783
                            [% ELSIF ( defaultRefundRule == 0 ) %]
784
                            <option value="refund">Refund lost item charge</option>
785
                            <option value="charge">Refund lost item charge and charge new overdue fine</option>
786
                            <option value="restore">Refund lost item charge and restore overdue fine</option>
787
                            <option value="0" selected="selected">Leave lost item charge</option>
770
                            [% ELSE %]
788
                            [% ELSE %]
771
                            <option value="1">
789
                            <option value="refund">Refund lost item charge</option>
790
                            <option value="charge">Refund lost item charge and charge new overdue fine</option>
791
                            <option value="restore">Refund lost item charge and restore overdue fine</option>
792
                            <option value="0">Leave lost item charge</option>
772
                            [% END %]
793
                            [% END %]
773
                                Yes
774
                            </option>
775
                            [% IF ( not defaultRefundRule ) %]
776
                            <option value="0" selected="selected">
777
                            [% ELSE %]
778
                            <option value="0">
779
                            [% END %]
780
                                No
781
                            </option>
782
                          [% ELSE %]
794
                          [% ELSE %]
783
                          [%# Branch-specific %]
795
                          [%# Branch-specific %]
784
                            [% IF ( not refundLostItemFeeRule ) %]
796
                            [% IF ( not refundLostItemFeeRule ) %]
Lines 786-815 Link Here
786
                            [% ELSE %]
798
                            [% ELSE %]
787
                                <option value="*">
799
                                <option value="*">
788
                            [% END %]
800
                            [% END %]
789
                              [% IF defaultRefundRule %]
801
                              [% IF defaultRefundRule == 'refund' %]
790
                                Use default (Yes)
802
                                Use default (Refund lost item charge)
803
                              [% ELSIF defaultRefundRule == 'charge' %]
804
                                Use default (Refund lost item charge and restore overdue fine)
805
                              [% ELSIF defaultRefundRule == 'restore' %]
806
                                Use default (Refund lost item charge and charge new overdue fine)
791
                              [% ELSE %]
807
                              [% ELSE %]
792
                                Use default (No)
808
                                Use default (Leave lost item charge)
793
                              [% END %]
809
                              [% END %]
794
                                </option>
810
                                </option>
795
                            [% IF ( not refundLostItemFeeRule ) %]
811
                            [% IF ( not refundLostItemFeeRule ) %]
796
                                <option value="1">Yes</option>
812
                                <option value="refund">Refund lost item charge</option>
797
                                <option value="0">No</option>
813
                                <option value="charge">Refund lost item charge and charge new overdue fine</option>
814
                                <option value="restore">Refund lost item charge and restore overdue fine</option>
815
                                <option value="0">Leave lost item charge</option>
798
                            [% ELSE %]
816
                            [% ELSE %]
799
                                [% IF ( refundLostItemFeeRule.rule_value ) %]
817
                                [% IF ( refundLostItemFeeRule.rule_value == 'refund' ) %]
800
                                <option value="1" selected="selected">
818
                                <option value="refund" selected="selected">Refund lost item charge</option>
801
                                [% ELSE %]
819
                                <option value="charge">Refund lost item charge and charge new overdue fine</option>
802
                                <option value="1">
820
                                <option value="restore">Refund lost item charge and restore overdue fine</option>
821
                                <option value="0">Leave lost item charge</option>
822
                                [% ELSIF ( refundLostItemFeeRule.rule_value == 'charge' ) %]
823
                                <option value="refund">Refund lost item charge</option>
824
                                <option value="charge" selected="selected">Refund lost item charge and charge new overdue fine</option>
825
                                <option value="restore">Refund lost item charge and restore overdue fine</option>
826
                                <option value="0">Leave lost item charge</option>
827
                                [% ELSIF ( refundLostItemFeeRule.rule_value == 'restore' ) %]
828
                                <option value="refund">Refund lost item charge</option>
829
                                <option value="charge">Refund lost item charge and charge new overdue fine</option>
830
                                <option value="restore" selected="selected">Refund lost item charge and restore overdue fine</option>
831
                                <option value="0">Leave lost item charge</option>
832
                                [% ELSIF ( refundLostItemFeeRule.rule_value == 0 ) %]
833
                                <option value="refund">Refund lost item charge</option>
834
                                <option value="charge">Refund lost item charge and charge new overdue fine</option>
835
                                <option value="restore">Refund lost item charge and restore overdue fine</option>
836
                                <option value="0" selected="selected">Leave lost item charge</option>
803
                                [% END %]
837
                                [% END %]
804
                                    Yes
805
                                </option>
806
                                [% IF ( not refundLostItemFeeRule.rule_value ) %]
807
                                <option value="0" selected="selected">
808
                                [% ELSE %]
809
                                <option value="0">
810
                                [% END %]
811
                                    No
812
                                </option>
813
                            [% END %]
838
                            [% END %]
814
                          [% END %]
839
                          [% END %]
815
                        </select>
840
                        </select>
816
- 

Return to bug 23091