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