EXECUTE "SET-THOUS ."
EXECUTE "SET-DEC ,"
EXECUTE "DATE.FORMAT"
OPEN "", "DETAILCALCUL" TO F.DETAILCALCUL ELSE STOP
OPEN "", "CONTRAT" TO F.CONTRAT ELSE STOP
OPEN "", "CIVILAIDANT" TO F.AIDANT ELSE STOP
OPEN "", "SECTEUR" TO F.SECTEUR ELSE STOP

***********************************************
* 100 : criture de l'en-tete
* 200 : changement de secteur
***********************************************
PRINT "Indiquez la priode de dbut (sous la forme AAAAMM)"
INPUT W_PerDeb
PRINT "Indiquez maintenant la periode de fin (AAAAMM)"
INPUT W_PerFin

PRINTER ON

EXECUTE 'SELECT DETAILCALCUL AVEC PeriodeDetailCalcul >= "':W_PerDeb:'" AND AVEC PeriodeDetailCalcul <= "':W_PerFin:'" PAR SecteurAidantDetailCalcul PAR NomPrenomAidantDetailCalcul PAR PeriodeDetailCalcul'

W_Fin = "Faux"
W_CompteurLigne = 67
W_PremierAidant = "Vrai"
W_TamponAidant = ""
W_TamponSecteur = ""
W_PremierDetail = "Vrai"
W_CumulHeures = 0
W_HresDirectes=0
W_HresMOI=0
W_Pourc=0

LOOP 

	READNEXT W_Cle ELSE W_Fin = "Vrai"

WHILE W_Fin = "Faux"

	READ ENR_DETAIL FROM F.DETAILCALCUL, W_Cle ELSE ENR_DETAIL = ""
	
		IF W_PremierDetail = "Vrai" THEN
			W_PremierDetail = "Faux"
			W_TamponAidant = W_Cle[1,8]
		END
	
		IF W_Cle[1,5] # W_TamponAidant[1,5] THEN

			*Traitement aidant prcdent
			
			READ ENR_AIDANT FROM F.AIDANT, W_TamponAidant[1,5] ELSE ENR_AIDANT = ""
			
			IF ENR_AIDANT<31> # W_TamponSecteur OR W_CompteurLigne >=65 THEN
				IF W_PremierAidant = "Faux" THEN
					PAGE
				END ELSE
					W_PremierAidant = "Faux"
				END
				GOSUB 100
				W_TamponSecteur = ENR_AIDANT<31>
				GOSUB 200
				W_CompteurLigne =  9 
			END

			READ ENR_CONTRAT FROM F.CONTRAT, W_TamponAidant ELSE ENR_CONTRAT = ""
			W_NomPrenomAidant = ENR_AIDANT<2>:" ":ENR_AIDANT<3>
			W_NomPrenomAidant = W_NomPrenomAidant[1,49]
			W_NomPrenomAidant = W_NomPrenomAidant"L 50"
			ENR_CONTRAT<23,1>=ENR_CONTRAT<23,1>/1000

                        IF W_CumulHeures # 0 THEN
                           W_Pourc=W_HresMOI/W_CumulHeures*100
                        END ELSE
                           W_Pourc=0
                           W_HresDirectes=0
                           W_HresMOI=0
                        END
                        W_Pourc=W_Pourc"R2 5"
                        W_HresMOI=W_HresMOI"R2 7"
			W_HresDirectes=W_HresDirectes"R2 7"
			W_CumulHeures=W_CumulHeures"R2 7"

			PRINT W_TamponAidant[1,5]:" ":W_NomPrenomAidant:OCONV(ENR_CONTRAT<7>, "D4/"):"   ":ENR_CONTRAT<22,1>"L 3":"   ":ENR_CONTRAT<23,1>"R34":"   ":W_CumulHeures:"   ":W_HresDirectes:"   ":W_HresMOI:"    ":W_Pourc

                        W_CompteurLigne = W_CompteurLigne + 1
			
			*traitement aidant actuel

			W_CumulHeures = ENR_DETAIL<6>/100
			W_HresDirectes = ENR_DETAIL<41>/100
                        W_HresMOI=W_CumulHeures-W_HresDirectes
                        W_Count=DCOUNT(ENR_DETAIL<2>,CHAR(253))
                        FOR i = 1 TO W_Count
                           IF ENR_DETAIL<2,i>="818" OR ENR_DETAIL<2,i>="819" OR ENR_DETAIL<2,i>="803" OR ENR_DETAIL<2,i>="817" OR ENR_DETAIL<2,i>="802" THEN
                              W_HresMOI=W_HresMOI-(ENR_DETAIL<3,i>/100)
                           END
                        NEXT i

			W_TamponAidant = W_Cle[1,8]

		END ELSE 

			W_CumulHeures = W_CumulHeures + ENR_DETAIL<6>/100	
			W_HresDirectes = W_HresDirectes + ENR_DETAIL<41>/100
                        W_HresMOI=W_HresMOI+((ENR_DETAIL<6>-ENR_DETAIL<41>)/100)
                        W_Count=DCOUNT(ENR_DETAIL<2>,CHAR(253))
                        FOR i = 1 TO W_Count
                           IF ENR_DETAIL<2,i>="818" OR ENR_DETAIL<2,i>="819" OR ENR_DETAIL<2,i>="803" OR ENR_DETAIL<2,i>="817" OR ENR_DETAIL<2,i>="802" THEN
                              W_HresMOI=W_HresMOI-(ENR_DETAIL<3,i>/100)
                           END
                        NEXT i
			W_TamponAidant = W_Cle[1,8]	

		END 

