DEFINITION DUP_SMS_MO_660004600 1
DEFINITION DUP_SMS_MO_LA_660004600 2
DEFINITION DUP_SMS_MT_660004600 3
DEFINITION DUP_SMS_MTM2M_660004600 4
DEFINITION DUP_SMS_MT_IDPART_BILL_660004600 5
DEFINITION Multidistribution_Non_660004600 0
DEFINITION DISTRIBUTION_INCONNU_660004600 1
DEFINITION TRAI_KO_660004600 -1
DEFINITION MODULE_DISTR_660004600 0xA000
DEFINITION ERR_NORM_660004600 0x010
DEFINITION ERR_DUPL_660004600 0x0D0
DEFINITION ERR_CONV_660004600 0x0E0
DEFINITION ERR_DISTR_660004600 0x110
DEFINITION IDENTIFIANT_M2M_660004600 "11525"
REGISTRE ENTIER flag_rdt_660004600
REGISTRE POINTEUR pt_recipAddress_660004600
REGISTRE POINTEUR pt_short_id_660004600
REGISTRE POINTEUR pt_val_idemet_660004600
REGISTRE POINTEUR pt_consolAlph_660004600
REGISTRE POINTEUR pt_billidAlph_660004600
REGISTRE POINTEUR pt_smsc_la_mode_660004600
REGISTRE POINTEUR pt_contentDcs_660004600
REGISTRE POINTEUR pt_cmg_fact_inf_660004600
REGISTRE POINTEUR pt_cmg_fact_sup_660004600
REGISTRE POINTEUR pt_erreur_660004600
REGISTRE POINTEUR pt_sgtqs_tmp_660004600
REGISTRE POINTEUR pt_sgtqs_660004600
REGISTRE ENTIER date_pivot_660004600
REGISTRE ENTIER erreur_660004600
REGISTRE ENTIER billiD_Num_660004600
REGISTRE ENTIER length_billID_660004600
REGISTRE ENTIER consolNum_660004600
REGISTRE ENTIER cmg_fact_inf_660004600
REGISTRE ENTIER cmg_fact_sup_660004600
REGISTRE ENTIER valid_chp_660004600
REGISTRE ENTIER origAddressTON_660004600
REGISTRE ENTIER origAddressNPI_660004600
REGISTRE ENTIER origAddressDIGIT1_660004600
REGISTRE ENTIER origAddressDIGIT2_660004600
REGISTRE ENTIER origAddressLong_660004600
REGISTRE ENTIER status_val_660004600
REGISTRE ENTIER consolidation_present_660004600
REGISTRE ENTIER ogtiAddressTON_660004600
REGISTRE ENTIER ogtiAddressNPI_660004600
REGISTRE ENTIER ogtiAddressDIGIT1_660004600
REGISTRE ENTIER ogtiAddressDIGIT2_660004600
REGISTRE ENTIER ogtiAddressDIGIT3_660004600
REGISTRE ENTIER ogtiAddressDIGIT4_660004600
REGISTRE ENTIER ogtiAddressDIGIT5_660004600
REGISTRE ENTIER ogtiAddressLong_660004600
REGISTRE ENTIER length_contentDcs_660004600
REGISTRE ENTIER taille_origAddress_660004600
REGISTRE ENTIER taille_consol_660004600
REGISTRE ENTIER val_origAddress_660004600
REGISTRE ENTIER val_consolidation_660004600
REGISTRE ENTIER indice_consolidation_660004600
REGISTRE ENTIER indice_origAddress_660004600
REGISTRE ENTIER champ_diff_660004600
REGISTRE ENTIER sms_gratuit_660004600
REGISTRE ENTIER smsc_prepaid_660004600
REGISTRE ENTIER tm_smid_660004600
REGISTRE ENTIER hh_smid_660004600
REGISTRE ENTIER mm_smid_660004600
REGISTRE ENTIER ss_smid_660004600
REGISTRE ENTIER indice_billid_660004600
REGISTRE ENTIER taille_billid_660004600
REGISTRE ENTIER val_billid_660004600
REGISTRE ENTIER date_fin_660004600
REGISTRE ENTIER code_rejet_660004600
REGISTRE ENTIER EFFICACE_660004600
REGISTRE ENTIER MODULE_660004600
REGISTRE ENTIER ERREUR_660004600
REGISTRE ENTIER SMS_MT_Gateway_660004600
REGISTRE ENTIER SMS_PrepaidMO_PRISM_660004600
REGISTRE ENTIER SMS_PrepaidMO_GORI_660004600
#################################################################################
#              Article TSms_cmg Module de Distribution
#
#              Creation le 09/09/2005 par :RAS
# 26/03/07 JLG G3R0CyME Ajout des champ T3t3 et T3t33
# 30/05/07 JLG FO521 evolution T3.t33
# 04/06/07 DRE FO 524 simplification de l'alimentation de v3t33
# 04/09/07 RHE FO576 (report G1R3) correction du champ contentDCs
# 18/09/07 RHE Reactivation des traces (demande SOFRECOM)
# 18/09/07 RHE G1R5 report TT0023/FO577 : utilisation de i_get_art_str et de champ sans deplacement au lieu de i_get_art_fieldptr
# 16/03/09 DRE G2R2 : IMSI destinataire dans les CRAs SMS sortants (spec Traitement des CRAs SMS-C CMG, version A12.0)
# 11/06/2010 - JLG - G2R6C800 : appel fonction aiguillage2, creation enveloppe E_Redistri2,
#                               ajout champ T3t55 (GFlag2) et T3t56 (GValue)
# 22/11/2010 - JLG - G3R1lot4 Verification/Correction des variables (constantes, entiers, pointeurs)
# 10/03/2011 - JLG -G3R2C4 fusion G3R2C3 avec G3R1C600 (ajout champ T3t99)
# 05/12/2012 - PKH -G3R5 lot1 SMS Roming ajout information localisation aux cras MVNO prepayes
# 29/02/2012 - JLG -G3R6 QC1005 modif alarme retour aiguillage
# 31/01/2014 - JLG -G5R1 lot1 item : SMS_Numerotation_Erronee
# 11/02/2014 - JLG -G5R1 QC1331, Built 3 : Changement Marque Audit
# 02/07/2014 - JLG -G5R1 QC1405, champ eec du DPV si g_ieec > 500
#################################################################################
#definition des constantes
#indice des tables de duplication




#declaration des variables locales


#G3R5 lot1

SMS_PrepaidMO_PRISM_660004600 = 0
SMS_PrepaidMO_GORI_660004600 = 0
ogtiAddressDIGIT1_660004600 = 0
ogtiAddressDIGIT2_660004600 = 0
ogtiAddressDIGIT3_660004600 = 0
ogtiAddressDIGIT4_660004600 = 0
ogtiAddressDIGIT5_660004600 = 0

# TSms_cmg : module de distribution
####################################################################
# duplication au format pivot Tdpvgsm 3.3
####################################################################

trace(" [TSms_cmg]: Debut Pcode de DISTRIBUTION article SMS-C CMG ")

# affectation des pointeurs
pt_val_idemet_660004600 ="33001000000FFFFFFFF"
pt_short_id_660004600="01234567890123456789"
pt_consolAlph_660004600="0123456789"
pt_billidAlph_660004600="1234567890"
pt_recipAddress_660004600="0123456789012345678901234567890123456789"
pt_smsc_la_mode_660004600="01234"
pt_cmg_fact_inf_660004600="2345678901"
pt_cmg_fact_sup_660004600="3456789012"
pt_erreur_660004600="1230"
pt_contentDcs_660004600 = "pt_contentDcs567891234561234512345678912345678912345612345123456789123456789123456123451234567891234567891234561234512345678912\
34567891234561234512345678912345678912345612345123456789123456789123456123451234567891234567891234561234512345678912345678912345123456789"
pt_sgtqs_tmp_660004600="sgtqs_idemet_112233F"
pt_sgtqs_660004600="AX_IDEMET_sgtqs_idemet_112233F"

#initialisation des variables
# entiers
EFFICACE_660004600 = 1
MODULE_660004600 = MODULE_DISTR_660004600
ERREUR_660004600 = 0
code_rejet_660004600 = 0
SMS_MT_Gateway_660004600 = 0
# pointeurs
i_strcpy(pt_recipAddress_660004600,"")
i_strcpy(pt_short_id_660004600,"")
i_strcpy(pt_val_idemet_660004600,"")
i_strcpy(pt_consolAlph_660004600,"")
i_strcpy(pt_billidAlph_660004600,"")
i_strcpy(pt_smsc_la_mode_660004600,"")
i_strcpy(pt_cmg_fact_inf_660004600,"")
i_strcpy(pt_cmg_fact_sup_660004600,"")
i_strcpy(pt_erreur_660004600,"")
i_strcpy(pt_contentDcs_660004600,"")
i_strcpy(pt_sgtqs_tmp_660004600,"")
i_strcpy(pt_sgtqs_660004600,"")

#  comptabilisation des CRAs issus de la redistribution
date_fin_660004600=i_get_art_field(g_iartin,$TSms_cmg::dfin)
erreur_660004600= i_incr_redist_dist_660004265(date_fin_660004600)

