acompañante agregado

This commit is contained in:
2026-03-21 00:01:47 -03:00
parent d3aea762d2
commit 821674d9f5
3 changed files with 61 additions and 35 deletions

43
app.py
View File

@@ -52,18 +52,20 @@ def init_db():
# 5. Rendiciones (The main form headers) # 5. Rendiciones (The main form headers)
c.execute('''CREATE TABLE IF NOT EXISTS rendiciones c.execute('''CREATE TABLE IF NOT EXISTS rendiciones
(id INTEGER PRIMARY KEY AUTOINCREMENT, (id INTEGER PRIMARY KEY AUTOINCREMENT,
worker_id INTEGER NOT NULL, worker_id INTEGER NOT NULL,
modulo_id INTEGER NOT NULL, companion_id INTEGER, -- Nueva columna
fecha DATE NOT NULL, modulo_id INTEGER NOT NULL,
turno TEXT NOT NULL, fecha DATE NOT NULL,
venta_tarjeta INTEGER DEFAULT 0, turno TEXT NOT NULL,
venta_mp INTEGER DEFAULT 0, venta_tarjeta INTEGER DEFAULT 0,
venta_efectivo INTEGER DEFAULT 0, venta_mp INTEGER DEFAULT 0,
gastos INTEGER DEFAULT 0, venta_efectivo INTEGER DEFAULT 0,
observaciones TEXT, gastos INTEGER DEFAULT 0,
FOREIGN KEY (worker_id) REFERENCES workers(id), observaciones TEXT,
FOREIGN KEY (modulo_id) REFERENCES modulos(id))''') FOREIGN KEY (worker_id) REFERENCES workers(id),
FOREIGN KEY (companion_id) REFERENCES workers(id),
FOREIGN KEY (modulo_id) REFERENCES modulos(id))''')
# 6. Rendicion Items (The individual product quantities sold) # 6. Rendicion Items (The individual product quantities sold)
c.execute('''CREATE TABLE IF NOT EXISTS rendicion_items c.execute('''CREATE TABLE IF NOT EXISTS rendicion_items
@@ -228,6 +230,9 @@ def worker_dashboard():
efectivo = clean_and_validate(request.form.get('venta_efectivo')) efectivo = clean_and_validate(request.form.get('venta_efectivo'))
gastos = clean_and_validate(request.form.get('gastos')) or 0 gastos = clean_and_validate(request.form.get('gastos')) or 0
obs = request.form.get('observaciones', '').strip() obs = request.form.get('observaciones', '').strip()
companion_id = request.form.get('companion_id')
if companion_id == "":
companion_id = None
# VERIFICACIÓN: Todos los campos de venta deben estar rellenos # 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: if tarjeta is None or mp is None or efectivo is None or not fecha or not turno:
@@ -239,10 +244,7 @@ def worker_dashboard():
total_ventas_general = total_digital + efectivo total_ventas_general = total_digital + efectivo
# Insertar Cabecera de Rendición # Insertar Cabecera de Rendición
c.execute('''INSERT INTO rendiciones c.execute('''INSERT INTO rendiciones (worker_id, companion_id, modulo_id, fecha, turno, venta_tarjeta, venta_mp, venta_efectivo, gastos, observaciones) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', (session['user_id'], companion_id, modulo_id, fecha, turno, tarjeta, mp, efectivo, gastos, obs))
(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 rendicion_id = c.lastrowid
# Insertar Productos (Solo aquellos con cantidad > 0) # Insertar Productos (Solo aquellos con cantidad > 0)
@@ -265,6 +267,10 @@ def worker_dashboard():
return redirect(url_for('worker_dashboard')) return redirect(url_for('worker_dashboard'))
# 3. Cargar Productos para la solicitud GET # 3. Cargar Productos para la solicitud GET
c.execute("SELECT id, name FROM workers WHERE id != ? AND is_admin = 0 ORDER BY name", (session['user_id'],))
otros_trabajadores = c.fetchall()
# Cargar Productos (código existente)
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()
@@ -276,6 +282,7 @@ def worker_dashboard():
zona_name=zona_name, zona_name=zona_name,
productos=productos, productos=productos,
has_commission=has_commission, has_commission=has_commission,
otros_trabajadores=otros_trabajadores,
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'])
@@ -605,10 +612,12 @@ def view_rendicion(id):
# Get Header Info # Get Header Info
c.execute(''' c.execute('''
SELECT r.id, r.fecha, w.name, m.name, r.turno, SELECT r.id, r.fecha, w.name, m.name, r.turno,
r.venta_tarjeta, r.venta_mp, r.venta_efectivo, r.gastos, r.observaciones r.venta_tarjeta, r.venta_mp, r.venta_efectivo, r.gastos, r.observaciones,
c_w.name -- Nombre del acompañante (índice 10)
FROM rendiciones r FROM rendiciones r
JOIN workers w ON r.worker_id = w.id JOIN workers w ON r.worker_id = w.id
JOIN modulos m ON r.modulo_id = m.id JOIN modulos m ON r.modulo_id = m.id
LEFT JOIN workers c_w ON r.companion_id = c_w.id -- Join para el acompañante
WHERE r.id = ? WHERE r.id = ?
''', (id,)) ''', (id,))
rendicion = c.fetchone() rendicion = c.fetchone()

View File

@@ -58,20 +58,29 @@
<div class="col-md-4 mb-4"> <div class="col-md-4 mb-4">
<div class="card shadow-sm mb-4 border-info"> <div class="card shadow-sm mb-4 border-info">
<div class="card-header bg-info text-dark fw-bold">Declaración del Trabajador</div> <div class="card-header bg-info text-dark fw-bold">Declaración del Trabajador</div>
<div class="card-body"> <div class="card-body">
<dl class="row mb-0"> <dl class="row mb-0">
<dt class="col-sm-5 text-muted">Fecha</dt> <dt class="col-sm-5 text-muted">Fecha</dt>
<dd class="col-sm-7">{{ rendicion[1] }}</dd> <dd class="col-sm-7">{{ rendicion[1] }}</dd>
<dt class="col-sm-5 text-muted">Trabajador</dt> <dt class="col-sm-5 text-muted">Trabajador</dt>
<dd class="col-sm-7">{{ rendicion[2] }}</dd> <dd class="col-sm-7">{{ rendicion[2] }}</dd>
<dt class="col-sm-5 text-muted">Módulo</dt> <dt class="col-sm-5 text-muted">Acompañante</dt>
<dd class="col-sm-7"><span class="badge bg-secondary">{{ rendicion[3] }}</span></dd> <dd class="col-sm-7">
{% if rendicion[10] %}
{{ rendicion[10] }}
{% else %}
<span class="text-muted italic small">Sin acompañante</span>
{% endif %}
</dd>
<dt class="col-sm-5 text-muted">Turno</dt> <dt class="col-sm-5 text-muted">Módulo</dt>
<dd class="col-sm-7">{{ rendicion[4] }}</dd> <dd class="col-sm-7"><span class="badge bg-secondary">{{ rendicion[3] }}</span></dd>
</dl>
<dt class="col-sm-5 text-muted">Turno</dt>
<dd class="col-sm-7">{{ rendicion[4] }}</dd>
</dl>
<hr> <hr>

View File

@@ -43,10 +43,18 @@
<option value="Part Time">Part Time</option> <option value="Part Time">Part Time</option>
</select> </select>
</div> </div>
<div class="col-md-12">
<label class="form-label">Acompañante (Opcional)</label>
<select class="form-select" name="companion_id">
<option value="">Trabajando solo / Sin acompañante</option>
{% for worker in otros_trabajadores %}
<option value="{{ worker[0] }}">{{ worker[1] }}</option>
{% endfor %}
</select>
</div>
</div> </div>
</div> </div>
</div> </div>
<div class="card mb-4 shadow-sm"> <div class="card mb-4 shadow-sm">
<div class="card-header bg-primary text-white">Detalle de Productos Vendidos</div> <div class="card-header bg-primary text-white">Detalle de Productos Vendidos</div>
<div class="card-body p-0"> <div class="card-body p-0">
@@ -110,21 +118,21 @@
<label class="form-label">Venta Tarjeta</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 sale-input" name="venta_tarjeta" id="venta_tarjeta" required> <input type="text" class="form-control money-input sale-input" placeholder="0" name="venta_tarjeta" id="venta_tarjeta" required>
</div> </div>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<label class="form-label">Venta 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 sale-input" name="venta_mp" id="venta_mp" required> <input type="text" class="form-control money-input sale-input" placeholder="0" name="venta_mp" id="venta_mp" required>
</div> </div>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<label class="form-label">Venta 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 sale-input" name="venta_efectivo" id="venta_efectivo" required> <input type="text" class="form-control money-input sale-input" placeholder="0" name="venta_efectivo" id="venta_efectivo" required>
</div> </div>
</div> </div>
</div> </div>
@@ -134,14 +142,14 @@
<label class="form-label text-info fw-bold">Total Digital (Tarjeta + MP)</label> <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 bg-info text-white border-info">$</span> <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> <input type="text" class="form-control bg-dark-subtle fw-bold" placeholder="0" id="total_digital" readonly>
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<label class="form-label text-success fw-bold">Total Ventas (Todos los medios)</label> <label class="form-label text-success fw-bold">Total Ventas (Todos los medios)</label>
<div class="input-group"> <div class="input-group">
<span class="input-group-text bg-success text-white border-success">$</span> <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> <input type="text" class="form-control bg-dark-subtle fw-bold" placeholder="0" id="total_general" readonly>
</div> </div>
</div> </div>
</div> </div>