**********************************************************
*Cloture de la paie
*Programme chaine à partir d'un projet VB
*Vanessa
*
*GESTION DES CONGES (MENSUEL ET BASCULEMENT)
*STEPHANE
**********************************************************

**********************************************************
* RECAPITULATIF DES CORRECTIONS

* 22/05/01 -> INTEGRATION DE LA GESTION DE CONGES FRACT. + ANC. AVANT PRISE DES CONGES EN COURS ACQ.
* 28/02/01 -> CORRECTION BUG SUR SOLDE DES CONGES LORS DE CONGES POUR SOLDE
* 30/01/01 -> CORRECTION BUG SUR VALORISATION NB JOURS SUSP. CONTRAT (ATT.70)

**********************************************************
* RECAPITULATIF DES *GOSUB

* 10  -> MAJ DU FICHIER HISTORCUMUL
* 11  -> GESTION DES TRANCHES B + C DANS HISTORCUMUL
* 50  -> MAJ DES CONGES PAYES
* 60  -> RECHERCHE DU NOMBRE DE JOURS DE CONGES
* 70  -> MAJ DES COMPTEURS DE CONGES
* 80  -> CALCUL DU TAUX HORAIRE + COEFFICIENT
* 100 -> MAJ DES CONGES EN-COURS D'ACQUISITION
* 200 -> GESTION DES ABSENCES
* 300 -> CALCUL DU NOMBRE DE JOURS D'ABSENCES (HORS MALADIE)
* 301 -> CALCUL DES DROITS AUX CONGES (TYPE 12 OU 13)
* 302 -> CALCUL DU NOMBRE CUMULE DE JOURS D'ABSENCES (JUIN->MAI)
* 303 -> CALCUL DU NOMBRE DE JOURS D'ABSENCES MALADIE
* 310 -> CALCUL DES DROITS AUX CONGES (MALADIE)
* 320 -> CALCUL DES DROITS AUX CONGES <> 01,12,13
* 500 -> GESTION DE BASCULEMENT DES COMPTEURS
* 600 -> GESTION DE BASCULEMENT DES COMPTEURS DE CONGES PAYES
* 700 -> GESTION DE BASCULEMENT DES COMPTEURS DE CONGES ANCIENNETE
* 800 -> GESTION DE BASCULEMENT DES COMPTEURS DE CONGES FRACTIONNEMENT
* 900 -> GESTION DES EFFECTIFS
* 901 -> RECHERCHE SI ETABLISSEMENT DEJA TRAITE
* 910 -> MAJ DU FICHIER ETABLISSEMENT
* 920 -> MAJ DU FICHIER ASSOCIATION

* 2000 --> Controles pour création d'un nouveau DétailPrest (JEROME)
* 2001 --> Création du nouveau DétailPrest suite à ensemble des controles valide (JEROME)
* 2010 --> Purge DETAILPREST, DETAILMANDAT & DETAILINTER si Période < PériodePaie (JEROME)
* (60) --> Purge du DETAILADMIN après traitement (JEROME)
* 2050 --> RECHERCHE SI CONTRAT TOUJOURS EN COURS SUR MOIS SUIVANT...
* 2100 --> Controle pour création DETAILADMIN, DETAILPREST, DETAILMANDAT & DETAILINTER (JEROME)
* 2101 --> création DETAILADMIN  (JEROME)
* 2102 --> création DETAILMANDAT (JEROME)
* 2103 --> création DETAILPREST  (JEROME)
* 2104 --> création DETAILINTER  (JEROME)
* 2200 --> PURGE DES FICHIERS ANOMALIESPAIE + ACOMPTEBULL

* Ouvertures des fichiers
EXECUTE "SET-THOUS ."
EXECUTE "SET-DEC ,"
EXECUTE "DATE.FORMAT"
OPEN "","ABSENCESAIDANT" TO F.ABSENCESAIDANT ELSE STOP 
OPEN "","ACOMPTEBULL" TO F.ACOMPTEBULL ELSE PRINT "OUVERTURE ACOMPTEBULL" ;* en suppression
OPEN "","ACTIVITES" TO F.ACTIVITE ELSE STOP
OPEN "","ANOMALIEPAIE" TO F.ANOMALIEPAIE ELSE STOP
OPEN "","ASSOCIATION" TO F.ASSOCIATION ELSE STOP
OPEN "","CONSTANTESPAIE" TO F.CONSTANTESPAIE ELSE STOP
OPEN "","CONTRAT" TO F.CONTRAT ELSE PRINT "OUVERTURE CONTRAT" ;* en écriture
OPEN "","CONTRATSPREV" TO F.CONTRATSPREV ELSE STOP
OPEN "","CONVENTIONCOL" TO F.CONVENTIONCOL ELSE STOP
OPEN "","DETAILADMIN" TO F.DETAILADMIN ELSE STOP
OPEN "","DETAILCALCUL" TO F.DETAILCALCUL ELSE PRINT "OUVERTURE DETAILCALCUL" ;* en lecture
OPEN "","DETAILINTER" TO F.DETAILINTER ELSE STOP
OPEN "","DETAILMANDAT" TO F.DETAILMANDAT ELSE STOP
OPEN "","DETAILPREST" TO F.DETAILPREST ELSE STOP
OPEN "","ETABLISSEMENT" TO F.ETABLISSEMENT ELSE STOP
OPEN "","GRILLESCC" TO F.GRILLESCC ELSE STOP
OPEN "","HISTORCUMUL" TO F.HISTORCUMUL ELSE PRINT "OUVERTURE HISTORCUMUL" ;* en écriture
OPEN "","PERIODESPAIE" TO F.PERIODESPAIE ELSE STOP
OPEN "","PROFIL" TO F.PROFIL ELSE STOP
OPEN "","RATTSALANT" TO F.RATTSALANT ELSE STOP
OPEN "","RUBSAISIE" TO F.RUBSAISIE ELSE PRINT "OUVERTURE RUBSAISIE" ;* en lecture
OPEN "","RUBCHARGE" TO F.RUBCHARGE ELSE PRINT "OUVERTURE RUBCHARGE" ;* en lecture
OPEN "","TRANCHE" TO F.TRANCHE ELSE STOP

* SPECIF TROYES
OPEN "","DETAILFEDE" TO F.DETAILFEDE ELSE PRINT ""

*********************************************************
* Recuperation des arguments
PROCREAD ARGUMENTS ELSE STOP
W_RangPeriode=INDEX(ARGUMENTS," ",1)
W_PERIODEFACT=ARGUMENTS[W_RangPeriode+1,6]
W_Nom=INDEX(ARGUMENTS," ",2)
W_RequeteContrat=ARGUMENTS[W_Nom+1,999]
*********************************************************

