DEFINITION INCREMENT_660004716 1
DEFINITION CPT_1501_660004716 1501
DEFINITION CPT_4G_660004716 1533
DEFINITION MODULE_660004716 0x5000
DEFINITION ERR_SEM_660004716 0x040
DEFINITION ERR_DATE_660004716 0x060
DEFINITION ERR_CROISE_660004716 0x0F0
DEFINITION EFFICACE_660004716 1
DEFINITION OFFSET_660004716 11
DEFINITION ENTRANT_660004716 0x01
DEFINITION SORTANT_660004716 0x00
DEFINITION RENVOIG_660004716 0x06
DEFINITION RENVOIM_660004716 0x02
REGISTRE ENTIER code_erreur_660004716
REGISTRE ENTIER code_rejet_660004716
REGISTRE ENTIER date_660004716
REGISTRE ENTIER date_audit_660004716
REGISTRE ENTIER erreur_660004716
REGISTRE ENTIER recordtype_660004716
REGISTRE ENTIER roleofnode_660004716
REGISTRE ENTIER causeforrecclos_660004716
REGISTRE ENTIER cgitype_660004716
REGISTRE ENTIER transactiontype_660004716
REGISTRE ENTIER subidtype01_660004716
REGISTRE ENTIER subidtype02_660004716
REGISTRE ENTIER callduration_660004716
REGISTRE ENTIER indice_660004716
REGISTRE ENTIER servicetype_660004716
REGISTRE ENTIER Mode_ServiceType6_660004716
REGISTRE ENTIER type_CRA_660004716
REGISTRE ENTIER b_RENVOI_660004716
######################################################################
#
#    TmmTelTas_trait.src
#
#
# article CRA TmmTelTas ASN1 => type DPV TLV = 0x83 (T1=0x69 T2=0x02)
#
# 13/11/2014 - RHE - G5R3 lot2 : Creation
# 05/12/2014 - RHE - G5R3 lot3 : QC1468 calcul type SORTANT
# 12/12/2014 - RHE - G5R3 lot3 QC1472
# 26/01/2015 - RHE - G5R3 lot3 QC1502 pas d'envoi en errone si champ sceDeliveryEndTime absent
# 05/02/2015 - JLG - G5R3 QC1513 : Presence au moins d'un des champs : T4t5.1/callingAdr01 ou T4t5.2/callingAdr02
# 06/02/2015 - JLG - G5R3 QC1514 sceDelivStartT plus obligatoire
# 24/02/2015 - RHE - G5R3 QC1523 evolution : suppression de la variable renvoiAssociated
# 23/04/2015 - JLG - G5R4 QC1549, evolution des T4 du T3t5 Calling sequence de LCPA_sIP_URI et LCPA_tEL_URI
######################################################################






trace("<<<<<< TmmTelTas_trait : Debut TRAITEMENT")

########## Controles unitaires sur les champs de l'article ##########

# QC1514 evolution
SI (i_valid_field_n(g_iartin, $TmmTelTas::sceDelivStartT))
ALORS
  date_660004716  = i_get_art_field(g_iartin,$TmmTelTas::sceDelivStartT)
SINON
  date_660004716  = i_get_art_field(g_iartin,$TmmTelTas::SceReqTimeStamp)
FINSI

#trace1("<<<__LINE__<<<__FILE__<<< TmmTelTas_trait: date (sceDelivStartT) = %d ", date)
SI (date_660004716 == -1)
ALORS
  trace1("TmmTelTas_trait : champ date, sceDelivStartT incorrect = 0x%x", date_660004716)
  code_erreur_660004716 = ERR_DATE_660004716
  code_rejet_660004716 = MODULE_660004716 + code_erreur_660004716 + EFFICACE_660004716
  erreur_660004716 = i_PlvMessEmettre(6080,2,g_iartin,"",1, code_rejet_660004716, 0, 0)
  SAUT STOCKE_ERRONE
FINSI

