DEFINITION C_Article_860026296 "Tri2gTT"
DEFINITION NUMTABSEL_860026296 0
DEFINITION NUMTAB_860026296 2
DEFINITION ZONEMETRO_860026296 7
DEFINITION C_Conversion_860026296 "Conversion"
DEFINITION IDUS_BNC_860026296 "**00"
DEFINITION BASE_BNC_860026296 1
DEFINITION CATEG_BNC_860026296 8
DEFINITION CODE_BNC_860026296 1
DEFINITION C_InstCENTDEA_860026296 "CENTAUREDEA"
DEFINITION C_TcentaureDEA_860026296 "TcentRi2gTTDEA"
DEFINITION RES_CLDEST_860026296 1
DEFINITION RES_TYPCOM_860026296 0
DEFINITION RES_CODCIR_860026296 3
REGISTRE ENTIER erreur_860026296
REGISTRE ENTIER code_errone_860026296
REGISTRE ENTIER dduree_860026296
REGISTRE ENTIER ddebut_860026296
REGISTRE ENTIER dpivot_860026296
REGISTRE ENTIER numzone_860026296
REGISTRE ENTIER EFFICACE_860026296
REGISTRE ENTIER DATE_GMT_860026296
REGISTRE ENTIER ICAR_S_860026296
REGISTRE ENTIER L_NDE_860026296
REGISTRE ENTIER TYPCOM_ITX_860026296
REGISTRE ENTIER SPORTABILITE_860026296
REGISTRE ENTIER CCD_860026296
REGISTRE ENTIER CCD_REEL_860026296
REGISTRE ENTIER CODCIR_860026296
REGISTRE ENTIER TYPCOM_860026296
REGISTRE ENTIER VAL_860026296
REGISTRE ENTIER NBUT_860026296
REGISTRE ENTIER bCENTDEA_860026296
REGISTRE ENTIER REF_860026296
REGISTRE ENTIER DURCONV_860026296
REGISTRE ENTIER DEDE_INF_860026296
REGISTRE ENTIER instCENTDEA_860026296
REGISTRE ENTIER res_860026296
REGISTRE ENTIER longueur_860026296
REGISTRE POINTEUR pt_SGTQS_860026296
REGISTRE POINTEUR pt_IDUS_860026296
REGISTRE POINTEUR pt_DEDE_NUM_860026296
REGISTRE POINTEUR pt_DEDE_DIST_NUM_860026296
REGISTRE POINTEUR pt_CodeOp_860026296
REGISTRE POINTEUR pt_BUF_860026296
REGISTRE POINTEUR pt_IDCORREL_860026296
REGISTRE POINTEUR pt_REF_860026296
################################################################################################
#
# Fichier : Tri2gTT_dist.src 
#
################################################################################################
#
# Distribution :
#    Article Tri2gTT
#
# En entree :
#    Article : Tri2gTT
#
# En sortie :
#	g_iartout, 
#	g_iartout2, Conversion
#	g_iartout3, DISTRI_ERR
#	g_iartout4, 
#	g_iartout5, 
#	g_iartout6, 
#	g_iartout7, 
#	g_iartout8, 
#	g_iartout9, 
#	g_iartout10, 
#	g_iartout11, 
#	g_iartout12, 
#	g_iartout13, 
#
# HISTORIQUE :
#
# 	20/07/2009	THE - Creation - Param FTSA-G3R14
# 	26/08/2009	DRE/THE - Correction QC 279
#	26/10/2009	PK/JLG  - Correction QC299
#	04/10/2011 - THE - VerifPcode
#
################################################################################################

# CONSTANTES
#############


# ENTIERS
##########


