Jewellery Quotation - GBJ (Shopify)
Disc. Diamond (%)
Disc. Making (%)
Flat Making (%)
Add SKUs to create quotation cards.
'); win.document.close(); setTimeout(()=>{ win.focus(); win.print(); }, 700); } /* MAIN RENDER: respects checkbox visibility for discount rows and computes net & avg making */ function renderQuotes(){ const container = document.getElementById("quoteContainer"); container.innerHTML = ""; if(allQuotes.length === 0){ const ph = document.createElement('div'); ph.id = 'placeholderMsg'; ph.style.background = '#fff'; ph.style.padding = '18px'; ph.style.borderRadius = '10px'; ph.style.boxShadow = '0 6px 18px rgba(2,6,23,0.04)'; ph.style.textAlign = 'center'; ph.style.color = 'var(--muted)'; ph.innerText = 'Add SKUs to create quotation cards.'; container.appendChild(ph); document.getElementById("summaryWrap").style.display = "none"; document.getElementById("pvTotal").innerText = '₹0'; return; } // totals let totalGold = 0, totalDia = 0, totalStone = 0, totalMaking = 0, totalOthers = 0; let totGross = 0, totNet = 0, totDiaWt = 0, totStnWt = 0; const enableMaking = document.getElementById("enableMakingDiscount").checked; const enableDiamond = document.getElementById("enableDiamondDiscount").checked; const makingDiscountPercent = enableMaking ? parseFloat(document.getElementById("makingDiscountInput").value || "0") : 0; const diamondDiscountPercent = enableDiamond ? parseFloat(document.getElementById("diamondDiscountInput").value || "0") : 0; const enableFlatMaking = document.getElementById("enableFlatMaking").checked; const flatMakingPercent = enableFlatMaking ? parseFloat(document.getElementById("flatMakingPercentInput").value || "0") : 0; allQuotes.forEach((data) => { const gold = parseAmount(data["gold amount"] || data["goldamount"] || data["gold"] || data["gld"] ); const diaRaw = parseAmount(data["dia. amount"] || data["diamond amount"] || data["dia amount"] || data["dia"]); const stn = parseAmount(data["st. amount"] || data["stone amount"] || data["stn amount"] || data["stn"]); const others = parseAmount(data["others amount"] || data["other charges"] || data["others"]) || 0; const netWt = parseAmount(data["net.wt."] || data["net wt"] || data["net"] || data["netwt"]); const grossWt = parseAmount(data["gr.wt."] || data["gr.wt"] || data["gross wt"] || data["gr.wt."]); // making amount let makingBase = parseAmount(data["making amount"] || data["makingcharge"] || data["making"] ); let making = 0; if(enableFlatMaking && !isNaN(flatMakingPercent) && flatMakingPercent > 0){ making = gold * (flatMakingPercent / 100); } else { making = makingBase; } const makingDiscount = (enableMaking && !enableFlatMaking) ? making * (makingDiscountPercent / 100) : 0; const makingAfter = making - makingDiscount; const diaDiscount = enableDiamond ? diaRaw * (diamondDiscountPercent / 100) : 0; const diaAfter = diaRaw - diaDiscount; const subtotal = gold + diaAfter + stn + makingAfter + others; const gst = Math.round(subtotal * 0.03); const mrp = subtotal + gst; // add to totals totalGold += gold; totalDia += diaAfter; totalStone += stn; totalMaking += makingAfter; totalOthers += others; totGross += grossWt; totNet += netWt; totDiaWt += parseAmount(data["dia.wt."] || data["dia wt"] || data["diawt"]); totStnWt += parseAmount(data["stn.wt."] || data["stn wt"] || data["stnwt"]); // certificate const cert = (data["cert.no."] || data["cert no"] || data["cert"] || "").trim(); let certLink = ""; if(cert){ const isDGLA = cert.toLowerCase().startsWith("k1"); const link = isDGLA ? `https://www.dgla.co/online-tools/${cert}` : `https://www.igi.org/verify-your-report/?r=${cert}`; certLink = `${cert}`; } let makingPercentDisplay = ""; if(netWt > 0 && gold > 0){ const pct = (makingAfter / gold) * 100; makingPercentDisplay = `${pct.toFixed(2)} %`; } else if(data["making percent"] || data["making %"]) { makingPercentDisplay = (data["making percent"] || data["making %"]); } const showDiaDiscountRow = enableDiamond && diaDiscount > 0; const showMakingDiscountRow = enableMaking && !enableFlatMaking && makingDiscount > 0; // build card DOM const card = document.createElement("div"); card.className = "card"; card.setAttribute('data-uid', data._uid); card.innerHTML = `
${data["item name"] || data["item"] || data["name"] || ''}
${data["short description"] || data["description"] || ''}
SKU: ${data["sku"]||data["item code"]||''} • Size: ${data["size"]||''}
${data["item name"] || data["item"] || data["name"] || ''} ${data["carat"] ? ' — ' + data["carat"] + ' Gold' : ''}
${data["short description"] || data["description"] || ''}
${data["gr.wt."] ? `
Gross Weight
${data["gr.wt."]}
` : ''} ${data["net.wt."] ? `
Net Weight
${data["net.wt."]}
` : ''} ${data["dia.wt."] ? `
Diamond Weight
${data["dia.wt."]}
` : ''} ${data["stn.wt."] ? `
Stone Weight
${data["stn.wt."]}
` : ''}
Making %
${makingPercentDisplay || (data["making percent"]||data["making %"]||'')}
Certificate
${certLink || '—'}
Colour / Clarity
${(data["color"] || data["colour"] || '')}${data["clarity"] ? ' | ' + data["clarity"] : ''}
Gold Amount
₹ ${Math.round(gold).toLocaleString()}
${diaRaw > 0 ? `
Diamond Amount
₹ ${Math.round(diaAfter).toLocaleString()}
` : ''} ${stn > 0 ? `
Stone Amount
₹ ${Math.round(stn).toLocaleString()}
` : ''} ${showDiaDiscountRow ? `
Discount (Diamond)
-₹ ${Math.round(diaDiscount).toLocaleString()}
` : ''} ${making > 0 ? `
Making Charges
₹ ${Math.round(makingAfter).toLocaleString()}
` : ''} ${showMakingDiscountRow ? `
Discount (Making)
-₹ ${Math.round(makingDiscount).toLocaleString()}
` : ''} ${others > 0 ? `
Other Charges
₹ ${Math.round(others).toLocaleString()}
` : ''}
GST (3%)
₹ ${Math.round(gst).toLocaleString()}
MRP (Incl. GST)
₹ ${Math.round(mrp).toLocaleString()}
Valid until: ${new Date().toLocaleString('en-IN',{day:'2-digit',month:'short',year:'numeric', hour:'2-digit', minute:'2-digit'})}
© GBJ Jewels
`; const delBtn = card.querySelector('.deleteCard'); delBtn && delBtn.addEventListener('click', () => { deleteQuoteByUid(data._uid); }); container.appendChild(card); }); // summary and totals if(allQuotes.length > 0){ document.getElementById("summaryWrap").style.display = "flex"; // recompute totals robustly let totalGold2=0, totalDia2=0, totalStone2=0, totalMaking2=0, totalOthers2=0; let g=0,n=0,dw=0,sw=0; const enableMaking2 = document.getElementById("enableMakingDiscount").checked; const enableDiamond2 = document.getElementById("enableDiamondDiscount").checked; const enableFlat2 = document.getElementById("enableFlatMaking").checked; const makePct = enableMaking2 ? parseFloat(document.getElementById("makingDiscountInput").value||'0') : 0; const flatPctVal = enableFlat2 ? parseFloat(document.getElementById("flatMakingPercentInput").value||'0') : 0; allQuotes.forEach(data=>{ const gold = parseAmount(data["gold amount"] || data["goldamount"] || data["gold"] || data["gld"]); const diaRaw = parseAmount(data["dia. amount"] || data["diamond amount"] || data["dia amount"] || data["dia"]); const stn = parseAmount(data["st. amount"] || data["stone amount"] || data["stn amount"] || data["stn"]); const others = parseAmount(data["others amount"] || data["other charges"] || data["others"]) || 0; const netWt = parseAmount(data["net.wt."] || data["net wt"] || data["net"] || data["netwt"]); const grossWt = parseAmount(data["gr.wt."] || data["gr.wt"] || data["gross wt"] || data["gr.wt."]); let making = parseAmount(data["making amount"] || data["makingcharge"] || data["making"] ); if(enableFlat2 && !isNaN(flatPctVal) && flatPctVal > 0){ making = gold * (flatPctVal / 100); } const makingDiscount = (enableMaking2 && !enableFlat2) ? making * (makePct / 100) : 0; const makingAfter = making - makingDiscount; const diaDiscount = enableDiamond2 ? diaRaw * (parseFloat(document.getElementById("diamondDiscountInput").value||'0')/100) : 0; const diaAfter = diaRaw - diaDiscount; totalGold2 += gold; totalDia2 += diaAfter; totalStone2 += stn; totalMaking2 += makingAfter; totalOthers2 += others; g += grossWt; n += netWt; dw += parseAmount(data["dia.wt."] || data["dia wt"] || data["diawt"]); sw += parseAmount(data["stn.wt."] || data["stn wt"] || data["stnwt"]); }); document.getElementById("totalGross").innerText = g ? g.toFixed(3) + ' gm' : '—'; document.getElementById("totalNet").innerText = n ? n.toFixed(3) + ' gm' : '—'; document.getElementById("totalDiaWt").innerText = dw ? dw.toFixed(2) + ' ct' : '—'; document.getElementById("totalStnWt").innerText = sw ? sw.toFixed(2) + ' ct' : '—'; const avgMakingPct = totalGold2 > 0 ? ((totalMaking2 / totalGold2) * 100) : 0; document.getElementById("totalMakingPct").innerText = totalGold2 > 0 ? avgMakingPct.toFixed(2) + ' %' : '—'; const subtotal = totalGold2 + totalDia2 + totalStone2 + totalMaking2 + totalOthers2; const gstTotal = Math.round(subtotal * 0.03); const grandTotal = subtotal + gstTotal; document.getElementById("sumGold").innerText = '₹ ' + Math.round(totalGold2).toLocaleString(); document.getElementById("sumDia").innerText = '₹ ' + Math.round(totalDia2).toLocaleString(); document.getElementById("sumStn").innerText = '₹ ' + Math.round(totalStone2).toLocaleString(); document.getElementById("sumMak").innerText = '₹ ' + Math.round(totalMaking2).toLocaleString(); document.getElementById("sumOther").innerText = '₹ ' + Math.round(totalOthers2).toLocaleString(); document.getElementById("sumGst").innerText = '₹ ' + Math.round(gstTotal).toLocaleString(); document.getElementById("sumTotal").innerText = '₹ ' + Math.round(grandTotal).toLocaleString(); // compute discount totals (summary) only when checkboxes ON let totalDiaOriginal = totalDia2; if (document.getElementById("enableDiamondDiscount").checked){ const pct = parseFloat(document.getElementById("diamondDiscountInput").value || "0"); const denom = 1 - (pct / 100); totalDiaOriginal = denom > 0 ? (totalDia2 / denom) : totalDia2; } let totalMakingOriginal = totalMaking2; if (document.getElementById("enableMakingDiscount").checked && !document.getElementById("enableFlatMaking").checked){ const pct = parseFloat(document.getElementById("makingDiscountInput").value || "0"); const denom2 = 1 - (pct / 100); totalMakingOriginal = denom2 > 0 ? (totalMaking2 / denom2) : totalMaking2; } const totalDiaDiscount = Math.round(totalDiaOriginal - totalDia2); const totalMakingDiscount = Math.round(totalMakingOriginal - totalMaking2); document.getElementById("sumDiaDisc").innerText = (document.getElementById("enableDiamondDiscount").checked && totalDiaDiscount) ? ('-₹ ' + totalDiaDiscount.toLocaleString()) : '—'; document.getElementById("sumMakDisc").innerText = ((document.getElementById("enableMakingDiscount").checked && !document.getElementById("enableFlatMaking").checked) && totalMakingDiscount) ? ('-₹ ' + totalMakingDiscount.toLocaleString()) : '—'; document.getElementById("pvTotal").innerText = '₹ ' + Math.round(grandTotal).toLocaleString(); } else { document.getElementById("summaryWrap").style.display = "none"; } } /* init */ window.addEventListener('load', () => { document.getElementById('enableFlatMaking').addEventListener('change', onFlatMakingToggle); document.getElementById('enableMakingDiscount').addEventListener('change', onMakingDiscountToggle); loadCSV(); }); /* debug */ window._debug = { csvData, allQuotes, loadCSV, renderQuotes, deleteQuoteByUid, shareCardImage, showLoader, handleScannedInput };
BACK TO TOP