##################################################################################
# Identification de la provenance de l'article
# flag_rdt : nb de passage en redistribution (lecture de l'enveloppe obligatoire)
##################################################################################
flag_rdt_660004600 = -1
flag_rdt_660004600 = i_LireRedistCpt()

SI (flag_rdt_660004600 == 0)
ALORS
  erreur_660004600 = i_add_opt( "E_Redistri2" )
FINSI
erreur_660004600 = i_set_attr_val_n( $E_Redistri2::EnvoiRedis, 0)

####################################################################
#  Calcul de consolidation_present (equivalent a SMS_MO_LA, SMS_MT_ServPrive)
####################################################################
consolidation_present_660004600 = i_valid_field_n(g_iartin,$TSms_cmg::consolidation)
SI (consolidation_present_660004600 == 1)
ALORS
  taille_consol_660004600=i_get_art_field(g_iartin,$TSms_cmg::consolidation-1)
  SI(taille_consol_660004600==0)
  ALORS
    consolidation_present_660004600=0
  FINSI
FINSI

####################################################################
# Determine le type de CRA (ToSms_cmg ou TtSms_cmg)
####################################################################

#G3R5 lot1 SMS_MO = Vrai si on est SMSC_SORTANT

origAddressTON_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::origAddress,0)
origAddressNPI_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::origAddress,1)
origAddressDIGIT1_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::origAddress,2)
origAddressDIGIT2_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::origAddress,3)

origAddressLong_660004600 = i_get_art_field(g_iartin,$TSms_cmg::origAddress - 1)

SI  ( (origAddressTON_660004600 == 8 && origAddressNPI_660004600 == 1 && origAddressDIGIT1_660004600 == 0 && origAddressDIGIT2_660004600 >= 1 && origAddressDIGIT2_660004600 <= 7 && origAddressLong_660004600 > 4) || (origAddressTON_660004600 == 8 && origAddressNPI_660004600 == 1 && origAddressDIGIT1_660004600 == 0 && origAddressDIGIT2_660004600 == 0 && origAddressLong_660004600 > 2) || (origAddressTON_660004600 == 9 && origAddressNPI_660004600 == 1 && origAddressLong_660004600 > 1) )
ALORS
  SAUT SMSC_SORTANT
SINON
  SAUT SMSC_ENTRANT
FINSI

####################### Duplication SMS-C CMG MO ###########################################################

POINT SMSC_SORTANT

#-- la date pivot de l article SMS CMG MO et MO vers LA

date_pivot_660004600=i_get_art_field(g_iartin,$TSms_cmg::orSubmitDate)+i_get_art_field(g_iartin,$TSms_cmg::orSubmitTime)

#-- determiner l indice de la table de duplication a utiliser DUP_SMS_MO ou DUP_SMS_MO_LA

#****************************************************************************************
#-- duplication de idpart V3t2
#-- 1 er cas SMS_MO_Mobile :idpart <- recipAddress
#-- 2 eme cas SMS_MO_LA : idpart <- consolidation
#*****************************************************************************************

# calcul de consolidation_present remontee plus haut
#G3R5 lot1
# Determine la plateforme origine RI MVNO PRISM(SAC=890) ou RI MVNO GORI(SAC = 891)
SI (i_valid_field_n(g_iartin,$TSms_cmg::ogtiAddress))
ALORS
  ogtiAddressTON_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::ogtiAddress,0)
  ogtiAddressNPI_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::ogtiAddress,1)
  ogtiAddressDIGIT1_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::ogtiAddress,2)
  ogtiAddressDIGIT2_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::ogtiAddress,3)
  ogtiAddressDIGIT3_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::ogtiAddress,4)
  ogtiAddressDIGIT4_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::ogtiAddress,5)
  ogtiAddressDIGIT5_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::ogtiAddress,6)
  ogtiAddressLong_660004600 = i_get_art_field(g_iartin,$TSms_cmg::ogtiAddress - 1)

  SI ( (ogtiAddressTON_660004600 == 8 && ogtiAddressNPI_660004600 == 1 && ogtiAddressDIGIT1_660004600 == 8 && ogtiAddressDIGIT2_660004600 == 9 && ogtiAddressDIGIT3_660004600 == 0 && ogtiAddressDIGIT4_660004600 == 0 && ogtiAddressLong_660004600 > 3) || (ogtiAddressTON_660004600 == 8 && ogtiAddressNPI_660004600 == 1 && ogtiAddressDIGIT1_660004600 == 0 && ogtiAddressDIGIT2_660004600 == 0 && ogtiAddressDIGIT3_660004600 == 8 && ogtiAddressDIGIT4_660004600 == 9 && ogtiAddressDIGIT5_660004600 == 0 && ogtiAddressLong_660004600 > 4) )
  ALORS
    SMS_PrepaidMO_PRISM_660004600 = 1
  SINON
    SI (
      (ogtiAddressTON_660004600 == 8 && ogtiAddressNPI_660004600 == 1 && ogtiAddressDIGIT1_660004600 == 8 && ogtiAddressDIGIT2_660004600 == 9 && ogtiAddressDIGIT3_660004600 == 1 && ogtiAddressDIGIT4_660004600 == 0 && ogtiAddressLong_660004600 > 3) || ( ogtiAddressTON_660004600 == 8 && ogtiAddressNPI_660004600 == 1 && ogtiAddressDIGIT1_660004600 == 0 && ogtiAddressDIGIT2_660004600 == 0 && ogtiAddressDIGIT3_660004600 == 8 && ogtiAddressDIGIT4_660004600 == 9 && ogtiAddressDIGIT5_660004600 == 1 && ogtiAddressLong_660004600 > 4) )
    ALORS
      SMS_PrepaidMO_GORI_660004600 = 1
    FINSI
  FINSI
FINSI
#Fin G3R5 lot1

SI (consolidation_present_660004600 != 1)
ALORS
  erreur_660004600= i_dup_art_tab_choix(g_iartin,g_iartout,"Tdpvgsm", DUP_SMS_MO_660004600)
SINON
  erreur_660004600= i_dup_art_tab_choix(g_iartin,g_iartout,"Tdpvgsm", DUP_SMS_MO_LA_660004600)
FINSI

SI (erreur_660004600)
ALORS
# On teste si l echec de duplication vient de la normalisation de recipAddress (sauf MO vers LA)
  SI (consolidation_present_660004600 != 1)
  ALORS
    erreur_660004600 = i_cree_art("Tnormal",g_iartout2)

    erreur_660004600 = i_dup_chp_rnisGSM(g_iartin,g_iartout2,$TSms_cmg::recipAddress,$Tnormal::Address,-$NORM:SMSC_MO_RECIP,0)
    SI (erreur_660004600)
    ALORS
      # G5R1 lot1 : SMS_Numerotation_Erronee
      erreur_660004600 = i_get_art_str(g_iartin, $TSms_cmg::recipAddress, pt_recipAddress_660004600)
      SI (i_strplcmp(pt_recipAddress_660004600,"810",0,3) == 0)
      ALORS
        trace("SMS-C CMG MO : Erreur normalisation champ recipAddress (==810*), Envoi elimines divers ")
        erreur_660004600 = i_stocke_art(g_iartin,0,PT_DIVERS,0)
        RETOUR TRAIT_OK
      SINON
        trace("SMS-C CMG MO : Erreur normalisation champ recipAddress (!=810*), stockage dans les errones ")
        ERREUR_660004600 = ERR_NORM_660004600
        code_rejet_660004600 = MODULE_660004600 + ERREUR_660004600 + EFFICACE_660004600
        erreur_660004600=i_PlvMessEmettre(8010, 2, g_iartin, "", 2, code_rejet_660004600, "recipAddress", 0)
        SAUT STOCKE_ERRONE
      FINSI
    FINSI
  FINSI
# correspond a consolidation_present ou normalisation recipAdress correcte
# Si MO vers LA OU erreur non due a la normalisation de recipAddress => Stockage en erronne
  trace("SMS-C CMG MO: erreur duplication, DUP_SMS_MO ou DUP_SMS_MO_LA")
  ERREUR_660004600 = ERR_DUPL_660004600
  code_rejet_660004600 = MODULE_660004600 + ERREUR_660004600 + EFFICACE_660004600
  erreur_660004600=i_PlvMessEmettre(8009, 2, g_iartin, "", 2, code_rejet_660004600, "Tdpvgsm", 0)
  SAUT STOCKE_ERRONE

FINSI

#----- ajout i ndicateur SMS prepaid sur SMS MO CMG

# si le champ ogtiAdress appartient a une liste d'adresse,
# le champ PrepaidMO (dernier octet V4T13.3) vaut 1
# 0 sinon

