ELP Engineering & Consultancy LLP
ISO 9001:2015 Certified
MSME Registered
ELP Engineering | Operations Command Center

ELP Control Center

Authorized Workspace Entry

`); doc.close(); }// PRINT INVOICE AND SAVE AUTOMATICALLY function printAndSaveInvoiceSequence() { // 1. Gather values and write/append invoice metadata locally const titleType = document.getElementById('invDocTitle').value; const currencySymbol = document.getElementById('invCurrency').value; const invNumber = document.getElementById('invNum').value.trim(); const invDateValue = document.getElementById('invDate').value; const finalDate = invDateValue ? invDateValue : new Date().toISOString().split('T')[0];const fromCreator = document.getElementById('invFromCreator').value.trim(); const fromCompany = document.getElementById('invFromCompany').value.trim(); const fromEmail = document.getElementById('invFromEmail').value.trim(); const fromMobile = document.getElementById('invFromMobile').value.trim(); const fromAddress = document.getElementById('invFromAddress').value.trim(); const fromTax = document.getElementById('invFromTax').value.trim();const toName = document.getElementById('invToName').value.trim() || "John Doe"; const toCompany = document.getElementById('invToCompany').value.trim() || "L&T Switchyard Ltd"; const toEmail = document.getElementById('invToEmail').value.trim() || "client@ltindia.com"; const toMobile = document.getElementById('invToMobile').value.trim() || "+91-9988776655"; const toAddress = document.getElementById('invToAddress').value.trim() || "Gurugram, India"; const toTax = document.getElementById('invToTax').value.trim() || "07AABCL2035F1ZX";const gstPercent = parseFloat(document.getElementById('invGst').value) || 0; const discountVal = parseFloat(document.getElementById('invDiscount').value) || 0; const termsAndConditions = document.getElementById('invTerms').value.trim();let subtotal = 0; invoiceRows.forEach(r => { subtotal += (r.qty * r.rate); }); const gstAmount = subtotal * (gstPercent / 100); const totalVal = Math.max(0, subtotal + gstAmount - discountVal);const newInvoiceRecord = { titleType, currencySymbol, invNumber, date: finalDate, fromCreator, fromCompany, fromEmail, fromMobile, fromAddress, fromTax, toName, toCompany, toEmail, toMobile, toAddress, toTax, gstPercent, discountVal, termsAndConditions, rows: JSON.parse(JSON.stringify(invoiceRows)), totalVal: totalVal.toFixed(2) };// Save locally let localCache = JSON.parse(localStorage.getItem('elp_local_invoice_cache')) || []; const existingIdx = localCache.findIndex(i => i.invNumber === invNumber); const registryFormat = { invNumber: invNumber, toCompany: toCompany || toName, date: finalDate, totalVal: currencySymbol + totalVal.toFixed(2), raw: newInvoiceRecord };if (existingIdx !== -1) { localCache[existingIdx] = registryFormat; } else { localCache.push(registryFormat); } localStorage.setItem('elp_local_invoice_cache', JSON.stringify(localCache)); loadedInvoicesRegistry = localCache; renderSavedInvoicesHistory(); renderDashboardInvoicesHistory();// 2. Automatically dispatch sync payloads to the designated google sheets endpoint commitInvoiceToSheetSilently(newInvoiceRecord);// 3. Trigger Native Print (Bulletproof Isolated Single Page) setTimeout(() => { printFormattedInvoice(); }, 800); }// PUSHING TRANSACTION ENTRIES TO SPREADSHEET (SILENT SEQUENCE) function commitInvoiceToSheetSilently(invRecord) { if (!apiEndpoints.invoices) { triggerToast("Sync with Google Sheets skipped. Configure API Web App URL in 'Manage Portal'.", "error"); return; }let subtotal = 0; let itemsSummaryArray = []; invRecord.rows.forEach(r => { const total = r.qty * r.rate; subtotal += total; itemsSummaryArray.push(`${r.desc} (${r.qty} x ${r.rate})`); });const gstAmount = subtotal * (invRecord.gstPercent / 100); const grandTotal = Math.max(0, subtotal + gstAmount - invRecord.discountVal);const payload = { action: "save", invoiceNumber: invRecord.invNumber, clientName: invRecord.toCompany || invRecord.toName, clientEmail: invRecord.toEmail, date: invRecord.date, subtotal: invRecord.currencySymbol + subtotal.toFixed(2), gst: invRecord.currencySymbol + gstAmount.toFixed(2), total: invRecord.currencySymbol + grandTotal.toFixed(2), itemsSummary: `${invRecord.titleType}: ${itemsSummaryArray.join(' | ')} (From: ${invRecord.fromCompany})`, rawData: JSON.stringify(invRecord) // Backs up original rows so they can be re-loaded perfectly! };// Post dispatch using Apps Script fetch(apiEndpoints.invoices, { method: "POST", mode: "no-cors", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload) }) .then(() => { triggerToast("Invoice synced successfully to Sheet Tab: 'invoice details'.", "success"); // Refresh list to keep registry synced setTimeout(fetchInvoicesFromGoogleSheet, 1200); }) .catch(err => { triggerToast("Sync Exception: " + err.toString(), "error"); }); }function closeInvoiceModal() { document.getElementById('invoiceModal').classList.add('hidden'); }// Live Dashboard search filtering function filterDashboardInvoicesList() { const query = document.getElementById('dashboardSearchQuery').value; renderDashboardInvoicesHistory(query); }// GENERAL SYSTEM ROUTINES function handlePortalLogin(event) { event.preventDefault(); const enteredId = document.getElementById('employeeId').value.trim().toLowerCase(); const enteredPass = document.getElementById('employeePassword').value; const errBox = document.getElementById('loginErrorMessage');const isMaster = (enteredId === masterCreds.email && enteredPass === masterCreds.pass); const authenticatedUser = isMaster || portalEmployees.find(e => e.email === enteredId && e.pass === enteredPass);if (authenticatedUser) { errBox.classList.add('hidden'); document.getElementById('loginOverlay').classList.add('hidden'); document.getElementById('mainPortalWorkspace').classList.remove('hidden'); localStorage.setItem('elpSessionActive', 'true'); localStorage.setItem('elpUserIdentity', enteredId); triggerToast("Security Access Confirmed. Session initiated.", "success"); // Load sheets on successful login fetchInvoicesFromGoogleSheet(true); } else { errBox.classList.remove('hidden'); } }// SECURE SYSTEM LOGOUT function handlePortalLogout() { localStorage.removeItem('elpSessionActive'); localStorage.removeItem('elpUserIdentity'); window.location.reload(); }window.addEventListener('DOMContentLoaded', () => { initializePortalDashboard(); if (localStorage.getItem('elpSessionActive') === 'true') { document.getElementById('loginOverlay').classList.add('hidden'); document.getElementById('mainPortalWorkspace').classList.remove('hidden'); } });