DEFINITION RLVERS_2PP_660003955 "03"
DEFINITION RLVERS_2P5_660003955 "05"
DEFINITION FORMAT_ECC_660003955 "Format_ECC"
DEFINITION MODULE_DISTR_660003955 0xA000
DEFINITION ERR_DUPL_660003955 0x0D0
DEFINITION ERR_DISTR_660003955 0x110
DEFINITION EFFICACE_660003955 0x01
DEFINITION STCK_KO_660003955 0x00
REGISTRE ENTIER erreur_660003955
REGISTRE ENTIER code_rejet_660003955
REGISTRE ENTIER type_cra_660003955
REGISTRE ENTIER date_fin_660003955
REGISTRE ENTIER UTCOffcode_660003955
REGISTRE ENTIER UTCOffcode_map_660003955
REGISTRE ENTIER ic_utccode_660003955
REGISTRE ENTIER ic_utctime_660003955
REGISTRE ENTIER ic_eltUTC_660003955
REGISTRE ENTIER nb_eltUTC_660003955
REGISTRE POINTEUR pt_flCreatTime_660003955
REGISTRE POINTEUR pt_flCreatDate_660003955
REGISTRE POINTEUR pt_utcINTName_660003955
REGISTRE POINTEUR pt_utcTimeName_660003955
REGISTRE POINTEUR pt_utcOUMEM_660003955
REGISTRE POINTEUR pt_NameOfFile_660003955
REGISTRE POINTEUR pt_LibelleAlarme_660003955
#                         - Pcode du module de distribution : CRAE Header
#                         - creation le 11/09/2006
#                         - Auteur : RAS
# HISTORIQUE:
# creation : 18/09/2006
# 15/12/2006 FO 381 decalgae du mapping de TAPIN14/UTCOfTimeCode
# 09/02/2007 FO381 annulee
# 02/11/2009 G2R5 QC490
# 23/12/2009 - DECI - G2R6 QC367 : (report G2R3C7) le mapping se fait maintenant dans le pcode IECC
# 17/06/2010 - DECI - G3R1 QC657 condition -1 au lieu de 0 pour UTCcode
# 10/12/2010 - JLG - G3R1lot4 Verification/Correction des variables (constantes, entiers, pointeurs)
# 17/08/11 - JLG - G3R4 lot3 QC852, CRAE enrichissement du libelle des alarmes par le nom du fichier collecte
##########################################################################################################





# initialisation des variables


pt_flCreatDate_660003955 ="20060912115733"
pt_flCreatTime_660003955 ="1157334"
pt_utcINTName_660003955 ="1515"
pt_utcTimeName_660003955 ="UTCTimeOffsetxxzz"
pt_utcOUMEM_660003955 ="+032600"

i_strcpy(pt_utcINTName_660003955,"")

pt_NameOfFile_660003955="01234567890123456789"
i_strcpy(pt_NameOfFile_660003955,"")
pt_LibelleAlarme_660003955="pt_LibelleAlarme_111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
i_strcpy(pt_LibelleAlarme_660003955,"")


# G3R4 QC852
erreur_660003955 = i_get_art_str(g_iartin, $Tcrae_header::NameOfFile, pt_NameOfFile_660003955)
# /G3R4 QC852


############################################################################
# duplication vers les format TAPIN 10 12 14
############################################################################

# duplication vers le format TAP2++ et TAP2.5
# g_iartout = TAP2++ et g_iartout2 = TAP2.5

############################################################################
# duplication vers le format TAPIN10 TAP2++
############################################

erreur_660003955 = i_dup_art_dest(g_iartin , g_iartout , "Ttapin10")

SI (erreur_660003955 !=0)
ALORS
	trace("Tcrae_header, erreur de duplication vers le format TAPIN10**")
	code_rejet_660003955 = MODULE_DISTR_660003955 + ERR_DUPL_660003955 + EFFICACE_660003955
	erreur_660003955 = i_format_str2(pt_LibelleAlarme_660003955, "%s> <f=%s", "Ttapin10", pt_NameOfFile_660003955)
	erreur_660003955 = i_PlvMessEmettre(8802, 2, g_iartin, "", 2, code_rejet_660003955, "Ttapin10", 0)
	SAUT STOCKE_ERRONE
