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, @peredat_id numeric(18,0) begin tran select @action_id = %ACTION_ID% select @id = convert(numeric, @sid) .CHECK_USER .CHECK_UPDATE if @id=.SD_COMMON_PART4PAYS .EXIT_MESSAGE('Действие невозможно для системного документа') .UPDATE_STATE .ACTION_HISTORY .GET_PROPS --------------------------- -- отмена исх.платежей --------------------------- if isnull((.GET_CONST('EXEC_PAYMENTS_WITH_CLAIMS')),'0') = '1' begin declare @pmt_sid varchar(30) declare pmts cursor for select convert(varchar(30),p.id) from t_paydocs p, tp_extract2claim ec where p.pif_pay_id = ec.claim_id and ec.extract_id = @id and .ITEM_STATE_CODE(ec.claim_id) = 'CRT' and .ITEM_STATE_CODE(p.id) = 'PERF' and .ITEM_TYPE_CODE(p.id) = 'SD_PAYBANK_OUT' for read only open pmts fetch pmts into @pmt_sid while .CURSOR_STATE = 0 begin .EXEC_ACTION(@pmt_sid,'SD_PAYBANK_OUT','SIG_RET',Y) fetch pmts into @pmt_sid end close pmts .DEALLOCATE pmts end if exists(select 1 from tp_pif_queries, tp_extract2claim where tp_pif_queries.id = tp_extract2claim.claim_id and tp_extract2claim.extract_id=@id and upper(.ITEM_STATE_CODE(tp_pif_queries.id)) in ('CRT','CRT_NEXT','CRT_RET') and upper(.ITEM_TYPE_CODE(tp_pif_queries.id)) = 'PIF_PAY_BUY') .EXIT_MESSAGE('Для данного документа существуют заявки на погашение с уже исполненной оплатой') update t_items set state_id=.STATE_ID_FROM_CODE((.TYPE_ID('PIF_PAYS2REPORT')),'CRT') from tp_extract2claim where t_items.id=tp_extract2claim.id and tp_extract2claim.extract_id=@id update t_items set state_id=.STATE_ID_FROM_CODE((.TYPE_ID('PIF_PAY_BUY')),'PROV') from tp_pif_queries, tp_extract2claim where t_items.id=tp_pif_queries.id and upper(.ITEM_TYPE_CODE(tp_pif_queries.id)) = 'PIF_PAY_BUY' and tp_pif_queries.id = tp_extract2claim.claim_id and tp_extract2claim.extract_id=@id update t_items set state_id=.STATE_ID_FROM_CODE((.TYPE_ID('PIF_PAY_ALLOCATE')),'PROV') from tp_pif_queries, tp_extract2claim where t_items.id=tp_pif_queries.id and upper(.ITEM_TYPE_CODE(tp_pif_queries.id)) = 'PIF_PAY_ALLOCATE' and tp_pif_queries.id = tp_extract2claim.claim_id and tp_extract2claim.extract_id=@id .OPERS_ROLL if rtrim(ltrim(.GET_CONST('CLIENT_CODE'))) = 'WEBINVEST' begin -------- Передача реестра ----------- declare tmp_pered_cur cursor for select tp_pif_queries.id from tp_pif_queries where tp_pif_queries.reestr_report_id = @id and .ITEMS_EXISTS_BY_TYPE(tp_pif_queries.id,'TP_PIF_PAYS_MOVES') open tmp_pered_cur fetch tmp_pered_cur into @peredat_id while .CURSOR_STATE = 0 begin .EXEC_ACTION(@peredat_id,'TP_PIF_PAYS_MOVES','ACTION6',1) fetch tmp_pered_cur into @peredat_id end close tmp_pered_cur .DEALLOCATE tmp_pered_cur end commit tran