DEFINITION C_Article_860026368 "Tftld"
DEFINITION C_InstSPOT_860026368 "SPOT_CTI"
DEFINITION C_InstSYMP_860026368 "SYMP"
DEFINITION C_TsymTftld_860026368 "TsymTftld"
DEFINITION C_TspotTftld_860026368 "TspotTftld"
DEFINITION C_InstENTREFF_860026368 "ENTREFF"
DEFINITION C_InstENTRINEF_860026368 "ENTRINEF"
DEFINITION C_Tentr101_860026368 "Tentr101"
DEFINITION C_TcentHF_860026368 "TcentHF"
DEFINITION C_InstCENTHF_860026368 "CENTHF"
DEFINITION ZONE_METRO_860026368 7
DEFINITION NUMTAB1_860026368 1
DEFINITION NUMTAB2_860026368 2
DEFINITION NUMTABSEL_860026368 1
DEFINITION C_NB_1970_860026368 0x83ABD000
DEFINITION Prefixe_Portabilite_860026368 "Prefixe_Portabilite"
DEFINITION Prefixe_Portabilite_Inter_860026368 "Prefixe_Porta_Inter"
DEFINITION C_INST_ALICE_860026368 "ALICE"
DEFINITION TD_SVA_860026368 9
REGISTRE ENTIER NUMZONE_860026368
REGISTRE ENTIER EFFICACE_860026368
REGISTRE ENTIER MONO_DCI_860026368
REGISTRE ENTIER TYPENR_860026368
REGISTRE ENTIER TYPDR_860026368
REGISTRE ENTIER TYPDE_860026368
REGISTRE ENTIER DUREE_860026368
REGISTRE ENTIER instSYMPH_860026368
REGISTRE ENTIER instSPOT_860026368
REGISTRE ENTIER instENTREFF_860026368
REGISTRE ENTIER instENTRINEF_860026368
REGISTRE ENTIER erreur_860026368
REGISTRE ENTIER res_860026368
REGISTRE ENTIER code_errone_860026368
REGISTRE ENTIER date_locale_860026368
REGISTRE ENTIER date_Metro_fin_860026368
REGISTRE ENTIER date_fin_GMT_860026368
REGISTRE ENTIER date_fin_GMT_UNIX_860026368
REGISTRE ENTIER date_pivot_860026368
REGISTRE ENTIER date_locale_fin_860026368
REGISTRE ENTIER TYPDES_860026368
REGISTRE ENTIER size_Port_860026368
REGISTRE ENTIER size_PPY_860026368
REGISTRE ENTIER ICAR_860026368
REGISTRE ENTIER ICAR_ABS_860026368
REGISTRE ENTIER increment_ndr_860026368
REGISTRE ENTIER increment_ndrs_860026368
REGISTRE ENTIER increment_nde_860026368
REGISTRE ENTIER increment_ndeorg_860026368
REGISTRE ENTIER increment_nred_860026368
REGISTRE ENTIER isize_ndr_860026368
REGISTRE ENTIER isize_nde_860026368
REGISTRE ENTIER isize_ndrs_860026368
REGISTRE ENTIER isize_ndeorg_860026368
REGISTRE ENTIER isize_nred_860026368
REGISTRE ENTIER TFAISCEAU_860026368
REGISTRE ENTIER DateDeb_860026368
REGISTRE ENTIER DateFin_860026368
REGISTRE ENTIER instCENTHF_860026368
REGISTRE ENTIER date_debut_gmt_860026368
REGISTRE ENTIER b_SONUSHD_860026368
REGISTRE ENTIER CATLIG_860026368
REGISTRE ENTIER CPT_REDIST_860026368
REGISTRE ENTIER longueur_860026368
REGISTRE ENTIER bREDIST_860026368
REGISTRE ENTIER instALICE_860026368 
REGISTRE ENTIER val_860026368
REGISTRE ENTIER b_ALICE_860026368
REGISTRE ENTIER b_CENTHF_860026368
REGISTRE ENTIER Date_CPS_860026368
REGISTRE POINTEUR pt_fsent_860026368
REGISTRE POINTEUR pt_fssort_860026368
REGISTRE POINTEUR pt_TEMP1_860026368
REGISTRE POINTEUR pt_TEMP2_860026368
REGISTRE POINTEUR pt_nomECCFact_860026368
REGISTRE POINTEUR pt_sgtqs_860026368
REGISTRE POINTEUR pt_typap_860026368
REGISTRE POINTEUR pt_valeur1_860026368
REGISTRE POINTEUR pt_BUF_860026368
REGISTRE POINTEUR pt_fsentft_860026368
REGISTRE POINTEUR pt_fssortft_860026368
REGISTRE POINTEUR pt_NDE1_860026368
REGISTRE POINTEUR pt_NDES1_860026368
REGISTRE POINTEUR pt_CC2_860026368
REGISTRE POINTEUR pt_CC3_860026368
REGISTRE POINTEUR pt_PREFPORT_860026368
REGISTRE POINTEUR pt_return_TablePort_860026368
REGISTRE POINTEUR pt_cle_860026368
REGISTRE POINTEUR pt_valeur_860026368
REGISTRE POINTEUR pt_return_TFAISCEAU_860026368
REGISTRE POINTEUR pt_DateDeb_860026368
REGISTRE POINTEUR pt_DateFin_860026368
REGISTRE POINTEUR pt_CATLIG_860026368
REGISTRE POINTEUR pt_MESSAGE_860026368
REGISTRE POINTEUR pt_LIBELREDIST_860026368
REGISTRE POINTEUR pt_CODE_TARIF_860026368
REGISTRE POINTEUR pt_TYPE_EDIT_860026368
REGISTRE POINTEUR pt_NDE_NORM_860026368
############################################################################
#	Article DC FTLD venant du CTI4G
#	Pcode de distribution
#
# EN SORTIE:
#
#    SYMPHONIE	(TsymTftld - g_iartout5)  : TOUS
#    ENTROPI	(Tentr101 - g_iartout2) - ENTREFF = efficace et (faiscioin ou faiscioout = 1) / ENTRINEF = Inefficace
#    SPOT_CTI	(TspotTftld - g_iartout4) : TOUS
#    CENTHF		(TcentHF - g_iartout6) : EFFICACE=vrai et DUREE non nulle et FD/FSSORT <> "          " 
#                                et ( MONO_DCI vrai ou FSSORTFT faux)
#
#	01/10/2013 - Creation
# Historique
#    01/10/2013 - THE DRE - Creation a partir de TctiTss40 avec remplacement SAFIRE par ENTROPI
#    07/10/2013 - THE DRE - G4R4C2 QC754
#    24/04/2014 - THE - ##### G4R6 Lot3 ##### C+S appelant
#    13/05/2014 - THE - ##### G4R6 Lot3 ##### G4R6 QC814 
#
############################################################################


#G4R4 lot2
##### G4R6 Lot3 #####


#############################################################################################
#G4R4 lot2

##### G4R6 Lot3 #####


#####################################################################
#	Initialisations
#####################################################################

code_errone_860026368  = 0
EFFICACE_860026368     = 0
MONO_DCI_860026368     = 0
DUREE_860026368        = 0
instSYMPH_860026368    = 0
#instSAFIRE   = 0
instSPOT_860026368     = 0
instCENTHF_860026368   = 0
#G4R4 lot2
instENTREFF_860026368  = -1
instENTRINEF_860026368 = -1
TYPDE_860026368        = 0
TYPDES_860026368       = 0
size_Port_860026368    = 0
size_PPY_860026368     = 0
date_debut_gmt_860026368 = 0
b_SONUSHD_860026368    = 0
CATLIG_860026368	     = 0
##### G4R6 Lot3 #####
CPT_REDIST_860026368   = 0
longueur_860026368     = 0
bREDIST_860026368      = 0
instALICE_860026368    = -1
val_860026368          = 0
b_ALICE_860026368      = 0
b_CENTHF_860026368     = 0
Date_CPS_860026368     = 0


################################################################################
##### G4R6 Lot3 #####


