si recibe o no comision

This commit is contained in:
2026-03-22 20:18:40 -03:00
parent e801fb9ee1
commit eccd1d12a9
4 changed files with 62 additions and 18 deletions

44
app.py
View File

@@ -146,6 +146,7 @@ def init_db():
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,
worker_comision BOOLEAN DEFAULT 1,
companion_id INTEGER, companion_id INTEGER,
modulo_id INTEGER NOT NULL, modulo_id INTEGER NOT NULL,
fecha DATE NOT NULL, fecha DATE NOT NULL,
@@ -153,6 +154,7 @@ def init_db():
hora_salida TEXT NOT NULL, hora_salida TEXT NOT NULL,
companion_hora_entrada TEXT, companion_hora_entrada TEXT,
companion_hora_salida TEXT, companion_hora_salida TEXT,
companion_comision BOOLEAN DEFAULT 0,
venta_debito INTEGER DEFAULT 0, venta_debito INTEGER DEFAULT 0,
venta_credito INTEGER DEFAULT 0, venta_credito INTEGER DEFAULT 0,
venta_mp INTEGER DEFAULT 0, venta_mp INTEGER DEFAULT 0,
@@ -299,7 +301,8 @@ def worker_dashboard():
c.execute(''' c.execute('''
SELECT r.id, r.fecha, w.name, m.name, SELECT r.id, r.fecha, w.name, m.name,
r.venta_debito, r.venta_credito, r.venta_mp, r.venta_efectivo, r.gastos, r.observaciones, r.venta_debito, r.venta_credito, r.venta_mp, r.venta_efectivo, r.gastos, r.observaciones,
c_w.name, r.worker_id, r.companion_id, r.modulo_id c_w.name, r.worker_id, r.companion_id, r.modulo_id,
r.worker_comision, r.companion_comision
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
@@ -387,15 +390,27 @@ def new_rendicion():
flash("Error: Todos los campos obligatorios deben estar rellenos.", "danger") flash("Error: Todos los campos obligatorios deben estar rellenos.", "danger")
return redirect(url_for('new_rendicion')) return redirect(url_for('new_rendicion'))
# --- NUEVO: Calcular comisiones por defecto según jornada ---
c.execute("SELECT tipo FROM workers WHERE id = ?", (session['user_id'],))
worker_tipo = c.fetchone()[0]
worker_comision = 1 if worker_tipo == 'Full Time' else 0
companion_comision = 0
if companion_id:
c.execute("SELECT tipo FROM workers WHERE id = ?", (companion_id,))
comp_tipo = c.fetchone()
if comp_tipo and comp_tipo[0] == 'Full Time':
companion_comision = 1
total_digital = debito + credito + mp total_digital = debito + credito + mp
total_ventas_general = total_digital + efectivo total_ventas_general = total_digital + efectivo
c.execute('''INSERT INTO rendiciones c.execute('''INSERT INTO rendiciones
(worker_id, companion_id, modulo_id, fecha, hora_entrada, hora_salida, companion_hora_entrada, companion_hora_salida, (worker_id, companion_id, modulo_id, fecha, hora_entrada, hora_salida, companion_hora_entrada, companion_hora_salida,
venta_debito, venta_credito, venta_mp, venta_efectivo, gastos, observaciones) venta_debito, venta_credito, venta_mp, venta_efectivo, gastos, observaciones, worker_comision, companion_comision)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''',
(session['user_id'], companion_id, modulo_id, fecha, hora_entrada, hora_salida, companion_hora_entrada, companion_hora_salida, (session['user_id'], companion_id, modulo_id, fecha, hora_entrada, hora_salida, companion_hora_entrada, companion_hora_salida,
debito, credito, mp, efectivo, gastos, obs)) debito, credito, mp, efectivo, gastos, obs, worker_comision, companion_comision))
rendicion_id = c.lastrowid rendicion_id = c.lastrowid
for key, value in request.form.items(): for key, value in request.form.items():
@@ -746,7 +761,8 @@ def admin_rendiciones():
c.execute(''' c.execute('''
SELECT r.id, r.fecha, w.name, m.name, SELECT r.id, r.fecha, w.name, m.name,
r.venta_debito, r.venta_credito, r.venta_mp, r.venta_efectivo, r.gastos, r.observaciones, r.venta_debito, r.venta_credito, r.venta_mp, r.venta_efectivo, r.gastos, r.observaciones,
c_w.name, r.worker_id, r.companion_id, r.modulo_id c_w.name, r.worker_id, r.companion_id, r.modulo_id,
r.worker_comision, r.companion_comision
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
@@ -822,6 +838,9 @@ def edit_rendicion(id):
efectivo = request.form.get('venta_efectivo', '0').replace('.', '') efectivo = request.form.get('venta_efectivo', '0').replace('.', '')
gastos = request.form.get('gastos', '0').replace('.', '') gastos = request.form.get('gastos', '0').replace('.', '')
observaciones = request.form.get('observaciones', '').strip() observaciones = request.form.get('observaciones', '').strip()
worker_comision = 1 if request.form.get('worker_comision') else 0
companion_comision = 1 if request.form.get('companion_comision') else 0
try: try:
debito = int(debito) if debito else 0 debito = int(debito) if debito else 0
@@ -839,10 +858,10 @@ def edit_rendicion(id):
c.execute(''' c.execute('''
UPDATE rendiciones UPDATE rendiciones
SET fecha=?, worker_id=?, modulo_id=?, companion_id=?, SET fecha=?, worker_id=?, modulo_id=?, companion_id=?,
venta_debito=?, venta_credito=?, venta_mp=?, venta_efectivo=?, gastos=?, observaciones=? venta_debito=?, venta_credito=?, venta_mp=?, venta_efectivo=?, gastos=?, observaciones=?,
worker_comision=?, companion_comision=?
WHERE id=? WHERE id=?
''', (fecha, worker_id, modulo_id, companion_id, debito, credito, mp, efectivo, gastos, observaciones, id)) ''', (fecha, worker_id, modulo_id, companion_id, debito, credito, mp, efectivo, gastos, observaciones, worker_comision, companion_comision, id))
conn.commit() conn.commit()
conn.close() conn.close()
@@ -889,10 +908,11 @@ def report_modulo_periodo(modulo_id):
# 1. Obtener finanzas (pagos y gastos) agrupadas por día # 1. Obtener finanzas (pagos y gastos) agrupadas por día
c.execute(''' c.execute('''
SELECT strftime('%d', fecha) as dia, SELECT strftime('%d', r.fecha) as dia,
SUM(venta_debito), SUM(venta_credito), SUM(venta_mp), SUM(venta_efectivo), SUM(gastos) SUM(ri.cantidad * ri.comision_historica * CASE WHEN r.worker_comision = 1 OR r.companion_comision = 1 THEN 1 ELSE 0 END) as comision_total
FROM rendiciones FROM rendicion_items ri
WHERE modulo_id = ? AND strftime('%m', fecha) = ? AND strftime('%Y', fecha) = ? JOIN rendiciones r ON ri.rendicion_id = r.id
WHERE r.modulo_id = ? AND strftime('%m', r.fecha) = ? AND strftime('%Y', r.fecha) = ?
GROUP BY dia GROUP BY dia
''', (modulo_id, f'{mes_actual:02}', str(anio_actual))) ''', (modulo_id, f'{mes_actual:02}', str(anio_actual)))
finanzas_db = c.fetchall() finanzas_db = c.fetchall()

View File

@@ -48,7 +48,7 @@
<button type="button" class="btn btn-sm btn-danger" data-bs-toggle="modal" data-bs-target="#deleteRendicion{{ r[0] }}" title="Eliminar Rendición"><i class="bi bi-trash"></i></button> <button type="button" class="btn btn-sm btn-danger" data-bs-toggle="modal" data-bs-target="#deleteRendicion{{ r[0] }}" title="Eliminar Rendición"><i class="bi bi-trash"></i></button>
</div> </div>
{{ rendicion_detail_modal(r, r[14], r[15], r[16]) }} {{ rendicion_detail_modal(r, r[16], r[17], r[18]) }}
{{ edit_rendicion_modal(r, workers, modulos) }} {{ edit_rendicion_modal(r, workers, modulos) }}
{{ confirm_modal( {{ confirm_modal(

View File

@@ -188,7 +188,13 @@
<tr> <tr>
<td colspan="3" class="text-end fw-bold">Total Calculado por Sistema:</td> <td colspan="3" class="text-end fw-bold">Total Calculado por Sistema:</td>
<td class="text-end fw-bold fs-6">${{ "{:,.0f}".format(total_calculado or 0).replace(',', '.') }}</td> <td class="text-end fw-bold fs-6">${{ "{:,.0f}".format(total_calculado or 0).replace(',', '.') }}</td>
<td class="text-end fw-bold text-success fs-6">${{ "{:,.0f}".format(comision_total or 0).replace(',', '.') }}</td> <td class="text-end fw-bold text-success fs-6">
{% if not rendicion[14] and not rendicion[15] %}
<span class="text-decoration-line-through text-muted">${{ "{:,.0f}".format(comision_total or 0).replace(',', '.') }}</span>
{% else %}
${{ "{:,.0f}".format(comision_total or 0).replace(',', '.') }}
{% endif %}
</td>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>
@@ -206,12 +212,23 @@
<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] }}
{% if session.get('is_admin') %}
<span class="badge {% if rendicion[14] %}bg-success{% else %}bg-secondary{% endif %} ms-1" style="font-size: 0.65em;">
{% if rendicion[14] %}$ Sí{% else %}$ No{% endif %}
</span>
{% endif %}
</dd>
<dt class="col-sm-5 text-muted">Acompañante</dt> <dt class="col-sm-5 text-muted">Acompañante</dt>
<dd class="col-sm-7"> <dd class="col-sm-7">
{% if rendicion[10] %} {% if rendicion[10] %}
{{ rendicion[10] }} {{ rendicion[10] }}
{% if session.get('is_admin') %}
<span class="badge {% if rendicion[15] %}bg-success{% else %}bg-secondary{% endif %} ms-1" style="font-size: 0.65em;">
{% if rendicion[15] %}$ Sí{% else %}$ No{% endif %}
</span>
{% endif %}
{% else %} {% else %}
<span class="text-muted italic small">Sin acompañante</span> <span class="text-muted italic small">Sin acompañante</span>
{% endif %} {% endif %}
@@ -309,17 +326,24 @@
<option value="{{ w[0] }}" {% if w[0] == rendicion[11] %}selected{% endif %}>{{ w[1] }}</option> <option value="{{ w[0] }}" {% if w[0] == rendicion[11] %}selected{% endif %}>{{ w[1] }}</option>
{% endfor %} {% endfor %}
</select> </select>
<div class="form-check form-switch mt-2">
<input class="form-check-input" type="checkbox" role="switch" name="worker_comision" id="wc_{{ rendicion[0] }}" {% if rendicion[14] %}checked{% endif %}>
<label class="form-check-label text-warning small" for="wc_{{ rendicion[0] }}"><i class="bi bi-star me-1"></i>Recibe comisión</label>
</div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<label class="form-label">Acompañante</label> <label class="form-label">Acompañante</label>
<select class="form-select" name="companion_id"> <select class="form-select" name="companion_id" onchange="document.getElementById('comp_com_div_{{ rendicion[0] }}').style.display = this.value ? 'block' : 'none';">
<option value="">Sin acompañante</option> <option value="">Sin acompañante</option>
{% for w in workers %} {% for w in workers %}
<option value="{{ w[0] }}" {% if w[0] == rendicion[12] %}selected{% endif %}>{{ w[1] }}</option> <option value="{{ w[0] }}" {% if w[0] == rendicion[12] %}selected{% endif %}>{{ w[1] }}</option>
{% endfor %} {% endfor %}
</select> </select>
<div class="form-check form-switch mt-2" id="comp_com_div_{{ rendicion[0] }}" {% if not rendicion[12] %}style="display:none;"{% endif %}>
<input class="form-check-input" type="checkbox" role="switch" name="companion_comision" id="cc_{{ rendicion[0] }}" {% if rendicion[15] %}checked{% endif %}>
<label class="form-check-label text-warning small" for="cc_{{ rendicion[0] }}"><i class="bi bi-star me-1"></i>Recibe comisión</label>
</div>
</div> </div>
</div>
<h6 class="border-bottom pb-2 text-success">Declaración de Dinero</h6> <h6 class="border-bottom pb-2 text-success">Declaración de Dinero</h6>
<div class="row g-3"> <div class="row g-3">

View File

@@ -64,7 +64,7 @@
<button type="button" class="btn btn-sm btn-info text-white" data-bs-toggle="modal" data-bs-target="#viewRendicion{{ r[0] }}" title="Ver Detalle"> <button type="button" class="btn btn-sm btn-info text-white" data-bs-toggle="modal" data-bs-target="#viewRendicion{{ r[0] }}" title="Ver Detalle">
<i class="bi bi-eye"></i> <i class="bi bi-eye"></i>
</button> </button>
{{ rendicion_detail_modal(r, r[14], r[15], r[16]) }} {{ rendicion_detail_modal(r, r[16], r[17], r[18]) }}
</td> </td>
</tr> </tr>
{% else %} {% else %}