Spaces:
Running
Running
Update script.js
Browse files
script.js
CHANGED
@@ -5,9 +5,11 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
5 |
const cartTable = document.getElementById('cartTable').getElementsByTagName('tbody')[0];
|
6 |
const totalSoldElement = document.getElementById('totalSold');
|
7 |
const totalRevenueElement = document.getElementById('totalRevenue');
|
|
|
8 |
|
9 |
let totalSold = 0; // Общее количество проданных товаров
|
10 |
let totalRevenue = 0; // Общая выручка
|
|
|
11 |
let cart = []; // Корзина
|
12 |
|
13 |
// Загрузка данных из localStorage при загрузке страницы
|
@@ -95,9 +97,10 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
95 |
|
96 |
// Функция загрузки статистики из localStorage
|
97 |
function loadStats() {
|
98 |
-
const stats = JSON.parse(localStorage.getItem('stats')) || { totalSold: 0, totalRevenue: 0 };
|
99 |
totalSold = stats.totalSold;
|
100 |
totalRevenue = stats.totalRevenue;
|
|
|
101 |
updateStatsDisplay();
|
102 |
}
|
103 |
|
@@ -111,6 +114,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
111 |
function updateStatsDisplay() {
|
112 |
totalSoldElement.textContent = totalSold;
|
113 |
totalRevenueElement.textContent = totalRevenue.toFixed(2);
|
|
|
114 |
}
|
115 |
|
116 |
// Функция обновления отображения корзины
|
@@ -147,6 +151,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
147 |
id: productId,
|
148 |
name: product.name,
|
149 |
salePrice: product.salePrice,
|
|
|
150 |
quantity: quantity
|
151 |
});
|
152 |
}
|
@@ -184,13 +189,14 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
184 |
product.quantity -= cartItem.quantity;
|
185 |
totalSold += cartItem.quantity;
|
186 |
totalRevenue += cartItem.quantity * cartItem.salePrice;
|
|
|
187 |
} else {
|
188 |
alert(`Недостаточно товара "${cartItem.name}" на складе.`);
|
189 |
}
|
190 |
});
|
191 |
|
192 |
localStorage.setItem('products', JSON.stringify(products));
|
193 |
-
localStorage.setItem('stats', JSON.stringify({ totalSold, totalRevenue }));
|
194 |
localStorage.removeItem('cart');
|
195 |
|
196 |
cart = [];
|
|
|
5 |
const cartTable = document.getElementById('cartTable').getElementsByTagName('tbody')[0];
|
6 |
const totalSoldElement = document.getElementById('totalSold');
|
7 |
const totalRevenueElement = document.getElementById('totalRevenue');
|
8 |
+
const totalProfitElement = document.getElementById('totalProfit');
|
9 |
|
10 |
let totalSold = 0; // Общее количество проданных товаров
|
11 |
let totalRevenue = 0; // Общая выручка
|
12 |
+
let totalProfit = 0; // Общая прибыль
|
13 |
let cart = []; // Корзина
|
14 |
|
15 |
// Загрузка данных из localStorage при загрузке страницы
|
|
|
97 |
|
98 |
// Функция загрузки статистики из localStorage
|
99 |
function loadStats() {
|
100 |
+
const stats = JSON.parse(localStorage.getItem('stats')) || { totalSold: 0, totalRevenue: 0, totalProfit: 0 };
|
101 |
totalSold = stats.totalSold;
|
102 |
totalRevenue = stats.totalRevenue;
|
103 |
+
totalProfit = stats.totalProfit;
|
104 |
updateStatsDisplay();
|
105 |
}
|
106 |
|
|
|
114 |
function updateStatsDisplay() {
|
115 |
totalSoldElement.textContent = totalSold;
|
116 |
totalRevenueElement.textContent = totalRevenue.toFixed(2);
|
117 |
+
totalProfitElement.textContent = totalProfit.toFixed(2);
|
118 |
}
|
119 |
|
120 |
// Функция обновления отображения корзины
|
|
|
151 |
id: productId,
|
152 |
name: product.name,
|
153 |
salePrice: product.salePrice,
|
154 |
+
purchasePrice: product.purchasePrice,
|
155 |
quantity: quantity
|
156 |
});
|
157 |
}
|
|
|
189 |
product.quantity -= cartItem.quantity;
|
190 |
totalSold += cartItem.quantity;
|
191 |
totalRevenue += cartItem.quantity * cartItem.salePrice;
|
192 |
+
totalProfit += cartItem.quantity * (cartItem.salePrice - cartItem.purchasePrice);
|
193 |
} else {
|
194 |
alert(`Недостаточно товара "${cartItem.name}" на складе.`);
|
195 |
}
|
196 |
});
|
197 |
|
198 |
localStorage.setItem('products', JSON.stringify(products));
|
199 |
+
localStorage.setItem('stats', JSON.stringify({ totalSold, totalRevenue, totalProfit }));
|
200 |
localStorage.removeItem('cart');
|
201 |
|
202 |
cart = [];
|