kaza namazı hesaplama düzeltildi.
This commit is contained in:
+14
-17
@@ -101,7 +101,6 @@ export function renderDesktop(selectedCity = "Edremit", pb) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Canlı Saat Mantığı (Saniyede Bir Güncellenir)
|
|
||||||
function startClock(container) {
|
function startClock(container) {
|
||||||
const clockEl = container.querySelector("#liveClock");
|
const clockEl = container.querySelector("#liveClock");
|
||||||
if (!clockEl) return;
|
if (!clockEl) return;
|
||||||
@@ -113,13 +112,12 @@ function startClock(container) {
|
|||||||
setInterval(update, 1000);
|
setInterval(update, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PocketBase üzerindeki sabit hedeflere (target_*) göre kaza durumunu okuma
|
|
||||||
async function loadDesktopKazaProgress(container, pb) {
|
async function loadDesktopKazaProgress(container, pb) {
|
||||||
const user = pb.authStore.model;
|
const user = pb.authStore.model;
|
||||||
if (!user) return;
|
if (!user) return;
|
||||||
|
|
||||||
let totalTarget = 0;
|
let initialTotal = 0;
|
||||||
let totalCompleted = 0;
|
let remainingDebtTotal = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const record = await pb
|
const record = await pb
|
||||||
@@ -127,15 +125,15 @@ async function loadDesktopKazaProgress(container, pb) {
|
|||||||
.getFirstListItem(`user = "${user.id}"`);
|
.getFirstListItem(`user = "${user.id}"`);
|
||||||
|
|
||||||
if (record) {
|
if (record) {
|
||||||
totalTarget =
|
initialTotal =
|
||||||
(record.target_fajr || 0) +
|
(record.target_fajr || record.fajr || 0) +
|
||||||
(record.target_dhuhr || 0) +
|
(record.target_dhuhr || record.dhuhr || 0) +
|
||||||
(record.target_asr || 0) +
|
(record.target_asr || record.asr || 0) +
|
||||||
(record.target_maghrib || 0) +
|
(record.target_maghrib || record.maghrib || 0) +
|
||||||
(record.target_isha || 0) +
|
(record.target_isha || record.isha || 0) +
|
||||||
(record.target_vitr || 0);
|
(record.target_vitr || record.vitr || 0);
|
||||||
|
|
||||||
totalCompleted =
|
remainingDebtTotal =
|
||||||
(record.fajr || 0) +
|
(record.fajr || 0) +
|
||||||
(record.dhuhr || 0) +
|
(record.dhuhr || 0) +
|
||||||
(record.asr || 0) +
|
(record.asr || 0) +
|
||||||
@@ -145,10 +143,10 @@ async function loadDesktopKazaProgress(container, pb) {
|
|||||||
}
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
const remaining = Math.max(0, totalTarget - totalCompleted);
|
const completed = Math.max(0, initialTotal - remainingDebtTotal);
|
||||||
const pct =
|
const pct =
|
||||||
totalTarget > 0
|
initialTotal > 0
|
||||||
? Math.min(100, Math.round((totalCompleted / totalTarget) * 100))
|
? Math.min(100, Math.round((completed / initialTotal) * 100))
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
const bar = container.querySelector("#desktopKazaBar");
|
const bar = container.querySelector("#desktopKazaBar");
|
||||||
@@ -157,8 +155,7 @@ async function loadDesktopKazaProgress(container, pb) {
|
|||||||
|
|
||||||
if (bar) bar.style.width = `${pct}%`;
|
if (bar) bar.style.width = `${pct}%`;
|
||||||
if (pctText) pctText.textContent = `%${pct}`;
|
if (pctText) pctText.textContent = `%${pct}`;
|
||||||
if (subText)
|
if (subText) subText.textContent = `${remainingDebtTotal} kalan borç vakti`;
|
||||||
subText.textContent = `${totalCompleted} kılınan / ${remaining} kalan`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadWeather(container, selectedCity) {
|
async function loadWeather(container, selectedCity) {
|
||||||
|
|||||||
+89
-86
@@ -11,7 +11,7 @@ const PRAYERS = [
|
|||||||
|
|
||||||
export function renderKaza(pb) {
|
export function renderKaza(pb) {
|
||||||
const user = pb.authStore.model;
|
const user = pb.authStore.model;
|
||||||
const birthdate = user?.birthdate || user?.birthdate;
|
const birthDate = user?.birthDate || user?.birthdate;
|
||||||
const gender = user?.gender || "male";
|
const gender = user?.gender || "male";
|
||||||
|
|
||||||
const html = `
|
const html = `
|
||||||
@@ -24,20 +24,20 @@ export function renderKaza(pb) {
|
|||||||
<span class="text-3xl">📿</span>
|
<span class="text-3xl">📿</span>
|
||||||
<div>
|
<div>
|
||||||
<h2 class="text-2xl font-bold text-white">Kaza Namazı Sayaç & Takip</h2>
|
<h2 class="text-2xl font-bold text-white">Kaza Namazı Sayaç & Takip</h2>
|
||||||
<p class="text-slate-400 text-xs">Hicri takvime göre kaza borcunuzu hesaplayın ve PocketBase'de takip edin.</p>
|
<p class="text-slate-400 text-xs">Hicri takvime göre kaza borcunuzu PocketBase'e sabitleyin ve kıldıkça düşürün.</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
${
|
${
|
||||||
!birthdate
|
!birthDate
|
||||||
? `
|
? `
|
||||||
<div class="bg-slate-950/50 border border-white/10 p-6 rounded-2xl my-auto text-center max-w-md mx-auto w-full">
|
<div class="bg-slate-950/50 border border-white/10 p-6 rounded-2xl my-auto text-center max-w-md mx-auto w-full">
|
||||||
<h3 class="text-base font-bold text-white mb-2">Doğum Tarihi Gerekli</h3>
|
<h3 class="text-base font-bold text-white mb-2">Doğum Tarihi Gerekli</h3>
|
||||||
<p class="text-xs text-slate-400 mb-6">Kaza namazı borcunuzu Hicri takvime göre hesaplayabilmemiz için doğum tarihini ve saatinizi girin.</p>
|
<p class="text-xs text-slate-400 mb-6">Kaza namazı borcunuzu hesaplayabilmemiz için profil bilgilerinizi girin.</p>
|
||||||
<form id="profileForm" class="space-y-4">
|
<form id="profileForm" class="space-y-4">
|
||||||
<div class="text-left">
|
<div class="text-left">
|
||||||
<label class="block text-xs text-slate-300 mb-1">Doğum Tarihi ve Saati</label>
|
<label class="block text-xs text-slate-300 mb-1">Doğum Tarihi ve Saati</label>
|
||||||
<input type="datetime-local" id="birthdateInput" required class="w-full bg-slate-900 border border-slate-800 rounded-xl px-4 py-2.5 text-white text-sm focus:border-indigo-500 focus:outline-none" />
|
<input type="datetime-local" id="birthDateInput" required class="w-full bg-slate-900 border border-slate-800 rounded-xl px-4 py-2.5 text-white text-sm focus:border-indigo-500 focus:outline-none" />
|
||||||
</div>
|
</div>
|
||||||
<div class="text-left">
|
<div class="text-left">
|
||||||
<label class="block text-xs text-slate-300 mb-1">Cinsiyet</label>
|
<label class="block text-xs text-slate-300 mb-1">Cinsiyet</label>
|
||||||
@@ -57,8 +57,8 @@ export function renderKaza(pb) {
|
|||||||
<div class="bg-slate-950/60 border border-white/10 p-5 rounded-2xl mb-6 mt-2 flex flex-col gap-4">
|
<div class="bg-slate-950/60 border border-white/10 p-5 rounded-2xl mb-6 mt-2 flex flex-col gap-4">
|
||||||
<div class="flex flex-wrap items-center justify-between gap-2 border-b border-white/10 pb-3">
|
<div class="flex flex-wrap items-center justify-between gap-2 border-b border-white/10 pb-3">
|
||||||
<div>
|
<div>
|
||||||
<h3 class="text-xs font-bold text-indigo-300 uppercase tracking-wider">Hicri Kaza Borcu Tanımlama</h3>
|
<h3 class="text-xs font-bold text-indigo-300 uppercase tracking-wider">Kaza Borcu Tanımlama</h3>
|
||||||
<p class="text-[11px] text-slate-400">12 yaş mükellefiyeti ve doğum saatiniz (hilal düzeltmesi) baz alınarak borcunuz sabitlenir.</p>
|
<p class="text-[11px] text-slate-400">Hicri takvime göre kaza borcunuzu hesaplar ve PocketBase'e ilk borç olarak kaydeder.</p>
|
||||||
</div>
|
</div>
|
||||||
<button id="calcAndSaveBtn" class="bg-indigo-600 hover:bg-indigo-500 text-white px-4 py-2 rounded-xl text-xs font-semibold transition-all shadow-md active:scale-95">
|
<button id="calcAndSaveBtn" class="bg-indigo-600 hover:bg-indigo-500 text-white px-4 py-2 rounded-xl text-xs font-semibold transition-all shadow-md active:scale-95">
|
||||||
⚡ Kaza Borçlarını Otomatik Hesapla & PB'ye Kaydet
|
⚡ Kaza Borçlarını Otomatik Hesapla & PB'ye Kaydet
|
||||||
@@ -68,16 +68,16 @@ export function renderKaza(pb) {
|
|||||||
<div>
|
<div>
|
||||||
<div class="flex items-center justify-between mb-2">
|
<div class="flex items-center justify-between mb-2">
|
||||||
<span class="text-xs font-bold text-indigo-300 flex items-center gap-1.5">
|
<span class="text-xs font-bold text-indigo-300 flex items-center gap-1.5">
|
||||||
<span>📊</span> GENEL KAZA BİTİRME ORANI
|
<span>📊</span> KAZA BORCU DURUMU
|
||||||
</span>
|
</span>
|
||||||
<span id="overallPercentage" class="text-sm font-extrabold text-emerald-400">%0</span>
|
<span id="overallPercentage" class="text-sm font-extrabold text-emerald-400">%0 Kılındı</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="w-full h-4 bg-slate-900 rounded-full overflow-hidden border border-white/5 p-0.5">
|
<div class="w-full h-4 bg-slate-900 rounded-full overflow-hidden border border-white/5 p-0.5">
|
||||||
<div id="overallProgressBar" class="h-full bg-linear-to-r from-indigo-500 via-purple-500 to-emerald-400 rounded-full transition-all duration-700 ease-out w-[0%]"></div>
|
<div id="overallProgressBar" class="h-full bg-linear-to-r from-indigo-500 via-purple-500 to-emerald-400 rounded-full transition-all duration-700 ease-out w-[0%]"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-between items-center text-[11px] text-slate-400 mt-2.5">
|
<div class="flex justify-between items-center text-[11px] text-slate-400 mt-2.5">
|
||||||
<span>Kılınan Toplam: <b id="totalCompletedText" class="text-emerald-400">0</b> vakit</span>
|
<span>İlk Toplam Borç: <b id="initialTotalText" class="text-slate-300">0</b> vakit</span>
|
||||||
<span>Kalan Toplam Borç: <b id="totalRemainingText" class="text-amber-400">0</b> vakit</span>
|
<span>Kalan Güncel Borç: <b id="totalRemainingText" class="text-amber-400">0</b> vakit</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -88,8 +88,8 @@ export function renderKaza(pb) {
|
|||||||
(p) => `
|
(p) => `
|
||||||
<div class="bg-slate-950/40 border border-white/10 p-3.5 rounded-2xl text-center relative overflow-hidden group">
|
<div class="bg-slate-950/40 border border-white/10 p-3.5 rounded-2xl text-center relative overflow-hidden group">
|
||||||
<p class="text-[11px] font-bold text-slate-300 mb-1">${p.name}</p>
|
<p class="text-[11px] font-bold text-slate-300 mb-1">${p.name}</p>
|
||||||
<p class="text-xs text-slate-400">Kalan: <span id="remaining-${p.id}" class="font-extrabold text-amber-300">-</span></p>
|
<p class="text-xs text-slate-400">Kalan Borç: <span id="remaining-${p.id}" class="font-extrabold text-amber-300">-</span></p>
|
||||||
<p class="text-[10px] text-slate-500 mt-0.5">Kılınan: <span id="completed-${p.id}" class="text-emerald-400">0</span></p>
|
<p class="text-[10px] text-slate-500 mt-0.5">İlk Borç: <span id="initial-${p.id}" class="text-slate-400">0</span></p>
|
||||||
<div class="w-full bg-slate-800 h-1.5 rounded-full mt-2.5 overflow-hidden">
|
<div class="w-full bg-slate-800 h-1.5 rounded-full mt-2.5 overflow-hidden">
|
||||||
<div id="progress-${p.id}" class="bg-emerald-400 h-full w-[0%] transition-all duration-500"></div>
|
<div id="progress-${p.id}" class="bg-emerald-400 h-full w-[0%] transition-all duration-500"></div>
|
||||||
</div>
|
</div>
|
||||||
@@ -100,18 +100,18 @@ export function renderKaza(pb) {
|
|||||||
|
|
||||||
<!-- HIZLI SAYAÇ GÜNCELLEME ALANI -->
|
<!-- HIZLI SAYAÇ GÜNCELLEME ALANI -->
|
||||||
<div class="bg-slate-950/40 border border-white/10 p-5 rounded-2xl mb-auto">
|
<div class="bg-slate-950/40 border border-white/10 p-5 rounded-2xl mb-auto">
|
||||||
<h3 class="text-xs font-bold text-slate-300 uppercase tracking-wider mb-3">Kaza Kıldım / Düzenle</h3>
|
<h3 class="text-xs font-bold text-slate-300 uppercase tracking-wider mb-3">Kaza Kıldım (Borçtan Düş)</h3>
|
||||||
<form id="addKazaForm" class="flex flex-wrap items-center gap-3">
|
<form id="addKazaForm" class="flex flex-wrap items-center gap-3">
|
||||||
<select id="kazaPrayerType" class="bg-slate-900 border border-slate-800 rounded-xl px-4 py-2.5 text-white text-sm focus:outline-none">
|
<select id="kazaPrayerType" class="bg-slate-900 border border-slate-800 rounded-xl px-4 py-2.5 text-white text-sm focus:outline-none">
|
||||||
${PRAYERS.map((p) => `<option value="${p.id}">${p.name}</option>`).join("")}
|
${PRAYERS.map((p) => `<option value="${p.id}">${p.name}</option>`).join("")}
|
||||||
</select>
|
</select>
|
||||||
<input type="number" id="kazaCount" min="1" value="1" required class="w-24 bg-slate-900 border border-slate-800 rounded-xl px-4 py-2.5 text-white text-sm text-center focus:outline-none font-bold" />
|
<input type="number" id="kazaCount" min="1" value="1" required class="w-24 bg-slate-900 border border-slate-800 rounded-xl px-4 py-2.5 text-white text-sm text-center focus:outline-none font-bold" />
|
||||||
|
|
||||||
<button type="button" id="addKazaBtn" class="bg-emerald-600 hover:bg-emerald-500 text-white px-5 py-2.5 rounded-xl text-sm font-semibold transition-all shadow-lg active:scale-95 flex items-center gap-1.5">
|
<button type="button" id="subtractKazaBtn" class="bg-emerald-600 hover:bg-emerald-500 text-white px-5 py-2.5 rounded-xl text-sm font-semibold transition-all shadow-lg active:scale-95 flex items-center gap-1.5">
|
||||||
<span>✓</span> Kıldım (+1)
|
<span>✓</span> Kıldım (Borçtan Düş -)
|
||||||
</button>
|
</button>
|
||||||
<button type="button" id="removeKazaBtn" class="bg-rose-600/30 hover:bg-rose-600/50 text-rose-300 border border-rose-500/30 px-4 py-2.5 rounded-xl text-sm font-medium transition-all active:scale-95">
|
<button type="button" id="addKazaBtn" class="bg-rose-600/30 hover:bg-rose-600/50 text-rose-300 border border-rose-500/30 px-4 py-2.5 rounded-xl text-sm font-medium transition-all active:scale-95">
|
||||||
Geri Al (-)
|
Borç Ekle (+)
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
<p id="kazaMsg" class="text-xs mt-3 hidden"></p>
|
<p id="kazaMsg" class="text-xs mt-3 hidden"></p>
|
||||||
@@ -130,17 +130,17 @@ export function renderKaza(pb) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!birthdate) {
|
if (!birthDate) {
|
||||||
container
|
container
|
||||||
.querySelector("#profileForm")
|
.querySelector("#profileForm")
|
||||||
?.addEventListener("submit", async (e) => {
|
?.addEventListener("submit", async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const bInput = container.querySelector("#birthdateInput").value;
|
const bInput = container.querySelector("#birthDateInput").value;
|
||||||
const gInput = container.querySelector("#genderInput").value;
|
const gInput = container.querySelector("#genderInput").value;
|
||||||
try {
|
try {
|
||||||
await pb.collection("users").update(pb.authStore.model.id, {
|
await pb.collection("users").update(pb.authStore.model.id, {
|
||||||
birthdate: bInput,
|
birthdate: bInput,
|
||||||
birthdate: bInput,
|
birthDate: bInput,
|
||||||
gender: gInput,
|
gender: gInput,
|
||||||
});
|
});
|
||||||
pb.authStore.model.birthdate = bInput;
|
pb.authStore.model.birthdate = bInput;
|
||||||
@@ -149,28 +149,27 @@ export function renderKaza(pb) {
|
|||||||
new CustomEvent("navigate", { detail: "kaza" }),
|
new CustomEvent("navigate", { detail: "kaza" }),
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert(
|
alert("Profil kaydedilemedi.");
|
||||||
"Profil kaydedilemedi. PocketBase kullanıcı alanlarını kontrol edin.",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
refreshKazaStats(container, pb);
|
refreshKazaStats(container, pb);
|
||||||
|
|
||||||
|
// Hesapla ve PB'ye Ilk Borc Olarak Kaydet
|
||||||
container
|
container
|
||||||
.querySelector("#calcAndSaveBtn")
|
.querySelector("#calcAndSaveBtn")
|
||||||
?.addEventListener("click", async () => {
|
?.addEventListener("click", async () => {
|
||||||
if (
|
if (
|
||||||
confirm(
|
confirm(
|
||||||
"Doğum tarihiniz ve saatiniz Hicri takvime dönüştürülüp 12 yaş borcunuz PocketBase'e kaydedilecek. Onaylıyor musunuz?",
|
"Doğum tarihinize göre kaza borcunuz hesaplanıp PocketBase veritabanına kaydedilecek. Var olan borç verileriniz sıfırlanır. Onaylıyor musunuz?",
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
const res = await initAndSaveInitialKaza(pb, birthdate, gender);
|
const res = await initAndSaveInitialKaza(pb, birthDate, gender);
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
await refreshKazaStats(container, pb);
|
await refreshKazaStats(container, pb);
|
||||||
showKazaMsg(
|
showKazaMsg(
|
||||||
container.querySelector("#kazaMsg"),
|
container.querySelector("#kazaMsg"),
|
||||||
`✓ Hicri borç hesaplandı (${res.days} gün) ve PocketBase'e kaydedildi!`,
|
`✓ Borç hesaplandı (${res.days} gün) ve PocketBase'e başarıyla kaydedildi!`,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@@ -183,31 +182,34 @@ export function renderKaza(pb) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Kildim (Borctan Dus / Eksi Deger)
|
||||||
|
container
|
||||||
|
.querySelector("#subtractKazaBtn")
|
||||||
|
?.addEventListener("click", async () => {
|
||||||
|
await updateKazaDebt(container, pb, -1);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Yanlislikla dusulduyse borca geri ekle (Artir / Artı Deger)
|
||||||
container
|
container
|
||||||
.querySelector("#addKazaBtn")
|
.querySelector("#addKazaBtn")
|
||||||
?.addEventListener("click", async () => {
|
?.addEventListener("click", async () => {
|
||||||
await updateKazaCount(container, pb, 1);
|
await updateKazaDebt(container, pb, 1);
|
||||||
});
|
|
||||||
|
|
||||||
container
|
|
||||||
.querySelector("#removeKazaBtn")
|
|
||||||
?.addEventListener("click", async () => {
|
|
||||||
await updateKazaCount(container, pb, -1);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function initAndSaveInitialKaza(pb, birthdate, gender) {
|
// PB tarafina ilk borclari kaydetme (target_* alanlarina da ilk borcu yedekliyoruz)
|
||||||
|
async function initAndSaveInitialKaza(pb, birthDate, gender) {
|
||||||
try {
|
try {
|
||||||
const calc = calculateMissedPrayers(birthdate, gender, 12);
|
const calc = calculateMissedPrayers(birthDate, gender, 12);
|
||||||
|
|
||||||
if (!calc || calc.days <= 0) {
|
if (!calc || calc.days <= 0) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error:
|
error:
|
||||||
"Doğum tarihiniz henüz mükellefiyet yaşından (12 Hicri yıl) küçük görünüyor.",
|
"Doğum tarihiniz henüz mükellefiyet yaşından (12 Hicri yıl) küçük.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,24 +220,24 @@ async function initAndSaveInitialKaza(pb, birthdate, gender) {
|
|||||||
userRecord = await pb
|
userRecord = await pb
|
||||||
.collection("kaza_logs")
|
.collection("kaza_logs")
|
||||||
.getFirstListItem(`user = "${userId}"`);
|
.getFirstListItem(`user = "${userId}"`);
|
||||||
} catch (e) {
|
} catch (e) {}
|
||||||
// Kayıt yoksa yeni oluşturulacak
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Kaza borclarini sakliyoruz (fajr, dhuhr... doğrudan Kalan Borçtur)
|
||||||
const initialData = {
|
const initialData = {
|
||||||
user: userId,
|
user: userId,
|
||||||
|
fajr: calc.fajr,
|
||||||
|
dhuhr: calc.dhuhr,
|
||||||
|
asr: calc.asr,
|
||||||
|
maghrib: calc.maghrib,
|
||||||
|
isha: calc.isha,
|
||||||
|
vitr: calc.vitr,
|
||||||
|
// Ilk borcu orantı hesabi icin sakliyoruz
|
||||||
target_fajr: calc.fajr,
|
target_fajr: calc.fajr,
|
||||||
target_dhuhr: calc.dhuhr,
|
target_dhuhr: calc.dhuhr,
|
||||||
target_asr: calc.asr,
|
target_asr: calc.asr,
|
||||||
target_maghrib: calc.maghrib,
|
target_maghrib: calc.maghrib,
|
||||||
target_isha: calc.isha,
|
target_isha: calc.isha,
|
||||||
target_vitr: calc.vitr,
|
target_vitr: calc.vitr,
|
||||||
fajr: userRecord?.fajr || 0,
|
|
||||||
dhuhr: userRecord?.dhuhr || 0,
|
|
||||||
asr: userRecord?.asr || 0,
|
|
||||||
maghrib: userRecord?.maghrib || 0,
|
|
||||||
isha: userRecord?.isha || 0,
|
|
||||||
vitr: userRecord?.vitr || 0,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (userRecord) {
|
if (userRecord) {
|
||||||
@@ -251,16 +253,19 @@ async function initAndSaveInitialKaza(pb, birthdate, gender) {
|
|||||||
success: false,
|
success: false,
|
||||||
error:
|
error:
|
||||||
err?.message ||
|
err?.message ||
|
||||||
"PocketBase kayıt yaparken hata oluştu. kaza_logs izinlerini kontrol edin.",
|
"PocketBase'e kaydedilemedi. Collection alan izinlerini kontrol edin.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateKazaCount(container, pb, direction) {
|
// Kildikca Borctan Dusme Fonksiyonu (-1 ile çarparak eksiltir)
|
||||||
|
async function updateKazaDebt(container, pb, direction) {
|
||||||
const prayerId = container.querySelector("#kazaPrayerType").value;
|
const prayerId = container.querySelector("#kazaPrayerType").value;
|
||||||
const countInput = container.querySelector("#kazaCount");
|
const countInput = container.querySelector("#kazaCount");
|
||||||
const amount =
|
const countValue = Math.max(1, parseInt(countInput?.value || "1", 10));
|
||||||
Math.max(1, parseInt(countInput?.value || "1", 10)) * direction;
|
|
||||||
|
// direction -1 ise borctan duser, +1 ise borca ekler
|
||||||
|
const changeAmount = countValue * direction;
|
||||||
const msg = container.querySelector("#kazaMsg");
|
const msg = container.querySelector("#kazaMsg");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -272,24 +277,26 @@ async function updateKazaCount(container, pb, direction) {
|
|||||||
if (!userRecord) {
|
if (!userRecord) {
|
||||||
showKazaMsg(
|
showKazaMsg(
|
||||||
msg,
|
msg,
|
||||||
"Önce yukarıdaki 'Kaza Borçlarını Otomatik Hesapla & PB'ye Kaydet' butonuna tıklamalısınız.",
|
"Önce 'Kaza Borçlarını Otomatik Hesapla & PB'ye Kaydet' butonuna basmalısınız.",
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentCompleted = userRecord[prayerId] || 0;
|
const currentDebt = userRecord[prayerId] || 0;
|
||||||
const newCompleted = Math.max(0, currentCompleted + amount);
|
// Yeni kalan borcu hesapla (0'ın altına düşmesin)
|
||||||
|
const newDebt = Math.max(0, currentDebt + changeAmount);
|
||||||
|
|
||||||
|
// PocketBase'e Guncel Borcu Kaydet (PATCH / UPDATE)
|
||||||
await pb.collection("kaza_logs").update(userRecord.id, {
|
await pb.collection("kaza_logs").update(userRecord.id, {
|
||||||
[prayerId]: newCompleted,
|
[prayerId]: newDebt,
|
||||||
});
|
});
|
||||||
|
|
||||||
showKazaMsg(
|
showKazaMsg(
|
||||||
msg,
|
msg,
|
||||||
amount > 0
|
direction < 0
|
||||||
? `✓ ${amount} vakit kılınanlara eklendi!`
|
? `✓ ${countValue} vakit kılındı, borçtan düşüldü! Kalan: ${newDebt}`
|
||||||
: `${Math.abs(amount)} vakit düşüldü.`,
|
: `${countValue} vakit borca geri eklendi. Güncel: ${newDebt}`,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -297,10 +304,11 @@ async function updateKazaCount(container, pb, direction) {
|
|||||||
await refreshKazaStats(container, pb);
|
await refreshKazaStats(container, pb);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Güncelleme hatası:", err);
|
console.error("Güncelleme hatası:", err);
|
||||||
showKazaMsg(msg, "Güncelleme başarısız.", false);
|
showKazaMsg(msg, "PocketBase güncellenirken hata oluştu.", false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PB Verilerini ekrana yansıtma
|
||||||
async function refreshKazaStats(container, pb) {
|
async function refreshKazaStats(container, pb) {
|
||||||
const userId = pb.authStore.model.id;
|
const userId = pb.authStore.model.id;
|
||||||
let userRecord = null;
|
let userRecord = null;
|
||||||
@@ -314,60 +322,55 @@ async function refreshKazaStats(container, pb) {
|
|||||||
if (!userRecord) {
|
if (!userRecord) {
|
||||||
PRAYERS.forEach((p) => {
|
PRAYERS.forEach((p) => {
|
||||||
const remainEl = container.querySelector(`#remaining-${p.id}`);
|
const remainEl = container.querySelector(`#remaining-${p.id}`);
|
||||||
const completedEl = container.querySelector(`#completed-${p.id}`);
|
const initialEl = container.querySelector(`#initial-${p.id}`);
|
||||||
if (remainEl) remainEl.textContent = "Hesaplanmadı";
|
if (remainEl) remainEl.textContent = "Hesaplanmadı";
|
||||||
if (completedEl) completedEl.textContent = "0";
|
if (initialEl) initialEl.textContent = "0";
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let grandTotalTarget = 0;
|
let grandInitialTotal = 0;
|
||||||
let grandTotalCompleted = 0;
|
let grandCurrentDebtTotal = 0;
|
||||||
|
|
||||||
PRAYERS.forEach((p) => {
|
PRAYERS.forEach((p) => {
|
||||||
const target = userRecord[`target_${p.id}`] || 0;
|
const initialDebt = userRecord[`target_${p.id}`] || userRecord[p.id] || 0;
|
||||||
const completed = userRecord[p.id] || 0;
|
const currentDebt = userRecord[p.id] || 0;
|
||||||
const remaining = Math.max(0, target - completed);
|
|
||||||
|
|
||||||
grandTotalTarget += target;
|
grandInitialTotal += initialDebt;
|
||||||
grandTotalCompleted += completed;
|
grandCurrentDebtTotal += currentDebt;
|
||||||
|
|
||||||
const remainEl = container.querySelector(`#remaining-${p.id}`);
|
const remainEl = container.querySelector(`#remaining-${p.id}`);
|
||||||
const completedEl = container.querySelector(`#completed-${p.id}`);
|
const initialEl = container.querySelector(`#initial-${p.id}`);
|
||||||
const progressEl = container.querySelector(`#progress-${p.id}`);
|
const progressEl = container.querySelector(`#progress-${p.id}`);
|
||||||
|
|
||||||
if (remainEl) remainEl.textContent = remaining;
|
if (remainEl) remainEl.textContent = currentDebt;
|
||||||
if (completedEl) completedEl.textContent = completed;
|
if (initialEl) initialEl.textContent = initialDebt;
|
||||||
|
|
||||||
if (progressEl) {
|
if (progressEl) {
|
||||||
|
const completed = Math.max(0, initialDebt - currentDebt);
|
||||||
const pct =
|
const pct =
|
||||||
target > 0
|
initialDebt > 0
|
||||||
? Math.min(100, Math.round((completed / target) * 100))
|
? Math.min(100, Math.round((completed / initialDebt) * 100))
|
||||||
: 100;
|
: 100;
|
||||||
progressEl.style.width = `${pct}%`;
|
progressEl.style.width = `${pct}%`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const grandTotalRemaining = Math.max(
|
const totalCompleted = Math.max(0, grandInitialTotal - grandCurrentDebtTotal);
|
||||||
0,
|
|
||||||
grandTotalTarget - grandTotalCompleted,
|
|
||||||
);
|
|
||||||
const overallPct =
|
const overallPct =
|
||||||
grandTotalTarget > 0
|
grandInitialTotal > 0
|
||||||
? Math.min(
|
? Math.min(100, Math.round((totalCompleted / grandInitialTotal) * 100))
|
||||||
100,
|
: 0;
|
||||||
Math.round((grandTotalCompleted / grandTotalTarget) * 100),
|
|
||||||
)
|
|
||||||
: 100;
|
|
||||||
|
|
||||||
const bar = container.querySelector("#overallProgressBar");
|
const bar = container.querySelector("#overallProgressBar");
|
||||||
const pctText = container.querySelector("#overallPercentage");
|
const pctText = container.querySelector("#overallPercentage");
|
||||||
const compText = container.querySelector("#totalCompletedText");
|
const initText = container.querySelector("#initialTotalText");
|
||||||
const remText = container.querySelector("#totalRemainingText");
|
const remText = container.querySelector("#totalRemainingText");
|
||||||
|
|
||||||
if (bar) bar.style.width = `${overallPct}%`;
|
if (bar) bar.style.width = `${overallPct}%`;
|
||||||
if (pctText) pctText.textContent = `%${overallPct}`;
|
if (pctText) pctText.textContent = `%${overallPct} Kılındı`;
|
||||||
if (compText) compText.textContent = grandTotalCompleted;
|
if (initText) initText.textContent = grandInitialTotal;
|
||||||
if (remText) remText.textContent = grandTotalRemaining;
|
if (remText) remText.textContent = grandCurrentDebtTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
function showKazaMsg(el, text, success) {
|
function showKazaMsg(el, text, success) {
|
||||||
|
|||||||
Reference in New Issue
Block a user