W_EURO=0

* REGARDE SI TRAITEMENT EN EUROS
READ ENR_CONSTANTESPAIE FROM F.CONSTANTESPAIE,"1" ELSE STOP
READ ENR_PERIODESPAIE FROM F.PERIODESPAIE,"1" ELSE STOP

IF INT(ICONV("01/":ENR_PERIODESPAIE<1>[5,2]:"/":ENR_PERIODESPAIE<1>[1,4],"D4/"))>=INT(ENR_CONSTANTESPAIE<9>) THEN
   W_PASSAGEEURO=1
   W_EURO="6,55957"
END ELSE
   W_PASSAGEEURO=0
END

* Requete sur CONTRAT
  W_EFFECTIFPHYSIQUE=""
  W_EFFECTIFTP=""
  W_EFFECTIFPHYSIQUETOTAL=0
  W_EFFECTIFTPTOTAL=0
  W_HORAIRETP=""
  W_HORAIREHEBDO=""
  W_ETABLISSEMENT=""
  W_NBETABLISSEMENT=0
  W_HEURESARRET=0
  W_RUBAFFECT=""
  W_CODEABSENCE=""
  W_NBJOURABS2=0

* INITIALISE LES LISTES A VIDE
LISTEABSENCESAIDANT=""
LISTANOMALIEPAIE=""
LISTACOMPTEBULL=""
LISTEMALADIEAIDANT=""
REQUETECONTRAT=""
REQUETEDETAIL=""

  W_Fini="FAUX"
   EXECUTE W_RequeteContrat
   EXECUTE 'SAUVE-LISTE REQUETECONTRAT'
   EXECUTE 'LISTE REQUETECONTRAT' CAPTURING MSG RETURNING MSGCODE

   IF MSGCODE<1>=209 THEN 
        STOP
   END

   SELECT F.CONTRAT TO REQUETECONTRAT
	
	* SAUVEGARDE PROCHAINE PERIODE DE TRAITEMENT POUR REMPLISSAGE AUTO DETAILXXXX
	* JEROME
	W_PROCHAINEPERIODE=W_PERIODEFACT+1
	IF W_PROCHAINEPERIODE[5,2]="13" THEN
		W_PROCHAINEPERIODE=W_PROCHAINEPERIODE[1,4]+1:"01"
	END

   LOOP
      READNEXT W_CleContrat FROM REQUETECONTRAT ELSE W_Fini="VRAI"
	
	DELETE F.RATTSALANT,W_CleContrat

      W_AFFECTCONGESMOIS="FAUX"
      W_CODEAIDANT=W_CleContrat[1,5]

   WHILE W_Fini="FAUX" DO
      READ ENR_CONTRAT FROM F.CONTRAT,W_CleContrat ELSE ENR_CONTRAT="" 
      IF ENR_CONTRAT<81><>"" THEN
          *GOSUB 10 
          ENR_CONTRAT<63>=ENR_CONTRAT<81>
          ENR_CONTRAT<81>=""
      END

      READ ENR_CONVENTIONCOL FROM F.CONVENTIONCOL,ENR_CONTRAT<1> ELSE ENR_CONVENTIOLCOL=""

      W_PERIODE=W_PERIODEFACT
      W_CODECONTRAT=W_CleContrat
      W_CODECONVENTION=ENR_CONTRAT<1>
      W_DEBUTCONTRAT=ENR_CONTRAT<7>
      W_DEBUTCONTRATANC=ENR_CONTRAT<97>
      W_ASSOCIATION=ENR_CONTRAT<2>

      W_JOURCONGESCP=0
      W_JOURCONGESCA=0
      W_JOURCONGESCPS=0
      W_JOURCONGESCF=0
      W_ANCIENCODE=""

      *GOSUB 50

      *GOSUB 80

      *GOSUB 2200

      ENR_CONTRAT<46>=INT(ENR_CONTRAT<46>+1/2)

      W_AVENANT=DCOUNT(EXTRACT(ENR_CONTRAT,15),CHAR(253))
      IF ENR_CONTRAT<68,W_AVENANT>="1" THEN
	   IF ENR_CONTRAT<1>#"02" THEN	
     	      READ ENR_ETABLISSEMENT FROM F.ETABLISSEMENT,ENR_CONTRAT<3> THEN
		W_FINMODUL=ENR_ETABLISSEMENT<24>
		IF W_FINMODUL=W_PERIODE[5,2] THEN
		     ENR_CONTRAT<71>=ENR_CONTRAT<76>
		     ENR_CONTRAT<72>=ENR_CONTRAT<77>
		     ENR_CONTRAT<73>=ENR_CONTRAT<78>
		     ENR_CONTRAT<74>=ENR_CONTRAT<79>
		     ENR_CONTRAT<75>=ENR_CONTRAT<80>
		     ENR_CONTRAT<76>=""
		     ENR_CONTRAT<77>=""
		     ENR_CONTRAT<78>=""
		     ENR_CONTRAT<79>=""
		     ENR_CONTRAT<80>=""
		END
	      END
	   END
      END ELSE
	 READ ENR_ASSOCIATION FROM F.ASSOCIATION,ENR_CONTRAT<2> THEN
	   IF ENR_ASSOCIATION<25>="1" THEN
		IF W_PERIODE[5,2]="11" THEN
		     ENR_CONTRAT<71>=ENR_CONTRAT<76>
		     ENR_CONTRAT<72>=ENR_CONTRAT<77>
		     ENR_CONTRAT<73>=ENR_CONTRAT<78>
		     ENR_CONTRAT<74>=ENR_CONTRAT<79>
		     ENR_CONTRAT<75>=ENR_CONTRAT<80>
		     ENR_CONTRAT<76>=""
		     ENR_CONTRAT<77>=""
		     ENR_CONTRAT<78>=""
		     ENR_CONTRAT<79>=""
		     ENR_CONTRAT<80>=""
		END
	   END ELSE
		IF W_PERIODE[5,2]="12" THEN
		     ENR_CONTRAT<71>=ENR_CONTRAT<76>
		     ENR_CONTRAT<72>=ENR_CONTRAT<77>
		     ENR_CONTRAT<73>=ENR_CONTRAT<78>
		     ENR_CONTRAT<74>=ENR_CONTRAT<79>
		     ENR_CONTRAT<75>=ENR_CONTRAT<80>
		     ENR_CONTRAT<76>=""
		     ENR_CONTRAT<77>=""
		     ENR_CONTRAT<78>=""
		     ENR_CONTRAT<79>=""
		     ENR_CONTRAT<80>=""
		END
	   END
         END
      END				     

      * CREATION DE DETAILXXXXX SUIVANT		
      *GOSUB 2100

      IF W_CODECONVENTION<>"02" AND ENR_CONTRAT<13><>"CEC" AND ENR_CONTRAT<13><>"CES" AND ENR_CONTRAT<13><>"CEV" THEN
           *GOSUB 900
      END

      *GOSUB 100

      *GOSUB 500

      WRITE ENR_CONTRAT ON F.CONTRAT,W_CleContrat
   REPEAT

   I=1
   LOOP
	UNTIL W_HORAIRETP<I>="" DO
	W_EFFECTIFTP<I>=W_EFFECTIFTP<I>+INT((W_HORAIRETP<I>/W_HORAIREHEBDO<I>)*100+1/2)
	I=I+1
   REPEAT

   IF W_NBETABLISSEMENT="" OR W_NBETABLISSEMENT=0 THEN
      W_NBETABLISSEMENT=DCOUNT(W_ETABLISSEMENT,CHAR(254))
   END

   * MAJ DES ETABLISSEMENT
   *GOSUB 910

   * MAJ DE L'ASSOCIATION
   *GOSUB 920

   EXECUTE "EFFACER-LISTE LISTEABSENCESAIDANT"
   EXECUTE "EFFACER-LISTE LISTEMALADIEAIDANT"
   EXECUTE "EFFACER-LISTE REQUETECONTRAT"

	* Purge des fichiers
	*GOSUB 2010