pt_fsent_860026368	 = "6677889900112233445566"
pt_fssort_860026368	 = "7788990011223344556677"
pt_TEMP1_860026368	 = "8899001122334455667788"
pt_TEMP2_860026368	 = "pt_TEMP2990011223344556677889900"
pt_nomECCFact_860026368	 ="67676767676767"
pt_sgtqs_860026368	 = "5566778899001122334455"
pt_typap_860026368	 = "0011223344556677889900"
pt_valeur1_860026368	 = "1199001122334455667788"
pt_BUF_860026368		 = "8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888"
pt_fsentft_860026368	 = "4444444444444444"
pt_fssortft_860026368	 = "3333333333333333"
pt_NDE1_860026368		 = "9509509509509509509509509509505950950950950"
pt_CC2_860026368		 = "1596790"
pt_CC3_860026368		 = "7597907"
pt_PREFPORT_860026368	 = "333333333333333333333333333"
pt_NDES1_860026368	 = "565656566565665656565656565656565656565656"
pt_cle_860026368		 = "98798798798798798798776987987987"
pt_return_TablePort_860026368 = "1717171717171717"
pt_valeur_860026368	 = "valeur"
pt_return_TFAISCEAU_860026368 = "pt_return_TFAISCEAU111111111111111111"
pt_DateDeb_860026368 = "pt_DateDeb222222222222222"
pt_DateFin_860026368 = "pt_DateFin333333333333333"
pt_CATLIG_860026368 = "pt_CATLIG"
##### G4R6 Lot3 #####
pt_MESSAGE_860026368 = "pt_MESSAGE012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
pt_LIBELREDIST_860026368 = "pt_LIBELREDIST012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
pt_CODE_TARIF_860026368  = "pt_CODE_TARIF0123456789"
pt_TYPE_EDIT_860026368   = "pt_TYPE_EDIT98765432109"
pt_NDE_NORM_860026368    = "pt_NDE_NORM987654321098"


####################################################################
# Initialisation des pointeurs
####################################################################

i_strcpy(pt_fsent_860026368,"") 
i_strcpy(pt_fssort_860026368,"")
i_strcpy(pt_TEMP1_860026368,"")    
i_strcpy(pt_TEMP2_860026368,"")    
i_strcpy(pt_sgtqs_860026368,"") 
i_strcpy(pt_typap_860026368,"") 
i_strcpy(pt_valeur1_860026368,"")  
i_strcpy(pt_BUF_860026368,"")   
i_strcpy(pt_fsentft_860026368,"")
i_strcpy(pt_fssortft_860026368,"")
i_strcpy(pt_NDE1_860026368,"")  
i_strcpy(pt_NDES1_860026368,"") 
i_strcpy(pt_CC2_860026368,"")   
i_strcpy(pt_CC3_860026368,"")   
i_strcpy(pt_cle_860026368,"")   
i_strcpy(pt_valeur_860026368,"")
i_strcpy(pt_return_TFAISCEAU_860026368, "")
i_strcpy(pt_DateDeb_860026368, "")
i_strcpy(pt_DateFin_860026368, "")
i_strcpy(pt_CATLIG_860026368, "")
##### G4R6 Lot3 #####
i_strcpy(pt_CODE_TARIF_860026368, "")
i_strcpy(pt_TYPE_EDIT_860026368, "")
i_strcpy(pt_NDE_NORM_860026368, "")


####################################################################
# Initialisation des variables
####################################################################

erreur_860026368 = i_dup_art_id(g_iartin,g_iartout)

##### G4R6 Lot3 #####
#Nb de passage en redistribution
CPT_REDIST_860026368 = i_LireRedistCpt()

increment_ndr_860026368 = 0
increment_ndrs_860026368 = 0
increment_nde_860026368 = 0
increment_ndeorg_860026368 = 0
increment_nred_860026368 = 0
isize_ndr_860026368 = g_iartout.NDR!NELEM
isize_ndrs_860026368 = g_iartout.NDRS!NELEM
isize_nde_860026368 = g_iartout.NDE!NELEM
isize_ndeorg_860026368 = g_iartout.NDEORG!NELEM
isize_nred_860026368 = g_iartout.NRED!NELEM
TFAISCEAU_860026368 = 0

####################################################################
# NORMALISATION  No NDR NDRS NDE et NDEORG
# par une justification a gauche et le  repport des bits de bourrage de valeur 0xF a droite
####################################################################

#  NDR
POINT boucle_ndr
SI increment_ndr_860026368 < isize_ndr_860026368
ALORS
	erreur_860026368        = i_skip_f_in_field_n(g_iartout, $Tftld::NDR)
	increment_ndr_860026368 = increment_ndr_860026368 + 1

	SAUT boucle_ndr
FINSI


#  NDE
POINT boucle_nde
SI increment_nde_860026368 < isize_nde_860026368
ALORS
	erreur_860026368        = i_skip_f_in_field_n(g_iartout, $Tftld::NDE)
	increment_nde_860026368 = increment_nde_860026368 + 1

	SAUT boucle_nde
FINSI


#  NDRS
POINT boucle_ndrs
SI increment_ndrs_860026368 < isize_ndrs_860026368
ALORS
	erreur_860026368        = i_skip_f_in_field_n(g_iartout, $Tftld::NDRS)
	increment_ndrs_860026368 = increment_ndrs_860026368 + 1

	SAUT boucle_ndrs
FINSI


#  NDEORG
POINT boucle_ndeorg
SI increment_ndeorg_860026368 < isize_ndeorg_860026368
ALORS
	erreur_860026368        = i_skip_f_in_field_n(g_iartout, $Tftld::NDEORG)
	increment_ndeorg_860026368 = increment_ndeorg_860026368 + 1

	SAUT boucle_ndeorg
FINSI


#  NRED
POINT boucle_nred
SI increment_nred_860026368 < isize_nred_860026368
ALORS
	erreur_860026368        = i_skip_f_in_field_n(g_iartout, $Tftld::NRED)
	increment_nred_860026368 = increment_nred_860026368 + 1

	SAUT boucle_nred
FINSI

i_strcpy(pt_nomECCFact_860026368, "")


# Creation de l'article Conversion (g_iartout10)
erreur_860026368 = i_cree_art("Conversion",g_iartout10)


# Calcul de la variable EFFICACE
TYPENR_860026368 = i_get_art_field(g_iartout,$Tftld::TYPENR)
SI ( ( TYPENR_860026368 == 0 ) || ( TYPENR_860026368 == 2 ) || ( TYPENR_860026368 == 4 ) )
ALORS
	EFFICACE_860026368 = 1
FINSI
trace1("========== EFFICACE = %d =====",EFFICACE_860026368)


# recuperation du Champ DUREE
DUREE_860026368 = i_get_art_field(g_iartout, $Tftld::DUREE)


# recuperation de la date pivot
date_pivot_860026368 = i_get_art_field(g_iartout, $Tftld::dpivot)


# Calcul de la variable MONO_DCI
erreur_860026368 = i_get_art_str(g_iartout,$Tftld::FSENT, pt_fsent_860026368)
erreur_860026368 = i_get_art_str(g_iartout,$Tftld::FSSORT, pt_fssort_860026368)
#G4R2C12 QC729

#G4R4 lot2
#SI (i_strcmp(i_get_tab_field( "code_apache", date_pivot, C_ENVCORR ) , "0") == 0)
#ALORS
#	MONO_DCI = 1
#SINON


# Recherche dans la table externe, de la valeur correspondante a la cle
i_get_sub_str(pt_fsent_860026368,0,3,pt_BUF_860026368)

trace2("====== pt_fsent=%s",pt_BUF_860026368,"")
erreur_860026368 = i_format_str2( pt_TEMP1_860026368, "%s%s", "CTI4G", pt_BUF_860026368 )
i_get_sub_str(pt_fssort_860026368,0,3,pt_BUF_860026368)

trace2("====== pt_fssort=%s",pt_BUF_860026368,"")
erreur_860026368 = i_format_str2( pt_TEMP2_860026368, "%s%s", "CTI4G", pt_BUF_860026368 )

pt_fsentft_860026368  = i_get_tab_field( "code_apache", date_pivot_860026368, pt_TEMP1_860026368 )
pt_fssortft_860026368 = i_get_tab_field( "code_apache", date_pivot_860026368, pt_TEMP2_860026368 )

trace2("====== pt_fsentft=>%s< ===== pt_fssortft=>%s<",pt_fsentft_860026368,pt_fssortft_860026368)
trace2("====== pt_TEMP1=%s ==== pt_TEMP2=%s",pt_TEMP1_860026368,pt_TEMP2_860026368)


# Recherche du debut du nom des faiseaux entrant et sortant
i_get_sub_str(pt_fsent_860026368,0,1,pt_TEMP1_860026368)
i_get_sub_str(pt_fssort_860026368,0,1,pt_TEMP2_860026368)