FINSI

# complement de duplication hors table  TAPIN10

# mis a jour de RecordType   ERREUR de CSTE  NUM/ASCII
#QC490
erreur_660003955 = i_memcpy_art_field(g_iartout, "RecordType" ,"10", 2)

# mis a jour de FileSequencNumber
erreur_660003955 = i_memcpy_art_field(g_iartout, "FileSeqNumber" , g_iartin.FileSeqNumber[], 5)

# mis a jour  des TaxRates

SI(i_valid_field_n(g_iartin, $Tcrae_header::TaxeRate1))
ALORS
	erreur_660003955 = i_memcpy_art_field(g_iartout, "TaxRate1" , g_iartin.TaxeRate1[], 4)
FINSI

SI(i_valid_field_n(g_iartin, $Tcrae_header::TaxeRate2))
ALORS
	erreur_660003955 = i_memcpy_art_field(g_iartout, "TaxRate2" , g_iartin.TaxeRate2[], 4)
FINSI

SI(i_valid_field_n(g_iartin, $Tcrae_header::TaxeRate3))
ALORS
	erreur_660003955 = i_memcpy_art_field(g_iartout, "TaxRate3" , g_iartin.TaxeRate3[], 4)
FINSI
SI(i_valid_field_n(g_iartin, $Tcrae_header::TaxeRate4))
ALORS
	erreur_660003955 = i_memcpy_art_field(g_iartout, "TaxRate4" , g_iartin.TaxeRate4[], 4)
FINSI

SI(i_valid_field_n(g_iartin, $Tcrae_header::TaxeRate5))
ALORS
	erreur_660003955 = i_memcpy_art_field(g_iartout, "TaxRate5" , g_iartin.TaxeRate5[], 4)
FINSI

SI(i_valid_field_n(g_iartin, $Tcrae_header::TaxeRate6))
ALORS
	erreur_660003955 = i_memcpy_art_field(g_iartout, "TaxRate6" , g_iartin.TaxeRate6[], 4)
FINSI

SI(i_valid_field_n(g_iartin, $Tcrae_header::TaxeRate7))
ALORS
	erreur_660003955 = i_memcpy_art_field(g_iartout, "TaxRate7" , g_iartin.TaxeRate7[], 4)
FINSI

SI(i_valid_field_n(g_iartin, $Tcrae_header::TaxeRate8))
ALORS
	erreur_660003955 = i_memcpy_art_field(g_iartout, "TaxRate8" , g_iartin.TaxeRate8[], 4)
FINSI

# mis a jour du champ FileCreatTime par hhmmss extrait de FileCreatDate (AAAAMMJJhhmmss)

#erreur = i_get_field_str(g_iartin, "FileCreatDate", pt_flCreatDate)
pt_flCreatDate_660003955 = i_get_art_fieldptr(g_iartin , $Tcrae_header::FileCreatDate)
trace2("**Tcare_header ,pt_flCreatDate =%s", pt_flCreatDate_660003955, 0)
i_get_sub_str(pt_flCreatDate_660003955, 8, 13 ,pt_flCreatTime_660003955)
trace2("**Tcrae_header , FileCreateTime extrait de Date:<%s>",pt_flCreatTime_660003955, 0)
erreur_660003955 = i_memcpy_art_field(g_iartout ,"FileCreatTime" ,pt_flCreatTime_660003955 ,6)

# mis a jour du champ SpecVersionNumber
erreur_660003955 = i_memcpy_art_field(g_iartout , "SpecVersNb" , "02" , 2)

# mis jour de IdCrae
SI(i_valid_field_n(g_iartin, $Tcrae_header::IdCrae))
ALORS
	erreur_660003955 = i_memcpy_art_field(g_iartout, "IdCrae" , g_iartin.IdCrae[], 8)
FINSI


# mis a jour de NameOfFile


# duplication vers le TAPIN10 TAP2.5
erreur_660003955 = i_dup_art_id(g_iartout, g_iartout5)

# mis a jour du champ ReleaseVersion 03-> 2++ et 05 pour le 2.5

