create procedure dbo.%PROC% @sid varchar(30) = null as declare @action_id numeric, @id numeric, @user_id numeric, @state_id numeric, @new_state_id numeric, @type_id numeric begin tran select @action_id = %ACTION_ID% select @id = convert(numeric, @sid) .CHECK_USER .CHECK_UPDATE .ACTION_HISTORY /*-------Проводки ----------*/ .GET_PROPS .TEST_RATE2CUR2DATE(@in_date,@cur_id) -- проверка курса на дату declare @organisation_id numeric, @plan_money_id numeric, @plan_securs_id numeric, @out_method_id numeric, @investor_subc_str varchar(255), @investor_id numeric, @from_subc_str varchar(255), @to_subc_str varchar(255) declare @is_realiz int, @is_p2l_comis int, @is_com_in int, @is_allow_short4stocks int, @is_allow_short4money int, @asset4pereoc_type_id numeric ---получение параметров для проводок .BACK_GET_ORG_PARMS(@owner_id,@organisation_id,@plan_money_id,@plan_securs_id,@out_method_id,@is_realiz,@is_p2l_comis,@is_com_in,@is_allow_short4stocks,@is_allow_short4money,@asset4pereoc_type_id) if @character_id=2 select @investor_id=@client_contract_id else select @investor_id=@organisation_id .ASSIGN(@investor_subc_str,'') --формирование строки аналитики .SUBC_STR_ADD(@investor_subc_str,'investors',@investor_id) .SUBC_STR_ADD(@investor_subc_str,'portfolio',@portfolio_id) .SUBC_STR_ADD(@investor_subc_str,'investor2portfolio',@portfolio_sub_id) .ASSIGN(@from_subc_str,@investor_subc_str) .SUBC_STR_ADD(@from_subc_str,'BANK_ACCOUNT',@from_partner_acc_id) .SUBC_STR_ADD(@from_subc_str,'ASSET_PLACES',@from_object_id) .ASSIGN(@to_subc_str,@investor_subc_str) .SUBC_STR_ADD(@to_subc_str,'BANK_ACCOUNT',@to_partner_acc_id) .SUBC_STR_ADD(@to_subc_str,'ASSET_PLACES',@to_object_id) --проводки .BACK_OPERS_BEGIN_MOVE(@owner_id,0,@from_direction_id,@from_object_id,@to_direction_id,@to_object_id,@client_contract_id,@investor_subc_str,@portfolio_sub_id) ---@from_direction .BACK_MONEY_MOVE(@sum_cur_dealing,@in_date,@cur_price_date,@cur_dealing_id,@from_subc_str,@to_subc_str,@doc_sum,@doc_sum) .ID_VAR(@res_char_id) ---.ID_VAR(@client_contract_id) if @organisation_id != @investor_id select @client_contract_id = @investor_id #ifdef ALD_BANK_SECS ---проводки по Центробанку IF (.TEST_SINT_ACCOUNTING(@organisation_id)) or (.TEST_CLIENT_ACCOUNTING(@client_contract_id)) BEGIN .INV_CHARACTER_CALC(@investor_id,@res_char_id) .EXEC_PROC((ap_move_own_money_aliases @id),'Перевод ДС внутри инвестора: формирование алиасов') END #endif if @instruction_on2off=1 and @character_id=2 begin -------------- Создаем поручение на перевод автоматически-------- .TYPE_INIT('INSTRUCTION_DS_INOUT',5) .TYPE_ASSIGN(type_poruch_id,3,5) .BACK_GEN_NO(@in_no5_1,1,@in_date) .TYPE_ASSIGN(in_no,@in_no5_1,5) .TYPE_ASSIGN(in_date,@in_date,5) .TYPE_ASSIGN(depo_doc_type,1,5) .TYPE_ASSIGN(client_id,@client_id,5) .TYPE_ASSIGN(bank_account_id,@from_partner_acc_id,5) .TYPE_ASSIGN(asset_place_id,@from_object_id,5) .TYPE_ASSIGN(bank_account2move_id,@to_partner_acc_id,5) .TYPE_ASSIGN(asset_place_2move_id,@to_object_id,5) .TYPE_ASSIGN(price_cur_id,@cur_id,5) .TYPE_ASSIGN(doc_sum_lim,@doc_sum,5) .TYPE_ASSIGN(owner_id,@owner_id,5) .TYPE_ASSIGN(exec_end_date,@in_date,5) .TYPE_ASSIGN(client_contract_id,@client_contract_id,5) .TYPE_ASSIGN(portfolio_id,@portfolio_id,5) .TYPE_ASSIGN(investor2portfolio_id,@portfolio_sub_id,5) .TYPE_INSERT('INSTRUCTION_DS_INOUT','COMPLIT',5) update t_paydocs set foundation_id=@id5_1 where id=@id update tb_directions set in_time = dateadd(minute, rand()*390, '09:30:00') where id=@id5_1 end else if @instruction_on2off=0 and @character_id =2 begin declare @doc_sum_lim money select @doc_sum_lim=doc_sum_lim from tb_directions where id=@foundation_id if @doc_sum_lim=(select sum(doc_sum) from t_paydocs where foundation_id=@foundation_id and .ITEMS_EXISTS_BY_TYPE_STATE(t_paydocs.id,'MONEY_MOVE_COMMISSION_2','OP_FULL')) begin .ITEM_MOVE_STATE(@foundation_id,'COMPLIT') end end #ifdef ALD_UKPIF ------------ ПИФ ----------------- if .TEST_PIF_CLIENT(@client_contract_id) begin if @schet_on_off = 1 execute ap_pif_pay_exec_move_from_57 @sid, ---Изменено добавлено _from_57 ----- востановленно @action_history_id, @client_contract_id, @from_direction_id, @from_object_id, @to_direction_id, @to_object_id, @doc_sum, @in_date, @cur_id, @from_partner_acc_id, @to_partner_acc_id if isnull(@schet_on_off,0) = 0 execute ap_pif_pay_exec_move @sid, @action_history_id, @client_contract_id, @from_direction_id, @from_object_id, @to_direction_id, @to_object_id, @doc_sum, @in_date, @cur_id, @from_partner_acc_id, @to_partner_acc_id if @@error != 0 begin if @@trancount<>0 rollback tran return end end #endif --kashuba_av Изменение статуса выполняется после создания проводок. .UPDATE_STATE #ifdef ALD_BANK_SECS ------------ БАНК ----------------- IF .TEST_SINT_ACCOUNTING(@organisation_id) BEGIN .ID_VAR(@account_type_id) --- Определяем тип учета select @account_type_id = (select sint_account_type_id from tb_broker_change where id = @organisation_id) if @account_type_id is null select @account_type_id = 1 -- По умолчанию - банковский /* .GENERATE_TYPED_OPERATIONS(@owner_id,1,@id,@type_id,@action_id,0,@character_id,'Фактический платеж',@action_history_id,null,'Перевод ДС внутри инвестора')*/ .GENERATE_OPERATIONS(@owner_id,@account_type_id,@id,@type_id,@action_id,@action_history_id,0,@res_char_id,'Фактический платеж: перевод ДС внутри инвестора.') -- .ITEM_ALIASES_CLEAR(@id) END #endif commit tran