# test recordType, valeur attendue 0x53 (83 dec)
recordtype_660004716 = i_get_art_field(g_iartin,$TmmTelTas::recordType)
#trace1("<<<__LINE__<<<__FILE__<<< TmmTelTas_trait: recordtype = %d ", recordtype)
SI (recordtype_660004716 != 0x53)
ALORS
  trace1("TmmTelTas_trait : champ recordType != 0x83 car = 0x%x", recordtype_660004716)
  code_erreur_660004716 = ERR_SEM_660004716
  code_rejet_660004716 = MODULE_660004716 + code_erreur_660004716 + EFFICACE_660004716
  erreur_660004716 = i_PlvMessEmettre(6082, 2, g_iartin, "",2, code_rejet_660004716, recordtype_660004716, 0)
  SAUT STOCKE_ERRONE
FINSI

# test roleOfNode, valeur 0 ou 1
roleofnode_660004716 = i_get_art_field(g_iartin,$TmmTelTas::roleOfNode)
#trace1("<<<__LINE__<<<__FILE__<<< TmmTelTas_trait: roleofnode = %d ", roleofnode)
SI (roleofnode_660004716 != 0x0 && roleofnode_660004716 != 0x1)
ALORS
  trace1("TmmTelTas_trait : champ roleOfNode != 0 ou 1 car = 0x%x", roleofnode_660004716)
  code_erreur_660004716 = ERR_SEM_660004716
  code_rejet_660004716 = MODULE_660004716 + code_erreur_660004716 + EFFICACE_660004716
  erreur_660004716 = i_PlvMessEmettre(6083, 2, g_iartin, "",2, code_rejet_660004716, roleofnode_660004716, 0)
  SAUT STOCKE_ERRONE
FINSI

# test causeForRecClos, valeur:  0x0, 0x1, 0x64, 0x65
causeforrecclos_660004716 = i_get_art_field(g_iartin,$TmmTelTas::causeForRecClos)
#trace1("<<<__LINE__<<<__FILE__<<< TmmTelTas_trait: causeforrecclos = %d ", causeforrecclos)
#QC1472 ajout de 0x03
#SI (causeforrecclos != 0x0 && causeforrecclos != 0x1 && causeforrecclos != 0x64 && causeforrecclos != 0x65)
SI (causeforrecclos_660004716 != 0x0 && causeforrecclos_660004716 != 0x1 && causeforrecclos_660004716 != 0x3 && causeforrecclos_660004716 != 0x64 && causeforrecclos_660004716 != 0x65)
ALORS
  trace1("TmmTelTas_trait : champ causeForRecClos != 0x0, 0x1, 0x64, 0x65 car = 0x%x", causeforrecclos_660004716)
  code_erreur_660004716 = ERR_SEM_660004716
  code_rejet_660004716 = MODULE_660004716 + code_erreur_660004716 + EFFICACE_660004716
  erreur_660004716 = i_PlvMessEmettre(6084, 2, g_iartin, "",2, code_rejet_660004716, causeforrecclos_660004716, 0)
  SAUT STOCKE_ERRONE
FINSI

# test cgiType, valeur 0 ou 1 (si champ present)
SI (i_valid_field_n(g_iartin, $TmmTelTas::cgiType))
ALORS
  cgitype_660004716 = i_get_art_field(g_iartin,$TmmTelTas::cgiType)
  #trace1("<<<__LINE__<<<__FILE__<<< TmmTelTas_trait: cgitype = %d ", cgitype)
  SI (cgitype_660004716 != 0x00 && cgitype_660004716 != 0x01)
  ALORS
    trace1("TmmTelTas_trait : champ cgiType != 0 ou 1 car = 0x%x", cgitype_660004716)
    code_erreur_660004716 = ERR_SEM_660004716
    code_rejet_660004716 = MODULE_660004716 + code_erreur_660004716 + EFFICACE_660004716
    erreur_660004716 = i_PlvMessEmettre(6085, 2, g_iartin, "",2, code_rejet_660004716, cgitype_660004716, 0)
    SAUT STOCKE_ERRONE
  FINSI
FINSI

