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

(-)a/C4/Circulation.pm (-23 / +134 lines)
Lines 1453-1471 sub AddIssue { Link Here
1453
                UpdateTotalIssues( $item_object->biblionumber, 1 );
1453
                UpdateTotalIssues( $item_object->biblionumber, 1 );
1454
            }
1454
            }
1455
1455
1456
            ## If item was lost, it has now been found, reverse any list item charges if necessary.
1456
            ## If item was lost, it has now been found, reverse any lost item charges if necessary.
1457
            if ( $item_object->itemlost ) {
1457
            if ( $item_object->itemlost ) {
1458
                if (
1458
                my $lostreturn_policy =
1459
                    Koha::CirculationRules->get_lostreturn_policy(
1459
                  Koha::CirculationRules->get_lostreturn_policy(
1460
                        {
1460
                    {
1461
                            return_branch => C4::Context->userenv->{branch},
1461
                        return_branch => C4::Context->userenv->{branch},
1462
                            item          => $item_object
1462
                        item          => $item_object
1463
                        }
1463
                    }
1464
                    )
1464
                  );
1465
                  )
1465
1466
                {
1466
                if ($lostreturn_policy) {
1467
                    _FixAccountForLostAndFound( $item_object->itemnumber, undef,
1467
                    _FixAccountForLostAndFound( $item_object->itemnumber, undef,
1468
                        $item_object->barcode );
1468
                        $item_object->barcode );
1469
1470
                    if ( $lostreturn_policy eq 'charge' ) {
1471
                        $actualissue //= Koha::Old::Checkouts->search(
1472
                            { itemnumber => $item_unblessed->{itemnumber} },
1473
                            {
1474
                                order_by => { '-desc' => 'returndate' },
1475
                                rows     => 1
1476
                            }
1477
                        )->single;
1478
1479
                        _CalculateAndUpdateFine(
1480
                            {
1481
                                issue    => $actualissue,
1482
                                item     => $item_unblessed,
1483
                                borrower => $borrower
1484
                            }
1485
                        );
1486
                        _FixOverduesOnReturn( $borrower->{borrowernumber},
1487
                            $item_object->itemnumber, undef, 'RENEWED' );
1488
                    }
1489
                    elsif ( $lostreturn_policy eq 'restore' ) {
1490
                        _RestoreOverdueForLostAndFound(
1491
                            $borrower->{'borrowernumber'},
1492
                            $item_object->itemnumber
1493
                        );
1494
                    }
1469
                }
1495
                }
1470
            }
1496
            }
1471
1497
Lines 2038-2055 sub AddReturn { Link Here
2038
    if ( $item->itemlost ) {
2064
    if ( $item->itemlost ) {
2039
        $messages->{'WasLost'} = 1;
2065
        $messages->{'WasLost'} = 1;
2040
        unless ( C4::Context->preference("BlockReturnOfLostItems") ) {
2066
        unless ( C4::Context->preference("BlockReturnOfLostItems") ) {
2041
            if (
2067
            my $lostreturn_policy =
2042
                Koha::CirculationRules->get_lostreturn_policy(
2068
              Koha::CirculationRules->get_lostreturn_policy(
2043
                    {
2069
                {
2044
                        return_branch => C4::Context->userenv->{branch},
2070
                    return_branch => C4::Context->userenv->{branch},
2045
                        item          => $item,
2071
                    item          => $item
2046
                    }
2072
                }
2047
                  )
2073
              );
2048
              )
2074
2049
            {
2075
            if ($lostreturn_policy) {
2050
                _FixAccountForLostAndFound( $item->itemnumber,
2076
                _FixAccountForLostAndFound( $item->itemnumber,
2051
                    $borrowernumber, $barcode );
2077
                    $borrowernumber, $barcode );
2052
                $messages->{'LostItemFeeRefunded'} = 1;
2078
                $messages->{'LostItemFeeRefunded'} = 1;
2079
2080
                if ( $lostreturn_policy eq 'charge' ) {
2081
                    $issue //= Koha::Old::Checkouts->search(
2082
                        { itemnumber => $item->itemnumber },
2083
                        { order_by   => { '-desc' => 'returndate' }, rows => 1 }
2084
                    )->single;
2085
                    _CalculateAndUpdateFine(
2086
                        {
2087
                            issue       => $issue,
2088
                            item        => $item->unblessed,
2089
                            borrower    => $patron_unblessed,
2090
                            return_date => $return_date
2091
                        }
2092
                    );
2093
                    $messages->{'LostItemFeeCharged'} = 1;
2094
                }
2095
                elsif ( $lostreturn_policy eq 'restore' ) {
2096
                    _RestoreOverdueForLostAndFound( $borrowernumber,
2097
                        $item->itemnumber );
2098
                    $messages->{'LostItemFeeRestored'} = 1;
2099
                }
2053
            }
2100
            }
2054
        }
2101
        }
2055
    }
2102
    }
