|
Lines 33-39
use C4::Members;
Link Here
|
| 33 |
use Koha::Account; |
33 |
use Koha::Account; |
| 34 |
use Koha::Account::Lines; |
34 |
use Koha::Account::Lines; |
| 35 |
use Koha::Account::Offsets; |
35 |
use Koha::Account::Offsets; |
|
|
36 |
use Koha::CirculationRules; |
| 37 |
use Koha::Checkouts; |
| 36 |
use Koha::Items; |
38 |
use Koha::Items; |
|
|
39 |
use Koha::Patrons; |
| 37 |
|
40 |
|
| 38 |
=head1 NAME |
41 |
=head1 NAME |
| 39 |
|
42 |
|
|
Lines 65-76
FIXME : if no replacement price, borrower just doesn't get charged?
Link Here
|
| 65 |
|
68 |
|
| 66 |
sub chargelostitem { |
69 |
sub chargelostitem { |
| 67 |
my $dbh = C4::Context->dbh(); |
70 |
my $dbh = C4::Context->dbh(); |
| 68 |
my ( $borrowernumber, $itemnumber, $replacementprice, $description ) = @_; |
71 |
my ( $borrowernumber, $itemnumber, $replacementprice, $description, $opts ) = @_; |
|
|
72 |
$opts ||= {}; |
| 73 |
|
| 69 |
my $patron = Koha::Patrons->find($borrowernumber); |
74 |
my $patron = Koha::Patrons->find($borrowernumber); |
| 70 |
my $item = Koha::Items->find($itemnumber); |
75 |
my $item = Koha::Items->find($itemnumber); |
| 71 |
my $itype = $item->itemtype; |
76 |
my $itype = $item->itemtype; |
| 72 |
$replacementprice //= 0; |
77 |
$replacementprice //= 0; |
| 73 |
my $defaultreplacecost = $itype->defaultreplacecost; |
78 |
|
|
|
79 |
my $defaultreplacecost = $itype->defaultreplacecost; |
| 80 |
my $usedefaultreplacementcost = C4::Context->preference("useDefaultReplacementCost"); |
| 81 |
my $processingfeenote = C4::Context->preference("ProcessingFeeNote"); |
| 74 |
|
82 |
|
| 75 |
my $lost_control_pref = C4::Context->preference('LostChargesControl'); |
83 |
my $lost_control_pref = C4::Context->preference('LostChargesControl'); |
| 76 |
my $lost_control_branch; |
84 |
my $lost_control_branch; |
|
Lines 85-125
sub chargelostitem {
Link Here
|
| 85 |
: $item->holdingbranch; |
93 |
: $item->holdingbranch; |
| 86 |
} |
94 |
} |
| 87 |
|
95 |
|
| 88 |
my $processfee = Koha::CirculationRules->get_effective_rule_value( |
96 |
my $interface = $opts->{interface} // C4::Context->interface; |
| 89 |
{ |
97 |
my $library_id = defined $opts->{library_id} ? $opts->{library_id} : $lost_control_branch; |
| 90 |
rule_name => "lost_item_processing_fee", |
98 |
|
| 91 |
categorycode => undef, |
99 |
my $issue_id = $opts->{issue_id}; |
| 92 |
itemtype => $itype->itemtype, |
100 |
if ( !defined $issue_id ) { |
| 93 |
branchcode => $lost_control_branch |
101 |
my $checkout = Koha::Checkouts->find( { itemnumber => $itemnumber } ); |
|
|
102 |
if ( !$checkout && $item->in_bundle ) { |
| 103 |
my $host = $item->bundle_host; |
| 104 |
$checkout = $host->checkout; |
| 94 |
} |
105 |
} |
| 95 |
) // 0; |
106 |
$issue_id = $checkout ? $checkout->issue_id : undef; |
| 96 |
my $usedefaultreplacementcost = C4::Context->preference("useDefaultReplacementCost"); |
107 |
} |
| 97 |
my $processingfeenote = C4::Context->preference("ProcessingFeeNote"); |
|
|
| 98 |
|
108 |
|
| 99 |
if ( $usedefaultreplacementcost && $replacementprice == 0 && $defaultreplacecost ) { |
109 |
if ( $usedefaultreplacementcost && $replacementprice == 0 && $defaultreplacecost ) { |
| 100 |
$replacementprice = $defaultreplacecost; |
110 |
$replacementprice = $defaultreplacecost; |
| 101 |
} |
111 |
} |
| 102 |
my $checkout = Koha::Checkouts->find( { itemnumber => $itemnumber } ); |
|
|
| 103 |
if ( !$checkout && $item->in_bundle ) { |
| 104 |
my $host = $item->bundle_host; |
| 105 |
$checkout = $host->checkout; |
| 106 |
} |
| 107 |
my $issue_id = $checkout ? $checkout->issue_id : undef; |
| 108 |
|
112 |
|
| 109 |
my $account = Koha::Account->new( { patron_id => $borrowernumber } ); |
113 |
my $account = Koha::Account->new( { patron_id => $borrowernumber } ); |
| 110 |
|
114 |
|
| 111 |
# first make sure the borrower hasn't already been charged for this item (for this issuance) |
|
|
| 112 |
my $existing_charges = $account->lines->search( |
115 |
my $existing_charges = $account->lines->search( |
| 113 |
{ |
116 |
{ |
| 114 |
itemnumber => $itemnumber, |
117 |
item_id => $itemnumber, |
| 115 |
debit_type_code => 'LOST', |
118 |
debit_type_code => 'LOST', |
| 116 |
issue_id => $issue_id |
119 |
issue_id => $issue_id, |
| 117 |
} |
120 |
} |
| 118 |
)->count(); |
121 |
)->count(); |
| 119 |
|
122 |
|
| 120 |
# OK, they haven't |
123 |
# OK, they haven't |
| 121 |
unless ($existing_charges) { |
124 |
unless ($existing_charges) { |
| 122 |
|
125 |
|
|
|
126 |
my $processfee = Koha::CirculationRules->get_effective_rule_value( |
| 127 |
{ |
| 128 |
rule_name => "lost_item_processing_fee", |
| 129 |
categorycode => undef, |
| 130 |
itemtype => $itype->itemtype, |
| 131 |
branchcode => $library_id, |
| 132 |
} |
| 133 |
) // 0; |
| 134 |
|
| 123 |
#add processing fee |
135 |
#add processing fee |
| 124 |
if ( $processfee && $processfee > 0 ) { |
136 |
if ( $processfee && $processfee > 0 ) { |
| 125 |
my $accountline = $account->add_debit( |
137 |
my $accountline = $account->add_debit( |
|
Lines 129-138
sub chargelostitem {
Link Here
|
| 129 |
note => $processingfeenote, |
141 |
note => $processingfeenote, |
| 130 |
user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, |
142 |
user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, |
| 131 |
interface => C4::Context->interface, |
143 |
interface => C4::Context->interface, |
| 132 |
library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, |
144 |
library_id => $library_id, |
| 133 |
type => 'PROCESSING', |
145 |
type => 'PROCESSING', |
| 134 |
item_id => $itemnumber, |
146 |
item_id => $itemnumber, |
| 135 |
issue_id => $issue_id, |
147 |
( defined $issue_id ? ( issue_id => $issue_id ) : () ), |
| 136 |
} |
148 |
} |
| 137 |
); |
149 |
); |
| 138 |
} |
150 |
} |
|
Lines 146-155
sub chargelostitem {
Link Here
|
| 146 |
note => undef, |
158 |
note => undef, |
| 147 |
user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, |
159 |
user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, |
| 148 |
interface => C4::Context->interface, |
160 |
interface => C4::Context->interface, |
| 149 |
library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, |
161 |
library_id => $library_id, |
| 150 |
type => 'LOST', |
162 |
type => 'LOST', |
| 151 |
item_id => $itemnumber, |
163 |
item_id => $itemnumber, |
| 152 |
issue_id => $issue_id, |
164 |
( defined $issue_id ? ( issue_id => $issue_id ) : () ), |
| 153 |
} |
165 |
} |
| 154 |
); |
166 |
); |
| 155 |
} |
167 |
} |