trace2("====== pt_TEMP1=%s ==== pt_TEMP2=%s",pt_TEMP1_860026368,pt_TEMP2_860026368)
SI ( (i_strcmp(pt_TEMP1_860026368,"WW") != 0) && (i_strcmp(pt_TEMP2_860026368,"WW") != 0) && (pt_fsentft_860026368 == g_inull) && (pt_fssortft_860026368 == g_inull) )
ALORS
	MONO_DCI_860026368 = 1
FINSI

#FINSI
trace1("======= MONO_DCI = %d =======",MONO_DCI_860026368)


#--------------------------------------------------------
#--	 Extraction du prefixe de portabilite  PREFPORTNDE et NDE
#---------------------------------------------------------
erreur_860026368 = i_get_art_str(g_iartout,$Tftld::NDE, pt_NDE1_860026368)
erreur_860026368 = i_get_art_str(g_iartout,$Tftld::NDE, pt_cle_860026368)
TYPDE_860026368 = i_get_art_field(g_iartout, $Tftld::TYPDE)


# CAS nature International sinon nature National
i_strcpy(pt_return_TablePort_860026368, "")

SI ( TYPDE_860026368 == 0x01 )
ALORS
	#size cas international
	i_get_sub_str(pt_NDE1_860026368, 0, 1, pt_CC2_860026368)
	i_get_sub_str(pt_NDE1_860026368, 0, 2, pt_CC3_860026368)

	SI  (i_strcmp(pt_CC2_860026368,"33") == 0)
	ALORS
		#National
		# cle pour interroger la table Prefixe_Portabilite
		i_get_sub_str (pt_NDE1_860026368, 2, -1, pt_cle_860026368)
		# pour calculer NDE dans le cas pas de portabilite (suppression du 33)
		i_strcpy(pt_NDE1_860026368, pt_cle_860026368)

		#====== DRE Debut G3R16 lot1 HUB NP
		TYPDE_860026368 = 0x04
	SINON
		SI (i_strcmp(pt_CC3_860026368, "590") == 0 || i_strcmp(pt_CC3_860026368, "594") == 0 || i_strcmp(pt_CC3_860026368, "596") == 0 || i_strcmp(pt_CC3_860026368, "262") == 0)
		ALORS
			#DOM
			# cle pour interroger la table Prefixe_Portabilite suppression du code pays
			i_get_sub_str(pt_NDE1_860026368, 3, -1, pt_cle_860026368)
			i_strcpy(pt_return_TablePort_860026368, table_exp_reg_860026233(pt_cle_860026368, Prefixe_Portabilite_860026368, date_pivot_860026368) )

			SI ( i_strcmp(pt_return_TablePort_860026368, g_inull) != 0 )
			ALORS
				#calcul du NDE sans le prefix de portabilite ccc+num
				size_Port_860026368 = CONV_ASCIINUMDEC_INT_860026233(pt_return_TablePort_860026368)
				i_get_sub_str(pt_cle_860026368,size_Port_860026368, -1, pt_cle_860026368)
				erreur_860026368 = i_format_str2(pt_NDE1_860026368, "%s%s", pt_CC3_860026368, pt_cle_860026368)
			FINSI
		SINON
			#Etranger NDE=PPYNum
			i_strcpy(pt_return_TablePort_860026368, table_exp_reg_860026233(pt_cle_860026368, Prefixe_Portabilite_Inter_860026368, date_pivot_860026368) )

			SI(i_strcmp(pt_return_TablePort_860026368,g_inull) != 0)
			ALORS
				i_get_sub_str(pt_return_TablePort_860026368, 0, 0, pt_TEMP1_860026368)
				size_PPY_860026368 = CONV_ASCIINUMDEC_INT_860026233(pt_TEMP1_860026368)
				i_get_sub_str(pt_return_TablePort_860026368, 1, 1, pt_TEMP1_860026368)
				size_Port_860026368 = CONV_ASCIINUMDEC_INT_860026233(pt_TEMP1_860026368)
				#calcul du NDE sans le prefixe de portabilite PPY+num
				#NUM
				i_get_sub_str(pt_NDE1_860026368, size_PPY_860026368 + size_Port_860026368, -1, pt_cle_860026368)
				#PPY
				i_get_sub_str(pt_NDE1_860026368, 0, size_PPY_860026368 - 1, pt_TEMP1_860026368)
				erreur_860026368 = i_format_str2(pt_NDE1_860026368, "%s%s", pt_TEMP1_860026368, pt_cle_860026368)
			FINSI
		FINSI
	FINSI
FINSI
	
SI (TYPDE_860026368 == 0x04)
ALORS
	i_strcpy(pt_return_TablePort_860026368,table_exp_reg_860026233(pt_cle_860026368, Prefixe_Portabilite_860026368, date_pivot_860026368))

	SI ( i_strcmp(pt_return_TablePort_860026368, g_inull) != 0 )
	ALORS
		size_Port_860026368 = CONV_ASCIINUMDEC_INT_860026233(pt_return_TablePort_860026368)
		i_get_sub_str(pt_cle_860026368, size_Port_860026368,-1,pt_NDE1_860026368)
	FINSI
FINSI

##### G4R6 Lot3 #####
#---------------------------------
# Recuperation de NDE normalise
#---------------------------------
longueur_860026368 = i_conv_ascii_dcb(pt_NDE1_860026368, pt_NDE_NORM_860026368)


#-------------------------------------------------
#-- 	calcul du PREFPORT a partir du NDES
#-------------------------------------------------
erreur_860026368 = i_get_art_str(g_iartout, $Tftld::NDES, pt_NDES1_860026368)
TYPDES_860026368 = i_get_art_field(g_iartout, $Tftld::TYPDES)
i_strcpy(pt_return_TablePort_860026368, "")


# init pt_PREFPORT avec 10 espaces
i_strcpy(pt_PREFPORT_860026368, "          ")

SI ( TYPDES_860026368 == 0x01 )
ALORS
	i_get_sub_str(pt_NDES1_860026368, 0, 1, pt_CC2_860026368)
	i_get_sub_str(pt_NDES1_860026368, 0, 2, pt_CC3_860026368)

	SI ( i_strcmp(pt_CC2_860026368, "33") == 0 )
	ALORS
		i_get_sub_str(pt_NDES1_860026368, 2, -1, pt_NDES1_860026368 )
		i_strcpy( pt_return_TablePort_860026368, table_exp_reg_860026233(pt_NDES1_860026368, Prefixe_Portabilite_860026368, date_pivot_860026368) )

		SI(i_strcmp(pt_return_TablePort_860026368,g_inull) != 0)
		ALORS
			res_860026368 = CONV_ASCIINUMDEC_INT_860026233(pt_return_TablePort_860026368)
			i_get_sub_str(pt_NDES1_860026368, 0, res_860026368 - 1, pt_PREFPORT_860026368)
		FINSI
	SINON
		# DOM
		SI ( i_strcmp(pt_CC3_860026368, "590") == 0 || i_strcmp(pt_CC3_860026368, "594") == 0 || i_strcmp(pt_CC3_860026368, "596") == 0 || i_strcmp(pt_CC3_860026368, "262") == 0 )
		ALORS
			i_get_sub_str(pt_NDES1_860026368, 3, -1, pt_NDES1_860026368)
			i_strcpy(pt_return_TablePort_860026368, table_exp_reg_860026233(pt_NDES1_860026368, Prefixe_Portabilite_860026368, date_pivot_860026368))
			SI ( i_strcmp(pt_return_TablePort_860026368, g_inull) != 0 )
			ALORS
				res_860026368 = CONV_ASCIINUMDEC_INT_860026233(pt_return_TablePort_860026368)
				i_get_sub_str(pt_NDES1_860026368, 0, res_860026368 - 1, pt_PREFPORT_860026368)
			FINSI
		SINON
			#Etranger
			i_strcpy(pt_return_TablePort_860026368, table_exp_reg_860026233(pt_NDES1_860026368, Prefixe_Portabilite_Inter_860026368, date_pivot_860026368) )

			SI ( i_strcmp(pt_return_TablePort_860026368, g_inull) != 0 )
			ALORS
				i_get_sub_str(pt_return_TablePort_860026368, 0, 0, pt_TEMP1_860026368)
				size_PPY_860026368 = CONV_ASCIINUMDEC_INT_860026233(pt_TEMP1_860026368)	
				i_get_sub_str(pt_return_TablePort_860026368, 1, 1, pt_TEMP1_860026368)
				size_Port_860026368 = CONV_ASCIINUMDEC_INT_860026233(pt_TEMP1_860026368)	
				#calcul du PREFPORT 
				i_get_sub_str(pt_NDES1_860026368, size_PPY_860026368,size_PPY_860026368 + size_Port_860026368 - 1, pt_PREFPORT_860026368)
			FINSI
		FINSI
	FINSI
