diff --git a/internal/tender/email_template.go b/internal/tender/email_template.go new file mode 100644 index 0000000..fa7b110 --- /dev/null +++ b/internal/tender/email_template.go @@ -0,0 +1,483 @@ +package tender + +import ( + "fmt" + "html" + "strings" + "time" +) + +// TenderConfirmationEmailTemplateData represents the data needed for the tender confirmation email template +type TenderConfirmationEmailTemplateData struct { + TenderID string + TenderTitle string + TenderDescription string + SubmittedBy string + CompanyName string + CompanyEmail string + SubmittedAt int64 + EstimatedValue string + TenderDeadline int64 + CompanyLogo string + CompanyURL string + SupportEmail string +} + +// GenerateTenderConfirmationEmailTemplate generates a beautiful HTML email template for tender submission confirmation +func GenerateTenderConfirmationEmailTemplate(data *TenderConfirmationEmailTemplateData) string { + // Sanitize all user inputs before inserting into HTML + safeTenderTitle := html.EscapeString(data.TenderTitle) + safeTenderDescription := html.EscapeString(data.TenderDescription) + safeSubmittedBy := html.EscapeString(data.SubmittedBy) + safeCompanyName := html.EscapeString(data.CompanyName) + safeCompanyEmail := html.EscapeString(data.CompanyEmail) + + // Format dates + submittedAt := time.Unix(data.SubmittedAt, 0).Format("January 2, 2006 at 3:04 PM") + deadlineAt := time.Unix(data.TenderDeadline, 0).Format("January 2, 2006") + + emailHTML := ` + + + + + + Tender Submitted Successfully - {{COMPANY_NAME}} + + + +
+ +
+

Tender Submitted Successfully!

+

Your tender has been received and is now under review

+
+ + +
+
+
+ ✓ Your tender submission has been confirmed! +
+ +
+
{{TENDER_TITLE}}
+ +
+ Tender ID: + {{TENDER_ID}} +
+ +
+ Submitted By: + {{SUBMITTED_BY}} +
+ +
+ Company: + {{COMPANY_NAME}} +
+ +
+ Estimated Value: + {{ESTIMATED_VALUE}} +
+ +
+ Submission Deadline: + {{TENDER_DEADLINE}} +
+ +
+ Description:
+ {{TENDER_DESCRIPTION}} +
+
+ +
+ Submitted on: {{SUBMITTED_AT}} +
+

This email confirms your tender submission to {{COMPANY_NAME}}

+
+
+ +
+

🎯 What Happens Next?

+

Your tender is now in our review queue. Our procurement team will carefully evaluate your proposal against our requirements and selection criteria.

+

You'll receive notifications at each stage of the process, keeping you informed and giving you the opportunity to provide additional information if needed.

+

Why choose us? We value transparency, fairness, and efficiency in our tender process, ensuring all qualified suppliers have an equal opportunity to contribute to our projects.

+
+ +
+

Next Steps & Timeline

+
    +
  • Initial Review (1-2 business days): Our team will perform an initial assessment of your submission
  • +
  • Detailed Evaluation (3-5 business days): Comprehensive review against our requirements
  • +
  • Clarification Period (if needed): We'll contact you if we need additional information
  • +
  • Final Decision: You'll be notified of the outcome within the tender timeline
  • +
+
+ +
+

Need Help or Have Questions?

+

Email: {{SUPPORT_EMAIL}}

+

Portal: {{COMPANY_URL}}

+

Our team is here to support you throughout the tender process. Don't hesitate to reach out!

+
+
+ + + +
+ +` + + // Replace placeholders with sanitized data + emailHTML = strings.ReplaceAll(emailHTML, "{{COMPANY_NAME}}", safeCompanyName) + emailHTML = strings.ReplaceAll(emailHTML, "{{TENDER_ID}}", html.EscapeString(data.TenderID)) + emailHTML = strings.ReplaceAll(emailHTML, "{{TENDER_TITLE}}", safeTenderTitle) + emailHTML = strings.ReplaceAll(emailHTML, "{{TENDER_DESCRIPTION}}", safeTenderDescription) + emailHTML = strings.ReplaceAll(emailHTML, "{{SUBMITTED_BY}}", safeSubmittedBy) + emailHTML = strings.ReplaceAll(emailHTML, "{{COMPANY_EMAIL}}", safeCompanyEmail) + emailHTML = strings.ReplaceAll(emailHTML, "{{SUBMITTED_AT}}", submittedAt) + emailHTML = strings.ReplaceAll(emailHTML, "{{ESTIMATED_VALUE}}", html.EscapeString(data.EstimatedValue)) + emailHTML = strings.ReplaceAll(emailHTML, "{{TENDER_DEADLINE}}", deadlineAt) + emailHTML = strings.ReplaceAll(emailHTML, "{{SUPPORT_EMAIL}}", html.EscapeString(data.SupportEmail)) + emailHTML = strings.ReplaceAll(emailHTML, "{{COMPANY_URL}}", html.EscapeString(data.CompanyURL)) + + return emailHTML +} + +// GenerateTenderConfirmationEmailMessage generates a simple text message for the email +func GenerateTenderConfirmationEmailMessage(data *TenderConfirmationEmailTemplateData) string { + submittedAt := time.Unix(data.SubmittedAt, 0).Format("January 2, 2006 at 3:04 PM") + deadlineAt := time.Unix(data.TenderDeadline, 0).Format("January 2, 2006") + + return fmt.Sprintf(` +Tender Submission Confirmation + +✅ Your tender has been successfully submitted! + +Tender Details: +- Tender ID: %s +- Title: %s +- Submitted By: %s +- Company: %s +- Estimated Value: %s +- Submission Deadline: %s +- Submitted on: %s + +Description: +%s + +🎯 What Happens Next? +Your tender is now under review by our procurement team. Here's what to expect: + +1. Initial Review (1-2 business days): Preliminary assessment +2. Detailed Evaluation (3-5 business days): Comprehensive review +3. Clarification Period (if needed): We'll contact you for additional info +4. Final Decision: Notification of outcome within tender timeline + +Why Choose Us? +• Transparent and fair evaluation process +• Equal opportunity for all qualified suppliers +• Dedicated support throughout the tender process +• Clear communication at every stage + +Need Help? +Email: %s +Portal: %s + +This is an automated confirmation from %s. +Please save this email for your records. + +Best regards, +The Procurement Team +`, + data.TenderID, + data.TenderTitle, + data.SubmittedBy, + data.CompanyName, + data.EstimatedValue, + deadlineAt, + submittedAt, + data.TenderDescription, + data.SupportEmail, + data.CompanyURL, + data.CompanyName, + ) +} + +// GenerateTenderConfirmationEmailSubject generates an appropriate subject line for the email +func GenerateTenderConfirmationEmailSubject(data *TenderConfirmationEmailTemplateData) string { + return fmt.Sprintf("✅ Tender Submitted: %s (ID: %s)", data.TenderTitle, data.TenderID) +}