Comments added for explanation
This commit is contained in:
@@ -15,7 +15,7 @@ let pdfFile = process.argv[3];
|
|||||||
// pdf1 => /Users/ddatinguinoo/Downloads/G-S IPP 5.pdf
|
// pdf1 => /Users/ddatinguinoo/Downloads/G-S IPP 5.pdf
|
||||||
// pdf2 => /Users/ddatinguinoo/Downloads/H IPP 5.pdf
|
// pdf2 => /Users/ddatinguinoo/Downloads/H IPP 5.pdf
|
||||||
const data = []; // contains the info of all the clients
|
const data = []; // contains the info of all the clients
|
||||||
const tempFilePath = [];
|
const tempFilePath = []; // contains the temp files
|
||||||
|
|
||||||
const authConfig = {
|
const authConfig = {
|
||||||
sfdcTokenFile: process.env.SFDC_TOKEN_FILE, // Path to store/retrieve OAuth tokens
|
sfdcTokenFile: process.env.SFDC_TOKEN_FILE, // Path to store/retrieve OAuth tokens
|
||||||
@@ -51,7 +51,7 @@ async function attachPdfToAccount(sfdc) {
|
|||||||
let contentVersion;
|
let contentVersion;
|
||||||
for (let i = 0; i < tempFilePath.length; i++) {
|
for (let i = 0; i < tempFilePath.length; i++) {
|
||||||
// 1. Read the local PDF file and convert it to Base64
|
// 1. Read the local PDF file and convert it to Base64
|
||||||
const pdfBuffer = fs.readFileSync(tempFilePath[i]); // pdfFilePath is tempFilePath
|
const pdfBuffer = fs.readFileSync(tempFilePath[i]);
|
||||||
const base64Pdf = pdfBuffer.toString('base64');
|
const base64Pdf = pdfBuffer.toString('base64');
|
||||||
parser = new PDFParse({ data: pdfBuffer });
|
parser = new PDFParse({ data: pdfBuffer });
|
||||||
try {
|
try {
|
||||||
@@ -64,10 +64,12 @@ async function attachPdfToAccount(sfdc) {
|
|||||||
conditions.push(`CF__c='${ codiceFiscale }'`);
|
conditions.push(`CF__c='${ codiceFiscale }'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// since the name and lastname of the user are reversed, I need to put it in order
|
||||||
|
// to match the name from the database
|
||||||
const nameMatch = result.text.match(/Il\s+Sig\.\/La\s+Sig\.ra[ \t]+([A-Za-zÀ-ÿ']+(?:[ \t]+[A-Za-zÀ-ÿ']+)+)/i);
|
const nameMatch = result.text.match(/Il\s+Sig\.\/La\s+Sig\.ra[ \t]+([A-Za-zÀ-ÿ']+(?:[ \t]+[A-Za-zÀ-ÿ']+)+)/i);
|
||||||
|
|
||||||
if (nameMatch) {
|
if (nameMatch) {
|
||||||
const rawName = nameMatch[1].trim();
|
const rawName = nameMatch[1].trim()
|
||||||
const parts = rawName.split(/\s+/);
|
const parts = rawName.split(/\s+/);
|
||||||
|
|
||||||
if (parts.length >= 2) {
|
if (parts.length >= 2) {
|
||||||
@@ -81,7 +83,8 @@ async function attachPdfToAccount(sfdc) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// use the soql comand to search in the database
|
// use the soql command to search in the database
|
||||||
|
// if codice fiscale is not available, I search the user's account based on their name and lastname
|
||||||
const soql = `SELECT Id, Name FROM Account WHERE (${conditions.join(' OR ')}) ORDER BY CreatedDate DESC LIMIT 1`;
|
const soql = `SELECT Id, Name FROM Account WHERE (${conditions.join(' OR ')}) ORDER BY CreatedDate DESC LIMIT 1`;
|
||||||
const result_soql = await sfdc.query(soql);
|
const result_soql = await sfdc.query(soql);
|
||||||
if (result_soql && result_soql.records && result_soql.records.length > 0) { // if we find something
|
if (result_soql && result_soql.records && result_soql.records.length > 0) { // if we find something
|
||||||
@@ -110,7 +113,7 @@ async function attachPdfToAccount(sfdc) {
|
|||||||
async function uploadUserAccount() {
|
async function uploadUserAccount() {
|
||||||
await initializeSalesforceConnection();
|
await initializeSalesforceConnection();
|
||||||
|
|
||||||
// now for each client we need to create an Account on Salesforce
|
// now for each client we need to create an Account on Salesforce Sandbox
|
||||||
try {
|
try {
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
const firstName = (data[i].NOME || '').toString().trim();
|
const firstName = (data[i].NOME || '').toString().trim();
|
||||||
@@ -128,7 +131,7 @@ async function uploadUserAccount() {
|
|||||||
console.log('Something went wrong while creating the accounts: ', error);
|
console.log('Something went wrong while creating the accounts: ', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// this is where i need to store each page in a common temporary pdf file
|
// this is where i need to store each page in a temporary pdf file
|
||||||
async function processPage(pdfDoc, pageIndex) {
|
async function processPage(pdfDoc, pageIndex) {
|
||||||
try {
|
try {
|
||||||
const newDoc = await PDFDocument.create();
|
const newDoc = await PDFDocument.create();
|
||||||
@@ -146,7 +149,7 @@ async function processPage(pdfDoc, pageIndex) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function splitExcelFile(inputFile) {
|
async function splitExcelFile(inputFile) {
|
||||||
let numRows; // this parameter is needed when we need to analyze the pdf file in case it has duplicates
|
let numRows; // this parameter is needed when we need to analyze the pdf file in case it has duplicate pages
|
||||||
const columnNames = []; // contains the names of the columns (header names)
|
const columnNames = []; // contains the names of the columns (header names)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user