Spaces:
No application file
No application file
File size: 1,322 Bytes
cf064e5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
window.onload = function () {
const tg = window.Telegram?.WebApp;
if (!tg) {
console.warn('Not in Telegram Web App');
return;
}
// Payment Slip Form
document.getElementById('slip-form').addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(e.target);
const file = formData.get('slip_image');
const reader = new FileReader();
reader.onload = () => {
const base64 = reader.result.split(',')[1];
tg.sendData(JSON.stringify({
type: "payment_slip",
booking_id: formData.get('booking_id'),
reference: formData.get('reference') || "",
file_base64: base64,
file_name: file.name
}));
tg.close();
};
reader.readAsDataURL(file);
});
// Expense Form
document.getElementById('expense-form').addEventListener('submit', (e) => {
e.preventDefault();
const data = new FormData(e.target);
tg.sendData(JSON.stringify({
type: "expense_entry",
amount: data.get('amount'),
category: data.get('category') || "อื่นๆ",
note: data.get('note') || ""
}));
tg.close();
});
};
|