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

(-)a/C4/Letters.pm (-12 / +13 lines)
Lines 758-775 sub _parseletter_sth { Link Here
758
    #       broke things for the rest of us. prepare_cached is a better
758
    #       broke things for the rest of us. prepare_cached is a better
759
    #       way to cache statement handles anyway.
759
    #       way to cache statement handles anyway.
760
    my $query = 
760
    my $query = 
761
    ($table eq 'biblio'       ) ? "SELECT * FROM $table WHERE   biblionumber = ?"                                  :
761
    ($table eq 'biblio'       )    ? "SELECT * FROM $table WHERE   biblionumber = ?"                                  :
762
    ($table eq 'biblioitems'  ) ? "SELECT * FROM $table WHERE   biblionumber = ?"                                  :
762
    ($table eq 'biblioitems'  )    ? "SELECT * FROM $table WHERE   biblionumber = ?"                                  :
763
    ($table eq 'items'        ) ? "SELECT * FROM $table WHERE     itemnumber = ?"                                  :
763
    ($table eq 'items'        )    ? "SELECT * FROM $table WHERE     itemnumber = ?"                                  :
764
    ($table eq 'issues'       ) ? "SELECT * FROM $table WHERE     itemnumber = ?"                                  :
764
    ($table eq 'issues'       )    ? "SELECT * FROM $table WHERE     itemnumber = ?"                                  :
765
    ($table eq 'old_issues'   ) ? "SELECT * FROM $table WHERE     itemnumber = ? ORDER BY timestamp DESC LIMIT 1"  :
765
    ($table eq 'old_issues'   )    ? "SELECT * FROM $table WHERE     itemnumber = ? ORDER BY timestamp DESC LIMIT 1"  :
766
    ($table eq 'reserves'     ) ? "SELECT * FROM $table WHERE borrowernumber = ? and biblionumber = ?"             :
766
    ($table eq 'reserves'     )    ? "SELECT * FROM $table WHERE borrowernumber = ? and biblionumber = ?"             :
767
    ($table eq 'borrowers'    ) ? "SELECT * FROM $table WHERE borrowernumber = ?"                                  :
767
    ($table eq 'borrowers'    )    ? "SELECT * FROM $table WHERE borrowernumber = ?"                                  :
768
    ($table eq 'branches'     ) ? "SELECT * FROM $table WHERE     branchcode = ?"                                  :
768
    ($table eq 'branches'     )    ? "SELECT * FROM $table WHERE     branchcode = ?"                                  :
769
    ($table eq 'suggestions'  ) ? "SELECT * FROM $table WHERE   suggestionid = ?"                                  :
769
    ($table eq 'suggestions'  )    ? "SELECT * FROM $table WHERE   suggestionid = ?"                                  :
770
    ($table eq 'aqbooksellers') ? "SELECT * FROM $table WHERE             id = ?"                                  :
770
    ($table eq 'aqbooksellers')    ? "SELECT * FROM $table WHERE             id = ?"                                  :
771
    ($table eq 'aqorders'     ) ? "SELECT * FROM $table WHERE    ordernumber = ?"                                  :
771
    ($table eq 'aqorders'     )    ? "SELECT * FROM $table WHERE    ordernumber = ?"                                  :
772
    ($table eq 'opac_news'    ) ? "SELECT * FROM $table WHERE          idnew = ?"                                  :
772
    ($table eq 'opac_news'    )    ? "SELECT * FROM $table WHERE          idnew = ?"                                  :
773
    ($table eq 'article_requests') ? "SELECT * FROM $table WHERE             id = ?"                                  :
773
    ($table eq 'borrower_modifications') ? "SELECT * FROM $table WHERE verification_token = ?" :
774
    ($table eq 'borrower_modifications') ? "SELECT * FROM $table WHERE verification_token = ?" :
774
    ($table eq 'subscription') ? "SELECT * FROM $table WHERE subscriptionid = ?" :
775
    ($table eq 'subscription') ? "SELECT * FROM $table WHERE subscriptionid = ?" :
775
    ($table eq 'serial') ? "SELECT * FROM $table WHERE serialid = ?" :
776
    ($table eq 'serial') ? "SELECT * FROM $table WHERE serialid = ?" :
(-)a/Koha/ArticleRequest.pm (+217 lines)
Line 0 Link Here
1
package Koha::ArticleRequest;
2
3
# Copyright ByWater Solutions 2015
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Carp;
23
24
use Koha::Database;
25
use Koha::Borrowers;
26
use Koha::Biblios;
27
use Koha::Items;
28
use Koha::Branches;
29
use Koha::ArticleRequest::Status;
30
31
use base qw(Koha::Object);
32
33
=head1 NAME
34
35
Koha::ArticleRequest - Koha Article Request Object class
36
37
=head1 API
38
39
=head2 Class Methods
40
41
=cut
42
43
=head3 open
44
45
=cut
46
47
sub open {
48
    my ($self) = @_;
49
50
    $self->status(Koha::ArticleRequest::Status::Open);
51
    $self->notify();
52
    return $self;
53
}
54
55
=head3 process
56
57
=cut
58
59
sub process {
60
    my ($self) = @_;
61
62
    $self->status(Koha::ArticleRequest::Status::Processing);
63
    $self->store();
64
    $self->notify();
65
    return $self;
66
}
67
68
=head3 complete
69
70
=cut
71
72
sub complete {
73
    my ($self) = @_;
74
75
    $self->status(Koha::ArticleRequest::Status::Completed);
76
    $self->store();
77
    $self->notify();
78
    return $self;
79
}
80
81
=head3 cancel
82
83
=cut
84
85
sub cancel {
86
    my ( $self, $notes ) = @_;
87
88
    $self->status(Koha::ArticleRequest::Status::Canceled);
89
    $self->notes($notes) if $notes;
90
    $self->store();
91
    $self->notify();
92
    return $self;
93
}
94
95
=head3 notify
96
97
=cut
98
99
sub notify {
100
    my ($self) = @_;
101
102
    my $status = $self->status;
103
104
    if (
105
        my $letter = C4::Letters::GetPreparedLetter(
106
            module                 => 'circulation',
107
            letter_code            => "AR_$status",
108
            message_transport_type => 'email',
109
            tables                 => {
110
                article_requests => $self->id,
111
                borrowers        => $self->borrowernumber,
112
                biblio           => $self->biblionumber,
113
                biblioitems      => $self->biblionumber,
114
                items            => $self->itemnumber,
115
                branches         => $self->branchcode,
116
            },
117
        )
118
      )
119
    {
120
        C4::Letters::EnqueueLetter(
121
            {
122
                letter                 => $letter,
123
                borrowernumber         => $self->borrowernumber,
124
                message_transport_type => 'email',
125
            }
126
        ) or warn "can't enqueue letter $letter";
127
    }
128
}
129
130
=head3 biblio
131
132
Returns the Koha::Biblio object for this article request
133
134
=cut
135
136
sub biblio {
137
    my ($self) = @_;
138
139
    $self->{_biblio} ||= Koha::Biblios->find( $self->biblionumber() );
140
141
    return $self->{_biblio};
142
}
143
144
=head3 item
145
146
Returns the Koha::Item object for this article request
147
148
=cut
149
150
sub item {
151
    my ($self) = @_;
152
153
    $self->{_item} ||= Koha::Items->find( $self->itemnumber() );
154
155
    return $self->{_item};
156
}
157
158
=head3 borrower
159
160
Returns the Koha::Borrower object for this article request
161
162
=cut
163
164
sub borrower {
165
    my ($self) = @_;
166
167
    $self->{_borrower} ||= Koha::Borrowers->find( $self->borrowernumber() );
168
169
    return $self->{_borrower};
170
}
171
172
=head3 branch
173
174
Returns the Koha::Branch object for this article request
175
176
=cut
177
178
sub branch {
179
    my ($self) = @_;
180
181
    $self->{_branch} ||= Koha::Branches->find( $self->branchcode() );
182
183
    return $self->{_branch};
184
}
185
186
=head3 store
187
188
Override the default store behavior so that new opan requests
189
will have notifications sent.
190
191
=cut
192
193
sub store {
194
    my ($self) = @_;
195
196
    return $self->SUPER::store() if $self->in_storage();
197
198
    my $r = $self->SUPER::store();
199
    $self->open();
200
    return $r;
201
}
202
203
=head3 type
204
205
=cut
206
207
sub type {
208
    return 'ArticleRequest';
209
}
210
211
=head1 AUTHOR
212
213
Kyle M Hall <kyle@bywatersolutions.com>
214
215
=cut
216
217
1;
(-)a/Koha/ArticleRequest/Status.pm (+44 lines)
Line 0 Link Here
1
package Koha::ArticleRequest::Status;
2
3
# Copyright ByWater Solutions 2015
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
sub Open {
23
    return 'OPEN';
24
}
25
26
sub Processing {
27
    return 'PROCESSING';
28
}
29
30
sub Completed {
31
    return 'COMPLETED';
32
}
33
34
sub Canceled {
35
    return 'CANCELED';
36
}
37
38
=head1 AUTHOR
39
40
Kyle M Hall <kyle@bywatersolutions.com>
41
42
=cut
43
44
1;
(-)a/Koha/ArticleRequests.pm (+103 lines)
Line 0 Link Here
1
package Koha::ArticleRequests;
2
3
# Copyright ByWater Solutions 2015
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Carp;
23
24
use Koha::Database;
25
26
use Koha::ArticleRequest;
27
use Koha::ArticleRequest::Status;
28
29
use base qw(Koha::Objects);
30
31
=head1 NAME
32
33
Koha::ArticleRequests - Koha ArticleRequests Object class
34
35
=head1 API
36
37
=head2 Class Methods
38
39
=cut
40
41
=head3 open
42
43
=cut
44
45
sub open {
46
    my ( $self, $branchcode ) = @_;
47
    my $params = { status => Koha::ArticleRequest::Status::Open };
48
    $params->{branchcode} = $branchcode if $branchcode;
49
    return Koha::ArticleRequests->search( $params );
50
}
51
52
=head3 processing
53
54
=cut
55
56
sub processing {
57
    my ( $self, $branchcode ) = @_;
58
    my $params = { status => Koha::ArticleRequest::Status::Processing };
59
    $params->{branchcode} = $branchcode if $branchcode;
60
    return Koha::ArticleRequests->search( $params );
61
}
62
63
=head3 completed
64
65
=cut
66
67
sub completed {
68
    my ( $self, $branchcode ) = @_;
69
    my $params = { status => Koha::ArticleRequest::Status::Completed };
70
    $params->{branchcode} = $branchcode if $branchcode;
71
    return Koha::ArticleRequests->search( $params );
72
}
73
74
=head3 canceled
75
76
=cut
77
78
sub canceled {
79
    my ( $self, $branchcode ) = @_;
80
    my $params = { status => Koha::ArticleRequest::Status::Canceled };
81
    $params->{branchcode} = $branchcode if $branchcode;
82
    return Koha::ArticleRequests->search( $params );
83
}
84
85
=head3 type
86
87
=cut
88
89
sub type {
90
    return 'ArticleRequest';
91
}
92
93
sub object_class {
94
    return 'Koha::ArticleRequest';
95
}
96
97
=head1 AUTHOR
98
99
Kyle M Hall <kyle@bywatersolutions.com>
100
101
=cut
102
103
1;
(-)a/Koha/Biblio.pm (+175 lines)
Lines 25-30 use Koha::Database; Link Here
25
25
26
use base qw(Koha::Object);
26
use base qw(Koha::Object);
27
27
28
use C4::Circulation qw(GetIssuingRule);
29
use Koha::Items;
30
use Koha::ArticleRequests;
31
use Koha::ArticleRequest::Status;
32
28
=head1 NAME
33
=head1 NAME
29
34
30
Koha::Biblio - Koha Biblio Object class
35
Koha::Biblio - Koha Biblio Object class
Lines 35-40 Koha::Biblio - Koha Biblio Object class Link Here
35
40
36
=cut
41
=cut
37
42
43
=head3 can_article_request
44
45
my $bool = $biblio->can_article_request( $borrower );
46
47
Returns true if article requests can be made for this record
48
49
$borrower must be a Koha::Borrower object
50
51
=cut
52
53
sub can_article_request {
54
    my ( $self, $borrower ) = @_;
55
56
    my $rule = $self->article_request_type($borrower);
57
    return q{} if $rule eq 'item_only' && !$self->items()->count();
58
    return 1 if $rule && $rule ne 'no';
59
60
    return q{};
61
}
62
63
=head3 article_request_type
64
65
my $type = $biblio->article_request_type( $borrower );
66
67
Returns the article request type based on items, or on the record
68
itself if there are no items.
69
70
$borrower must be a Koha::Borrower object
71
72
=cut
73
74
sub article_request_type {
75
    my ( $self, $borrower ) = @_;
76
77
    my $rule = $self->article_request_type_for_items( $borrower );
78
    return $rule if $rule;
79
80
    # If the record has no items that are requestable, go by the record itemtype
81
    $rule = $self->article_request_type_for_bib($borrower);
82
    return $rule if $rule;
83
84
    return q{};
85
}
86
87
=head3 article_request_type_for_bib
88
89
my $type = $biblio->article_request_type_for_bib
90
91
Returns the article request type 'yes', 'no', 'item_only', 'bib_only', for the given record
92
93
=cut
94
95
sub article_request_type_for_bib {
96
    my ( $self, $borrower ) = @_;
97
98
    my $borrowertype = $borrower->categorycode;
99
    my $itemtype     = $self->itemtype();
100
    my $rules        = GetIssuingRule( $borrowertype, $itemtype );
101
102
    return $rules->{article_requests} || q{};
103
}
104
105
=head3 article_request_type_for_items
106
107
my $type = $biblio->article_request_type_for_items
108
109
Returns the article request type 'yes', 'no', 'item_only', 'bib_only', for the given record's items
110
111
If there is a conflict where some items are 'bib_only' and some are 'item_only', 'bib_only' will be returned.
112
113
=cut
114
115
sub article_request_type_for_items {
116
    my ( $self, $borrower ) = @_;
117
118
    my $counts;
119
    foreach my $item ( $self->items()->as_list() ) {
120
        my $rule = $item->article_request_type($borrower);
121
        return $rule if $rule eq 'bib_only';    # we don't need to go any further
122
        $counts->{$rule}++;
123
    }
124
125
    return 'item_only' if $counts->{item_only};
126
    return 'yes'       if $counts->{yes};
127
    return 'no'        if $counts->{no};
128
    return q{};
129
}
130
131
=head3 article_requests
132
133
my @requests = $biblio->article_requests
134
135
Returns the article requests associated with this Biblio
136
137
=cut
138
139
sub article_requests {
140
    my ( $self, $borrower ) = @_;
141
142
    $self->{_article_requests} ||= Koha::ArticleRequests->search( { biblionumber => $self->biblionumber() } );
143
144
    return wantarray ? $self->{_article_requests}->as_list : $self->{_article_requests};
145
}
146
147
=head3 article_requests_current
148
149
my @requests = $biblio->article_requests_current
150
151
Returns the article requests associated with this Biblio that are incomplete
152
153
=cut
154
155
sub article_requests_current {
156
    my ( $self, $borrower ) = @_;
157
158
    $self->{_article_requests_current} ||= Koha::ArticleRequests->search(
159
        {
160
            biblionumber => $self->biblionumber(),
161
            -or          => [
162
                { status => Koha::ArticleRequest::Status::Open },
163
                { status => Koha::ArticleRequest::Status::Processing }
164
            ]
165
        }
166
    );
167
168
    return wantarray ? $self->{_article_requests_current}->as_list : $self->{_article_requests_current};
169
}
170
171
=head3 article_requests_finished
172
173
my @requests = $biblio->article_requests_finished
174
175
Returns the article requests associated with this Biblio that are completed
176
177
=cut
178
179
sub article_requests_finished {
180
    my ( $self, $borrower ) = @_;
181
182
    $self->{_article_requests_finished} ||= Koha::ArticleRequests->search(
183
        {
184
            biblionumber => $self->biblionumber(),
185
            -or          => [
186
                { status => Koha::ArticleRequest::Status::Completed },
187
                { status => Koha::ArticleRequest::Status::Canceled }
188
            ]
189
        }
190
    );
191
192
    return wantarray ? $self->{_article_requests_finished}->as_list : $self->{_article_requests_finished};
193
}
194
195
=head3 items
196
197
my @items = $biblio->items();
198
my $items = $biblio->items();
199
200
Returns a list of Koha::Item objects or a Koha::Items object of
201
items associated with this bib
202
203
=cut
204
205
sub items {
206
    my ( $self ) = @_;
207
208
    $self->{_items} ||= Koha::Items->search({ biblionumber => $self->biblionumber() });
209
210
    return $self->{_items};
211
}
212
38
=head3 type
213
=head3 type
39
214
40
=cut
215
=cut
(-)a/Koha/Biblios.pm (-1 / +1 lines)
Lines 1-6 Link Here
1
package Koha::Biblios;
1
package Koha::Biblios;
2
2
3
# Copyright ByWater Solutions 2014
3
# Copyright ByWater Solutions 2015
4
#
4
#
5
# This file is part of Koha.
5
# This file is part of Koha.
6
#
6
#
(-)a/Koha/Borrower.pm (+70 lines)
Lines 23-28 use Carp; Link Here
23
23
24
use Koha::Database;
24
use Koha::Database;
25
25
26
use Koha::ArticleRequests;
27
use Koha::ArticleRequest::Status;
28
26
use base qw(Koha::Object);
29
use base qw(Koha::Object);
27
30
28
=head1 NAME
31
=head1 NAME
Lines 35-40 Koha::Borrower - Koha Borrower Object class Link Here
35
38
36
=cut
39
=cut
37
40
41
=head3 article_requests
42
43
my @requests = $borrower->article_requests();
44
my $requests = $borrower->article_requests();
45
46
Returns either a list of ArticleRequests objects,
47
or an ArtitleRequests object, depending on the
48
calling context.
49
50
=cut
51
52
sub article_requests {
53
    my ( $self ) = @_;
54
55
    $self->{_article_requests} ||= Koha::ArticleRequests->search({ borrowernumber => $self->borrowernumber() });
56
57
    return $self->{_article_requests};
58
}
59
60
=head3 article_requests_current
61
62
my @requests = $patron->article_requests_current
63
64
Returns the article requests associated with this patron that are incomplete
65
66
=cut
67
68
sub article_requests_current {
69
    my ( $self ) = @_;
70
71
    $self->{_article_requests_current} ||= Koha::ArticleRequests->search(
72
        {
73
            borrowernumber => $self->id(),
74
            -or          => [
75
                { status => Koha::ArticleRequest::Status::Open },
76
                { status => Koha::ArticleRequest::Status::Processing }
77
            ]
78
        }
79
    );
80
81
    return $self->{_article_requests_current};
82
}
83
84
=head3 article_requests_finished
85
86
my @requests = $biblio->article_requests_finished
87
88
Returns the article requests associated with this patron that are completed
89
90
=cut
91
92
sub article_requests_finished {
93
    my ( $self, $borrower ) = @_;
94
95
    $self->{_article_requests_finished} ||= Koha::ArticleRequests->search(
96
        {
97
            borrowernumber => $self->id(),
98
            -or          => [
99
                { status => Koha::ArticleRequest::Status::Completed },
100
                { status => Koha::ArticleRequest::Status::Canceled }
101
            ]
102
        }
103
    );
104
105
    return $self->{_article_requests_finished};
106
}
107
38
=head3 type
108
=head3 type
39
109
40
=cut
110
=cut
(-)a/Koha/Item.pm (-2 / +45 lines)
Lines 21-28 use Modern::Perl; Link Here
21
21
22
use Carp;
22
use Carp;
23
23
24
use Koha::Database;
24
use C4::Context;
25
25
use C4::Circulation qw(GetIssuingRule);
26
use Koha::Branches;
26
use Koha::Branches;
27
27
28
use base qw(Koha::Object);
28
use base qw(Koha::Object);
Lines 73-78 sub holding_branch { Link Here
73
    return $self->{_holding_branch};
73
    return $self->{_holding_branch};
74
}
74
}
75
75
76
=head3 can_article_request
77
78
my $bool = $item->can_article_request( $borrower )
79
80
Returns true if item can be specifically requested
81
82
$borrower must be a Koha::Borrower object
83
84
=cut
85
86
sub can_article_request {
87
    my ( $self, $borrower ) = @_;
88
89
    my $rule = $self->article_request_type($borrower);
90
91
    return 1 if $rule && $rule ne 'no' && $rule ne 'bib_only';
92
    return q{};
93
}
94
95
=head3 article_request_type
96
97
my $type = $item->article_request_type( $borrower )
98
99
returns 'yes', 'no', 'bib_only', or 'item_only'
100
101
$borrower must be a Koha::Borrower object
102
103
=cut
104
105
sub article_request_type {
106
    my ( $self, $borrower ) = @_;
107
108
    my $branch_control = C4::Context->preference('HomeOrHoldingBranch');
109
    my $branchcode =
110
        $branch_control eq 'homebranch'    ? $self->homebranch
111
      : $branch_control eq 'holdingbranch' ? $self->holdingbranch
112
      :                                      undef;
113
    my $borrowertype = $borrower->categorycode;
114
    my $itemtype = $self->effective_itemtype();
115
    my $rules = GetIssuingRule( $borrowertype, $itemtype, $branchcode );
116
117
    return $rules->{article_requests} || q{};
118
}
76
119
77
=head3 type
120
=head3 type
78
121
(-)a/Koha/Template/Plugin/Biblio.pm (-1 / +11 lines)
Lines 23-28 use Template::Plugin; Link Here
23
use base qw( Template::Plugin );
23
use base qw( Template::Plugin );
24
24
25
use Koha::Holds;
25
use Koha::Holds;
26
use Koha::Biblios;
27
use Koha::Borrowers;
26
28
27
sub HoldsCount {
29
sub HoldsCount {
28
    my ( $self, $biblionumber ) = @_;
30
    my ( $self, $biblionumber ) = @_;
Lines 32-35 sub HoldsCount { Link Here
32
    return $holds->count();
34
    return $holds->count();
33
}
35
}
34
36
37
sub CanArticleRequest {
38
    my ( $self, $biblionumber, $borrowernumber ) = @_;
39
40
    my $biblio = Koha::Biblios->find( $biblionumber );
41
    my $borrower = Koha::Borrowers->find( $borrowernumber );
42
43
    return $biblio ? $biblio->can_article_request( $borrower ) : 0;
44
}
45
35
1;
46
1;
36
- 

Return to bug 14610