pervenir boton de volver si se cerro sesion, colores, navbar, calculo tarjeta + mp
This commit is contained in:
@@ -40,8 +40,6 @@ services:
|
|||||||
|
|
||||||
# TODO peppermint:
|
# TODO peppermint:
|
||||||
## formulario
|
## formulario
|
||||||
- añadir total ventas (todos los medios de pago)
|
|
||||||
- total tarjetas + mp
|
|
||||||
- cantidad de boletas por metodod de pago
|
- cantidad de boletas por metodod de pago
|
||||||
- añadir segunda persona a cargo
|
- añadir segunda persona a cargo
|
||||||
- verificar que todos los campos esten rellenos
|
- verificar que todos los campos esten rellenos
|
||||||
|
|||||||
54
app.py
54
app.py
@@ -140,6 +140,13 @@ def admin_required(f):
|
|||||||
return f(*args, **kwargs)
|
return f(*args, **kwargs)
|
||||||
return decorated_function
|
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 ---
|
# --- Routes ---
|
||||||
|
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
@@ -187,7 +194,7 @@ def worker_dashboard():
|
|||||||
conn = sqlite3.connect(DB_NAME)
|
conn = sqlite3.connect(DB_NAME)
|
||||||
c = conn.cursor()
|
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
|
c.execute('''SELECT w.modulo_id, m.name, z.id, z.name
|
||||||
FROM workers w
|
FROM workers w
|
||||||
JOIN modulos m ON w.modulo_id = m.id
|
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
|
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':
|
if request.method == 'POST':
|
||||||
fecha = request.form.get('fecha')
|
fecha = request.form.get('fecha')
|
||||||
turno = request.form.get('turno')
|
turno = request.form.get('turno')
|
||||||
|
|
||||||
# Clean the money inputs (strip dots)
|
# Función para limpiar puntos y validar presencia de datos
|
||||||
def clean_money(val):
|
def clean_and_validate(val):
|
||||||
return int(val.replace('.', '')) if val else 0
|
if val is None or val.strip() == "":
|
||||||
|
return None
|
||||||
tarjeta = clean_money(request.form.get('venta_tarjeta'))
|
try:
|
||||||
mp = clean_money(request.form.get('venta_mp'))
|
return int(val.replace('.', ''))
|
||||||
efectivo = clean_money(request.form.get('venta_efectivo'))
|
except ValueError:
|
||||||
gastos = clean_money(request.form.get('gastos'))
|
return None
|
||||||
|
|
||||||
|
# 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()
|
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
|
c.execute('''INSERT INTO rendiciones
|
||||||
(worker_id, modulo_id, fecha, turno, venta_tarjeta, venta_mp, venta_efectivo, gastos, observaciones)
|
(worker_id, modulo_id, fecha, turno, venta_tarjeta, venta_mp, venta_efectivo, gastos, observaciones)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)''',
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)''',
|
||||||
(session['user_id'], modulo_id, fecha, turno, tarjeta, mp, efectivo, gastos, obs))
|
(session['user_id'], modulo_id, fecha, turno, tarjeta, mp, efectivo, gastos, obs))
|
||||||
rendicion_id = c.lastrowid
|
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():
|
for key, value in request.form.items():
|
||||||
if key.startswith('qty_') and value and int(value) > 0:
|
if key.startswith('qty_') and value and int(value) > 0:
|
||||||
prod_id = int(key.split('_')[1])
|
prod_id = int(key.split('_')[1])
|
||||||
cantidad = int(value)
|
cantidad = int(value)
|
||||||
|
|
||||||
# Fetch current price/commission to snapshot it
|
|
||||||
c.execute("SELECT price, commission FROM productos WHERE id = ?", (prod_id,))
|
c.execute("SELECT price, commission FROM productos WHERE id = ?", (prod_id,))
|
||||||
prod_data = c.fetchone()
|
prod_data = c.fetchone()
|
||||||
|
|
||||||
@@ -240,15 +261,14 @@ def worker_dashboard():
|
|||||||
(rendicion_id, prod_id, cantidad, prod_data[0], prod_data[1]))
|
(rendicion_id, prod_id, cantidad, prod_data[0], prod_data[1]))
|
||||||
|
|
||||||
conn.commit()
|
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'))
|
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,))
|
c.execute("SELECT id, name, price, commission FROM productos WHERE zona_id = ? ORDER BY name", (zona_id,))
|
||||||
productos = c.fetchall()
|
productos = c.fetchall()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
# Determine if this module uses commissions (Peppermint) or not (Candy)
|
|
||||||
has_commission = any(prod[3] > 0 for prod in productos)
|
has_commission = any(prod[3] > 0 for prod in productos)
|
||||||
|
|
||||||
return render_template('worker_dashboard.html',
|
return render_template('worker_dashboard.html',
|
||||||
@@ -257,7 +277,7 @@ def worker_dashboard():
|
|||||||
productos=productos,
|
productos=productos,
|
||||||
has_commission=has_commission,
|
has_commission=has_commission,
|
||||||
today=date.today().strftime('%Y-%m-%d'))
|
today=date.today().strftime('%Y-%m-%d'))
|
||||||
|
|
||||||
@app.route('/admin/workers', methods=['GET', 'POST'])
|
@app.route('/admin/workers', methods=['GET', 'POST'])
|
||||||
@admin_required
|
@admin_required
|
||||||
def manage_workers():
|
def manage_workers():
|
||||||
|
|||||||
@@ -54,13 +54,25 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 576px) {
|
@media (max-width: 576px) {
|
||||||
.col-barcode {
|
.col-barcode {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
|
||||||
|
|
||||||
.btn-edit-sm,
|
|
||||||
.btn-del-sm {
|
|
||||||
padding: 4px 7px;
|
|
||||||
font-size: 0.75rem;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.btn-edit-sm,
|
||||||
|
.btn-del-sm {
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -4,13 +4,9 @@ function applyTheme(t) {
|
|||||||
|
|
||||||
const isDark = (t === 'dark');
|
const isDark = (t === 'dark');
|
||||||
const themeIcon = document.getElementById('theme-icon');
|
const themeIcon = document.getElementById('theme-icon');
|
||||||
const themeLabel = document.getElementById('theme-label');
|
|
||||||
|
|
||||||
if (themeIcon) {
|
if (themeIcon) {
|
||||||
themeIcon.className = isDark ? 'bi bi-sun me-2' : 'bi bi-moon-stars me-2';
|
themeIcon.className = isDark ? 'bi bi-sun fs-5' : 'bi bi-moon-stars fs-5';
|
||||||
}
|
|
||||||
if (themeLabel) {
|
|
||||||
themeLabel.innerText = isDark ? 'Modo Claro' : 'Modo Oscuro';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,8 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
{% block scripts %}
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const editWorkerModal = document.getElementById('editWorkerModal');
|
const editWorkerModal = document.getElementById('editWorkerModal');
|
||||||
@@ -154,4 +156,4 @@
|
|||||||
inp.addEventListener('input', () => formatPhone(inp));
|
inp.addEventListener('input', () => formatPhone(inp));
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
10
templates/index.html
Normal file
10
templates/index.html
Normal 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 %}
|
||||||
@@ -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">
|
<div class="container">
|
||||||
<a class="navbar-brand d-flex align-items-center fw-bold text-info" href="{{ url_for('index') }}">
|
<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"></i>
|
<i class="bi bi-receipt-cutoff me-2 fs-4 text-info"></i>
|
||||||
<span>SekiPOS</span>
|
<span>SekiPOS</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<button class="navbar-toggler border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
<button class="navbar-toggler border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
||||||
<span class="navbar-toggler-icon"></span>
|
<span class="navbar-toggler-icon"></span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div class="collapse navbar-collapse" id="navbarNav">
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
{% if session.get('user_id') %}
|
{% if session.get('user_id') %}
|
||||||
<ul class="navbar-nav me-auto">
|
<ul class="navbar-nav me-auto">
|
||||||
@@ -41,17 +43,16 @@
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div class="d-flex align-items-center gap-3">
|
<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">
|
<button class="btn btn-link nav-link p-2 border-0" onclick="toggleTheme()" title="Cambiar tema">
|
||||||
<i id="theme-icon" class="bi bi-sun-fill fs-5 text-warning"></i>
|
<i id="theme-icon" class="bi bi-sun fs-5"></i>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<span class="navbar-text text-light d-none d-md-block border-start ps-3 border-secondary">
|
<span class="navbar-text d-none d-md-block border-start ps-3 border-secondary-subtle">
|
||||||
<i class="bi bi-person-badge me-1 text-info"></i>
|
<i class="bi bi-person-circle me-1 text-info"></i> {{ session.get('rut') }}
|
||||||
<span class="fw-bold">{{ session.get('rut') }}</span>
|
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<a href="{{ url_for('logout') }}" class="btn btn-outline-danger btn-sm rounded-pill px-3">
|
<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>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
{% extends "macros/base.html" %}
|
{% extends "macros/base.html" %}
|
||||||
|
|
||||||
|
|
||||||
{% block title %}Rendición de Caja{% endblock %}
|
{% block title %}Rendición de Caja{% endblock %}
|
||||||
|
|
||||||
{% block head %}
|
{% block head %}
|
||||||
@@ -90,33 +89,43 @@
|
|||||||
<div class="card mb-4 shadow-sm border-info">
|
<div class="card mb-4 shadow-sm border-info">
|
||||||
<div class="card-header bg-info text-dark">Resumen Financiero</div>
|
<div class="card-header bg-info text-dark">Resumen Financiero</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="row g-3">
|
<div class="row g-3 mb-4">
|
||||||
<div class="col-md-3">
|
<div class="col-md-4">
|
||||||
<label class="form-label">Total Tarjetas (Crédito/Débito)</label>
|
<label class="form-label">Venta Tarjeta</label>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<span class="input-group-text">$</span>
|
<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>
|
</div>
|
||||||
<div class="col-md-3">
|
<div class="col-md-4">
|
||||||
<label class="form-label">Total Mercado Pago</label>
|
<label class="form-label">Venta Mercado Pago</label>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<span class="input-group-text">$</span>
|
<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>
|
</div>
|
||||||
<div class="col-md-3">
|
<div class="col-md-4">
|
||||||
<label class="form-label">Total Efectivo</label>
|
<label class="form-label">Venta Efectivo</label>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<span class="input-group-text">$</span>
|
<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>
|
</div>
|
||||||
<div class="col-md-3">
|
</div>
|
||||||
<label class="form-label">Gastos del Módulo</label>
|
|
||||||
|
<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">
|
<div class="input-group">
|
||||||
<span class="input-group-text text-danger">-$</span>
|
<span class="input-group-text bg-info text-white border-info">$</span>
|
||||||
<input type="text" class="form-control money-input" name="gastos" placeholder="0">
|
<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>
|
</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>
|
<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>
|
</form>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
<script>
|
<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
|
// Reuse our formatting script for the summary money inputs
|
||||||
document.querySelectorAll('.money-input').forEach(function(input) {
|
document.querySelectorAll('.money-input').forEach(function(input) {
|
||||||
input.addEventListener('input', function(e) {
|
input.addEventListener('input', function(e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user