|
Lines 219-235
as 'void' by updating it's status to "VOID".
Link Here
|
| 219 |
=cut |
219 |
=cut |
| 220 |
|
220 |
|
| 221 |
sub void { |
221 |
sub void { |
| 222 |
my ($self) = @_; |
222 |
my ($self, $params) = @_; |
| 223 |
|
223 |
|
| 224 |
# Make sure it is a payment we are voiding |
224 |
# Make sure it is a credit we are voiding |
| 225 |
return unless $self->amount < 0; |
225 |
unless ( $self->is_credit ) { |
|
|
226 |
Koha::Exceptions::Account::IsNotCredit->throw( |
| 227 |
error => 'Account line ' . $self->id . 'is not a credit' ); |
| 228 |
} |
| 229 |
|
| 230 |
# Make sure it is not already voided |
| 231 |
if ( $self->status && $self->status eq 'VOID' ) { |
| 232 |
Koha::Exceptions::Account->throw( |
| 233 |
error => 'Account line ' . $self->id . 'is already void' ); |
| 234 |
} |
| 235 |
|
| 236 |
# Check for mandatory parameters |
| 237 |
my @mandatory = ( 'staff_id', 'branch' ); |
| 238 |
for my $param (@mandatory) { |
| 239 |
unless ( defined( $params->{$param} ) ) { |
| 240 |
Koha::Exceptions::MissingParameter->throw( |
| 241 |
error => "The $param parameter is mandatory" ); |
| 242 |
} |
| 243 |
} |
| 226 |
|
244 |
|
|
|
245 |
# Find any applied offsets for the credit so we may reverse them |
| 227 |
my @account_offsets = |
246 |
my @account_offsets = |
| 228 |
Koha::Account::Offsets->search( |
247 |
Koha::Account::Offsets->search( |
| 229 |
{ credit_id => $self->id, amount => { '<' => 0 } } ); |
248 |
{ credit_id => $self->id, amount => { '<' => 0 } } ); |
| 230 |
|
249 |
|
|
|
250 |
my $void; |
| 231 |
$self->_result->result_source->schema->txn_do( |
251 |
$self->_result->result_source->schema->txn_do( |
| 232 |
sub { |
252 |
sub { |
|
|
253 |
|
| 254 |
# Reverse any applied payments |
| 233 |
foreach my $account_offset (@account_offsets) { |
255 |
foreach my $account_offset (@account_offsets) { |
| 234 |
my $fee_paid = |
256 |
my $fee_paid = |
| 235 |
Koha::Account::Lines->find( $account_offset->debit_id ); |
257 |
Koha::Account::Lines->find( $account_offset->debit_id ); |
|
Lines 251-256
sub void {
Link Here
|
| 251 |
)->store(); |
273 |
)->store(); |
| 252 |
} |
274 |
} |
| 253 |
|
275 |
|
|
|
276 |
# A 'void' is a 'debit' |
| 277 |
$void = Koha::Account::Line->new( |
| 278 |
{ |
| 279 |
date => \'NOW()', |
| 280 |
amount => $self->amount * -1, |
| 281 |
debit_type_code => 'VOID', |
| 282 |
status => 'ADDED', |
| 283 |
amountoutstanding => 0, |
| 284 |
manager_id => $params->{staff_id}, |
| 285 |
borrowernumber => $self->borrowernumber, |
| 286 |
interface => 'intranet', |
| 287 |
branchcode => $params->{branch}, |
| 288 |
} |
| 289 |
)->store(); |
| 290 |
|
| 291 |
Koha::Account::Offset->new( |
| 292 |
{ |
| 293 |
debit_id => $void->accountlines_id, |
| 294 |
type => 'VOID', |
| 295 |
amount => $self->amount * -1 |
| 296 |
} |
| 297 |
)->store(); |
| 298 |
|
| 299 |
# Link void to payment |
| 300 |
Koha::Account::Offset->new( |
| 301 |
{ credit_id => $self->id, |
| 302 |
debit_id => $void->id, |
| 303 |
amount => $self->amount, |
| 304 |
type => 'VOID' |
| 305 |
} |
| 306 |
)->store(); |
| 307 |
$self->set( |
| 308 |
{ |
| 309 |
status => 'VOID', |
| 310 |
amountoutstanding => 0 |
| 311 |
} |
| 312 |
); |
| 313 |
$self->store(); |
| 314 |
|
| 254 |
if ( C4::Context->preference("FinesLog") ) { |
315 |
if ( C4::Context->preference("FinesLog") ) { |
| 255 |
logaction( |
316 |
logaction( |
| 256 |
"FINES", 'VOID', |
317 |
"FINES", 'VOID', |
|
Lines 273-290
sub void {
Link Here
|
| 273 |
) |
334 |
) |
| 274 |
); |
335 |
); |
| 275 |
} |
336 |
} |
| 276 |
|
|
|
| 277 |
$self->set( |
| 278 |
{ |
| 279 |
status => 'VOID', |
| 280 |
amountoutstanding => 0, |
| 281 |
amount => 0, |
| 282 |
} |
| 283 |
); |
| 284 |
$self->store(); |
| 285 |
} |
337 |
} |
| 286 |
); |
338 |
); |
| 287 |
|
339 |
|
|
|
340 |
$void->discard_changes; |
| 341 |
return $void; |
| 288 |
} |
342 |
} |
| 289 |
|
343 |
|
| 290 |
=head3 cancel |
344 |
=head3 cancel |
| 291 |
- |
|
|