Spaces:
Running
Running
Update script.js
Browse files
script.js
CHANGED
@@ -159,83 +159,4 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
159 |
localStorage.setItem('cart', JSON.stringify(cart));
|
160 |
updateCartDisplay();
|
161 |
} else {
|
162 |
-
alert('Недостаточно
|
163 |
-
}
|
164 |
-
} else {
|
165 |
-
alert('Пожалуйста, введите корректное количество.');
|
166 |
-
}
|
167 |
-
};
|
168 |
-
|
169 |
-
// Функция удаления товара из корзины
|
170 |
-
window.removeFromCart = function (productId) {
|
171 |
-
cart = cart.filter(item => item.id !== productId);
|
172 |
-
localStorage.setItem('cart', JSON.stringify(cart));
|
173 |
-
updateCartDisplay();
|
174 |
-
};
|
175 |
-
|
176 |
-
// Функция продажи товаров из корзины
|
177 |
-
window.sellCart = function () {
|
178 |
-
if (cart.length === 0) {
|
179 |
-
alert('Корзина пуста.');
|
180 |
-
return;
|
181 |
-
}
|
182 |
-
|
183 |
-
const products = JSON.parse(localStorage.getItem('products')) || [];
|
184 |
-
|
185 |
-
cart.forEach(cartItem => {
|
186 |
-
const product = products.find(p => p.id === cartItem.id);
|
187 |
-
|
188 |
-
if (product && product.quantity >= cartItem.quantity) {
|
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 = [];
|
203 |
-
updateCartDisplay();
|
204 |
-
productTable.innerHTML = '';
|
205 |
-
loadProducts();
|
206 |
-
updateStatsDisplay();
|
207 |
-
};
|
208 |
-
|
209 |
-
// Функция добавления остатков
|
210 |
-
window.addStock = function (productId) {
|
211 |
-
const quantityToAdd = prompt('Введите количество для прихода:');
|
212 |
-
if (quantityToAdd && !isNaN(quantityToAdd) && quantityToAdd > 0) {
|
213 |
-
let products = JSON.parse(localStorage.getItem('products')) || [];
|
214 |
-
const productIndex = products.findIndex(p => p.id === productId);
|
215 |
-
|
216 |
-
if (productIndex !== -1) {
|
217 |
-
products[productIndex].quantity += parseInt(quantityToAdd);
|
218 |
-
localStorage.setItem('products', JSON.stringify(products));
|
219 |
-
|
220 |
-
// Обновляем таблицу
|
221 |
-
productTable.innerHTML = '';
|
222 |
-
loadProducts();
|
223 |
-
}
|
224 |
-
} else {
|
225 |
-
alert('Пожалуйста, введите корректное количество.');
|
226 |
-
}
|
227 |
-
};
|
228 |
-
|
229 |
-
// Функция удаления товара
|
230 |
-
window.deleteProduct = function (productId) {
|
231 |
-
if (confirm('Вы уверены, что хотите удалить этот товар?')) {
|
232 |
-
let products = JSON.parse(localStorage.getItem('products')) || [];
|
233 |
-
products = products.filter(p => p.id !== productId);
|
234 |
-
localStorage.setItem('products', JSON.stringify(products));
|
235 |
-
|
236 |
-
// Обновляем таблицу
|
237 |
-
productTable.innerHTML = '';
|
238 |
-
loadProducts();
|
239 |
-
}
|
240 |
-
};
|
241 |
-
});
|
|
|
159 |
localStorage.setItem('cart', JSON.stringify(cart));
|
160 |
updateCartDisplay();
|
161 |
} else {
|
162 |
+
alert('Недостаточно т
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|