Sales Management
New User Registration
Existing User Login
Update Sales
Retrieve Sales Data
Timestamp | Counter No | Product Name | Price | Commission |
---|
document.getElementById('newUserForm').style.display = 'none';
};
request.onerror = (event) => {
alert('Error registering user: ' + event.target.error.message);
};
}
function loginExistingUser() {
const phoneNumber = document.getElementById('existingPhoneNumber').value;
const secretKey = document.getElementById('existingSecretKey').value.toUpperCase();
const transaction = db.transaction(['users'], 'readonly');
const store = transaction.objectStore('users');
const request = store.get(phoneNumber);
request.onsuccess = (event) => {
const user = event.target.result;
if (user && user.secretKey === secretKey) {
alert('Login successful!');
document.getElementById('salesUpdateContainer').style.display = 'block';
document.getElementById('existingUserForm').style.display = 'none';
} else {
alert('Invalid credentials!');
}
};
request.onerror = () => {
alert('Error retrieving user data.');
};
}
function showSalesForm() {
document.getElementById('salesForm').style.display = 'block';
document.getElementById('retrieveForm').style.display = 'none';
}
function showRetrieveForm() {
document.getElementById('salesForm').style.display = 'none';
document.getElementById('retrieveForm').style.display = 'block';
}
function saveSalesEntry() {
const counterNo = document.getElementById('counterNo').value;
const productName = document.getElementById('productName').value;
const price = parseFloat(document.getElementById('price').value);
const timestamp = new Date().toISOString();
const commission = calculateCommission(price);
const salesEntry = {
timestamp,
counterNo,
productName,
price,
commission,
phoneNumber: document.getElementById('existingPhoneNumber').value || document.getElementById('newPhoneNumber').value
};
const transaction = db.transaction(['sales'], 'readwrite');
const store = transaction.objectStore('sales');
store.add(salesEntry);
transaction.oncomplete = () => {
alert('Sales entry saved successfully!');
document.getElementById('salesForm').reset();
addSalesEntryToTable(salesEntry);
};
}
function calculateCommission(price) {
return price * 0.1; // Example commission calculation (10%)
}
function addSalesEntryToTable(entry) {
const tableBody = document.getElementById('salesTableBody');
const row = tableBody.insertRow();
row.insertCell(0).textContent = entry.timestamp;
row.insertCell(1).textContent = entry.counterNo;
row.insertCell(2).textContent = entry.productName;
row.insertCell(3).textContent = entry.price;
row.insertCell(4).textContent = entry.commission;
}
function retrieveData() {
const fromDate = new Date(document.getElementById('fromDate').value).toISOString();
const toDate = new Date(document.getElementById('toDate').value).toISOString();
const tableBody = document.getElementById('salesTableBody');
tableBody.innerHTML = ''; // Clear previous results
const transaction = db.transaction(['sales'], 'readonly');
const store = transaction.objectStore('sales');
store.openCursor().onsuccess = (event) => {
const cursor = event.target.result;
if (cursor) {
const record = cursor.value;
if (record.timestamp >= fromDate && record.timestamp <= toDate) {
addSalesEntryToTable(record);
}
cursor.continue();
}
};
}
]]>
0 Response to "Sales and Commission Tracker"
Post a Comment