# Initialisations ENTIER
code_errone_860026296	 = 0
numzone_860026296		 = 0
erreur_860026296		 = 0
dduree_860026296		 = 0
ddebut_860026296		 = 0
dpivot_860026296		 = 0
L_NDE_860026296		 = 0
EFFICACE_860026296	 = 0
DATE_GMT_860026296	 = 0
ICAR_S_860026296		 = 0
CCD_860026296		 = 0
CCD_REEL_860026296	 = 0
CODCIR_860026296		 = 0
TYPCOM_860026296		 = 0
VAL_860026296		 = 0
NBUT_860026296		 = 0
bCENTDEA_860026296	 = 0
REF_860026296		 = 0
DURCONV_860026296		 = 0
DEDE_INF_860026296	 = 0
instCENTDEA_860026296	 = 0
res_860026296		 = 0
longueur_860026296	 = 0

# POINTEURS
############

# Allocation de memoire pour les pointeurs
pt_CodeOp_860026296	 = "pt_codeOPpt_codeOP"
pt_SGTQS_860026296	 = "pt_SGTQSpt_SGTQS"
pt_IDUS_860026296		 = "pt_IDUSpt_IDUS0123456789012345"
pt_DEDE_NUM_860026296	 = "pt_DEDE_NUM0123456789012345678"
pt_DEDE_DIST_NUM_860026296 = "pt_DEDE_DIST_NUMpt_DEDE_DIST_NUM"
pt_IDCORREL_860026296	 = "pt_IDCORRELpt_IDCORRELpt_IDCORREL"
pt_REF_860026296		 = "pt_REFpt_REFpt_REFpt_REF"
pt_BUF_860026296		 = "pt_BUF01234567890123456789012345678901234567890"

# Initialisations pointeur
i_strcpy(pt_IDCORREL_860026296, "")
i_strcpy(pt_SGTQS_860026296, "")
i_strcpy(pt_CodeOp_860026296, "")
i_strcpy(pt_IDUS_860026296, "")
i_strcpy(pt_DEDE_NUM_860026296, "")
i_strcpy(pt_DEDE_DIST_NUM_860026296, "")
i_strcpy(pt_REF_860026296, "")
i_strcpy(pt_BUF_860026296, "")


################################################################################################

trace (":__LINE__ #### DEBUT Pcode de Distri <__FILE__> #### ")

erreur_860026296 = i_cree_art(C_Conversion_860026296, g_iartout2)
dduree_860026296 = i_get_art_field(g_iartin, $Tri2gTT::dduree)
ddebut_860026296 = i_get_art_field(g_iartin, $Tri2gTT::ddebut)
dpivot_860026296 = i_get_art_field(g_iartin, $Tri2gTT::dpivot)

################################################################################################
# 	Variables fonctionnelles Globales
################################################################################################

#######################################
# IDUS_N
erreur_860026296 = i_get_art_str(g_iartin, $Tri2gTT::IDUS_NUM, pt_IDUS_860026296)


#######################################
# EFFICACE

SI (i_valid_field_n(g_iartin, $Tri2gTT::TREP_DURCONV) == 1)
ALORS
	DURCONV_860026296 = i_get_art_field(g_iartin, $Tri2gTT::TREP_DURCONV)
	SI DURCONV_860026296 != 0
	ALORS
		EFFICACE_860026296 = 1
	FINSI
FINSI


################################################################################################
# 	Variables fonctionnelles
################################################################################################

#######################################
# ICAR_REF

# Init de numzone si IDUS_NUM ABSENT
numzone_860026296 = 7
numzone_860026296 = i_DHgetZoneID(NUMTABSEL_860026296, g_iartin)

# DATE_GMT
DATE_GMT_860026296 = i_DHgetCe2gTime(NUMTAB_860026296, ZONEMETRO_860026296, ddebut_860026296)


#######################################
# ICAR_S

# DATE_LOCALE
ICAR_S_860026296 = i_DHgetLocalTime(NUMTAB_860026296, numzone_860026296, ddebut_860026296)

#######################################
# APPEL BNC

erreur_860026296 = i_get_art_str(g_iartin, $Tri2gTT::DEDE_NUM, pt_DEDE_NUM_860026296)
longueur_860026296 = i_strlen (pt_DEDE_NUM_860026296)

VAL_860026296 = i_get_art_field(g_iartin, $Tri2gTT::DEDE_INF)

SI ( VAL_860026296 == 3 || ( VAL_860026296 == 2 && longueur_860026296 > 6 ) )
ALORS
	DEDE_INF_860026296 = 0x82
