• December 2, 2025

    ผลรวม
    tp+=parseFloat(c[4].value)

    เปลี่ยนเป็น
    // 🟢 NEW FIX: ลบคอมม่าออกก่อนคำนวณ const premiumValueCleaned = c[4].value.replace(/,/g, ”); tp += parseFloat(premiumValueCleaned) || 0;

    โค๊ด จะเป็น

    const c=tr.querySelectorAll('input'); 
            if (c.length >= 7) { 
                 // Premium index 4, paid index 5, Pay index 6
                 // 🟢 NEW FIX: ลบคอมม่าออกก่อนคำนวณ
                 const premiumValueCleaned = c[4].value.replace(/,/g, '');
                 tp += parseFloat(premiumValueCleaned) || 0;
                 /*trv+=parseFloat(c[5].value)||0;
                 py+=parseFloat(c[6].value)||0;*/			 
            }
        });
        
        /*document.getElementById('sumPremium').textContent=tp.toFixed(2);
    	document.getElementById('sumpaid').textContent=trv.toFixed(2);
        document.getElementById('sumPay').textContent=py.toFixed(2);*/
    
        document.getElementById("sumPremium").textContent =
        tp.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 });	
    }

    เดิม
    { type: ‘number’, value: d.premium },

    เปลี่ยนเป็น
    { type: ‘text’, value: parseFloat(d.premium || 0).toLocaleString(‘en-US’, { minimumFractionDigits: 2, maximumFractionDigits: 2 }) },

    เพิ่ม Event Listener เพื่อจัดรูปแบบเมื่อผู้ใช้กรอก

    ถึงแม้เราจะเปลี่ยนเป็น type="text" แล้ว แต่เราต้องแนบ Event Listener เพื่อจัดรูปแบบเมื่อผู้ใช้กรอกข้อมูลเสร็จสิ้น (Blur) และอนุญาตให้พิมพ์ตัวเลขและจุดทศนิยมได้

    เพิ่มโค้ดใหม่ ในส่วนท้ายของการวนลูป cellData.forEach ภายในฟังก์ชัน createTableRow(d):
    ตำแหน่ง: ต่อจากบรรทัดที่ 500 หรือก่อนบรรทัด if (input.classList.contains("expandable-input")) {

    JavaScript

            // 🟢 NEW: Premium Number Formatting (เฉพาะคอลัมน์ Premium Index 4)
            if (index === 4) {
                // อนุญาตให้ใช้ keyup เพื่อป้องกันการจัดรูปแบบซ้ำขณะพิมพ์
                input.addEventListener('blur', function() {
                    const cleanValue = this.value.replace(/,/g, '');
                    const num = parseFloat(cleanValue);
                    if (!isNaN(num)) {
                        this.value = num.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
                    } else if (cleanValue.trim() === '') {
                        this.value = '';
                    } else {
                        // หากไม่เป็นตัวเลข อาจจะแจ้งเตือนหรือรีเซ็ต
                        this.value = parseFloat(0).toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
                    }
                });
                
                 // 🟢 NEW: ทำให้เป็น input แบบ text แต่ใช้คุณสมบัติการขยายตัวเหมือน number
                 input.classList.remove('form-control-sm');
                 input.classList.add('form-control');
            }
    /* ==================== EXTRACT DATA (สำหรับ Save) ======================= */
    ...
    // ⭐️ comma ลบตัวคั่นหลักพัน (,) ออกจากค่า Premium ก่อนบันทึก ⭐️
                const cleanPremiumValue = c[4].value.replace(/,/g, '');			
                
                data.push({
                    date: c[0].value, 
                    product: c[1].value, 
                    company: c[2].value,
                    name: c[3].value, 
    	        premium: cleanPremiumValue, // ✅ ใช้ค่าที่สะอาดแล้ว 
    // ...

    ตรงนี้ด้วย

    function createTableRow(d) {
        const tr = document.createElement("tr");
        
        // ข้อมูลเซลล์หลัก 9 ช่อง (รวมวันที่)
        const cellData = [
            { type: 'date', value: d.date, className: 'date-cell-status' }, // คอลัมน์ D/M/Y
            { type: 'text', value: d.product, className: 'expandable-cell' },
            { type: 'text', value: d.company, className: 'expandable-cell' },
            { type: 'text', value: d.name, className: 'expandable-cell' },
    // 🟢 Comma		
    	{ type: 'text', value: parseFloat(d.premium || 0).toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) },
            { type: 'checkbox', value: d.paid === "true" || d.paid === true, ispaid: true }, // คอลัมน์ Paid/Receive
            { type: 'checkbox', value: d.pay === "true" || d.pay === true, isPay: true },   // คอลัมน์ Pay
            { type: 'text', value: d.note, className: 'expandable-cell' },
            { type: 'text', value: d.contact, className: 'expandable-cell' },
        ];


เวอไนน์ไอคอร์ส

ประหยัดเวลากว่า 100 เท่า!






เวอไนน์เว็บไซต์⚡️
สร้างเว็บไซต์ ดูแลเว็บไซต์

Categories


Uncategorized