File size: 37,242 Bytes
8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 d13f14f 8bde1f0 | 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Excel Stock Manager</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.cell:focus {
outline: 2px solid #3b82f6;
outline-offset: -1px;
z-index: 10;
}
.selected {
background-color: #bfdbfe;
}
.header-cell {
background-color: #f3f4f6;
font-weight: 600;
position: sticky;
top: 0;
z-index: 20;
}
.row-header {
background-color: #f3f4f6;
font-weight: 600;
position: sticky;
left: 0;
z-index: 20;
}
.corner-cell {
background-color: #f3f4f6;
position: sticky;
top: 0;
left: 0;
z-index: 30;
}
.scroll-container {
overflow: auto;
height: calc(100vh - 120px);
}
.formula-bar {
border-bottom: 1px solid #e5e7eb;
}
.tab-active {
border-bottom: 2px solid #3b82f6;
color: #3b82f6;
}
.autocomplete-items {
position: absolute;
border: 1px solid #d1d5db;
border-top: none;
z-index: 99;
top: 100%;
left: 0;
right: 0;
}
.autocomplete-items div {
padding: 8px;
cursor: pointer;
background-color: white;
}
.autocomplete-items div:hover {
background-color: #e5e7eb;
}
</style>
</head>
<body class="bg-gray-50">
<div class="container mx-auto p-4">
<div class="bg-white rounded-lg shadow-lg overflow-hidden">
<!-- Header -->
<div class="bg-blue-600 text-white p-4 flex justify-between items-center">
<div class="flex items-center">
<i class="fas fa-table text-2xl mr-3"></i>
<h1 class="text-xl font-bold">Excel Stock Manager</h1>
</div>
<div class="flex space-x-2">
<button id="save-btn" class="bg-blue-700 hover:bg-blue-800 px-4 py-2 rounded flex items-center">
<i class="fas fa-save mr-2"></i> Save
</button>
<button id="load-btn" class="bg-blue-700 hover:bg-blue-800 px-4 py-2 rounded flex items-center">
<i class="fas fa-folder-open mr-2"></i> Load
</button>
<button id="export-btn" class="bg-blue-700 hover:bg-blue-800 px-4 py-2 rounded flex items-center">
<i class="fas fa-file-export mr-2"></i> Export
</button>
</div>
</div>
<!-- Tabs -->
<div class="flex border-b">
<button class="tab-active px-4 py-2 font-medium">Inventory</button>
<button class="px-4 py-2 font-medium text-gray-500 hover:text-gray-700">Suppliers</button>
<button class="px-4 py-2 font-medium text-gray-500 hover:text-gray-700">Reports</button>
<button class="px-4 py-2 font-medium text-gray-500 hover:text-gray-700">Settings</button>
</div>
<!-- Toolbar -->
<div class="flex items-center p-2 border-b bg-gray-50">
<div class="flex space-x-1 mr-4">
<button class="p-2 hover:bg-gray-200 rounded" title="Cut">
<i class="fas fa-cut"></i>
</button>
<button class="p-2 hover:bg-gray-200 rounded" title="Copy">
<i class="fas fa-copy"></i>
</button>
<button class="p-2 hover:bg-gray-200 rounded" title="Paste">
<i class="fas fa-paste"></i>
</button>
<button class="p-2 hover:bg-gray-200 rounded" title="Format Painter">
<i class="fas fa-paint-brush"></i>
</button>
</div>
<div class="flex space-x-1 mr-4">
<button class="p-2 hover:bg-gray-200 rounded" title="Bold">
<i class="fas fa-bold"></i>
</button>
<button class="p-2 hover:bg-gray-200 rounded" title="Italic">
<i class="fas fa-italic"></i>
</button>
<button class="p-2 hover:bg-gray-200 rounded" title="Underline">
<i class="fas fa-underline"></i>
</button>
</div>
<div class="flex space-x-1">
<button class="p-2 hover:bg-gray-200 rounded" title="Align Left">
<i class="fas fa-align-left"></i>
</button>
<button class="p-2 hover:bg-gray-200 rounded" title="Align Center">
<i class="fas fa-align-center"></i>
</button>
<button class="p-2 hover:bg-gray-200 rounded" title="Align Right">
<i class="fas fa-align-right"></i>
</button>
</div>
<div class="flex space-x-1 ml-auto">
<button id="add-row-btn" class="bg-blue-500 hover:bg-blue-600 text-white px-3 py-1 rounded flex items-center">
<i class="fas fa-plus mr-1"></i> Add Row
</button>
<button id="delete-row-btn" class="bg-red-500 hover:bg-red-600 text-white px-3 py-1 rounded flex items-center">
<i class="fas fa-minus mr-1"></i> Delete Row
</button>
</div>
</div>
<!-- Formula Bar -->
<div class="formula-bar flex items-center p-1">
<div class="w-16 text-center font-mono text-sm text-gray-600" id="active-cell-address">A1</div>
<div class="flex-1 relative">
<input type="text" id="formula-input" class="w-full border border-gray-300 p-1 font-mono text-sm" placeholder="Enter formula or value">
<div id="autocomplete-list" class="autocomplete-items hidden"></div>
</div>
<button id="enter-formula-btn" class="bg-blue-500 text-white px-2 py-1 ml-1 rounded">
<i class="fas fa-check"></i>
</button>
<button id="cancel-formula-btn" class="bg-gray-200 text-gray-700 px-2 py-1 ml-1 rounded">
<i class="fas fa-times"></i>
</button>
</div>
<!-- Spreadsheet -->
<div class="scroll-container">
<table id="spreadsheet" class="border-collapse">
<thead>
<tr>
<th class="corner-cell w-10 h-8 border border-gray-300"></th>
<th class="header-cell w-40 border border-gray-300">Product ID</th>
<th class="header-cell w-60 border border-gray-300">Product Name</th>
<th class="header-cell w-40 border border-gray-300">Category</th>
<th class="header-cell w-40 border border-gray-300">Supplier</th>
<th class="header-cell w-40 border border-gray-300">Unit Price</th>
<th class="header-cell w-40 border border-gray-300">Quantity</th>
<th class="header-cell w-40 border border-gray-300">Total Value</th>
<th class="header-cell w-40 border border-gray-300">Reorder Level</th>
<th class="header-cell w-40 border border-gray-300">Status</th>
</tr>
</thead>
<tbody id="sheet-body">
<!-- Rows will be added dynamically -->
</tbody>
</table>
</div>
<!-- Status Bar -->
<div class="flex items-center justify-between p-2 border-t bg-gray-100 text-sm text-gray-600">
<div class="flex space-x-4">
<span id="selected-range">Ready</span>
<span id="sum-value">Sum: $0.00</span>
<span id="average-value">Avg: $0.00</span>
<span id="count-value">Count: 0</span>
</div>
<div>
<span id="last-saved">Last saved: Never</span>
</div>
</div>
</div>
</div>
<!-- Modals -->
<div id="save-modal" class="fixed inset-0 bg-black bg-opacity-50 hidden flex items-center justify-center z-50">
<div class="bg-white rounded-lg p-6 w-96">
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-bold">Save Inventory</h3>
<button id="close-save-modal" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<div class="mb-4">
<label class="block text-gray-700 mb-2">File Name</label>
<input type="text" id="save-filename" class="w-full border border-gray-300 rounded p-2" placeholder="inventory.json">
</div>
<div class="flex justify-end space-x-2">
<button id="cancel-save" class="px-4 py-2 bg-gray-200 text-gray-700 rounded">Cancel</button>
<button id="confirm-save" class="px-4 py-2 bg-blue-500 text-white rounded">Save</button>
</div>
</div>
</div>
<div id="load-modal" class="fixed inset-0 bg-black bg-opacity-50 hidden flex items-center justify-center z-50">
<div class="bg-white rounded-lg p-6 w-96">
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-bold">Load Inventory</h3>
<button id="close-load-modal" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<div class="mb-4">
<label class="block text-gray-700 mb-2">Select File</label>
<input type="file" id="load-file" class="w-full border border-gray-300 rounded p-2" accept=".json">
</div>
<div class="flex justify-end space-x-2">
<button id="cancel-load" class="px-4 py-2 bg-gray-200 text-gray-700 rounded">Cancel</button>
<button id="confirm-load" class="px-4 py-2 bg-blue-500 text-white rounded">Load</button>
</div>
</div>
</div>
<div id="export-modal" class="fixed inset-0 bg-black bg-opacity-50 hidden flex items-center justify-center z-50">
<div class="bg-white rounded-lg p-6 w-96">
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-bold">Export Data</h3>
<button id="close-export-modal" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<div class="mb-4">
<label class="block text-gray-700 mb-2">Format</label>
<select id="export-format" class="w-full border border-gray-300 rounded p-2">
<option value="csv">CSV (Comma Separated Values)</option>
<option value="json">JSON</option>
<option value="excel">Excel (XLSX)</option>
</select>
</div>
<div class="mb-4">
<label class="block text-gray-700 mb-2">File Name</label>
<input type="text" id="export-filename" class="w-full border border-gray-300 rounded p-2" placeholder="inventory_export">
</div>
<div class="flex justify-end space-x-2">
<button id="cancel-export" class="px-4 py-2 bg-gray-200 text-gray-700 rounded">Cancel</button>
<button id="confirm-export" class="px-4 py-2 bg-blue-500 text-white rounded">Export</button>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Sample data for autocomplete
const categories = ["Electronics", "Clothing", "Food", "Furniture", "Office Supplies"];
const suppliers = ["TechCorp", "Fashion Inc", "Food Distributors", "Home & Office", "Global Suppliers"];
const statuses = ["In Stock", "Low Stock", "Out of Stock", "Discontinued"];
// Initialize spreadsheet with 20 rows
const sheetBody = document.getElementById('sheet-body');
const rowCount = 20;
let activeCell = null;
let selectedRange = { startRow: -1, startCol: -1, endRow: -1, endCol: -1 };
let spreadsheetData = [];
// Create initial data structure
function initializeData() {
for (let i = 0; i < rowCount; i++) {
const rowData = {
id: `P${1000 + i}`,
name: `Product ${i + 1}`,
category: categories[Math.floor(Math.random() * categories.length)],
supplier: suppliers[Math.floor(Math.random() * suppliers.length)],
price: (Math.random() * 100 + 10).toFixed(2),
quantity: Math.floor(Math.random() * 100),
reorder: Math.floor(Math.random() * 20 + 5),
status: statuses[Math.floor(Math.random() * statuses.length)]
};
rowData.total = (rowData.price * rowData.quantity).toFixed(2);
spreadsheetData.push(rowData);
}
}
// Render the spreadsheet
function renderSpreadsheet() {
sheetBody.innerHTML = '';
spreadsheetData.forEach((rowData, rowIndex) => {
const row = document.createElement('tr');
// Row header
const rowHeader = document.createElement('td');
rowHeader.className = 'row-header border border-gray-300 text-center';
rowHeader.textContent = rowIndex + 1;
row.appendChild(rowHeader);
// Product ID
const idCell = createCell(rowData.id, rowIndex, 0);
row.appendChild(idCell);
// Product Name
const nameCell = createCell(rowData.name, rowIndex, 1);
row.appendChild(nameCell);
// Category
const categoryCell = createCell(rowData.category, rowIndex, 2);
row.appendChild(categoryCell);
// Supplier
const supplierCell = createCell(rowData.supplier, rowIndex, 3);
row.appendChild(supplierCell);
// Unit Price
const priceCell = createCell(rowData.price, rowIndex, 4);
priceCell.classList.add('text-right');
row.appendChild(priceCell);
// Quantity
const quantityCell = createCell(rowData.quantity, rowIndex, 5);
quantityCell.classList.add('text-right');
row.appendChild(quantityCell);
// Total Value
const totalCell = createCell(rowData.total, rowIndex, 6);
totalCell.classList.add('text-right', 'font-medium');
row.appendChild(totalCell);
// Reorder Level
const reorderCell = createCell(rowData.reorder, rowIndex, 7);
reorderCell.classList.add('text-right');
row.appendChild(reorderCell);
// Status
const statusCell = createCell(rowData.status, rowIndex, 8);
if (rowData.status === "Low Stock") {
statusCell.classList.add('text-yellow-600');
} else if (rowData.status === "Out of Stock") {
statusCell.classList.add('text-red-600');
}
row.appendChild(statusCell);
sheetBody.appendChild(row);
});
}
function createCell(value, rowIndex, colIndex) {
const cell = document.createElement('td');
cell.className = 'cell border border-gray-300 p-1';
cell.textContent = value;
cell.dataset.row = rowIndex;
cell.dataset.col = colIndex;
cell.addEventListener('click', function() {
handleCellClick(this, rowIndex, colIndex);
});
cell.addEventListener('dblclick', function() {
handleCellDoubleClick(this, rowIndex, colIndex);
});
return cell;
}
function handleCellClick(cell, rowIndex, colIndex) {
// Clear previous selection
document.querySelectorAll('.selected').forEach(el => el.classList.remove('selected'));
// Select the clicked cell
cell.classList.add('selected');
activeCell = cell;
// Update active cell address
const colLetter = String.fromCharCode(65 + colIndex);
document.getElementById('active-cell-address').textContent = `${colLetter}${rowIndex + 1}`;
// Update formula bar with cell content
document.getElementById('formula-input').value = spreadsheetData[rowIndex][getPropertyName(colIndex)] || '';
// Update selected range
selectedRange = {
startRow: rowIndex,
startCol: colIndex,
endRow: rowIndex,
endCol: colIndex
};
updateStatusBar();
}
function handleCellDoubleClick(cell, rowIndex, colIndex) {
const input = document.createElement('input');
input.type = 'text';
input.value = cell.textContent;
input.className = 'w-full h-full p-1 border-0 focus:outline-none';
cell.innerHTML = '';
cell.appendChild(input);
input.focus();
input.addEventListener('blur', function() {
const newValue = input.value;
cell.textContent = newValue;
updateCellData(rowIndex, colIndex, newValue);
});
input.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
const newValue = input.value;
cell.textContent = newValue;
updateCellData(rowIndex, colIndex, newValue);
input.blur();
}
});
}
function getPropertyName(colIndex) {
const properties = ['id', 'name', 'category', 'supplier', 'price', 'quantity', 'total', 'reorder', 'status'];
return properties[colIndex];
}
function updateCellData(rowIndex, colIndex, value) {
const property = getPropertyName(colIndex);
spreadsheetData[rowIndex][property] = value;
// If quantity or price changes, update total
if (property === 'quantity' || property === 'price') {
const price = parseFloat(spreadsheetData[rowIndex].price) || 0;
const quantity = parseFloat(spreadsheetData[rowIndex].quantity) || 0;
spreadsheetData[rowIndex].total = (price * quantity).toFixed(2);
// Update status based on quantity and reorder level
const reorder = parseFloat(spreadsheetData[rowIndex].reorder) || 0;
if (quantity === 0) {
spreadsheetData[rowIndex].status = "Out of Stock";
} else if (quantity <= reorder) {
spreadsheetData[rowIndex].status = "Low Stock";
} else {
spreadsheetData[rowIndex].status = "In Stock";
}
// Re-render the row to update all cells
renderSpreadsheet();
}
updateStatusBar();
}
function updateStatusBar() {
// Calculate sum, average, count for selected numeric cells
let sum = 0;
let count = 0;
if (selectedRange.startRow === selectedRange.endRow &&
selectedRange.startCol === selectedRange.endCol) {
// Single cell selected
const cellValue = parseFloat(spreadsheetData[selectedRange.startRow][getPropertyName(selectedRange.startCol)]);
if (!isNaN(cellValue)) {
sum = cellValue;
count = 1;
}
} else {
// Range selected (not implemented in this simplified version)
}
document.getElementById('sum-value').textContent = `Sum: $${sum.toFixed(2)}`;
document.getElementById('average-value').textContent = `Avg: $${(count > 0 ? sum / count : 0).toFixed(2)}`;
document.getElementById('count-value').textContent = `Count: ${count}`;
}
// Formula bar autocomplete
const formulaInput = document.getElementById('formula-input');
formulaInput.addEventListener('input', function() {
const input = this.value.toLowerCase();
const autocompleteList = document.getElementById('autocomplete-list');
if (input.length === 0) {
autocompleteList.classList.add('hidden');
return;
}
// Filter functions
const functions = ['SUM', 'AVERAGE', 'COUNT', 'MAX', 'MIN', 'IF'];
const filteredFunctions = functions.filter(fn => fn.toLowerCase().startsWith(input));
// Filter categories and suppliers if typing in category or supplier columns
let filteredCategories = [];
let filteredSuppliers = [];
if (activeCell && (activeCell.dataset.col == 2 || input.startsWith('='))) {
filteredCategories = categories.filter(cat => cat.toLowerCase().includes(input));
}
if (activeCell && (activeCell.dataset.col == 3 || input.startsWith('='))) {
filteredSuppliers = suppliers.filter(sup => sup.toLowerCase().includes(input));
}
if (filteredFunctions.length === 0 && filteredCategories.length === 0 && filteredSuppliers.length === 0) {
autocompleteList.classList.add('hidden');
return;
}
autocompleteList.innerHTML = '';
if (filteredFunctions.length > 0) {
const funcGroup = document.createElement('div');
funcGroup.className = 'font-bold text-gray-500 px-2 py-1';
funcGroup.textContent = 'Functions';
autocompleteList.appendChild(funcGroup);
filteredFunctions.forEach(func => {
const item = document.createElement('div');
item.textContent = func;
item.addEventListener('click', function() {
formulaInput.value = `=${func}(`;
formulaInput.focus();
autocompleteList.classList.add('hidden');
});
autocompleteList.appendChild(item);
});
}
if (filteredCategories.length > 0) {
const catGroup = document.createElement('div');
catGroup.className = 'font-bold text-gray-500 px-2 py-1 mt-2';
catGroup.textContent = 'Categories';
autocompleteList.appendChild(catGroup);
filteredCategories.forEach(cat => {
const item = document.createElement('div');
item.textContent = cat;
item.addEventListener('click', function() {
formulaInput.value = cat;
formulaInput.focus();
autocompleteList.classList.add('hidden');
});
autocompleteList.appendChild(item);
});
}
if (filteredSuppliers.length > 0) {
const supGroup = document.createElement('div');
supGroup.className = 'font-bold text-gray-500 px-2 py-1 mt-2';
supGroup.textContent = 'Suppliers';
autocompleteList.appendChild(supGroup);
filteredSuppliers.forEach(sup => {
const item = document.createElement('div');
item.textContent = sup;
item.addEventListener('click', function() {
formulaInput.value = sup;
formulaInput.focus();
autocompleteList.classList.add('hidden');
});
autocompleteList.appendChild(item);
});
}
autocompleteList.classList.remove('hidden');
});
// Hide autocomplete when clicking outside
document.addEventListener('click', function(e) {
if (e.target !== formulaInput) {
document.getElementById('autocomplete-list').classList.add('hidden');
}
});
// Formula bar buttons
document.getElementById('enter-formula-btn').addEventListener('click', function() {
if (activeCell) {
const rowIndex = parseInt(activeCell.dataset.row);
const colIndex = parseInt(activeCell.dataset.col);
const newValue = formulaInput.value;
activeCell.textContent = newValue;
updateCellData(rowIndex, colIndex, newValue);
}
});
document.getElementById('cancel-formula-btn').addEventListener('click', function() {
formulaInput.value = '';
if (activeCell) {
const rowIndex = parseInt(activeCell.dataset.row);
const colIndex = parseInt(activeCell.dataset.col);
formulaInput.value = spreadsheetData[rowIndex][getPropertyName(colIndex)] || '';
}
});
// Add row button
document.getElementById('add-row-btn').addEventListener('click', function() {
const newRow = {
id: `P${1000 + spreadsheetData.length}`,
name: `New Product`,
category: categories[0],
supplier: suppliers[0],
price: "0.00",
quantity: "0",
reorder: "10",
status: "In Stock",
total: "0.00"
};
spreadsheetData.push(newRow);
renderSpreadsheet();
});
// Delete row button
document.getElementById('delete-row-btn').addEventListener('click', function() {
if (activeCell && spreadsheetData.length > 1) {
const rowIndex = parseInt(activeCell.dataset.row);
spreadsheetData.splice(rowIndex, 1);
renderSpreadsheet();
// Select the first cell of the same row if it exists, or the previous row
const newRowIndex = Math.min(rowIndex, spreadsheetData.length - 1);
const newCell = document.querySelector(`td[data-row="${newRowIndex}"][data-col="0"]`);
if (newCell) {
handleCellClick(newCell, newRowIndex, 0);
}
}
});
// Save modal
document.getElementById('save-btn').addEventListener('click', function() {
document.getElementById('save-modal').classList.remove('hidden');
});
document.getElementById('close-save-modal').addEventListener('click', function() {
document.getElementById('save-modal').classList.add('hidden');
});
document.getElementById('cancel-save').addEventListener('click', function() {
document.getElementById('save-modal').classList.add('hidden');
});
document.getElementById('confirm-save').addEventListener('click', function() {
const filename = document.getElementById('save-filename').value || 'inventory.json';
const dataStr = JSON.stringify(spreadsheetData, null, 2);
const dataUri = 'data:application/json;charset=utf-8,'+ encodeURIComponent(dataStr);
const link = document.createElement('a');
link.setAttribute('href', dataUri);
link.setAttribute('download', filename);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
document.getElementById('save-modal').classList.add('hidden');
document.getElementById('last-saved').textContent = `Last saved: ${new Date().toLocaleString()}`;
});
// Load modal
document.getElementById('load-btn').addEventListener('click', function() {
document.getElementById('load-modal').classList.remove('hidden');
});
document.getElementById('close-load-modal').addEventListener('click', function() {
document.getElementById('load-modal').classList.add('hidden');
});
document.getElementById('cancel-load').addEventListener('click', function() {
document.getElementById('load-modal').classList.add('hidden');
});
document.getElementById('confirm-load').addEventListener('click', function() {
const fileInput = document.getElementById('load-file');
if (fileInput.files.length > 0) {
const file = fileInput.files[0];
const reader = new FileReader();
reader.onload = function(e) {
try {
const data = JSON.parse(e.target.result);
if (Array.isArray(data)) {
spreadsheetData = data;
renderSpreadsheet();
document.getElementById('load-modal').classList.add('hidden');
document.getElementById('last-saved').textContent = `Last saved: ${new Date().toLocaleString()}`;
} else {
alert('Invalid file format. Expected an array of inventory items.');
}
} catch (error) {
alert('Error parsing JSON file: ' + error.message);
}
};
reader.readAsText(file);
}
});
// Export modal
document.getElementById('export-btn').addEventListener('click', function() {
document.getElementById('export-modal').classList.remove('hidden');
});
document.getElementById('close-export-modal').addEventListener('click', function() {
document.getElementById('export-modal').classList.add('hidden');
});
document.getElementById('cancel-export').addEventListener('click', function() {
document.getElementById('export-modal').classList.add('hidden');
});
document.getElementById('confirm-export').addEventListener('click', function() {
const format = document.getElementById('export-format').value;
const filename = document.getElementById('export-filename').value || 'inventory_export';
if (format === 'csv') {
exportToCSV(filename);
} else if (format === 'json') {
exportToJSON(filename);
} else {
alert('Excel export would require a library like SheetJS. This is a simplified demo.');
}
document.getElementById('export-modal').classList.add('hidden');
});
function exportToCSV(filename) {
let csv = 'Product ID,Product Name,Category,Supplier,Unit Price,Quantity,Total Value,Reorder Level,Status\n';
spreadsheetData.forEach(row => {
csv += `"${row.id}","${row.name}","${row.category}","${row.supplier}",${row.price},${row.quantity},${row.total},${row.reorder},"${row.status}"\n`;
});
const dataUri = 'data:text/csv;charset=utf-8,' + encodeURIComponent(csv);
const link = document.createElement('a');
link.setAttribute('href', dataUri);
link.setAttribute('download', filename + '.csv');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
function exportToJSON(filename) {
const dataStr = JSON.stringify(spreadsheetData, null, 2);
const dataUri = 'data:application/json;charset=utf-8,' + encodeURIComponent(dataStr);
const link = document.createElement('a');
link.setAttribute('href', dataUri);
link.setAttribute('download', filename + '.json');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
// Initialize the application
initializeData();
renderSpreadsheet();
// Select the first cell by default
const firstCell = document.querySelector('td[data-row="0"][data-col="0"]');
if (firstCell) {
handleCellClick(firstCell, 0, 0);
}
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=ltaimo/projects" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |