Delimiter $$
/**
 * Author:  armen
 * Created: 21 juin 2018
 */

--  Accounts
Drop Procedure if Exists BUSINESS_COMPUTE_PUBLICVIEWS_ACCOUNTS $$
Create Procedure BUSINESS_COMPUTE_PUBLICVIEWS_ACCOUNTS ()
Begin
    Truncate Table TMP_V_PUBLIC_ACCOUNTS_VIEW;

    Insert Into TMP_V_PUBLIC_ACCOUNTS_VIEW (
        ID_ACCOUNTS
        , ACCOUNTS_ID_ACCOUNTS
        , ENTITIES_ID_ENTITIES
        , ENTITIES_CODE
        , DF_CURRENCIES_ID_DF_CURRENCIES
        , DF_CURRENCIES_CODE
        , DF_ACC_CATEG_ID_DF_ACC_CATEG
        , DF_ACC_CATEG_CODE
        , DF_PRIORITY_ID_DF_PRIORITY
        , DF_PRIORITY_LEVEL
        , DF_SAND_STATE_ID_DF_SAND_STATE
        , DF_SANDBOX_STATE_CODE
        , DF_RATE_GRID_ID_DF_RATE_GRID
        , DF_RATE_GRID_CODE
        , DF_RATE_GRID_LABEL
        , DF_DEBTS_TYPES_ID_DF_DEBTS_TYPES
        , DF_DEBTS_TYPES_CODE
        , ACCOUNTS_TYPE
        , DF_ACCOUNTS_TYPES_CODE
        , DF_ACCOUNTS_TYPES_IS_CONSOLIDATED
        , CONTACTS_ID_CONTACTS
        , ACCOUNTS_REF
        , ACCOUNTS_CREATED
        , ACCOUNTS_LAST_EVENT_UPDATE
        , ENTITIES_AGENCIES_ID_ENTITIES_AGENCIES
        , ENTITIES_AGENCIES_CODE
        , ENTITIES_AGENCIES_LABEL_1
        , ENTITIES_AGENCIES_LABEL_2
        , ENTITIES_AGENCIES_LABEL_3
        , ENTITIES_AGENCIES_LABEL_4
        , ENTITIES_AGENCIES_LABEL_5
        , CONTACTS_GLOBAL_NAME
        , CONTACTS_BUSINESS_BRAND_NAME
        , CONTACTS_BUSINESS_COMPANY_NAME
        , CONTACTS_BUSINESS_SIRET
        , CONTACTS_INDIVIDUAL_FIRST_NAME
        , CONTACTS_INDIVIDUAL_LAST_NAME
        , CONTACTS_INDIVIDUAL_BIRTH_NAME
        , DF_FUNCTIONS_SHORT_LABEL
        , CONTACTS_INDIVIDUAL_LAST_UPDAT
        , DF_TITLES_SHORT_TITLE
        , DF_TITLES_FULL_TITLE 
        , ACCOUNTS_NOTES
    )
    Select 
        ID_ACCOUNTS
        , ACCOUNTS_ID_ACCOUNTS
        , ENTITIES_ID_ENTITIES
        , ENTITIES_CODE
        , DF_CURRENCIES_ID_DF_CURRENCIES
        , DF_CURRENCIES_CODE
        , DF_ACC_CATEG_ID_DF_ACC_CATEG
        , DF_ACC_CATEG_CODE
        , DF_PRIORITY_ID_DF_PRIORITY
        , DF_PRIORITY_LEVEL
        , DF_SAND_STATE_ID_DF_SAND_STATE
        , DF_SANDBOX_STATE_CODE
        , DF_RATE_GRID_ID_DF_RATE_GRID
        , DF_RATE_GRID_CODE
        , DF_RATE_GRID_LABEL
        , DF_DEBTS_TYPES_ID_DF_DEBTS_TYPES
        , DF_DEBTS_TYPES_CODE
        , ACCOUNTS_TYPE
        , DF_ACCOUNTS_TYPES_CODE
        , DF_ACCOUNTS_TYPES_IS_CONSOLIDATED
        , CONTACTS_ID_CONTACTS
        , ACCOUNTS_REF
        , ACCOUNTS_CREATED
        , ACCOUNTS_LAST_EVENT_UPDATE
        , ENTITIES_AGENCIES_ID_ENTITIES_AGENCIES
        , ENTITIES_AGENCIES_CODE
        , ENTITIES_AGENCIES_LABEL_1
        , ENTITIES_AGENCIES_LABEL_2
        , ENTITIES_AGENCIES_LABEL_3
        , ENTITIES_AGENCIES_LABEL_4
        , ENTITIES_AGENCIES_LABEL_5
        , CONTACTS_GLOBAL_NAME
        , CONTACTS_BUSINESS_BRAND_NAME
        , CONTACTS_BUSINESS_COMPANY_NAME
        , CONTACTS_BUSINESS_SIRET
        , CONTACTS_INDIVIDUAL_FIRST_NAME
        , CONTACTS_INDIVIDUAL_LAST_NAME
        , CONTACTS_INDIVIDUAL_BIRTH_NAME
        , DF_FUNCTIONS_SHORT_LABEL
        , CONTACTS_INDIVIDUAL_LAST_UPDAT
        , DF_TITLES_SHORT_TITLE
        , DF_TITLES_FULL_TITLE 
        , ACCOUNTS_NOTES
    From V_PUBLIC_ACCOUNTS_VIEW ;
End $$
Delimiter ;

