acompañante agregado
This commit is contained in:
43
app.py
43
app.py
@@ -52,18 +52,20 @@ def init_db():
|
||||
|
||||
# 5. Rendiciones (The main form headers)
|
||||
c.execute('''CREATE TABLE IF NOT EXISTS rendiciones
|
||||
(id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
worker_id INTEGER NOT NULL,
|
||||
modulo_id INTEGER NOT NULL,
|
||||
fecha DATE NOT NULL,
|
||||
turno TEXT NOT NULL,
|
||||
venta_tarjeta INTEGER DEFAULT 0,
|
||||
venta_mp INTEGER DEFAULT 0,
|
||||
venta_efectivo INTEGER DEFAULT 0,
|
||||
gastos INTEGER DEFAULT 0,
|
||||
observaciones TEXT,
|
||||
FOREIGN KEY (worker_id) REFERENCES workers(id),
|
||||
FOREIGN KEY (modulo_id) REFERENCES modulos(id))''')
|
||||
(id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
worker_id INTEGER NOT NULL,
|
||||
companion_id INTEGER, -- Nueva columna
|
||||
modulo_id INTEGER NOT NULL,
|
||||
fecha DATE NOT NULL,
|
||||
turno TEXT NOT NULL,
|
||||
venta_tarjeta INTEGER DEFAULT 0,
|
||||
venta_mp INTEGER DEFAULT 0,
|
||||
venta_efectivo INTEGER DEFAULT 0,
|
||||
gastos INTEGER DEFAULT 0,
|
||||
observaciones TEXT,
|
||||
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)
|
||||
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'))
|
||||
gastos = clean_and_validate(request.form.get('gastos')) or 0
|
||||
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
|
||||
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
|
||||
|
||||
# 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))
|
||||
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))
|
||||
rendicion_id = c.lastrowid
|
||||
|
||||
# Insertar Productos (Solo aquellos con cantidad > 0)
|
||||
@@ -265,6 +267,10 @@ def worker_dashboard():
|
||||
return redirect(url_for('worker_dashboard'))
|
||||
|
||||
# 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,))
|
||||
productos = c.fetchall()
|
||||
conn.close()
|
||||
@@ -276,6 +282,7 @@ def worker_dashboard():
|
||||
zona_name=zona_name,
|
||||
productos=productos,
|
||||
has_commission=has_commission,
|
||||
otros_trabajadores=otros_trabajadores,
|
||||
today=date.today().strftime('%Y-%m-%d'))
|
||||
|
||||
@app.route('/admin/workers', methods=['GET', 'POST'])
|
||||
@@ -605,10 +612,12 @@ def view_rendicion(id):
|
||||
# Get Header Info
|
||||
c.execute('''
|
||||
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
|
||||
JOIN workers w ON r.worker_id = w.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 = ?
|
||||
''', (id,))
|
||||
rendicion = c.fetchone()
|
||||
|
||||
@@ -58,20 +58,29 @@
|
||||
<div class="col-md-4 mb-4">
|
||||
<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-body">
|
||||
<dl class="row mb-0">
|
||||
<dt class="col-sm-5 text-muted">Fecha</dt>
|
||||
<dd class="col-sm-7">{{ rendicion[1] }}</dd>
|
||||
<div class="card-body">
|
||||
<dl class="row mb-0">
|
||||
<dt class="col-sm-5 text-muted">Fecha</dt>
|
||||
<dd class="col-sm-7">{{ rendicion[1] }}</dd>
|
||||
|
||||
<dt class="col-sm-5 text-muted">Trabajador</dt>
|
||||
<dd class="col-sm-7">{{ rendicion[2] }}</dd>
|
||||
<dt class="col-sm-5 text-muted">Trabajador</dt>
|
||||
<dd class="col-sm-7">{{ rendicion[2] }}</dd>
|
||||
|
||||
<dt class="col-sm-5 text-muted">Módulo</dt>
|
||||
<dd class="col-sm-7"><span class="badge bg-secondary">{{ rendicion[3] }}</span></dd>
|
||||
<dt class="col-sm-5 text-muted">Acompañante</dt>
|
||||
<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>
|
||||
<dd class="col-sm-7">{{ rendicion[4] }}</dd>
|
||||
</dl>
|
||||
<dt class="col-sm-5 text-muted">Módulo</dt>
|
||||
<dd class="col-sm-7"><span class="badge bg-secondary">{{ rendicion[3] }}</span></dd>
|
||||
|
||||
<dt class="col-sm-5 text-muted">Turno</dt>
|
||||
<dd class="col-sm-7">{{ rendicion[4] }}</dd>
|
||||
</dl>
|
||||
|
||||
<hr>
|
||||
|
||||
|
||||
@@ -43,10 +43,18 @@
|
||||
<option value="Part Time">Part Time</option>
|
||||
</select>
|
||||
</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 class="card mb-4 shadow-sm">
|
||||
<div class="card-header bg-primary text-white">Detalle de Productos Vendidos</div>
|
||||
<div class="card-body p-0">
|
||||
@@ -110,21 +118,21 @@
|
||||
<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 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 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 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 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 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>
|
||||
@@ -134,14 +142,14 @@
|
||||
<label class="form-label text-info fw-bold">Total Digital (Tarjeta + MP)</label>
|
||||
<div class="input-group">
|
||||
<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 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>
|
||||
<input type="text" class="form-control bg-dark-subtle fw-bold" placeholder="0" id="total_general" readonly>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user