Bug 5770: Email librarian when purchase suggestion made
authorNazlı Çetin <nazli@devinim.com.tr>
Tue, 30 Apr 2019 15:50:43 +0000 (15:50 +0000)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 10 May 2019 17:29:30 +0000 (17:29 +0000)
Signed-off-by: Liz Rea <wizzyrea@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

C4/Suggestions.pm

index e2dd3e7..6958967 100644 (file)
@@ -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