Alan Lam 3 лет назад
Родитель
Сommit
a5ed3c62fa
3 измененных файлов с 15 добавлено и 2 удалено
  1. 8 1
      controllers/document.php
  2. 6 0
      public/js/document-page.js
  3. 1 1
      templates/email/document.html

+ 8 - 1
controllers/document.php

@@ -458,22 +458,29 @@ $controller = new class($document_type, $document_number) {
 			}
 
 			$title = $document->getTitle();
+			$text = "Hereby attached is your information.";
 
 			if($document->isSalesOrder()) {
 				if($variant === "commercial") {
 					$title = __("Commercial Invoice %d", $document->number);
+					$text = __("Hereby attached is your Commercial Invoice as requested.");
 				}
 				else {
 					$title = __("Proforma Invoice %d", $document->number);
+					$text = __("Hereby attached is your Pro-forma Offer.");
 				}
 			}
+			if($document->isDeliveryNote()) {
+				$text = __("Hereby attached is your Delivery Note information.");
+			}
 
 			$body = file_get_contents("templates/email/document.html");
 			$search_replace = [
 				"%contact-name%" => $document->contact_name,
 				"%document-title%" => $title,
 				"%company-name%" => $company->name,
-				"%user-name%" => $user->getDisplayName()
+				"%user-name%" => $user->getDisplayName(),
+				"%document-text%" => $text
 			];
 			$body = str_replace(array_keys($search_replace), array_values($search_replace), $body);
 

+ 6 - 0
public/js/document-page.js

@@ -54,10 +54,16 @@ class DocumentPage {
 			const { variant } = $element.data();
 
 			DocumentPage.SaveForm().then(() => {
+				toastr.info("Emailing PDF...");
 				$.post(window.location + "/email-pdf", {
 					variant: variant
 				}).then(() => {
 					toastr.success("Email sent successfully.");
+				}).catch(error => {
+					const { responseJSON } = error;
+					if(responseJSON && responseJSON.message) {
+						toastr.error(responseJSON.message);
+					}
 				});
 			});
 		});

+ 1 - 1
templates/email/document.html

@@ -17,7 +17,7 @@
 		Dear %contact-name%,
 	</p>
 	<p>
-		Thank you for your continued custom. Hereby attached is your information.
+		Thank you for your continued custom. %document-text%
 	</p>
 	<p>
 		Regards,<br />