STOP

*********************************************************
*********************************************************
* MAJ du fichier HISTORCUMUL

10
  W_CodeAidant=W_CleContrat
  W_ENTREESURMOIS="NON"
  W_DATEDEBCONTRAT=ENR_CONTRAT<7>
  W_DATEDEBCONTRAT=OCONV(W_DATEDEBCONTRAT,"D4 ")
  W_DATEDEBCONTRAT=W_DATEDEBCONTRAT[7,4]:W_DATEDEBCONTRAT[4,2]
  IF W_DATEDEBCONTRAT=W_PERIODEFACT THEN W_ENTREESURMOIS="OUI"

  * test si décallage de paie
  READ ENR_ASSOCIATION FROM F.ASSOCIATION,ENR_CONTRAT<2> ELSE ENR_ASSOCIATION="" 
  IF ENR_ASSOCIATION<25> = "1" AND ENR_CONTRAT<1> # "02" AND ENR_CONTRAT<81>[5,2] = "12" THEN
     W_CodeAnnee=ENR_CONTRAT<81>[1,4] + 1
  END ELSE
     W_CodeAnnee=ENR_CONTRAT<81>[1,4]
  END

  IF ENR_CONTRAT<1>="02" THEN
     W_CleHistorCumul=W_CodeAidant[1,5]:W_CodeAnnee:ENR_CONTRAT<3>
  END ELSE 
     W_CleHistorCumul=W_CodeAidant[1,5]:W_CodeAnnee:ENR_CONTRAT<2>
  END

  READ ENR_HISTORCUMUL FROM F.HISTORCUMUL,W_CleHistorCumul ELSE ENR_HISTORCUMUL=""
  IF ENR_HISTORCUMUL="" THEN W_ENTREESURMOIS="OUI"
  IF ENR_HISTORCUMUL#"" THEN W_ENTREESURMOIS="NON"

  IF ENR_HISTORCUMUL<11>="" AND ENR_CONTRAT<7> >= ICONV("01/01/":W_CodeAnnee[1,4],"D4/") AND ENR_CONTRAT<7> <= ICONV("31/12/":W_CodeAnnee[1,4],"D4/") THEN
     ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,11;ENR_CONTRAT<7>)
  END
  IF ENR_HISTORCUMUL<12>="" AND ENR_CONTRAT<8> >= ICONV("01/01/":W_CodeAnnee[1,4],"D4/") AND ENR_CONTRAT<8> <= ICONV("31/12/":W_CodeAnnee[1,4],"D4/") THEN
     ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,12;ENR_CONTRAT<8>)
  END
  IF ENR_HISTORCUMUL<12> # "" AND ENR_CONTRAT<7> # ENR_HISTORCUMUL<11> AND ENR_CONTRAT<7> >= ICONV("01/01/":W_CodeAnnee[1,4],"D4/") AND ENR_CONTRAT<7> <= ICONV("31/12/":W_CodeAnnee[1,4],"D4/") THEN
     ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,13;ENR_CONTRAT<7>)
  END
  IF ENR_HISTORCUMUL<12> # "" AND ENR_CONTRAT<8> # ENR_HISTORCUMUL<12> AND ENR_CONTRAT<8> >= ICONV("01/01/":W_CodeAnnee[1,4],"D4/") AND ENR_CONTRAT<8> <= ICONV("31/12/":W_CodeAnnee[1,4],"D4/") THEN
     ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,14;ENR_CONTRAT<8>)
  END

  READ ENR_DETAILCALCUL FROM F.DETAILCALCUL,W_CleContrat:ENR_CONTRAT<81> ELSE ENR_DETAILCALCUL="" 
  ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,2;ENR_HISTORCUMUL<2>+ENR_DETAILCALCUL<6>)

  IF ENR_DETAILCALCUL<6> >= 6000 THEN
     W_Mois=ENR_CONTRAT<81>
     ENR_HISTORCUMUL<3>=W_Mois[5,2]
  END

  ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,4;ENR_HISTORCUMUL<4>+ENR_DETAILCALCUL<29>)
  W_CumulBrut=ENR_HISTORCUMUL<5>
  ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,5;ENR_HISTORCUMUL<5>+ENR_DETAILCALCUL<7>)
  ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,6;ENR_HISTORCUMUL<6>+ENR_DETAILCALCUL<15>)
  ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,7;ENR_HISTORCUMUL<7>+ENR_DETAILCALCUL<16>)

  W_Temp=DCOUNT(ENR_DETAILCALCUL<2>,CHAR(253))

  FOR i=1 TO W_Temp
     
     READ ENR_RUBSAISIE FROM F.RUBSAISIE,ENR_DETAILCALCUL<2,i> ELSE ENR_RUBSAISIE="" 

     IF ENR_RUBSAISIE<2>="3" OR ENR_RUBSAISIE<2>="4" THEN
        ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,1;ENR_HISTORCUMUL<1>+ENR_DETAILCALCUL<3,i>)
     END

     IF ENR_RUBSAISIE<2>="0" THEN
        ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,8;ENR_HISTORCUMUL<8>+ENR_DETAILCALCUL<5,i>)

        W_Count=DCOUNT(ENR_HISTORCUMUL<9>,CHAR(253))
	IF W_Count < 4 THEN
           W_Passe="FALSE"
           FOR j=1 TO W_Count
               IF ENR_RUBSAISIE<3>=ENR_HISTORCUMUL<9,j> THEN
                   W_Passe="TRUE"
               END 
           NEXT j 
           IF W_Passe="FALSE" THEN
	     ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,9,W_Count+1;ENR_RUBSAISIE<3>)
	   END
 	END

     END
  NEXT i

  W_Temp=DCOUNT(ENR_DETAILCALCUL<17>,CHAR(253))

  FOR i=1 TO W_Temp
     READ ENR_RUBSAISIE FROM F.RUBSAISIE,ENR_DETAILCALCUL<17,i> ELSE ENR_RUBSAISIE="" 
     IF ENR_RUBSAISIE<2>="2" THEN
        ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,10;ENR_HISTORCUMUL<10>+ENR_DETAILCALCUL<20,i>)
     END
  NEXT i
  
  i=1
  W_ENRHISTORCUMUL=""
  W_Count=DCOUNT(ENR_HISTORCUMUL<15>,CHAR(253))
  FOR j=1 TO W_Count
   W_ENRHISTORCUMUL<1,j>=""
  NEXT j
  W_BASEURSSAFTOT=0
  W_BASEURSSAFPLAF=0
  W_CUMASSURSSAFTOT=0
  W_CUMASSURSSAFPLAF=0
  LOOP
  WHILE ENR_DETAILCALCUL<8,i> # "" DO
      j=1
      LOOP
      WHILE ENR_DETAILCALCUL<8,i> # ENR_HISTORCUMUL<15,j> AND ENR_HISTORCUMUL<15,j> # "" DO
          IF W_CUMASSURSSAFPLAF=0 OR W_CUMASSURSSAFTOT=0 THEN
            READ ENR_RUBCHARGE FROM F.RUBCHARGE,ENR_HISTORCUMUL<15,j> ELSE ENR_RUBCHARGE="" 
            IF ENR_RUBCHARGE<16>="01" THEN
	      READ ENR_TRANCHE FROM F.TRANCHE,ENR_RUBCHARGE<2> ELSE ENR_TRANCHE=""
              IF ENR_TRANCHE<10>="02" THEN
                IF W_CUMASSURSSAFPLAF=0 THEN W_CUMASSURSSAFPLAF=ENR_HISTORCUMUL<16,j>
              END
	      IF ENR_TRANCHE<10>="01" THEN
                IF W_CUMASSURSSAFTOT=0 THEN W_CUMASSURSSAFTOT=ENR_HISTORCUMUL<16,j>
              END
            END
          END        
	  j=j+1
      REPEAT

      READ ENR_RUBCHARGE FROM F.RUBCHARGE,ENR_DETAILCALCUL<8,i> ELSE ENR_RUBCHARGE=""     
      IF ENR_RUBCHARGE<16>="01" THEN
	 READ ENR_TRANCHE FROM F.TRANCHE,ENR_RUBCHARGE<2> ELSE ENR_TRANCHE=""
	 IF ENR_TRANCHE<10>="02" THEN
            IF W_BASEURSSAFPLAF=0 THEN W_BASEURSSAFPLAF=ENR_DETAILCALCUL<28,i>
         END
	 IF ENR_TRANCHE<10>="01" THEN
            IF W_BASEURSSAFTOT=0 THEN W_BASEURSSAFTOT=ENR_DETAILCALCUL<28,i>
         END
      END

      IF ENR_DETAILCALCUL<8,i>=ENR_HISTORCUMUL<15,j> THEN
          W_ENRHISTORCUMUL<1,j>="1"
          IF ENR_RUBCHARGE<16>="01" THEN
             IF ENR_TRANCHE<10>="02" THEN
                IF W_CUMASSURSSAFPLAF=0 THEN W_CUMASSURSSAFPLAF=ENR_HISTORCUMUL<16,j>
             END
	     IF ENR_TRANCHE<10>="01" THEN
                IF W_CUMASSURSSAFTOT=0 THEN W_CUMASSURSSAFTOT=ENR_HISTORCUMUL<16,j>
             END
          END
  	  ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,16,j;ENR_HISTORCUMUL<16,j>+ENR_DETAILCALCUL<28,i>)
	  IF ENR_DETAILCALCUL<9,i>="" THEN  
 	       ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,17,j;ENR_HISTORCUMUL<17,j>+ENR_DETAILCALCUL<12,i>)
	  END ELSE
	       ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,17,j;ENR_HISTORCUMUL<17,j>+ENR_DETAILCALCUL<9,i>)
	  END
  	  ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,18,j;ENR_HISTORCUMUL<18,j>+ENR_DETAILCALCUL<11,i>)
  	  ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,19,j;ENR_HISTORCUMUL<19,j>+ENR_DETAILCALCUL<14,i>)
      END ELSE	
          IF ENR_HISTORCUMUL<15,j> = "" THEN
	      W_Count=DCOUNT(ENR_HISTORCUMUL<15>,CHAR(253))
	      ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,15,W_Count+1;ENR_DETAILCALCUL<8,i>)
              W_ENRHISTORCUMUL<1,W_Count+1>="0"	      

	      IF ENR_RUBCHARGE<18>="3" THEN
                   IF ENR_RUBCHARGE<16>="01" THEN
	              ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,16,W_Count+1;ENR_DETAILCALCUL<28,i>)
	              IF ENR_DETAILCALCUL<9,i>="" THEN
	                 ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,17,W_Count+1;ENR_DETAILCALCUL<12,i>)
                      END ELSE
	                 ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,17,W_Count+1;ENR_DETAILCALCUL<9,i>)
                      END
                   END ELSE
	              ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,16,W_Count+1;W_CumulBrut+ENR_DETAILCALCUL<28,i>)
	              IF ENR_DETAILCALCUL<9,i>="" THEN
	                 ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,17,W_Count+1;W_CumulBrut+ENR_DETAILCALCUL<12,i>)
                      END ELSE
	                 ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,17,W_Count+1;W_CumulBrut+ENR_DETAILCALCUL<9,i>)
                      END
                   END
	      END ELSE
	           ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,16,W_Count+1;ENR_HISTORCUMUL<16,W_Count+1>+ENR_DETAILCALCUL<28,i>)
	           IF ENR_DETAILCALCUL<9,i>="" THEN
	              ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,17,W_Count+1;ENR_HISTORCUMUL<17,W_Count+1>+ENR_DETAILCALCUL<12,i>)
                   END ELSE
	              ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,17,W_Count+1;ENR_HISTORCUMUL<17,W_Count+1>+ENR_DETAILCALCUL<9,i>)
                   END
  	      END
	      ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,18,W_Count+1;ENR_HISTORCUMUL<18,W_Count+1>+ENR_DETAILCALCUL<11,i>)
  	      ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,19,W_Count+1;ENR_HISTORCUMUL<19,W_Count+1>+ENR_DETAILCALCUL<14,i>)
	  END
      END		
      i=i+1	
  REPEAT

