Browse Source

add log system

latapp 10 tháng trước cách đây
mục cha
commit
6bb90b7ec6
3 tập tin đã thay đổi với 17 bổ sung12 xóa
  1. 2 0
      .gitignore
  2. 8 0
      main.py
  3. 7 12
      public/js/app.js

+ 2 - 0
.gitignore

@@ -3,3 +3,5 @@ pedidos_express.zip
 tailwind.config.js
 __pycache__
 .venv
+users.json
+logs.csv

+ 8 - 0
main.py

@@ -1,3 +1,4 @@
+import csv
 import os
 import json
 import secrets
@@ -211,6 +212,13 @@ async def printer_order(order: OrderWeb):
     printer = PrinterUSB(0xfe6,0x811e)
     print_order = Order(order.customerName,[Item(item.name, item.price, item.quantity) for item in items])
     printer.print_order(print_order, table)
+    if not os.path.exists('logs.csv'):
+        with open('logs.csv', 'w', newline='') as f:
+            writer = csv.writer(f)
+            writer.writerow(['userName', 'table', 'orderDate', 'items'])
+    with open('logs.csv', 'a', newline='') as f:
+        writer = csv.writer(f)
+        writer.writerow([order.customerName, order.table, order.orderDate, items])
 
 
 @app.post("/api/chat/completions",

+ 7 - 12
public/js/app.js

@@ -88,22 +88,17 @@ async function processOrder() {
         };
         console.log("Enviando Pedido:", orderData);
         await sendOrder(orderData);
-        if (orderConfirmationModal) orderConfirmationModal.style.display = "flex";
+        alert("Pedido enviado con éxito.");
+        cart = []
+        updateCartDisplay();
     } catch (error) {
         console.error("Error al procesar la orden:", error);
-        if (orderErrorModal) {
-            const errorMessageElement = orderErrorModal.querySelector('p.text-lg');
-            if (errorMessageElement) {
-                errorMessageElement.textContent = `Hubo un problema: ${error.message || "Por favor, inténtalo de nuevo."}`;
-            }
-            orderErrorModal.style.display = "flex";
-        }
+        alert(`Hubo un problema: ${error.message || "Por favor, inténtalo de nuevo."}`);
+        
     } finally {
         hideGlobalLoader();
-        if (checkoutButton) {
-            checkoutButton.disabled = cart.length === 0;
-            checkoutButton.textContent = originalCheckoutButtonText;
-        }
+        checkoutButton.disabled = cart.length === 0;
+
     }
 }