FINSI

SI (TYPDES_860026368 == 0x04)
ALORS
	i_strcpy(pt_return_TablePort_860026368, table_exp_reg_860026233(pt_NDES1_860026368, Prefixe_Portabilite_860026368, date_pivot_860026368))
	SI ( i_strcmp(pt_return_TablePort_860026368, g_inull) != 0 )
	ALORS
		res_860026368 = CONV_ASCIINUMDEC_INT_860026233(pt_return_TablePort_860026368)
		i_get_sub_str(pt_NDES1_860026368, 0, res_860026368 - 1, pt_PREFPORT_860026368)
	FINSI
FINSI


############################################################################
# Recherche Instances des ECC
############################################################################

######################################
#G4R4 lot2	 ENTROPI Remplace SAFIREIPMONO

######################################
#ENTROPI DC Efficace
instENTREFF_860026368=i_LireInstanceECC(C_InstENTREFF_860026368)
trace1("========= instENTREFF = %d ======",instENTREFF_860026368)

SI (!instENTREFF_860026368)
ALORS
	#trace("Pas d'instance pour ENTREFF!")
	code_errone_860026368 = 0xA0B0
	code_errone_860026368 = code_errone_860026368 + EFFICACE_860026368
	erreur_860026368 = i_PlvMessEmettre(8601, 2, g_iartin, "", 3, code_errone_860026368,C_InstENTREFF_860026368, C_Article_860026368)
	SAUT DISTRI_ERR
FINSI

######################################
#ENTROPI DC Inefficace
instENTRINEF_860026368=i_LireInstanceECC(C_InstENTRINEF_860026368)
trace1("========= instENTRINEF = %d ======",instENTRINEF_860026368)

SI (!instENTRINEF_860026368)
ALORS
	#trace("Pas d'instance pour ENTRINEF!")
	code_errone_860026368 = 0xA0B0
	code_errone_860026368 = code_errone_860026368 + EFFICACE_860026368
	erreur_860026368 = i_PlvMessEmettre(8601, 2, g_iartin, "", 3, code_errone_860026368,C_InstENTRINEF_860026368,C_Article_860026368)
	SAUT DISTRI_ERR
FINSI

######################################
#G4R4 lot2	  Suppression SafireIN (instSAFIRE )

######################################
# SPOT
instSPOT_860026368 = i_LireInstanceECC( C_InstSPOT_860026368 )
trace1("========= instSPOT = %d ======",instSPOT_860026368)

SI (!instSPOT_860026368)
ALORS
	code_errone_860026368 = 0xA0B0
	code_errone_860026368 = code_errone_860026368 + EFFICACE_860026368
	erreur_860026368 = i_PlvMessEmettre(8601, 2, g_iartin, "", 3, code_errone_860026368, C_InstSPOT_860026368, C_Article_860026368)
	SAUT DISTRI_ERR
FINSI

######################################
# Symphonie 
instSYMPH_860026368=i_LireInstanceECC(C_InstSYMP_860026368)
trace1("========= instSYMPH = %d ======",instSYMPH_860026368)

SI (!instSYMPH_860026368)
ALORS
	code_errone_860026368 = 0xA0B0
	code_errone_860026368 = code_errone_860026368 + EFFICACE_860026368
	erreur_860026368 = i_PlvMessEmettre(8601, 2, g_iartin, "", 3, code_errone_860026368,C_InstSYMP_860026368, C_Article_860026368)
	SAUT DISTRI_ERR
FINSI

######################################
#G4R4 lot2	SUPPRESSION TRANSIT (instTRANSIT )

######################################
# CENTHF
instCENTHF_860026368 = i_LireInstanceECC( C_InstCENTHF_860026368 )
trace1("========= instCENTHF = %d ======",instCENTHF_860026368)

SI (!instCENTHF_860026368)
ALORS
	code_errone_860026368 = 0xA0B0
	code_errone_860026368 = code_errone_860026368 + EFFICACE_860026368
	erreur_860026368 = i_PlvMessEmettre(8601, 2, g_iartin, "", 3, code_errone_860026368, C_InstCENTHF_860026368, C_Article_860026368)
	SAUT DISTRI_ERR
FINSI

############################################################################
# Criteres communs
############################################################################

#DATE_PLATINE
ICAR_ABS_860026368 = i_get_art_field(g_iartin, $Tftld::DATE)

erreur_860026368 = i_get_attr_str_n ( $E_FTLD::SoNuS,  pt_valeur_860026368)
#G4R4C2 QC754 #erreur = i_set_attr_val_n( $E_FTLD::EFFICACE, EFFICACE)

ICAR_860026368 = i_get_attr_val_n ( $E_FTLD::DateMetroDeb )

SI ( i_strcmp(pt_valeur_860026368,"6") == 0 )
ALORS
	#DC SONUS HD
	b_SONUSHD_860026368 = 1
FINSI

#DATE_LOCALE
NUMZONE_860026368 = i_DHgetZoneID(NUMTABSEL_860026368, g_iartout)
date_locale_860026368 = i_DHgetLocalTime(NUMTAB2_860026368, NUMZONE_860026368, ICAR_860026368)

SI( date_locale_860026368 == -1 )
ALORS
	code_errone_860026368 = 0xA080
	code_errone_860026368 = code_errone_860026368 + EFFICACE_860026368
	erreur_860026368 = i_PlvMessEmettre(8600, 2, g_iartin, "", 3, code_errone_860026368, C_Article_860026368, "i_DHgetLocalTime")
	SAUT DISTRI_ERR
FINSI

# DATE_LOCALE_FIN
date_locale_fin_860026368 = date_locale_860026368 + DUREE_860026368

# DATE_METRO_FIN
date_Metro_fin_860026368 = ICAR_860026368 + DUREE_860026368

#DATE_DEBUT GMT 
date_debut_gmt_860026368 = i_DHgetCe2gTime(NUMTAB1_860026368, ZONE_METRO_860026368, ICAR_860026368)

# DATE_FIN GMT
date_fin_GMT_860026368 = date_debut_gmt_860026368 + DUREE_860026368

# DATE FIN GMT EN UNIX
#    Pour avoir une date de fin GMT en seconde depuis 1970 (date UNIX)
#    on retire la valeur de la constante C_NB_1970, representant le delta(hexa) en seconde
#    entre 1970 et 1900
date_fin_GMT_UNIX_860026368 = date_fin_GMT_860026368  - C_NB_1970_860026368

#Recherche criteres pour envoi a CENTHF
i_get_sub_str(pt_fssort_860026368, 0, 4, pt_TEMP2_860026368)
i_strcpy(pt_return_TFAISCEAU_860026368, i_get_tab_field( "TFAISCEAU", date_pivot_860026368, pt_TEMP2_860026368 ) )

SI ( i_strcmp(pt_return_TFAISCEAU_860026368, g_inull) != 0 )
ALORS
	i_get_sub_str(pt_return_TFAISCEAU_860026368, 0, 7, pt_DateDeb_860026368)
	i_get_sub_str(pt_return_TFAISCEAU_860026368,8,15,pt_DateFin_860026368)
	
	erreur_860026368 = i_set_art_str(g_iartout10, $Conversion::DATE_STR, pt_DateDeb_860026368)
	DateDeb_860026368 = i_get_art_field(g_iartout10, $Conversion::DATE_ASC)
	
	erreur_860026368 = i_set_art_str(g_iartout10, $Conversion::DATE_STR, pt_DateFin_860026368)
	DateFin_860026368 = i_get_art_field(g_iartout10, $Conversion::DATE_ASC)

	SI ICAR_860026368 >= DateDeb_860026368 && ICAR_860026368 <= DateFin_860026368
	ALORS
		TFAISCEAU_860026368 = 1
	FINSI
FINSI

i_strcpy(pt_CATLIG_860026368, "00")
SI b_SONUSHD_860026368 == 1
ALORS
	CATLIG_860026368 = i_get_art_field(g_iartout, $Tftld::CATLIG)

	erreur_860026368 = i_set_art_field(g_iartout10, $Conversion::REF_NUM, CATLIG_860026368)
	erreur_860026368 = i_get_art_str(g_iartout10, $Conversion::REF_TAB, pt_CATLIG_860026368)
	i_get_sub_str(pt_CATLIG_860026368, -2, -1, pt_CATLIG_860026368)