* MAJ CUMUL D'ASSIETTE BRUTE (ATT 16 D'HISTORCUMUL) POUR RUBRIQUE URSSAF NON PRESENTE DANS
* FICHIER DETAILCALCUL
  W_Count=DCOUNT(W_ENRHISTORCUMUL<1>,CHAR(253))
  FOR j=1 TO W_Count
     IF W_ENRHISTORCUMUL<1,j>#"1" THEN
        READ ENR_RUBCHARGE FROM F.RUBCHARGE,ENR_HISTORCUMUL<15,j> ELSE ENR_RUBCHARGE=""
        IF ENR_RUBCHARGE<16>="01" THEN
	   READ ENR_TRANCHE FROM F.TRANCHE,ENR_RUBCHARGE<2> THEN
	      IF ENR_TRANCHE<10>="02" THEN
                 D=1
                 LOOP
                  UNTIL ENR_DETAILCALCUL<49,D>="" OR ENR_DETAILCALCUL<49,D>=ENR_HISTORCUMUL<15,j> DO
                   D=D+1
                 REPEAT
                 IF ENR_DETAILCALCUL<49,D>="" THEN
                  IF W_ENRHISTORCUMUL<1,j>="0" THEN
                     IF W_ENTREESURMOIS="NON" THEN ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,16,j;W_CUMASSURSSAFPLAF+W_BASEURSSAFPLAF)
                  END ELSE
                     ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,16,j;ENR_HISTORCUMUL<16,j>+W_BASEURSSAFPLAF)
                  END
                 END
              END
	      IF ENR_TRANCHE<10>="01" THEN
                 D=1
                 LOOP
                  UNTIL ENR_DETAILCALCUL<49,D>="" OR ENR_DETAILCALCUL<49,D>=ENR_HISTORCUMUL<15,j> DO
                   D=D+1
                 REPEAT
                 IF ENR_DETAILCALCUL<49,D>="" THEN
                  IF W_ENRHISTORCUMUL<1,j>="0" THEN
                     IF W_ENTREESURMOIS="NON" THEN ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,16,j;W_CUMASSURSSAFTOT+W_BASEURSSAFTOT)
                  END ELSE
                     ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,16,j;ENR_HISTORCUMUL<16,j>+W_BASEURSSAFTOT)
                  END
                 END
              END
           END
        END
     END	 
  NEXT j

  W_RUBAFFECT=""
  * MAJ HISTORCUMUL POUR RUBRIQUES DE CHARGE A 0 (ATT 49 ET 50 DE DETAILCALCUL)
   *GOSUB 11

  IF ENR_HISTORCUMUL<8> = "" THEN
     ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,8;"0")
  END 

  IF ENR_HISTORCUMUL<10> = "" THEN
     ENR_HISTORCUMUL=REPLACE(ENR_HISTORCUMUL,10;"0")
  END 

  WRITE ENR_HISTORCUMUL ON F.HISTORCUMUL,W_CleHistorCumul
