From da239dd5b7b7d2bd19623473339a84f9ca66909c Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Thu, 22 Apr 2021 19:29:37 -0300 Subject: [PATCH] Bug 27946: Add article request fee feature This patch adds the ability to charge a fee for article scan requests. To test: 1. apply patches 2. updatedatabase 3. restart_all 4. enable ArticleRequest in preferences 5. grab a patron category and set a fee for article requests 6. grab a patron of that category (patron a) and another fron different category (patron b) 7. place an article request for both patrons SUCCESS => only for patron a, a warning is displayed saying a fee will be charged 8. check the account for both patrons SUCCESS => only for patron a there is a debit of type ARTICLE_REQUEST 9. cancel the article request for patron a SUCCESS => the debit for patron a gets canceled 10. repeat step 7 only for patron a 11. change article request fee for the patron a's category 12. repeat step 10 13. check account for patron a SUCCESS => there are 2 debits with different amount of typ ARTICLE_REQUEST 14. cancel only one article request SUCCESS => only the corresponding debit gets canceled 15. prove t/db_dependent/ArticleRequests.t --- Koha/ArticleRequest.pm | 23 +++++++++++++++++++ admin/categories.pl | 3 +++ .../prog/en/modules/admin/categories.tt | 16 +++++++++++++ .../prog/en/modules/circ/request-article.tt | 7 +++++- .../en/modules/opac-request-article.tt | 7 ++++++ 5 files changed, 55 insertions(+), 1 deletion(-) diff --git a/Koha/ArticleRequest.pm b/Koha/ArticleRequest.pm index 2c47dd03fe..450361705d 100644 --- a/Koha/ArticleRequest.pm +++ b/Koha/ArticleRequest.pm @@ -27,6 +27,8 @@ use Koha::Biblios; use Koha::Items; use Koha::Libraries; use Koha::DateUtils qw(dt_from_string); +use C4::Context; +use Koha::Account::Lines; use base qw(Koha::Object); @@ -48,6 +50,18 @@ sub open { my ($self) = @_; $self->status(Koha::ArticleRequest::Status::Pending); + if(C4::Context->preference('ArticleRequests') && $self->borrower->category->article_request_fee) { + my $debit_line = $self->borrower->account->add_debit( + { + amount => $self->borrower->category->article_request_fee, + user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, + interface => C4::Context->interface, + library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, + type => 'ARTICLE_REQUEST' + } + ); + $self->debit_line_id($debit_line->id); + } $self->SUPER::store(); $self->notify(); return $self; @@ -88,6 +102,15 @@ sub cancel { $self->status(Koha::ArticleRequest::Status::Canceled); $self->notes($notes) if $notes; + if($self->debit_line_id) { + my $line = Koha::Account::Lines->find($self->debit_line_id); + $line->cancel( + { + branch => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, + staff_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, + } + ) unless $line->status eq 'CANCELLED' || $line->amount != $line->amountoutstanding; + } $self->store(); $self->notify(); return $self; diff --git a/admin/categories.pl b/admin/categories.pl index afc2950468..93aefa0516 100755 --- a/admin/categories.pl +++ b/admin/categories.pl @@ -79,6 +79,7 @@ elsif ( $op eq 'add_validate' ) { my $exclude_from_local_holds_priority = $input->param('exclude_from_local_holds_priority'); my $min_password_length = $input->param('min_password_length'); my $require_strong_password = $input->param('require_strong_password'); + my $article_request_fee = $input->param('article_request_fee'); my @branches = grep { $_ ne q{} } $input->multi_param('branches'); $reset_password = undef if $reset_password eq -1; @@ -119,6 +120,7 @@ elsif ( $op eq 'add_validate' ) { $category->exclude_from_local_holds_priority($exclude_from_local_holds_priority); $category->min_password_length($min_password_length); $category->require_strong_password($require_strong_password); + $category->article_request_fee($article_request_fee); eval { $category->store; $category->replace_library_limits( \@branches ); @@ -150,6 +152,7 @@ elsif ( $op eq 'add_validate' ) { exclude_from_local_holds_priority => $exclude_from_local_holds_priority, min_password_length => $min_password_length, require_strong_password => $require_strong_password, + article_request_fee => $article_request_fee, }); eval { $category->store; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt index 768d1259fb..fa6462b809 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt @@ -202,6 +202,12 @@ + [% IF Koha.Preference('ArticleRequests') %] +
  • + + +
  • + [% END %]
  • diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-request-article.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-request-article.tt index caf214e8b0..26f9a91f96 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-request-article.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-request-article.tt @@ -1,6 +1,7 @@ [% USE Koha %] [% USE Branches %] [% USE ItemTypes %] +[% USE Price %] [% INCLUDE 'doc-head-open.inc' %] Request article › [% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog @@ -38,6 +39,12 @@

    Place article request for [% biblio.title | html %]

    + [% IF patron.category.article_request_fee > 0 %] +
    + You will be charged with [% patron.category.article_request_fee | $Price %] for every request +
    + [% END %] +
    -- 2.27.0