SI(i_valid_field_n(g_iartin,$TSms_cmg::ogtiAddress))
ALORS
  erreur_660004600 = i_cree_art("Tnormal",g_iartout2)
  #G3R5 lot1 Nouveau automate SMSC_MO_OGTI_Prepaid
  erreur_660004600 = i_dup_chp_rnisGSM(g_iartin,g_iartout2,$TSms_cmg::ogtiAddress,$Tnormal::Address,-$NORM:SMSC_MO_OGTI_PREPAID,0)

  # i_test_tab_PrepaidMO , a remplacer par la fonction de recherche dans
  # la table externe SMS_CMG_PrepaidMO
  # il faut recuperer la cle qui pt_address_Prepaid normalisee de l article
  # g_iartout2 et tester si elle existe dans la table SMS_CMG_PrepaidMO

  erreur_660004600=i_get_field_str(g_iartout2, "Address" ,pt_recipAddress_660004600)
  trace2("SMS MO conversion ogitAddress <%s> ",pt_recipAddress_660004600 , "")
  SI(erreur_660004600!=0)
  ALORS
    trace("SMS CMG : erreur recuperation ogitAddress ")
    ERREUR_660004600 = ERR_CONV_660004600
    code_rejet_660004600 = MODULE_660004600 + ERREUR_660004600 + EFFICACE_660004600
    erreur_660004600=i_PlvMessEmettre(8011, 2, g_iartin, "", 3, code_rejet_660004600, "ogitAddress", "DCB")
    SAUT STOCKE_ERRONE
  FINSI

  pt_erreur_660004600=i_get_tab_field("SMS_CMG_PrepaidMO",date_pivot_660004600,pt_recipAddress_660004600)

  smsc_prepaid_660004600 = 0

  SI ( i_strcmp(pt_erreur_660004600,g_inull) || SMS_PrepaidMO_PRISM_660004600 == 1 || SMS_PrepaidMO_GORI_660004600 == 1)
  ALORS
# --Cas ou l'adresse est presente dans la liste des adresses PrepaidMO
    smsc_prepaid_660004600 = 1
    erreur_660004600=i_set_art_field(g_iartout,$Tdpvgsm::PrepaidMO,1)
    trace("SMS-C MO : Champ ogtiAdressGSM present dans la liste des adresses PrepaidMO")
  SINON
    erreur_660004600=i_set_art_field(g_iartout,$Tdpvgsm::PrepaidMO,0)
    trace("SMS-C MO : Champ ogtiAdressGSM absent dans la liste des adresses PrepaidMO")
  FINSI
  
SINON
  smsc_prepaid_660004600 = 0
  erreur_660004600=i_set_art_field(g_iartout,$Tdpvgsm::PrepaidMO,0)
FINSI
#Fin G3R5 lot1

#---3 eme cas SMS_MO_Gateway idpart <- shortID correspondant
#   SI le champ consolidation present dans le CRA et renseigne par un des short ID
#   appartenant a la Gateway
# ALORS le champ destinataire vaut le short ID correspondant dans la table
#   de correspondance Destination/short ID

SI ( consolidation_present_660004600 == 1 )
ALORS
  erreur_660004600 = i_get_art_str(g_iartin,$TSms_cmg::consolidationA,pt_consolAlph_660004600)
  i_get_sub_str(pt_consolAlph_660004600,0,4,pt_consolAlph_660004600)
  trace2("SMSC MO consolAlph %s %s",pt_consolAlph_660004600 , "")

  pt_erreur_660004600=i_get_tab_field("SMS_CMG_Gateway",date_pivot_660004600,pt_consolAlph_660004600)

  SI (i_strcmp(pt_erreur_660004600,g_inull))
  ALORS
    trace("*******Cas SMS MO vers Gateway********")
    #SI recipAddress a un shortID correspondant dans la table SMS_CMG_DestShortID, alors idpart<- shortID

    erreur_660004600 = i_get_art_str(g_iartin, $TSms_cmg::recipAddress, pt_recipAddress_660004600)
    trace2("conversion pt_recipAddress:%s %s ",pt_recipAddress_660004600 , "")
    SI(erreur_660004600!=0)
    ALORS
      trace("SMS CMG : erreur recuperation recipAddress ")
      ERREUR_660004600 = ERR_CONV_660004600
      code_rejet_660004600 = MODULE_660004600 + ERREUR_660004600 + EFFICACE_660004600
      erreur_660004600=i_PlvMessEmettre(8011, 2, g_iartin, "", 3, code_rejet_660004600, "recipAddress", "DCB")
      SAUT STOCKE_ERRONE
    FINSI

# Appel a la fonction i_test_ShortID

    trace("SMS-C appel a la fonction i_test_ShortID")
    erreur_660004600=i_test_ShortID_660004265(pt_recipAddress_660004600,"SMS_CMG_ShortId",date_pivot_660004600,pt_short_id_660004600)
    #--- si short_id existe l affecter a idpart

    SI(i_strcmp(pt_short_id_660004600,g_inull))
    ALORS
      trace("SMS CMG : recipAddress a un shortID correspondant")
      SI( i_strlen(pt_short_id_660004600) %2)
      ALORS
        taille_consol_660004600 =((i_strlen(pt_short_id_660004600)+1)/2)*8
      SINON
        taille_consol_660004600 =((i_strlen(pt_short_id_660004600))/2)*8
      FINSI
      erreur_660004600=i_resize_tlv(g_iartout, "T3t2" ,"idpart",taille_consol_660004600)
      erreur_660004600=affectation_tab_660004265(g_iartout,$Tdpvgsm::idpart,pt_short_id_660004600)
      SI(erreur_660004600==0)
      ALORS
        trace("SMS-C MO : Erreur duplication idpart <-  shortid ")
        ERREUR_660004600 = ERR_DUPL_660004600
        code_rejet_660004600 = MODULE_660004600 + ERREUR_660004600 + EFFICACE_660004600
        erreur_660004600=i_PlvMessEmettre(8010, 2, g_iartin, "", 2, code_rejet_660004600, "recipAddress", 0)
        SAUT STOCKE_ERRONE
      FINSI
      trace1("Longueur idpart apres resize :%d",i_get_art_field(g_iartout, $Tdpvgsm::idpart-1))
      #-- si short_id non trouve idpart <- recipAddress + normalisation
    SINON
      trace("SMS CMG : recipAddress n a pas de shortID correspondant")
      erreur_660004600 = i_resize_tlv(g_iartout,"T3t2","idpart", 152)
# Prise en compte de la normalisation des ShortId associ?s aux Gateway : SMSC_MO_RECIP_GW
      erreur_660004600 = i_dup_chp_rnisGSM(g_iartin,g_iartout,$TSms_cmg::recipAddress,$Tdpvgsm::idpart,-$NORM:SMSC_MO_RECIP_GW,0)
      SI (erreur_660004600)
      ALORS
        # G5R1 lot1 : SMS_Numerotation_Erronee
        erreur_660004600 = i_get_art_str(g_iartin, $TSms_cmg::recipAddress, pt_recipAddress_660004600)
        SI (i_strplcmp(pt_recipAddress_660004600,"81114",0,5) == 0)
        ALORS
          trace("SMS-C CMG MO : Erreur normalisation champ recipAddress (==81114*), Envoi elimines divers ")
          erreur_660004600 = i_stocke_art(g_iartin,0,PT_DIVERS,0)
          RETOUR TRAIT_OK
        SINON
          trace("SMS-C CMG MO : Erreur normalisation champ recipAddress (!=81114*) pour idpart, stockage dans les errones ")
          ERREUR_660004600 = ERR_NORM_660004600
          code_rejet_660004600 = MODULE_660004600 + ERREUR_660004600 + EFFICACE_660004600
          erreur_660004600=i_PlvMessEmettre(8010, 2, g_iartin, "", 2, code_rejet_660004600, "recipAddress", 0)
          SAUT STOCKE_ERRONE
        FINSI
      FINSI
    FINSI
  FINSI
FINSI

# DRE  G2R2 : IMSI destinataire dans les CRAs SMS sortants
# duplication vers T3t25 MMSsubscribId2
SI (i_valid_field_n(g_iartin,$TSms_cmg::intlMobSubId))
ALORS
  erreur_660004600 = i_ajout_tlv(g_iartout, "T3t25" , "")
  erreur_660004600 = i_dup_chp_1val(g_iartin, g_iartout, $TSms_cmg::intlMobSubId, $Tdpvgsm::MMSsubscribId2)
FINSI

#----- complement de duplication hors table

#   mise a jour du champ idemet
#   recuperation de la variable AX_IDEMET correspondant a l'eec et mise a jour du champ dans l'article

# on lit l info AX_IDENT_EEC de l EEC pour identifier laquelle des EEC SMS CMG est en amont
# pour avoir la bonne valeur AX_IDEMET en sortie
# => on concatene "AX_IDEMET_" et le retour de la fonction i_LireEECSGTQS() pour faire la recherche dans la table externe
pt_sgtqs_tmp_660004600 = i_LireEECSGTQS( g_ieec)
erreur_660004600 = i_format_str2( pt_sgtqs_660004600, "%s_%s", "AX_IDEMET", pt_sgtqs_tmp_660004600)
trace2("### pt_sgtqs == <%s>%s", pt_sgtqs_660004600, "")
i_strcpy(pt_val_idemet_660004600,i_get_tab_field("VariableContexte",date_pivot_660004600,pt_sgtqs_660004600))
trace("SMS MO : mise a jour idemet ")
SI (i_strcmp(pt_val_idemet_660004600,g_inull))
ALORS
  trace2("SMS MO valeur AX_IDEMET_SMSCMG :<%s> %s",pt_val_idemet_660004600, "")
  erreur_660004600=affectation_tab_660004265(g_iartout,$Tdpvgsm::idemet,pt_val_idemet_660004600)
SINON
  erreur_660004600=affectation_tab_660004265(g_iartout,$Tdpvgsm::idemet,"33001000000FFFFFFF")
FINSI

SI (erreur_660004600 == 0)
ALORS
  trace("SMS-C CMG MT : Erreur duplication idemet ")
  ERREUR_660004600 = ERR_DUPL_660004600
  code_rejet_660004600 = MODULE_660004600 + ERREUR_660004600 + EFFICACE_660004600
  erreur_660004600=i_PlvMessEmettre(8012, 2, g_iartin, "", 2, code_rejet_660004600, "idemet", 0)
  SAUT STOCKE_ERRONE
FINSI

#-- recuperation de la variable de contexte SMS_LA_MODE

i_strcpy(pt_smsc_la_mode_660004600,i_get_tab_field("VariableContexte",date_pivot_660004600,"SMS_LA_MODE"))

#   Mise a jour du champ indeff pour les MO vers LA en mode de fonctionnement 2
status_val_660004600=i_get_art_field(g_iartin,$TSms_cmg::status)

SI (consolidation_present_660004600)
ALORS
  SI (!i_strcmp(pt_smsc_la_mode_660004600,"2"))
  ALORS
    SI (status_val_660004600 == 0)
    ALORS
# --- Mise a jour champ indeff a 0x00
      erreur_660004600 = i_set_art_field(g_iartout,$Tdpvgsm::indeff,0x00)
    SINON
# --- Mise a jour champ indeff a 0x04
      erreur_660004600 = i_set_art_field(g_iartout,$Tdpvgsm::indeff,0x04)
    FINSI
  FINSI
FINSI

#   Mise a jour champ DATE  de T3t1
erreur_660004600=i_set_art_field(g_iartout, $Tdpvgsm::DATE, date_pivot_660004600)

#   Mise a jour variable "sms_gratuit" (Determine si le sms est dans une tranche de gratuite) indtax de T3t1
#-- i test horaire, teste si la date de l article est comprise dans les tranches horaires gratuites

sms_gratuit_660004600 = i_test_Horaire_660004265(g_iartout,$Tdpvgsm::DATE,"SMS_CMG_HGratuit")
trace1("SMS-C sms-gratuit:[%d]",sms_gratuit_660004600)

SI (sms_gratuit_660004600)
ALORS
  erreur_660004600 = i_set_art_field(g_iartout,$Tdpvgsm::indtax,0x00)
FINSI

# mise a jour du champ IMSI de T3t1
erreur_660004600 = i_set_art_fieldtab(g_iartout,$Tdpvgsm::IMSI,15,0xf)
erreur_660004600 = i_maj_ila(g_iartout)

#G3R5lot1 deja fait en G3R0Cyme
# URSLYON G3R0CyME
#------mise a jour du champ local de T3t3 (Si SMS_MO)
SI (i_valid_field_n(g_iartin,$TSms_cmg::ogtiAddress))
ALORS
  erreur_660004600 = i_ajout_tlv(g_iartout, "T3t3" , "")
  erreur_660004600 = i_dup_chp_rnisGSM(g_iartin,g_iartout,$TSms_cmg::ogtiAddress,$Tdpvgsm::local,-$NORM:SMSC_MO_OGTI,0)
  SI (erreur_660004600 != 0)
  ALORS
    # Si erreur de normalisation de ogtiAddress => Stockage au format d entree
    trace("SMS-C CMG MO : Erreur duplication avec Normalisation du champ ogtiAddress")
    ERREUR_660004600 = ERR_DUPL_660004600
    code_rejet_660004600 = MODULE_660004600 + ERREUR_660004600 + EFFICACE_660004600
    erreur_660004600=i_PlvMessEmettre(8010, 2, g_iartin, "", 2, code_rejet_660004600, "ogtiAddress", 0)
    SAUT STOCKE_ERRONE
  FINSI
FINSI
#/ fin URSLYON G3R0CyME
#/ fin G3R5lot1 deja fait en G3R0Cyme

# recopie de terminTime dans smid (aligne a gauche bourre a valdef=0xFF) de T4t13.2
tm_smid_660004600 = i_get_art_field(g_iartin, $TSms_cmg::orSubmitTime)
trace1(" SMS MO , submitTime =%x", tm_smid_660004600)
hh_smid_660004600 = tm_smid_660004600 /3600
mm_smid_660004600 = (tm_smid_660004600 % 3600) / 60
ss_smid_660004600 = (tm_smid_660004600 %3600 ) % 60
tm_smid_660004600= ( hh_smid_660004600 << 24) + ( mm_smid_660004600 << 16 ) + ( ss_smid_660004600 << 8 ) + 0xFF
erreur_660004600 = i_set_art_field(g_iartout, $Tdpvgsm::smid, tm_smid_660004600)

#   determine le type de numero dans recipAddress
#   si num court => type de mess de bout en bout = 01 sinon 00

#-- mise a jour du champ svcPpMO

SI (consolidation_present_660004600)
ALORS
  erreur_660004600 = i_set_art_field(g_iartout,$Tdpvgsm::svcPpMO,1)
FINSI

#--mise a jour du champ demacqMO
valid_chp_660004600 = i_valid_field_n(g_iartin,$TSms_cmg::notifIndic)
SI ( (!valid_chp_660004600) || (i_get_art_field(g_iartin , $TSms_cmg::notifIndic) == 0) )
ALORS
  erreur_660004600 = i_set_art_field(g_iartout,$Tdpvgsm::demacqMO,0)
SINON
  SI(i_get_art_field(g_iartin , $TSms_cmg::notifIndic) !=0)
  ALORS
    erreur_660004600 = i_set_art_field(g_iartout,$Tdpvgsm::demacqMO,1)
  FINSI
FINSI

#####################################################################
# Mise a jour 'date d'entree dans le CE' + 'EEC'
# #####################################################################
# QC1331
#erreur=set_timeInCE_EEC(0)
########### Date_Audit
erreur_660004600 = i_set_art_field(g_iartout, $Tdpvgsm::timeInCE,  i_DHgetLocalTime(4, 7, i_date_audit()))
########### eec
# QC1405
SI (g_ieec > 500)
ALORS
  erreur_660004600 = i_set_art_field(g_iartout, $Tdpvgsm::eec, g_ieec - 500)
SINON
  erreur_660004600 = i_set_art_field(g_iartout, $Tdpvgsm::eec, g_ieec)
FINSI
#/QC1405
#----fin du complement de duplication
####################################################################
#   Gestion du champ V3t1.12 "origine de l'appel" CRA CMG
SI (i_valid_field_n(g_iartin,$TSms_cmg::ogtiAddress))
ALORS
  ogtiAddressTON_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::ogtiAddress,0)
  ogtiAddressNPI_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::ogtiAddress,1)
  ogtiAddressDIGIT1_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::ogtiAddress,2)
  ogtiAddressDIGIT2_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::ogtiAddress,3)
  ogtiAddressDIGIT3_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::ogtiAddress,4)
  ogtiAddressDIGIT4_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::ogtiAddress,5)
  ogtiAddressDIGIT5_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::ogtiAddress,6)
  ogtiAddressLong_660004600 = i_get_art_field(g_iartin,$TSms_cmg::ogtiAddress -1)
#G3R5 lot1 normalisation avec automate SMSC_MO_OGTI pour valoriser champ origine
  erreur_660004600 = i_cree_art("Tnormal",g_iartout2)
  erreur_660004600 = i_dup_chp_rnisGSM(g_iartin,g_iartout2,$TSms_cmg::ogtiAddress,$Tnormal::Address,-$NORM:SMSC_MO_OGTI,0)
  SI (erreur_660004600!=0)
  ALORS
    trace("SMS CMG : erreur normalisation  ogitAddress ")
    ERREUR_660004600 = ERR_CONV_660004600
    code_rejet_660004600 = MODULE_660004600 + ERREUR_660004600 + EFFICACE_660004600
    erreur_660004600=i_PlvMessEmettre(8011, 2, g_iartin, "", 3, code_rejet_660004600, "ogitAddress", "DCB")
    SAUT STOCKE_ERRONE
  FINSI

  erreur_660004600=i_get_field_str(g_iartout2, "Address" ,pt_recipAddress_660004600)
  trace2("SMS MO conversion ogitAddress %s %s ",pt_recipAddress_660004600 , "")

  pt_erreur_660004600=i_get_tab_field("SMS_CMG_PrepaidMO",date_pivot_660004600,pt_recipAddress_660004600)
  SI (i_strcmp(pt_erreur_660004600,g_inull))
  ALORS
    erreur_660004600 = i_set_art_field(g_iartout,$Tdpvgsm::origine,0xFF)
  SINON
    #-- Si TON+NPI=81 et 1 =< Z <= 9     =>  origine = 0  (DPV)
    SI  (
      (( ogtiAddressTON_660004600 == 8 )  && (ogtiAddressNPI_660004600 == 1) &&
      ( ogtiAddressDIGIT1_660004600 == 0 ) && (ogtiAddressDIGIT2_660004600 > 0) &&
      (ogtiAddressDIGIT2_660004600 <= 9) )
      || (( ogtiAddressTON_660004600 == 8 )  && (ogtiAddressNPI_660004600 == 1) &&
      (ogtiAddressDIGIT1_660004600 == 8 )  && (ogtiAddressDIGIT2_660004600 == 9)&&
      (ogtiAddressDIGIT3_660004600 == 0 )  && (ogtiAddressDIGIT4_660004600 == 0) &&
      (ogtiAddressDIGIT5_660004600 > 0) && (ogtiAddressDIGIT5_660004600 <= 9))
      || (( ogtiAddressTON_660004600 == 8 )  && (ogtiAddressNPI_660004600 == 1) &&
      (ogtiAddressDIGIT1_660004600 == 8 )  && (ogtiAddressDIGIT2_660004600 == 9)&&
      (ogtiAddressDIGIT3_660004600 == 1 )  && (ogtiAddressDIGIT4_660004600 == 0) &&
      (ogtiAddressDIGIT5_660004600 > 0) && (ogtiAddressDIGIT5_660004600 <= 9))
      )
    ALORS
      #  -- mise a jour du champ origine (val = 0)
      erreur_660004600=i_set_art_field(g_iartout,$Tdpvgsm::origine,0)
    SINON
      #--Si TON+NPI=81 et  Z = 0 ou TON+NPI=91    =>  origine = 1  (DPV)
      SI ( (ogtiAddressTON_660004600 == 8   && ogtiAddressNPI_660004600 == 1 && ogtiAddressDIGIT1_660004600 == 0 && ogtiAddressDIGIT2_660004600 == 0) || ( ogtiAddressTON_660004600 == 9   && ogtiAddressNPI_660004600 == 1) )
      ALORS
        erreur_660004600=i_set_art_field(g_iartout,$Tdpvgsm::origine,1)
      SINON
        #-- origine = 0xFF (DPV)
        erreur_660004600=i_set_art_field(g_iartout,$Tdpvgsm::origine,0xff)
      FINSI
    FINSI
  FINSI
FINSI
#/Fin G3R5 lot1

trace("SMS MO :Fin module de distribution")
#----- envoi de l article e IEEC

# Ajout des T3t55 et T3t56
SI (!i_valid_field_n(g_iartout, $Tdpvgsm::GFlag2))
ALORS
  erreur_660004600 = i_ajout_tlv(g_iartout,"T3t55","")
FINSI

SI (!i_valid_field_n(g_iartout, $Tdpvgsm::GValue))
ALORS
  erreur_660004600 = i_ajout_tlv(g_iartout,"T3t56","")
FINSI

SI (!i_valid_field_n(g_iartout, $Tdpvgsm::GretaTag))
ALORS
  erreur_660004600 = i_ajout_tlv(g_iartout,"T3t99","")
FINSI
# QC1005
erreur_660004600 = aiguillage2_660004590 (g_iartin, g_iartout, DISTRIBUTION_INCONNU_660004600, Multidistribution_Non_660004600)
SI (erreur_660004600 == TRAI_KO_660004600)
ALORS
  trace("<<<__LINE__<<<__FILE__<<< Erreur retour fonction aiguillage2")
  SAUT STOCKE_ERRONE
FINSI
RETOUR TRAIT_OK

#----------- fin duplication SMS-C CMG MO--------------------------------

################# Duplication SMS-C CMG MT ###############################

POINT SMSC_ENTRANT

#-- date pivot de l article SMS MT
#-- date pivot SMS MT= termineDate+termineTime
#-- si termineDate ou terminTime absent et status=4 date pivot = submitDate+submitTime

status_val_660004600=i_get_art_field(g_iartin,$TSms_cmg::status)

date_pivot_660004600=i_get_art_field(g_iartin, $TSms_cmg::terminDate)+i_get_art_field(g_iartin, $TSms_cmg::terminTime)

SI (status_val_660004600 == 4)
ALORS
  SI (!i_valid_field_n(g_iartin,$TSms_cmg::terminDate) || !i_valid_field_n(g_iartin,$TSms_cmg::terminTime))
  ALORS
    date_pivot_660004600 = i_get_art_field(g_iartin,$TSms_cmg::submitDate) + i_get_art_field(g_iartin,$TSms_cmg::submitTime)
  FINSI
FINSI

#-- choix de la table de duplication
#*******duplication de idpart *****************************************************
#   SI SMS MT depuis Gateway
#       SI Consolidation ="11525"  => origAddress (Nouvelle normalisation)
#       SI billid present et appartient a la table externe listeM2M => origAddress
#       SI billid present et n appartient pas a listeM2M => billid
#       SI billid absent => origAddress
#   SI SMS MT depuis serveur prive  => consolidation
#***********************************************************************************

erreur_660004600 = i_get_art_str(g_iartin,$TSms_cmg::consolidationA,pt_consolAlph_660004600)
i_get_sub_str(pt_consolAlph_660004600,0,4,pt_consolAlph_660004600)
pt_erreur_660004600=i_get_tab_field("SMS_CMG_Gateway",date_pivot_660004600,pt_consolAlph_660004600)
SMS_MT_Gateway_660004600 = 0
SI (i_strcmp(pt_erreur_660004600,g_inull))
ALORS
  trace("*** SMS-C CMG depuis Gateway***")
  SMS_MT_Gateway_660004600 = 1
# Nouvelle normalisation, cas des SMS M2M:
# Si consolidation =="11525" T3t2/idpart=YYYYY a extraire de origAddressGSM sous forme de 81336000YYYYY

  SI (!i_strcmp(pt_consolAlph_660004600 ,IDENTIFIANT_M2M_660004600))
  ALORS
    trace("SMS-C M2M Connect: cas consolidation=<11525>")
    erreur_660004600 = i_dup_art_tab_choix(g_iartin,g_iartout,"Tdpvgsm",DUP_SMS_MT_660004600)
    SI (erreur_660004600 !=0)
    ALORS
      trace("SMS-C M2M  Connect: Echec de duplication vers Tdpvgsm")
      ERREUR_660004600 = ERR_DUPL_660004600
      code_rejet_660004600 = MODULE_660004600 + ERREUR_660004600 + EFFICACE_660004600
      erreur_660004600=i_PlvMessEmettre(8009, 2, g_iartin, "", 2, code_rejet_660004600 ,"Tdpvgsm" , 0)
      SAUT STOCKE_ERRONE
    FINSI
# mise a jour de T3t2/idpart

    erreur_660004600=i_ajout_tlv(g_iartout, "T3t2" , "")
    erreur_660004600 = i_dup_chp_rnisGSM(g_iartin,g_iartout,$TSms_cmg::origAddress,$Tdpvgsm::idpart,-$NORM:SMSC_MT_ORIG_M2M,0)
    SI (erreur_660004600 !=0)
    ALORS
      trace("SMS-C M2M  Connect: Echec de normalisation de idpart")
      ERREUR_660004600 = ERR_DUPL_660004600
      code_rejet_660004600 = MODULE_660004600 + ERREUR_660004600 + EFFICACE_660004600
      erreur_660004600=i_PlvMessEmettre(8012, 2, g_iartin, "", 2, code_rejet_660004600 ,"idpart" , 0)
      SAUT STOCKE_ERRONE
    FINSI
  SINON
#-- test de presence du champ billID : S15F9

    SI (i_valid_field_n(g_iartin, $TSms_cmg::billID))
    ALORS
      trace("SMS MT: champ billid present ")
      erreur_660004600 = i_get_art_str(g_iartin,$TSms_cmg::billIDA,pt_billidAlph_660004600)
      length_billID_660004600=i_get_art_field(g_iartin,$TSms_cmg::billID-1)
      i_get_sub_str(pt_billidAlph_660004600,0,length_billID_660004600-1,pt_billidAlph_660004600)
      pt_erreur_660004600=i_get_tab_field("SMS_CMG_SMS_HUB", date_pivot_660004600, pt_billidAlph_660004600)

      SI (i_strcmp(pt_erreur_660004600,g_inull))
      ALORS
        trace("SMS-MT cas M2M billId present dans SMS_HUB ,idpart <-origAddress")
        erreur_660004600 = i_dup_art_tab_choix(g_iartin,g_iartout,"Tdpvgsm",DUP_SMS_MTM2M_660004600)
        SI(erreur_660004600 !=0 )
        ALORS
          trace("SMS-C M2M  : Echec de duplication vers Tdpvgsm")
          ERREUR_660004600 = ERR_DUPL_660004600
          code_rejet_660004600 = MODULE_660004600 + ERREUR_660004600 + EFFICACE_660004600
          erreur_660004600=i_PlvMessEmettre(8009, 2, g_iartin, "", 2, code_rejet_660004600 ,"Tdpvgsm" , 0)
          SAUT STOCKE_ERRONE
        FINSI
      SINON
        trace("billid present et <> liste des SMS HUB => idpart <- billid ")
        erreur_660004600 = i_dup_art_tab_choix(g_iartin,g_iartout,"Tdpvgsm",DUP_SMS_MT_IDPART_BILL_660004600)
        SI (erreur_660004600 !=0 )
        ALORS
          trace("SMS-C M2M  : Echec de duplication vers Tdpvgsm")
          ERREUR_660004600 = ERR_DUPL_660004600
          code_rejet_660004600 = MODULE_660004600 + ERREUR_660004600 + EFFICACE_660004600
          erreur_660004600=i_PlvMessEmettre(8009, 2, g_iartin, "", 2, code_rejet_660004600 ,"Tdpvgsm" , 0)
          SAUT STOCKE_ERRONE
        FINSI
      FINSI
    SINON
      trace(" SMS MT: champ billid absent => idpart <- origAddress ")
      erreur_660004600 = i_dup_art_tab_choix(g_iartin,g_iartout,"Tdpvgsm",DUP_SMS_MTM2M_660004600)
      SI (erreur_660004600 !=0)
      ALORS
        trace("SMS-C M2M  : Echec de duplication vers Tdpvgsm")
        ERREUR_660004600 = ERR_DUPL_660004600
        code_rejet_660004600 = MODULE_660004600 + ERREUR_660004600 + EFFICACE_660004600
        erreur_660004600=i_PlvMessEmettre(8009, 2, g_iartin, "", 2, code_rejet_660004600 ,"Tdpvgsm" , 0)
        SAUT STOCKE_ERRONE
      FINSI
    FINSI
  FINSI