SINON
	SI VAL_860026296 == 4
	ALORS
		DEDE_INF_860026296 = 0xC0
	FINSI
FINSI
#trace1("__FILE__:__LINE__ ## TEST ## ======> Valeur de DEDE_INF : <%d> #### ", DEDE_INF)

SI (DEDE_INF_860026296 == 0xC0)
ALORS
	erreur_860026296 = i_format_str2( pt_DEDE_DIST_NUM_860026296, "%s%s", "00", pt_DEDE_NUM_860026296)
SINON
	SI ( DEDE_INF_860026296 == 0x82 )
	ALORS
		erreur_860026296 = i_format_str2( pt_DEDE_DIST_NUM_860026296, "%s%s", "0", pt_DEDE_NUM_860026296)
	SINON
		i_strcpy(pt_DEDE_DIST_NUM_860026296,pt_DEDE_NUM_860026296)
	FINSI
FINSI

erreur_860026296 = i_memcpy_art_field_n(g_icopo, $Tcopo::NDR, IDUS_BNC_860026296, 5)

L_NDE_860026296 = i_strlen(pt_DEDE_DIST_NUM_860026296)
erreur_860026296 = i_memcpy_art_field_n(g_icopo, $Tcopo::NDE, pt_DEDE_DIST_NUM_860026296, L_NDE_860026296 + 1)

g_icopo.TAXE   = 0
g_icopo.CREDIT = 0
erreur_860026296 = i_set_art_date(g_icopo, i_get_art_field(g_iartin, $Tri2gTT::ddebut))
g_icopo.DUREE  = dduree_860026296
g_icopo.CODE   = CODE_BNC_860026296
g_icopo.CATEG  = CATEG_BNC_860026296
g_icopo.SUP[0] = 0
g_icopo.SUP[1] = 0
g_icopo.SUP[2] = 0
g_icopo.SUP[3] = 0
g_icopo.SUP[4] = 0
g_icopo.SUP[RES_CLDEST_860026296] = 0xff

erreur_860026296 = i_comptage(g_icopo, BASE_BNC_860026296, ICAR_S_860026296)

SI (erreur_860026296 == 0)
ALORS
	CCD_860026296 = g_icopo.SUP[RES_CLDEST_860026296]
	TYPCOM_860026296 = g_icopo.SUP[RES_TYPCOM_860026296]
	CODCIR_860026296 = g_icopo.SUP[RES_CODCIR_860026296]
SINON
	CCD_860026296 = 0
	CODCIR_860026296 = 0
	TYPCOM_860026296 = 0
FINSI

#######################################
# CCD

#######################################
# TYPCOM_ITX

TYPCOM_ITX_860026296 = 0

SI ( TYPCOM_860026296 == 83 || TYPCOM_860026296 == 98 )
ALORS
	TYPCOM_ITX_860026296 = 1
FINSI

#######################################
# SPORTABILITE ( Appel 45S )

SPORTABILITE_860026296 = 0

# variable pointeur temporaire pt_BUF au lieu de pt_DEDE_NUM
i_strcpy(pt_BUF_860026296, pt_DEDE_NUM_860026296)
pt_CodeOp_860026296 = CodeOperateurTable6_860026233(DATE_GMT_860026296, pt_BUF_860026296, "45S")

SI (i_strcmp(pt_CodeOp_860026296, "84208") != 0) && (i_strcmp(pt_CodeOp_860026296, g_inull) != 0) 
ALORS
	SPORTABILITE_860026296 = 1
FINSI

#######################################
# CCD_REEL

SI SPORTABILITE_860026296
ALORS
	CCD_REEL_860026296 = 213
SINON
	CCD_REEL_860026296 = CCD_860026296
FINSI

#######################################
# NBUT

i_strcpy(pt_BUF_860026296, "")
erreur_860026296=i_get_art_str(g_iartin, $Tri2gTT::TREP_INFTAX, pt_BUF_860026296)
#trace2("__FILE__:__LINE__ ## TEST ## ======> pt_BUF <%s> #### ",pt_BUF ,"")