FINSI

############################################################################
# Creation de l'enveloppe optionnelle E_FTLD pour passage vers IECC(dlot_rel)
############################################################################
#---------------------
#  AJOUT ENVELOPPE Optionelle:
# Ajout enveloppe optionnelle E_FTLD
# Contient la date locale pour la distri
#---------------------
# Creation de l'enveloppe

#  Mise a jour de l'ENVELOPPE Optionelle:
# Contient la date de fin locale et metropole necessaire pour les metachamps de distri


############################################################################
# Valeur du code SGTQS
############################################################################
erreur_860026368 = i_get_art_str(g_iartin, $Tftld::SGTQS, pt_sgtqs_860026368)


############################################################################
# Critere de distribution vers CENTHF
############################################################################
i_get_sub_str(pt_fssort_860026368, 0, 1, pt_TEMP1_860026368)

##### G4R6 Lot3 #####
SI ( EFFICACE_860026368  && instCENTHF_860026368 && DUREE_860026368 != 0 && i_strcmp(pt_fssort_860026368, "       ") != 0 && i_strcmp(pt_TEMP1_860026368, "WW") != 0 && TFAISCEAU_860026368 == 1 && (MONO_DCI_860026368 == 1 || pt_fssortft_860026368 == g_inull) )
ALORS
	trace("===== Ajout de CENTHF a la liste courante des ECC:===")
	#erreur=i_AjouterCouranteECC(instCENTHF)
	# CENTHF ne doit pas etre consideree comme une ECC de facturation 
	b_CENTHF_860026368 = 1
FINSI

SI b_CENTHF_860026368
ALORS
	i_strcpy(pt_TEMP1_860026368, i_get_tab_field( "TDATCPS", date_debut_gmt_860026368, "DATCPS" ))
	erreur_860026368 = i_set_art_str (g_iartout10,$Conversion::DATE_STR,pt_TEMP1_860026368)
	Date_CPS_860026368 = i_get_art_field(g_iartout10, $Conversion::DATE_ASC)
	
	SI ICAR_ABS_860026368 > Date_CPS_860026368
	ALORS

		#######################################
		#  Soumission de la requete de consultation d'une table de distribution ALICE
		#######################################
		SI ( i_EnvoiReqConsTabDist( TD_SVA_860026368, date_debut_gmt_860026368, pt_NDE_NORM_860026368, longueur_860026368, 0, 1) != 0 )
		ALORS
			#trace("Erreur i_EnvoiReqConsTabDist ALICE")
			bREDIST_860026368 = 1
			i_strcpy(pt_LIBELREDIST_860026368, "Echec sur i_EnvoiReqConsTabDistDouble ALICE ")
		FINSI

		#######################################
		# Recherche de l'instance ECC ALICE
		#######################################
		instALICE_860026368 = i_LireInstanceECC(C_INST_ALICE_860026368)
		SI (!instALICE_860026368)
		ALORS
			#trace("Pas d'instance pour ALICE !")
			erreur_860026368 = i_PlvMessEmettre(8501, 1, g_iartout, "", 3, C_INST_ALICE_860026368, C_Article_860026368, g_ieec)
			SAUT DISTRI_ERR
		FINSI
		#trace1("instALICE  =<%d>",instALICE)	

		#######################################
		# Lecture Resultat requete ALICE
		#######################################
		erreur_860026368 = i_LireReqConsTabDist()
		#trace1("RETOUR i_LireReqConsTabDist retour requette ALICE, erreur=<%d>",erreur)
		SI ( erreur_860026368 != 0 )
		ALORS
			#trace1( "Erreur i_LireReqConsTabDist ALICE: <%d>", erreur)
			bREDIST_860026368 = 1
			i_strcpy(pt_LIBELREDIST_860026368,"Echec sur i_LireReqConsTabDistDouble ALICE ")
		FINSI

		val_860026368 = i_LireInfoECC( instALICE_860026368, 0 )
		i_strcpy(pt_TEMP1_860026368,"")

		SI (val_860026368 != 0)
		ALORS
			# AR present dans ALICE
			erreur_860026368 = i_LireChaineInfo( val_860026368, 0, 4, pt_TEMP1_860026368 )

			SI i_strcmp(pt_TEMP1_860026368,"") != 0
			ALORS
				i_strcpy(pt_CODE_TARIF_860026368,pt_TEMP1_860026368)
				b_ALICE_860026368 = 1
			SINON
				# info complementaire CODE_TARIF vide
				bREDIST_860026368 = 1
				erreur_860026368 = i_format_str2(pt_LIBELREDIST_860026368," AR <%s> trouve dans LAR ALICE mais aucune info complementaire valorisee",pt_NDE1_860026368,0)
			FINSI

			erreur_860026368 = i_LireChaineInfo( val_860026368, 4, 1, pt_TEMP1_860026368 )
			SI i_strcmp(pt_TEMP1_860026368,"") != 0
			ALORS
				i_strcpy(pt_TYPE_EDIT_860026368,pt_TEMP1_860026368)
				b_ALICE_860026368 = 1
			SINON
				# info complementaire TYPE_EDIT vide
				bREDIST_860026368 = 1
				erreur_860026368 = i_format_str2(pt_LIBELREDIST_860026368," AR <%s> trouve dans LAR ALICE mais aucune info complementaire valorisee",pt_NDE1_860026368,0)
			FINSI
		SINON
			erreur_860026368 = i_format_str2(pt_LIBELREDIST_860026368," AR <%s> non trouve dans ALICE",pt_NDE1_860026368,0)
			trace2("__FILE__:__LINE__ ## TEST ## ======> pt_LIBELREDIST <%s> #### ",pt_LIBELREDIST_860026368 ,"")
			#erreur = i_PlvMessEmettre(8503, 2, g_iartin, "", 3, pt_LIBELREDIST, C_Article, pt_sgtqs)
		FINSI
	FINSI
FINSI


SI b_CENTHF_860026368 && ( !bREDIST_860026368 || ( bREDIST_860026368 && CPT_REDIST_860026368 == 2 ) )
ALORS
	erreur_860026368=i_AjouterCouranteECC(instCENTHF_860026368)
FINSI


############################################################################
#G4R4 lot2 Critere de distribution vers ENTROPI
############################################################################
##### G4R6 Lot3 #####
SI !bREDIST_860026368 || ( bREDIST_860026368 && CPT_REDIST_860026368 == 2 )
ALORS
	SI ( EFFICACE_860026368 && DUREE_860026368 != 0 && i_strcmp(pt_fssort_860026368, "       ") != 0 )
	ALORS
		#trace1("  ENTROPI (ENTREFF) <%d> sera alimente", instENTREFF)
		#G4R4C2 QC754 
		erreur_860026368 = i_set_attr_val_n( $E_FTLD::EnvoiEFF, 0x01)
		erreur_860026368=i_AjouterCouranteECC(instENTREFF_860026368)
		i_strcpy(pt_nomECCFact_860026368, "ENTROPI")
	SINON
		#trace1("  ENTROPI (ENTRINEF) <%d> sera alimente", instENTRINEF)
		#G4R4C2 QC754 
		erreur_860026368 = i_set_attr_val_n( $E_FTLD::EnvoiEFF, 0x00)
		erreur_860026368=i_AjouterCouranteECC(instENTRINEF_860026368)
		i_strcpy(pt_nomECCFact_860026368, "ENTROPI")
	FINSI
FINSI


############################################################################
#G4R4 lot2 suppression distribution vers SAFIRE
############################################################################


############################################################################
#G4R4 lot2 suppression distribution vers TRANSIT
############################################################################


############################################################################
# Validation de la liste des ECCs destinatrices
############################################################################
erreur_860026368 = i_ValiderListeECC( 0, 0, 0, 0)


