EXECUTE "SET-THOUS ."
EXECUTE "SET-DEC ,"
EXECUTE "DATE.FORMAT"
OPEN "", "DETAILCALCUL" TO F.DETAILCALCUL ELSE STOP
OPEN "", "HISTORCUMUL" TO F.HISTORCUMUL ELSE STOP
OPEN "", "CIVILAIDANT" TO F.CIVILAIDANT ELSE STOP
OPEN "", "CONTRAT" TO F.CONTRAT ELSE STOP
PRINT "Mois de debut de l'année de déclaration (AAAAMM)"
INPUT W_MoisDeb
PRINT "Mois de fin de l'année de déclaration (AAAAMM)"
INPUT W_MoisFin
PRINT "Code entité juridique"
INPUT W_CodeAsso
PRINT "Code rubrique de charge"
INPUT W_CodeRubChg
W_DateFinPer = ICONV("01/":W_MoisFin[5,2]:"/":W_MoisFin[1,4],"D4/")
EXECUTE 'COMO ON VerifRubChgEXOAADDADS.txt'
W_Str =  'SELECT DETAILCALCUL AVEC CodAssoContratDetailCalcul = "':W_CodeAsso:'" AND AVEC ConvColContratDetailCalcul # "02" AND AVEC PeriodeDetailCalcul >= "':W_MoisDeb:'" AND AVEC PeriodeDetailCalcul <= "':W_MoisFin:'" PAR CodeAidantDetailCalcul PAR CodeAideDetailCalcul PAR PeriodeDetailCalcul'
EXECUTE W_Str
W_TamponAidant = ""
W_Cumulrubchg = 0
W_NbAidants = 0
W_NbAidantsMod = 0
W_CleCont = ""
W_IndCont = 1
W_SommeBullTOT = 0
W_SommeDADSTOT = 0
W_SommeDADSArrondieTOT = 0
W_TamponAide = ""
W_Fin = "F"
LOOP
	READNEXT W_Cle ELSE W_Fin = "V"
WHILE W_Fin = "F"
	READ ENR_CONTRAT FROM F.CONTRAT, W_Cle[1,8] ELSE ENR_CONTRAT = ""
	IF ENR_CONTRAT<3> # W_TamponAide OR W_Cle[1,5] # W_TamponAidant THEN
		IF W_TamponAide # "" THEN
			READ ENR_CIVILAIDANT FROM F.CIVILAIDANT, W_TamponAidant THEN
			GOSUB 400
			END
		END
		W_TamponAidant = W_Cle[1,5]
		W_TamponAide = ENR_CONTRAT<3>
	END
	READ ENR_DETAILCALCUL FROM F.DETAILCALCUL, W_Cle ELSE ENR_DETAILCALCUL = ""
	J=1
	LOOP
 	 CODERUBCHG=EXTRACT(ENR_DETAILCALCUL,8,J)
	  IF INDEX(W_CodeRubChg,CODERUBCHG,1) # 0 THEN W_Cumulrubchg = W_Cumulrubchg + EXTRACT(ENR_DETAILCALCUL,9,J)	
	  UNTIL CODERUBCHG="" DO
  	   J=J+1
	REPEAT
REPEAT
GOSUB 400
PRINT 	W_NbAidants:" parcourus, ":W_NbAidantsMod:" présentaient une anomalie "
PRINT "Totaux :"
PRINT "   - DADS                : ":W_SommeDADSTOT/100
PRINT "   - DADS arrondie       : ":W_SommeDADSArrondieTOT
PRINT "   - Bulletins           : ":W_SommeBullTOT/100
EXECUTE 'COMO OFF'
STOP
100
* Impression de la rubrique
W_Diff = W_Cumulrubchg - W_BASERUBCHG
IF W_Diff > 1 OR W_Diff < -1 THEN
 W_NbAidantsMod = W_NbAidantsMod + 1
 PRINT W_TamponAidant:" ":ENR_CIVILAIDANT<4>:" ":ENR_CIVILAIDANT<2>:" ":ENR_CIVILAIDANT<3>:" ":W_TamponAide
 PRINT " cumul DADS : ":W_BASERUBCHG/100"R2 8":"   Total bulletins : ":W_Cumulrubchg/100"R2 8":"   Diff. : ":W_Diff/100"R2 8"
 PRINT
END
RETURN
200
* Pas de DADS
IF W_Cumulrubchg > 1 OR W_Cumulrubchg < -1 THEN
	W_NbAidantsMod = W_NbAidantsMod + 1
	PRINT W_TamponAidant:" ":ENR_CIVILAIDANT<4>:" ":ENR_CIVILAIDANT<2>:" ":ENR_CIVILAIDANT<3>:" ":W_TamponAide
	PRINT "Cet aidant n'a pas de DADS ! "	
END
RETURN
***************************************
* Total Aide
******************************************			
400
W_SommeBullTOT = W_SommeBullTOT + W_Cumulrubchg
W_NbAidants = W_NbAidants + 1
W_BASERUBCHG=0
READ ENR_HISTORCUMUL FROM F.HISTORCUMUL, W_TamponAidant[1,5]:W_MoisFin[1,4]:W_TamponAide[1,3] THEN
 I=1
 LOOP
  CODERUBCHG=EXTRACT(ENR_HISTORCUMUL,15,I)
  IF INDEX(W_CodeRubChg,CODERUBCHG,1)#0 THEN 
	W_BASERUBCHG=W_BASERUBCHG+EXTRACT(ENR_HISTORCUMUL,17,I)
	W_SommeDADSArrondieTOT = W_SommeDADSArrondieTOT + INT(EXTRACT(ENR_HISTORCUMUL,17,I)/100 + 1/2)

  END
  UNTIL CODERUBCHG="" DO
   I=I+1
 REPEAT
 W_SommeDADSTOT = W_SommeDADSTOT + W_BASERUBCHG
 
  IF W_Cumulrubchg # W_BASERUBCHG THEN	
	GOSUB 100
  END
END ELSE
	ENR_HISTORCUMUL = ""
	GOSUB 200
END
W_Cumulrubchg = 0
W_CleCont = ""
W_IndCont = 1
RETURN