# T4t24.1/SubIdType01 = 0 ou 1
subidtype01_660004716 = i_get_art_field(g_iartin,$TmmTelTas::subIdType01)
#trace1("<<<__LINE__<<<__FILE__<<< TmmTelTas_trait: subidtype01 = %d ", subidtype01)
SI (subidtype01_660004716 != 0x00 && subidtype01_660004716 != 0x01)
ALORS
  trace1("TmmTelTas_trait : champ SubIdType01 != 0 ou 1 car = 0x%x", subidtype01_660004716)
  code_erreur_660004716 = ERR_SEM_660004716
  code_rejet_660004716 = MODULE_660004716 + code_erreur_660004716 + EFFICACE_660004716
  erreur_660004716 = i_PlvMessEmettre(6086, 2, g_iartin, "",2, code_rejet_660004716, subidtype01_660004716, 0)
  SAUT STOCKE_ERRONE
FINSI

# T4t24.3/SubIdType02 = 0 ou 1
SI (i_valid_field_n(g_iartin, $TmmTelTas::subIdType02))
ALORS
  subidtype02_660004716 = i_get_art_field(g_iartin,$TmmTelTas::subIdType02)
  #trace1("<<<__LINE__<<<__FILE__<<< TmmTelTas_trait: subidtype02 = %d ", subidtype02)
  SI (subidtype02_660004716 != 0x00 && subidtype02_660004716 != 0x01)
  ALORS
    trace1("TmmTelTas_trait : champ SubIdType02 != 0 ou 1 car = 0x%x", subidtype02_660004716)
    code_erreur_660004716 = ERR_SEM_660004716
    code_rejet_660004716 = MODULE_660004716 + code_erreur_660004716 + EFFICACE_660004716
    erreur_660004716 = i_PlvMessEmettre(6087, 2, g_iartin, "",2, code_rejet_660004716, subidtype02_660004716, 0)
    SAUT STOCKE_ERRONE
  FINSI
SINON
  subidtype02_660004716 = -1
FINSI


########## Controles croises entre champs de l'article ##########

transactiontype_660004716 = i_get_art_field(g_iartin,$TmmTelTas::transactionType)
#trace1("<<<__LINE__<<<__FILE__<<< TmmTelTas_trait: transactiontype = %d ", transactiontype)

# T3t3/roleOfNode = 0 (Originating) et T3t21/TransactionType =  2 ou 5
SI (roleofnode_660004716 == 0)
ALORS
  SI (transactiontype_660004716 != 0x02 && transactiontype_660004716 != 0x05)
  ALORS
    trace1("TmmTelTas_trait : controle croise champ roleOfNode = 0 et TransactionType != 2 ou 5 car = 0x%x", transactiontype_660004716)
    code_erreur_660004716 = ERR_CROISE_660004716
    code_rejet_660004716 = MODULE_660004716 + code_erreur_660004716 + EFFICACE_660004716
    erreur_660004716 = i_PlvMessEmettre(6088, 2, g_iartin, "", 3, code_rejet_660004716, roleofnode_660004716, transactiontype_660004716)
    SAUT STOCKE_ERRONE
  FINSI
FINSI

# T3t3/roleOfNode = 1 (Terminating) et T3t21/TransactionType  =  3 , 6 ou 7
SI (roleofnode_660004716 == 1)
ALORS
  SI (transactiontype_660004716 != 0x03 && transactiontype_660004716 != 0x06 && transactiontype_660004716 != 0x07)
  ALORS
    trace1("TmmTelTas_trait : controle croise champ roleOfNode = 1 et TransactionType != 3,6 ou 7 car = 0x%x", transactiontype_660004716)
    code_erreur_660004716 = ERR_CROISE_660004716
    code_rejet_660004716 = MODULE_660004716 + code_erreur_660004716 + EFFICACE_660004716
    erreur_660004716 = i_PlvMessEmettre(6088, 2, g_iartin, "", 3, code_rejet_660004716,roleofnode_660004716, transactiontype_660004716)
    SAUT STOCKE_ERRONE
  FINSI
FINSI

# Presence champ : T4t24.1/SubIdType01 = 0 ou T4t24.3/SubIdType02 = 0
SI (subidtype01_660004716 != 0  && subidtype02_660004716 != 0)
ALORS
  trace("TmmTelTas_trait : controle croise champ SubIdType01 != 0 et SubIdType02 != 0")
  code_erreur_660004716 = ERR_CROISE_660004716
  code_rejet_660004716 = MODULE_660004716 + code_erreur_660004716 + EFFICACE_660004716
  erreur_660004716 = i_PlvMessEmettre(6089, 2, g_iartin, "", 3, code_rejet_660004716, subidtype01_660004716, subidtype02_660004716)
  SAUT STOCKE_ERRONE