SI i_strlen (pt_BUF_860026296) > 2
ALORS
	i_get_sub_str (pt_BUF_860026296, 0, -3,pt_BUF_860026296)
	#trace2("__FILE__:__LINE__ ## TEST ## ======> pt_BUF <%s> #### ",pt_BUF ,"")
	NBUT_860026296 = CONV_ASCIINUMDEC_INT_860026233(pt_BUF_860026296)
	#trace1("__FILE__:__LINE__ ## TEST ## ======> Valeur de NBUT : <%d> #### ", NBUT)
	SI NBUT_860026296 == -1
	ALORS
		code_errone_860026296 = 0xA080
		code_errone_860026296 = code_errone_860026296 + EFFICACE_860026296
		erreur_860026296 = i_PlvMessEmettre(8600, 2, g_iartin, "", 3, code_errone_860026296, C_Article_860026296, " CONV_ASCIINUMDEC_INT, contenu de INFTAX incorrect")
		SAUT DISTRI_ERR
	FINSI
FINSI

#######################################
# REF

erreur_860026296 = i_get_art_str(g_iartin, $Tri2gTT::IdCorrel, pt_IDCORREL_860026296)
trace2("__FILE__:__LINE__ ## TEST ## ======> pt_IDCORREL <%s> #### ",pt_IDCORREL_860026296 ,"")
i_get_sub_str(pt_IDCORREL_860026296, -3, -1, pt_REF_860026296)
trace2("__FILE__:__LINE__ ## TEST ## ======> pt_REF <%s> #### ",pt_REF_860026296 ,"")
REF_860026296 = i_get_val_num(pt_REF_860026296, 3, 12)
trace1("__FILE__:__LINE__ ## TEST ## ======> Valeur de REF : <%d> #### ", REF_860026296)

#######################################
# SGTQS

erreur_860026296 = i_get_art_str(g_iartin, $Tri2gTT::IdPCS, pt_SGTQS_860026296)

################################################################################################
# 	Critere de distribution
################################################################################################

#######################################
# CENTAUREDEA

instCENTDEA_860026296= i_LireInstanceECC(C_InstCENTDEA_860026296)
SI (!instCENTDEA_860026296)
ALORS
	bCENTDEA_860026296 = 0
	code_errone_860026296 = 0xA0B0
	code_errone_860026296 = code_errone_860026296 + EFFICACE_860026296
	erreur_860026296 = i_PlvMessEmettre(8601, 2, g_iartin, "", 3, code_errone_860026296, C_InstCENTDEA_860026296, C_Article_860026296)
	SAUT DISTRI_ERR
FINSI

################################################################################################
# 	Consolidation des applications destinatrices
################################################################################################

SI ( EFFICACE_860026296 && ( ( CCD_REEL_860026296 == 24 && TYPCOM_ITX_860026296 ) || CCD_REEL_860026296 == 213 ) )
ALORS
	bCENTDEA_860026296 = 1
	erreur_860026296 = i_AjouterCouranteECC(instCENTDEA_860026296)
SINON
	SAUT ELM_DIVERS
FINSI

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

#######################################
# 	CENTAUREDEA

#*************CENTAUREDEA**************************************#

