Delimiter $$
/**
 * Author:  armen
 * Created: 21 juin 2018
 */
--  contacts
Drop Procedure if Exists BUSINESS_COMPUTE_PUBLICVIEWS_CONTACTS $$
Create Procedure BUSINESS_COMPUTE_PUBLICVIEWS_CONTACTS ()
Begin
    Truncate Table TMP_V_PUBLIC_CONTACTS_VIEW;

    Insert Into TMP_V_PUBLIC_CONTACTS_VIEW (
        ID_CONTACTS
        , CONTACTS_ID_CONTACTS
        , ACCOUNTS_ID_ACCOUNTS
        , CONTACTS_IS_MAIN
        , DF_LANGUAGES_ID_DF_LANGUAGE
        , DF_LANGUAGES_CODE
        , DF_LANGUAGES_LABEL
        , DF_SANDBOX_STATE_CODE
        , CONTACTS_REF
        , CONTACTS_NOTE
        , CONTACTS_TRASHED
        , CONTACTS_LAST_UPDATE
        , CONTACTS_INDIVIDUAL_ID_CONTACTS_INDIVIDUAL
        , DF_TITLES_ID_DF_TITLES
        , DF_TITLES_SHORT_TITLE
        , DF_TITLES_FULL_TITLE
        , DF_FUNCTIONS_ID_DF_FUNCTIONS
        , DF_FUNCTIONS_SHORT_LABEL
        , DF_FUNCTIONS_LABEL
        , CONTACTS_INDIVIDUAL_FIRST_NAME
        , CONTACTS_INDIVIDUAL_LAST_NAME
        , CONTACTS_INDIVIDUAL_BIRTH_NAME
        , CONTACTS_INDIVIDUAL_FULL_NAME
        , CONTACTS_INDIVIDUAL_BIRTH_DAY
        , CONTACTS_INDIVIDUAL_LAST_UPDAT
        , CONTACTS_BUSINESS_ID_CONTACTS_BUSINESS
        , CONTACTS_IS_BUSINESS
        , DF_FORMS_ID_DF_FORMS
        , DF_FORMS_SHORT_FORM
        , DF_FORMS_FULL_TITLE
        , CONTACTS_BUSINESS_COMPANY_NAME
        , CONTACTS_BUSINESS_BRAND_NAME
        , CONTACTS_BUSINESS_SIRET
        , CONTACTS_BUSINESS_NAF
        , CONTACTS_BUSINESS_CAPITAL
        , CONTACTS_BUSINESS_CREATED_DATE
        , CONTACTS_BUSINESS_LAST_UPDATE
        , MEMBERS_ID_MEMBERS
        , CONTACTS_IS_MEMBER
        , ENTITIES_ID_ENTITIES
        , CONTACTS_IS_ENTITY
        , CONTACTS_GLOBAL_NAME
    )
    Select 
        ID_CONTACTS
        , CONTACTS_ID_CONTACTS
        , ACCOUNTS_ID_ACCOUNTS
        , CONTACTS_IS_MAIN
        , DF_LANGUAGES_ID_DF_LANGUAGE
        , DF_LANGUAGES_CODE
        , DF_LANGUAGES_LABEL
        , DF_SANDBOX_STATE_CODE
        , CONTACTS_REF
        , CONTACTS_NOTE
        , CONTACTS_TRASHED
        , CONTACTS_LAST_UPDATE
        , CONTACTS_INDIVIDUAL_ID_CONTACTS_INDIVIDUAL
        , DF_TITLES_ID_DF_TITLES
        , DF_TITLES_SHORT_TITLE
        , DF_TITLES_FULL_TITLE
        , DF_FUNCTIONS_ID_DF_FUNCTIONS
        , DF_FUNCTIONS_SHORT_LABEL
        , DF_FUNCTIONS_LABEL
        , CONTACTS_INDIVIDUAL_FIRST_NAME
        , CONTACTS_INDIVIDUAL_LAST_NAME
        , CONTACTS_INDIVIDUAL_BIRTH_NAME
        , CONTACTS_INDIVIDUAL_FULL_NAME
        , CONTACTS_INDIVIDUAL_BIRTH_DAY
        , CONTACTS_INDIVIDUAL_LAST_UPDAT
        , CONTACTS_BUSINESS_ID_CONTACTS_BUSINESS
        , CONTACTS_IS_BUSINESS
        , DF_FORMS_ID_DF_FORMS
        , DF_FORMS_SHORT_FORM
        , DF_FORMS_FULL_TITLE
        , CONTACTS_BUSINESS_COMPANY_NAME
        , CONTACTS_BUSINESS_BRAND_NAME
        , CONTACTS_BUSINESS_SIRET
        , CONTACTS_BUSINESS_NAF
        , CONTACTS_BUSINESS_CAPITAL
        , CONTACTS_BUSINESS_CREATED_DATE
        , CONTACTS_BUSINESS_LAST_UPDATE
        , MEMBERS_ID_MEMBERS
        , CONTACTS_IS_MEMBER
        , ENTITIES_ID_ENTITIES
        , CONTACTS_IS_ENTITY
        , CONTACTS_GLOBAL_NAME
    From V_PUBLIC_CONTACTS_VIEW
    Where
    -- ci-dessous la champ TMP_V_PUBLIC_CONTACTS_VIEW.ACCOUNTS_ID_ACCOUNTS n'est pas nullable et
    -- la valeur par défaut n'est pas inséré du fait de la presence du champ dans la projection
    -- vu avec OB : uniquement les contacts associés aux comptes
    -- pour avoir tous les contacts, il faudra rendre nullable le champ TMP_V_PUBLIC_CONTACTS_VIEW.ACCOUNTS_ID_ACCOUNTS
          ACCOUNTS_ID_ACCOUNTS Is Not Null
    ;
End $$
Delimiter ;




