edicion de rendiciones
This commit is contained in:
@@ -36,13 +36,10 @@ services:
|
||||
# TODO general:
|
||||
- separar productos para tiendas
|
||||
- limpiar requirements.txt
|
||||
- hacer prompts mas bonitos y estandar
|
||||
|
||||
# TODO peppermint:
|
||||
## formulario
|
||||
- cantidad de boletas por metodod de pago
|
||||
- añadir segunda persona a cargo
|
||||
- verificar que todos los campos esten rellenos
|
||||
- cantidad de boletas por metodo de pago
|
||||
- separar credito y debito
|
||||
- permitir subir foto de total gastos (boleta/factura)
|
||||
## otros
|
||||
|
||||
111
app.py
111
app.py
@@ -588,11 +588,11 @@ def admin_rendiciones():
|
||||
conn = sqlite3.connect(DB_NAME)
|
||||
c = conn.cursor()
|
||||
|
||||
# 1. Obtenemos la cabecera exacta igual que en view_rendicion (Índices 0 al 10)
|
||||
# Añadimos worker_id (11), companion_id (12) y modulo_id (13) a la consulta
|
||||
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,
|
||||
c_w.name
|
||||
r.venta_tarjeta, r.venta_mp, r.venta_efectivo, r.gastos, r.observaciones,
|
||||
c_w.name, r.worker_id, r.companion_id, r.modulo_id
|
||||
FROM rendiciones r
|
||||
JOIN workers w ON r.worker_id = w.id
|
||||
JOIN modulos m ON r.modulo_id = m.id
|
||||
@@ -603,7 +603,6 @@ def admin_rendiciones():
|
||||
|
||||
rendiciones_completas = []
|
||||
|
||||
# 2. Por cada rendición, buscamos sus ítems y calculamos los totales
|
||||
for r in rendiciones_basicas:
|
||||
c.execute('''
|
||||
SELECT p.name, ri.cantidad, ri.precio_historico, ri.comision_historica,
|
||||
@@ -618,60 +617,84 @@ def admin_rendiciones():
|
||||
total_calculado = sum(item[4] for item in items)
|
||||
comision_total = sum(item[5] for item in items)
|
||||
|
||||
# 3. Anexamos los nuevos datos a la tupla original
|
||||
# r[11] = items, r[12] = total_calculado, r[13] = comision_total
|
||||
# Ahora los ítems y totales ocupan los índices 14, 15 y 16
|
||||
r_completa = r + (items, total_calculado, comision_total)
|
||||
rendiciones_completas.append(r_completa)
|
||||
|
||||
# Obtenemos listas para los <select> del modal de edición
|
||||
c.execute("SELECT id, name FROM workers WHERE is_admin = 0 ORDER BY name")
|
||||
workers = c.fetchall()
|
||||
|
||||
c.execute("SELECT id, name FROM modulos ORDER BY name")
|
||||
modulos = c.fetchall()
|
||||
|
||||
conn.close()
|
||||
|
||||
return render_template('admin_rendiciones.html', rendiciones=rendiciones_completas)
|
||||
return render_template('admin_rendiciones.html',
|
||||
rendiciones=rendiciones_completas,
|
||||
workers=workers,
|
||||
modulos=modulos)
|
||||
|
||||
@app.route('/admin/rendiciones/<int:id>')
|
||||
@app.route('/admin/rendiciones/delete/<int:id>', methods=['POST'])
|
||||
@admin_required
|
||||
def view_rendicion(id):
|
||||
def delete_rendicion(id):
|
||||
conn = sqlite3.connect(DB_NAME)
|
||||
c = conn.cursor()
|
||||
|
||||
# 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,
|
||||
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()
|
||||
c.execute("DELETE FROM rendicion_items WHERE rendicion_id=?", (id,))
|
||||
c.execute("DELETE FROM rendiciones WHERE id=?", (id,))
|
||||
|
||||
if not rendicion:
|
||||
conn.close()
|
||||
flash("Rendición no encontrada.", "danger")
|
||||
return redirect(url_for('admin_rendiciones'))
|
||||
|
||||
# Get Line Items
|
||||
c.execute('''
|
||||
SELECT p.name, ri.cantidad, ri.precio_historico, ri.comision_historica,
|
||||
(ri.cantidad * ri.precio_historico) as total_linea,
|
||||
(ri.cantidad * ri.comision_historica) as total_comision
|
||||
FROM rendicion_items ri
|
||||
JOIN productos p ON ri.producto_id = p.id
|
||||
WHERE ri.rendicion_id = ?
|
||||
''', (id,))
|
||||
items = c.fetchall()
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
# Calculate the mathematical truth vs what they declared
|
||||
total_calculado = sum(item[4] for item in items)
|
||||
comision_total = sum(item[5] for item in items)
|
||||
flash("Rendición eliminada.", "info")
|
||||
return redirect(url_for('admin_rendiciones'))
|
||||
|
||||
return render_template('admin_rendicion_detail.html',
|
||||
rendicion=rendicion,
|
||||
items=items,
|
||||
total_calculado=total_calculado,
|
||||
comision_total=comision_total)
|
||||
|
||||
@app.route('/admin/rendiciones/edit/<int:id>', methods=['POST'])
|
||||
@admin_required
|
||||
def edit_rendicion(id):
|
||||
# Campos de cabecera
|
||||
fecha = request.form.get('fecha')
|
||||
turno = request.form.get('turno')
|
||||
worker_id = request.form.get('worker_id')
|
||||
modulo_id = request.form.get('modulo_id')
|
||||
companion_id = request.form.get('companion_id')
|
||||
|
||||
if companion_id == "":
|
||||
companion_id = None
|
||||
|
||||
# Campos de dinero
|
||||
tarjeta = request.form.get('venta_tarjeta', '0').replace('.', '')
|
||||
mp = request.form.get('venta_mp', '0').replace('.', '')
|
||||
efectivo = request.form.get('venta_efectivo', '0').replace('.', '')
|
||||
gastos = request.form.get('gastos', '0').replace('.', '')
|
||||
observaciones = request.form.get('observaciones', '').strip()
|
||||
|
||||
try:
|
||||
tarjeta = int(tarjeta) if tarjeta else 0
|
||||
mp = int(mp) if mp else 0
|
||||
efectivo = int(efectivo) if efectivo else 0
|
||||
gastos = int(gastos) if gastos else 0
|
||||
except ValueError:
|
||||
flash("Los valores ingresados deben ser números válidos.", "danger")
|
||||
return redirect(url_for('admin_rendiciones'))
|
||||
|
||||
conn = sqlite3.connect(DB_NAME)
|
||||
c = conn.cursor()
|
||||
|
||||
c.execute('''
|
||||
UPDATE rendiciones
|
||||
SET fecha=?, turno=?, worker_id=?, modulo_id=?, companion_id=?,
|
||||
venta_tarjeta=?, venta_mp=?, venta_efectivo=?, gastos=?, observaciones=?
|
||||
WHERE id=?
|
||||
''', (fecha, turno, worker_id, modulo_id, companion_id, tarjeta, mp, efectivo, gastos, observaciones, id))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
flash("Rendición actualizada correctamente.", "success")
|
||||
return redirect(url_for('admin_rendiciones'))
|
||||
|
||||
if __name__ == '__main__':
|
||||
init_db()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{% extends "macros/base.html" %}
|
||||
{% from 'macros/modals.html' import rendicion_detail_modal %}
|
||||
{% from 'macros/modals.html' import rendicion_detail_modal, confirm_modal, edit_rendicion_modal %}
|
||||
|
||||
{% block title %}Historial de Rendiciones{% endblock %}
|
||||
|
||||
@@ -9,6 +9,14 @@
|
||||
{% block content %}
|
||||
<h2 class="mb-4">Historial de Rendiciones</h2>
|
||||
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
{% for category, message in messages %}
|
||||
<div class="alert alert-{{ category }}">{{ message|safe }}</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body p-0">
|
||||
<table class="table table-striped table-hover mb-0">
|
||||
@@ -33,14 +41,43 @@
|
||||
<td class="align-middle">${{ "{:,.0f}".format((r[5] or 0) + (r[6] or 0) + (r[7] or 0)).replace(',', '.') }}</td>
|
||||
<td class="align-middle text-danger">${{ "{:,.0f}".format(r[8] or 0).replace(',', '.') }}</td>
|
||||
<td class="text-end">
|
||||
<button type="button"
|
||||
class="btn btn-sm btn-primary"
|
||||
data-bs-toggle="modal"
|
||||
data-bs-target="#viewRendicion{{ r[0] }}">
|
||||
Ver Detalle
|
||||
</button>
|
||||
<div class="btn-group" role="group">
|
||||
<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>
|
||||
</button>
|
||||
|
||||
{{ rendicion_detail_modal(r, r[11], r[12], r[13]) }}
|
||||
<button type="button"
|
||||
class="btn btn-sm btn-primary"
|
||||
data-bs-toggle="modal"
|
||||
data-bs-target="#editRendicion{{ r[0] }}"
|
||||
title="Editar Valores Declarados">
|
||||
<i class="bi bi-pencil"></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>
|
||||
|
||||
{{ rendicion_detail_modal(r, r[14], r[15], r[16]) }}
|
||||
{{ edit_rendicion_modal(r, workers, modulos) }}
|
||||
|
||||
{{ confirm_modal(
|
||||
id='deleteRendicion' ~ r[0],
|
||||
title='Eliminar Rendición',
|
||||
message='¿Estás seguro de que deseas eliminar la rendición #' ~ r[0] ~ '? Esta acción no se puede deshacer.',
|
||||
action_url=url_for('delete_rendicion', id=r[0]),
|
||||
btn_class='btn-danger',
|
||||
btn_text='Eliminar'
|
||||
) }}
|
||||
</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
@@ -53,3 +90,19 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
function calcTotalEdit(id) {
|
||||
const getVal = (inputId) => parseInt(document.getElementById(inputId).value.replace(/\D/g, '')) || 0;
|
||||
|
||||
const tarjeta = getVal(`edit_tarjeta_${id}`);
|
||||
const mp = getVal(`edit_mp_${id}`);
|
||||
const efectivo = getVal(`edit_efectivo_${id}`);
|
||||
|
||||
const total = tarjeta + mp + efectivo;
|
||||
|
||||
document.getElementById(`display_nuevo_total_${id}`).innerText = '$' + total.toLocaleString('es-CL');
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -247,3 +247,113 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro edit_rendicion_modal(rendicion, workers, modulos) %}
|
||||
<div class="modal fade" id="editRendicion{{ rendicion[0] }}" tabindex="-1" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Editar Rendición #{{ rendicion[0] }}</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<form method="POST" action="{{ url_for('edit_rendicion', id=rendicion[0]) }}">
|
||||
<div class="modal-body text-start">
|
||||
<h6 class="border-bottom pb-2 text-primary">Datos Generales</h6>
|
||||
<div class="row g-3 mb-4">
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Fecha</label>
|
||||
<input type="date" class="form-control" name="fecha" value="{{ rendicion[1] }}" required>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Turno</label>
|
||||
<select class="form-select" name="turno" required>
|
||||
<option value="Primer Turno" {% if rendicion[4] == 'Primer Turno' %}selected{% endif %}>Primer Turno</option>
|
||||
<option value="Segundo Turno" {% if rendicion[4] == 'Segundo Turno' %}selected{% endif %}>Segundo Turno</option>
|
||||
<option value="Part Time" {% if rendicion[4] == 'Part Time' %}selected{% endif %}>Part Time</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Módulo</label>
|
||||
<select class="form-select" name="modulo_id" required>
|
||||
{% for mod in modulos %}
|
||||
<option value="{{ mod[0] }}" {% if mod[0] == rendicion[13] %}selected{% endif %}>{{ mod[1] }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Trabajador</label>
|
||||
<select class="form-select" name="worker_id" required>
|
||||
{% for w in workers %}
|
||||
<option value="{{ w[0] }}" {% if w[0] == rendicion[11] %}selected{% endif %}>{{ w[1] }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Acompañante</label>
|
||||
<select class="form-select" name="companion_id">
|
||||
<option value="">Sin acompañante</option>
|
||||
{% for w in workers %}
|
||||
<option value="{{ w[0] }}" {% if w[0] == rendicion[12] %}selected{% endif %}>{{ w[1] }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h6 class="border-bottom pb-2 text-success">Declaración de Dinero</h6>
|
||||
<div class="row g-3">
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Tarjetas</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text">$</span>
|
||||
<input type="text" class="form-control money-input" id="edit_tarjeta_{{ rendicion[0] }}" name="venta_tarjeta" value="{{ rendicion[5] }}" oninput="calcTotalEdit({{ rendicion[0] }})" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Mercado Pago</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text">$</span>
|
||||
<input type="text" class="form-control money-input" id="edit_mp_{{ rendicion[0] }}" name="venta_mp" value="{{ rendicion[6] }}" oninput="calcTotalEdit({{ rendicion[0] }})" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Efectivo</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text">$</span>
|
||||
<input type="text" class="form-control money-input" id="edit_efectivo_{{ rendicion[0] }}" name="venta_efectivo" value="{{ rendicion[7] }}" oninput="calcTotalEdit({{ rendicion[0] }})" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% set total_declarado_actual = (rendicion[5] or 0) + (rendicion[6] or 0) + (rendicion[7] or 0) %}
|
||||
<div class="col-12 mt-3 bg-body-secondary p-3 rounded border border-secondary-subtle">
|
||||
<div class="d-flex justify-content-between pb-2">
|
||||
<span class="text-body-secondary">Total Declarado (Original):</span>
|
||||
<span class="text-body-secondary">${{ "{:,.0f}".format(total_declarado_actual).replace(',', '.') }}</span>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between pt-2 border-top border-secondary-subtle">
|
||||
<strong class="text-info">Nuevo Total Declarado:</strong>
|
||||
<strong class="text-info fs-5" id="display_nuevo_total_{{ rendicion[0] }}">${{ "{:,.0f}".format(total_declarado_actual).replace(',', '.') }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 mt-4">
|
||||
<label class="form-label text-danger">Gastos</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text">$</span>
|
||||
<input type="text" class="form-control money-input border-danger" name="gastos" value="{{ rendicion[8] }}" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-8 mt-4">
|
||||
<label class="form-label">Observaciones</label>
|
||||
<textarea class="form-control" name="observaciones" rows="1">{{ rendicion[9] }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancelar</button>
|
||||
<button type="submit" class="btn btn-primary">Guardar Cambios</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
Reference in New Issue
Block a user