View | Details | Raw Unified | Return to bug 27945
Collapse All | Expand All

(-)a/Koha/ArticleRequest.pm (-2 / +10 lines)
Lines 27-33 use Koha::Items; Link Here
27
use Koha::Libraries;
27
use Koha::Libraries;
28
use Koha::DateUtils qw( dt_from_string );
28
use Koha::DateUtils qw( dt_from_string );
29
use C4::Context;
29
use C4::Context;
30
use Koha::ArticleRequests;
30
use Koha::Account::Lines;
31
use Koha::Account::Lines;
32
use Koha::Exceptions::ArticleRequest;
31
33
32
use base qw(Koha::Object);
34
use base qw(Koha::Object);
33
35
Lines 48-58 Koha::ArticleRequest - Koha Article Request Object class Link Here
48
sub open {
50
sub open {
49
    my ($self) = @_;
51
    my ($self) = @_;
50
52
53
    Koha::Exceptions::ArticleRequest::LimitReached->throw(
54
        error => 'Patron cannot request more articles for today'
55
    ) unless $self->borrower->can_request_article;
56
51
    $self->status(Koha::ArticleRequest::Status::Pending);
57
    $self->status(Koha::ArticleRequest::Status::Pending);
52
    if(C4::Context->preference('ArticleRequests') && $self->borrower->category->article_request_fee) {
58
59
    my $fee = $self->borrower->category->article_request_fee;
60
    if($fee && $fee > 0) {
53
      my $debit_line = $self->borrower->account->add_debit(
61
      my $debit_line = $self->borrower->account->add_debit(
54
        {
62
        {
55
          amount     => $self->borrower->category->article_request_fee,
63
          amount     => $fee,
56
          user_id    => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef,
64
          user_id    => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef,
57
          interface  => C4::Context->interface,
65
          interface  => C4::Context->interface,
58
          library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef,
66
          library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef,
(-)a/Koha/Exceptions/ArticleRequest.pm (+47 lines)
Line 0 Link Here
1
package Koha::Exceptions::ArticleRequest;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Exception::Class (
21
    'Koha::Exceptions::ArticleRequest' => {
22
        description => 'Something went wrong!',
23
    },
24
    'Koha::Exceptions::ArticleRequest::LimitReached' => {
25
        isa         => 'Koha::Exceptions::ArticleRequest',
26
        description => 'Article request limit was reached'
27
    },
28
);
29
30
=head1 NAME
31
32
Koha::Exceptions::ArticleRequest - Base class for ArticleRequest exceptions
33
34
=head1 Exceptions
35
36
=head2 Koha::Exceptions::ArticleRequest
37
38
Generic ArticleRequest exception
39
40
=head2 Koha::Exceptions::ArticleRequest::IsNotCredit
41
42
Exception to be used when an action on an account line requires it to be a
43
credit and it isn't.
44
45
=cut
46
47
1;
(-)a/Koha/Patron.pm (+26 lines)
Lines 958-963 sub move_to_deleted { Link Here
958
    return Koha::Database->new->schema->resultset('Deletedborrower')->create($patron_infos);
958
    return Koha::Database->new->schema->resultset('Deletedborrower')->create($patron_infos);
959
}
959
}
960
960
961
=head3 can_request_article
962
963
my $can_request = $borrower->can_request_article
964
965
Returns true if patron can request articles
966
967
=cut
968
969
sub can_request_article {
970
    my ($self) = @_;
971
    my $limit = $self->category->article_request_limit;
972
973
    return 1 if !$limit;
974
975
    my $date = dt_from_string;
976
    my $count = Koha::ArticleRequests->search({
977
            borrowernumber => $self->borrowernumber,
978
            status => {'!=' => 'CANCELED'},
979
            created_on => {
980
                '>=' => $date->date.' 00:00:00',
981
                '<=' => $date->date.' 23:59:59'
982
            }
983
        })->count;
984
    return $count < $limit ? 1 : 0;
985
}
986
961
=head3 article_requests
987
=head3 article_requests
962
988
963
my @requests = $borrower->article_requests();
989
my @requests = $borrower->article_requests();
(-)a/admin/categories.pl (+9 lines)
Lines 68-73 if ( $op eq 'add_validate' ) { Link Here
68
    my $min_password_length = $input->param('min_password_length');
68
    my $min_password_length = $input->param('min_password_length');
69
    my $require_strong_password = $input->param('require_strong_password');
69
    my $require_strong_password = $input->param('require_strong_password');
70
    my $article_request_fee = $input->param('article_request_fee');
70
    my $article_request_fee = $input->param('article_request_fee');
71
    my $article_request_limit = $input->param('article_request_limit');
71
    my @branches = grep { $_ ne q{} } $input->multi_param('branches');
72
    my @branches = grep { $_ ne q{} } $input->multi_param('branches');
72
73
73
    $reset_password = undef if $reset_password eq -1;
74
    $reset_password = undef if $reset_password eq -1;
Lines 80-85 if ( $op eq 'add_validate' ) { Link Here
80
    if ($article_request_fee < 0) {
81
    if ($article_request_fee < 0) {
81
        push @messages, {type => 'error', code => 'article_request_negative_fee' };
82
        push @messages, {type => 'error', code => 'article_request_negative_fee' };
82
        $op = 'add_form';
83
        $op = 'add_form';
84
    } elsif ($article_request_limit ne '' && $article_request_limit !~ /\d+/) {
85
        push @messages, {type => 'error', code => 'article_request_numeric_limit' };
86
        $op = 'add_form';
87
    } elsif ($article_request_limit ne '' && $article_request_limit < 0) {
88
        push @messages, {type => 'error', code => 'article_request_negative_limit' };
89
        $op = 'add_form';
83
    } else {
90
    } else {
84
        if ($enrolmentperioddate) {
91
        if ($enrolmentperioddate) {
85
            $enrolmentperioddate = output_pref(
92
            $enrolmentperioddate = output_pref(
Lines 113-118 if ( $op eq 'add_validate' ) { Link Here
113
            $category->min_password_length($min_password_length);
120
            $category->min_password_length($min_password_length);
114
            $category->require_strong_password($require_strong_password);
121
            $category->require_strong_password($require_strong_password);
115
            $category->article_request_fee($article_request_fee);
122
            $category->article_request_fee($article_request_fee);
123
            $category->article_request_limit($article_request_limit);
116
            eval {
124
            eval {
117
                $category->store;
125
                $category->store;
118
                $category->replace_library_limits( \@branches );
126
                $category->replace_library_limits( \@branches );
Lines 145-150 if ( $op eq 'add_validate' ) { Link Here
145
                min_password_length => $min_password_length,
153
                min_password_length => $min_password_length,
146
                require_strong_password => $require_strong_password,
154
                require_strong_password => $require_strong_password,
147
                article_request_fee => $article_request_fee,
155
                article_request_fee => $article_request_fee,
156
                article_request_limit => $article_request_limit
148
            });
157
            });
149
            eval {
158
            eval {
150
                $category->store;
159
                $category->store;
(-)a/circ/request-article.pl (-17 / +31 lines)
Lines 27-32 use C4::Serials qw( CountSubscriptionFromBiblionumber ); Link Here
27
use Koha::Biblios;
27
use Koha::Biblios;
28
use Koha::Patrons;
28
use Koha::Patrons;
29
use Koha::ArticleRequests;
29
use Koha::ArticleRequests;
30
use Try::Tiny;
30
31
31
my $cgi = CGI->new;
32
my $cgi = CGI->new;
32
33
Lines 68-90 if ( $action eq 'create' ) { Link Here
68
    my $patron_notes = $cgi->param('patron_notes') || undef;
69
    my $patron_notes = $cgi->param('patron_notes') || undef;
69
    my $format       = $cgi->param('format')       || undef;
70
    my $format       = $cgi->param('format')       || undef;
70
71
71
    my $ar = Koha::ArticleRequest->new(
72
    try {
72
        {
73
        my $ar = Koha::ArticleRequest->new(
73
            borrowernumber => $borrowernumber,
74
            {
74
            biblionumber   => $biblionumber,
75
                borrowernumber => $borrowernumber,
75
            branchcode     => $branchcode,
76
                biblionumber   => $biblionumber,
76
            itemnumber     => $itemnumber,
77
                branchcode     => $branchcode,
77
            title          => $title,
78
                itemnumber     => $itemnumber,
78
            author         => $author,
79
                title          => $title,
79
            volume         => $volume,
80
                author         => $author,
80
            issue          => $issue,
81
                volume         => $volume,
81
            date           => $date,
82
                issue          => $issue,
82
            pages          => $pages,
83
                date           => $date,
83
            chapters       => $chapters,
84
                pages          => $pages,
84
            patron_notes   => $patron_notes,
85
                chapters       => $chapters,
85
            format         => $format,
86
                patron_notes   => $patron_notes,
86
        }
87
                format         => $format,
87
    )->store();
88
            }
89
        )->store();
90
    } catch {
91
        $template->param(
92
            error_message => $_->{message}
93
        );
94
    };
88
95
89
}
96
}
90
97
Lines 109-114 if ( !$patron && $patron_cardnumber ) { Link Here
109
    }
116
    }
110
}
117
}
111
118
119
if( $patron && !$patron->can_request_article) {
120
    $patron = undef;
121
    $template->param(
122
        error_message => 'Patron cannot request more articles for today'
123
    );
124
}
125
112
$template->param(
126
$template->param(
113
    biblio => $biblio,
127
    biblio => $biblio,
114
    patron => $patron,
128
    patron => $patron,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt (+14 lines)
Lines 110-115 Link Here
110
            This patron category already exists.
110
            This patron category already exists.
111
        [% CASE 'article_request_negative_fee' %]
111
        [% CASE 'article_request_negative_fee' %]
112
            Article request fee cannot be negative.
112
            Article request fee cannot be negative.
113
        [% CASE 'article_request_negative_limit' %]
114
            Maximum article request limit cannot be negative.
115
        [% CASE 'article_request_numeric_limit' %]
116
            Maximum article request limit must be a positive number.
113
        [% CASE %]
117
        [% CASE %]
114
            [% m.code | html %]
118
            [% m.code | html %]
115
        [% END %]
119
        [% END %]
Lines 209-214 Link Here
209
                    <label for="article_request_fee">Cost for article scan request</label>
213
                    <label for="article_request_fee">Cost for article scan request</label>
210
                    <input type="text" name="article_request_fee" id="article_request_fee" size="6" value="[% category.article_request_fee | $Price on_editing => 1 %]" />
214
                    <input type="text" name="article_request_fee" id="article_request_fee" size="6" value="[% category.article_request_fee | $Price on_editing => 1 %]" />
211
                </li>
215
                </li>
216
                <li>
217
                    <label for="article_request_limit">Maximum article scan requests</label>
218
                    <input type="text" name="article_request_limit" id="article_request_limit" size="6" value="[% category.article_request_limit | html %]" /> per day
219
                </li>
212
                [% END %]
220
                [% END %]
213
                <li>
221
                <li>
214
                    <label for="category_type" class="required">Category type: </label>
222
                    <label for="category_type" class="required">Category type: </label>
Lines 535-540 Link Here
535
                    <th scope="col">Hold fee</th>
543
                    <th scope="col">Hold fee</th>
536
                    [% IF Koha.Preference('ArticleRequests') %]
544
                    [% IF Koha.Preference('ArticleRequests') %]
537
                    <th scope="col">Article request fee</th>
545
                    <th scope="col">Article request fee</th>
546
                    <th scope="col">Maximum request limit</th>
538
                    [% END %]
547
                    [% END %]
539
                    [% IF ( EnhancedMessagingPreferences ) %]
548
                    [% IF ( EnhancedMessagingPreferences ) %]
540
                    <th scope="col">Messaging</th>
549
                    <th scope="col">Messaging</th>
Lines 600-605 Link Here
600
                            [% ELSE %]
609
                            [% ELSE %]
601
                                <td>-</td>
610
                                <td>-</td>
602
                            [% END %]
611
                            [% END %]
612
                            [% IF (category.article_request_limit > 0) %]
613
                                <td>[% category.article_request_limit | html %]</td>
614
                            [% ELSE %]
615
                                <td>-</td>
616
                            [% END %]
603
                        [% END %]
617
                        [% END %]
604
                        [% IF Koha.Preference('EnhancedMessagingPreferences') %]
618
                        [% IF Koha.Preference('EnhancedMessagingPreferences') %]
605
                            <td style="white-space: nowrap; font-size:80%;">
619
                            <td style="white-space: nowrap; font-size:80%;">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt (+5 lines)
Lines 47-52 Link Here
47
            <main>
47
            <main>
48
48
49
                    <h1>Request article from [% INCLUDE 'biblio-title.inc' link = 1 %]</h1>
49
                    <h1>Request article from [% INCLUDE 'biblio-title.inc' link = 1 %]</h1>
50
                    [% IF error_message %]
51
                        <div class="dialog alert">
52
                            <p>[% error_message | html %]</p>
53
                        </div>
54
                    [% END %]
50
                    [% IF no_patrons_found %]
55
                    [% IF no_patrons_found %]
51
                        <div class="dialog alert">
56
                        <div class="dialog alert">
52
                            <h3>Patron not found</h3>
57
                            <h3>Patron not found</h3>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-request-article.tt (-1 / +6 lines)
Lines 34-40 Link Here
34
    <div class="container-fluid maincontent">
34
    <div class="container-fluid maincontent">
35
        <div class="row">
35
        <div class="row">
36
            <div class="col">
36
            <div class="col">
37
                [% IF biblio.can_article_request( patron ) %]
37
                [% IF !error_message && biblio.can_article_request( patron ) %]
38
                    <h1>Place article request for [% biblio.title | html %]</h1>
38
                    <h1>Place article request for [% biblio.title | html %]</h1>
39
                    [% IF ( disclaimer && !action) %]
39
                    [% IF ( disclaimer && !action) %]
40
                        <div class="alert alert-warning">
40
                        <div class="alert alert-warning">
Lines 223-228 Link Here
223
                            <input type="submit" class="btn btn-primary" value="Place request" />
223
                            <input type="submit" class="btn btn-primary" value="Place request" />
224
                        </form>
224
                        </form>
225
                    [% END %]
225
                    [% END %]
226
                [% ELSIF error_message %]
227
                    <h1 class="title">[% biblio.title | html %]</h1>
228
                    <div class="alert alert-info">
229
                        [% error_message | html %]
230
                    </div>
226
                [% ELSE %]
231
                [% ELSE %]
227
                    <h1 class="title">[% biblio.title | html %]</h1>
232
                    <h1 class="title">[% biblio.title | html %]</h1>
228
                    <div class="alert alert-info">
233
                    <div class="alert alert-info">
(-)a/opac/opac-request-article.pl (-21 / +34 lines)
Lines 26-31 use C4::Output qw( output_html_with_http_headers ); Link Here
26
26
27
use Koha::Biblios;
27
use Koha::Biblios;
28
use Koha::Patrons;
28
use Koha::Patrons;
29
use Try::Tiny;
29
30
30
my $cgi = CGI->new;
31
my $cgi = CGI->new;
31
32
Lines 59-84 if ( $action eq 'create' ) { Link Here
59
    my $patron_notes = $cgi->param('patron_notes') || undef;
60
    my $patron_notes = $cgi->param('patron_notes') || undef;
60
    my $format       = $cgi->param('format')       || undef;
61
    my $format       = $cgi->param('format')       || undef;
61
62
62
    my $ar = Koha::ArticleRequest->new(
63
    try {
63
        {
64
        my $ar = Koha::ArticleRequest->new(
64
            borrowernumber => $borrowernumber,
65
            {
65
            biblionumber   => $biblionumber,
66
                borrowernumber => $borrowernumber,
66
            branchcode     => $branchcode,
67
                biblionumber   => $biblionumber,
67
            itemnumber     => $itemnumber,
68
                branchcode     => $branchcode,
68
            title          => $title,
69
                itemnumber     => $itemnumber,
69
            author         => $author,
70
                title          => $title,
70
            volume         => $volume,
71
                author         => $author,
71
            issue          => $issue,
72
                volume         => $volume,
72
            date           => $date,
73
                issue          => $issue,
73
            pages          => $pages,
74
                date           => $date,
74
            chapters       => $chapters,
75
                pages          => $pages,
75
            patron_notes   => $patron_notes,
76
                chapters       => $chapters,
76
            format         => $format,
77
                patron_notes   => $patron_notes,
77
        }
78
                format         => $format,
78
    )->store();
79
            }
79
80
        )->store();
80
    print $cgi->redirect("/cgi-bin/koha/opac-user.pl#opac-user-article-requests");
81
81
    exit;
82
        print $cgi->redirect("/cgi-bin/koha/opac-user.pl#opac-user-article-requests");
83
        exit;
84
    } catch {
85
        exit unless $_->[0] && $_->[0] eq 'EXIT';
86
        $template->param(
87
            error_message => $_->{message}
88
        );
89
    };
82
# Should we redirect?
90
# Should we redirect?
83
}
91
}
84
elsif ( !$action && C4::Context->preference('ArticleRequestsOpacHostRedirection') ) {
92
elsif ( !$action && C4::Context->preference('ArticleRequestsOpacHostRedirection') ) {
Lines 96-101 elsif ( !$action && C4::Context->preference('ArticleRequestsOpacHostRedirection' Link Here
96
104
97
my $patron = Koha::Patrons->find($borrowernumber);
105
my $patron = Koha::Patrons->find($borrowernumber);
98
106
107
if(!$patron->can_request_article) {
108
    $template->param(
109
        error_message => 'You cannot request more articles for today'
110
    );
111
}
112
99
$template->param(
113
$template->param(
100
    biblio => $biblio,
114
    biblio => $biblio,
101
    patron => $patron,
115
    patron => $patron,
102
- 

Return to bug 27945