SINON

  SI (consolidation_present_660004600)
  ALORS
    trace("**Cas SMS-C CMG MT depuis serveur prive :idpart <- consolidation**")
    erreur_660004600 = i_dup_art_tab_choix(g_iartin,g_iartout,"Tdpvgsm",DUP_SMS_MT_660004600)
    # mise a jour de T3t2/idpart
    erreur_660004600=i_ajout_tlv(g_iartout, "T3t2" , "")
    erreur_660004600 = i_dup_chp_rnisGSM(g_iartin,g_iartout,$TSms_cmg::consolidation,$Tdpvgsm::idpart,-$NORM:SMSC_MO_CONS,0)
    SI (erreur_660004600 !=0)
    ALORS
      trace("SMS MT erreur duplication ")
      ERREUR_660004600 = ERR_DUPL_660004600
      code_rejet_660004600 = MODULE_660004600 + ERREUR_660004600 + EFFICACE_660004600
      erreur_660004600=i_PlvMessEmettre(8009, 2, g_iartin, "", 2, code_rejet_660004600 ,"Tdpvgsm" , 0)
      SAUT STOCKE_ERRONE
    FINSI
  SINON
    trace(" SMS MT: champ consolidation absent => idpart <- origAddress ")
    erreur_660004600 = i_dup_art_tab_choix(g_iartin,g_iartout,"Tdpvgsm",DUP_SMS_MTM2M_660004600)
    SI (erreur_660004600 !=0 )
    ALORS
      trace("SMS MT M2M  : Echec de duplication vers Tdpvgsm")
      ERREUR_660004600 = ERR_DUPL_660004600
      code_rejet_660004600 = MODULE_660004600 + ERREUR_660004600 + EFFICACE_660004600
      erreur_660004600=i_PlvMessEmettre(8009, 2, g_iartin, "", 2, code_rejet_660004600 ,"Tdpvgsm" , 0)
      SAUT STOCKE_ERRONE
    FINSI
  FINSI
FINSI

#----- complement de duplication hors table ---------------------------------------

status_val_660004600=i_get_art_field(g_iartin,$TSms_cmg::status)

#-- SI status=4 et IMSI absent ALORS  IMSI=999999999999999F (DPV)

valid_chp_660004600 = i_valid_field_n(g_iartin,$TSms_cmg::intlMobSubId)
SI (!valid_chp_660004600)
ALORS
  erreur_660004600=affectation_tab_660004265(g_iartout,$Tdpvgsm::IMSI,"999999999999999F")
  SI (erreur_660004600 == 0)
  ALORS
    trace(" SMS MT status 4: erreur mise a jour IMSI ")
    ERREUR_660004600 = ERR_DUPL_660004600
    code_rejet_660004600 = MODULE_660004600 + ERREUR_660004600 + EFFICACE_660004600
    erreur_660004600=i_PlvMessEmettre(8012, 2, g_iartin, "", 2, code_rejet_660004600 ,"IMSI" , 0)
    SAUT STOCKE_ERRONE
  FINSI
FINSI

SI (!consolidation_present_660004600)
ALORS
  trace("T3t33 SMS MT: champ billid absent ")
  erreur_660004600 = i_ajout_tlv(g_iartout, "T3t33" , "")
  erreur_660004600 = i_dup_chp_rnisGSM(g_iartin,g_iartout,$TSms_cmg::origAddress,$Tdpvgsm::SMSrecepMSISDN,-$NORM:SMSC_MT_ORIG,0)
  SI (erreur_660004600 != 0)
  ALORS
    # Si erreur de normalisation de origAddress => Stockage au format d entree
    trace("T3t33 SMS-C CMG MT : Erreur duplication avec Normalisation du champ origAddress")
    ERREUR_660004600 = ERR_DUPL_660004600
    code_rejet_660004600 = MODULE_660004600 + ERREUR_660004600 + EFFICACE_660004600
    erreur_660004600=i_PlvMessEmettre(8010, 2, g_iartin, "", 2, code_rejet_660004600, "origAddress", 0)
    SAUT STOCKE_ERRONE
  FINSI
FINSI
#/ fin URSLYON G3R0CyME

#------mise a jour du champ idemet de T3t1
# on lit l info AX_IDENT_EEC de l EEC pour identifier laquelle des EEC SMS CMG est en amont
# pour avoir la bonne valeur AX_IDEMET en sortie
# => on concatene "AX_IDEMET_" et le retour de la fonction i_LireEECSGTQS() pour faire la recherche dans la table externe
pt_sgtqs_tmp_660004600 = i_LireEECSGTQS( g_ieec)
erreur_660004600 = i_format_str2( pt_sgtqs_660004600, "%s_%s", "AX_IDEMET", pt_sgtqs_tmp_660004600)
trace2("### pt_sgtqs == <%s>%s", pt_sgtqs_660004600, "")
i_strcpy(pt_val_idemet_660004600,i_get_tab_field("VariableContexte",date_pivot_660004600,pt_sgtqs_660004600))
trace("SMS MT mise a jour idemet")
SI (i_strcmp(pt_val_idemet_660004600,g_inull))
ALORS
  erreur_660004600=affectation_tab_660004265(g_iartout,$Tdpvgsm::idemet,pt_val_idemet_660004600)
SINON
  trace2("SMS MT valeur AX_IDEMET_SMSCMG :<%s> %s",pt_val_idemet_660004600, "")
  erreur_660004600=affectation_tab_660004265(g_iartout,$Tdpvgsm::idemet,"33001000000FFFFFFF")
FINSI

SI (erreur_660004600 == 0)
ALORS
  trace("SMS-MT : Erreur duplication idemet ")
  ERREUR_660004600 = ERR_DUPL_660004600
  code_rejet_660004600 = MODULE_660004600 + ERREUR_660004600 + EFFICACE_660004600
  erreur_660004600=i_PlvMessEmettre(8012, 2, g_iartin, "", 2, code_rejet_660004600,"idemet" , 0)
  SAUT STOCKE_ERRONE
FINSI

#- duplication du champ smid V4t13.2
#-recopie de terminTime dans smid (aligne a gauche bourre a valdef=0xFF)

SI (!(i_valid_field_n(g_iartin,$TSms_cmg::terminTime)))
ALORS
#-- status 4
  tm_smid_660004600 = i_get_art_field(g_iartin, $TSms_cmg::submitTime)
SINON
#-- status 0
  tm_smid_660004600 = i_get_art_field(g_iartin, $TSms_cmg::terminTime)
FINSI

trace1(" SMS MT , [submit|termine]Time =%x", tm_smid_660004600)
hh_smid_660004600 = tm_smid_660004600 /3600
mm_smid_660004600 = (tm_smid_660004600 % 3600) / 60
ss_smid_660004600 = (tm_smid_660004600 %3600 ) % 60
tm_smid_660004600= ( hh_smid_660004600 << 24) + ( mm_smid_660004600 << 16 ) + ( ss_smid_660004600 << 8 ) + 0xFF
erreur_660004600 = i_set_art_field(g_iartout, $Tdpvgsm::smid, tm_smid_660004600)

#-- duplication du champ priorite V4t13.1.1

valid_chp_660004600 = i_valid_field_n(g_iartin,$TSms_cmg::prioIndic)
SI (!valid_chp_660004600 || i_get_art_field(g_iartin, $TSms_cmg::prioIndic)==0)
ALORS
  erreur_660004600 = i_set_art_field(g_iartout,$Tdpvgsm::priorite,0)
SINON
  SI (i_get_art_field(g_iartin, $TSms_cmg::prioIndic)!=0)
  ALORS
    erreur_660004600 = i_set_art_field(g_iartout,$Tdpvgsm::priorite,1)
  FINSI
FINSI

#-- duplication des champ nbdemMT V4t13.1.4
#-- duplication des champ nbstatMT V4t13.1.5

valid_chp_660004600 = i_valid_field_n(g_iartin,$TSms_cmg::notifIndic)
SI (!valid_chp_660004600 || i_get_art_field(g_iartin, $TSms_cmg::notifIndic)==0)
ALORS
  erreur_660004600 = i_set_art_field(g_iartout,$Tdpvgsm::nbdemMT,0)
  erreur_660004600 = i_set_art_field(g_iartout,$Tdpvgsm::nbstatMT,0)
