diff --git a/server/utils/emailService.js b/server/utils/emailService.js index c4d41d5..1f17f2e 100644 --- a/server/utils/emailService.js +++ b/server/utils/emailService.js @@ -151,7 +151,14 @@ export async function sendContactEmail(contactData) { // Send admin notification for new order export async function sendAdminNotification(orderDetails, customerEmail) { - const subject = `New Order: ${orderDetails.tons} tons CO₂ - $${(orderDetails.totalAmount / 100).toFixed(2)}`; + // totalAmount is already in dollars (converted before calling this function) + const totalAmount = typeof orderDetails.totalAmount === 'string' + ? orderDetails.totalAmount + : (orderDetails.totalAmount / 100).toFixed(2); + + // Format amount with commas for subject line + const formattedAmount = parseFloat(totalAmount).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ','); + const subject = `New Order: ${orderDetails.tons} tons CO₂ - $${formattedAmount}`; const adminEmail = process.env.ADMIN_EMAIL || 'matt@puffinoffset.com'; // Check if admin notifications are enabled @@ -167,7 +174,7 @@ export async function sendAdminNotification(orderDetails, customerEmail) { { tons: orderDetails.tons, portfolioId: orderDetails.portfolioId, - totalAmount: (orderDetails.totalAmount / 100).toFixed(2), + totalAmount: totalAmount, orderId: orderDetails.orderId, customerEmail, timestamp: new Date().toLocaleString('en-US', {