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

(-)a/C4/Circulation.pm (-1 / +39 lines)
Lines 1441-1447 sub AddIssue { Link Here
1441
                UpdateTotalIssues( $item_object->biblionumber, 1 );
1441
                UpdateTotalIssues( $item_object->biblionumber, 1 );
1442
            }
1442
            }
1443
1443
1444
            ## If item was lost, it has now been found, reverse any list item charges if necessary.
1444
            ## If item was lost, it has now been found, reverse any lost item charges if necessary.
1445
            if ( $item_object->itemlost ) {
1445
            if ( $item_object->itemlost ) {
1446
                if (
1446
                if (
1447
                    Koha::RefundLostItemFeeRules->should_refund(
1447
                    Koha::RefundLostItemFeeRules->should_refund(
Lines 1456-1461 sub AddIssue { Link Here
1456
                    _FixAccountForLostAndReturned( $item_object->itemnumber, undef,
1456
                    _FixAccountForLostAndReturned( $item_object->itemnumber, undef,
1457
                        $item_object->barcode );
1457
                        $item_object->barcode );
1458
                }
1458
                }
1459
                if (
1460
                    Koha::RefundLostItemFeeRules->should_charge_fine(
1461
                        {
1462
                            current_branch   => C4::Context->userenv->{branch},
1463
                            item_home_branch => $item_object->homebranch,
1464
                            item_holding_branch => $item_object->holdingbranch
1465
                        }
1466
                    )
1467
                  )
1468
                {
1469
                    _CalculateAndUpdateFine(
1470
                        {
1471
                            issue       => $issue,
1472
                            item        => $item_unblessed,
1473
                            borrower    => $borrower
1474
                        }
1475
                    );
1476
                    _FixOverduesOnReturn( $borrower->{borrowernumber}, $item_object->itemnumber, undef, 'RENEWED' );
1477
                }
1459
            }
1478
            }
1460
1479
1461
            ModItem(
1480
            ModItem(
Lines 2027-2032 sub AddReturn { Link Here
2027
                    $borrowernumber, $barcode );
2046
                    $borrowernumber, $barcode );
2028
                $messages->{'LostItemFeeRefunded'} = 1;
2047
                $messages->{'LostItemFeeRefunded'} = 1;
2029
            }
2048
            }
2049
            if (
2050
                Koha::RefundLostItemFeeRules->should_charge_fine(
2051
                    {
2052
                        current_branch      => C4::Context->userenv->{branch},
2053
                        item_home_branch    => $item->homebranch,
2054
                        item_holding_branch => $item_holding_branch
2055
                    }
2056
                )
2057
              )
2058
            {
2059
                _CalculateAndUpdateFine(
2060
                    {
2061
                        issue       => $issue,
2062
                        item        => $item_unblessed,
2063
                        borrower    => $patron_unblessed,
2064
                        return_date => $return_date
2065
                    }
2066
                );
2067
            }
2030
        }
2068
        }
2031
    }
2069
    }
2032
2070
(-)a/Koha/RefundLostItemFeeRules.pm (-7 / +48 lines)
Lines 66-72 sub should_refund { Link Here
66
    my $self = shift;
66
    my $self = shift;
67
    my $params = shift;
67
    my $params = shift;
68
68
69
    return $self->_effective_branch_rule( $self->_choose_branch( $params ) );
69
    # Options are:
70
    # 'none' - Do not refund
71
    # 'refund' - Refund only
72
    # 'restore' - Refund and Restore original fine value
73
    # 'charge' - Refund and Charge new fine value
74
    my $rule = $self->_effective_branch_rule( $self->_choose_branch( $params ) );
75
    return $rule eq 'none' ? 0 : 1;
76
}
77
78
=head3 should_restore_fine
79
80
Koha::RefundLostItemFeeRules->should_restore()
81
82
Returns a boolean telling if the original overdue fee needs to be restored
83
given the passed params, and the current rules/sysprefs configuration.
84
85
=cut
86
87
sub should_restore_fine {
88
89
    my $self = shift;
90
    my $params = shift;
91
92
    my $rule = $self->_effective_branch_rule( $self->_choose_branch( $params ) );
93
    return $rule eq 'restore' ? 1 : 0;
94
}
95
96
=head3 should_charge_fine
97
98
Koha::RefundLostItemFeeRules->should_charge_fine()
99
100
Returns a boolean telling if a new overdue fee should be chargeed given the
101
passed params, and the current rules/sysprefs configuration.
102
103
=cut
104
105
sub should_charge_fine {
106
107
    my $self = shift;
108
    my $params = shift;
109
110
    my $rule = $self->_effective_branch_rule( $self->_choose_branch( $params ) );
111
    return $rule eq 'charge' ? 1 : 0;
70
}
112
}
71
113
72
114
Lines 89-95 sub _effective_branch_rule { Link Here
89
            branchcode   => $branch,
131
            branchcode   => $branch,
90
            categorycode => undef,
132
            categorycode => undef,
91
            itemtype     => undef,
133
            itemtype     => undef,
92
            rule_name    => 'refund',
134
            rule_name    => 'lost_return',
93
        }
135
        }
94
    )->next();
136
    )->next();
95
137
Lines 138-144 sub _choose_branch { Link Here
138
180
139
=head3 Koha::RefundLostItemFeeRules->find();
181
=head3 Koha::RefundLostItemFeeRules->find();
140
182
141
Inherit from Koha::Objects->find(), but forces rule_name => 'refund'
183
Inherit from Koha::Objects->find(), but forces rule_name => 'lost_return'
142
184
143
=cut
185
=cut
144
186
Lines 146-152 sub find { Link Here
146
    my ( $self, @pars ) = @_;
188
    my ( $self, @pars ) = @_;
147
189
148
    if ( ref($pars[0]) eq 'HASH' ) {
190
    if ( ref($pars[0]) eq 'HASH' ) {
149
        $pars[0]->{rule_name} = 'refund';
191
        $pars[0]->{rule_name} = 'lost_return';
150
    }
192
    }
151
193
152
    return $self->SUPER::find(@pars);
194
    return $self->SUPER::find(@pars);
Lines 167-179 sub _default_rule { Link Here
167
            branchcode   => undef,
209
            branchcode   => undef,
168
            categorycode => undef,
210
            categorycode => undef,
169
            itemtype     => undef,
211
            itemtype     => undef,
170
            rule_name    => 'refund',
212
            rule_name    => 'lost_return',
171
        }
213
        }
172
    )->next();
214
    )->next();
173
215
174
    return (defined $default_rule)
216
    return (defined $default_rule)
175
                ? $default_rule->rule_value
217
                ? $default_rule->rule_value
176
                : 1;
218
                : 'refund';
177
}
219
}
178
220
179
1;
221
1;
180
- 

Return to bug 23091