SINON
  SI (i_get_art_field(g_iartin, $TSms_cmg::notifIndic)!=0)
  ALORS
    erreur_660004600 = i_set_art_field(g_iartout,$Tdpvgsm::nbdemMT,1)
    erreur_660004600 = i_set_art_field(g_iartout,$Tdpvgsm::nbstatMT,1)
  FINSI
FINSI

#######################################################################################
#  Mise a jour 'date d'entree dans le CE' + 'EEC'
########################################################################################
# QC1331
#erreur=set_timeInCE_EEC(0)
########### Date_Audit
erreur_660004600 = i_set_art_field(g_iartout, $Tdpvgsm::timeInCE,  i_DHgetLocalTime(4, 7, i_date_audit()))
########### eec
# QC1405
SI (g_ieec > 500)
ALORS
  erreur_660004600 = i_set_art_field(g_iartout, $Tdpvgsm::eec, g_ieec - 500)
SINON
  erreur_660004600 = i_set_art_field(g_iartout, $Tdpvgsm::eec, g_ieec)
FINSI
#/QC1405

#-- mise a jour du champ DATE par date pivot de l article

erreur_660004600=i_set_art_field(g_iartout,$Tdpvgsm::DATE, date_pivot_660004600)

#----- Gestion du champ "origine de l'appel" CRA CMG

ogtiAddressTON_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::ogtiAddress,0)
ogtiAddressNPI_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::ogtiAddress,1)
ogtiAddressDIGIT1_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::ogtiAddress,2)
ogtiAddressDIGIT2_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::ogtiAddress,3)
ogtiAddressLong_660004600 = i_get_art_field(g_iartin,$TSms_cmg::ogtiAddress -1)

#  -- SI TON+NPI=81 et 1 =< Z <= 9  (ogtiAddress national )  =>  origine = 0  (DPV)
SI (ogtiAddressTON_660004600 == 8 && ogtiAddressNPI_660004600 == 1 && ogtiAddressDIGIT1_660004600 == 0 && ogtiAddressDIGIT2_660004600 > 0 && ogtiAddressDIGIT2_660004600 <= 9)
ALORS
#  -- mise a jour du champ origine (val = 0)
  erreur_660004600=i_set_art_field(g_iartout,$Tdpvgsm::origine,0)
SINON

#  -- SI TON+NPI=81 et  Z = 0 ou TON+NPI=91 (ogtiAddress international)    =>  origine = 1  (DPV)
  SI ( (ogtiAddressTON_660004600 == 8 && ogtiAddressNPI_660004600 == 1 && ogtiAddressDIGIT1_660004600 == 0 && ogtiAddressDIGIT2_660004600 == 0) || (ogtiAddressTON_660004600 == 9 && ogtiAddressNPI_660004600 == 1) )
  ALORS
    erreur_660004600=i_set_art_field(g_iartout,$Tdpvgsm::origine,1)
  SINON
#  -- origine = 0xFF (DPV)
    erreur_660004600=i_set_art_field(g_iartout,$Tdpvgsm::origine,0xff)
  FINSI
FINSI

####################################################################
#   Gestion du champ "facturation au destinataire" CRA CMG


i_strcpy(pt_cmg_fact_inf_660004600,i_get_tab_field("VariableContexte",date_pivot_660004600,"CMG_FACT_INF"))
i_strcpy(pt_cmg_fact_sup_660004600,i_get_tab_field("VariableContexte",date_pivot_660004600,"CMG_FACT_SUP"))

#-- conversion des chaine pt_cmg_fact_inf et pt_cmg_fact_sup aux entiers

cmg_fact_inf_660004600=Convert_alpha_entier_660004265(pt_cmg_fact_inf_660004600)
cmg_fact_sup_660004600=Convert_alpha_entier_660004265(pt_cmg_fact_sup_660004600)

erreur_660004600 = i_get_art_str(g_iartin,$TSms_cmg::consolidationA,pt_consolAlph_660004600)

i_get_sub_str(pt_consolAlph_660004600,0,4,pt_consolAlph_660004600)
trace2("consolAlph : %s %s",pt_consolAlph_660004600,"")
pt_erreur_660004600=i_get_tab_field("SMS_CMG_Gateway",date_pivot_660004600,pt_consolAlph_660004600)
SI (i_strcmp(pt_erreur_660004600,g_inull))
ALORS
  trace("** Cas SMS depuis Gateway,comparer billId avec fact_inf et fact_sup) **")

  erreur_660004600 = i_get_art_str(g_iartin,$TSms_cmg::billIDA,pt_billidAlph_660004600)
  length_billID_660004600=i_get_art_field(g_iartin,$TSms_cmg::billID-1)
  i_get_sub_str(pt_billidAlph_660004600,0, length_billID_660004600-1,pt_billidAlph_660004600)

#--conversion de pt_billidAlph a un entier

  billiD_Num_660004600=Convert_alpha_entier_660004265(pt_billidAlph_660004600)
  trace2("SMS MT pt_billidAlph :\"%s\"%s",pt_billidAlph_660004600, "")
  trace1("SMS MT billID_Num :<%d>",billiD_Num_660004600)

  SI (billiD_Num_660004600<=cmg_fact_sup_660004600 && billiD_Num_660004600 >=cmg_fact_inf_660004600)
  ALORS
    erreur_660004600=i_set_art_field(g_iartout,$Tdpvgsm::factdest,1)
  SINON
    erreur_660004600=i_set_art_field(g_iartout,$Tdpvgsm::factdest,0)
  FINSI
SINON
  trace("**Cas SMS depuis serveur prive,comparer consolidation avec fact_inf et fact_sup **")

#  -- SI CMG_FACT_INF <= consolNum <= CMG_FACT_SUP    => factdest = 1  (DPV)

#-- conversion de la chaine pt_consolAlph vers un entier

  consolNum_660004600=Convert_alpha_entier_660004265(pt_consolAlph_660004600)
  trace2("SMS MT pt_consolAlph :<%s> %s",pt_consolAlph_660004600, "")
  trace1("SMS MT consolNum:<%d>",consolNum_660004600)

  SI (consolNum_660004600<=cmg_fact_sup_660004600 &&consolNum_660004600>=cmg_fact_inf_660004600)
  ALORS
    erreur_660004600=i_set_art_field(g_iartout,$Tdpvgsm::factdest,1)
  SINON
#  -- factdest = 0 (DPV)
    erreur_660004600=i_set_art_field(g_iartout,$Tdpvgsm::factdest,0)
  FINSI

FINSI

#############################################################################
#---- Mise a jour du champ indeff
SI (status_val_660004600 == 0)
ALORS
# --- Mise a jour champ indeff a 0x00
  erreur_660004600 = i_set_art_field(g_iartout,$Tdpvgsm::indeff,0x00)
SINON
# --- Mise a jour champ indeff a 0x04
  erreur_660004600 = i_set_art_field(g_iartout,$Tdpvgsm::indeff,0x04)
FINSI

####################################################################
#   Mise a jour du champ Class of the SMS <classe> V4t13.1.2
SI (i_valid_field_n(g_iartin,$TSms_cmg::contentDcs))
ALORS
  erreur_660004600 = i_get_art_str(g_iartin,$TSms_cmg::contentDcsA,pt_contentDcs_660004600)
  length_contentDcs_660004600=i_get_art_field(g_iartin,$TSms_cmg::contentDcs-1)
  i_get_sub_str(pt_contentDcs_660004600,0,length_contentDcs_660004600-1,pt_contentDcs_660004600)
  trace2("SMS-C contentDCs:<%s> %s", pt_contentDcs_660004600,"")
  SI (!(i_strcmp(pt_contentDcs_660004600,"DATA")))
  ALORS
    trace("SMS-C MT: Le champ contentDcs==\"DATA\" -> classe=0x01")
    erreur_660004600 = i_set_art_field(g_iartout,$Tdpvgsm::classe,0x01)
  FINSI
SINON
  trace("SMS-C MT: Le champ contentDcs!=\"DATA\" -> classe=0x00")
  erreur_660004600 = i_set_art_field(g_iartout,$Tdpvgsm::classe,0x00)
FINSI

####################################################################
#   Mise a jour du champ <reserve1> V4t13.1.7
#-- SI SMS MT depuis Gateway
#---- SI billid==origAddress sans le TON+NPI et sans les F de bourrage => reserve =0
#---- SINON  => reserve1=1
#-- SINON SI SMS MT depuis serveur prive => reserve=0
#---------SINON reserve1=1

erreur_660004600 = i_get_art_str(g_iartin,$TSms_cmg::consolidationA,pt_consolAlph_660004600)
i_get_sub_str(pt_consolAlph_660004600,0,4,pt_consolAlph_660004600)
pt_erreur_660004600=i_get_tab_field("SMS_CMG_Gateway",date_pivot_660004600,pt_consolAlph_660004600)
SI (i_strcmp(pt_erreur_660004600,g_inull))
ALORS
  erreur_660004600 = i_get_art_str(g_iartin,$TSms_cmg::billIDA,pt_billidAlph_660004600)
  length_billID_660004600=i_get_art_field(g_iartin,$TSms_cmg::billID-1)
  i_get_sub_str(pt_billidAlph_660004600,0,length_billID_660004600-1,pt_billidAlph_660004600)

