WinTechGuru Token System
| # |
Master ID |
Name |
Mobile |
Plan |
Tokens |
Actions |
`);
printWindow.document.close();
}
function saveAsPDF() {
const printContainer = document.getElementById('printContainer');
if(printContainer.children.length === 0) {
Swal.fire('No Tokens', 'Please load tokens first', 'info');
return;
}
const element = document.createElement('div');
element.innerHTML = `
${printContainer.innerHTML}
`;
const opt = {
margin: 0.5,
filename: `WinTechGuru_Tokens_${Date.now()}.pdf`,
html2canvas: { scale: 2 },
jsPDF: { unit: 'cm', format: 'a4', orientation: 'portrait' }
};
Swal.fire({
title: 'Generating PDF...',
allowOutsideClick: false,
didOpen: () => Swal.showLoading()
});
html2pdf().set(opt).from(element).save().then(() => {
Swal.fire('PDF Saved!', 'Tokens exported as PDF', 'success');
});
}
// ==================== ADMIN FUNCTIONS ====================
function updateStats() {
document.getElementById('totalCustomers').textContent = customers.length;
document.getElementById('totalTokens').textContent = tokens.length;
document.getElementById('availableTokens').textContent = TOTAL_TOKENS - usedTokens;
document.getElementById('currentSlot').textContent = currentSlot;
}
function updateTokenPoolInfo() {
const slotTokens = tokenPool.filter(t => t.slot === currentSlot);
const usedInSlot = slotTokens.filter(t => t.assigned).length;
document.getElementById('tokenPoolInfo').innerHTML = `
Slot ${currentSlot}
Used: ${usedInSlot}/${slotTokens.length} tokens
Next slot starts at: ${(currentSlot * TOKENS_PER_SLOT) + 1}
${usedInSlot}/${slotTokens.length}
`;
}
function upgradePlanModal() {
if(customers.length === 0) {
Swal.fire('No Customers', 'Register customers first', 'info');
return;
}
let options = customers.map(c => `
`).join('');
Swal.fire({
title: 'Upgrade Customer Plan',
html: `
`,
showCancelButton: true,
confirmButtonText: 'Upgrade'
}).then((result) => {
if(result.isConfirmed) {
Swal.fire('Upgraded', 'Plan upgrade completed', 'success');
}
});
}
function reassignTokens() {
Swal.fire({
title: 'Reassign Tokens?',
text: 'This will reset token allocation',
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Yes, reassign'
}).then((result) => {
if(result.isConfirmed) {
// Simple reset - in real system, implement proper reassignment
Swal.fire('Reset', 'Token pool reset to initial state', 'info');
}
});
}
function exportData() {
const data = {
customers: customers,
tokens: tokens,
exportDate: new Date().toISOString()
};
const dataStr = JSON.stringify(data, null, 2);
const dataUri = 'data:application/json;charset=utf-8,'+ encodeURIComponent(dataStr);
const link = document.createElement('a');
link.setAttribute('href', dataUri);
link.setAttribute('download', `WinTechGuru_Data_${Date.now()}.json`);
link.click();
Swal.fire('Exported!', 'Data exported successfully', 'success');
}
function showDisclaimer() {
Swal.fire({
title: 'Terms & Conditions',
html: `
1. Tokens valid only after 20,000+ customers
2. One registration per person
3. Non-transferable
4. Company decision is final
5. No refund policy
`,
width: 600
});
}
// ==================== AUTO LOGIN CHECK ====================
document.addEventListener('DOMContentLoaded', function() {
// Check if user was previously logged in
const loggedIn = localStorage.getItem('wtg_loggedIn');
if(loggedIn === 'true') {
// Auto login
document.getElementById('loginPage').style.display = 'none';
document.getElementById('mainApp').style.display = 'block';
initializeSystem();
}
// Set default values for login
document.getElementById('loginUsername').value = 'admin';
document.getElementById('loginPassword').value = 'admin123';
// Add enter key login
document.getElementById('loginPassword').addEventListener('keypress', function(e) {
if(e.key === 'Enter') {
login();
}
});
});