function addPurchase() {
const customerId = document.getElementById('customerId').value.trim();
const customerName = document.getElementById('customerName').value.trim();
const customerPhone = document.getElementById('customerPhone').value.trim();
const purchaseAmount = parseFloat(document.getElementById('purchaseAmount').value);
if (!customerId || !customerName || isNaN(purchaseAmount) || purchaseAmount <= 0) {
showNotification("يرجى ملء جميع الحقول بشكل صحيح", "error");
return;
}
const pointsEarned = Math.floor(purchaseAmount * 0.2);
// --- الجزء الجديد لإرسال الإيميل ---
// الصق الرابط الذي نسخته من Google Apps Script هنا
const SCRIPT_URL = "https://script.google.com/macros/s/AKfycbzoN_52hz9ou91hXid9BAc1iJsS_FFtf0K8BEloYmRMWqDXuUOquRI9QMyGubdJ8ltJCg/exec";
const purchaseData = {
customerId: customerId,
customerName: customerName,
purchaseAmount: purchaseAmount,
pointsEarned: pointsEarned
};
fetch(SCRIPT_URL, {
method: 'POST',
mode: 'no-cors', // مهم جدًا
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(purchaseData)
}).then(response => {
console.log("تم إرسال طلب التقرير بنجاح");
}).catch(error => {
console.error("حدث خطأ أثناء إرسال طلب التقرير:", error);
});
// --- نهاية الجزء الجديد ---
let customer = customers.find(c => c.id === customerId);
if (customer) {
customer.points += pointsEarned;
customer.name = customerName;
customer.phone = customerPhone;
} else {
customers.push({ id: customerId, name: customerName, phone: customerPhone, points: pointsEarned });
}
const now = new Date();
transactions.unshift({
date: now.toLocaleDateString('ar-EG'),
time: now.toLocaleTimeString('ar-EG'),
customerId, customerName, type: 'شراء', value: purchaseAmount, points: pointsEarned
});
updateUI();
saveData();
showNotification(`تم إضافة ${pointsEarned} نقطة للعميل ${customerName}`);
['customerId', 'customerName', 'customerPhone', 'purchaseAmount'].forEach(id => document.getElementById(id).value = '');
}
علوش البازار نقط