SI (!i_ChercherCouranteECC(instCENTDEA_860026296))
ALORS
	#trace1("<<<__LINE__:__FILE__<<< dup instCENTVG <%d>",instCENTVG)
	SI (i_dup_art_dest(g_iartin, g_iartout10, C_TcentaureDEA_860026296))
	ALORS
		code_errone_860026296 = 0xA0D0
		code_errone_860026296 = code_errone_860026296 + EFFICACE_860026296
		erreur_860026296 = i_PlvMessEmettre(8602, 2, g_iartin, "", 3, code_errone_860026296, C_TcentaureDEA_860026296, C_Article_860026296)
		SAUT DISTRI_ERR
	FINSI

	# Champ DATE
	erreur_860026296 = i_set_art_field(g_iartout10, $TcentRi2gTTDEA::DATE, ICAR_S_860026296)

	# champ IIDUS
	erreur_860026296 = i_get_art_str(g_iartin, $Tri2gTT::IDUS_NUM,pt_BUF_860026296)
	longueur_860026296 = i_strlen (pt_BUF_860026296)
	SI ( ( longueur_860026296 == 9 ) && ( g_iartin.IDUS_NUM[0] != 0x0 ) )
	ALORS
		VAL_860026296 = i_get_val_num("130", 3, 12)
		erreur_860026296 = i_set_art_field(g_iartout10, $TcentRi2gTTDEA::IIDUS, VAL_860026296 )
	FINSI

	# champ NIDUS
	erreur_860026296 = i_get_art_str(g_iartin, $Tri2gTT::IDUS_NUM,pt_BUF_860026296)
	erreur_860026296 = i_set_art_str(g_iartout10, $TcentRi2gTTDEA::NIDUS, pt_BUF_860026296)

	# champ IDEDE
	erreur_860026296 = i_set_art_field(g_iartout10,  $TcentRi2gTTDEA::IDEDE, DEDE_INF_860026296)

	# champ NDEDE
	erreur_860026296 = i_set_art_str(g_iartout10, $TcentRi2gTTDEA::NDEDE, pt_DEDE_NUM_860026296)

	# champ NIDAV  FO2292
	SI SPORTABILITE_860026296
	ALORS
		SI (i_strplcmp(pt_DEDE_NUM_860026296 ,"842",0,3)!=0)
		ALORS
			erreur_860026296= i_format_str2( pt_BUF_860026296, "%s%s", pt_CodeOp_860026296, pt_DEDE_NUM_860026296)
			erreur_860026296 = i_set_art_str(g_iartout10, $TcentRi2gTTDEA::NIDAV,pt_BUF_860026296)
		SINON
			erreur_860026296 = i_set_art_str(g_iartout10, $TcentRi2gTTDEA::NIDAV,pt_DEDE_NUM_860026296)
		FINSI
	SINON
		erreur_860026296 = i_set_art_str(g_iartout10, $TcentRi2gTTDEA::NIDAV,pt_DEDE_NUM_860026296)
	FINSI

	# champ NICOM
	erreur_860026296 = i_set_art_str(g_iartout10, $TcentRi2gTTDEA::NICOM,"SVAITX")

	# champ REF
	erreur_860026296 = i_set_art_field(g_iartout10, $TcentRi2gTTDEA::REF, REF_860026296)

	# champ DUR (DUREE) 
	erreur_860026296 = i_set_art_field(g_iartout10, $TcentRi2gTTDEA::DUREE, DURCONV_860026296)

	# champ TAX
	erreur_860026296 = i_set_art_field(g_iartout10,$TcentRi2gTTDEA::TAX, NBUT_860026296)

	# champ CDSGTQS
	erreur_860026296=i_set_art_str(g_iartout10, $TcentRi2gTTDEA::CDSGTQS, pt_SGTQS_860026296)
FINSI

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

SI (!i_ChercherCouranteECC(instCENTDEA_860026296))
ALORS
	res_860026296 = i_stocke_art_iecc(g_iartout10, instCENTDEA_860026296)
FINSI

RETOUR TRAIT_OK

############################################################################
# Stockage en Errone
############################################################################

POINT DISTRI_ERR

trace( "__LINE__ : Fin du Pcode de distribution <__FILE__>: Stockage en ERRONE" )
res_860026296 = i_make_art_rej(g_iartin, g_iartout3, code_errone_860026296)
res_860026296 = i_stocke_art(g_iartout3, 0, PT_ERRONE, 0)

RETOUR TRAIT_OK

###########################################################################
# Stockage en elimine DIVERS
###########################################################################

POINT ELM_DIVERS

trace( "__LINE__ : Fin du Pcode de distribution <__FILE__>: Stockage en ELIMINE" )

res_860026296 = i_stocke_art( g_iartin, 0, PT_DIVERS, 0 )

RETOUR TRAIT_OK

################################################ Tri2gTT_dist.src #####################################################
