tipo de trabajador part time o full time

This commit is contained in:
2026-03-21 21:35:05 -03:00
parent 72b81b26b8
commit a76c0a879e
5 changed files with 45 additions and 23 deletions

View File

@@ -33,7 +33,6 @@ services:
restart: unless-stopped
```
# TODO preguntas:
- ver si gastos debe o no restar del total
- ver si tienen como turnos fijos para setear un horario
- ver si trabajan mas de 2 personas maximo al dia
@@ -41,7 +40,6 @@ services:
- añadir si es part time o full time en la tabla de trabajadores para ver si necesitan comisiones
- separar productos para tiendas
- limpiar requirements.txt
- hacer placeholders funcionales (si dice 0 que el sistema lea 0 no null)
- mostrar rendiciones antiguas
- hacer como un hub del trabajador qu permita ver antiguos y crear uno nuevo
- mostrar total de ventas con graficos en el index(?)

30
app.py
View File

@@ -80,7 +80,7 @@ def populateDefaults():
for name, price, commission in productos_data:
c.execute("INSERT INTO productos (zona_id, name, price, commission) VALUES (?, ?, ?, ?)",
(zona_id, name, price, commission))
c.execute("SELECT COUNT(*) FROM workers WHERE is_admin = 0")
if c.fetchone()[0] == 0:
c.execute("SELECT id FROM modulos LIMIT 2")
@@ -93,16 +93,16 @@ def populateDefaults():
default_pass = generate_password_hash("123456")
workers_data = [
("11.111.111-1", "Juan Perez", "+56 9 1111 1111", default_pass, 0, mod_1),
("22.222.222-2", "Maria Gonzalez", "+56 9 2222 2222", default_pass, 0, mod_1),
("33.333.333-3", "Pedro Soto", "+56 9 3333 3333", default_pass, 0, mod_2),
("44.444.444-4", "Ana Silva", "+56 9 4444 4444", default_pass, 0, mod_2)
("11.111.111-1", "Juan Perez", "+56 9 1111 1111", default_pass, 0, mod_1, "Full Time"),
("22.222.222-2", "Maria Gonzalez", "+56 9 2222 2222", default_pass, 0, mod_1, "Part Time"),
("33.333.333-3", "Pedro Soto", "+56 9 3333 3333", default_pass, 0, mod_2, "Full Time"),
("44.444.444-4", "Ana Silva", "+56 9 4444 4444", default_pass, 0, mod_2, "Part Time")
]
for w in workers_data:
c.execute("INSERT OR IGNORE INTO workers (rut, name, phone, password_hash, is_admin, modulo_id) VALUES (?, ?, ?, ?, ?, ?)", w)
conn.commit()
c.execute("INSERT OR IGNORE INTO workers (rut, name, phone, password_hash, is_admin, modulo_id, tipo) VALUES (?, ?, ?, ?, ?, ?, ?)", w)
conn.commit()
conn.close()
def init_db():
conn = sqlite3.connect(DB_NAME)
@@ -130,7 +130,6 @@ def init_db():
FOREIGN KEY (zona_id) REFERENCES zonas(id))''')
# 4. Workers (Now tied to a Modulo)
# Added modulo_id. It can be NULL for the system admin.
c.execute('''CREATE TABLE IF NOT EXISTS workers
(id INTEGER PRIMARY KEY AUTOINCREMENT,
rut TEXT UNIQUE NOT NULL,
@@ -139,6 +138,7 @@ def init_db():
password_hash TEXT NOT NULL,
is_admin BOOLEAN DEFAULT 0,
modulo_id INTEGER,
tipo TEXT DEFAULT 'Full Time',
FOREIGN KEY (modulo_id) REFERENCES modulos(id))''')
# 5. Rendiciones (The main form headers)
@@ -404,6 +404,7 @@ def manage_workers():
raw_phone = request.form['phone']
name = request.form['name'].strip()
modulo_id = request.form.get('modulo_id')
tipo = request.form.get('tipo', 'Full Time')
form_data = request.form
if not validate_rut(raw_rut):
@@ -420,8 +421,8 @@ def manage_workers():
try:
# Now inserting modulo_id
c.execute("INSERT INTO workers (rut, name, phone, password_hash, is_admin, modulo_id) VALUES (?, ?, ?, ?, 0, ?)",
(rut, name, phone, p_hash, modulo_id))
c.execute("INSERT INTO workers (rut, name, phone, password_hash, is_admin, modulo_id, tipo) VALUES (?, ?, ?, ?, 0, ?, ?)",
(rut, name, phone, p_hash, modulo_id, tipo))
conn.commit()
flash(f"Trabajador guardado. Contraseña temporal: <strong>{password}</strong>", "success")
return redirect(url_for('manage_workers'))
@@ -429,7 +430,7 @@ def manage_workers():
flash("El RUT ya existe en el sistema.", "danger")
# Fetch workers and JOIN their module name
c.execute('''SELECT w.id, w.rut, w.name, w.phone, m.name, w.modulo_id
c.execute('''SELECT w.id, w.rut, w.name, w.phone, m.name, w.modulo_id, w.tipo
FROM workers w
LEFT JOIN modulos m ON w.modulo_id = m.id
WHERE w.is_admin = 0''')
@@ -456,6 +457,7 @@ def edit_worker(id):
raw_phone = request.form['phone']
name = request.form['name'].strip()
modulo_id = request.form.get('modulo_id')
tipo = request.form.get('tipo', 'Full Time')
if not validate_phone(raw_phone):
flash("El teléfono debe tener 9 dígitos válidos.", "danger")
@@ -464,8 +466,8 @@ def edit_worker(id):
flash("Debes seleccionar un módulo.", "danger")
return redirect(url_for('edit_worker', id=id))
c.execute("UPDATE workers SET name=?, phone=?, modulo_id=? WHERE id=?",
(name, format_phone(raw_phone), modulo_id, id))
c.execute("UPDATE workers SET name=?, phone=?, modulo_id=?, tipo=? WHERE id=?",
(name, format_phone(raw_phone), modulo_id, tipo, id))
conn.commit()
flash("Trabajador actualizado exitosamente.", "success")
conn.close()

View File

@@ -25,7 +25,7 @@
<div class="card-body">
<form method="POST" action="{{ url_for('manage_workers') }}">
<div class="row g-3">
<div class="col-md-3">
<div class="col-md-2">
<label class="form-label">RUT</label>
<input type="text" class="form-control" name="rut" id="rutInput" placeholder="12.345.678-9" value="{{ form.get('rut', '') }}" required>
</div>
@@ -33,7 +33,7 @@
<label class="form-label">Nombre Completo</label>
<input type="text" class="form-control" name="name" value="{{ form.get('name', '') }}" required>
</div>
<div class="col-md-3">
<div class="col-md-2">
<label class="form-label">Teléfono</label>
<input type="text" class="form-control" name="phone" id="phoneInput" placeholder="9 1234 5678" value="{{ form.get('phone', '') }}" required>
</div>
@@ -46,6 +46,13 @@
{% endfor %}
</select>
</div>
<div class="col-md-2">
<label class="form-label">Jornada</label>
<select class="form-select" name="tipo" required>
<option value="Full Time" {% if form.get('tipo') == 'Full Time' %}selected{% endif %}>Full Time</option>
<option value="Part Time" {% if form.get('tipo') == 'Part Time' %}selected{% endif %}>Part Time</option>
</select>
</div>
</div>
<button type="submit" class="btn btn-primary mt-3">Guardar Trabajador</button>
</form>
@@ -61,6 +68,7 @@
<th>Nombre</th>
<th>Teléfono</th>
<th>Módulo</th>
<th>Tipo</th>
<th class="text-end">Acciones</th>
</tr>
</thead>
@@ -71,6 +79,11 @@
<td class="align-middle">{{ worker[2] }}</td>
<td class="align-middle">{{ worker[3] }}</td>
<td class="align-middle"><span class="badge bg-info text-dark">{{ worker[4] }}</span></td>
<td class="align-middle">
<span class="badge {% if worker[6] == 'Full Time' %}bg-success{% else %}bg-secondary{% endif %}">
{{ worker[6] }}
</span>
</td>
<td class="text-end">
<button type="button"
class="btn btn-primary btn-sm btn-edit-sm"
@@ -80,7 +93,8 @@
data-rut="{{ worker[1] }}"
data-name="{{ worker[2] }}"
data-phone="{{ worker[3] }}"
data-modulo="{{ worker[5] }}">
data-modulo="{{ worker[5] }}"
data-tipo="{{ worker[6] }}">
<i class="bi bi-pencil"></i>
</button>
@@ -99,7 +113,7 @@
</tr>
{% else %}
<tr>
<td colspan="5" class="text-center py-3 text-muted">No hay trabajadores registrados.</td>
<td colspan="6" class="text-center py-3 text-muted">No hay trabajadores registrados.</td>
</tr>
{% endfor %}
</tbody>
@@ -143,6 +157,7 @@
editWorkerModal.querySelector('#edit_worker_name').value = name;
editWorkerModal.querySelector('#edit_worker_phone').value = button.getAttribute('data-phone');
editWorkerModal.querySelector('#edit_worker_modulo').value = button.getAttribute('data-modulo');
editWorkerModal.querySelector('#edit_worker_tipo').value = button.getAttribute('data-tipo');
}
});
}

View File

@@ -113,6 +113,13 @@
{% endfor %}
</select>
</div>
<div class="mb-3">
<label class="form-label">Jornada</label>
<select class="form-select" name="tipo" id="edit_worker_tipo" required>
<option value="Full Time">Full Time</option>
<option value="Part Time">Part Time</option>
</select>
</div>
</form>
<hr>

View File

@@ -31,8 +31,8 @@
<div class="card-body">
<div class="row g-3">
<div class="col-md-4">
<label class="form-label">Fecha de Venta</label>
<input type="date" class="form-control" name="fecha" value="{{ today }}" required>
<label class="form-label">Fecha</label>
<input type="date" class="form-control" name="fecha" value="{{ today }}" min="{{ today }}" required>
</div>
<div class="col-md-4">
<label class="form-label">Entrada</label>
@@ -308,7 +308,7 @@ document.addEventListener('DOMContentLoaded', function() {
mainForm.submit();
} else {
bootstrap.Modal.getInstance(submitModal).hide();
mostrarError("Por favor, rellena los campos obligatorios (Fecha y Turno) antes de enviar.");
mostrarError("Por favor, rellena los campos obligatorios (Fecha y Hora) antes de enviar.");
}
});