|
|
@@ -12,8 +12,8 @@ from path import Path # @UnusedImport
|
|
|
from core import logconf
|
|
|
from core.model import Sql
|
|
|
|
|
|
-logger = logging.getLogger("ctrl2analytique")
|
|
|
-logconf.start("ctrl2analytique", logging.DEBUG)
|
|
|
+#logger = logging.getLogger("ctrl2analytique")
|
|
|
+#logconf.start("ctrl2analytique", logging.DEBUG)
|
|
|
|
|
|
# # POUR TESTER, d�commenter les lignes suivantes
|
|
|
# > Lancer le script /resources/test_ctrl2analytique.py pour reinitialiser les donn�es de la base de test
|
|
|
@@ -41,56 +41,102 @@ AnneeRH = 2017
|
|
|
#Parcours de tbl_importRH transfo donnée et écriture dans tbl_formHS
|
|
|
|
|
|
def main():
|
|
|
- if agrhum_db.exists("select * from tbl_suiviRH where codeagent ='{}' and moisrh = {} and anneerh = {}".format(CodeAgent, MoisRH,AnneeRH)):
|
|
|
- #if input("Voulez vous retarite ces donnees(o/n)") != "o" :
|
|
|
- # print("Annulation")
|
|
|
- # return
|
|
|
- agrhum_db.execute("delete * from tbl_formDep where codeagent ='{}' and moisrh = {} and anneerh = {}".format(CodeAgent, MoisRH,AnneeRH))
|
|
|
- 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))
|
|
|
- sql = Sql.format("""SELECT
|
|
|
- tbl_baremes.NomBareme,
|
|
|
- tbl_baremes.BorneInf,
|
|
|
- tbl_baremes.BorneSup,
|
|
|
- tbl_baremes.Valeur,
|
|
|
- tbl_PeriodeBareme.DateInf,
|
|
|
- tbl_PeriodeBareme.DateSup
|
|
|
- FROM tbl_baremes
|
|
|
- INNER JOIN tbl_PeriodeBareme ON (tbl_baremes.PeriodeValidite = tbl_PeriodeBareme.CodePeriode) AND (tbl_baremes.NomBareme = tbl_PeriodeBareme.NomBareme)
|
|
|
- WHERE tbl_baremes.NomBareme = 'Heures de route'
|
|
|
- AND tbl_PeriodeBareme.DateInf <= {:date}
|
|
|
- AND (tbl_PeriodeBareme.DateSup is null or tbl_PeriodeBareme.DateSup > {:date}) """, datetime(AnneeRH,MoisRH,1), datetime(AnneeRH,MoisRH,1))
|
|
|
- baremes = agrhum_db.read_all(sql)
|
|
|
-
|
|
|
- index = {}
|
|
|
- for el in data :
|
|
|
- if not el.DateRH.day in index :
|
|
|
- fraisdep = FraisDeplacement()
|
|
|
- fraisdep.AnneeRH = AnneeRH
|
|
|
- fraisdep.CodeAgent = CodeAgent
|
|
|
- fraisdep.MoisRH = MoisRH
|
|
|
- fraisdep.JourRH = el.DateRH.day
|
|
|
- fraisdep.Depart = el.Depart
|
|
|
- # mettre a jour le codedepart
|
|
|
- fraisdep.Itineraire = " - ".join([loc for loc in (fraisdep.Depart, el.Localisation) if loc])
|
|
|
- fraisdep.Distance1_perso = int(el.DistanceTranche1) if el.VehiculePersoTranche1 == "True" else 0
|
|
|
- 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))
|
|
|
-
|
|
|
- with open(Path(r"%temp%\test.json").expandvars(), "w+") as f:
|
|
|
- f.write(str(index))
|
|
|
+ suivi = agrhum_db.first("select * from tbl_suiviRH where codeagent ='{}' and moisrh = {} and anneerh = {}".format(CodeAgent, MoisRH,AnneeRH))
|
|
|
+ if not suivi:
|
|
|
+ print("suivi manquant")
|
|
|
+ return
|
|
|
+
|
|
|
+ #if input("Voulez vous retarite ces donnees(o/n)") != "o" :
|
|
|
+ # print("Annulation")
|
|
|
+ # return
|
|
|
+
|
|
|
+
|
|
|
+ agrhum_db.execute("delete * from tbl_formDep where codeagent ='{}' and moisrh = {} and anneerh = {}".format(CodeAgent, MoisRH,AnneeRH))
|
|
|
+ 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))
|
|
|
+ sql = Sql.format("""SELECT
|
|
|
+ tbl_baremes.NomBareme,
|
|
|
+ tbl_baremes.BorneInf,
|
|
|
+ tbl_baremes.BorneSup,
|
|
|
+ tbl_baremes.Valeur,
|
|
|
+ tbl_PeriodeBareme.DateInf,
|
|
|
+ tbl_PeriodeBareme.DateSup
|
|
|
+ FROM tbl_baremes
|
|
|
+ INNER JOIN tbl_PeriodeBareme ON (tbl_baremes.PeriodeValidite = tbl_PeriodeBareme.CodePeriode) AND (tbl_baremes.NomBareme = tbl_PeriodeBareme.NomBareme)
|
|
|
+ WHERE tbl_baremes.NomBareme = 'Heures de route'
|
|
|
+ AND tbl_PeriodeBareme.DateInf <= {:date}
|
|
|
+ AND (tbl_PeriodeBareme.DateSup is null or tbl_PeriodeBareme.DateSup > {:date}) """, datetime(AnneeRH,MoisRH,1), datetime(AnneeRH,MoisRH,1))
|
|
|
+ baremes = agrhum_db.read_all(sql)
|
|
|
+
|
|
|
+ index = {}
|
|
|
+ for el in data :
|
|
|
+ if not el.DateRH.day in index :
|
|
|
+ fraisdep = FraisDeplacement()
|
|
|
+ fraisdep.IDSuivi = suivi.IDSuivi
|
|
|
+ fraisdep.AnneeRH = AnneeRH
|
|
|
+ fraisdep.CodeAgent = CodeAgent
|
|
|
+ fraisdep.MoisRH = MoisRH
|
|
|
+ fraisdep.JourRH = el.DateRH.day
|
|
|
+ fraisdep.Depart = el.Depart
|
|
|
+ # mettre a jour le codedepart
|
|
|
+ fraisdep.Itineraire = " - ".join([loc for loc in (fraisdep.Depart, el.Localisation) if loc])
|
|
|
+ fraisdep.Distance1_perso = int(el.DistanceTranche1) if el.VehiculePersoTranche1 == "True" else 0
|
|
|
+ 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,
|
|
|
+ MoisRH,
|
|
|
+ AnneeRH,
|
|
|
+ Depart,
|
|
|
+ Itineraire,
|
|
|
+ Distance2_perso,
|
|
|
+ Distance2_service,
|
|
|
+ Distance1_perso,
|
|
|
+ HeuresDep,
|
|
|
+ HeuresDepNuit,
|
|
|
+ Repas,
|
|
|
+ Remarque,
|
|
|
+ Valide,
|
|
|
+ CreePar,
|
|
|
+ CreeLe )
|
|
|
+ VALUES ({fraisdep.IDSuivi},
|
|
|
+ {fraisdep.CodeAgent:text},
|
|
|
+ {fraisdep.JourRH},
|
|
|
+ {fraisdep.MoisRH},
|
|
|
+ {fraisdep.AnneeRH},
|
|
|
+ {fraisdep.Depart:text},
|
|
|
+ {fraisdep.Itineraire:text},
|
|
|
+ {fraisdep.Distance2_perso},
|
|
|
+ {fraisdep.Distance2_service},
|
|
|
+ {fraisdep.Distance1_perso},
|
|
|
+ {fraisdep.HeuresDep},
|
|
|
+ {fraisdep.HeuresDepNuit},
|
|
|
+ {fraisdep.Repas},
|
|
|
+ {fraisdep.Remarque:text},
|
|
|
+ {fraisdep.Valide},
|
|
|
+ {fraisdep.CreePar:text},
|
|
|
+ {fraisdep.CreeLe:date})""",fraisdep = fraisdep)
|
|
|
+ agrhum_db.execute(sqlexec)
|
|
|
+
|
|
|
+ with open(Path(r"%temp%\test.json").expandvars(), "w+") as f:
|
|
|
+ f.write(str(index))
|
|
|
+
|
|
|
+ agrhum_db.commit()
|
|
|
|
|
|
|
|
|
|