|
|
@@ -55,7 +55,7 @@ def main():
|
|
|
agrhum_db.execute("delete * from tbl_formHS where codeagent ='{}' and moisrh = {} and anneerh = {}".format(CodeAgent, MoisRH,AnneeRH))
|
|
|
|
|
|
|
|
|
- data = agrhum_db.read_all("select * from tbl_importrh where codeagent ='{}' and Month([daterh]) = {} and Year([daterh]) = {}".format(CodeAgent, MoisRH,AnneeRH))
|
|
|
+ data = agrhum_db.read_all("select * from tbl_importrh where codeagent ='{}' and Month([daterh]) = {} and Year([daterh]) = {} order by DateRH".format(CodeAgent, MoisRH,AnneeRH))
|
|
|
sql = Sql.format("""SELECT
|
|
|
tbl_baremes.NomBareme,
|
|
|
tbl_baremes.BorneInf,
|
|
|
@@ -71,6 +71,7 @@ def main():
|
|
|
baremes = agrhum_db.read_all(sql)
|
|
|
|
|
|
index = {}
|
|
|
+ indexHS ={}
|
|
|
for el in data :
|
|
|
if not el.DateRH.day in index :
|
|
|
fraisdep = FraisDeplacement()
|
|
|
@@ -86,17 +87,26 @@ def main():
|
|
|
fraisdep.Distance2_perso = int(el.DistanceTranche2) if el.VehiculePersoTranche2 == "True" else 0
|
|
|
fraisdep.Distance2_service = int(el.DistanceTranche2) if not el.VehiculePersoTranche2 == "True" else 0
|
|
|
fraisdep.Repas = int(el.Repas)
|
|
|
+
|
|
|
index[el.DateRH.day] = fraisdep
|
|
|
+
|
|
|
+
|
|
|
else :
|
|
|
index[el.DateRH.day].Itineraire += " - " + el.Localisation
|
|
|
index[el.DateRH.day].Distance1_perso += int(el.DistanceTranche1) if el.VehiculePersoTranche1 == "True" else 0
|
|
|
index[el.DateRH.day].Distance2_perso += int(el.DistanceTranche2) if el.VehiculePersoTranche2 == "True" else 0
|
|
|
index[el.DateRH.day].Distance2_service += int(el.DistanceTranche2) if not el.VehiculePersoTranche2 == "True" else 0
|
|
|
index[el.DateRH.day].Repas += int(el.Repas)
|
|
|
+
|
|
|
+
|
|
|
for fraisdep in index.values() :
|
|
|
distance2 = (fraisdep.Distance2_perso + fraisdep.Distance2_service)
|
|
|
fraisdep.HeuresDep = next((bareme.Valeur for bareme in baremes if bareme.BorneInf <= distance2 and bareme.BorneSup > distance2))
|
|
|
fraisdep.HeuresDepNuit = next((bareme.Valeur for bareme in baremes if bareme.BorneInf <= fraisdep.Distance1_perso and bareme.BorneSup > fraisdep.Distance1_perso))
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
sqlexec = Sql.format("""INSERT INTO tbl_FormDep ( IDSuivi,
|
|
|
CodeAgent,
|
|
|
JourRH,
|
|
|
@@ -131,8 +141,58 @@ def main():
|
|
|
{fraisdep.Valide},
|
|
|
{fraisdep.CreePar:text},
|
|
|
{fraisdep.CreeLe:date})""",fraisdep = fraisdep)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
agrhum_db.execute(sqlexec)
|
|
|
+
|
|
|
+ indexHS ={}
|
|
|
|
|
|
+ for el in data :
|
|
|
+ if not el.DateRH.day in indexHS :
|
|
|
+ hs = HeureSupp()
|
|
|
+ hs.IDSuivi = suivi.IDSuivi
|
|
|
+ hs.AnneeRH = AnneeRH
|
|
|
+ hs.CodeAgent = CodeAgent
|
|
|
+ hs.MoisRH = MoisRH
|
|
|
+ hs.JourRH = el.DateRH.day
|
|
|
+ hs.HeureSup1 = el.HeureSup1
|
|
|
+ hs.HeuresDep = index[el.DateRH.day].HeuresDep
|
|
|
+ hs.HeuresDepNuit = index[el.DateRH.day].HeuresDepNuit
|
|
|
+ hs.HeureSupNuit = float( el.HeureSup2) + hs.HeuresDepNuit
|
|
|
+ hs.HeureSupDim = el.HeureSupDimanche
|
|
|
+ hs.HS_VHCanal = float(el.HeureSup1) + float(el.HeureSup2) + float(el.HeureSupDimanche) if el.strCategorieInterventionId == "07" else 0.0
|
|
|
+ hs.HS_Chantier = float(el.HeureSup1) + float(el.HeureSup2) + float(el.HeureSupDimanche) if el.strCategorieInterventionId != "07" else 0.0
|
|
|
+
|
|
|
+ indexHS[el.DateRH.day] = hs
|
|
|
+ else :
|
|
|
+ indexHS[el.DateRH.day].HeureSup1 += float( el.HeureSup1)
|
|
|
+ indexHS[el.DateRH.day].HeureSupNuit += float( el.HeureSup2)
|
|
|
+ indexHS[el.DateRH.day].HeureSupDim += float( el.HeureSupDimanche)
|
|
|
+ indexHS[el.DateRH.day].HS_VHCanal += float(el.HeureSup1) + float(el.HeureSup2) + float(el.HeureSupDimanche) if el.strCategorieInterventionId == "07" else 0.0
|
|
|
+ indexHS[el.DateRH.day].HS_Chantier += float(el.HeureSup1) + float(el.HeureSup2) + float(el.HeureSupDimanche) if el.strCategorieInterventionId != "07" else 0.0
|
|
|
+
|
|
|
+ totalhs = 0.0
|
|
|
+ totalhsmois = 0.0
|
|
|
+
|
|
|
+ for hs in indexHS.values() :
|
|
|
+ totalhs = hs.HeureSup1 + hs.HeureSupNuit + hs.HeureSupDim
|
|
|
+ if totalhs + totalhsmois <= 14 :
|
|
|
+ hs.HeureSup1Inf14 = totalhs
|
|
|
+ elif totalhsmois >14 :
|
|
|
+ hs.HeureSup1Sup14 = totalhs
|
|
|
+ elif totalhs + totalhsmois > 14 :
|
|
|
+ hs.HeureSup1Inf14 = 14.0 - totalhsmois
|
|
|
+ hs.HeureSup1Sup14 = totalhs + totalhsmois -14.0
|
|
|
+
|
|
|
+ totalhsmois += totalhs
|
|
|
+
|
|
|
+ sqlexechs = Sql.format("""INSERT INTO tbl_FormHS ( IDSuivi, CodeAgent, JourRH, MoisRH, AnneeRH, HeureSup1, HeuresDep, HeuresDepNuit, [HeureSup1<=14], [HeureSup1>14], HeureSupNuit, HeureSupDim, HS_VHCanal, HS_Chantier, Valide, CreePar, CreeLe )
|
|
|
+VALUES ({hs.IDSuivi}, {hs.CodeAgent:text}, {hs.JourRH}, {hs.MoisRH}, {hs.AnneeRH}, {hs.HeureSup1}, {hs.HeuresDep}, {hs.HeuresDepNuit}, {hs.HeureSup1Inf14}, {hs.HeureSup1Sup14}, {hs.HeureSupNuit}, {hs.HeureSupDim}, {hs.HS_VHCanal}, {hs.HS_Chantier}, {hs.Valide}, {hs.CreePar:text}, {hs.CreeLe:date})
|
|
|
+""", hs = hs)
|
|
|
+
|
|
|
+ agrhum_db.execute(sqlexechs)
|
|
|
+
|
|
|
with open(Path(r"%temp%\test.json").expandvars(), "w+") as f:
|
|
|
f.write(str(index))
|
|
|
|