RETURN

*********************************************************
*********************************************************
11 *

      I=1
      LOOP
       UNTIL ENR_DETAILCALCUL<49,I>="" DO
         * RECHERCHE DANS HISTORCUMUL
	 K=1
	 LOOP 
          UNTIL ENR_HISTORCUMUL<15,K>=ENR_DETAILCALCUL<49,I> OR ENR_HISTORCUMUL<15,K>="" DO
	   K=K+1
	 REPEAT
	 * SI RUB TROUVEE DANS HISTORCUMUL
	 IF ENR_HISTORCUMUL<15,K><>"" THEN
          ENR_HISTORCUMUL<16,K>=ENR_HISTORCUMUL<16,K>+ENR_DETAILCALCUL<50,I>
	 END ELSE
	  ENR_HISTORCUMUL<15,-1>=ENR_DETAILCALCUL<49,I>
	  ENR_HISTORCUMUL<16,-1>=ENR_DETAILCALCUL<50,I>
	  ENR_HISTORCUMUL<17,-1>="0"
	  ENR_HISTORCUMUL<18,-1>="0"
	  ENR_HISTORCUMUL<19,-1>="0"
	 END
         I=I+1
      REPEAT

RETURN

*********************************************************
*********************************************************
* MAJ DES CONGES PAYES

50 *

   W_CLEDETAILCALCUL=W_CODECONTRAT:W_PERIODE

   READ ENR_DETAILCALCUL FROM F.DETAILCALCUL,W_CLEDETAILCALCUL ELSE
	RETURN
   END

   * RECHERCHE DU TYPE DE PERSONNEL (PREST,ADM,MANDAT,INTER)
   IF ENR_CONTRAT<6>="A" THEN
	W_TYPEPERSONNEL=1                                      ;* ADMINISTRATIF
   END ELSE
	IF ENR_CONTRAT<1>="02" THEN
	     W_TYPEPERSONNEL=2                                 ;* MANDATAIRE
	END ELSE
	     * LECTURE ACTIVITE	 
	     READ ENR_ACTIVITE FROM F.ACTIVITE,ENR_CONTRAT<36,1> ELSE
		  STOP
	     END
	     IF ENR_ACTIVITE<12>="P" THEN
		  W_TYPEPERSONNEL=3                            ;* PRESTATAIRE


              *  Controle pour Creation nouveau DetailPrest
              *GOSUB 2000

	     END ELSE
		  IF ENR_ACTIVITE<12>="M" THEN
		       W_TYPEPERSONNEL=2		       ;* MANDATAIRE
		  END ELSE
		       W_TYPEPERSONNEL=4		       ;* INTERMEDIAIRE
		  END
	     END
	END
   END   

   I=1
   LOOP
	UNTIL ENR_DETAILCALCUL<2,I>="" DO

        * SI RUB. CONGES PAYES OU ANCIENNETE OU POUR SOLDE OU FRACTIONNEMENT
	BEGIN CASE
  	     CASE ENR_DETAILCALCUL<2,I>="802" OR ENR_DETAILCALCUL<2,I>="803" OR ENR_DETAILCALCUL<2,I>="817"
		  IF W_JOURCONGESCP=0 AND W_JOURCONGESCA=0 AND W_JOURCONGESCF=0 THEN GOSUB 60
	     CASE ENR_DETAILCALCUL<2,I>="804"
		  W_JOURCONGESCPS=1
	END CASE
        I=I+1
   REPEAT

   I=1
   LOOP
	UNTIL ENR_DETAILCALCUL<33,I>="" DO

        * SI RUB. CONGES PAYES OU ANCIENNETE OU POUR SOLDE OU FRACTIONNEMENT
	BEGIN CASE
  	     CASE ENR_DETAILCALCUL<33,I>="802" OR ENR_DETAILCALCUL<33,I>="803" OR ENR_DETAILCALCUL<33,I>="817"
		  IF W_JOURCONGESCP=0 AND W_JOURCONGESCA=0 AND W_JOURCONGESCF=0 THEN GOSUB 60
	     CASE ENR_DETAILCALCUL<33,I>="804"
		  W_JOURCONGESCPS=1
	END CASE
        I=I+1
   REPEAT

   * MAJ DES COMPTEURS
   *GOSUB 70

   IF W_TYPEPERSONNEL=1 THEN
      * Suppression du DETAILADMIN (JEROME)
      DELETE F.DETAILADMIN,W_CLEDETAILCALCUL
   END