########################################################################################################
# G4R4 lot2  Mise au format pour ENTROPI (ENTREFF ou ENTRINEF
########################################################################################################
SI ( !i_ChercherCouranteECC(instENTREFF_860026368) || !i_ChercherCouranteECC(instENTRINEF_860026368) )
ALORS
	#trace("Duplication vers ENTROPI")
	#i_strcpy(pt_nomECCFact,"ENTROPI")

	# Duplication de l article
	SI ( i_dup_art_dest(g_iartin,g_iartout2,C_Tentr101_860026368) )
	ALORS
		#trace("Erreur de i_dup_art_dest")
		code_errone_860026368 = 0xA0D0
		code_errone_860026368 = code_errone_860026368 + EFFICACE_860026368
		erreur_860026368 = i_PlvMessEmettre(8602, 2, g_iartin, "", 3, code_errone_860026368, C_Tentr101_860026368, C_Article_860026368)
		SAUT  DISTRI_ERR
	FINSI

	# Champ DATE 
	erreur_860026368 = i_set_art_field(g_iartout2, $Tentr101::DATE, ICAR_860026368)

	#IDUS.ABCDEF 
	erreur_860026368 = i_set_art_str(g_iartout2, $Tentr101::IDUS_AaF, pt_CATLIG_860026368)

	# Champ IDUS_GH
	TYPDR_860026368 = i_get_art_field(g_iartout, $Tftld::TYPDR)

	SI (TYPDR_860026368 == 0x01)
	ALORS
		erreur_860026368 = i_set_art_field(g_iartout2, $Tentr101::IDUS_GH, 3)
	SINON
		SI (TYPDR_860026368 == 0x02)
		ALORS
			erreur_860026368 = i_set_art_field(g_iartout2, $Tentr101::IDUS_GH, 1)
		SINON
			SI (TYPDR_860026368 == 0x03)
			ALORS
				erreur_860026368 = i_set_art_field(g_iartout2, $Tentr101::IDUS_GH, 0)
			SINON
				SI (TYPDR_860026368 == 0x04)
				ALORS
					erreur_860026368 = i_set_art_field(g_iartout2, $Tentr101::IDUS_GH, 2)
				FINSI
			FINSI
		FINSI
	FINSI

	# Champ IDUS_NUM
	erreur_860026368 = i_get_art_str(g_iartout, $Tftld::NDR, pt_TEMP1_860026368)
	i_replace_str(pt_TEMP1_860026368, "BC", "*#", pt_TEMP1_860026368)
	erreur_860026368 = i_set_art_str(g_iartout2, $Tentr101::IDUS_NUM, pt_TEMP1_860026368)

	# CAUSE_CODE
	res_860026368 = 000
	SI ( i_valid_field_n(g_iartin, $Tftld::CCODE) )
	ALORS
		res_860026368 = i_get_art_field(g_iartin, $Tftld::CCODE)
	FINSI
	erreur_860026368 = i_set_art_field(g_iartout2, $Tentr102::CAUSE_CODE, res_860026368)

	# Champ DEDE_NUM
	i_replace_str(pt_NDE1_860026368, "BC", "*#", pt_TEMP2_860026368)
	erreur_860026368 = i_set_art_str(g_iartout2, $Tentr101::DEDE_NUM, pt_TEMP2_860026368)

	# Champ DUREE
	erreur_860026368 = i_set_art_field(g_iartout2, $Tentr101::DUREE, DUREE_860026368)

	# Champ CTISI_CD
	erreur_860026368 = i_set_art_field(g_iartout2, $Tentr101::CTISI_CD, 0)

	# Champ CTISI_GH
	res_860026368 = i_get_art_field(g_iartout, $Tftld::TSC) & 0x03
	erreur_860026368 = i_set_art_field(g_iartout2, $Tentr101::CTISI_GH, res_860026368)

	#Champ NDES_NUM
	erreur_860026368 = i_get_art_str(g_iartout, $Tftld::NDES, pt_TEMP2_860026368)
	i_replace_str(pt_TEMP2_860026368, "BC", "*#", pt_TEMP2_860026368)
	erreur_860026368 = i_set_art_str(g_iartout2, $Tentr101::NDES_NUM, pt_TEMP2_860026368)

	#Champ NDES_Nat
	TYPDR_860026368 = i_get_art_field(g_iartout, $Tftld::TYPDES)

	SI ( TYPDR_860026368 == 0x00 || TYPDR_860026368 == 0x04 )
	ALORS
		erreur_860026368 = i_set_art_field(g_iartout2, $Tentr101::NDES_Nat, 2)
	SINON
		SI ( TYPDR_860026368 == 0x01 )
		ALORS
			erreur_860026368 = i_set_art_field(g_iartout2, $Tentr101::NDES_Nat, 3)
		SINON
			SI ( TYPDR_860026368 == 0x02 )
			ALORS
				erreur_860026368 = i_set_art_field(g_iartout2, $Tentr101::NDES_Nat, 0)
			SINON
				erreur_860026368 = i_set_art_field(g_iartout2, $Tentr101::NDES_Nat, 1)
			FINSI
		FINSI
	FINSI

	#Champ PREFPORT
	erreur_860026368 = i_set_art_str(g_iartout2, $Tentr101::PREFPORT, pt_PREFPORT_860026368)

	# Champ NBRE
	erreur_860026368 = i_set_art_field(g_iartout2, $Tentr101::NBRE, 1)

	# Champ TYPAP_ABC
	erreur_860026368 = i_set_art_field(g_iartout2, $Tentr101::TYPAP1_ABC, 6)

	# Champ TYPAP.DE
	SI ( TYPDE_860026368 == 0x00 || TYPDE_860026368 == 0x04 )
	ALORS
		erreur_860026368 = i_set_art_field(g_iartout2, $Tentr101::TYPAP1_DE, 2)
	SINON
		SI ( TYPDE_860026368 == 0x01 )
		ALORS
			erreur_860026368 = i_set_art_field(g_iartout2, $Tentr101::TYPAP1_DE, 3)
		SINON
			SI ( TYPDE_860026368 == 0x02 )
			ALORS
				erreur_860026368 = i_set_art_field(g_iartout2, $Tentr101::TYPAP1_DE, 0)
			SINON
				erreur_860026368 = i_set_art_field(g_iartout2, $Tentr101::TYPAP1_DE, 1)
			FINSI
		FINSI
	FINSI

	# Champ TYPAP_F
	erreur_860026368 = i_set_art_field(g_iartout2, $Tentr101::TYPAP1_F, 0)

	# Champ TYPAP_G
	erreur_860026368 = i_set_art_field(g_iartout2, $Tentr101::TYPAP1_G, 0)

	# Champ SGTQS
	i_get_sub_str(pt_sgtqs_860026368, 0, 3, pt_TEMP1_860026368)
	erreur_860026368 = i_set_art_str(g_iartout2, $Tentr101::SGTQS1, pt_TEMP1_860026368)

	# Champ FAISCENT
	i_get_sub_str(pt_fsent_860026368, 0, 4, pt_TEMP1_860026368)
	erreur_860026368 = i_set_art_str(g_iartout2, $Tentr101::FAISCENT1, pt_TEMP1_860026368)

	# Champ FAISSORT
	i_get_sub_str(pt_fssort_860026368, 0, 4, pt_TEMP2_860026368)
	erreur_860026368 = i_set_art_str(g_iartout2, $Tentr101::FAISSORT1, pt_TEMP2_860026368)

	#FIN
	erreur_860026368 = i_set_art_field(g_iartout2, $Tentr101::FIN, 0x0A )
FINSI


############################################################################
#G4R4 lot2 Arret Mises au format SAFIREIN
############################################################################