erreur_660003955 = i_memcpy_art_field(g_iartout , "ReleaseVers" , RLVERS_2PP_660003955 , 2)
erreur_660003955 = i_memcpy_art_field(g_iartout5 , "ReleaseVers" , RLVERS_2P5_660003955 , 2)

# Distribution de l'article vers les application destinatrices

type_cra_660003955 = 10
date_fin_660003955 = i_get_art_field(g_iartin , $Tcrae_header::dfin)
erreur_660003955 = aiguillage_header_notif_660003942(g_iartin , g_iartout , g_iartout5 ,type_cra_660003955, date_fin_660003955, FORMAT_ECC_660003955 )
SI(erreur_660003955 == STCK_KO_660003955)
ALORS
	trace("Tcrae_header, echec d'envoi de l'article aux applications destinatrices")
	code_rejet_660003955 = MODULE_DISTR_660003955 + ERR_DISTR_660003955 + EFFICACE_660003955
	erreur_660003955 = i_format_str2(pt_LibelleAlarme_660003955, "%s%s", "f=", pt_NameOfFile_660003955)
	erreur_660003955 = i_PlvMessEmettre(8803, 2, g_iartin, "", 2, code_rejet_660003955, pt_LibelleAlarme_660003955, 0)
	SAUT STOCKE_ERRONE
FINSI

##########################################################################################
# duplication vers le format TAPIN12
####################################
erreur_660003955 = i_dup_art_dest(g_iartin , g_iartout , "Ttapin12")
SI (erreur_660003955 !=0)
ALORS
	trace("Tcrae_header, erreur de duplication vers le format TAPIN12**")
	code_rejet_660003955 = MODULE_DISTR_660003955 + ERR_DUPL_660003955 + EFFICACE_660003955
	erreur_660003955 = i_format_str2(pt_LibelleAlarme_660003955, "%s> <f=%s", "Ttapin12", pt_NameOfFile_660003955)
	erreur_660003955 = i_PlvMessEmettre(8802, 2, g_iartin, "", 2, code_rejet_660003955, pt_LibelleAlarme_660003955, 0)
	SAUT STOCKE_ERRONE
FINSI

# complement de duplication hors table

# mis a jour de RecordType   ERREUR de CSTE  NUM/ASCII
#QC490
erreur_660003955 = i_memcpy_art_field(g_iartout, "RecordType" ,"12", 2)

# mis a jour des 3 premiers ExchangeRateCode = 100000
erreur_660003955 = i_memcpy_art_field(g_iartout , "RateCode1", "0000100000", 10)
erreur_660003955 = i_memcpy_art_field(g_iartout , "RateCode2", "0000100000", 10)
erreur_660003955 = i_memcpy_art_field(g_iartout , "RateCode3", "0000100000", 10)

# mis a jour

# mis a jour de IdCrae
erreur_660003955 = i_memcpy_art_field(g_iartout , "IdCrae", g_iartin.IdCrae[], 8)

# Distribution de l'article vers les application destinatrices

type_cra_660003955 = 12
date_fin_660003955 = i_get_art_field(g_iartin , $Tcrae_header::dfin)
erreur_660003955 = aiguillage_header_notif_660003942(g_iartin , g_iartout , g_iartout ,type_cra_660003955, date_fin_660003955, FORMAT_ECC_660003955 )
SI(erreur_660003955 == STCK_KO_660003955)
ALORS
	trace("Tcrae_header, echec d'envoi de l'article aux applications destinatrices")
	code_rejet_660003955 = MODULE_DISTR_660003955 + ERR_DISTR_660003955 + EFFICACE_660003955
	erreur_660003955 = i_format_str2(pt_LibelleAlarme_660003955, "%s%s", "f=", pt_NameOfFile_660003955)
	erreur_660003955 = i_PlvMessEmettre(8803, 2, g_iartin, "", 2, code_rejet_660003955, pt_LibelleAlarme_660003955, 0)
	SAUT STOCKE_ERRONE
FINSI

###########################################################################################
# duplication vers le format TAPIN14
#####################################