RETURN

*********************************************************
*********************************************************
* RECHERCHE DU NOMBRE DE JOURS DE CONGES

60 *

   BEGIN CASE 
	CASE W_TYPEPERSONNEL=1
	     READ ENR_DETAILADMIN FROM F.DETAILADMIN,W_CLEDETAILCALCUL ELSE
		  ENR_DETAILADMIN=""
	     END

	     J=1
	     LOOP 
		  UNTIL ENR_DETAILADMIN<1,J>="" DO
		       IF ENR_DETAILADMIN<1,J>="802" THEN
			    IF W_JOURCONGESCP<>ENR_DETAILADMIN<6,J> THEN
			        W_JOURCONGESCP=W_JOURCONGESCP+ENR_DETAILADMIN<6,J>
			        W_ANCIENCODE=W_CLEDETAILCALCUL
			    END
		       END
		       IF ENR_DETAILADMIN<1,J>="803" THEN
			    IF W_JOURCONGESCA<>ENR_DETAILADMIN<6,J> THEN
			        W_JOURCONGESCA=W_JOURCONGESCA+ENR_DETAILADMIN<6,J>
			        W_ANCIENCODE=W_CLEDETAILCALCUL
			    END
		       END
		       IF ENR_DETAILADMIN<1,J>="817" THEN
			    IF W_JOURCONGESCF<>ENR_DETAILADMIN<6,J> THEN
			        W_JOURCONGESCF=W_JOURCONGESCF+ENR_DETAILADMIN<6,J>
			        W_ANCIENCODE=W_CLEDETAILCALCUL
			    END
		       END
		  J=J+1
	     REPEAT

	CASE W_TYPEPERSONNEL=2
	     READ ENR_DETAILMANDAT FROM F.DETAILMANDAT,W_CLEDETAILCALCUL ELSE
		  ENR_DETAILMANDAT=""
	     END

	     J=1
	     LOOP 
		  UNTIL ENR_DETAILMANDAT<1,J>="" DO
		       IF ENR_DETAILMANDAT<1,J>="802" THEN
			    IF W_JOURCONGESCP<>ENR_DETAILMANDAT<6,J> THEN
			        W_JOURCONGESCP=W_JOURCONGESCP+ENR_DETAILMANDAT<6,J>
			        W_ANCIENCODE=W_CLEDETAILCALCUL
			    END
		       END
		       IF ENR_DETAILMANDAT<1,J>="803" THEN
			    IF W_JOURCONGESCA<>ENR_DETAILMANDAT<6,J> THEN
			        W_JOURCONGESCA=W_JOURCONGESCA+ENR_DETAILMANDAT<6,J>
			        W_ANCIENCODE=W_CLEDETAILCALCUL
			    END
		       END
		       IF ENR_DETAILMANDAT<1,J>="817" THEN
			    IF W_JOURCONGESCF<>ENR_DETAILMANDAT<6,J> THEN
			        W_JOURCONGESCF=W_JOURCONGESCF+ENR_DETAILMANDAT<6,J>
			        W_ANCIENCODE=W_CLEDETAILCALCUL
			    END
		       END
		  J=J+1
	     REPEAT

	CASE W_TYPEPERSONNEL=3
	     READ ENR_DETAILPREST FROM F.DETAILPREST,W_CLEDETAILCALCUL ELSE
		  ENR_DETAILPREST=""
	     END

	     J=1
	     LOOP 
		  UNTIL ENR_DETAILPREST<5,J>="" DO
		       IF ENR_DETAILPREST<5,J>="802" THEN
			    IF W_JOURCONGESCP<>ENR_DETAILPREST<14,J> THEN
			        W_JOURCONGESCP=W_JOURCONGESCP+ENR_DETAILPREST<14,J>
			        W_ANCIENCODE=W_CLEDETAILCALCUL
			    END
		       END
		       IF ENR_DETAILPREST<5,J>="803" THEN
			    IF W_JOURCONGESCA<>ENR_DETAILPREST<14,J> THEN
 			        W_JOURCONGESCA=W_JOURCONGESCA+ENR_DETAILPREST<14,J>
			        W_ANCIENCODE=W_CLEDETAILCALCUL
			    END
		       END
		       IF ENR_DETAILPREST<5,J>="817" THEN
			    IF W_JOURCONGESCF<>ENR_DETAILPREST<14,J> THEN
 			        W_JOURCONGESCF=W_JOURCONGESCF+ENR_DETAILPREST<14,J>
			        W_ANCIENCODE=W_CLEDETAILCALCUL
			    END
		       END
		  J=J+1
	     REPEAT

	CASE W_TYPEPERSONNEL=4
	     READ ENR_DETAILINTER FROM F.DETAILINTER,W_CODECONTRAT:W_PERIODE ELSE
		  ENR_DETAILINTER=""
	     END

	     J=1
	     LOOP 
		  UNTIL ENR_DETAILINTER<8,J>="" DO
		       IF ENR_DETAILINTER<8,J>="802" THEN
			    IF W_JOURCONGESCP<>ENR_DETAILINTER<14,J> THEN
 			        W_JOURCONGESCP=W_JOURCONGESCP+ENR_DETAILINTER<14,J>
			        W_ANCIENCODE=W_CLEDETAILCALCUL
			    END
		       END
		       IF ENR_DETAILINTER<8,J>="803" THEN
			    IF W_JOURCONGESCA<>ENR_DETAILINTER<14,J> THEN
 			        W_JOURCONGESCA=W_JOURCONGESCA+ENR_DETAILINTER<14,J>
			        W_ANCIENCODE=W_CLEDETAILCALCUL
			    END
		       END
		       IF ENR_DETAILINTER<8,J>="817" THEN
			    IF W_JOURCONGESCF<>ENR_DETAILINTER<14,J> THEN
 			        W_JOURCONGESCF=W_JOURCONGESCF+ENR_DETAILINTER<14,J>
			        W_ANCIENCODE=W_CLEDETAILCALCUL
			    END
		       END
		  J=J+1
	     REPEAT

   END CASE
   J=1
RETURN
   
