瀏覽代碼

agrhum_traitement: partie 2 ok (presque)

emmanuel.pheulpin 7 年之前
父節點
當前提交
385ebf2881
共有 2 個文件被更改,包括 70 次插入10 次删除
  1. 61 1
      agrhum_traitement.py
  2. 9 9
      core/pde.py

+ 61 - 1
agrhum_traitement.py

@@ -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))
 

+ 9 - 9
core/pde.py

@@ -496,15 +496,15 @@ class HeureSupp(Model):
         self.JourRH = 0, int
         self.MoisRH = 0, int 
         self.AnneeRH = 0,int
-        self.HeureSup1 = 0, int
-        self.HeuresDep = 0, int
-        self.HeuresDepNuit = 0, int
-        self.HeureSup1Inf14 = 0, int
-        self.HeureSup1Sup14 = 0, int
-        self.HeureSupNuit = 0, int
-        self.HeureSupDim = 0, int
-        self.HS_VHCanal = 0, int
-        self.HS_Chantier = 0, int
+        self.HeureSup1 = 0.0, float
+        self.HeuresDep = 0.0, float
+        self.HeuresDepNuit = 0.0, float
+        self.HeureSup1Inf14 = 0.0, float
+        self.HeureSup1Sup14 = 0.0, float
+        self.HeureSupNuit = 0.0, float
+        self.HeureSupDim = 0.0, float
+        self.HS_VHCanal = 0.0, float
+        self.HS_Chantier = 0.0, float
         self.Valide = False,bool
         self.CreePar = "scriptauto", str
         self.CreeLe = datetime.now(), datetime