SI(i_get_art_field(g_iartin, $Tcrae_header::T3t19_UTCTmInfo +1) >0 )
ALORS

	ic_eltUTC_660003955 =1

	POINT BOUCLE_DUP_TAPIN14

	POINT PREMIER_UTC_OK

	erreur_660003955 = i_EntierToString(ic_eltUTC_660003955, pt_utcINTName_660003955, 4)
	trace2("pt_utcINName =<%s>",pt_utcINTName_660003955,0)

	# Recherche du premier utcTimOffCode present

	erreur_660003955 = i_format_str2(pt_utcTimeName_660003955,"%s%s" ,"utcTimOffCode",pt_utcINTName_660003955)
	trace2("i_format_str2 :%s",pt_utcTimeName_660003955, 0)
	ic_utccode_660003955 = i_get_field_num(g_iartin, pt_utcTimeName_660003955)


	# Recherche du premier utcTimeOffset present

	erreur_660003955 = i_format_str2(pt_utcTimeName_660003955,"%s%s" ,"utcTimeOffset",pt_utcINTName_660003955)
	trace2("i_format_str2 :%s",pt_utcTimeName_660003955, 0)
	ic_utctime_660003955 = i_get_field_num(g_iartin, pt_utcTimeName_660003955)

	SI((ic_utccode_660003955 == -1) && (ic_utctime_660003955 == -1) &&(ic_eltUTC_660003955 <45))
	ALORS
		ic_eltUTC_660003955 = ic_eltUTC_660003955 +1
		SAUT PREMIER_UTC_OK
	FINSI

	SI (ic_eltUTC_660003955 <= 45)
	ALORS

		erreur_660003955 = i_dup_art_dest(g_iartin , g_iartout , "Ttapin14")

		SI (erreur_660003955 !=0)
		ALORS
			trace("Tcrae_header, erreur de duplication vers le format TAPIN14**")
			trace("Tcrae_header, erreur de duplication vers le format TAPIN14**")
			code_rejet_660003955 = MODULE_DISTR_660003955 + ERR_DUPL_660003955 + EFFICACE_660003955
			erreur_660003955 = i_format_str2(pt_LibelleAlarme_660003955, "%s> <f=%s", "Ttapin14", pt_NameOfFile_660003955)
			erreur_660003955 = i_PlvMessEmettre(8802, 2, g_iartin, "", 2, code_rejet_660003955, pt_LibelleAlarme_660003955, 0)
			SAUT STOCKE_ERRONE
		FINSI


# complement de duplication hors table  TAPIN14

# mis a jour de RecordType
		erreur_660003955 = i_memcpy_art_field(g_iartout , "RecordType" , "14" , 2)

		nb_eltUTC_660003955 = 1

		POINT  MAJ_UTCOFFDEF

		SI (ic_utccode_660003955 != -1)
		ALORS
			UTCOffcode_660003955 = i_get_art_field(g_iartin, ic_utccode_660003955)
			trace1("info UTCOffcode_in:<%x>", UTCOffcode_660003955)

#QC367 : le mapping se fait maintenant dans le pcode IECC
			UTCOffcode_map_660003955 =UTCOffcode_660003955

			# mis a jour de UTCoffsetcode

			trace1("info UTCOffcode_map:<%x>", UTCOffcode_map_660003955)
			# si pas de mapping le champ garde la valeur par defaut (espace)
			#QC657
			SI (UTCOffcode_map_660003955 != -1)
			ALORS
				erreur_660003955 = i_EntierToString(nb_eltUTC_660003955, pt_utcINTName_660003955, 4)
				erreur_660003955 = i_format_str2(pt_utcTimeName_660003955,"%s%s" ,"UTCOfTimeCode",pt_utcINTName_660003955)
				erreur_660003955 = i_memset_field(g_iartout ,pt_utcTimeName_660003955, UTCOffcode_map_660003955)
			FINSI
		FINSI

		SI (ic_utctime_660003955 != -1)
		ALORS
			erreur_660003955 = i_EntierToString(nb_eltUTC_660003955, pt_utcINTName_660003955, 4)
			erreur_660003955 = i_format_str2(pt_utcTimeName_660003955,"%s%s" ,"UTCTimeOffset",pt_utcINTName_660003955)
			pt_utcOUMEM_660003955 = i_get_art_fieldptr(g_iartin, ic_utctime_660003955 )
			erreur_660003955 = i_memcpy_art_field(g_iartout , pt_utcTimeName_660003955 ,pt_utcOUMEM_660003955 , 5)
		FINSI
		SI ((ic_utctime_660003955 != -1)||(ic_utccode_660003955 != -1))
		ALORS
			nb_eltUTC_660003955 =  nb_eltUTC_660003955 +1
		FINSI

