secmi / utils /indemnites.py
tgey's picture
APP test
2145052
from typing import List
import streamlit as st
from utils.times import date_to_week_day, date_to_week_number
def calculate_indemnites_km(indem_vehicles: List[str] = ['Perso']) -> (float, float):
location = st.session_state.location
vehicule = st.session_state.vehicules
prestataire = st.session_state.df['affaire'][st.session_state.df['affaire']['affaire'] == st.session_state.affaire]['prestataire'].values[0]
if st.session_state.intervenant == '-' \
or st.session_state.client == '-' \
or location == 'En Atelier' \
or not vehicule in indem_vehicles:
return 0, 0
else:
secteur = st.session_state.df['intervenants'][st.session_state.df['intervenants']['intervenant'] == st.session_state.intervenant]['secteur'].values[0]
distance = st.session_state.df['Clients'][(st.session_state.df['Clients']['Nom client'] == st.session_state.client) & (st.session_state.df['Clients']['Prestataire'] == prestataire)][f'Dist {secteur}'].values[0]
duration = st.session_state.df['Clients'][(st.session_state.df['Clients']['Nom client'] == st.session_state.client) & (st.session_state.df['Clients']['Prestataire'] == prestataire)][f'Duration {secteur}'].values[0]
if distance * 2 < 35:
return 0, 0
indemnites = float(distance) * 2 * 0.35
drive_hours = float(duration) * 2
indemnites = round(indemnites, 2)
hours, minutes = divmod(drive_hours, 60)
return indemnites, hours + (minutes / 60)
def calculate_astreinte():
public_holyday = st.session_state.public_holyday
intervenant = st.session_state.intervenant
year = st.session_state.date_input.year
month = st.session_state.date_input.month
week = date_to_week_number(st.session_state.date_input)
if 'fit' in st.session_state.keys() and intervenant in st.session_state.fit.keys() and year in st.session_state.fit[intervenant].keys() and month in st.session_state.fit[intervenant][year].keys() and week in st.session_state.fit[intervenant][year][month].keys():
totals = st.session_state.fit[intervenant][year][month][week]['totals']
if totals['worked_hours'] >= st.session_state.contract_hours and st.session_state.contract_hours != 0:
if public_holyday:
return 321.0
return 321.0
return 0.0
def calculate_overtimes():
overtime25, overtime50, overtime100 = 0., 0., 0.
intervenant = st.session_state.intervenant
year = st.session_state.date_input.year
month = st.session_state.date_input.month
week = date_to_week_number(st.session_state.date_input)
weekday = date_to_week_day(st.session_state.date_input)
hour_price = st.session_state.df['intervenants'][st.session_state.df['intervenants']['intervenant'] == st.session_state.intervenant]['cout horaire'].values[0]
if 'fit' in st.session_state.keys() and intervenant in st.session_state.fit.keys() and year in st.session_state.fit[intervenant].keys() and month in st.session_state.fit[intervenant][year].keys() and week in st.session_state.fit[intervenant][year][month].keys():
week_hours = st.session_state.fit[intervenant][year][month][week]['totals']['worked_hours']
if st.session_state.contract_hours != 0 and st.session_state.contract_hours < week_hours:
overtime25 = max(0, min(8, week_hours - 35))
if st.session_state.contract_hours != 0 and week_hours >= 43:
overtime50 = (week_hours - 43)
if weekday == 'samedi':
overtime50 = st.session_state.total_hours
if weekday == 'dimanche' or st.session_state.public_holyday:
overtime100 = st.session_state.total_hours
return overtime25, overtime50, overtime100
def calculate_arrets():
secteur = st.session_state.df['intervenants'][st.session_state.df['intervenants']['intervenant'] == st.session_state.intervenant]['secteur'].values[0]
mask = st.session_state.df['absences'].applymap(lambda x: isinstance(x, str) and st.session_state.affaire.find(x) != -1)
mask = st.session_state.df['absences']['Libellé GTP2023'].apply(lambda x: st.session_state.affaire.find(x) != -1)
hr_code = st.session_state.df['absences'][mask]['Code_RH'].values[0]
contract_hours = st.session_state.contract_hours
if not contract_hours in [35., 37., 37.5, 39.]:
return 0
weekday = date_to_week_day(st.session_state.date_input)
weekday = 'JS_' if weekday != 'vendredi' else 'V_'
weekday = weekday if secteur == 'STE' else ''
am_values = st.session_state.df['arrets'][st.session_state.df['arrets']['code_absence'] == f'{hr_code}1_{weekday}{secteur}'][f'H-{float(contract_hours)}'].values
return am_values[0] if len(am_values) > 0 else 0