รายได้ค่ารอบ
+฿0.00
+รวมจากงานที่บันทึก
+From b5b280d6a7a05ff6eab94ef517fb9d8c3a98c524 Mon Sep 17 00:00:00 2001 From: LUKZConnectz <163946633+LUKZConnectz@users.noreply.github.com> Date: Sun, 7 Jun 2026 07:23:55 +0700 Subject: [PATCH] Build rider profit dashboard --- README.md | 22 ++- index.html | 292 +++++++++++++++++++++++++++----- script.js | 484 +++++++++++++++++++++++++++++++++++++++++++++-------- style.css | 319 +++++++++-------------------------- 4 files changed, 760 insertions(+), 357 deletions(-) diff --git a/README.md b/README.md index 42f2503..4582e8d 100644 --- a/README.md +++ b/README.md @@ -1 +1,21 @@ -# pxomdev.github.io \ No newline at end of file +# Rider Profit Dashboard + +เว็บสำหรับไรเดอร์บันทึกค่ารอบ ระยะทาง ค่าน้ำมัน และกำไรสุทธิแบบ responsive ด้วย Tailwind CSS + +## Features + +- บันทึกค่ารอบและระยะทางของแต่ละงาน +- คำนวณลิตรที่ใช้จากอัตราสิ้นเปลืองรถ เช่น 40 กม./ลิตร +- คำนวณค่าน้ำมันและกำไรสุทธิอัตโนมัติ +- สรุปรายวัน รายสัปดาห์ รายเดือน หรือทั้งหมด +- Dark Mode และบันทึกข้อมูลใน localStorage +- ดึงราคาน้ำมันจาก API พร้อม fallback/cache หาก API หรือ CORS ไม่พร้อมใช้งาน +- Export เป็น Excel (`.xls`) และ PDF ผ่านคำสั่งพิมพ์ของเบราว์เซอร์ + +## Run locally + +```bash +python3 -m http.server 4173 +``` + +จากนั้นเปิด `http://127.0.0.1:4173/index.html` diff --git a/index.html b/index.html index 1ebfe64..8571525 100644 --- a/index.html +++ b/index.html @@ -1,44 +1,248 @@ - - -
- - - -
-
- + Grab Rider Fuel & Profit Tracker +
++ จดรายได้แต่ละงาน ใส่กิโลเมตร ระบบจะคำนวณลิตรที่ใช้ ค่าน้ำมัน และสรุปผลรายวัน รายสัปดาห์ รายเดือนให้อัตโนมัติ +
+รายได้ค่ารอบ
+฿0.00
+รวมจากงานที่บันทึก
+ค่าน้ำมันรวม
+฿0.00
+0.00 ลิตร
+กำไรสุทธิ
+฿0.00
+ค่ารอบ - ค่าน้ำมัน
+ระยะทางทั้งหมด
+0.00 กม.
+0 งาน
+กำลังโหลดราคาน้ำมัน...
+ +เลือกช่วงเวลาเพื่อดูรายวัน รายสัปดาห์ หรือรายเดือน
+จำนวนงาน
+0
+ค่ารอบ
+฿0.00
+ค่าน้ำมัน
+฿0.00
+กำไรสุทธิ
+฿0.00
+ข้อมูลเก็บในเครื่องของคุณด้วย localStorage
+| วันที่ | +ค่ารอบ | +กม. | +ลิตร | +ค่าน้ำมัน | +กำไร | +หมายเหตุ | +จัดการ | +
|---|
🛵
+ยังไม่มีรายการงาน
+เพิ่มงานแรกเพื่อเริ่มคำนวณกำไรได้เลย
+${escapeHtml(fuel.name)}
+${decimal(fuel.price)} ฿/L
+แตะเพื่อใช้ราคานี้
+ `; + card.addEventListener("click", () => { + elements.fuelPrice.value = fuel.price; + settings.fuelPrice = Number(fuel.price); + saveSettings(); + updatePreview(); + }); + elements.fuelCards.appendChild(card); + }); + + const updated = new Date().toLocaleString("th-TH", { dateStyle: "medium", timeStyle: "short" }); + elements.fuelStatus.textContent = `อัปเดตล่าสุด ${updated} • แหล่งข้อมูล: ${source}`; +} + +async function fetchFuelPrices() { + elements.fuelStatus.textContent = "กำลังโหลดราคาน้ำมันแบบ Real-time..."; + const cached = readFuelCache(); + + try { + const response = await fetch("https://api.allorigins.win/raw?url=" + encodeURIComponent("https://energy.go.th/index"), { + cache: "no-store", + }); + if (!response.ok) throw new Error("Fuel API unavailable"); + const html = await response.text(); + const fuels = parseFuelPrices(html); + if (fuels.length < 2) throw new Error("Cannot parse fuel prices"); + localStorage.setItem(FUEL_CACHE_KEY, JSON.stringify({ fuels, savedAt: Date.now() })); + renderFuelCards(fuels, "energy.go.th"); + if (!settings.fuelPrice) { + elements.fuelPrice.value = fuels[0].price; + settings.fuelPrice = fuels[0].price; + saveSettings(); + updatePreview(); + } + } catch (error) { + const fuels = cached?.fuels?.length ? cached.fuels : fallbackFuels; + renderFuelCards(fuels, cached ? "cache" : "fallback"); + elements.fuelStatus.textContent += " • ใช้ข้อมูลสำรอง เพราะ API อาจติด CORS หรือไม่พร้อมใช้งาน"; + } +} + +function parseFuelPrices(html) { + const text = html.replace(/<[^>]+>/g, " ").replace(/ /g, " "); + const fuelNames = ["Gasohol 95", "Gasohol 91", "E20", "E85", "Diesel", "Premium Diesel"]; + const fuels = []; + + fuelNames.forEach((name) => { + const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); + const regex = new RegExp(`${escaped}[^0-9]{0,80}(\\d{2,3}\\.\\d{2})`, "i"); + const match = text.match(regex); + if (match) fuels.push({ name, price: Number(match[1]) }); + }); + + return fuels.slice(0, 6); +} + +function readFuelCache() { + try { + return JSON.parse(localStorage.getItem(FUEL_CACHE_KEY)); + } catch { + return null; + } +} + +function escapeHtml(value) { + return String(value).replace(/[&<>'"]/g, (char) => ({ + "&": "&", + "<": "<", + ">": ">", + "'": "'", + '"': """, + }[char])); +} + +function exportExcel() { + const rows = jobs.map((job) => ` +| วันที่ | ค่ารอบ | กม. | กม./ลิตร | บาท/ลิตร | ลิตร | ค่าน้ำมัน | กำไร | หมายเหตุ |
|---|