# Recherche de l'UTC suivant


		POINT UTC_SUIVANT
		ic_eltUTC_660003955 = ic_eltUTC_660003955 +1
		SI(ic_eltUTC_660003955 > 45)
		ALORS
			SAUT SUITE_MAJ_DUP14
		FINSI

		erreur_660003955 = i_EntierToString(ic_eltUTC_660003955, pt_utcINTName_660003955, 4)
		trace2("pt_utcINName =<%s>",pt_utcINTName_660003955,0)

		# Recherche de utcTimOffCode suivant

		erreur_660003955 = i_format_str2(pt_utcTimeName_660003955,"%s%s" ,"utcTimOffCode",pt_utcINTName_660003955)
		trace2("i_format_str2 :%s",pt_utcTimeName_660003955, 0)
		ic_utccode_660003955 = i_get_field_num(g_iartin, pt_utcTimeName_660003955)

		# Recherche de utcTimeOffset suivant

		erreur_660003955 = i_format_str2(pt_utcTimeName_660003955,"%s%s" ,"utcTimeOffset",pt_utcINTName_660003955)
		trace2("i_format_str2 :%s",pt_utcTimeName_660003955, 0)
		ic_utctime_660003955 = i_get_field_num(g_iartin, pt_utcTimeName_660003955)

		SI((ic_utctime_660003955 ==-1)&&(ic_utccode_660003955== -1))
		ALORS
			SAUT UTC_SUIVANT
		FINSI

		SI(nb_eltUTC_660003955 <=15 )
		ALORS
			SAUT MAJ_UTCOFFDEF
		FINSI

		POINT SUITE_MAJ_DUP14

# mis a jour de IdCrae
		erreur_660003955 = i_memcpy_art_field(g_iartout , "IdCrae" , g_iartin.IdCrae[] , 8)
## mis a jour de IdCrae
#           erreur = i_memcpy_art_field(g_iartout , "IdCrae" , g_iartin.IdCrae[] , 8)

# Distribution de l'article vers les application destinatrices

		type_cra_660003955 = 14
		date_fin_660003955 = i_get_art_field(g_iartin , $Tcrae_header::dfin)
		erreur_660003955 = aiguillage_header_notif_660003942(g_iartin , g_iartout , g_iartout ,type_cra_660003955, date_fin_660003955, FORMAT_ECC_660003955 )
		SI(erreur_660003955 == STCK_KO_660003955)
		ALORS
			trace("Tcrae_header, echec d'envoir de l'article aux applications destinatrices")
			code_rejet_660003955 = MODULE_DISTR_660003955 + ERR_DISTR_660003955 + EFFICACE_660003955
			erreur_660003955 = i_format_str2(pt_LibelleAlarme_660003955, "%s%s", "f=", pt_NameOfFile_660003955)
			erreur_660003955 = i_PlvMessEmettre(8803, 2, g_iartin, "", 2, code_rejet_660003955, pt_LibelleAlarme_660003955, 0)
			SAUT STOCKE_ERRONE
		FINSI
		#     ic_eltUTC = ic_eltUTC +1
		SI(ic_eltUTC_660003955 <=45)
		ALORS
			SAUT  BOUCLE_DUP_TAPIN14
		FINSI
	FINSI
FINSI

trace("** Tcrae_header :fin pcode du module de distribution **")
RETOUR TRAIT_OK

# stockage de l'article en errone

POINT STOCKE_ERRONE

erreur_660003955 = i_make_art_rej(g_iartin, g_iartout2, code_rejet_660003955)
erreur_660003955 = i_stocke_art(g_iartout2,0,PT_ERRONE,0)
trace("**Tcrae_header , Artcile stocke en errone**")
#      RETOUR TRAIT_OK
RETOUR BAD_BLOC
#------------------------------------------- FIN Tcrae_header_dis.src --------------------------------------------