*********************************************************
*********************************************************
* MAJ DES COMPTEURS DE CONGES

70 *
   
   * SI PAS CONGES PAYES POUR SOLDE
   IF W_JOURCONGESCPS=0 THEN

       * SI MANDATAIRE ALORS CONGES PRIS EN ATT. 47 DE DETAILCALCUL
       IF ENR_CONTRAT<1>="02" AND ENR_CONTRAT<31>=1 THEN
	   W_JOURCONGESCP=ENR_DETAILCALCUL<47>
       END

       * CONGES PAYES
       IF ENR_CONTRAT<39>-W_JOURCONGESCP>=0 THEN
           ENR_CONTRAT<39>=ENR_CONTRAT<39>-W_JOURCONGESCP
       END ELSE
	   * SI PAS ASSEZ DE DROITS

	   * PRISE SUR CONGES FRACTIONNEMENT
	   W_JOURCONGESCP=W_JOURCONGESCP-ENR_CONTRAT<39>
           ENR_CONTRAT<39>=0

	   IF ENR_CONTRAT<41>-W_JOURCONGESCP>=0 THEN	
		ENR_CONTRAT<41>=ENR_CONTRAT<41>-W_JOURCONGESCP
	   END ELSE

		* PRISE SUR CONGES ANCIENNETE
		W_JOURCONGESCP=W_JOURCONGESCP-ENR_CONTRAT<41>
		ENR_CONTRAT<41>=0

		IF ENR_CONTRAT<48>-W_JOURCONGESCP>=0 THEN
		     ENR_CONTRAT<48>=ENR_CONTRAT<48>-W_JOURCONGESCP
		END ELSE
		     * PRISE PAR ANTICIPATION
 	  	     ENR_CONTRAT<83>=ENR_CONTRAT<83>+(W_JOURCONGESCP-ENR_CONTRAT<48>)
		     ENR_CONTRAT<48>=0
		END
	   END
       END

       * CONGES ANCIENNETE
       IF ENR_CONTRAT<48>-W_JOURCONGESCA>=0 THEN
           ENR_CONTRAT<48>=ENR_CONTRAT<48>-W_JOURCONGESCA
       END ELSE
	   ENR_CONTRAT<83>=ENR_CONTRAT<83>+(W_JOURCONGESCA-ENR_CONTRAT<48>)
           ENR_CONTRAT<48>=0
       END
       * CONGES FRACTIONNEMENT
       IF ENR_CONTRAT<41>-W_JOURCONGESCF>=0 THEN
           ENR_CONTRAT<41>=ENR_CONTRAT<41>-W_JOURCONGESCF
       END ELSE
	   ENR_CONTRAT<83>=ENR_CONTRAT<83>+(W_JOURCONGESCF-ENR_CONTRAT<41>)
           ENR_CONTRAT<41>=0
       END
   END ELSE
       ENR_CONTRAT<38>=0
       ENR_CONTRAT<39>=0
       ENR_CONTRAT<40>=0
       ENR_CONTRAT<41>=0
       ENR_CONTRAT<44>=0
       ENR_CONTRAT<45>=0
       ENR_CONTRAT<46>=0
       ENR_CONTRAT<47>=0
       ENR_CONTRAT<48>=0
       ENR_CONTRAT<85>=0
       ENR_CONTRAT<86>=0
       WRITE ENR_CONTRAT ON F.CONTRAT,W_CODECONTRAT
   END

RETURN

*********************************************************
*********************************************************
* CALCUL DU TAUX HORAIRE + COEFFICIENT

80 *

   * CALCULE DERNIER JOUR PERIODE SUIVANTE
   READ ENR_PERIODESPAIE FROM F.PERIODESPAIE,"1" ELSE
       STOP
   END
   ENR_PERIODESPAIE<2>=ENR_PERIODESPAIE<2>+1
   IF ENR_PERIODESPAIE<2>[5,2]=13 THEN
       ENR_PERIODESPAIE<2>[4,1]=ENR_PERIODESPAIE<2>[4,1]+1
       ENR_PERIODESPAIE<2>=ENR_PERIODESPAIE<2>[1,4]:"01"
   END
  
   W_DERNIERJOURMOISSUIV=ICONV("01/":ENR_PERIODESPAIE<2>[5,2]:"/":ENR_PERIODESPAIE<2>[1,4],"D4/")
   W_DERNIERJOURMOISSUIV=W_DERNIERJOURMOISSUIV-1

   * VERIFIE SI PLUSIEURS AVENANTS DISPONIBLES
   IF ENR_CONTRAT<14,2><>"" THEN
       * RECHERCHE DE L'AVENANT EN COURS
       J=1
       LOOP
	    UNTIL ENR_CONTRAT<15,J+1>>W_DERNIERJOURMOISSUIV OR ENR_CONTRAT<15,J+1>="" DO
	    J=J+1
       REPEAT
   END ELSE
       J=1
   END

   * VERIFIE SI GRILLE DE CLASSIFICATION
   IF ENR_CONTRAT<20,J><>"" THEN
       * LECTURE FICHIER GRILLESCC
       READ ENR_GRILLESCC FROM F.GRILLESCC,ENR_CONTRAT<20,J> ELSE 
	    STOP
       END

       * CALCUL ANCIENNETE DU CONTRAT
       W_DATEDEPARTGRILLECC=OCONV(ENR_CONTRAT<21,J>+ENR_CONTRAT<70>,"D4/")
       W_DATEDEPARTGRILLECC=W_DATEDEPARTGRILLECC[7,4]:W_DATEDEPARTGRILLECC[4,2]
       W_ANCIENNETE=W_PERIODE-W_DATEDEPARTGRILLECC+1
       W_ANCIENNETE=INT(W_ANCIENNETE/100)*100

       * RECHERCHE LA VALEUR ATTRIBUEE A L'ANCIENNETE DU CONTRAT
       W_FINGRILLESCC="FAUX"
       W_TAUXHORCONTRAT=0
       K=1
       LOOP 
	    IF ENR_GRILLESCC<2,K>="" THEN W_FINGRILLESCC="VRAI"
	    UNTIL W_FINGRILLESCC="VRAI" DO

	    * RECHERCHE DU TAUX HORAIRE
	    IF ENR_GRILLESCC<2,K><=W_ANCIENNETE AND W_ANCIENNETE<ENR_GRILLESCC<3,K> THEN
		 W_TAUXHORCONTRAT=ENR_GRILLESCC<4,K>
		 W_FINGRILLESCC="VRAI"
	    END ELSE
		 K=K+1
	    END
       REPEAT

       IF W_TAUXHORCONTRAT<>0 THEN
	    IF ENR_GRILLESCC<5>="C" THEN
                 * RECHERCHE DATE VALEUR POINT
                 A=1
                 LOOP
	              UNTIL ENR_CONVENTIONCOL<9,A><=W_DERNIERJOURMOISSUIV OR ENR_CONVENTIONCOL<9,A>="" DO
                      A=A+1
                 REPEAT

	         IF ENR_CONTRAT<22,J><>W_TAUXHORCONTRAT THEN
		      ENR_CONTRAT<22,J>=W_TAUXHORCONTRAT
   	         END

