Of course! Combining everything into a single HTML file is a great way to create a portable, self-contained web application. The CSS will be placed inside a <style> tag in the <head>, and the JavaScript will be placed in a <script> tag at the end of the <body>.
Here is the complete code for the Odoo-like sales and inventory website in one HTML file.
Instructions:
- Copy the entire code block below.
- Paste it into a new text file.
- Save the file with an
.html extension (e.g., inventory.html).
- Open the saved file in your web browser (like Chrome, Firefox, or Edge).
The application will be fully functional, saving all your data in the browser's localStorage, so it will be there the next time you open the file.
The All-in-One inventory.html File
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Odoo-like Sales & Inventory</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<style>
/* --- CSS STYLES --- */
/* Basic Reset & Fonts */
body {
font-family: 'Roboto', sans-serif;
margin: 0;
padding: 0;
background-color: #f0f2f5;
color: #333;
line-height: 1.6;
}
/* Header */
header {
background-color: #007bff; /* A nice blue, like Odoo's branding */
color: white;
padding: 20px;
text-align: center;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
header h1 {
margin: 0;
font-weight: 700;
}
header p {
margin: 5px 0 0;
font-size: 1rem;
opacity: 0.9;
}
/* Main Container */
.container {
max-width: 1200px;
margin: 20px auto;
padding: 20px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
}
/* Tab Navigation */
.nav-tabs {
display: flex;
justify-content: flex-start;
border-bottom: 2px solid #e0e0e0;
margin-bottom: 20px;
gap: 10px;
}
.tab-button {
padding: 12px 25px;
font-size: 1rem;
font-weight: bold;
cursor: pointer;
border: none;
background-color: transparent;
color: #555;
border-bottom: 3px solid transparent;
transition: all 0.3s ease;
}
.tab-button:hover {
background-color: #f7f7f7;
}
.tab-button.active {
color: #007bff;
border-bottom-color: #007bff;
background-color: #f2f8ff;
}
/* Tab Content */
.tab-pane {
display: none;
padding: 20px 0;
}
.tab-pane.active {
display: block;
}
section h2 {
margin-top: 0;
color: #007bff;
border-bottom: 2px solid #eee;
padding-bottom: 10px;
margin-bottom: 20px;
}
/* Form Styles */
.form-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin-bottom: 20px;
background-color: #f9f9f9;
padding: 20px;
border-radius: 8px;
border: 1px solid #e0e0e0;
}
input[type="text"],
input[type="number"],
select {
width: 100%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 6px;
font-size: 1rem;
box-sizing: border-box;
transition: border-color 0.3s;
}
input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
outline: none;
border-color: #007bff;
box-shadow: 0 0 5px rgba(0, 123, 255, 0.2);
}
/* Buttons */
.btn {
padding: 12px 25px;
font-size: 1rem;
font-weight: bold;
cursor: pointer;
border: none;
border-radius: 6px;
color: white;
transition: background-color 0.3s ease, transform 0.1s ease;
width: 100%;
}
.btn-primary { background-color: #007bff; }
.btn-primary:hover { background-color: #0056b3; }
.btn-success { background-color: #28a745; }
.btn-success:hover { background-color: #218838; }
.btn-danger { background-color: #dc3545; }
.btn-danger:hover { background-color: #c82333; }
.btn:active { transform: scale(0.98); }
/* Table Styles */
.table-container { overflow-x: auto; }
table {
width: 100%;
border-collapse: collapse;
margin-top: 15px;
background-color: #fff;
border-radius: 8px;
overflow: hidden; /* To apply border-radius to the table */
}
table th, table td {
padding: 15px;
text-align: left;
border-bottom: 1px solid #ddd;
}
table th {
background-color: #f5f5f5;
font-weight: bold;
color: #555;
text-transform: uppercase;
font-size: 0.9rem;
}
table tr:hover { background-color: #fbfbfb; }
table tbody tr:nth-child(even) { background-color: #fafafa; }
/* Dashboard Cards */
.summary-cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 20px;
margin-top: 20px;
}
.card {
background-color: #fff;
border: 1px solid #e0e0e0;
border-radius: 8px;
padding: 25px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
text-align: center;
}
.card h3 {
margin: 0 0 10px;
font-size: 1.1rem;
color: #666;
}
.card p {
margin: 0;
font-size: 2.2rem;
font-weight: bold;
}
.revenue-card p { color: #007bff; }
.profit-card p { color: #28a745; }
.margin-card p { color: #ffc107; }
.inventory-card p { color: #17a2b8; }
/* Dynamic helper classes for JS */
.text-success { color: #28a745 !important; font-weight: bold; }
.text-danger { color: #dc3545 !important; font-weight: bold; }
.low-stock { color: #ff9800 !important; font-weight: bold; }
</style>
</head>
<body>
<header>
<h1>Odoo-like Sales & Inventory</h1>
<p>Simple Dashboard, Product & Sales Management</p>
</header>
<main class="container">
<div class="nav-tabs">
<button class="tab-button active" data-tab-target="#dashboard-section">Dashboard</button>
<button class="tab-button" data-tab-target="#products-section">Products</button>
<button class="tab-button" data-tab-target="#sales-section">Sales</button>
</div>
<div class="tab-content">
<!-- Dashboard Section -->
<section id="dashboard-section" class="tab-pane active">
<h2>📊 Dashboard Summary</h2>
<div class="summary-cards">
<div class="card revenue-card">
<h3>Total Revenue</h3>
<p>$ <span id="total-revenue-span">0.00</span></p>
</div>
<div class="card profit-card">
<h3>Total Profit</h3>
<p>$ <span id="total-profit-span">0.00</span></p>
</div>
<div class="card margin-card">
<h3>Gross Margin</h3>
<p><span id="gross-margin-span">0.00</span> %</p>
</div>
<div class="card inventory-card">
<h3>Total Stock Value</h3>
<p>$ <span id="total-stock-value-span">0.00</span></p>
</div>
</div>
</section>
<!-- Products Section -->
<section id="products-section" class="tab-pane">
<h2>📦 Product Inventory</h2>
<form id="product-form" class="form-grid">
<input type="text" id="product-name" placeholder="Product Name" required>
<input type="number" id="product-cost" placeholder="Cost Price ($)" step="0.01" min="0" required>
<input type="number" id="product-price" placeholder="Selling Price ($)" step="0.01" min="0" required>
<input type="number" id="product-quantity" placeholder="Initial Quantity" min="0" required>
<button type="submit" class="btn btn-primary">Add Product</button>
</form>
<div class="table-container">
<table id="product-table">
<thead>
<tr>
<th>Name</th>
<th>Cost Price</th>
<th>Selling Price</th>
<th>In Stock</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<!-- Product rows will be inserted here by JavaScript -->
</tbody>
</table>
</div>
</section>
<!-- Sales Section -->
<section id="sales-section" class="tab-pane">
<h2>📈 Record a Sale</h2>
<form id="sale-form" class="form-grid">
<select id="sale-product-select" required>
<option value="" disabled selected>Select a Product</option>
</select>
<input type="number" id="sale-quantity" placeholder="Quantity Sold" min="1" required>
<button type="submit" class="btn btn-success">Record Sale</button>
</form>
<h3>Recent Sales</h3>
<div class="table-container">
<table id="sale-table">
<thead>
<tr>
<th>Product</th>
<th>Qty Sold</th>
<th>Revenue</th>
<th>Profit</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<!-- Sale rows will be inserted here by JavaScript -->
</tbody>
</table>
</div>
</section>
</div>
</main>
<script>
// --- JAVASCRIPT LOGIC ---
document.addEventListener('DOMContentLoaded', () => {
// --- 1. DOM Element References ---
const productForm = document.getElementById('product-form');
const productTableBody = document.querySelector('#product-table tbody');
const saleForm = document.getElementById('sale-form');
const saleProductSelect = document.getElementById('sale-product-select');
const saleTableBody = document.querySelector('#sale-table tbody');
const tabButtons = document.querySelectorAll('.tab-button');
const tabPanes = document.querySelectorAll('.tab-pane');
// Dashboard elements
const totalRevenueSpan = document.getElementById('total-revenue-span');
const totalProfitSpan = document.getElementById('total-profit-span');
const grossMarginSpan = document.getElementById('gross-margin-span');
const totalStockValueSpan = document.getElementById('total-stock-value-span');
// --- 2. Data Storage (using localStorage) ---
let products = JSON.parse(localStorage.getItem('products')) || [];
let sales = JSON.parse(localStorage.getItem('sales')) || [];
const saveData = () => {
localStorage.setItem('products', JSON.stringify(products));
localStorage.setItem('sales', JSON.stringify(sales));
};
// --- 3. UI and Rendering Functions ---
const renderProducts = () => {
productTableBody.innerHTML = '';
let totalStockValue = 0;
products.forEach(product => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${product.name}</td>
<td>$${product.cost.toFixed(2)}</td>
<td>$${product.price.toFixed(2)}</td>
<td class="${product.quantity <= 5 ? 'low-stock' : ''}">${product.quantity}</td>
<td>
<button class="btn btn-danger" onclick="deleteProduct(${product.id})">Delete</button>
</td>
`;
productTableBody.appendChild(row);
totalStockValue += product.quantity * product.cost;
});
totalStockValueSpan.textContent = totalStockValue.toFixed(2);
};
window.deleteProduct = (id) => {
if (sales.some(sale => sale.productId === id)) {
alert('Cannot delete this product as it has associated sales records.');
return;
}
if (confirm('Are you sure you want to delete this product?')) {
products = products.filter(p => p.id !== id);
saveData();
renderAll();
alert('Product deleted successfully!');
}
};
const populateProductSelect = () => {
saleProductSelect.innerHTML = '<option value="" disabled selected>Select a Product</option>';
products.forEach(product => {
if (product.quantity > 0) {
const option = document.createElement('option');
option.value = product.id;
option.textContent = `${product.name} (In Stock: ${product.quantity})`;
saleProductSelect.appendChild(option);
}
});
};
const renderSales = () => {
saleTableBody.innerHTML = '';
// Show most recent sales first
const sortedSales = [...sales].sort((a, b) => new Date(b.date) - new Date(a.date));
sortedSales.forEach(sale => {
const product = products.find(p => p.id === sale.productId);
const productName = product ? product.name : 'Unknown Product';
const revenue = sale.quantity * (product ? product.price : 0);
const costOfGoods = sale.quantity * (product ? product.cost : 0);
const profit = revenue - costOfGoods;
const row = document.createElement('tr');
row.innerHTML = `
<td>${productName}</td>
<td>${sale.quantity}</td>
<td>$${revenue.toFixed(2)}</td>
<td class="${profit >= 0 ? 'text-success' : 'text-danger'}">$${profit.toFixed(2)}</td>
<td>${new Date(sale.date).toLocaleString()}</td>
`;
saleTableBody.appendChild(row);
});
};
const updateDashboard = () => {
let totalRevenue = 0;
let totalCostOfGoods = 0;
sales.forEach(sale => {
const product = products.find(p => p.id === sale.productId);
if (product) {
totalRevenue += sale.quantity * product.price;
totalCostOfGoods += sale.quantity * product.cost;
}
});
const totalProfit = totalRevenue - totalCostOfGoods;
const grossMargin = totalRevenue > 0 ? (totalProfit / totalRevenue) * 100 : 0;
totalRevenueSpan.textContent = totalRevenue.toFixed(2);
totalProfitSpan.textContent = totalProfit.toFixed(2);
grossMarginSpan.textContent = grossMargin.toFixed(2);
};
const setupTabs = () => {
tabButtons.forEach(button => {
button.addEventListener('click', () => {
tabButtons.forEach(btn => btn.classList.remove('active'));
tabPanes.forEach(pane => pane.classList.remove('active'));
const targetTab = document.querySelector(button.dataset.tabTarget);
button.classList.add('active');
targetTab.classList.add('active');
renderAll(); // Re-render data when switching tabs
});
});
};
// --- 4. Event Listeners ---
productForm.addEventListener('submit', (e) => {
e.preventDefault();
const name = document.getElementById('product-name').value;
const cost = parseFloat(document.getElementById('product-cost').value);
const price = parseFloat(document.getElementById('product-price').value);
const quantity = parseInt(document.getElementById('product-quantity').value);
if (price < cost) {
alert('Selling Price cannot be less than Cost Price!');
return;
}
const newProduct = { id: Date.now(), name, cost, price, quantity };
products.push(newProduct);
saveData();
renderAll();
productForm.reset();
alert('Product added successfully!');
});
saleForm.addEventListener('submit', (e) => {
e.preventDefault();
const selectedProductId = parseInt(saleProductSelect.value);
const quantitySold = parseInt(document.getElementById('sale-quantity').value);
const product = products.find(p => p.id === selectedProductId);
if (!product) { alert('Please select a valid product.'); return; }
if (quantitySold <= 0) { alert('Quantity sold must be greater than 0.'); return; }
if (product.quantity < quantitySold) {
alert(`Not enough stock! Only ${product.quantity} units of ${product.name} are available.`);
return;
}
product.quantity -= quantitySold;
const newSale = { id: Date.now(), productId: product.id, quantity: quantitySold, date: new Date().toISOString() };
sales.push(newSale);
saveData();
renderAll();
saleForm.reset();
alert('Sale recorded successfully!');
});
// --- 5. Initial Page Load ---
const renderAll = () => {
renderProducts();
populateProductSelect();
renderSales();
updateDashboard();
}
setupTabs();
renderAll(); // Initial render on page load
});
</script>
</body>
</html>