शिव परिवार पंजीकरण
मानव सेवा ही शिव सेवा
/* GOOGLE SCRIPT URL */
const scriptURL =
"https://script.google.com/macros/s/AKfycbw2y5w-8a1g3Y6hImdHhL-7kNLt8UbDRfqqN_ju1hAZr4EaLxyLxGgAaXquB8JfFqSJgg/exec";
/* TOTAL COUNT */
function updateTotal(){
let total =
(+maleCount.value || 0) +
(+femaleCount.value || 0) +
(+childCount.value || 0);
totalCount.value = total;
}
maleCount.oninput = updateTotal;
femaleCount.oninput = updateTotal;
childCount.oninput = updateTotal;
updateTotal();
/* QR SHOW */
relation.onchange = function(){
if(this.value === "sankalp"){
qrbox.style.display = "block";
}else{
qrbox.style.display = "none";
}
};
/* PDF FUNCTION */
function makePDF(data){
const { jsPDF } = window.jspdf;
let doc = new jsPDF();
doc.setFontSize(22);
doc.text("SHIV PARIWAR",60,20);
doc.setFontSize(14);
doc.text("Registration Receipt",60,35);
doc.line(10,40,200,40);
doc.text("Registration ID: " + data.id,20,60);
doc.text("Name: " + data.name,20,80);
doc.text("Mobile: " + data.mobile,20,100);
doc.text("Txn ID: " + data.txn,20,120);
doc.text("Har Har Mahadev",20,150);
doc.save("Receipt_" + data.id + ".pdf");
}
/* FORM SUBMIT */
document
.getElementById("familyForm")
.addEventListener("submit", async function(e){
e.preventDefault();
/* FORM DATA */
let formData = {
headName:
document.getElementById("headName").value,
mobile:
document.getElementById("mobile").value,
address:
document.getElementById("address").value,
maleCount:
document.getElementById("maleCount").value,
femaleCount:
document.getElementById("femaleCount").value,
childCount:
document.getElementById("childCount").value,
totalCount:
document.getElementById("totalCount").value,
regBy:
document.getElementById("regBy").value,
regById:
document.getElementById("regById").value,
txn:
document.getElementById("txn").value
};
/* OPEN WHATSAPP WINDOW */
let whatsappWindow = window.open("", "_blank");
try{
let response = await fetch(scriptURL,{
method:"POST",
body:JSON.stringify(formData)
});
let data = await response.json();
console.log(data);
if(data.success){
let id = data.id;
/* SUCCESS MESSAGE */
let successBox =
document.getElementById("successBox");
successBox.style.display = "block";
successBox.innerHTML =
"✅ सफल पंजीकरण
" +
"आपकी ID: " + id + "";
/* PDF DOWNLOAD */
makePDF({
id:id,
name:formData.headName,
mobile:formData.mobile,
txn:formData.txn
});
/* WHATSAPP MESSAGE */
let msg =
"🙏 हर हर महादेव %0A" +
"आपका Registration सफल हुआ। %0A" +
"आपकी ID: " + id;
/* OPEN WHATSAPP */
whatsappWindow.location =
"https://wa.me/91"+
formData.mobile+
"?text="+msg;
/* RESET FORM */
document
.getElementById("familyForm")
.reset();
updateTotal();
document
.getElementById("qrbox")
.style.display = "none";
}else{
alert("Server Error");
}
}
catch(err){
console.log(err);
alert("❌ Data Save Failed");
}
});

