Bugzilla – Attachment 122522 Details for
Bug 27946
Add a charge per article request to patron categories
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27946: Add article request fee feature
Bug-27946-Add-article-request-fee-feature.patch (text/plain), 19.63 KB, created by
Agustín Moyano
on 2021-07-02 03:17:05 UTC
(
hide
)
Description:
Bug 27946: Add article request fee feature
Filename:
MIME Type:
Creator:
Agustín Moyano
Created:
2021-07-02 03:17:05 UTC
Size:
19.63 KB
patch
obsolete
>From 350538a5781762a83af09cb21bdefabaa1e85e9e Mon Sep 17 00:00:00 2001 >From: Agustin Moyano <agustinmoyano@theke.io> >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 | 48 +++++ > admin/categories.pl | 187 +++++++++--------- > .../prog/en/modules/admin/categories.tt | 22 ++- > .../prog/en/modules/circ/request-article.tt | 7 +- > .../en/modules/opac-request-article.tt | 7 + > 5 files changed, 180 insertions(+), 91 deletions(-) > >diff --git a/Koha/ArticleRequest.pm b/Koha/ArticleRequest.pm >index 6b8809bc33..310065387c 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,19 @@ 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', >+ item_id => $self->itemnumber >+ } >+ ); >+ $self->debit_line_id($debit_line->id); >+ } > $self->SUPER::store(); > $self->notify(); > return $self; >@@ -88,6 +103,39 @@ 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 ); >+ if ( $line->amount != $line->amountoutstanding ) { >+ $self->borrower->account->add_credit( >+ { >+ amount => $line->amount, >+ 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 => 'CREDIT', >+ description => 'Article request cancelled', >+ item_id => $self->itemnumber >+ } >+ ); >+ } >+ else { >+ $line->cancel( >+ { >+ branch => C4::Context->userenv >+ ? C4::Context->userenv->{'branch'} >+ : undef, >+ staff_id => C4::Context->userenv >+ ? C4::Context->userenv->{'number'} >+ : undef, >+ } >+ ) unless $line->status && $line->status eq 'CANCELLED'; >+ } >+ } >+ > $self->store(); > $self->notify(); > return $self; >diff --git a/admin/categories.pl b/admin/categories.pl >index d8d8513b91..4feb2319d1 100755 >--- a/admin/categories.pl >+++ b/admin/categories.pl >@@ -46,18 +46,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > } > ); > >-if ( $op eq 'add_form' ) { >- >- $template->param( >- category => scalar Koha::Patron::Categories->find($categorycode), >- ); >- >- if ( C4::Context->preference('EnhancedMessagingPreferences') ) { >- C4::Form::MessagingPreferences::set_form_values( >- { categorycode => $categorycode }, $template ); >- } >-} >-elsif ( $op eq 'add_validate' ) { >+if ( $op eq 'add_validate' ) { > > my $categorycode = $input->param('categorycode'); > my $description = $input->param('description'); >@@ -78,6 +67,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; >@@ -87,88 +77,95 @@ elsif ( $op eq 'add_validate' ) { > > my $is_a_modif = $input->param("is_a_modif"); > >- if ($enrolmentperioddate) { >- $enrolmentperioddate = output_pref( >- { >- dt => dt_from_string($enrolmentperioddate), >- dateformat => 'iso', >- dateonly => 1, >- } >- ); >- } >+ if ($article_request_fee < 0) { >+ push @messages, {type => 'error', code => 'article_request_negative_fee' }; >+ $op = 'add_form'; >+ } else { >+ if ($enrolmentperioddate) { >+ $enrolmentperioddate = output_pref( >+ { >+ dt => dt_from_string($enrolmentperioddate), >+ dateformat => 'iso', >+ dateonly => 1, >+ } >+ ); >+ } > >- if ($is_a_modif) { >- my $category = Koha::Patron::Categories->find( $categorycode ); >- $category->categorycode($categorycode); >- $category->description($description); >- $category->enrolmentperiod($enrolmentperiod); >- $category->enrolmentperioddate($enrolmentperioddate); >- $category->upperagelimit($upperagelimit); >- $category->dateofbirthrequired($dateofbirthrequired); >- $category->enrolmentfee($enrolmentfee); >- $category->reservefee($reservefee); >- $category->hidelostitems($hidelostitems); >- $category->overduenoticerequired($overduenoticerequired); >- $category->category_type($category_type); >- $category->BlockExpiredPatronOpacActions($BlockExpiredPatronOpacActions); >- $category->checkprevcheckout($checkPrevCheckout); >- $category->default_privacy($default_privacy); >- $category->reset_password($reset_password); >- $category->change_password($change_password); >- $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); >- eval { >- $category->store; >- $category->replace_library_limits( \@branches ); >- }; >- if ( $@ ) { >- push @messages, {type => 'error', code => 'error_on_update' }; >- } else { >- push @messages, { type => 'message', code => 'success_on_update' }; >+ if ($is_a_modif) { >+ my $category = Koha::Patron::Categories->find( $categorycode ); >+ $category->categorycode($categorycode); >+ $category->description($description); >+ $category->enrolmentperiod($enrolmentperiod); >+ $category->enrolmentperioddate($enrolmentperioddate); >+ $category->upperagelimit($upperagelimit); >+ $category->dateofbirthrequired($dateofbirthrequired); >+ $category->enrolmentfee($enrolmentfee); >+ $category->reservefee($reservefee); >+ $category->hidelostitems($hidelostitems); >+ $category->overduenoticerequired($overduenoticerequired); >+ $category->category_type($category_type); >+ $category->BlockExpiredPatronOpacActions($BlockExpiredPatronOpacActions); >+ $category->checkprevcheckout($checkPrevCheckout); >+ $category->default_privacy($default_privacy); >+ $category->reset_password($reset_password); >+ $category->change_password($change_password); >+ $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 ); >+ }; >+ if ( $@ ) { >+ push @messages, {type => 'error', code => 'error_on_update' }; >+ } else { >+ push @messages, { type => 'message', code => 'success_on_update' }; >+ } > } >- } >- else { >- my $category = Koha::Patron::Category->new({ >- categorycode => $categorycode, >- description => $description, >- enrolmentperiod => $enrolmentperiod, >- enrolmentperioddate => $enrolmentperioddate, >- upperagelimit => $upperagelimit, >- dateofbirthrequired => $dateofbirthrequired, >- enrolmentfee => $enrolmentfee, >- reservefee => $reservefee, >- hidelostitems => $hidelostitems, >- overduenoticerequired => $overduenoticerequired, >- category_type => $category_type, >- BlockExpiredPatronOpacActions => $BlockExpiredPatronOpacActions, >- checkprevcheckout => $checkPrevCheckout, >- default_privacy => $default_privacy, >- reset_password => $reset_password, >- change_password => $change_password, >- exclude_from_local_holds_priority => $exclude_from_local_holds_priority, >- min_password_length => $min_password_length, >- require_strong_password => $require_strong_password, >- }); >- eval { >- $category->store; >- $category->replace_library_limits( \@branches ); >- }; >- >- if ( $@ ) { >- push @messages, { type => 'error', code => 'error_on_insert' }; >- } else { >- push @messages, { type => 'message', code => 'success_on_insert' }; >+ else { >+ my $category = Koha::Patron::Category->new({ >+ categorycode => $categorycode, >+ description => $description, >+ enrolmentperiod => $enrolmentperiod, >+ enrolmentperioddate => $enrolmentperioddate, >+ upperagelimit => $upperagelimit, >+ dateofbirthrequired => $dateofbirthrequired, >+ enrolmentfee => $enrolmentfee, >+ reservefee => $reservefee, >+ hidelostitems => $hidelostitems, >+ overduenoticerequired => $overduenoticerequired, >+ category_type => $category_type, >+ BlockExpiredPatronOpacActions => $BlockExpiredPatronOpacActions, >+ checkprevcheckout => $checkPrevCheckout, >+ default_privacy => $default_privacy, >+ reset_password => $reset_password, >+ change_password => $change_password, >+ 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; >+ $category->replace_library_limits( \@branches ); >+ }; >+ >+ if ( $@ ) { >+ push @messages, { type => 'error', code => 'error_on_insert' }; >+ } else { >+ push @messages, { type => 'message', code => 'success_on_insert' }; >+ } > } >- } > >- if ( C4::Context->preference('EnhancedMessagingPreferences') ) { >- C4::Form::MessagingPreferences::handle_form_action( $input, >- { categorycode => scalar $input->param('categorycode') }, $template ); >+ if ( C4::Context->preference('EnhancedMessagingPreferences') ) { >+ C4::Form::MessagingPreferences::handle_form_action( $input, >+ { categorycode => scalar $input->param('categorycode') }, $template ); >+ } >+ >+ $searchfield = q||; >+ $op = 'list'; > } >- >- $searchfield = q||; >- $op = 'list'; > } > elsif ( $op eq 'delete_confirm' ) { > >@@ -199,6 +196,18 @@ elsif ( $op eq 'delete_confirmed' ) { > $op = 'list'; > } > >+if ( $op eq 'add_form' ) { >+ >+ $template->param( >+ category => scalar Koha::Patron::Categories->find($categorycode), >+ ); >+ >+ if ( C4::Context->preference('EnhancedMessagingPreferences') ) { >+ C4::Form::MessagingPreferences::set_form_values( >+ { categorycode => $categorycode }, $template ); >+ } >+} >+ > if ( $op eq 'list' ) { > my $categories = Koha::Patron::Categories->search( > { >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..215892fa0d 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt >@@ -108,6 +108,8 @@ > Patron category deleted successfully. > [% CASE 'already_exists' %] > This patron category already exists. >+ [% CASE 'article_request_negative_fee' %] >+ Article request fee cannot be negative. > [% CASE %] > [% m.code | html %] > [% END %] >@@ -202,6 +204,12 @@ > <label for="reservefee">Hold fee: </label> > <input type="text" name="reservefee" id="reservefee" size="6" value="[% category.reservefee | $Price on_editing => 1 %]" /> > </li> >+ [% IF Koha.Preference('ArticleRequests') %] >+ <li> >+ <label for="article_request_fee">Cost for article scan request</label> >+ <input type="text" name="article_request_fee" id="article_request_fee" size="6" value="[% category.article_request_fee | $Price on_editing => 1 %]" /> >+ </li> >+ [% END %] > <li> > <label for="category_type" class="required">Category type: </label> > <select name="category_type" id="category_type"> >@@ -455,7 +463,9 @@ > <tr><th scope="row">Receives overdue notices: </th><td>[% IF category. overduenoticerequired %]Yes[% ELSE %]No[% END %]</td></tr> > <tr><th scope="row">Lost items in staff interface</th><td>[% IF category.hidelostitems %]Hidden by default[% ELSE %]Shown[% END %]</td></tr> > <tr><th scope="row">Hold fee: </th><td>[% category.reservefee | $Price %]</td></tr> >- >+ [% IF Koha.Preference('ArticleRequests') %] >+ <tr><th scope="row">Article request fee: </th><td>[% category.article_request_fee | $Price %]</td></tr> >+ [% END %] > [% IF ( Koha.Preference('CheckPrevCheckout') == 'softyes' || Koha.Preference('CheckPrevCheckout') == 'softno' ) %] > <tr> > <th scope="row">Check previous checkouts: </th> >@@ -523,6 +533,9 @@ > <th scope="col">Overdue</th> > <th scope="col">Lost items</th> > <th scope="col">Hold fee</th> >+ [% IF Koha.Preference('ArticleRequests') %] >+ <th scope="col">Article request fee</th> >+ [% END %] > [% IF ( EnhancedMessagingPreferences ) %] > <th scope="col">Messaging</th> > [% END %] >@@ -581,6 +594,13 @@ > [% ELSE %] > <td>-</td> > [% END %] >+ [% IF Koha.Preference('ArticleRequests') %] >+ [% IF (category.article_request_fee > 0) %] >+ <td>[% category.article_request_fee | $Price %]</td> >+ [% ELSE %] >+ <td>-</td> >+ [% END %] >+ [% END %] > [% IF Koha.Preference('EnhancedMessagingPreferences') %] > <td style="white-space: nowrap; font-size:80%;"> > [% SET default_messaging = category.default_messaging %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt >index e59703482e..ca94b04d26 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt >@@ -3,6 +3,7 @@ > [% USE KohaDates %] > [% USE Branches %] > [% USE ItemTypes %] >+[% USE Price %] > [% SET footerjs = 1 %] > [% SET article_requests_view = 1 %] > [% SET biblionumber = biblio.biblionumber %] >@@ -94,7 +95,11 @@ > </form> > [% ELSE %] > [% IF biblio.can_article_request( patron ) %] >- >+ [% IF patron.category.article_request_fee > 0 %] >+ <div class="dialog alert"> >+ Patron will be charged with <strong>[% patron.category.article_request_fee | $Price %]</strong> for every request >+ </div> >+ [% END %] > <form id="place-article-request" method="post" action="/cgi-bin/koha/circ/request-article.pl"> > <input type="hidden" name="action" value="create" /> > <input type="hidden" name="biblionumber" id="biblionumber" value="[% biblio.biblionumber | html %]" /> >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 69dd4f0b58..6b545aff49 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' %] > > <title>Request article › [% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog</title> >@@ -38,6 +39,12 @@ > > <h1>Place article request for [% biblio.title | html %]</h1> > >+ [% IF patron.category.article_request_fee > 0 %] >+ <div class="alert alert-warning"> >+ You will be charged with <strong>[% patron.category.article_request_fee | $Price %]</strong> for every request >+ </div> >+ [% END %] >+ > <form id="place-article-request" method="post" action="/cgi-bin/koha/opac-request-article.pl"> > <legend class="sr-only">Place article request</legend> > <input type="hidden" name="action" value="create" /> >-- >2.25.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 27946
:
120144
|
120145
|
120146
|
120147
|
122522
|
122529
|
122530
|
122531
|
122532
|
122552
|
123503
|
123504
|
123505
|
123506
|
123507
|
128660
|
128661
|
128662
|
128663
|
128664
|
128665
|
128868
|
128869
|
128870
|
128871
|
128872
|
128873
|
129141
|
129142
|
129143
|
129144
|
129145
|
129146
|
129147
|
129171
|
129172
|
129173
|
129174
|
129175
|
129176
|
129177