FINSI

# QC1549 : Presence au moins d'un des champs : T4t5.1/callingSipAdr01 ou T4t5.2/callingTelAdr01 ou T4t5.1/callingSipAdr02 ou T4t5.2/callingTelAdr02
SI ( !i_valid_field_n(g_iartin, $TmmTelTas::callingSipAdr01) && !i_valid_field_n(g_iartin, $TmmTelTas::callingTelAdr01) && !i_valid_field_n(g_iartin, $TmmTelTas::callingSipAdr02) && !i_valid_field_n(g_iartin, $TmmTelTas::callingTelAdr02))
ALORS
  trace("TmmTelTas_trait : controle croise presence callingSipAdr01 ou callingTelAdr01 ou callingSipAdr02 ou callingTelAdr02")
  code_erreur_660004716 = ERR_CROISE_660004716
  code_rejet_660004716 = MODULE_660004716 + code_erreur_660004716 + EFFICACE_660004716
  erreur_660004716 = i_PlvMessEmettre(6081, 2, g_iartin, "", 1, code_rejet_660004716, 0, 0)
  SAUT STOCKE_ERRONE
FINSI

########## Controles de valorisation - Elimination des CRAs MMTel ##########

# doublons de CRA reseau
SI (i_valid_field_n(g_iartin, $TmmTelTas::callDuration))
ALORS
  callduration_660004716 = i_get_art_field(g_iartin,$TmmTelTas::callDuration)
  #trace1("<<<__LINE__<<<__FILE__<<< TmmTelTas_trait: callduration = %d ", callduration)
  SI (callduration_660004716 != 0 && roleofnode_660004716 == 1 && (transactiontype_660004716 == 6 || transactiontype_660004716 == 7))
  ALORS
    #trace("TmmTelTas_trait : Doublons de CRA reseau -> STOCKE_ELIMINE")
    SAUT STOCKE_ELIMINE
  FINSI
FINSI

# CDR partiel
SI (causeforrecclos_660004716 == 0x64 || causeforrecclos_660004716 == 0x65)
ALORS
  #trace("TmmTelTas_trait : CDR partiel (champ causeForRecClos = 0x64 ou 0x65 -> STOCKE_ELIMINE")
  SAUT STOCKE_ELIMINE
FINSI


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

# Mode_ServiceType6, renvoiAssociated (non utilise en traitement)
# recherche de serviceTypexx = 6 (si roleOfNode = 0 et TransactionType = 5)
Mode_ServiceType6_660004716 = -1
SI(roleofnode_660004716 == 0 && transactiontype_660004716 == 5)
ALORS

  indice_660004716 = 1

  POINT DEBUT_RECHERCHE_servicetype

  SI !(i_valid_field_n(g_iartin,$TmmTelTas::serviceType00 + (OFFSET_660004716 * (indice_660004716 - 1))))
  ALORS
    trace("TmmTelTas_trait : Pas de serviceTypexx = 6")
    code_erreur_660004716 = ERR_SEM_660004716
    code_rejet_660004716 = MODULE_660004716 + code_erreur_660004716 + EFFICACE_660004716
    erreur_660004716 = i_PlvMessEmettre(6090, 2, g_iartin, "", 1, code_rejet_660004716, 0, 0)
    SAUT STOCKE_ERRONE
  FINSI

  servicetype_660004716 = i_get_art_field(g_iartin,$TmmTelTas::serviceType00 + (OFFSET_660004716 * (indice_660004716 - 1)))
  SI (servicetype_660004716 != 6)
  ALORS
    indice_660004716 = indice_660004716 +1
    SAUT DEBUT_RECHERCHE_servicetype
  FINSI
  
#QC1523 suppression de renvoiAssociated
  SI !(i_valid_field_n(g_iartin,$TmmTelTas::serviceMode00 + (OFFSET_660004716 * (indice_660004716 - 1))))