############################################################################
# Mises au format CENTHF
############################################################################
SI ( !i_ChercherCouranteECC(instCENTHF_860026368) )
ALORS
	#trace("Duplication vers CENTHF")

	# Duplication article en entree
	SI (i_dup_art_dest( g_iartout, g_iartout6, C_TcentHF_860026368 ))
	ALORS
		code_errone_860026368 = 0xA0D0
		code_errone_860026368 = code_errone_860026368 + EFFICACE_860026368
		erreur_860026368 = i_PlvMessEmettre(8602, 2, g_iartin, "", 3, code_errone_860026368, C_TcentHF_860026368, C_Article_860026368)
		SAUT DISTRI_ERR
	FINSI

  	erreur_860026368 = i_set_art_field(g_iartout6, $TcentHF::DATE, ICAR_860026368)

	# Champ IDUS_AaF
	erreur_860026368 = i_get_art_str(g_iartout, $Tftld::CATLIG, pt_TEMP1_860026368)
	erreur_860026368 = i_format_str2( pt_typap_860026368, "%s%s", pt_TEMP1_860026368, "2" )

	i_strcpy(pt_valeur1_860026368, i_get_tab_field("typap", date_pivot_860026368, pt_typap_860026368 ) )
	SI ( i_strcmp(pt_valeur1_860026368,"") == 0 )
	ALORS
		i_strcpy(pt_valeur1_860026368, "10")
	FINSI

	erreur_860026368 = i_set_art_str(g_iartout10, $Conversion::IDUS_AaF, pt_valeur1_860026368)
	erreur_860026368 = i_conv_field("IDUS_AaF", g_iartout10, 3, g_iartout6, 3, 0)

	# Champ IDUS_GH
	TYPDR_860026368 = i_get_art_field(g_iartout, $Tftld::TYPDR)

	SI ( TYPDR_860026368 == 0x01 )
	ALORS
		erreur_860026368 = i_set_art_field(g_iartout6, $TcentHF::IDUS_GH, 3)
	SINON
		SI ( TYPDR_860026368 == 0x02 )
		ALORS
			erreur_860026368 = i_set_art_field(g_iartout6, $TcentHF::IDUS_GH, 1)
		SINON
			SI ( TYPDR_860026368 == 0x03 )
			ALORS
				erreur_860026368 = i_set_art_field(g_iartout6, $TcentHF::IDUS_GH, 0)
			SINON
				SI ( TYPDR_860026368 == 0x04 )
				ALORS
					erreur_860026368 = i_set_art_field(g_iartout6,$TcentHF::IDUS_GH, 2)
				FINSI
			FINSI
		FINSI
	FINSI

	# Champ IDUS_NUM
	erreur_860026368 = i_get_art_str(g_iartout, $Tftld::NDR, pt_TEMP1_860026368)
	i_replace_str(pt_TEMP1_860026368, "BC", "*#", pt_TEMP1_860026368)
	erreur_860026368 = i_set_art_str(g_iartout6, $TcentHF::IDUS_NUM, pt_TEMP1_860026368)

	# Champ DEDE_INF
	erreur_860026368 = i_set_art_field(g_iartout6, $TcentHF::DEDE_INF, 0x80)

	# Champ DEDE_NUM
	i_replace_str(pt_NDE1_860026368, "BC", "*#", pt_TEMP2_860026368)
	erreur_860026368 = i_set_art_str(g_iartout6, $TcentHF::DEDE_NUM, pt_TEMP2_860026368)

	# Champ DUREE
	erreur_860026368 = i_set_art_field(g_iartout6, $TcentHF::DUREE, DUREE_860026368)

	# Champ CTISI_CD
	erreur_860026368 = i_set_art_field(g_iartout6, $TcentHF::CTISI_CD, 0)

	# Champ CTISI_GH
	res_860026368 = i_get_art_field(g_iartout, $Tftld::TSC) & 0x03
	erreur_860026368 = i_set_art_field(g_iartout6, $TcentHF::CTISI_GH, res_860026368)

	#Champ NDES_NUM
	erreur_860026368 = i_get_art_str(g_iartout, $Tftld::NDES, pt_TEMP2_860026368)
	i_replace_str(pt_TEMP2_860026368, "BC", "*#", pt_TEMP2_860026368)
	erreur_860026368 = i_set_art_str(g_iartout6, $TcentHF::NDES_NUM, pt_TEMP2_860026368)

	#Champ NDES_Nat
	TYPDR_860026368 = i_get_art_field(g_iartout, $Tftld::TYPDES)

	SI ( TYPDR_860026368 == 0x00 || TYPDR_860026368 == 0x04 )
	ALORS
		erreur_860026368 = i_set_art_field(g_iartout6, $TcentHF::NDES_Nat, 2)
	SINON
		SI (TYPDR_860026368 == 0x01)
		ALORS
			erreur_860026368 = i_set_art_field(g_iartout6, $TcentHF::NDES_Nat, 3)
		SINON
			SI (TYPDR_860026368 == 0x02)
			ALORS
				erreur_860026368 = i_set_art_field(g_iartout6, $TcentHF::NDES_Nat, 0)
			SINON
				erreur_860026368 = i_set_art_field(g_iartout6, $TcentHF::NDES_Nat, 1)
			FINSI
		FINSI
	FINSI

	#Champ PREFPORT
	erreur_860026368 = i_set_art_str(g_iartout6, $TcentHF::PREFPORT, pt_PREFPORT_860026368)

	# Champ NBRE
	erreur_860026368 = i_set_art_field(g_iartout6, $TcentHF::NBRE, 1)

	# Champ TYPAP_ABC
	erreur_860026368 = i_set_art_field(g_iartout6, $TcentHF::TYPAP1_ABC, 6)

	# Champ TYPAP.DE

	SI ( TYPDE_860026368 == 0x00 || TYPDE_860026368 == 0x04 )
	ALORS
		erreur_860026368 = i_set_art_field(g_iartout6, $TcentHF::TYPAP1_DE, 2)
	SINON
		SI (TYPDE_860026368 == 0x01)
		ALORS
			erreur_860026368 = i_set_art_field(g_iartout6, $TcentHF::TYPAP1_DE, 3)
		SINON
			SI (TYPDE_860026368 == 0x02)
			ALORS
				erreur_860026368 = i_set_art_field(g_iartout6, $TcentHF::TYPAP1_DE, 0)
			SINON
				erreur_860026368 = i_set_art_field(g_iartout6, $TcentHF::TYPAP1_DE, 1)
			FINSI
		FINSI
	FINSI

	# Champ TYPAP_F
	erreur_860026368 = i_set_art_field(g_iartout6, $TcentHF::TYPAP1_F, 0)

	# Champ TYPAP_G
	erreur_860026368 = i_set_art_field(g_iartout6, $TcentHF::TYPAP1_G, 0)

	# Champ SGTQS
	#\ Modif metachamp
	#erreur = i_get_art_str(g_iartout,$Tftld::SGTQS, pt_sgtqs)
	i_get_sub_str(pt_sgtqs_860026368, 0, 3, pt_TEMP1_860026368)
	erreur_860026368 = i_set_art_str(g_iartout6, $TcentHF::SGTQS1, pt_TEMP1_860026368)

	# Champ FAISCENT
	i_get_sub_str(pt_fsent_860026368, 0, 4, pt_TEMP1_860026368)
	erreur_860026368 = i_set_art_str(g_iartout6, $TcentHF::FAISCENT1, pt_TEMP1_860026368)

	# Champ FAISSORT
	i_get_sub_str(pt_fssort_860026368, 0, 4, pt_TEMP2_860026368)
	erreur_860026368 = i_set_art_str(g_iartout6, $TcentHF::FAISSORT1, pt_TEMP2_860026368)

	##### G4R6 Lot3 #####
	SI b_ALICE_860026368
	ALORS
		#TYPE_EDIT
		erreur_860026368 = i_set_art_str(g_iartout6, $TcentHF::TYPE_EDIT, pt_TYPE_EDIT_860026368 )
		#CODE_TARIF
		erreur_860026368 = i_set_art_str(g_iartout6, $TcentHF::CODE_TARIF, pt_CODE_TARIF_860026368 )
	FINSI

	#FIN
	erreur_860026368 = i_set_art_field(g_iartout6, $TcentHF::FIN, 0x0A )
FINSI


############################################################################
#G4R4 lot2 Arret Mises au format TRANSIT
############################################################################


############################################################################
# Duplication Symphonie
############################################################################

