Delimiter //
/**
 * Author:  armen
 * Created: 3 déc. 2019
 */

Drop Procedure if Exists BUSINESS_ATTACHED_MEMBERS_UPDATE//
Create Procedure BUSINESS_ATTACHED_MEMBERS_UPDATE(
    In rulesRef Varchar(40)
    , In idEntities Int Unsigned
)
Begin
    Set @lamu_ref = rulesRef ;
    Set @lamu_idEntities = idEntities ;
    -- debug
--     Set @lamu_ref = CASH_LOADER_ACCOUNTS_has_MEMBERS_GET_REF(1);
    -- debug
--     Set @lamu_idEntities = 1 ;
    -- select @lamu_ref , @lamu_idEntities
    Set @lamu_accAcredRefTpe = (
                            Select ert.ID_ENTITIES_REF_TYPES From
                                ENTITIES_REF_TYPES ert
                            Where ert.ENTITIES_REF_TYPES_CODE = 'ACCRED_ACCOUNTS'
                        )
                    ;

    -- select @lamu_ref, @lamu_idEntities, @lamu_accAcredRefTpe

    bamu_main: Begin
        call BUSINESS_ATTACHED_MEMBERS_COMPUTE_PREPARED(@lamu_accAcredRefTpe);
        call BUSINESS_ATTACHED_MEMBERS_DELETE_PREPARED(@lamu_ref, @lamu_idEntities); 
        call BUSINESS_ATTACHED_MEMBERS_INSERT_ACC_PROVIDED();
        call BUSINESS_ATTACHED_MEMBERS_INSERT_ACC_NOT_PROVIDED(@lamu_accAcredRefTpe);
    End;
End //
Delimiter ;