REPEAT

READ ENR_AIDANT FROM F.AIDANT, W_TamponAidant[1,5] ELSE ENR_AIDANT = ""
IF ENR_AIDANT<31> # W_TamponSecteur THEN
	IF W_PremierAidant = "Vrai" THEN
		W_PremierAidant = "Faux"
	END ELSE
		PAGE
	END
	W_TamponSecteur = ENR_AIDANT<31>
	GOSUB 100
	GOSUB 200
	W_CompteurLigne = W_CompteurLigne + 5 
	W_TamponSecteur = ENR_AIDANT<31>
END
READ ENR_CONTRAT FROM F.CONTRAT, W_TamponAidant ELSE ENR_CONTRAT = ""
W_NomPrenomAidant = ENR_AIDANT<2>:" ":ENR_AIDANT<3>
W_NomPrenomAidant = W_NomPrenomAidant[1,49]
W_NomPrenomAidant = W_NomPrenomAidant"L 50"
ENR_CONTRAT<23,1>=ENR_CONTRAT<23,1>/1000

IF W_CumulHeures # 0 THEN
   W_Pourc=W_HresMOI/W_CumulHeures*100
END ELSE
   W_Pourc=0
   W_HresDirectes=0
   W_HresMOI=0
END
W_Pourc=W_Pourc"R2 5"
W_HresMOI=W_HresMOI"R2 7"
W_HresDirectes=W_HresDirectes"R2 7"

W_CumulHeures=W_CumulHeures"R2 7"

PRINT W_TamponAidant[1,5]:" ":W_NomPrenomAidant:OCONV(ENR_CONTRAT<7>, "D4/"):"   ":ENR_CONTRAT<22,1>"L 3":"   ":ENR_CONTRAT<23,1>"R34":"   ":W_CumulHeures:"   ":W_HresDirectes:"   ":W_HresMOI:"    ":W_Pourc

W_CompteurLigne=W_CompteurLigne + 1

STOP

* En-tete
100
W_Mois = W_PerDeb
GOSUB 300
W_PerDebut = W_LibMois:" ":W_PerDeb[1,4]
W_Mois=W_PerFin
GOSUB 300
W_PerF1 = W_LibMois:" ":W_PerFin[1,4]
PRINT "           Liste des heures effectuees par aidant par secteur entre ":W_PerDebut:" et ":W_PerF1
PRINT " "
RETURN

200
READ ENR_SECTEUR FROM F.SECTEUR, W_TamponSecteur ELSE ENR_SECTEUR = ""
PRINT " "
PRINT "Secteur : ":ENR_SECTEUR<1>
PRINT " "
PRINT " Aidant                                                   Debut du  Coef.  Taux   Nombre d'  Heures    Heures  % MOI/Brut"
PRINT "                                                          contrat         horaire  heures   directes    MOI     "
PRINT " "
RETURN

300
W_LibMois=""
BEGIN CASE
	CASE W_Mois[5,2] MATCHES "01"
		W_LibMois = "janvier"
	CASE W_Mois[5,2] MATCHES "02"
		W_LibMois = "fevrier"
	CASE W_Mois[5,2] MATCHES "03"
		W_LibMois = "mars"
	CASE W_Mois[5,2] MATCHES "04"
		W_LibMois = "avril"
	CASE W_Mois[5,2] MATCHES "05"
		W_LibMois = "mai"
	CASE W_Mois[5,2] MATCHES "06"
		W_LibMois = "juin"
	CASE W_Mois[5,2] MATCHES "07"
		W_LibMois = "juillet"
	CASE W_Mois[5,2] MATCHES "08"
		W_LibMois = "aout"
	CASE W_Mois[5,2] MATCHES "09"
		W_LibMois = "septembre"
	CASE W_Mois[5,2] MATCHES "10"
		W_LibMois = "octobre"
	CASE W_Mois[5,2] MATCHES "11"
		W_LibMois = "novembre"
	CASE W_Mois[5,2] MATCHES "12"
		W_LibMois = "decembre"
END CASE
RETURN
