X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=Koha%2FArticleRequest.pm;h=83c88bee8c3fc200a781568f67eaa5eb6e0a6857;hb=bdee83ef937262cfd504edb643f9b32bbcf8ad41;hp=2d7f5596da15c8cb5328d106e0d11b55c9efe184;hpb=707e68b7fcf831aceaddf72b576ec7cfd25af50b;p=koha-ffzg.git diff --git a/Koha/ArticleRequest.pm b/Koha/ArticleRequest.pm index 2d7f5596da..83c88bee8c 100644 --- a/Koha/ArticleRequest.pm +++ b/Koha/ArticleRequest.pm @@ -19,7 +19,7 @@ package Koha::ArticleRequest; use Modern::Perl; - +use Koha::Account::Lines; use Koha::Database; use Koha::Patrons; use Koha::Biblios; @@ -57,6 +57,12 @@ sub request { ) unless $self->borrower->can_request_article; $self->status(Koha::ArticleRequest::Status::Requested); + + # Handle possible fees + my $debit = $self->borrower->add_article_request_fee_if_needed({ item_id => $self->itemnumber }); + $self->debit_id( $debit->id ) + if $debit; + $self->store(); $self->notify(); return $self; @@ -132,6 +138,34 @@ sub cancel { $self->notes($notes) if $notes; $self->store(); $self->notify(); + + my $debit = $self->debit; + + if ( $debit ) { + # fees found, refund + my $account = $self->borrower->account; + + my $total_reversible = $debit->debit_offsets->filter_by_reversible->total; + if ( $total_reversible ) { + + $account->add_credit( + { + amount => abs $total_reversible, + interface => C4::Context->interface, + type => 'REFUND', + } + ); + } + + if ( $debit->amountoutstanding ) { + $debit->reduce({ + reduction_type => 'REFUND', + amount => $debit->amountoutstanding, + interface => C4::Context->interface, + })->discard_changes; + } + } + return $self; } @@ -149,6 +183,23 @@ sub biblio { return $self->{_biblio}; } +=head3 debit + + my $debit = $article_request->debit; + +Returns the related Koha::Account::Line object for this article request + +=cut + +sub debit { + my ($self) = @_; + + my $debit_rs = $self->_result->debit; + return unless $debit_rs; + + return Koha::Account::Line->_new_from_dbic( $debit_rs ); +} + =head3 item Returns the Koha::Item object for this article request @@ -200,12 +251,12 @@ will have notifications sent. sub store { my ($self) = @_; - if ( $self->in_storage ) { - return $self->SUPER::store; - } else { + + if ( !$self->in_storage ) { $self->created_on( dt_from_string() ); - return $self->SUPER::store; } + + return $self->SUPER::store; } =head2 Internal methods