Aleksmorshen commited on
Commit
2165ac9
·
verified ·
1 Parent(s): 77b52b6

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +88 -11
script.js CHANGED
@@ -230,19 +230,80 @@ document.addEventListener('DOMContentLoaded', function () {
230
  discount: discount
231
  };
232
 
233
- // Сохраняем чек
234
- saveReceipt(receipt);
 
235
 
236
- // Очищаем корзину и обновляем отображение
237
- cart = [];
238
- updateCartDisplay();
239
- productTable.innerHTML = '';
240
- loadProducts();
241
- updateStatsDisplay();
242
 
243
- // Сбрасываем поле скидки
244
- discountInput.value = '';
245
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
 
247
  // Функция для сохранения чека
248
  function saveReceipt(receipt) {
@@ -298,6 +359,22 @@ document.addEventListener('DOMContentLoaded', function () {
298
  modal.style.display = 'flex';
299
  }
300
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
301
  // Функция добавления остатков
302
  function addStock(productId) {
303
  const quantityToAdd = prompt('Введите количество для прихода:');
 
230
  discount: discount
231
  };
232
 
233
+ // Отображаем чек в модальном окне
234
+ openReceiptForConfirmation(receipt);
235
+ };
236
 
237
+ // Функция для отображения чека в модальном окне для подтверждения
238
+ function openReceiptForConfirmation(receipt) {
239
+ const modal = document.getElementById('receiptModal');
240
+ const receiptTable = document.getElementById('receiptTable').getElementsByTagName('tbody')[0];
 
 
241
 
242
+ // Заполняем дату и время
243
+ document.getElementById('receiptDateTime').textContent = receipt.dateTime;
244
+
245
+ // Заполняем таблицу товаров
246
+ receiptTable.innerHTML = '';
247
+ let totalAmount = 0;
248
+ receipt.items.forEach(item => {
249
+ const row = receiptTable.insertRow();
250
+ row.innerHTML = `
251
+ <td>${item.name}</td>
252
+ <td>${item.quantity}</td>
253
+ <td>${item.itemsPerPack}</td>
254
+ <td>${item.salePrice}</td>
255
+ <td>${item.quantity * item.salePrice}</td>
256
+ `;
257
+ totalAmount += item.quantity * item.salePrice;
258
+ });
259
+
260
+ // Отображаем общую сумму, скидку и итоговую сумму
261
+ document.getElementById('receiptTotal').textContent = totalAmount.toFixed(2);
262
+ document.getElementById('receiptDiscount').textContent = receipt.discount.toFixed(2);
263
+ document.getElementById('receiptFinalTotal').textContent = (totalAmount - receipt.discount).toFixed(2);
264
+
265
+ // Показываем модальное окно
266
+ modal.style.display = 'flex';
267
+
268
+ // Обработка подтверждения продажи
269
+ document.getElementById('confirmSaleBtn').onclick = function () {
270
+ // Сохраняем чек
271
+ saveReceipt(receipt);
272
+
273
+ // Обновляем статистику
274
+ updateStatistics(receipt);
275
+
276
+ // Очищаем корзину и обновляем отображение
277
+ cart = [];
278
+ updateCartDisplay();
279
+ productTable.innerHTML = '';
280
+ loadProducts();
281
+ updateStatsDisplay();
282
+
283
+ // Сбрасываем поле скидки
284
+ document.getElementById('discountInput').value = '';
285
+
286
+ // Закрываем модальное окно
287
+ modal.style.display = 'none';
288
+ };
289
+
290
+ // Обработка отмены продажи
291
+ document.getElementById('cancelSaleBtn').onclick = function () {
292
+ modal.style.display = 'none';
293
+ };
294
+
295
+ // Закрытие модального окна при клике на крестик
296
+ document.querySelector('.modal .close').onclick = function () {
297
+ modal.style.display = 'none';
298
+ };
299
+
300
+ // Закрытие модального окна при клике вне его области
301
+ window.onclick = function (event) {
302
+ if (event.target === modal) {
303
+ modal.style.display = 'none';
304
+ }
305
+ };
306
+ }
307
 
308
  // Функция для сохранения чека
309
  function saveReceipt(receipt) {
 
359
  modal.style.display = 'flex';
360
  }
361
 
362
+ // Функция для обновления статистики
363
+ function updateStatistics(receipt) {
364
+ receipt.items.forEach(item => {
365
+ totalSold += item.quantity;
366
+ totalRevenue += item.quantity * item.salePrice;
367
+ totalProfit += item.quantity * (item.salePrice - item.purchasePrice);
368
+ });
369
+
370
+ // Вычитаем скидку из прибыли
371
+ totalProfit -= receipt.discount;
372
+
373
+ // Сохраняем обновленные данные
374
+ localStorage.setItem('stats', JSON.stringify({ totalSold, totalRevenue, totalProfit }));
375
+ updateStatsDisplay();
376
+ }
377
+
378
  // Функция добавления остатков
379
  function addStock(productId) {
380
  const quantityToAdd = prompt('Введите количество для прихода:');