1 package Koha::Suggestion;
3 # Copyright ByWater Solutions 2015
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
26 use Koha::DateUtils qw( dt_from_string );
29 use base qw(Koha::Object);
33 Koha::Suggestion - Koha Suggestion object class
43 Override the default store behavior so that new suggestions have
44 a suggesteddate of today
51 $self->STATUS("ASKED") unless $self->STATUS;
53 $self->branchcode(undef) if defined $self->branchcode && $self->branchcode eq '';
54 unless ( $self->suggesteddate() ) {
55 $self->suggesteddate( dt_from_string()->ymd );
58 my $emailpurchasesuggestions = C4::Context->preference("EmailPurchaseSuggestions");
60 my $result = $self->SUPER::store();
62 if( $emailpurchasesuggestions ){
65 my $letter = C4::Letters::GetPreparedLetter(
66 module => 'suggestions',
67 letter_code => 'NEW_SUGGESTION',
69 'branches' => $result->branchcode,
70 'borrowers' => $result->suggestedby,
71 'suggestions' => $result->unblessed,
77 if ( $emailpurchasesuggestions eq "BranchEmailAddress" ) {
78 my $library = $result->library;
79 $toaddress = $library->inbound_email_address;
81 elsif ( $emailpurchasesuggestions eq "KohaAdminEmailAddress" ) {
82 $toaddress = C4::Context->preference('ReplytoDefault')
83 || C4::Context->preference('KohaAdminEmailAddress');
87 C4::Context->preference($emailpurchasesuggestions)
88 || C4::Context->preference('ReplytoDefault')
89 || C4::Context->preference('KohaAdminEmailAddress');
92 C4::Letters::EnqueueLetter(
95 borrowernumber => $result->suggestedby,
96 suggestionid => $result->id,
97 to_address => $toaddress,
98 message_transport_type => 'email',
100 ) or warn "can't enqueue letter $letter";
109 my $library = $suggestion->library;
111 Returns the library of the suggestion (Koha::Library for branchcode field)
117 my $library_rs = $self->_result->branchcode;
118 return unless $library_rs;
119 return Koha::Library->_new_from_dbic($library_rs);
124 my $patron = $suggestion->suggester
126 Returns the I<Koha::Patron> for the suggestion generator. I<undef> is
127 returned if no suggester is linked.
134 my $suggester_rs = $self->_result->suggester;
135 return unless $suggester_rs;
136 return Koha::Patron->_new_from_dbic($suggester_rs);
141 my $manager = $suggestion->manager;
143 Returns the manager of the suggestion (Koha::Patron for managedby field)
149 my $manager_rs = $self->_result->managedby;
150 return unless $manager_rs;
151 return Koha::Patron->_new_from_dbic($manager_rs);
156 my $rejecter = $suggestion->rejecter;
158 Returns the rejecter of the suggestion (Koha::Patron for rejectebby field)
164 my $rejecter_rs = $self->_result->managedby;
165 return unless $rejecter_rs;
166 return Koha::Patron->_new_from_dbic($rejecter_rs);
171 my $last_modifier = $suggestion->last_modifier;
173 Returns the librarian who last modified the suggestion (Koha::Patron for lastmodificationby field)
179 my $last_modifier_rs = $self->_result->managedby;
180 return unless $last_modifier_rs;
181 return Koha::Patron->_new_from_dbic($last_modifier_rs);
186 my $fund = $suggestion->fund;
188 Return the fund associated to the suggestion
194 my $fund_rs = $self->_result->budgetid;
195 return unless $fund_rs;
196 return Koha::Acquisition::Fund->_new_from_dbic($fund_rs);
207 =head3 to_api_mapping
209 This method returns the mapping for representing a Koha::Patron object
216 suggestionid => 'suggestion_id',
217 suggestedby => 'suggested_by',
218 suggesteddate => 'suggestion_date',
219 managedby => 'managed_by',
220 manageddate => 'managed_date',
221 acceptedby => 'accepted_by',
222 accepteddate => 'accepted_date',
223 rejectedby => 'rejected_by',
224 rejecteddate => 'rejected_date',
225 lastmodificationdate => 'last_status_change_date',
226 lastmodificationby => 'last_status_change_by',
229 staff_note => 'staff_note',
232 copyrightdate => 'copyright_date',
233 publishercode => 'publisher_code',
235 volumedesc => 'volume_desc',
236 publicationyear => 'publication_year',
237 place => 'publication_place',
239 biblionumber => 'biblio_id',
241 patronreason => 'patron_reason',
242 budgetid => 'budget_id',
243 branchcode => 'library_id',
244 collectiontitle => 'collection_title',
245 itemtype => 'item_type',
246 quantity => 'quantity',
247 currency => 'currency',
248 price => 'item_price',
249 total => 'total_price',
250 archived => 'archived',
256 Kyle M Hall <kyle@bywatersolutions.com>