import { db } from './firebase.js'; import { collection, addDoc } from "https://www.gstatic.com/firebasejs/9.22.1/firebase-firestore.js"; window.submitSurat = async function(e) { e.preventDefault(); const jenis = document.getElementById('jenisSurat').value; const nik = document.querySelector('input[placeholder="3302XXXXXXXXXXXX"]').value; const nama = document.getElementById('inputNamaPemohon').value.toUpperCase(); const hp = document.querySelector('input[placeholder="0812XXXXXXXX"]').value; const alamat = document.querySelector('input[placeholder="RT 01 / RW 02"]').value.toUpperCase(); const numPadded = String(Math.floor(100 + Math.random() * 900)); const romanMonths = ["I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII"]; const now = new Date(); const romanMonth = romanMonths[now.getMonth()]; const year = now.getFullYear(); const noRegis = `${numPadded}/${jenis}/${romanMonth}/${year}`; try { await addDoc(collection(db, "surat"), { noRegis: noRegis, nik: nik, nama: nama, jenis: jenis, hp: hp, alamat: alamat, status: "BERKAS SEDANG DIPROSES", created_at: new Date() }); } catch (err) { console.error("Gagal mengirim surat ke Firebase:", err); } document.getElementById('noRegistrasiTeks').innerText = noRegis; document.getElementById('modalRegistrasi').classList.remove('hidden'); document.getElementById('formSurat').reset(); selectCategory('SKU'); }