Lines 2454-2468 sub _FixOverduesOnReturn { Link Here
2454
2501
2455
                $credit->apply({ debits => [ $accountline ], offset_type => 'Forgiven' });
2502
                $credit->apply({ debits => [ $accountline ], offset_type => 'Forgiven' });
2456
2503
2457
                $accountline->status('FORGIVEN');
2458
2459
                if (C4::Context->preference("FinesLog")) {
2504
                if (C4::Context->preference("FinesLog")) {
2460
                    &logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item");
2505
                    &logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item");
2461
                }
2506
                }
2462
            } else {
2463
                $accountline->status($status);
2464
            }
2507
            }
2465
2508
2509
            $accountline->status($status);
2466
            return $accountline->store();
2510
            return $accountline->store();
2467
        }
2511
        }
2468
    );
2512
    );
Lines 2559-2564 sub _FixAccountForLostAndFound { Link Here
2559
    return ($credit) ? $credit->id : undef;
2603
    return ($credit) ? $credit->id : undef;
2560
}
2604
}
2561
2605
2606
=head2 _RestoreOverdueForLostAndFound
2607
2608
   &_RestoreOverdueForLostAndFound($borrowernumber, $itemnumber );
2609
2610
C<$borrowernumber> borrowernumber
2611
2612
C<$itemnumber> itemnumber
2613
2614
Internal function
2615
2616
=cut
2617
2618
sub _RestoreOverdueForLostAndFound {
2619
    my ( $borrowernumber, $item ) = @_;
2620
2621
    unless( $borrowernumber ) {
2622
        warn "_RestoreOverdueForLostAndFound() not supplied valid borrowernumber";
2623
        return;
2624
    }
2625
    unless( $item ) {
2626
        warn "_RestoreOverdueForLostAndFound() not supplied valid itemnumber";
2627
        return;
2628
    }
2629
2630
    my $schema = Koha::Database->schema;
2631
2632
    my $result = $schema->txn_do(
2633
        sub {
2634
            # check for lost overdue fine
2635
            my $accountlines = Koha::Account::Lines->search(
2636
                {
2637
                    borrowernumber  => $borrowernumber,
2638
                    itemnumber      => $item,
2639
                    debit_type_code => 'OVERDUE',
2640
                    status          => 'LOST'
2641
                },
2642
                {
2643
                    order_by => { '-desc' => 'date' },
2644
                    rows     => 1
2645
                }
2646
            );
2647
            return 0 unless $accountlines->count; # no warning, there's just nothing to fix
2648
2649
            # Update status of fine
2650
            my $overdue = $accountlines->next;
2651
            $overdue->status('RETURNED')->store();
2652
2653
            # Find related forgive credit
2654
            my $refunds = $overdue->credits(
2655
                {
2656
                    credit_type_code => 'FORGIVEN',
2657
                    itemnumber       => $item,
2658
                    status           => [ { '!=' => 'VOID' }, undef ]
2659
                },
2660
                { order_by => { '-desc' => 'date' }, rows => 1 }
2661
            );
2662
            return 0 unless $refunds->count; # no warning, there's just nothing to fix
2663
2664
            # Revert the forgive credit
2665
            my $refund = $refunds->next;
2666
            return $refund->void();
2667
        }
2668
    );
2669
2670
    return $result;
2671
}
2672
2562
=head2 _GetCircControlBranch
2673
=head2 _GetCircControlBranch
2563
2674
2564
   my $circ_control_branch = _GetCircControlBranch($iteminfos, $borrower);
2675
   my $circ_control_branch = _GetCircControlBranch($iteminfos, $borrower);
(-)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 739-761 Link Here
739
                </tr>
739
                </tr>
740
                <tr>
740
                <tr>
741
                    <td>
741
                    <td>
742
                        <select name="refund">
742
                        <select name="lostreturn">