##### G4R6 Lot3 #####
SI !bREDIST_860026368 || ( bREDIST_860026368 && CPT_REDIST_860026368 == 0 ) 
ALORS
	SI ( instSYMPH_860026368 )
	ALORS
		# Ajout de SYMPHONIE a la liste courante des ECC:
		erreur_860026368=i_AjouterCouranteECC(instSYMPH_860026368)
	
		trace("Duplication vers Symphonie")
	
		SI (i_dup_art_id(g_iartout, g_iartout5))
		ALORS
			trace("ERREUR de duplication vers Symphonie")
			code_errone_860026368 = 0xA0D0
			code_errone_860026368 = code_errone_860026368 + EFFICACE_860026368
			erreur_860026368 = i_PlvMessEmettre(8602, 2, g_iartin, "", 3, code_errone_860026368, C_TsymTftld_860026368, C_Article_860026368)
			SAUT DISTRI_ERR
		FINSI
	
		SI (i_rename_art(g_iartout5, C_TsymTftld_860026368))
		ALORS
			trace("ERREUR de duplication vers Symphonie")
			code_errone_860026368 = 0xA0D0
			code_errone_860026368 = code_errone_860026368 + EFFICACE_860026368
			erreur_860026368 = i_PlvMessEmettre(8602, 2, g_iartin, "", 3, code_errone_860026368, C_TsymTftld_860026368, C_Article_860026368)
			SAUT DISTRI_ERR
		FINSI
	
		erreur_860026368 = i_ajoutChampNum(g_iartout5, $TsymTftld::T4eccfact,$TsymTftld::ECC_FACT,6)
		trace(" Ajout de champs supplementaires")
	
		# Champ ECC_FACT
		erreur_860026368 = i_set_art_str(g_iartout5, $TsymTftld::ECC_FACT, pt_nomECCFact_860026368)
	
		# Champ SGTQS1
		i_get_sub_str(pt_sgtqs_860026368,0,5,pt_TEMP1_860026368)
		erreur_860026368 = i_set_art_str(g_iartout5, $TsymTftld::SGTQS1, pt_TEMP1_860026368)
	
		# champ CCD
		erreur_860026368 = i_set_art_field(g_iartout5, $TsymTftld::CCD, 216)
	
		# date_locale
		erreur_860026368 = i_set_art_field(g_iartout5, $TsymTftld::HLAHM1, date_locale_860026368)
	
		##### G4R6 Lot3 #####
		SI b_ALICE_860026368
		ALORS
			#CODE_TARIF
			erreur_860026368 = i_set_art_str(g_iartout5, $TsymTftld::CODE_TARIF, pt_CODE_TARIF_860026368 )
			#TYPE_EDIT
			erreur_860026368 = i_set_art_str(g_iartout5, $TsymTftld::TYPE_EDIT, pt_TYPE_EDIT_860026368 )
		# G4R6 QC814 #
		SINON
			erreur_860026368 = i_supprChamp(g_iartout5, "T4code_tarif")
			erreur_860026368 = i_supprChamp(g_iartout5, "T4type_edit")
		FINSI
	FINSI
FINSI


############################################################################
# Mises au format SPOT
############################################################################

##### G4R6 Lot3 #####
SI !bREDIST_860026368 || ( bREDIST_860026368 && CPT_REDIST_860026368 == 0 ) 
ALORS
	SI ( instSPOT_860026368 )
	ALORS
		# Ajout de SPOT a la liste courante des ECC:
		erreur_860026368=i_AjouterCouranteECC(instSPOT_860026368)
	
		trace("Duplication vers SPOT_CTI")
	
		SI (i_dup_art_id(g_iartin, g_iartout4) )
		ALORS
			trace("ERREUR de duplication vers Spot")
			code_errone_860026368 = 0xA0D0
			code_errone_860026368 = code_errone_860026368 + EFFICACE_860026368
			erreur_860026368 = i_PlvMessEmettre(8602, 2, g_iartin, "", 3, code_errone_860026368, C_TspotTftld_860026368, C_Article_860026368)
			SAUT DISTRI_ERR
		FINSI
	
		SI (i_rename_art(g_iartout4, C_TspotTftld_860026368) )
		ALORS
			trace("ERREUR de duplication vers Spot")
			code_errone_860026368 = 0xA0D0
			code_errone_860026368 = code_errone_860026368 + EFFICACE_860026368
			erreur_860026368 = i_PlvMessEmettre(8602, 2, g_iartin, "", 3, code_errone_860026368, C_TspotTftld_860026368, C_Article_860026368 )
			SAUT DISTRI_ERR
		FINSI
	
		trace(" Ajout de champs supplementaires")
		erreur_860026368 = i_ajoutChampNum(g_iartout4, $TspotTftld::T4eccfact, $TspotTftld::ECC_FACT, 6 )
	
		#trace(" Suppression des champs non utilises par spot ")
		SI (i_valid_field_n(g_iartout4, $TspotTftld::T4eccfact) )
		ALORS
			erreur_860026368 = i_supprChamp(g_iartout4, "T4eccfact")
		FINSI
	
		SI (i_valid_field_n(g_iartout4, $TspotTftld::T4ccd) )
		ALORS
			erreur_860026368 = i_supprChamp(g_iartout4, "T4ccd")
		FINSI
	
		SI (i_valid_field_n(g_iartout4, $TspotTftld::T4hlahm1))
		ALORS
			erreur_860026368 = i_supprChamp(g_iartout4, "T4hlahm1")
		FINSI
	
		# Champ SGTQS1
		i_get_sub_str(pt_sgtqs_860026368, 0, 5, pt_TEMP1_860026368)
		erreur_860026368 = i_set_art_str(g_iartout4, $TspotTftld::SGTQS1, pt_TEMP1_860026368)
	FINSI
FINSI


############################################################################
# Envoi vers IECC
############################################################################

#-------------------------------------------------------------------------
#G4R4 lot2 suppression SAFIRE
#-------------------------------------------------------------------------


#-------------------------------------------------------------------------
#G4R4 lot2 ENTROPI (ENTREFF)
#-------------------------------------------------------------------------
SI( !i_ChercherCouranteECC( instENTREFF_860026368 ) )
ALORS
	res_860026368 = i_stocke_art_iecc(g_iartout2, instENTREFF_860026368)
	#trace1("retour de i_stocke_art_iecc pour ENTREFF : %d",res)
FINSI


#-------------------------------------------------------------------------
#G4R4 lot2 ENTROPI (ENTRINEF)
#-------------------------------------------------------------------------
SI( !i_ChercherCouranteECC( instENTRINEF_860026368 ) )
ALORS
	res_860026368 = i_stocke_art_iecc(g_iartout2, instENTRINEF_860026368)
	#trace1("retour de i_stocke_art_iecc pour ENTRINEF : %d",res)
FINSI


#-------------------------------------------------------------------------
# SPOT
#-------------------------------------------------------------------------
SI ( !i_ChercherCouranteECC(instSPOT_860026368) )
ALORS
	res_860026368 = i_stocke_art_iecc(g_iartout4, instSPOT_860026368)
	trace("Emission vers SPOT_CTI")
FINSI


#-------------------------------------------------------------------------
# SYMPHONIE
#-------------------------------------------------------------------------
SI( !i_ChercherCouranteECC(instSYMPH_860026368) )
ALORS
	res_860026368 = i_stocke_art_iecc(g_iartout5, instSYMPH_860026368)
	trace("Emission vers SYMPHONIE")
FINSI


#-------------------------------------------------------------------------
# CENTAURE HF
#-------------------------------------------------------------------------
SI (!i_ChercherCouranteECC(instCENTHF_860026368))
ALORS
	res_860026368 = i_stocke_art_iecc(g_iartout6, instCENTHF_860026368)
	trace("Emission vers CENTHF")
FINSI


#-------------------------------------------------------------------------
#G4R4 lot2 Suppression TRANSIT
#-------------------------------------------------------------------------

##### G4R6 Lot3 #####
#-------------------------------------------------------------------------
# 	Test envoi en redistribution
#-------------------------------------------------------------------------
SI bREDIST_860026368 == 1
ALORS
	SAUT REDIST
FINSI

RETOUR TRAIT_OK


#####################################################################
# POINT de branchement : stockage PT_ERRONE
#####################################################################

POINT DISTRI_ERR

#IFDEF trace_niv1 = 1
trace( "Stockage de l'article Tftld en ERRONE" )
#ENDIF

erreur_860026368 = i_make_art_rej(g_iartout, g_iartout, code_errone_860026368)
erreur_860026368 = i_stocke_art(g_iartout, 0, PT_ERRONE, 0)

RETOUR TRAIT_OK


############################################################################
# Stockage en REDISTRIBUTION
############################################################################

POINT REDIST

# On emet le message d erreur uniquement au 1er passage
SI (CPT_REDIST_860026368 == 0)
ALORS
	i_strcpy(pt_sgtqs_860026368, i_LireEECSGTQS(g_ieec) )
	erreur_860026368 = i_PlvMessEmettre(8503, 1, g_iartin, "", 3, pt_LIBELREDIST_860026368, C_Article_860026368, pt_sgtqs_860026368)
FINSI

erreur_860026368 = i_stocke_art(g_iartin, 0, PT_REDIST|RD_TABLE1, 0)

RETOUR TRAIT_OK


###########################################################################
# POINT de branchement : stockage PT_DIVERS
###########################################################################
POINT DISTRI_DIVERS

#IFDEF trace_niv1 = 1
trace( "Stockage de l'article Tftld en DIVERS" )
#ENDIF
erreur_860026368 = i_stocke_art( g_iartout, 0, PT_DIVERS, 0 )

RETOUR TRAIT_OK


#--------------Fin Pcode Distribution Tv2oip_dis.src------------------------
