implement order number adjustment using 27470 in email and PDF generation

This commit is contained in:
Alaguraj0361 2026-06-02 16:48:11 +05:30
parent d848ac1462
commit 5097f60569
3 changed files with 31 additions and 2 deletions

View File

@ -11,3 +11,6 @@ SMTP_SECURE=false
SMTP_USER=your_email@gmail.com
SMTP_PASS=your_email_password_or_app_password
SMTP_FROM_EMAIL=your_email@gmail.com
# Order number offset (Next Shopify order is 1018. To make it start from 28470, offset is 28470 - 1018 = 27452)
ORDER_NUMBER_OFFSET=27470

View File

@ -2,6 +2,19 @@ const nodemailer = require('nodemailer');
const fs = require('fs');
const path = require('path');
/**
* Helper to adjust order number using ORDER_NUMBER_OFFSET
*/
const getAdjustedOrderNumber = (orderNumberOrName) => {
if (!orderNumberOrName) return '';
const offset = parseInt(27470, 10) || 0;
const str = orderNumberOrName.toString();
const matches = str.match(/\d+/);
if (!matches) return str;
const num = parseInt(matches[0], 10);
return (num + offset).toString();
};
/**
* Sends a premium custom email with the PDF attachment.
* @param {string} toEmail - The recipient's email address
@ -22,7 +35,7 @@ const sendEmailWithAttachment = async (toEmail, orderData, pdfBuffer) => {
}
});
const orderNumber = orderData.order_number || orderData.name;
const orderNumber = getAdjustedOrderNumber(orderData.order_number || orderData.name);
const currencySymbol = orderData.currency === 'INR' ? 'Rs. ' : `${orderData.currency} `;
// Check if local logo exists for CID inline attachment

View File

@ -37,6 +37,19 @@ async function fetchImageBuffer(url) {
}
}
/**
* Helper to adjust order number using ORDER_NUMBER_OFFSET
*/
const getAdjustedOrderNumber = (orderNumberOrName) => {
if (!orderNumberOrName) return '';
const offset = parseInt(27470, 10) || 0;
const str = orderNumberOrName.toString();
const matches = str.match(/\d+/);
if (!matches) return str;
const num = parseInt(matches[0], 10);
return (num + offset).toString();
};
/**
* Generates a PDF invoice matching the user's custom layout.
* @param {Object} orderData - The Shopify order payload
@ -177,7 +190,7 @@ const generateInvoicePDF = async (orderData) => {
doc.fontSize(14)
.font('Helvetica-Bold')
.fillColor(primaryColor)
.text(`Order no: ${orderData.order_number}`, 380, detailsY)
.text(`Order no: ${getAdjustedOrderNumber(orderData.order_number)}`, 380, detailsY)
.fontSize(10)
.font('Helvetica-Bold')
.text('Order date: ', 380, detailsY + 22, { continued: true })