743
                          [%# Default branch %]
743
                          [%# Default branch %]
744
                          [% IF ( current_branch == '*' ) %]
744
                          [% IF ( current_branch == '*' ) %]
745
                            [% IF ( defaultRefundRule ) %]
745
                            [% IF ( defaultRefundRule == 'refund' ) %]
746
                            <option value="1" selected="selected">
746
                            <option value="refund" selected="selected">Refund lost item charge</option>
747
                            <option value="charge">Refund lost item charge and charge new overdue fine</option>
748
                            <option value="restore">Refund lost item charge and restore overdue fine</option>
749
                            <option value="0">Leave lost item charge</option>
750
                            [% ELSIF ( defaultRefundRule == 'charge' ) %]
751
                            <option value="refund">Refund lost item charge</option>
752
                            <option value="charge" selected="selected">Refund lost item charge and charge new overdue fine</option>
753
                            <option value="restore">Refund lost item charge and restore overdue fine</option>
754
                            <option value="0">Leave lost item charge</option>
755
                            [% ELSIF ( defaultRefundRule == 'restore' ) %]
756
                            <option value="refund">Refund lost item charge</option>
757
                            <option value="charge">Refund lost item charge and charge new overdue fine</option>
758
                            <option value="restore" selected="selected">Refund lost item charge and restore overdue fine</option>
759
                            <option value="0">Leave lost item charge</option>
760
                            [% ELSIF ( defaultRefundRule == 0 ) %]
761
                            <option value="refund">Refund lost item charge</option>
762
                            <option value="charge">Refund lost item charge and charge new overdue fine</option>
763
                            <option value="restore">Refund lost item charge and restore overdue fine</option>
764
                            <option value="0" selected="selected">Leave lost item charge</option>
747
                            [% ELSE %]
765
                            [% ELSE %]
748
                            <option value="1">
766
                            <option value="refund">Refund lost item charge</option>
767
                            <option value="charge">Refund lost item charge and charge new overdue fine</option>
768
                            <option value="restore">Refund lost item charge and restore overdue fine</option>
769
                            <option value="0">Leave lost item charge</option>
749
                            [% END %]
770
                            [% END %]
750
                                Yes
751
                            </option>
752
                            [% IF ( not defaultRefundRule ) %]
753
                            <option value="0" selected="selected">
754
                            [% ELSE %]
755
                            <option value="0">
756
                            [% END %]
757
                                No
758
                            </option>
759
                          [% ELSE %]
771
                          [% ELSE %]
760
                          [%# Branch-specific %]
772
                          [%# Branch-specific %]
761
                            [% IF ( not refundLostItemFeeRule ) %]
773
                            [% IF ( not refundLostItemFeeRule ) %]
Lines 763-792 Link Here
763
                            [% ELSE %]
775
                            [% ELSE %]
764
                                <option value="*">
776
                                <option value="*">
765
                            [% END %]
777
                            [% END %]
766
                              [% IF defaultRefundRule %]
778
                              [% IF defaultRefundRule == 'refund' %]
767
                                Use default (Yes)
779
                                Use default (Refund lost item charge)
780
                              [% ELSIF defaultRefundRule == 'charge' %]
781
                                Use default (Refund lost item charge and restore overdue fine)
782
                              [% ELSIF defaultRefundRule == 'restore' %]
783
                                Use default (Refund lost item charge and charge new overdue fine)
768
                              [% ELSE %]
784
                              [% ELSE %]
769
                                Use default (No)
785
                                Use default (Leave lost item charge)
770
                              [% END %]
786
                              [% END %]
771
                                </option>
787
                                </option>
772
                            [% IF ( not refundLostItemFeeRule ) %]
788
                            [% IF ( not refundLostItemFeeRule ) %]
773
                                <option value="1">Yes</option>
789
                                <option value="refund">Refund lost item charge</option>
774
                                <option value="0">No</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>
775
                            [% ELSE %]
793
                            [% ELSE %]
776
                                [% IF ( refundLostItemFeeRule.rule_value ) %]
794
                                [% IF ( refundLostItemFeeRule.rule_value == 'refund' ) %]
777
                                <option value="1" selected="selected">
795
                                <option value="refund" selected="selected">Refund lost item charge</option>
778
                                [% ELSE %]
796
                                <option value="charge">Refund lost item charge and charge new overdue fine</option>
779
                                <option value="1">
797
                                <option value="restore">Refund lost item charge and restore overdue fine</option>
798
                                <option value="0">Leave lost item charge</option>
799
                                [% ELSIF ( refundLostItemFeeRule.rule_value == 'charge' ) %]
800
                                <option value="refund">Refund lost item charge</option>
801
                                <option value="charge" selected="selected">Refund lost item charge and charge new overdue fine</option>
802
                                <option value="restore">Refund lost item charge and restore overdue fine</option>
803
                                <option value="0">Leave lost item charge</option>
804
                                [% ELSIF ( refundLostItemFeeRule.rule_value == 'restore' ) %]
805
                                <option value="refund">Refund lost item charge</option>
806
                                <option value="charge">Refund lost item charge and charge new overdue fine</option>
807
                                <option value="restore" selected="selected">Refund lost item charge and restore overdue fine</option>
808
                                <option value="0">Leave lost item charge</option>
809
                                [% ELSIF ( refundLostItemFeeRule.rule_value == 0 ) %]
810
                                <option value="refund">Refund lost item charge</option>
811
                                <option value="charge">Refund lost item charge and charge new overdue fine</option>
812
                                <option value="restore">Refund lost item charge and restore overdue fine</option>
813
                                <option value="0" selected="selected">Leave lost item charge</option>
780
                                [% END %]
814
                                [% END %]
781
                                    Yes
782
                                </option>
783
                                [% IF ( not refundLostItemFeeRule.rule_value ) %]
784
                                <option value="0" selected="selected">
785
                                [% ELSE %]
786
                                <option value="0">
787
                                [% END %]
788
                                    No
789
                                </option>
790
                            [% END %]
815
                            [% END %]
791
                          [% END %]
816
                          [% END %]
792
                        </select>
817
                        </select>
793
- 

Return to bug 23091