From c892642d9f6ac3f342966e5ce71b6c8ed7937018 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nazl=C4=B1=20=C3=87etin?= Date: Tue, 30 Apr 2019 15:50:43 +0000 Subject: [PATCH] Bug 5770: Email librarian when purchase suggestion made Signed-off-by: Liz Rea Signed-off-by: Martin Renvoize Signed-off-by: Nick Clemens --- C4/Suggestions.pm | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm index e2dd3e7f91..6958967d9d 100644 --- a/C4/Suggestions.pm +++ b/C4/Suggestions.pm @@ -454,7 +454,38 @@ sub NewSuggestion { $suggestion->{suggesteddate} = dt_from_string unless $suggestion->{suggesteddate}; my $rs = Koha::Database->new->schema->resultset('Suggestion'); - return $rs->create($suggestion)->id; + my $new_id = $rs->create($suggestion)->id; + + my $full_suggestion = GetSuggestion( $new_id ); + if ( + my $letter = C4::Letters::GetPreparedLetter( + module => 'suggestions', + letter_code => 'NEW_SUGGESTION', + tables => { + 'branches' => $full_suggestion->{branchcode}, + 'borrowers' => $full_suggestion->{suggestedby}, + 'suggestions' => $full_suggestion, + }, + ) + ){ + my $emailpurchasesuggestions = C4::Context->preference("EmailPurchaseSuggestions"); + + my $toaddress = ( $emailpurchasesuggestions eq "BranchEmailAddress" ) + ? ( Koha::Libraries->find($full_suggestion->{branchcode})->branchemail || C4::Context->preference('KohaAdminEmailAddress') ) + : C4::Context->preference( $emailpurchasesuggestions ) ; + + C4::Letters::EnqueueLetter( + { + letter => $letter, + borrowernumber => $full_suggestion->{suggestedby}, + suggestionid => $full_suggestion->{suggestionid}, + to_address => $toaddress, + message_transport_type => 'email', + } + ) or warn "can't enqueue letter $letter"; + } + + return $new_id; } =head2 ModSuggestion -- 2.39.5