pervenir boton de volver si se cerro sesion, colores, navbar, calculo tarjeta + mp

This commit is contained in:
2026-03-20 00:21:02 -03:00
parent deb349adcc
commit ac8a5348dd
8 changed files with 153 additions and 59 deletions

View File

@@ -40,8 +40,6 @@ services:
# TODO peppermint:
## formulario
- añadir total ventas (todos los medios de pago)
- total tarjetas + mp
- cantidad de boletas por metodod de pago
- añadir segunda persona a cargo
- verificar que todos los campos esten rellenos

50
app.py
View File

@@ -140,6 +140,13 @@ def admin_required(f):
return f(*args, **kwargs)
return decorated_function
@app.after_request
def add_header(response):
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "0"
return response
# --- Routes ---
@app.route('/', methods=['GET', 'POST'])
@@ -187,7 +194,7 @@ def worker_dashboard():
conn = sqlite3.connect(DB_NAME)
c = conn.cursor()
# 1. Identify the worker and their assigned location
# 1. Identificar al trabajador y su zona asignada
c.execute('''SELECT w.modulo_id, m.name, z.id, z.name
FROM workers w
JOIN modulos m ON w.modulo_id = m.id
@@ -201,35 +208,49 @@ def worker_dashboard():
modulo_id, modulo_name, zona_id, zona_name = worker_info
# 2. Handle form submission
# 2. Manejo del envío del formulario
if request.method == 'POST':
fecha = request.form.get('fecha')
turno = request.form.get('turno')
# Clean the money inputs (strip dots)
def clean_money(val):
return int(val.replace('.', '')) if val else 0
# Función para limpiar puntos y validar presencia de datos
def clean_and_validate(val):
if val is None or val.strip() == "":
return None
try:
return int(val.replace('.', ''))
except ValueError:
return None
tarjeta = clean_money(request.form.get('venta_tarjeta'))
mp = clean_money(request.form.get('venta_mp'))
efectivo = clean_money(request.form.get('venta_efectivo'))
gastos = clean_money(request.form.get('gastos'))
# Captura y validación de campos obligatorios
tarjeta = clean_and_validate(request.form.get('venta_tarjeta'))
mp = clean_and_validate(request.form.get('venta_mp'))
efectivo = clean_and_validate(request.form.get('venta_efectivo'))
gastos = clean_and_validate(request.form.get('gastos')) or 0
obs = request.form.get('observaciones', '').strip()
# Insert Header
# VERIFICACIÓN: Todos los campos de venta deben estar rellenos
if tarjeta is None or mp is None or efectivo is None or not fecha or not turno:
flash("Error: Todos los campos (Fecha, Turno, Tarjeta, MP y Efectivo) son obligatorios. Use 0 si no hubo ventas.", "danger")
return redirect(url_for('worker_dashboard'))
# CÁLCULOS ADICIONALES (Para lógica de negocio o auditoría futura)
total_digital = tarjeta + mp
total_ventas_general = total_digital + efectivo
# Insertar Cabecera de Rendición
c.execute('''INSERT INTO rendiciones
(worker_id, modulo_id, fecha, turno, venta_tarjeta, venta_mp, venta_efectivo, gastos, observaciones)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)''',
(session['user_id'], modulo_id, fecha, turno, tarjeta, mp, efectivo, gastos, obs))
rendicion_id = c.lastrowid
# Insert Products (Only those with a quantity > 0)
# Insertar Productos (Solo aquellos con cantidad > 0)
for key, value in request.form.items():
if key.startswith('qty_') and value and int(value) > 0:
prod_id = int(key.split('_')[1])
cantidad = int(value)
# Fetch current price/commission to snapshot it
c.execute("SELECT price, commission FROM productos WHERE id = ?", (prod_id,))
prod_data = c.fetchone()
@@ -240,15 +261,14 @@ def worker_dashboard():
(rendicion_id, prod_id, cantidad, prod_data[0], prod_data[1]))
conn.commit()
flash("Rendición enviada exitosamente.", "success")
flash(f"Rendición enviada exitosamente. Total General Declarado: ${total_ventas_general:,}".replace(',', '.'), "success")
return redirect(url_for('worker_dashboard'))
# 3. Load Products for the GET request
# 3. Cargar Productos para la solicitud GET
c.execute("SELECT id, name, price, commission FROM productos WHERE zona_id = ? ORDER BY name", (zona_id,))
productos = c.fetchall()
conn.close()
# Determine if this module uses commissions (Peppermint) or not (Candy)
has_commission = any(prod[3] > 0 for prod in productos)
return render_template('worker_dashboard.html',

View File

@@ -63,4 +63,16 @@
padding: 4px 7px;
font-size: 0.75rem;
}
}
}
[data-bs-theme="light"] #theme-icon.bi-moon-stars {
color: #5856d6; /* Un color índigo vibrante para que resalte en el fondo claro */
}
[data-bs-theme="dark"] #theme-icon.bi-sun {
color: #ffc107; /* Amarillo cálido de Bootstrap */
}
#theme-switcher.nav-link {
color: inherit !important;
}

View File

@@ -4,13 +4,9 @@ function applyTheme(t) {
const isDark = (t === 'dark');
const themeIcon = document.getElementById('theme-icon');
const themeLabel = document.getElementById('theme-label');
if (themeIcon) {
themeIcon.className = isDark ? 'bi bi-sun me-2' : 'bi bi-moon-stars me-2';
}
if (themeLabel) {
themeLabel.innerText = isDark ? 'Modo Claro' : 'Modo Oscuro';
themeIcon.className = isDark ? 'bi bi-sun fs-5' : 'bi bi-moon-stars fs-5';
}
}

View File

@@ -106,6 +106,8 @@
</table>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
const editWorkerModal = document.getElementById('editWorkerModal');

10
templates/index.html Normal file
View File

@@ -0,0 +1,10 @@
{% extends "macros/base.html" %}
{% block title %}Dashboad?{% endblock %}
{% block content %}
<h2 class="mb-4">Poner algo aqui?</h2>
{% endblock %}
{% block scripts %}
{% endblock %}

View File

@@ -1,12 +1,14 @@
<nav class="navbar navbar-expand-lg navbar-dark bg-dark shadow-sm border-bottom border-secondary mb-4">
<nav class="navbar navbar-expand-lg bg-body-tertiary shadow-sm border-bottom mb-4">
<div class="container">
<a class="navbar-brand d-flex align-items-center fw-bold text-info" href="{{ url_for('index') }}">
<i class="bi bi-receipt-cutoff me-2 fs-4"></i>
<a class="navbar-brand d-flex align-items-center fw-bold text-primary-emphasis" href="{{ url_for('index') }}">
<i class="bi bi-receipt-cutoff me-2 fs-4 text-info"></i>
<span>SekiPOS</span>
</a>
<button class="navbar-toggler border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
{% if session.get('user_id') %}
<ul class="navbar-nav me-auto">
@@ -41,17 +43,16 @@
</ul>
<div class="d-flex align-items-center gap-3">
<button class="btn btn-link nav-link p-2 border-0" id="themeSwitcher" onclick="toggleTheme()" title="Cambiar tema">
<i id="theme-icon" class="bi bi-sun-fill fs-5 text-warning"></i>
<button class="btn btn-link nav-link p-2 border-0" onclick="toggleTheme()" title="Cambiar tema">
<i id="theme-icon" class="bi bi-sun fs-5"></i>
</button>
<span class="navbar-text text-light d-none d-md-block border-start ps-3 border-secondary">
<i class="bi bi-person-badge me-1 text-info"></i>
<span class="fw-bold">{{ session.get('rut') }}</span>
<span class="navbar-text d-none d-md-block border-start ps-3 border-secondary-subtle">
<i class="bi bi-person-circle me-1 text-info"></i> {{ session.get('rut') }}
</span>
<a href="{{ url_for('logout') }}" class="btn btn-outline-danger btn-sm rounded-pill px-3">
<i class="bi bi-box-arrow-right me-1"></i> Salir
Salir
</a>
</div>
{% endif %}

View File

@@ -1,6 +1,5 @@
{% extends "macros/base.html" %}
{% block title %}Rendición de Caja{% endblock %}
{% block head %}
@@ -90,33 +89,43 @@
<div class="card mb-4 shadow-sm border-info">
<div class="card-header bg-info text-dark">Resumen Financiero</div>
<div class="card-body">
<div class="row g-3">
<div class="col-md-3">
<label class="form-label">Total Tarjetas (Crédito/Débito)</label>
<div class="row g-3 mb-4">
<div class="col-md-4">
<label class="form-label">Venta Tarjeta</label>
<div class="input-group">
<span class="input-group-text">$</span>
<input type="text" class="form-control money-input" name="venta_tarjeta" placeholder="0">
<input type="text" class="form-control money-input sale-input" name="venta_tarjeta" id="venta_tarjeta" required>
</div>
</div>
<div class="col-md-3">
<label class="form-label">Total Mercado Pago</label>
<div class="col-md-4">
<label class="form-label">Venta Mercado Pago</label>
<div class="input-group">
<span class="input-group-text">$</span>
<input type="text" class="form-control money-input" name="venta_mp" placeholder="0">
<input type="text" class="form-control money-input sale-input" name="venta_mp" id="venta_mp" required>
</div>
</div>
<div class="col-md-3">
<label class="form-label">Total Efectivo</label>
<div class="col-md-4">
<label class="form-label">Venta Efectivo</label>
<div class="input-group">
<span class="input-group-text">$</span>
<input type="text" class="form-control money-input" name="venta_efectivo" placeholder="0">
<input type="text" class="form-control money-input sale-input" name="venta_efectivo" id="venta_efectivo" required>
</div>
</div>
<div class="col-md-3">
<label class="form-label">Gastos del Módulo</label>
</div>
<div class="row g-3 mb-4 p-3 bg-body-secondary rounded shadow-sm">
<div class="col-md-6">
<label class="form-label text-info fw-bold">Total Digital (Tarjeta + MP)</label>
<div class="input-group">
<span class="input-group-text text-danger">-$</span>
<input type="text" class="form-control money-input" name="gastos" placeholder="0">
<span class="input-group-text bg-info text-white border-info">$</span>
<input type="text" class="form-control bg-dark-subtle fw-bold" id="total_digital" readonly>
</div>
</div>
<div class="col-md-6">
<label class="form-label text-success fw-bold">Total Ventas (Todos los medios)</label>
<div class="input-group">
<span class="input-group-text bg-success text-white border-success">$</span>
<input type="text" class="form-control bg-dark-subtle fw-bold" id="total_general" readonly>
</div>
</div>
</div>
@@ -129,8 +138,54 @@
<button type="submit" class="btn btn-primary w-100 py-3 mb-5" onclick="return confirm('¿Enviar rendición? Revisa bien las cantidades.');">Enviar Rendición Diaria</button>
</form>
{% endblock %}
{% block scripts %}
<script>
const inputsVenta = document.querySelectorAll('.sale-input');
const displayDigital = document.getElementById('total_digital');
const displayGeneral = document.getElementById('total_general');
function calcularTotales() {
// Limpiamos los puntos para sumar números puros
const getVal = (id) => parseInt(document.getElementById(id).value.replace(/\D/g, '')) || 0;
const tarjeta = getVal('venta_tarjeta');
const mp = getVal('venta_mp');
const efectivo = getVal('venta_efectivo');
const totalDigital = tarjeta + mp;
const totalGeneral = totalDigital + efectivo;
// Formateamos de vuelta a moneda chilena para mostrar
displayDigital.value = totalDigital.toLocaleString('es-CL');
displayGeneral.value = totalGeneral.toLocaleString('es-CL');
}
inputsVenta.forEach(input => {
input.addEventListener('input', calcularTotales);
});
// Validación antes de enviar el formulario
document.querySelector('form').addEventListener('submit', function(e) {
const requiredInputs = this.querySelectorAll('[required]');
let valid = true;
requiredInputs.forEach(input => {
if (!input.value.trim()) {
input.classList.add('is-invalid');
valid = false;
} else {
input.classList.remove('is-invalid');
}
});
if (!valid) {
e.preventDefault();
alert("Por favor, rellena todos los campos obligatorios antes de enviar.");
}
});
// Reuse our formatting script for the summary money inputs
document.querySelectorAll('.money-input').forEach(function(input) {
input.addEventListener('input', function(e) {