** AVANT                 IF ENR_CONVENTIONCOL<8,A>#"" THEN ENR_CONTRAT<23,J>=INT((W_TAUXHORCONTRAT/1000)*ENR_CONVENTIONCOL<8,A>*10/169+1/2)

** APRES
      	         READ ENR_ETABLISSEMENT FROM F.ETABLISSEMENT,ENR_CONTRAT<3> ELSE ENR_ETABLISSEMENT<16>="0"
		 W_DUREEHEBDO=INT((ENR_ETABLISSEMENT<16>*52/12)+1/2)/100

		 IF ENR_CONVENTIONCOL<8,A>#"" THEN ENR_CONTRAT<23,J>=INT((W_TAUXHORCONTRAT/1000)*ENR_CONVENTIONCOL<8,A>*10/W_DUREEHEBDO+1/2)
	    END ELSE
		 ENR_CONTRAT<23,J>=W_TAUXHORCONTRAT
	    END
       END             
   END
RETURN

*********************************************************
*********************************************************
* GESTION DES CONGES
* MAJ DES CONGES EN-COURS D'ACQUISITION

100 *

    W_TOTNBJOURCONGES=0

    W_CODEABSENCE=""
    W_REQABSENCESVIDE="FAUX"
    W_TOTALJRSABSMALADIE=0
    W_NBJOURNONINDEM=0
    W_PASABS="VRAI"

    W_MOIS=W_PERIODE[5,2]
    W_ANNEE=W_PERIODE[1,4]

    W_DEBUTPERIODE=ICONV("01/":W_MOIS:"/":W_ANNEE,"D")
    W_MOISFIN=W_PERIODE[5,2]+1
    IF W_MOISFIN>12 THEN
	 W_ANNEEFIN=W_PERIODE[1,4]+1
	 W_MOISFIN="01"
    END ELSE
	 W_ANNEEFIN=W_PERIODE[1,4]
    END

    W_FINPERIODE=ICONV("01/":W_MOISFIN:"/":W_ANNEEFIN,"D4/")
    W_FINPERIODE=W_FINPERIODE-1
    W_FINPERIODE2=OCONV(W_FINPERIODE,"D4/")
    W_FINPERIODE2=W_FINPERIODE2[7,4]:W_FINPERIODE2[4,2]

    EXECUTE 'TSELECT ABSENCESAIDANT AVEC CodAbsAidant = "':W_CODEAIDANT:']" AND AVEC 2 >= "':W_DEBUTPERIODE:'" AND AVEC DebAbsAidant <= "':W_FINPERIODE:'" AND AVEC NumMotifAidant = "01" OR = "02" OR = "04" OR = "05" OR = "06" OR = "12" OR = "13"'
    EXECUTE "SAUVE-LISTE LISTEABSENCESAIDANT"
    EXECUTE "LISTE LISTEABSENCESAIDANT" CAPTURING MSG RETURNING MSGCODE

    IF MSGCODE<1><>209 THEN 
         SELECT F.ABSENCESAIDANT TO LISTEABSENCESAIDANT

         LOOP 
 	     READNEXT CLE FROM LISTEABSENCESAIDANT ELSE
	         W_REQABSENCESVIDE="VRAI"
  	     END
	   UNTIL W_REQABSENCESVIDE="VRAI" DO

	     W_CODEABSENCE=CLE[6,2]
	     W_CLEABSENCE=CLE

	     * LECTURE ABSENCESAIDANT
	     READ ENR_ABSENCESAIDANT FROM F.ABSENCESAIDANT,W_CLEABSENCE ELSE
               PRINT "PAS D'ABS"
	         STOP
	     END

 	     * GESTION DES ABSENCES AUTRES QUE MALADIE MATERNITE
	     IF ENR_CONTRAT<31> <> 1 OR ENR_CONTRAT<1>="02" THEN
              W_PASABS="FAUX"
              IF W_JOURCONGESCPS=0 THEN
                 * Pas conges payes pour soldes 
                 *GOSUB 200
              END
           END

         REPEAT

         * a voir
	   IF W_PASABS="VRAI" AND W_JOURCONGESCPS=0 THEN GOSUB 60

    END

* Mise a jour des 10 % du BS.

   IF W_DEBUTCONTRAT < W_DEBUTPERIODE THEN
      W_NBJOURPRESENT=250
   END ELSE
      * CALCUL AU PRORATA DES JOURS DE CONGES
      W_NBJOURPRESENT=W_DEBUTCONTRAT-W_DEBUTPERIODE+1
      W_NBJOURPRESENT=W_NBJOURPRESENT*100
      W_NBJOURPRESENT=W_NbJourMois-W_NBJOURPRESENT
      W_NBJOURPRESENT=250*W_NBJOURPRESENT/W_NbJourMois
      W_NBJOURPRESENT=INT(W_NBJOURPRESENT + 1/2)
    END

    W_MONTANTARRET=0

    * recherche des rubriques des contrats prevoyances
    * RECHERCHE DES RUBRIQUES 807 - 808

    W_CountDet2=DCOUNT(ENR_DETAILCALCUL<2>,CHAR(253))
    FOR iDet2=1 TO W_CountDet2
       FOR iRubPrev=1 TO W_CountRubPrev
          IF ENR_DETAILCALCUL<2,iDet2> = W_TabPrev<iRubPrev> THEN
             W_MONTANTARRET=W_MONTANTARRET+ENR_DETAILCALCUL<5,iDet2>
          END
       NEXT iRubPrev
    NEXT iDet2 

    W_BRUTARRET=ENR_DETAILCALCUL<7>-W_MONTANTARRET
    W_HEURESARRET=ENR_DETAILCALCUL<6>

    W_VALEURHEURESJOUR=INT((W_HEURESARRET*10/100)+1/2)
    W_VALEURMONTJOUR=INT((W_BRUTARRET*10/100)+1/2)  


   W_NBJOURPRESENT=W_NBJOURPRESENT-W_TOTNBJOURCONGES
   ENR_CONTRAT<44>=ENR_CONTRAT<44>+W_NBJOURPRESENT
   ENR_CONTRAT<45>=ENR_CONTRAT<45>+W_VALEURHEURESJOUR
   ENR_CONTRAT<46>=ENR_CONTRAT<46>+W_VALEURMONTJOUR

RETURN     