#-- fonction qui recupere le nombre de quartets sans tenir compte des F de bourage

  taille_origAddress_660004600=i_get_art_fieldlength(g_iartin,$TSms_cmg::origAddress)
  taille_billid_660004600=i_strlen(pt_billidAlph_660004600)
  trace1("taille_billid : %d",taille_billid_660004600)
  trace1("taille_origAddress sans TON NPI : %d",taille_origAddress_660004600-2)
  SI (taille_origAddress_660004600-2 !=taille_billid_660004600)
  ALORS
    champ_diff_660004600=1
    SAUT MET_AJOUR_RESERVE1
  SINON
#-- indice origAddress commence de l'offset 2 pour ne pas prendre en compte le TON et NPI

    indice_origAddress_660004600=2
    indice_billid_660004600=0
    champ_diff_660004600=0

    POINT BOUCLE_CMP_BILLID_ORIGADDERSS
    SI(indice_billid_660004600>=taille_billid_660004600)
    ALORS
      SAUT MET_AJOUR_RESERVE1
    FINSI
    val_origAddress_660004600=i_get_art_fieldtab(g_iartin,$TSms_cmg::origAddress,indice_origAddress_660004600)
    val_billid_660004600=i_strtab(pt_billidAlph_660004600,indice_billid_660004600)
    val_billid_660004600=val_billid_660004600 - 0x30
    trace3("val_origAdress(%d)=%d|taille_origAddress=%d",indice_origAddress_660004600,val_origAddress_660004600,taille_origAddress_660004600)
    trace3("val_billid(%d)=%d|taille_billid=%d",indice_billid_660004600,val_billid_660004600,taille_billid_660004600)

    SI (val_billid_660004600!=val_origAddress_660004600)
    ALORS
      champ_diff_660004600=1
      SAUT MET_AJOUR_RESERVE1
    SINON
      indice_billid_660004600=indice_billid_660004600+1
      indice_origAddress_660004600=indice_origAddress_660004600+1
      SAUT BOUCLE_CMP_BILLID_ORIGADDERSS
    FINSI
  FINSI

SINON
  trace("** [reserve1] Cas SMS-C CMG MT depuis serveur prive **")
# indice origAddress commence de l'offset 2 pour ne pas prendre en compte le TON + NPI
  indice_origAddress_660004600=2
  indice_consolidation_660004600=0
  champ_diff_660004600=0

  taille_origAddress_660004600=i_get_art_fieldlength(g_iartin,$TSms_cmg::origAddress)
  taille_consol_660004600 =i_strlen(pt_consolAlph_660004600)
  trace1("taille_consol: %d",taille_consol_660004600)
  trace1("taille_origAddress sans TON NPI : %d",taille_origAddress_660004600-2)
  SI (taille_origAddress_660004600-2 !=taille_consol_660004600)
  ALORS
    champ_diff_660004600=1
    SAUT MET_AJOUR_RESERVE1
  SINON
    indice_billid_660004600=0
    indice_origAddress_660004600=2
    champ_diff_660004600=0

    POINT BOUCLE_CMP_CONSOL_ORIGADDERSS
    SI(indice_consolidation_660004600>=taille_consol_660004600)
    ALORS
      SAUT MET_AJOUR_RESERVE1
    FINSI
    val_origAddress_660004600=i_get_art_fieldtab(g_iartin,$TSms_cmg::origAddress,indice_origAddress_660004600)
    val_consolidation_660004600=i_strtab(pt_consolAlph_660004600,indice_consolidation_660004600)
    val_consolidation_660004600=val_consolidation_660004600 - 0x30
    trace3("val_origAdress[%d]=%d |taille_origAddress=%d",indice_origAddress_660004600,val_origAddress_660004600,taille_origAddress_660004600)
    trace3("val_consolidation[%d]=%d |taille_consol=%d",indice_consolidation_660004600, val_consolidation_660004600,taille_consol_660004600)
    SI(val_consolidation_660004600!=val_origAddress_660004600)
    ALORS
      champ_diff_660004600=1
      SAUT MET_AJOUR_RESERVE1
    SINON
      indice_consolidation_660004600=indice_consolidation_660004600+1
      indice_origAddress_660004600=indice_origAddress_660004600+1
      SAUT BOUCLE_CMP_CONSOL_ORIGADDERSS
    FINSI
  FINSI

FINSI

#-- mettre a jour le champ reserve suivant la valeur de champ_diff

POINT MET_AJOUR_RESERVE1
SI (champ_diff_660004600==1)
ALORS
  trace("champs differents ->reserve1=0x01")
  erreur_660004600 = i_set_art_field(g_iartout,$Tdpvgsm::reserve1,0x01)
SINON
  trace("champs identiques ->reserve1=0x00")
  erreur_660004600 = i_set_art_field(g_iartout,$Tdpvgsm::reserve1,0x00)
FINSI


#-- duplication du champ ASCIIstring T3t62
#-- si reserve1=1 (dpv) et
#-- si origAddress est present => ASCIIstring contient la conversion en ASCII du champ origAddress
#-- sinon le champ DPV est absent

SI (i_get_art_field(g_iartout ,$Tdpvgsm::reserve1 ) == 1)
ALORS
  trace("SMS-C CMG MT: flagOADC est a 1->ajout ASCIIString")
  erreur_660004600 = i_ajout_tlv(g_iartout, "T3t62", "")
  taille_origAddress_660004600 = i_get_art_field(g_iartin,$TSms_cmg::origAddress -1)*2
  SI (taille_origAddress_660004600 <= 30)
  ALORS
    erreur_660004600 = i_resize_tlv(g_iartout,"T3t62","ASCIIString", taille_origAddress_660004600)
  SINON
    taille_origAddress_660004600 = 30
    erreur_660004600 = i_resize_tlv(g_iartout,"T3t62","ASCIIString", 30)
  FINSI

  indice_origAddress_660004600 = 0

  erreur_660004600 = i_cree_art("TnormalDAscii", g_iartout5)
  erreur_660004600 = i_ajout_tlv(g_iartout5, "T3t1", "")

  POINT BOUCLE_ASCIIString
  SI (indice_origAddress_660004600 < taille_origAddress_660004600)
  ALORS
    val_origAddress_660004600 = i_get_art_fieldtab(g_iartin,$TSms_cmg::origAddress, indice_origAddress_660004600)
    SI (val_origAddress_660004600 >= 0 && val_origAddress_660004600 <= 9)
    ALORS
      trace1("valeur OrigAddress + Ox30 %d", val_origAddress_660004600 + 0x30)
      erreur_660004600 = i_set_art_fieldtab(g_iartout5, $TnormalDAscii::buf, indice_origAddress_660004600, val_origAddress_660004600 + 0x30)
    SINON
      trace1("valeur OrigAddress + Ox37 %d", val_origAddress_660004600 + 0x37)
      erreur_660004600 = i_set_art_fieldtab(g_iartout5, $TnormalDAscii::buf, indice_origAddress_660004600, val_origAddress_660004600 + 0x37)
    FINSI
    indice_origAddress_660004600 = indice_origAddress_660004600 + 1
    SAUT BOUCLE_ASCIIString
  FINSI
  erreur_660004600 = i_memcpy_art_field_n(g_iartout, $Tdpvgsm::ASCIIString, g_iartout5.buf[], taille_origAddress_660004600)
  erreur_660004600 = i_resize_tlv(g_iartout,"T3t62","ASCIIString", taille_origAddress_660004600)

FINSI

#----- envoi de l article e IEEC

# Ajout des T3t55 et T3t56
SI !(i_valid_field_n(g_iartout, $Tdpvgsm::GFlag2))
ALORS
  erreur_660004600 = i_ajout_tlv(g_iartout,"T3t55","")
FINSI

SI !(i_valid_field_n(g_iartout, $Tdpvgsm::GValue))
ALORS
  erreur_660004600 = i_ajout_tlv(g_iartout,"T3t56","")
FINSI

SI !(i_valid_field_n(g_iartout, $Tdpvgsm::GretaTag))
ALORS
  erreur_660004600 = i_ajout_tlv(g_iartout,"T3t99","")
FINSI

# QC1005
erreur_660004600 = aiguillage2_660004590 (g_iartin, g_iartout, DISTRIBUTION_INCONNU_660004600, Multidistribution_Non_660004600)
SI (erreur_660004600 == TRAI_KO_660004600)
ALORS
  trace("<<<__LINE__<<<__FILE__<<< Erreur retour fonction aiguillage2")
  SAUT STOCKE_ERRONE
FINSI
RETOUR TRAIT_OK

#------- Point de branchement pour stockage en errone-------

POINT STOCKE_ERRONE
trace("SMS-C CMG [DIST]: stokage de l article en errone")
erreur_660004600 = i_make_art_rej(g_iartin, g_iartout11, code_rejet_660004600)
erreur_660004600 = i_stocke_art(g_iartout11, 0, PT_ERRONE, 0)
trace( "Fin traitement, Article TSms_cmg ERRONE " )

RETOUR TRAIT_OK

#----fin traitement module de distribution TSms_cmg_dis.src ----------------