#    || !(i_valid_field_n(g_iartin,$TmmTelTas::associatedAdr00 + (OFFSET * (indice - 1))))
  ALORS
    #trace("TmmTelTas_trait : serviceMode et/ou associatedAdr absent")
    trace("TmmTelTas_trait : serviceMode absent")
    code_erreur_660004716 = ERR_SEM_660004716
    code_rejet_660004716 = MODULE_660004716 + code_erreur_660004716 + EFFICACE_660004716
    erreur_660004716 = i_PlvMessEmettre(6091, 2, g_iartin, "", 1, code_rejet_660004716, 0, 0)
    SAUT STOCKE_ERRONE
  FINSI
  Mode_ServiceType6_660004716 = i_get_art_field(g_iartin,$TmmTelTas::serviceMode00 + (OFFSET_660004716 * (indice_660004716 - 1)))
  #trace1("<<<__LINE__<<<__FILE__<<< TmmTelTas_trait: Mode_ServiceType6 = %d ", Mode_ServiceType6)

FINSI

# type_CRA: ENTRANT (0x01), SORTANT (0x00), RENVOIG (0x06), RENVOIM (0x02)
SI (roleofnode_660004716 == 1 && (transactiontype_660004716 == 3 || transactiontype_660004716 == 6 || transactiontype_660004716 == 7))
ALORS
  type_CRA_660004716 = ENTRANT_660004716
FINSI

# QC1468
#SI (roleofnode == 0 && (transactiontype == 2 || (transactiontype == 5 && Mode_ServiceType6 == -1)))
SI (roleofnode_660004716 == 0 && transactiontype_660004716 == 2 )
ALORS
  type_CRA_660004716 = SORTANT_660004716
FINSI

SI (roleofnode_660004716 == 0 && transactiontype_660004716 == 5 && Mode_ServiceType6_660004716 == 0)
ALORS
  type_CRA_660004716 = RENVOIG_660004716
FINSI

SI (roleofnode_660004716 == 0 && transactiontype_660004716 == 5 && Mode_ServiceType6_660004716 > 0)
ALORS
  type_CRA_660004716 = RENVOIM_660004716
FINSI
#trace1("<<<__LINE__<<<__FILE__<<< TmmTelTas_trait: type_CRA = %d ", type_CRA)


#SI(type_CRA == RENVOIM || type_CRA == RENVOIG)
#ALORS
# b_RENVOI = 1
#SINON
# b_RENVOI = 1
#FINSI

########## Increment des compteurs ##########

date_audit_660004716 = i_DHgetLocalTime(4, 7, i_date_audit())
#trace1("<<<__LINE__<<<__FILE__<<< TmmTelTas_trait: date_audit = %d ", date_audit)

# Incremenation du compteur (1501) pour tous les CRA non-elimine par les tests ci-dessus
erreur_660004716=i_incr_cpt(CPT_1501_660004716, type_CRA_660004716, g_ieec, 0, date_audit_660004716, INCREMENT_660004716)

# Incremenation du compteur 4G (1533)
erreur_660004716=i_incr_cpt(CPT_4G_660004716, type_CRA_660004716, g_ieec, 0, date_audit_660004716, INCREMENT_660004716)


########## Fin traitement ##########

trace("[Trait] TmmTelTas : Fin traitement OK ")
erreur_660004716 = i_stocke_art(g_iartin, 0, PT_OK, 0)
RETOUR TRAIT_OK


POINT STOCKE_ERRONE
trace( "TmmTelTas_trait : Stockage de l'article en ERRONE" )
erreur_660004716 = i_make_art_rej(g_iartin, g_iartout, code_rejet_660004716)
erreur_660004716 = i_stocke_art(g_iartout,  0, PT_ERRONE, 0)
RETOUR TRAIT_OK


POINT STOCKE_ELIMINE
trace( "TmmTelTas_trait : Stockage de l'article en DIVERS (ELIMINE)" )
erreur_660004716 = i_stocke_art(g_iartin,0,PT_DIVERS,0)
RETOUR TRAIT_OK


#--------------- Fin  TmmTelTas_tr.src --------------------
