diff --git a/app.py b/app.py index 72b83f5..1637d53 100644 --- a/app.py +++ b/app.py @@ -65,6 +65,13 @@ def init_db(): subtotal REAL, FOREIGN KEY(sale_id) REFERENCES sales(id))''') + conn.execute('''CREATE TABLE IF NOT EXISTS dicom + (id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT UNIQUE, + amount REAL DEFAULT 0, + notes TEXT, + last_updated TEXT DEFAULT CURRENT_TIMESTAMP)''') + # Default user logic remains same... user = conn.execute('SELECT * FROM users WHERE username = ?', ('admin',)).fetchone() if not user: @@ -444,6 +451,57 @@ def reverse_sale(sale_id): except Exception as e: print(f"Reverse Sale Error: {e}") return jsonify({"error": str(e)}), 500 + +@app.route('/dicom') +@login_required +def dicom(): + with sqlite3.connect(DB_FILE) as conn: + debtors = conn.execute('SELECT id, name, amount, notes, datetime(last_updated, "localtime") FROM dicom ORDER BY amount DESC').fetchall() + return render_template('dicom.html', user=current_user, debtors=debtors) + +@app.route('/api/dicom/update', methods=['POST']) +@login_required +def update_dicom(): + data = request.get_json() + name = data.get('name', '').strip() + amount = float(data.get('amount', 0)) + notes = data.get('notes', '') + action = data.get('action') # 'add' or 'pay' + + if not name or amount <= 0: + return jsonify({"error": "Nombre y monto válidos son requeridos"}), 400 + + # If we are giving them credit (Fiar), their balance drops into the negative + if action == 'add': + amount = -amount + + try: + with sqlite3.connect(DB_FILE) as conn: + cur = conn.cursor() + # Upsert logic: if they exist, modify debt. If they don't, create them. + cur.execute('''INSERT INTO dicom (name, amount, notes, last_updated) + VALUES (?, ?, ?, CURRENT_TIMESTAMP) + ON CONFLICT(name) DO UPDATE SET + amount = amount + excluded.amount, + notes = excluded.notes, + last_updated = CURRENT_TIMESTAMP''', (name, amount, notes)) + conn.commit() + return jsonify({"status": "success"}), 200 + except Exception as e: + return jsonify({"error": str(e)}), 500 + +@app.route('/api/dicom/', methods=['DELETE']) +@login_required +def delete_dicom(debtor_id): + try: + with sqlite3.connect(DB_FILE) as conn: + conn.execute('DELETE FROM dicom WHERE id = ?', (debtor_id,)) + conn.commit() + return jsonify({"status": "success"}), 200 + except Exception as e: + return jsonify({"error": str(e)}), 500 + + # @app.route('/process_payment', methods=['POST']) # @login_required # def process_payment(): diff --git a/templates/checkout.html b/templates/checkout.html index e558a36..20c865a 100644 --- a/templates/checkout.html +++ b/templates/checkout.html @@ -461,6 +461,9 @@ Ventas + + Dicom +
diff --git a/templates/dicom.html b/templates/dicom.html new file mode 100644 index 0000000..80a140b --- /dev/null +++ b/templates/dicom.html @@ -0,0 +1,267 @@ + + + + + + SekiPOS - Dicom + + + + + + + + +
+
+ +
+
+
+
Registrar Movimiento
+ +
+
+ + +
+
+ + +
+
+ + +
+ +
+ + +
+
+
+ +
+
+ +
+ + +
+ +
+ + + + + + + + + + + + {% for d in debtors %} + + + + + + + + {% endfor %} + +
NombreDeuda TotalÚltima NotaActualizadoAcciones
{{ d[1] }}{{ d[3] }}{{ d[4] }} + + +
+
+
+
+ +
+
+ + + + + \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 3666331..5dabef3 100644 --- a/templates/index.html +++ b/templates/index.html @@ -285,6 +285,9 @@ Ventas + + Dicom +
diff --git a/templates/sales.html b/templates/sales.html index 40ec2a8..3a6726f 100644 --- a/templates/sales.html +++ b/templates/sales.html @@ -73,6 +73,9 @@