Select Git revision
Forked from
Vuillemot Romain / INF-TC1
Source project has a limited visibility.
streamlit_app.py 5.81 KiB
import streamlit as st
from datetime import date
import sqlite3
import pandas as pd
import numpy as np # Add this line to import numpy
st.title("Page de gestion des employés")
st.write("Bienvenue!😃")
if 'page' not in st.session_state:
st.session_state.page = None
tab1, tab2, tab3,tab4 = st.tabs(["Suivi des employés","Employés avec 3 ans d'anciénneté", "Création d'un compte employé", "Bonus"])
with tab1:
st.header("Suivi Employés")
popover = st.popover("Filtre employés à afficher")
total = popover.checkbox("Salaires des employés par semaine", True)
dimin = popover.checkbox("Salaires des employés ayant eu une diminution par semaine", True)
conn= sqlite3.connect(r'C:\Users\neiro\Documents\+\GitHub\sgbd-usine\donnees\company.db')
cursor = conn.cursor()
cursor.execute("SELECT DATE_LUNDI,SALAIRE_SEMAINE.NUMERO_EMPLOYE,NOM,PRENOM,SALAIRE_BASE,SALAIRE_AVANT, SALAIRE_APRES,NB_HEURES, NB_PRODUCTION,RETARD,ANCIENNETE,NOEL, DATE_DEBUT FROM SALAIRE_SEMAINE JOIN EMPLOYE ON EMPLOYE.NUMERO_EMPLOYE = SALAIRE_SEMAINE.NUMERO_EMPLOYE")
employees = cursor.fetchall()
# Convert the employee records to a DataFrame
df = pd.DataFrame(employees, columns=[desc[0] for desc in cursor.description])
df.columns = ['Date du lundi', 'Numéro employé', 'Nom', 'Prénom', 'Salaire base', 'Salaire avant primes','Salaire réel', 'Nombre d\'heures', 'Nombre de production', 'Retard','Ancienneté', 'Bonus de Noël', 'Date de début']
if total:
# Add code for "Suivi Employés" page here
st.write("Salaires des employés par semaine (question 1)")
st.dataframe(df)
if dimin:
st.write("Salaires des employés ayant eu une diminution par semaine (question 3)")
st.dataframe(df[df['Salaire avant primes']<df['Salaire base']])
conn.close()
with tab2:
conn= sqlite3.connect(r'C:\Users\neiro\Documents\+\GitHub\sgbd-usine\donnees\company.db')
cursor = conn.cursor()
on = st.toggle("Employés avec 3 ans d'anciénneté")
cursor.execute("SELECT NUMERO_EMPLOYE,NOM,PRENOM,TYPE,DATE_DEBUT FROM EMPLOYE")
employees = cursor.fetchall()
df=pd.DataFrame(employees, columns=[desc[0] for desc in cursor.description])
from datetime import datetime
today = datetime.today()
df['DATE_DEBUT'] = pd.to_datetime(df['DATE_DEBUT'])
if on:
st.header("Liste des employés avec 3 ans d'anciénneté")
df = df[(today - df['DATE_DEBUT']).dt.days > 3 * 365]
df.columns = ['Numéro employé', 'Nom', 'Prénom', 'Type du contrat', 'Date de début']
st.write("Liste des employés journaliers (question 2)")
st.dataframe(df[df['Type du contrat']==1])
st.write("Liste des employés par production")
st.dataframe(df[df['Type du contrat'] == 2])
else:
df.columns = ['Numéro employé', 'Nom', 'Prénom', 'Type du contrat', 'Date de début']
st.header("Liste de la totalité des employés")
st.write("Liste des employés journaliers")
st.dataframe(df[df['Type du contrat']==1])
st.write("Liste des employés par production")
st.dataframe(df[df['Type du contrat'] == 2])
with tab3:
st.header("Création de compte employé")
conn= sqlite3.connect(r'C:\Users\neiro\Documents\+\GitHub\sgbd-usine\donnees\company.db')
cursor = conn.cursor()
cursor.execute("SELECT MAX(NUMERO_EMPLOYE) FROM EMPLOYE")
max_numero_employe = cursor.fetchone()[0]
# Set the employee number to the next available number
NUMERO_EMPLOYE = max_numero_employe + 1 if max_numero_employe is not None else 1
# Employee type
# Employee name
NOM = st.text_input("Nom", value='')
# Employee first name
PRENOM = st.text_input("Prénom", value='')
TYPE = st.selectbox("Type de contrat", options=[1, 2], format_func=lambda x: "Journalier" if x == 1 else "Production", index=0)
# Conditional fields based on employee type
if TYPE == 2:
CS_PRODUCTION = st.number_input("Code salarial de production", min_value=1, step=1, value=None)
CS_JOURNEE = None
else:
CS_JOURNEE = st.number_input("Code salarial journalier", min_value=1, step=1, value=1)
CS_PRODUCTION = None
# Start date
date_debut = st.date_input("date de début", value=date(2024, 11, 13))
# Submit button
if st.button("Create Account"):
# Connect to the database
conn=sqlite3.connect(r'C:\Users\neiro\Documents\+\GitHub\sgbd-usine\donnees\company.db')
cursor = conn.cursor()
cursor.execute("""
SELECT NUMERO_EMPLOYE FROM EMPLOYE
WHERE NOM = ? AND PRENOM = ? AND DATE_DEBUT = ?
""", (NOM, PRENOM, date_debut))
existing_employee = cursor.fetchone()
if existing_employee:
st.write(f"Cet employé est déjà enregistré avec le numéro employé: {existing_employee[0]}")
conn.close()
else:
cursor.execute("""
INSERT INTO EMPLOYE (NUMERO_EMPLOYE, TYPE, NOM, PRENOM, CS_PRODUCTION, CS_JOURNEE, DATE_DEBUT)
VALUES (?, ?, ?, ?, ?, ?, ?)
""", (NUMERO_EMPLOYE, TYPE, NOM, PRENOM, CS_PRODUCTION if CS_PRODUCTION is not None else None, CS_JOURNEE if CS_JOURNEE is not None else None, date_debut))
# Commit the transaction
conn.commit()
st.write("Nouvel employé enregistré!")
st.write(f"Numéro employé: {NUMERO_EMPLOYE}")
st.write(f"Type de contrat: {'Journalier' if TYPE == 1 else 'Production'}")
st.write(f"Nom: {NOM}")
st.write(f"Prénom: {PRENOM}")
if TYPE == 2:
st.write(f"Code salarial de production: {CS_PRODUCTION}")
else:
st.write(f"code salarial journalier: {CS_JOURNEE}")
st.write(f"Date du début du contrat: {date_debut}")
conn.close()
st.stop()