# Date: 07/04/06 # Version: 105 $DOC(PIF_PAY_REPS_GROUP) name=Отчеты регистратора class=5 product=ALD_PIF name_formula=null remark_formula=null $STATE(CRT) name=Создан class=0 $ENDSTATE $PROP(OUT_DATE) name=Внешняя дата корреспондента field_name=out_date table_name=td_depo_docs field_type=datetime field_length=8 field_scale=3 field_prec=23 page=1 order=1 init_class=null init_formula=null unique_index=null numerator=null import_type=null import_table=null import_field=null import_where=null ref_table=null ref_key=null ref_display=null ref_alias=null ref_where=null $ENDPROP $PROP(IN_DATE) name=Дата документа field_name=in_date table_name=td_depo_docs field_type=datetime field_length=8 field_scale=3 field_prec=23 page=1 order=2 init_class=1 init_formula=.OPERDAY unique_index=1 numerator=null import_type=null import_table=null import_field=null import_where=null ref_table=null ref_key=null ref_display=null ref_alias=null ref_where=null $ENDPROP $PROP(WHO_GET) name=Кто принял field_name=who_get table_name=td_depo_docs field_type=varchar field_length=100 field_scale=null field_prec=100 page=1 order=3 init_class=0 init_formula=null unique_index=null numerator=null import_type=null import_table=null import_field=null import_where=null ref_table=null ref_key=null ref_display=null ref_alias=null ref_where=null $ENDPROP $PROP(WHO_PUT) name=Кто отправил field_name=who_put table_name=td_depo_docs field_type=varchar field_length=100 field_scale=null field_prec=100 page=1 order=4 init_class=0 init_formula=null unique_index=null numerator=null import_type=null import_table=null import_field=null import_where=null ref_table=null ref_key=null ref_display=null ref_alias=null ref_where=null $ENDPROP $PROP(OUT_NO) name=Внешний номер field_name=out_no table_name=td_depo_docs field_type=varchar field_length=50 field_scale=null field_prec=50 page=1 order=5 init_class=null init_formula=null unique_index=null numerator=null import_type=null import_table=null import_field=null import_where=null ref_table=null ref_key=null ref_display=null ref_alias=null ref_where=null $ENDPROP $PROP(IN_NO) name=Номер документа field_name=in_no table_name=td_depo_docs field_type=varchar field_length=50 field_scale=null field_prec=50 page=1 order=6 init_class=0 init_formula=.GET_CONST('DEPODOC_NO_PREFIX')+ .FILL(%N%,'0',6) unique_index=1 numerator=null import_type=null import_table=null import_field=null import_where=null ref_table=null ref_key=null ref_display=null ref_alias=null ref_where=null $ENDPROP $PROP(CORRESPONDENT_ID) name=Корреспондент field_name=correspondent_id table_name=td_depo_docs field_type=numeric field_length=9 field_scale=0 field_prec=18 page=1 order=7 init_class=1 init_formula=(select td_pay_fond.spec_reg_id from td_pay_fond where id=@owner_id) unique_index=null numerator=null import_type=null import_table=null import_field=null import_where=null ref_table=null ref_key=null ref_display=null ref_alias=null ref_where=null $ENDPROP $PROP(PAYER_ID) name=Плательщик field_name=payer_id table_name=td_depo_docs field_type=numeric field_length=9 field_scale=0 field_prec=18 page=1 order=8 init_class=0 init_formula=null unique_index=null numerator=null import_type=null import_table=null import_field=null import_where=null ref_table=null ref_key=null ref_display=null ref_alias=null ref_where=null $ENDPROP $PROP(PAY_SUM) name=Сумма field_name=pay_sum table_name=td_depo_docs field_type=money field_length=8 field_scale=4 field_prec=19 page=1 order=9 init_class=0 init_formula=null unique_index=null numerator=null import_type=null import_table=null import_field=null import_where=null ref_table=null ref_key=null ref_display=null ref_alias=null ref_where=null $ENDPROP $PROP(INITIATOR_ID) name=Инициатор field_name=initiator_id table_name=td_depo_docs field_type=numeric field_length=9 field_scale=0 field_prec=18 page=1 order=10 init_class=0 init_formula=null unique_index=null numerator=null import_type=null import_table=null import_field=null import_where=null ref_table=null ref_key=null ref_display=null ref_alias=null ref_where=null $ENDPROP $PROP(DOCUMENT_FORM_ID) name=Форма документа field_name=document_form_id table_name=td_depo_docs field_type=numeric field_length=9 field_scale=0 field_prec=18 page=1 order=11 init_class=1 init_formula=1 unique_index=null numerator=null import_type=null import_table=null import_field= import_where=null ref_table=null ref_key=null ref_display=null ref_alias=null ref_where=null $ENDPROP $PROP(DEPO_DOC_TYPE) name=Входящий исходящий или внутр field_name=depo_doc_type table_name=td_depo_docs field_type=int field_length=4 field_scale=0 field_prec=10 page=1 order=12 init_class=1 init_formula=1 unique_index=null numerator=null import_type=null import_table=null import_field=null import_where=null ref_table=null ref_key=null ref_display=null ref_alias=null ref_where=null $ENDPROP $PROP(FOLDER_ID) name=Депозитарная папка field_name=folder_id table_name=td_depo_docs field_type=numeric field_length=9 field_scale=0 field_prec=18 page=1 order=13 init_class=2 init_formula=.DEPO_FOLDER_DEFAULT unique_index=null numerator=null import_type=null import_table=null import_field=null import_where=null ref_table=null ref_key=null ref_display=null ref_alias=null ref_where=null $ENDPROP $PROP(SUM_CUR_ID) name=Валюта суммы field_name=sum_cur_id table_name=td_depo_docs field_type=numeric field_length=9 field_scale=0 field_prec=18 page=1 order=14 init_class=1 init_formula=.CUR("RUR") unique_index=null numerator=null import_type=null import_table=null import_field=null import_where=null ref_table=null ref_key=null ref_display=null ref_alias=null ref_where=null $ENDPROP $PROP(DOC_COMMENT) name=Коментарии field_name=doc_comment table_name=td_depo_docs field_type=varchar field_length=255 field_scale=null field_prec=255 page=1 order=15 init_class=null init_formula=null unique_index=null numerator=null import_type=null import_table=null import_field=null import_where=null ref_table=null ref_key=null ref_display=null ref_alias=null ref_where=null $ENDPROP $PROP(OWNER_ID) name=Фонд field_name=owner_id table_name=td_depo_docs field_type=numeric field_length=9 field_scale=0 field_prec=18 page=1 order=16 init_class=1 init_formula=.ORGANIZATION_PIF unique_index=null numerator=null import_type=null import_table=null import_field=null import_where=null ref_table=null ref_key=null ref_display=null ref_alias=null ref_where=null $ENDPROP $PROP(REG_DATE) name=Дата проведения в реестре field_name=reg_date table_name=ts_reg_report field_type=datetime field_length=8 field_scale=3 field_prec=23 page=1 order=17 init_class=0 init_formula=null unique_index=null numerator=null import_type=null import_table=null import_field=null import_where=null ref_table=null ref_key=null ref_display=null ref_alias=null ref_where=null $ENDPROP $PROP(PAY_PRICE) name=Цена пая field_name=pay_price table_name=ts_reg_report field_type=decimal field_length=9 field_scale=8 field_prec=18 page=1 order=18 init_class=0 init_formula=null unique_index=null numerator=null import_type=null import_table=null import_field=null import_where=null ref_table=null ref_key=null ref_display=null ref_alias=null ref_where=null $ENDPROP $PROP(REP_NO) name=Номер отчета field_name=rep_no table_name=ts_reg_report field_type=varchar field_length=50 field_scale=null field_prec=50 page=1 order=19 init_class=0 init_formula=null unique_index=null numerator=null import_type=null import_table=null import_field=null import_where=null ref_table=null ref_key=null ref_display=null ref_alias=null ref_where=null $ENDPROP $PROP(PAY_DATE) name=Дата ценообразования field_name=pay_date table_name=ts_reg_report field_type=datetime field_length=8 field_scale=3 field_prec=23 page=1 order=20 init_class=0 init_formula=null unique_index=null numerator=null import_type=null import_table=null import_field=null import_where=null ref_table=null ref_key=null ref_display=null ref_alias=null ref_where=null $ENDPROP $RELATION(REL3) class=0 type=PARTNERS form=null prop=CORRESPONDENT_ID idname=null order=1 $ENDRELATION $RELATION(REL4) class=0 type=PARTNERS form=null prop=PAYER_ID idname=null order=2 $ENDRELATION $RELATION(REL5) class=0 type=PARTNERS form=null prop=INITIATOR_ID idname=null order=3 $ENDRELATION $RELATION(REL6) class=0 type=PIF_FUND form=null prop=OWNER_ID idname=null order=4 $ENDRELATION $RELATION(REL1) class=5 type=PIF_PAY_REPORT form=D_PIF_PAY_REP_EDIT prop=null idname=null order=null $ENDRELATION $RELATION(REL2) class=5 type=PIF_PAY_CANCEL form=FORM1 prop=null idname=null order=null $ENDRELATION $FORM(D_REESTR_IMP) name=Список для импорта заявок к отчету регистратора class=5 filter=null target_state= uo=uo_reestr_import dw=d_reestr_ircol_txt_imp procedure=null patterns=null user_define=0 isvisible=1 istab=0 posx=0 posy=0 width=0 height=0 proc_text=null $ENDFORM $FORM(D_REESTR_IMP_DB) name=Список для импорта заявок к отчету регистратора(DB) class=5 filter=null target_state= uo=uo_csv_import dw=d_reestr_txt_imp_db procedure=null patterns=null user_define=0 isvisible=1 istab=0 posx=0 posy=0 width=0 height=0 proc_text=null $ENDFORM $FORM(ED_PIF_PAY_REP_LIST) name=Список отчетов к импорту class=4 filter=null target_state= uo=uo_list dw=d_pif_pay_rep_group_list procedure=ap_10000000000089132 patterns=GENERIC_MOVE user_define=0 isvisible=0 istab=0 posx=0 posy=0 width=0 height=0 proc_text=$TEXT(11405186) create procedure dbo.%PROC% @sid varchar(30) = null .ARGLIST_FILTER as declare @action_id numeric, @user_id numeric, @state_id numeric, @type_id numeric begin set nocount on select @action_id = %ACTION_ID% .CHECK_USER .CHECK_VIEW .ARGCONVERT_FILTER .VIEW_LIST and td_depo_docs.owner_id=.ORGANIZATION and upper((select t_states.state_code from t_states where t_items.state_id = t_states.id))='ED_CLAIM' end $ENDTEXT(11405186) $ACTION2RELATION(REL6.PARTNER_CODE) relation=REL6 where=null prop=PARTNER_CODE order=35 alias=partner_code $ENDACTION2RELATION $ACTION2RELATION(REL5.PARTNER_CODE) relation=REL5 where=null prop=PARTNER_CODE order=19 alias=initiator_code $ENDACTION2RELATION $ACTION2RELATION(REL5.PARTNER_SHORT_NAME) relation=REL5 where=null prop=PARTNER_SHORT_NAME order=10 alias=initiator_short_name $ENDACTION2RELATION $ACTION2RELATION(REL3.PARTNER_CODE) relation=REL3 where=null prop=PARTNER_CODE order=19 alias=corr_code $ENDACTION2RELATION $ACTION2RELATION(REL3.PARTNER_SHORT_NAME) relation=REL3 where=null prop=PARTNER_SHORT_NAME order=10 alias=corr_short_name $ENDACTION2RELATION $ACTION2RELATION(REL4.PARTNER_CODE) relation=REL4 where=null prop=PARTNER_CODE order=19 alias=payer_code $ENDACTION2RELATION $ACTION2RELATION(REL4.PARTNER_SHORT_NAME) relation=REL4 where=null prop=PARTNER_SHORT_NAME order=10 alias=payer_short_name $ENDACTION2RELATION $ENDFORM $FORM(FORM2) name=Фильтр class=6 filter=null target_state= uo=uo_filter dw=d_pif_pay_rep_filter procedure=ap_10000000000089137 patterns=null user_define=1 isvisible=0 istab=0 posx=0 posy=0 width=1458 height=684 proc_text=$TEXT(11405186) create procedure dbo.%PROC% as begin declare @owner_id numeric declare @owner_name varchar(255) select @owner_id=.ORGANIZATION_PIF select @owner_name=(select partner_short_name from t_partners where id=@owner_id) select convert(datetime, null) as in_date_db, convert(datetime, null) as in_date_de, convert(varchar(50), null) as in_no, convert(varchar(30), @owner_id) as owner_id_s, convert(datetime, null) as reg_date_db, convert(datetime, null) as reg_date_de, convert(varchar(50), null) as rep_no, @owner_name as owner_name end $ENDTEXT(11405186) $FILTER(OWNER_ID) type=1 label=фонд prop=OWNER_ID arg_code=null arg_type=null arg_length=null arg_prec=null arg_scale=null $ENDFILTER $FILTER(REP_NO) type=1 label=Номер отчета prop=REP_NO arg_code=null arg_type=null arg_length=null arg_prec=null arg_scale=null $ENDFILTER $FILTER(REG_DATE) type=2 label=Дата проведения в реестре prop=REG_DATE arg_code=null arg_type=null arg_length=null arg_prec=null arg_scale=null $ENDFILTER $FILTER(IN_DATE) type=2 label=IN_DATE prop=IN_DATE arg_code=null arg_type=null arg_length=null arg_prec=null arg_scale=null $ENDFILTER $FILTER(IN_NO) type=1 label=IN_NO prop=IN_NO arg_code=null arg_type=null arg_length=null arg_prec=null arg_scale=null $ENDFILTER $ENDFORM $FORM(PIF_PAY_REPS_LIST) name=Список для текущего фонда class=4 filter=FORM2 target_state= uo=uo_list dw=d_pif_pay_rep_group_list procedure=ap_10000000000089142 patterns=GENERIC_VIEW_LIST user_define=1 isvisible=0 istab=0 posx=0 posy=0 width=3575 height=1012 proc_text=$TEXT(11405186) create procedure dbo.%PROC% @sid varchar(30) = null .ARGLIST_FILTER as declare @action_id numeric, @user_id numeric, @state_id numeric, @type_id numeric begin set nocount on select @action_id = %ACTION_ID% .CHECK_USER .CHECK_VIEW .ARGCONVERT_FILTER .VIEW_LIST --and td_depo_docs.owner_id=.ORGANIZATION end $ENDTEXT(11405186) $ACTION2RELATION(REL5.PARTNER_CODE) relation=REL5 where=null prop=PARTNER_CODE order=20 alias=initiator_code $ENDACTION2RELATION $ACTION2RELATION(REL5.PARTNER_SHORT_NAME) relation=REL5 where=null prop=PARTNER_SHORT_NAME order=21 alias=initiator_short_name $ENDACTION2RELATION $ACTION2RELATION(REL3.PARTNER_CODE) relation=REL3 where=null prop=PARTNER_CODE order=20 alias=corr_code $ENDACTION2RELATION $ACTION2RELATION(REL3.PARTNER_SHORT_NAME) relation=REL3 where=null prop=PARTNER_SHORT_NAME order=21 alias=corr_short_name $ENDACTION2RELATION $ACTION2RELATION(REL4.PARTNER_CODE) relation=REL4 where=null prop=PARTNER_CODE order=20 alias=payer_code $ENDACTION2RELATION $ACTION2RELATION(REL4.PARTNER_SHORT_NAME) relation=REL4 where=null prop=PARTNER_SHORT_NAME order=21 alias=payer_short_name $ENDACTION2RELATION $ACTION2RELATION(REL6.PARTNER_CODE) relation=REL6 where=null prop=PARTNER_CODE order=35 alias=partner_code $ENDACTION2RELATION $ENDFORM $FORM(SBRF_REESTR_IMPORT_LIST) name=Список для импорта полученных и принятых заявок (СБРФ) class=5 filter=null target_state= uo=uo_sber_queries_reestr_import dw=d_pif_pay_opers_sbrf_import procedure=null patterns=null user_define=0 isvisible=1 istab=0 posx=0 posy=0 width=0 height=0 proc_text=null $ENDFORM $ACTION(ACTION_IMPORT) name=Импорт class=1 form=D_REESTR_IMP target_state=null procedure=ap_10000000000089147 patterns=GENERIC_INSERT_O user_define=0 isvisible=0 istab=0 posx=0 posy=0 width=0 height=0 proc_text=$TEXT(11405186) create procedure dbo.%PROC% @q_type varchar(255), -- тип заявки, @payer varchar(255), -- пайщик @acc_no varchar(255), -- № счета @q_date varchar(255), -- дата заявки @q_no varchar(255), -- номер заявки @p_date varchar(255), -- дата плат @p_no varchar(255), -- № плат @q_sum varchar(255), -- сумма @qty varchar(255), -- кол-во паев @agent varchar(255), -- агент @agent_sum varchar(255), -- сумма комиссии @report_id_s varchar(30) as declare @action_id numeric, @id numeric, @user_id numeric, @state_id numeric, @type_id numeric, @item_name varchar(100), @new_state_id numeric begin select @action_id = %ACTION_ID% .ID_VAR(@report_id) .ID_VAR(@q_type_id) .INT_VAR(@is_cancel) declare @q_date_d datetime declare @p_date_d datetime declare @q_sum_m money declare @qty_m .PIF_PAY_TYPE declare @agent_sum_m money select @report_id=convert(numeric,@report_id_s) if @report_id is null .EXIT_MESSAGE('Не указан отчет регистратора') if upper(.ITEM_TYPE_CODE(@report_id))='PIF_PAY_REPORT' select @is_cancel=0 else select @is_cancel=1 select @q_type=.STR_FOR_IF(@q_type) if @q_type='1' select @q_type_id=.TYPE_ID_FROM_CODE_FUNC('PIF_PAY_ALLOCATE') if @q_type='2' select @q_type_id=.TYPE_ID_FROM_CODE_FUNC('PIF_PAY_BUY') if @q_type_id is null .EXIT_MESSAGE('Не указан тип заявки') if @q_sum='' select @q_sum=null if @qty='' select @qty=null if @agent_sum='' select @agent_sum=null select @q_sum_m=convert(money,@q_sum) select @qty_m=convert(.PIF_PAY_TYPE,@qty) if @is_cancel=0 and (@q_sum_m is null or @qty_m is null) .EXIT_MESSAGE('Не указана сумма или кол-во паев') select @agent_sum_m=convert(money,@agent_sum) if @q_date <> '' select @q_date_d=convert(datetime,(substring(@q_date,9,2)+'/'+substring(@q_date,6,2)+'/'+substring(@q_date,1,4)),103) if @p_date <> '' select @p_date_d=convert(datetime,(substring(@p_date,9,2)+'/'+substring(@p_date,6,2)+'/'+substring(@p_date,1,4)),103) if @q_date_d is null or @q_no is null .EXIT_MESSAGE('Не указана дата или номер заявки') if @q_type='1' and (@p_date_d is null or @p_no is null) and @is_cancel=0 .EXIT_MESSAGE('Не указана дата или номер платежа для заявки на выдачу') if exists(select 1 from tp_pay2rep_imp where q_no=@q_no and q_date=@q_date_d and q_type_id=@q_type_id and ((@q_type='1' and p_no=@p_no and p_date=@p_date_d and @is_cancel=0) or @q_type='2' or @is_cancel=1)) .EXIT_MESSAGE('Заявка уже была импортирована') begin tran .TYPE_INIT('PIF_PAY2REP_IMP') .TYPE_ASSIGN(extract_id,@report_id) .TYPE_ASSIGN(agent,@agent) .TYPE_ASSIGN(payer,@payer) .TYPE_ASSIGN(acc_no,@acc_no) .TYPE_ASSIGN(q_type_id,@q_type_id) .TYPE_ASSIGN(q_date,@q_date_d) .TYPE_ASSIGN(q_no,@q_no) .TYPE_ASSIGN(p_date,@p_date_d) .TYPE_ASSIGN(p_no,@p_no) .TYPE_ASSIGN(q_sum,@q_sum_m) .TYPE_ASSIGN(q_qty,@qty_m) .TYPE_ASSIGN(agent_sum,@agent_sum_m) .TYPE_INSERT('PIF_PAY2REP_IMP','WAIT') if upper(.ITEM_STATE_CODE(@report_id))='ED' .ITEM_MOVE_STATE(@report_id,'WAIT_CHECK') commit tran select sid = convert(varchar, @id) end $ENDTEXT(11405186) $ENDACTION $ACTION(ACTION_INSERT) name=Импорт (DB) class=1 form=D_REESTR_IMP_DB target_state=null procedure=ap_30000000000027225 patterns=null user_define=1 isvisible=0 istab=0 posx=0 posy=0 width=0 height=0 proc_text=$TEXT(11405186) create procedure dbo.%PROC% @code varchar(255), @r_no varchar(255), @q_no varchar(255), @q_date varchar(255), @qty varchar(255), @pay_date_s varchar(255), @sk_proc varchar(255), @agent_sum varchar(255), @pay_price varchar(255), @q_sum varchar(255), @round varchar(255), @acc_no varchar(255), @agent varchar(255), @agent_up varchar(255), @payer varchar(255), @pay_price_op varchar(255), @as_of varchar(255), @a_fond varchar(255), @a_acc_no varchar(255), @a_payer varchar(255), @q_type varchar(255), @status varchar(255), @op_date varchar(255), @reason varchar(255), @p_no varchar(255), @p_date varchar(255), @b_sum varchar(255), @bank varchar(255), @b_rec_no varchar(255), @b_date varchar(255)--, --@report_id_s varchar(30) as declare @action_id numeric, @id numeric, @user_id numeric, @state_id numeric, @type_id numeric, @item_name varchar(100), @new_state_id numeric begin select @action_id = %ACTION_ID% .ID_VAR(@report_id) .ID_VAR(@q_type_id) .INT_VAR(@is_cancel) declare @q_date_d datetime declare @p_date_d datetime declare @q_sum_m money declare @qty_m .PIF_PAY_TYPE declare @agent_sum_m money declare @reg_date datetime declare @pay_date datetime declare @owner_id numeric(18,0) declare @owner_imp_id numeric(18,0) declare @op_date_d datetime declare @pay_date_d datetime declare @sk_proc_m money declare @pay_price_m money declare @round_m money declare @pay_price_op_m money declare @as_of_m money declare @indoc_type_id numeric, @document_form_id numeric, @indoc_comment varchar(255), @corr_name varchar(255), @corr_id numeric, @indoc_id numeric, @in_time datetime, @indoc_id_s varchar(30), @days int, @out_date datetime, @indate datetime, @out_no varchar(50), @indocs_id numeric select @in_time=.OPERDAY select @indate=.OPERDAY declare @fund_id numeric .NRC_CUT_FIELD(@code) .NRC_CUT_FIELD(@r_no) .NRC_CUT_FIELD(@q_no) .NRC_CUT_FIELD(@qty) .NRC_CUT_FIELD(@sk_proc) .NRC_CUT_FIELD(@agent_sum) .NRC_CUT_FIELD(@pay_price) .NRC_CUT_FIELD(@q_sum) .NRC_CUT_FIELD(@round) .NRC_CUT_FIELD(@acc_no) .NRC_CUT_FIELD(@agent) .NRC_CUT_FIELD(@agent_up) .NRC_CUT_FIELD(@payer) .NRC_CUT_FIELD(@pay_price_op) .NRC_CUT_FIELD(@as_of) .NRC_CUT_FIELD(@a_fond) .NRC_CUT_FIELD(@a_acc_no) .NRC_CUT_FIELD(@a_payer) .NRC_CUT_FIELD(@status) .NRC_CUT_FIELD(@op_date) .NRC_CUT_FIELD(@reason) .NRC_CUT_FIELD(@p_no) .NRC_CUT_FIELD(@b_sum) .NRC_CUT_FIELD(@bank) .NRC_CUT_FIELD(@b_rec_no) .NRC_CUT_FIELD(@q_date) .NRC_CUT_FIELD(@pay_date_s) .NRC_CUT_FIELD(@q_type) .NRC_CUT_FIELD(@p_date) .NRC_CUT_FIELD(@b_date) .ID_VAR(@folder_id) select @folder_id = .DEPO_FOLDER_DEFAULT select @q_sum = replace(@q_sum,',','.') select @b_sum = replace(@b_sum,',','.') select @qty = replace(@qty,',','.') select @sk_proc= replace(@sk_proc,',','.') select @pay_price= replace(@pay_price,',','.') select @round = replace(@round,',','.') select @pay_price_op = replace(@pay_price_op,',','.') select @as_of= replace(@as_of,',','.') select @agent_sum = replace(@agent_sum,',','.') if @q_type not in ('4') begin select @op_date_d = convert(datetime,@op_date) select @pay_date_d = convert(datetime,@pay_date_s) select @owner_imp_id = td_depo_docs.owner_id from td_depo_docs, t_item2class, t_classvalues, t_classes where td_depo_docs.owner_id = t_item2class.item_id and t_classvalues.id=t_item2class.value_id and t_classvalues.code='FUND_IMPORT_CODE' and t_classes.id=t_classvalues.class_id and t_classes.code='FUND_IMPORT_CODE' and t_item2class.code = @code if @status = '1' select @status = '0' if @status = '2' select @status = '1' --** Отчет регистратора if @status = 0 begin select @report_id = ts_reg_report.id from ts_reg_report, td_depo_docs where ts_reg_report.reg_date = @op_date_d and ts_reg_report.pay_date = @pay_date_d and td_depo_docs.owner_id = @owner_imp_id and td_depo_docs.id = ts_reg_report.id and .ITEMS_EXISTS_BY_TYPE_STATE(ts_reg_report.id,'PIF_PAY_REPORT','WAIT_CHECK') and .ITEMS_EXISTS_BY_TYPE(ts_reg_report.id,'PIF_PAY_REPORT') if @report_id is null ----- вставка отчета ----- begin .TYPE_INIT('PIF_PAY_REPORT',1) .TYPE_ASSIGN(owner_id,@owner_imp_id,1) .TYPE_ASSIGN(reg_date,@op_date_d,1) .TYPE_ASSIGN(in_date,@op_date_d,1) .TYPE_ASSIGN(folder_id,@folder_id,1) .TYPE_ASSIGN(pay_date,@pay_date_d,1) .TYPE_INSERT('PIF_PAY_REPORT','ED_CLAIM',1) select @id = @id1_1 select @report_id = @id1_1 .DEPO_GEN_NO(@in_no1_1,1) .TYPE_UPDATE(@id1_1,'PIF_PAY_REPORT',1) ------- генерация вход. документа---------- -----проверка существования вх. документа с типом "отчета регистратора" ,с данным фондом и датой if not exists(select 1 from t_sd_indocs where in_date=.OPERDAY and owner_id=@owner_imp_id and indoc_type_id=(select id FROM t_sd_indoc_types WHERE indoc_name = 'Отчет регистратора') and .ITEMS_EXISTS_BY_TYPE(t_sd_indocs.id,'SD_INDOC')) begin select @document_form_id=1 select @corr_id=spec_reg_id from td_pay_fond where id=@owner_imp_id select @corr_name=partner_name from t_partners where id = @corr_id select @indoc_comment='Фонды УК "ДВС Инвестмент"' select @indoc_type_id=id FROM t_sd_indoc_types WHERE indoc_name = 'Отчет регистратора' --время регистрации if not exists(select 1 from t_sd_indocs where in_date=.OPERDAY and .ITEMS_EXISTS_BY_TYPE(t_sd_indocs.id,'SD_INDOC')) select @in_time=dateadd(Hour,11,@in_time) else begin --select @in_time=dateadd(Hour,11,@in_time) select @in_time=dateadd(mi,1,max(t.in_time)) from t_sd_indocs t where in_date=.OPERDAY and .ITEMS_EXISTS_BY_TYPE(t.id,'SD_INDOC') end exec ap_calc_end_period @date_beg = @indate, @days_beg = -1, @date_end = @out_date out, @days =@days select @out_no =convert(varchar(10), @out_date,3) select @out_no=replace(@out_no,'/','') .TYPE_INIT('SD_INDOC',4) .TYPE_ASSIGN(out_date,@out_date,4) .TYPE_ASSIGN(in_date,.OPERDAY,4) .TYPE_ASSIGN(out_no,@out_no,4) .TYPE_ASSIGN(in_time,@in_time,4) .TYPE_ASSIGN(indoc_type_id,@indoc_type_id,4) .TYPE_ASSIGN(corr_name,@corr_name,4) .TYPE_ASSIGN(document_form_id,@document_form_id,4) .TYPE_ASSIGN(folder_id,.DEPO_FOLDER_DEFAULT,4) .TYPE_ASSIGN(owner_id,@owner_imp_id,4) .TYPE_ASSIGN(comment,@indoc_comment,4) .TYPE_ASSIGN(send_date,.OPERDAY,4) .TYPE_INSERT('SD_INDOC','ED',4) select @indoc_id=.TYPE_FIELD(id,4) select @indoc_id_s=convert(varchar(30),@indoc_id) exec ap_sd_indoc_fix @indoc_id_s if @@error<>0 begin if @@trancount>0 rollback tran return end .TYPE_INIT('SD_INDOC2DOC',5) .TYPE_ASSIGN(indoc_id,@id4_1,5) .TYPE_ASSIGN(doc_id,@id1_1,5) .TYPE_INSERT('SD_INDOC2DOC','CRT',5) --курсор declare curs1 cursor for select id from td_pay_fond where ctrl_comp_id=(select ctrl_comp_id from td_pay_fond where td_pay_fond.id=@owner_imp_id) and .ITEMS_EXISTS_BY_TYPE(td_pay_fond.id,'PIF_FUND') and not exists(select 1 from t_sd_indocs where t_sd_indocs.in_date=.OPERDAY and t_sd_indocs.owner_id=td_pay_fond.id and t_sd_indocs.indoc_type_id=(select id FROM t_sd_indoc_types WHERE indoc_name = 'Отчет регистратора') and .ITEMS_EXISTS_BY_TYPE(t_sd_indocs.id,'SD_INDOC')) open curs1 fetch curs1 into @fund_id while .CURSOR_STATE=0 begin select @corr_id = null, @corr_name = null select @document_form_id=1 select @corr_id=spec_reg_id from td_pay_fond where id=@fund_id select @corr_name=partner_name from t_partners where id =@corr_id select @indoc_comment='Фонды УК "ДВС Инвестмент"' select @indoc_type_id=id FROM t_sd_indoc_types WHERE indoc_name = 'Отчет регистратора' --время регистрации if not exists(select 1 from t_sd_indocs where in_date=.OPERDAY and .ITEMS_EXISTS_BY_TYPE(t_sd_indocs.id,'SD_INDOC')) select @in_time=dateadd(Hour,11,@in_time) else begin --select @in_time=dateadd(Hour,11,@in_time) select @in_time=dateadd(mi,1,max(t.in_time)) from t_sd_indocs t where in_date=.OPERDAY and .ITEMS_EXISTS_BY_TYPE(t.id,'SD_INDOC') end exec ap_calc_end_period @date_beg = @indate, @days_beg = -1, @date_end = @out_date out, @days =@days select @out_no =convert(varchar(10), @out_date,3) select @out_no=replace(@out_no,'/','') .TYPE_INIT('SD_INDOC',10) .TYPE_ASSIGN(out_date,@out_date,10) .TYPE_ASSIGN(in_date,.OPERDAY,10) .TYPE_ASSIGN(out_no,@out_no,10) .TYPE_ASSIGN(in_time,@in_time,10) .TYPE_ASSIGN(indoc_type_id,@indoc_type_id,10) .TYPE_ASSIGN(corr_name,@corr_name,10) .TYPE_ASSIGN(document_form_id,@document_form_id,10) .TYPE_ASSIGN(folder_id,.DEPO_FOLDER_DEFAULT,10) .TYPE_ASSIGN(owner_id,@fund_id,10) .TYPE_ASSIGN(comment,@indoc_comment,10) .TYPE_ASSIGN(send_date,.OPERDAY,10) .TYPE_INSERT('SD_INDOC','ED',10) select @indoc_id=.TYPE_FIELD(id,10) select @indoc_id_s=convert(varchar(30),@indoc_id) select @corr_id = null, @corr_name = null --test exec ap_sd_indoc_fix @indoc_id_s if @@error<>0 begin if @@trancount>0 rollback tran return end fetch curs1 into @fund_id end close curs1 deallocate curs1 end else begin --прикрепляем к существующему вход. документу select @indocs_id=id from t_sd_indocs where in_date=.OPERDAY and owner_id=@owner_imp_id and indoc_type_id=(select id FROM t_sd_indoc_types WHERE indoc_name = 'Отчет регистратора') and .ITEMS_EXISTS_BY_TYPE(t_sd_indocs.id,'SD_INDOC') .TYPE_INIT('SD_INDOC2DOC',6) .TYPE_ASSIGN(indoc_id,@indocs_id,6) .TYPE_ASSIGN(doc_id,@id1_1,6) .TYPE_INSERT('SD_INDOC2DOC','CRT',6) end -------конец генерации вход. документа---------- end end --** if @status = 1 begin select @report_id = ts_reg_report.id from ts_reg_report, td_depo_docs where ts_reg_report.reg_date = @op_date_d and ts_reg_report.pay_date = @pay_date_d and td_depo_docs.owner_id = @owner_imp_id and td_depo_docs.id = ts_reg_report.id and .ITEMS_EXISTS_BY_TYPE_STATE(ts_reg_report.id,'PIF_PAY_CANCEL','WAIT_CHECK') and .ITEMS_EXISTS_BY_TYPE(ts_reg_report.id,'PIF_PAY_CANCEL') if @report_id is null ----- вставка отчета ----- begin .TYPE_INIT('PIF_PAY_CANCEL',2) .TYPE_ASSIGN(owner_id,@owner_imp_id,2) .TYPE_ASSIGN(reg_date,@op_date_d,2) .TYPE_ASSIGN(in_date,@op_date_d,2) .TYPE_ASSIGN(folder_id,@folder_id,2) .TYPE_ASSIGN(pay_date,@pay_date_d,2) .TYPE_INSERT('PIF_PAY_CANCEL','ED_CLAIM',2) select @id = @id2_1 select @report_id = @id2_1 .DEPO_GEN_NO(@in_no2_1,2) .TYPE_UPDATE(@id2_1,'PIF_PAY_CANCEL',2) ------- генерация вход. документа---------- -----проверка существования вх. документа с типом "отчета регистратора" ,с данным фондом и датой if not exists(select 1 from t_sd_indocs where in_date=.OPERDAY and owner_id=@owner_imp_id and indoc_type_id=(select id FROM t_sd_indoc_types WHERE indoc_name = 'Отчет регистратора') and .ITEMS_EXISTS_BY_TYPE(t_sd_indocs.id,'SD_INDOC')) begin select @document_form_id=1 select @corr_id=spec_reg_id from td_pay_fond where id=@owner_imp_id select @corr_name=partner_name from t_partners where id = @corr_id select @indoc_comment='Фонды УК "ДВС Инвестмент"' select @indoc_type_id=id FROM t_sd_indoc_types WHERE indoc_name = 'Отчет регистратора' --время регистрации if not exists(select 1 from t_sd_indocs where in_date=.OPERDAY and .ITEMS_EXISTS_BY_TYPE(t_sd_indocs.id,'SD_INDOC')) select @in_time=dateadd(Hour,11,@in_time) else begin --select @in_time=dateadd(Hour,11,@in_time) select @in_time=dateadd(mi,1,max(t.in_time)) from t_sd_indocs t where in_date=.OPERDAY and .ITEMS_EXISTS_BY_TYPE(t.id,'SD_INDOC') end exec ap_calc_end_period @date_beg = @indate, @days_beg = -1, @date_end = @out_date out, @days =@days select @out_no =convert(varchar(10), @out_date,3) select @out_no=replace(@out_no,'/','') .TYPE_INIT('SD_INDOC',7) .TYPE_ASSIGN(out_date,@out_date,7) .TYPE_ASSIGN(in_date,.OPERDAY,7) .TYPE_ASSIGN(out_no,@out_no,7) .TYPE_ASSIGN(in_time,@in_time,7) .TYPE_ASSIGN(indoc_type_id,@indoc_type_id,7) .TYPE_ASSIGN(corr_name,@corr_name,7) .TYPE_ASSIGN(document_form_id,@document_form_id,7) .TYPE_ASSIGN(folder_id,.DEPO_FOLDER_DEFAULT,7) .TYPE_ASSIGN(owner_id,@owner_imp_id,7) .TYPE_ASSIGN(comment,@indoc_comment,7) .TYPE_ASSIGN(send_date,.OPERDAY,7) .TYPE_INSERT('SD_INDOC','ED',7) select @indoc_id=.TYPE_FIELD(id,7) select @indoc_id_s=convert(varchar(30),@indoc_id) exec ap_sd_indoc_fix @indoc_id_s if @@error<>0 begin if @@trancount>0 rollback tran return end .TYPE_INIT('SD_INDOC2DOC',8) .TYPE_ASSIGN(indoc_id,@id7_1,8) .TYPE_ASSIGN(doc_id,@id2_1,8) .TYPE_INSERT('SD_INDOC2DOC','CRT',8) declare curs1 cursor for select id from td_pay_fond where ctrl_comp_id=(select ctrl_comp_id from td_pay_fond where td_pay_fond.id=@owner_imp_id) and .ITEMS_EXISTS_BY_TYPE(td_pay_fond.id,'PIF_FUND') and not exists(select 1 from t_sd_indocs where t_sd_indocs.in_date=.OPERDAY and t_sd_indocs.owner_id=td_pay_fond.id and t_sd_indocs.indoc_type_id=(select id FROM t_sd_indoc_types WHERE indoc_name = 'Отчет регистратора') and .ITEMS_EXISTS_BY_TYPE(t_sd_indocs.id,'SD_INDOC')) open curs1 fetch curs1 into @fund_id while .CURSOR_STATE=0 begin select @corr_id = null, @corr_name = null select @document_form_id=1 select @corr_id=spec_reg_id from td_pay_fond where id=@fund_id select @corr_name=partner_name from t_partners where id =@corr_id select @indoc_comment='Фонды УК "ДВС Инвестмент"' select @indoc_type_id=id FROM t_sd_indoc_types WHERE indoc_name = 'Отчет регистратора' --время регистрации if not exists(select 1 from t_sd_indocs where in_date=.OPERDAY and .ITEMS_EXISTS_BY_TYPE(t_sd_indocs.id,'SD_INDOC')) select @in_time=dateadd(Hour,11,@in_time) else begin --select @in_time=dateadd(Hour,11,@in_time) select @in_time=dateadd(mi,1,max(t.in_time)) from t_sd_indocs t where in_date=.OPERDAY and .ITEMS_EXISTS_BY_TYPE(t.id,'SD_INDOC') end exec ap_calc_end_period @date_beg = @indate, @days_beg = -1, @date_end = @out_date out, @days =@days select @out_no =convert(varchar(10), @out_date,3) select @out_no=replace(@out_no,'/','') .TYPE_INIT('SD_INDOC',11) .TYPE_ASSIGN(out_date,@out_date,11) .TYPE_ASSIGN(in_date,.OPERDAY,11) .TYPE_ASSIGN(out_no,@out_no,11) .TYPE_ASSIGN(in_time,@in_time,11) .TYPE_ASSIGN(indoc_type_id,@indoc_type_id,11) .TYPE_ASSIGN(corr_name,@corr_name,11) .TYPE_ASSIGN(document_form_id,@document_form_id,11) .TYPE_ASSIGN(folder_id,.DEPO_FOLDER_DEFAULT,11) .TYPE_ASSIGN(owner_id,@fund_id,11) .TYPE_ASSIGN(comment,@indoc_comment,11) .TYPE_ASSIGN(send_date,.OPERDAY,11) .TYPE_INSERT('SD_INDOC','ED',11) select @indoc_id=.TYPE_FIELD(id,11) select @indoc_id_s=convert(varchar(30),@indoc_id) select @corr_id = null, @corr_name = null --test exec ap_sd_indoc_fix @indoc_id_s if @@error<>0 begin if @@trancount>0 rollback tran return end fetch curs1 into @fund_id end close curs1 deallocate curs1 end else begin --прикрепляем к существующему вход. документу select @indocs_id=id from t_sd_indocs where in_date=.OPERDAY and owner_id=@owner_imp_id and indoc_type_id=(select id FROM t_sd_indoc_types WHERE indoc_name = 'Отчет регистратора') and .ITEMS_EXISTS_BY_TYPE(t_sd_indocs.id,'SD_INDOC') .TYPE_INIT('SD_INDOC2DOC',9) .TYPE_ASSIGN(indoc_id,@indocs_id,9) .TYPE_ASSIGN(doc_id,@id2_1,9) .TYPE_INSERT('SD_INDOC2DOC','CRT',9) end -------конец генерации вход. документа---------- end end select @q_type=.STR_FOR_IF(@q_type) if @q_type='1' select @q_type_id=.TYPE_ID_FROM_CODE_FUNC('PIF_PAY_ALLOCATE') if @q_type='2' select @q_type_id=.TYPE_ID_FROM_CODE_FUNC('PIF_PAY_ALLOCATE') if @q_type='3' select @q_type_id=.TYPE_ID_FROM_CODE_FUNC('PIF_PAY_BUY') if @q_type='4' select @q_type_id=.TYPE_ID_FROM_CODE_FUNC('TP_PIF_PAYS_MOVES') if @q_type_id is null .EXIT_MESSAGE('Не указан тип заявки') if @q_sum='' select @q_sum=null if @qty='' select @qty=null if @agent_sum='' select @agent_sum=null if @sk_proc='' select @sk_proc=null if @pay_price='' select @pay_price=null if @round='' select @round=null if @pay_price_op='' select @pay_price_op=null if @as_of='' select @as_of=null select @q_sum_m=convert(money,@q_sum) --select @q_sum_m=convert(money,@b_sum) select @qty_m=convert(.PIF_PAY_TYPE,@qty) select @sk_proc_m=convert(money,@sk_proc) select @pay_price_m=convert(money,@pay_price) select @round_m=convert(money,@round) select @pay_price_op_m=convert(money,@pay_price_op) select @as_of_m=convert(money,@as_of) if @status=0 and (@q_sum_m is null or @qty_m is null) .EXIT_MESSAGE('Не указана сумма или кол-во паев') select @agent_sum_m=convert(money,@agent_sum) --.EXIT_MESSAGE_PARM('1',@q_date) if @q_date <> '' select @q_date_d=convert(datetime,@q_date) if @p_date <> '' select @p_date_d=convert(datetime,@p_date) if @q_date_d is null or @q_no is null .EXIT_MESSAGE('Не указана дата или номер заявки') if @q_type='1' and (@p_date_d is null or @p_no is null) and @status=0 .EXIT_MESSAGE('Не указана дата или номер платежа для заявки на выдачу') if @q_type='2' and (@p_date_d is null or @p_no is null) and @status=0 .EXIT_MESSAGE('Не указана дата или номер платежа для заявки на выдачу') if exists(select 1 from tp_pay2rep_imp where q_no=@q_no and q_date=@q_date_d and q_type_id=@q_type_id and ((@q_type='1' and p_no=@p_no and p_date=@p_date_d and @status=0) or (@q_type='1' and p_no=@p_no and p_date=@p_date_d and @status=0) /* or @q_type='3' or @q_type='4'*/ or @status=1)) .EXIT_MESSAGE('Заявка уже была импортирована') begin tran .TYPE_INIT('PIF_PAY2REP_IMP',3) .TYPE_ASSIGN(extract_id,@report_id,3) .TYPE_ASSIGN(agent,@agent,3) .TYPE_ASSIGN(payer,@payer,3) .TYPE_ASSIGN(acc_no,@acc_no,3) .TYPE_ASSIGN(q_type_id,@q_type_id,3) .TYPE_ASSIGN(q_date,@q_date_d,3) .TYPE_ASSIGN(q_no,@q_no,3) .TYPE_ASSIGN(p_date,@p_date_d,3) .TYPE_ASSIGN(p_no,@p_no,3) .TYPE_ASSIGN(q_sum,@q_sum_m,3) .TYPE_ASSIGN(q_qty,@qty_m,3) .TYPE_ASSIGN(agent_sum,@agent_sum_m,3) .TYPE_ASSIGN(sk_proc,@sk_proc_m,3) .TYPE_ASSIGN(pay_price,@pay_price_m,3) .TYPE_ASSIGN(round,@round_m,3) .TYPE_ASSIGN(pay_price_op,@pay_price_op_m,3) .TYPE_ASSIGN(as_of,@as_of_m,3) .TYPE_ASSIGN(a_fond,@a_fond,3) .TYPE_ASSIGN(a_acc_no,@a_acc_no,3) .TYPE_ASSIGN(a_payer,@a_payer,3) .TYPE_ASSIGN(reason,@reason,3) .TYPE_INSERT('PIF_PAY2REP_IMP','WAIT',3) if upper(.ITEM_STATE_CODE(@report_id))='ED' .ITEM_MOVE_STATE(@report_id,'WAIT_CHECK') commit tran end select sid = convert(varchar, @id) end $ENDTEXT(11405186) $ENDACTION $ACTION(REESTR_CHECK) name=Квитовка новая class=9 form=null target_state=null procedure=ap_10000000000089148 patterns=null user_define=1 isvisible=1 istab=0 posx=0 posy=0 width=0 height=0 proc_text=$TEXT(11405187) create procedure dbo.%PROC% @sid varchar(30) = null as .ID_VAR(@id) .ID_VAR(@fund_id) .INT_VAR(@res) .ID_VAR(@alloc_id) .INT_VAR(@is_cancel) declare @cl_id numeric(18,0) select @id=convert(numeric,@sid) if not exists(select 1 from tp_pay2rep_imp where extract_id=@id) .EXIT_MESSAGE('Нет заявок для квитовки') if upper(.ITEM_TYPE_CODE(@id))='PIF_PAY_REPORT' select @is_cancel=0 else select @is_cancel=1 select @fund_id=owner_id from td_depo_docs where id=@id select @res=1 select @alloc_id=.TYPE_ID_FROM_CODE_FUNC('PIF_PAY_ALLOCATE') .TRANSACTION_SAVE create table #check( imp_id numeric null, q_type_id numeric null, claim_id numeric null, paymt_id numeric null, mess varchar(255) null, bad int null ) insert into #check(imp_id,q_type_id) select tp_pay2rep_imp.id, tp_pay2rep_imp.q_type_id from tp_pay2rep_imp where upper(.ITEM_STATE_CODE(tp_pay2rep_imp.id))!='FIX' and tp_pay2rep_imp.extract_id=@id if exists(select 1 from #check) begin begin tran -- заявки update #check set claim_id = tp_pif_queries.id from tp_pif_queries, tp_pay2rep_imp imp, t_items, td_depo_docs where #check.imp_id=imp.id and rtrim(ltrim(tp_pif_queries.agent_regs_no))=rtrim(ltrim(imp.q_no)) and tp_pif_queries.agent_regs_date=imp.q_date and tp_pif_queries.id=td_depo_docs.id and td_depo_docs.owner_id=@fund_id and tp_pif_queries.id=t_items.id and t_items.type_id=#check.q_type_id and exists(select 1 from t_states where t_states.id=t_items.state_id and t_states.class_id=0) update #check set mess='Не найдена заявка по дате и номеру', bad=1 where claim_id is null update #check set mess='Найденная заявка находится в статусе '+t_states.state_name, bad=1 from t_items, t_states where #check.bad is null and #check.claim_id=t_items.id and t_items.state_id=t_states.id and upper(t_states.state_code) not in ('ED','NOT_PAYMT','PROV') update #check set mess='В найденной заявке не указан агентский договор', bad=1 from tp_pif_queries where #check.bad is null and #check.claim_id=tp_pif_queries.id and tp_pif_queries.type_queries not in (3,4) and (tp_pif_queries.agent_id is null or tp_pif_queries.agent_dog_id is null) update #check set mess='В найденной заявке не указан пайщик', bad=1 from tp_pif_queries where #check.bad is null and #check.claim_id=tp_pif_queries.id and tp_pif_queries.pay_owner_id is null -- платежи declare cur cursor for select claim_id from #check, tp_pif_queries where #check.claim_id=tp_pif_queries.id and tp_pif_queries.type_queries not in (3,4) open cur fetch cur into @cl_id while(@@fetch_status = 0) begin update #check set paymt_id=t_paydocs.id from t_paydocs, tp_pay2rep_imp imp, td_depo_docs , tp_pif_queries , t_items , t_states , #check where #check.bad is null and #check.imp_id=imp.id and #check.q_type_id=@alloc_id and rtrim(ltrim(t_paydocs.doc_number))=rtrim(ltrim(imp.p_no)) and t_paydocs.doc_date=imp.p_date and t_paydocs.id=td_depo_docs.id and td_depo_docs.owner_id=@fund_id and t_paydocs.doc_sum = imp.q_sum and tp_pif_queries.id = @cl_id and .PURPOSE_CODE(t_paydocs.purpose_id) in (4011) and rtrim(ltrim(tp_pif_queries.agent_regs_no))=rtrim(ltrim(imp.q_no)) and tp_pif_queries.agent_regs_date=imp.q_date and t_items.state_id=t_states.id and t_items.id = t_paydocs.id and upper(t_states.state_code) in ('ED','WAIT_QUERY','PERF') and t_paydocs.from_partner_id = tp_pif_queries.pay_owner_id and (.ITEMS_EXISTS_BY_TYPE(t_paydocs.id,'SD_PAYBANK_IN') or .ITEMS_EXISTS_BY_TYPE(t_paydocs.id,'SD_PAYDOCS_CASH_IN')) and claim_id = #check.claim_id update #check set mess='Не найден платеж', bad=2 where #check.bad is null and #check.paymt_id is null and #check.q_type_id=@alloc_id and @is_cancel=0 and #check.claim_id = @cl_id fetch cur into @cl_id end close cur deallocate cur -- заявки к платежам update t_paydocs set pif_pay_id=#check.claim_id from #check where #check.bad is null and #check.q_type_id=@alloc_id and t_paydocs.id=#check.paymt_id and t_paydocs.pif_pay_id is null update #check set mess='В найденном платеже указана другая заявка', bad=2 from t_paydocs, tp_pif_queries where #check.bad is null and #check.q_type_id=@alloc_id and #check.claim_id=tp_pif_queries.id and #check.paymt_id=t_paydocs.id and t_paydocs.pif_pay_id is not null and tp_pif_queries.type_queries not in (3,4) and t_paydocs.pif_pay_id != tp_pif_queries.id -- проверка привязок -- выкуп и одноразовые на размещение update #check set mess='Найденная заявка уже находится в отчете: док-т № '+ isnull(td_depo_docs.in_no,''), bad=1 from tp_extract2claim, td_depo_docs, tp_pif_queries where #check.bad is null and #check.claim_id=tp_pif_queries.id and tp_pif_queries.id=tp_extract2claim.claim_id and tp_extract2claim.extract_id=td_depo_docs.id and (#check.q_type_id!=@alloc_id or (#check.q_type_id=@alloc_id and tp_pif_queries.pif_pay_type_id=1 and ((tp_extract2claim.extract_id!=@id and @is_cancel=0) or @is_cancel=1))) -- размещение с таким же платежем update #check set mess='Найденная заявка c платежем уже находится в отчете: док-т № '+ isnull(td_depo_docs.in_no,''), bad=1 from tp_extract2claim, td_depo_docs, tp_pif_queries, tp_paymt2pays where #check.bad is null and #check.q_type_id=@alloc_id and #check.claim_id=tp_pif_queries.id and tp_pif_queries.type_queries not in (3,4) and tp_pif_queries.id=tp_extract2claim.claim_id and tp_extract2claim.extract_id=td_depo_docs.id and tp_paymt2pays.pif_pay_id=tp_extract2claim.id and tp_paymt2pays.paymt_id=#check.paymt_id and (tp_pif_queries.pif_pay_type_id=2 or (tp_pif_queries.pif_pay_type_id=1 and tp_extract2claim.extract_id=@id)) -- проверка повторной квитовки (выкуп) update #check set mess='Найденная заявка уже сквитована в этом отчете', bad=1 where #check.bad is null and #check.q_type_id!=@alloc_id and #check.imp_id in (select min(ch.imp_id) from #check ch where ch.bad is null and ch.q_type_id!=@alloc_id group by ch.claim_id having count(*)>1) -- проверка повторной квитовки (размещение) update #check set mess='Найденная заявка уже сквитована в этом отчете', bad=1 where #check.bad is null and #check.q_type_id=@alloc_id and #check.imp_id in (select min(ch.imp_id) from #check ch where ch.bad is null and ch.q_type_id=@alloc_id group by ch.claim_id, ch.paymt_id having count(*)>1) -- обработка сквитованного .ID_VAR(@q_type_id) .ID_VAR(@claim_id) .ID_VAR(@paymt_id) .ID_VAR(@agent_id) .ID_VAR(@payer_id) .ID_VAR(@extract2claim_id) .ID_VAR(@claim_type_id) .ID_VAR(@agent_dog_id) .INT_VAR(@first) declare @imp_sum money, @imp_qty .PIF_PAY_TYPE, @imp_agent_sum money declare @claim_id_s varchar(30), @paymt_id_s varchar(30) declare claims cursor for select #check.q_type_id, #check.claim_id, #check.paymt_id, imp.q_sum, imp.q_qty, imp.agent_sum, tp_pif_queries.agent_id, tp_pif_queries.pay_owner_id, tp_pif_queries.agent_dog_id from #check, tp_pay2rep_imp imp, tp_pif_queries where #check.bad is null and #check.imp_id=imp.id and #check.claim_id=tp_pif_queries.id for read only open claims fetch claims into @q_type_id, @claim_id, @paymt_id, @imp_sum, @imp_qty, @imp_agent_sum, @agent_id, @payer_id, @agent_dog_id while (.CURSOR_STATE = 0) begin select @first=0 .PIF_ROUND_PAYS(@fund_id,@imp_qty,@imp_qty) if @q_type_id=@alloc_id select @claim_type_id=1 else select @claim_type_id=2 select @extract2claim_id=(select id from tp_extract2claim where extract_id=@id and claim_id=@claim_id) if @extract2claim_id is null begin -- привязка заявки if upper(.ITEM_STATE_CODE(@claim_id)) in ('ED','NOT_PAYMT') begin .ITEM_MOVE_STATE(@claim_id,'PROV') end .TYPE_INIT('PIF_PAYS2REPORT',2) .TYPE_ASSIGN(share_qty,@imp_qty,2) .TYPE_ASSIGN(agent_sum,@imp_agent_sum,2) .TYPE_ASSIGN(sum_for_transfer,@imp_sum,2) .TYPE_ASSIGN(claim_id,@claim_id,2) .TYPE_ASSIGN(extract_id,@id,2) .TYPE_ASSIGN(pay_agent_id,@agent_id,2) .TYPE_ASSIGN(pay_partner_id,@payer_id,2) .TYPE_ASSIGN(tax_percent,0,2) .TYPE_ASSIGN(is_new_tax,0,2) .TYPE_ASSIGN(is_manual_tax,0,2) .TYPE_ASSIGN(tax_sum,0,2) .TYPE_ASSIGN(alloc_sum,0,2) .TYPE_ASSIGN(get_paymt_type,2,2) .TYPE_ASSIGN(claim_type_id,@claim_type_id,2) .TYPE_ASSIGN(agent_dog_id,@agent_dog_id,2) .TYPE_INSERT('PIF_PAYS2REPORT','CRT',2) select @extract2claim_id=.TYPE_FIELD(id,2) select @first=1 end if @q_type_id=@alloc_id and (@is_cancel=0 or (@is_cancel=1 and @paymt_id is not null)) begin -- привязка платежа к привязке заявки if upper(.ITEM_STATE_CODE(@paymt_id)) in ('ED','WAIT_QUERY') begin select @paymt_id_s=convert(varchar(30),@paymt_id) if upper(.ITEM_TYPE_CODE(@paymt_id))='SD_PAYBANK_IN' begin if upper(.ITEM_STATE_CODE(@paymt_id))='ED' begin .EXEC_ACTION(@paymt_id_s,'SD_PAYBANK_IN','OPS_IN',Y) end if upper(.ITEM_STATE_CODE(@paymt_id))='WAIT_QUERY' begin .EXEC_ACTION(@paymt_id_s,'SD_PAYBANK_IN','OPS_FOR_QUERY',Y) end end if upper(.ITEM_TYPE_CODE(@paymt_id))='SD_PAYDOCS_CASH_IN' begin .EXEC_ACTION(@paymt_id_s,'SD_PAYDOCS_CASH_IN','OPS_CASH_IN',Y) end end .TYPE_INIT('PIF_PAYMT2PAYS',3) .TYPE_ASSIGN(pif_pay_id,@extract2claim_id,3) .TYPE_ASSIGN(paymt_id,@paymt_id,3) .TYPE_INSERT('PIF_PAYMT2PAYS','CRT',3) if @first=0 update tp_extract2claim set sum_for_transfer=sum_for_transfer+@imp_sum, share_qty=share_qty+@imp_qty, agent_sum=agent_sum+@imp_agent_sum where id=@extract2claim_id end if @is_cancel=0 begin select @claim_id_s=convert(varchar(30),@extract2claim_id) .EXEC_ACTION(@claim_id_s,'PIF_PAYS2REPORT','claim_calc_parts',Y) end fetch claims into @q_type_id, @claim_id, @paymt_id, @imp_sum, @imp_qty, @imp_agent_sum, @agent_id, @payer_id, @agent_dog_id end close claims .DEALLOCATE claims .ID_VAR(@imp_type_id) .ID_VAR(@fix_id) .ID_VAR(@not1_id) .ID_VAR(@not2_id) select @imp_type_id=.TYPE_ID_FROM_CODE_FUNC('PIF_PAY2REP_IMP') select @fix_id=.STATE_ID_FROM_CODE(@imp_type_id,'FIX') select @not1_id=.STATE_ID_FROM_CODE(@imp_type_id,'NOT_CLAIM') select @not2_id=.STATE_ID_FROM_CODE(@imp_type_id,'NOT_PAYMT') update t_items set state_id=@fix_id from tp_pay2rep_imp, #check where tp_pay2rep_imp.id=t_items.id and t_items.type_id=@imp_type_id and tp_pay2rep_imp.extract_id=@id and tp_pay2rep_imp.id=#check.imp_id and #check.bad is null update t_items set state_id=@not1_id from tp_pay2rep_imp, #check where tp_pay2rep_imp.id=t_items.id and t_items.type_id=@imp_type_id and tp_pay2rep_imp.extract_id=@id and tp_pay2rep_imp.id=#check.imp_id and #check.bad=1 update t_items set state_id=@not2_id from tp_pay2rep_imp, #check where tp_pay2rep_imp.id=t_items.id and t_items.type_id=@imp_type_id and tp_pay2rep_imp.extract_id=@id and tp_pay2rep_imp.id=#check.imp_id and #check.bad=2 update tp_pay2rep_imp set cause=#check.mess from #check where #check.imp_id=tp_pay2rep_imp.id if exists(select 1 from #check where bad is not null) select @res=0 commit tran end drop table #check .TRANSACTION_RESTORE begin tran if @res=1 begin .ITEM_MOVE_STATE(@id,'END_CHECK') end else begin .ITEM_MOVE_STATE(@id,'NOT_CHECK') end commit tran $ENDTEXT(11405187) $ENDACTION $ACTION(REESTR_CHECK_OLD) name=Квитовка class=9 form=null target_state=null procedure=ap_reestr_check patterns=null user_define=0 isvisible=1 istab=0 posx=0 posy=0 width=0 height=0 proc_text=$TEXT(11405187) create procedure dbo.%PROC% @sid varchar(30) = null as .ID_VAR(@id) .ID_VAR(@fund_id) .INT_VAR(@res) .ID_VAR(@alloc_id) .INT_VAR(@is_cancel) select @id=convert(numeric,@sid) if not exists(select 1 from tp_pay2rep_imp where extract_id=@id) .EXIT_MESSAGE('Нет заявок для квитовки') if upper(.ITEM_TYPE_CODE(@id))='PIF_PAY_REPORT' select @is_cancel=0 else select @is_cancel=1 select @fund_id=owner_id from td_depo_docs where id=@id select @res=1 select @alloc_id=.TYPE_ID_FROM_CODE_FUNC('PIF_PAY_ALLOCATE') .TRANSACTION_SAVE create table #check( imp_id numeric null, q_type_id numeric null, claim_id numeric null, paymt_id numeric null, mess varchar(255) null, bad int null ) insert into #check(imp_id,q_type_id) select tp_pay2rep_imp.id, tp_pay2rep_imp.q_type_id from tp_pay2rep_imp where upper(.ITEM_STATE_CODE(tp_pay2rep_imp.id))!='FIX' and tp_pay2rep_imp.extract_id=@id if exists(select 1 from #check) begin begin tran -- заявки update #check set claim_id = tp_pif_queries.id from tp_pif_queries, tp_pay2rep_imp imp, t_items, td_depo_docs where #check.imp_id=imp.id and rtrim(ltrim(tp_pif_queries.agent_regs_no))=rtrim(ltrim(imp.q_no)) and tp_pif_queries.agent_regs_date=imp.q_date and tp_pif_queries.id=td_depo_docs.id and td_depo_docs.owner_id=@fund_id and tp_pif_queries.id=t_items.id and t_items.type_id=#check.q_type_id and exists(select 1 from t_states where t_states.id=t_items.state_id and t_states.class_id=0) update #check set mess='Не найдена заявка по дате и номеру', bad=1 where claim_id is null update #check set mess='Найденная заявка находится в статусе '+t_states.state_name, bad=1 from t_items, t_states where #check.bad is null and #check.claim_id=t_items.id and t_items.state_id=t_states.id and upper(t_states.state_code) not in ('ED','NOT_PAYMT','PROV') update #check set mess='В найденной заявке не указан агентский договор', bad=1 from tp_pif_queries where #check.bad is null and #check.claim_id=tp_pif_queries.id and (tp_pif_queries.agent_id is null or tp_pif_queries.agent_dog_id is null) update #check set mess='В найденной заявке не указан пайщик', bad=1 from tp_pif_queries where #check.bad is null and #check.claim_id=tp_pif_queries.id and tp_pif_queries.pay_owner_id is null -- платежи update #check set paymt_id=t_paydocs.id from t_paydocs, tp_pay2rep_imp imp, td_depo_docs where #check.bad is null and #check.imp_id=imp.id and #check.q_type_id=@alloc_id and rtrim(ltrim(t_paydocs.doc_number))=rtrim(ltrim(imp.p_no)) and t_paydocs.doc_date=imp.p_date and t_paydocs.id=td_depo_docs.id and td_depo_docs.owner_id=@fund_id and (.ITEMS_EXISTS_BY_TYPE(t_paydocs.id,'SD_PAYBANK_IN') or .ITEMS_EXISTS_BY_TYPE(t_paydocs.id,'SD_PAYDOCS_CASH_IN')) update #check set mess='Не найден платеж по дате и номеру', bad=2 where #check.bad is null and #check.paymt_id is null and #check.q_type_id=@alloc_id and @is_cancel=0 update #check set mess='В найденном платеже указана другая сумма', bad=2 from t_paydocs, tp_pay2rep_imp imp where #check.bad is null and #check.q_type_id=@alloc_id and #check.paymt_id=t_paydocs.id and #check.imp_id=imp.id and t_paydocs.doc_sum != imp.q_sum update #check set mess='В найденном платеже и заявке разные отправители', bad=2 from t_paydocs, tp_pif_queries where #check.bad is null and #check.q_type_id=@alloc_id and #check.claim_id=tp_pif_queries.id and #check.paymt_id=t_paydocs.id and t_paydocs.from_partner_id != tp_pif_queries.pay_owner_id update #check set mess='В найденном платеже указано другое целевое назначение', bad=2 from t_paydocs where #check.bad is null and #check.q_type_id=@alloc_id and #check.paymt_id=t_paydocs.id and .PURPOSE_CODE(t_paydocs.purpose_id)!=4011 update #check set mess='Найденный платеж находится в статусе '+t_states.state_name, bad=2 from t_items, t_states where #check.bad is null and #check.q_type_id=@alloc_id and #check.paymt_id=t_items.id and t_items.state_id=t_states.id and upper(t_states.state_code) not in ('ED','WAIT_QUERY','PERF') -- заявки к платежам update t_paydocs set pif_pay_id=#check.claim_id from #check where #check.bad is null and #check.q_type_id=@alloc_id and t_paydocs.id=#check.paymt_id and t_paydocs.pif_pay_id is null update #check set mess='В найденном платеже указана другая заявка', bad=2 from t_paydocs, tp_pif_queries where #check.bad is null and #check.q_type_id=@alloc_id and #check.claim_id=tp_pif_queries.id and #check.paymt_id=t_paydocs.id and t_paydocs.pif_pay_id is not null and t_paydocs.pif_pay_id != tp_pif_queries.id -- проверка привязок -- выкуп и одноразовые на размещение update #check set mess='Найденная заявка уже находится в отчете: док-т № '+ isnull(td_depo_docs.in_no,''), bad=1 from tp_extract2claim, td_depo_docs, tp_pif_queries where #check.bad is null and #check.claim_id=tp_pif_queries.id and tp_pif_queries.id=tp_extract2claim.claim_id and tp_extract2claim.extract_id=td_depo_docs.id and (#check.q_type_id!=@alloc_id or (#check.q_type_id=@alloc_id and tp_pif_queries.pif_pay_type_id=1 and ((tp_extract2claim.extract_id!=@id and @is_cancel=0) or @is_cancel=1))) -- размещение с таким же платежем update #check set mess='Найденная заявка c платежем уже находится в отчете: док-т № '+ isnull(td_depo_docs.in_no,''), bad=1 from tp_extract2claim, td_depo_docs, tp_pif_queries, tp_paymt2pays where #check.bad is null and #check.q_type_id=@alloc_id and #check.claim_id=tp_pif_queries.id and tp_pif_queries.id=tp_extract2claim.claim_id and tp_extract2claim.extract_id=td_depo_docs.id and tp_paymt2pays.pif_pay_id=tp_extract2claim.id and tp_paymt2pays.paymt_id=#check.paymt_id and (tp_pif_queries.pif_pay_type_id=2 or (tp_pif_queries.pif_pay_type_id=1 and tp_extract2claim.extract_id=@id)) -- проверка повторной квитовки (выкуп) update #check set mess='Найденная заявка уже сквитована в этом отчете', bad=1 where #check.bad is null and #check.q_type_id!=@alloc_id and #check.imp_id in (select min(ch.imp_id) from #check ch where ch.bad is null and ch.q_type_id!=@alloc_id group by ch.claim_id having count(*)>1) -- проверка повторной квитовки (размещение) update #check set mess='Найденная заявка уже сквитована в этом отчете', bad=1 where #check.bad is null and #check.q_type_id=@alloc_id and #check.imp_id in (select min(ch.imp_id) from #check ch where ch.bad is null and ch.q_type_id=@alloc_id group by ch.claim_id, ch.paymt_id having count(*)>1) -- обработка сквитованного .ID_VAR(@q_type_id) .ID_VAR(@claim_id) .ID_VAR(@paymt_id) .ID_VAR(@agent_id) .ID_VAR(@payer_id) .ID_VAR(@extract2claim_id) .ID_VAR(@claim_type_id) .ID_VAR(@agent_dog_id) .INT_VAR(@first) declare @imp_sum money, @imp_qty .PIF_PAY_TYPE, @imp_agent_sum money declare @claim_id_s varchar(30), @paymt_id_s varchar(30) declare claims cursor for select #check.q_type_id, #check.claim_id, #check.paymt_id, imp.q_sum, imp.q_qty, imp.agent_sum, tp_pif_queries.agent_id, tp_pif_queries.pay_owner_id, tp_pif_queries.agent_dog_id from #check, tp_pay2rep_imp imp, tp_pif_queries where #check.bad is null and #check.imp_id=imp.id and #check.claim_id=tp_pif_queries.id for read only open claims fetch claims into @q_type_id, @claim_id, @paymt_id, @imp_sum, @imp_qty, @imp_agent_sum, @agent_id, @payer_id, @agent_dog_id while (.CURSOR_STATE = 0) begin select @first=0 .PIF_ROUND_PAYS(@fund_id,@imp_qty,@imp_qty) if @q_type_id=@alloc_id select @claim_type_id=1 else select @claim_type_id=2 select @extract2claim_id=(select id from tp_extract2claim where extract_id=@id and claim_id=@claim_id) if @extract2claim_id is null begin -- привязка заявки if upper(.ITEM_STATE_CODE(@claim_id)) in ('ED','NOT_PAYMT') begin .ITEM_MOVE_STATE(@claim_id,'PROV') end .TYPE_INIT('PIF_PAYS2REPORT',2) .TYPE_ASSIGN(share_qty,@imp_qty,2) .TYPE_ASSIGN(agent_sum,@imp_agent_sum,2) .TYPE_ASSIGN(sum_for_transfer,@imp_sum,2) .TYPE_ASSIGN(claim_id,@claim_id,2) .TYPE_ASSIGN(extract_id,@id,2) .TYPE_ASSIGN(pay_agent_id,@agent_id,2) .TYPE_ASSIGN(pay_partner_id,@payer_id,2) .TYPE_ASSIGN(tax_percent,0,2) .TYPE_ASSIGN(is_new_tax,0,2) .TYPE_ASSIGN(is_manual_tax,0,2) .TYPE_ASSIGN(tax_sum,0,2) .TYPE_ASSIGN(alloc_sum,0,2) .TYPE_ASSIGN(get_paymt_type,2,2) .TYPE_ASSIGN(claim_type_id,@claim_type_id,2) .TYPE_ASSIGN(agent_dog_id,@agent_dog_id,2) .TYPE_INSERT('PIF_PAYS2REPORT','CRT',2) select @extract2claim_id=.TYPE_FIELD(id,2) select @first=1 end if @q_type_id=@alloc_id and (@is_cancel=0 or (@is_cancel=1 and @paymt_id is not null)) begin -- привязка платежа к привязке заявки if upper(.ITEM_STATE_CODE(@paymt_id)) in ('ED','WAIT_QUERY') begin select @paymt_id_s=convert(varchar(30),@paymt_id) if upper(.ITEM_TYPE_CODE(@paymt_id))='SD_PAYBANK_IN' begin if upper(.ITEM_STATE_CODE(@paymt_id))='ED' begin .EXEC_ACTION(@paymt_id_s,'SD_PAYBANK_IN','OPS_IN',Y) end if upper(.ITEM_STATE_CODE(@paymt_id))='WAIT_QUERY' begin .EXEC_ACTION(@paymt_id_s,'SD_PAYBANK_IN','OPS_FOR_QUERY',Y) end end if upper(.ITEM_TYPE_CODE(@paymt_id))='SD_PAYDOCS_CASH_IN' begin .EXEC_ACTION(@paymt_id_s,'SD_PAYDOCS_CASH_IN','OPS_CASH_IN',Y) end end .TYPE_INIT('PIF_PAYMT2PAYS',3) .TYPE_ASSIGN(pif_pay_id,@extract2claim_id,3) .TYPE_ASSIGN(paymt_id,@paymt_id,3) .TYPE_INSERT('PIF_PAYMT2PAYS','CRT',3) if @first=0 update tp_extract2claim set sum_for_transfer=sum_for_transfer+@imp_sum, share_qty=share_qty+@imp_qty, agent_sum=agent_sum+@imp_agent_sum where id=@extract2claim_id end if @is_cancel=0 begin select @claim_id_s=convert(varchar(30),@extract2claim_id) .EXEC_ACTION(@claim_id_s,'PIF_PAYS2REPORT','claim_calc_parts',Y) end fetch claims into @q_type_id, @claim_id, @paymt_id, @imp_sum, @imp_qty, @imp_agent_sum, @agent_id, @payer_id, @agent_dog_id end close claims .DEALLOCATE claims .ID_VAR(@imp_type_id) .ID_VAR(@fix_id) .ID_VAR(@not1_id) .ID_VAR(@not2_id) select @imp_type_id=.TYPE_ID_FROM_CODE_FUNC('PIF_PAY2REP_IMP') select @fix_id=.STATE_ID_FROM_CODE(@imp_type_id,'FIX') select @not1_id=.STATE_ID_FROM_CODE(@imp_type_id,'NOT_CLAIM') select @not2_id=.STATE_ID_FROM_CODE(@imp_type_id,'NOT_PAYMT') update t_items set state_id=@fix_id from tp_pay2rep_imp, #check where tp_pay2rep_imp.id=t_items.id and t_items.type_id=@imp_type_id and tp_pay2rep_imp.extract_id=@id and tp_pay2rep_imp.id=#check.imp_id and #check.bad is null update t_items set state_id=@not1_id from tp_pay2rep_imp, #check where tp_pay2rep_imp.id=t_items.id and t_items.type_id=@imp_type_id and tp_pay2rep_imp.extract_id=@id and tp_pay2rep_imp.id=#check.imp_id and #check.bad=1 update t_items set state_id=@not2_id from tp_pay2rep_imp, #check where tp_pay2rep_imp.id=t_items.id and t_items.type_id=@imp_type_id and tp_pay2rep_imp.extract_id=@id and tp_pay2rep_imp.id=#check.imp_id and #check.bad=2 update tp_pay2rep_imp set cause=#check.mess from #check where #check.imp_id=tp_pay2rep_imp.id if exists(select 1 from #check where bad is not null) select @res=0 commit tran end drop table #check .TRANSACTION_RESTORE begin tran if @res=1 begin .ITEM_MOVE_STATE(@id,'END_CHECK') end else begin .ITEM_MOVE_STATE(@id,'NOT_CHECK') end commit tran $ENDTEXT(11405187) $ENDACTION $ACTION(SBRF_REESTR_IMPORT) name=Импорт полученных и принятых заявок (СБРФ) class=1 form=SBRF_REESTR_IMPORT_LIST target_state=null procedure=ap_30000000000012479 patterns=null user_define=0 isvisible=0 istab=0 posx=0 posy=0 width=0 height=0 proc_text=$TEXT(11405187) create procedure dbo.%PROC% @req varchar(255), -- № заявки, @reqdate varchar(255), -- дата заявки @reqtype varchar(255), -- тип заявки (операции), @reqstatus varchar(255), -- статус заявки, @operdate varchar(255), -- дата операции, @opertype varchar(255), -- 1-приход, -1-расход (для заявок на обмен паев) @dname varchar(255), -- пайщик (ФИО/Наименование) @dcclienttype varchar(255), -- тип лица @dpdoctype varchar(255), -- тип документа @dpdocseries varchar(255), -- док.-серия (физ.) @dpdocnumber varchar(255), -- док.-номер (физ.) @dpdocdep varchar(255), -- док. - кем выдан (физ.) @dpdocplace varchar(255), -- док. - где выдан (физ.) @dpdocdate varchar(255), -- док. - дата выдачи (физ.) @dudocnumber varchar(255), -- св-во - номер (юр.) @dudocdep varchar(255), -- св-во - кем выдано (юр.) @dudocdate varchar(255), -- св-во - дата выдачи (юр.) @dinn varchar(255), -- ИНН @dbankname varchar(255), -- наименование банка @dpersonalaccount varchar(255), -- № банковского счета (физ.) @daccount varchar(255), -- № банковского счета (юр.) @dbankcorr varchar(255), -- корр. счет @dbic varchar(255), -- БИК @dbankcity varchar(255), -- город банка @dbankinn varchar(255), -- ИНН банка @dpostindex varchar(255), -- почтовый индекс @dpostaddress varchar(255), -- почтовый адрес @dbaseindex varchar(255), -- индекс регистрации @dbaseaddress varchar(255), -- адрес регистрации @dphone varchar(255), -- телефон @dfax varchar(255), -- факс @demail varchar(255), -- email @dokpo varchar(255), -- ОКПО @dokonh varchar(255), -- ОКОНХ @dkpp varchar(255), -- КПП @daccname varchar(255), -- № счета в реестре @cname varchar(255), -- УК (наименование) @cinn varchar(255), -- ИНН @cbankname varchar(255), -- наименование банка @cpersonalaccount varchar(255), -- № банковского счета (физ.) ??????????????? @caccount varchar(255), -- № банковского счета (юр.) @cbankcorr varchar(255), -- корр. счет @cbic varchar(255), -- БИК @cbankcity varchar(255), -- город банка @cbankinn varchar(255), -- ИНН банка @cpostindex varchar(255), -- почтовый индекс @cpostaddress varchar(255), -- почтовый адрес @cbaseindex varchar(255), -- индекс регистрации @cbaseaddress varchar(255), -- адрес регистрации @cphone varchar(255), -- телефон @cfax varchar(255), -- факс @cemail varchar(255), -- email @cokpo varchar(255), -- ОКПО @cokonh varchar(255), -- ОКОНХ @ckpp varchar(255), -- КПП @cdoc varchar(255), -- документ @sharename varchar(255), -- фонд @agentname varchar(255), -- агент - пока =фонду @saldo decimal(18,8), -- кол-во паев @pnum varchar(255), -- № платежа @pdate varchar(255), -- дата платежа @ppremiumagent money, -- сумма комиссии (премия агенту) @ppayer varchar(255), -- плательщик @psumma money, -- сумма платежа @report_id_s varchar(30), -- отчет регистратора о принятых заявках @cancel_report_id_s varchar(30) -- отчет регистратора об отказах as declare @action_id numeric, @id numeric, @user_id numeric, @state_id numeric, @type_id numeric, @item_name varchar(100), @new_state_id numeric begin select @action_id = %ACTION_ID% --**********Проверка заполнения полей файла************************* if @reqtype is null .EXIT_MESSAGE('Не указан тип заявки') declare @req_date datetime select @req_date = convert(datetime, @reqdate) if @req_date is null .EXIT_MESSAGE('Не указана дата заявки') if @req is null .EXIT_MESSAGE('Не указан номер заявки') --**********КОНЕЦ - Проверка заполнения полей файла************************* --**********************Определение ФОНДа и договора с агентом************************* -- ФОНД declare @fund_id numeric, @fund_code varchar(50) --для классификатора PARTNER_IMPORT_CODE - PAYER_ACC_NO select @fund_id = max(tp.id) from t_partners tp where ltrim(rtrim(upper(tp.partner_name))) = ltrim(rtrim(upper(@sharename))) and .ITEMS_EXISTS_BY_TYPE(tp.id,'PIF_FUND') if @fund_id is null .EXIT_MESSAGE('Фонд не определен') select @fund_code=partner_code from t_partners where id=@fund_id --Агент - всегда одно лицо -- declare @agent_id numeric declare @agent_dog_id numeric /* -- АГЕНТ - константа?! select @agent_id = max(tp.id) from t_partners tp where ltrim(rtrim(upper(tp.partner_name))) = ltrim(rtrim(upper(@agentname))) and .ITEMS_EXISTS_BY_TYPE(tp.id,'PARTNERS_JUR') if @agent_id is null .EXIT_MESSAGE('Не найден АГЕНТ!!!') */ --Только 1 договор комиссии (и соотв-но, агент) для каждого фонда select @agent_dog_id = max(tb_contracts.id) from tb_contracts, td_depo_docs where --tb_contracts.client_id = @agent_id and tb_contracts.dog_type_id = 2 and tb_contracts.id = td_depo_docs.id and td_depo_docs.owner_id = @fund_id and .ITEMS_EXISTS_BY_TYPE(tb_contracts.id,'FUND_CONTRACTS') if @agent_dog_id is null .EXIT_MESSAGE('Для фонда не задан договор комиссии') select @agent_id = client_id from tb_contracts where id=@agent_dog_id if @agent_id is null .EXIT_MESSAGE('Не найден АГЕНТ!!!') declare @agent varchar(255) select @agent=partner_name from t_partners where id=@agent_id --**********************КОНЕЦ - Определение ФОНДа и договора с агентом************************* --********************Импорт заявок************************************ declare @folder_id numeric select @folder_id = .DEPO_FOLDER_DEFAULT declare @req_type int select @req_type= --Тип заявки case when charindex('ПРИОБРЕТЕН', upper(@reqtype))>0 then 1 when charindex('ВЫКУП', upper(@reqtype))>0 then 2 when charindex('ОБМЕН', upper(@reqtype))>0 and convert(int,ltrim(rtrim(@opertype)))=1 then 3 when charindex('ОБМЕН', upper(@reqtype))>0 and convert(int,ltrim(rtrim(@opertype)))=-1 then 4 end --*******************НОВЫЕ заявки************************************ if charindex('НОВ', upper(@reqstatus))>0 begin declare @is_jur int select @is_jur=null --**********************Импорт пайщика************************* declare @partner_id numeric, @doc_type_id numeric, @i1 int, @i2 int, @last_name varchar(255), @first_name varchar(255), @second_name varchar(255), @partner_code varchar(50) if charindex('ФИ', upper(@dcclienttype))>0 or charindex('ПБОЮЛ', upper(@dcclienttype))>0 --ФИЗ.ЛИЦО или ПБОЮЛ begin if isnull(replace(@dpdocnumber,' ',''),'')='' and isnull(replace(@dpdocseries,' ',''),'')='' .EXIT_MESSAGE('Не заданы паспортные данные физ.лица') select @is_jur=0 --Пробуем найти пайщика select @partner_id = t_partners.id from t_partners, t_partners_fis f where t_partners.id = f.id and (isnull(upper(replace(f.f_passport_serial,' ','')),'') + isnull(upper(replace(f.f_passport_no,' ','')),'')) = (isnull(upper(replace(@dpdocseries,' ','')),'') + isnull(upper(replace(@dpdocnumber,' ','')),'')) and .ITEMS_EXISTS_BY_TYPE(t_partners.id, 'partners_fis') end else if charindex('ЮР', upper(@dcclienttype))>0 begin select @is_jur=1 select @partner_id = t_partners.id from t_partners, t_partners_jur where t_partners.id = t_partners_jur.id and ltrim(upper(t_partners.partner_name)) = ltrim(upper(@dname)) and .ITEMS_EXISTS_BY_TYPE(t_partners.id, 'partners_jur') end else .EXIT_MESSAGE('Тип лица не содержит слов фи/юр/пбоюл') --**************СОЧЕТАНИЕ реквизиты пайщика - Лиц. счет*************** declare @count int if @partner_id is null --если не нашли по документу или наименованию begin --Сколько партнеров с таким ЛС и фондом select @count=count(t_partners.id) from t_partners, t_item2class i, t_classvalues v, t_classes c where t_partners.id=i.item_id and i.value_id=v.id and v.class_id=c.id and upper(c.code)='PARTNER_IMPORT_CODE' and upper(v.code)='PAYER_ACC_NO' and upper(i.code)=upper(@daccname) and upper(i.remark)=upper(@fund_code) if @count=1 --один и тот самый begin select @partner_id=t_partners.id from t_partners, t_item2class i, t_classvalues v, t_classes c where t_partners.id=i.item_id and i.value_id=v.id and v.class_id=c.id and upper(c.code)='PARTNER_IMPORT_CODE' and upper(v.code)='PAYER_ACC_NO' and upper(i.code)=upper(@daccname) and upper(i.remark)=upper(@fund_code) --update реквизитов пайщика------------------------------------------------------- /*if @is_jur=0... if @is_jur=1... .TYPE_INIT('PARTNERS_JUR',5) .TYPE_ASSIGN(partner_name,@dname,5) .TYPE_UPDATE(@partner_id,'PARTNERS_JUR',5)*/ ---------------------------------------------------------------------------------- end if @count>1 --несколько с одинаковыми ЛС!!! .EXIT_MESSAGE('Существует несколько лиц с одинаковым сочетанием ЛС-Фонд в классификаторе PAYER_ACC_NO!') --if isnull(@count,0)=0 --нет ни одного => @partner_id=null end --**************КОНЕЦ - СОЧЕТАНИЕ реквизиты пайщика - Лиц. счет*************** --Если не нашли if @partner_id is null begin if @is_jur=0 begin --**********Новый пайщик-физик или ПБОЮЛ******************* select @doc_type_id= case when @dpdoctype='Паспорт РФ' then (select id from t_simples where type_id=1004 and upper(simple_name) = ltrim(rtrim(upper('Паспорт РФ')))) when @dpdoctype='Воен бл' then (select id from t_simples where type_id=1004 and upper(simple_name) = ltrim(rtrim(upper('Военный билет')))) when @dpdoctype='Удостоверение личности' then (select id from t_simples where type_id=1004 and upper(simple_name) = ltrim(rtrim(upper('Удостоверение личности')))) when @dpdoctype='Национальный заграничный паспорт' then (select id from t_simples where type_id=1004 and upper(simple_name) = ltrim(rtrim(upper('Национальный заграничный паспорт')))) when @dpdoctype='Паспорт моряка' then (select id from t_simples where type_id=1004 and upper(simple_name) = ltrim(rtrim(upper('Паспорт моряка')))) when @dpdoctype='Вид на жительство' then (select id from t_simples where type_id=1004 and upper(simple_name) = ltrim(rtrim(upper('Вид на жительство')))) when @dpdoctype='Удостоверение беженца в РФ' then (select id from t_simples where type_id=1004 and upper(simple_name) = ltrim(rtrim(upper('Удостоверение беженца в РФ')))) end if @doc_type_id is null .EXIT_MESSAGE('Не найден тип документа у физического лица') --определяем фам., имя, отчество select @i1=charindex(' ',@dname,1) select @last_name=substring(@dname,1,@i1-1) select @i2=charindex(' ',@dname,@i1+1) select @first_name=substring(@dname,@i1+1,@i2-@i1-1) select @second_name=substring(@dname,@i2+1,.CHAR_LENGTH(@dname)-@i2) --Новый пайщик .TYPE_INIT('PARTNERS_FIS',3) .TYPE_ASSIGN(f_doctype_id,@doc_type_id,3) .TYPE_ASSIGN(f_passport_no,@dpdocnumber,3) .TYPE_ASSIGN(f_passport_serial,@dpdocseries,3) .TYPE_ASSIGN(f_passport_distributor,(@dpdocdep+' '+@dpdocplace),3) .TYPE_ASSIGN(f_passport_when,@dpdocdate,3) .TYPE_ASSIGN(f_first_name,@first_name,3) .TYPE_ASSIGN(f_middle_name,@second_name,3) .TYPE_ASSIGN(f_last_name,@last_name,3) .TYPE_ASSIGN(partner_name,@dname,3) .TYPE_ASSIGN(partner_short_name,(@last_name+' '+isnull(substring(@first_name,1,1)+'.','')+' '+isnull(substring(@second_name,1,1)+'.','')),3) select @partner_code='IMPORT'+'(' + @last_name+' '+isnull(@dpdocnumber, '')+')' .TYPE_ASSIGN(partner_code,@partner_code,3) .TYPE_ASSIGN(j_inn,@dinn,3) .TYPE_ASSIGN(tax_category_id,1,3) .TYPE_ASSIGN(postal_code,@dpostindex,3) .TYPE_ASSIGN(partner_post_address,@dpostaddress,3) .TYPE_ASSIGN(real_code,@dbaseindex,3) .TYPE_ASSIGN(partner_address,@dbaseaddress,3) .TYPE_ASSIGN(jur_code,@dbaseindex,3) .TYPE_ASSIGN(juraddress,@dbaseaddress,3) .TYPE_ASSIGN(partner_phone,(@dphone+' факс: '+@dfax),3) .TYPE_ASSIGN(partner_email,@demail,3) .TYPE_ASSIGN(okpo_code,@dokpo,3) .TYPE_ASSIGN(okonh_code,@dokonh,3) if charindex('ПБОЮЛ', upper(@dcclienttype))>0 begin .TYPE_ASSIGN(regist_sertificate_no,@dudocnumber,3) .TYPE_ASSIGN(regist_sertificate_date,@dudocdate,3) .TYPE_ASSIGN(regist_organisation,@dudocdep,3) end .TYPE_INSERT('PARTNERS_FIS','CRT',3) select @partner_id = @id3_1 --***************КОНЕЦ - Новый пайщик-физик или ПБОЮЛ************************ end if @is_jur=1 begin --***************Новый пайщик-юрик******************************************* .TYPE_INIT('PARTNERS_JUR',4) .TYPE_ASSIGN(partner_name,@dname,4) .TYPE_ASSIGN(partner_short_name,@dname,4) select @partner_code='IMPORT'+'(' + @dname+' '+isnull(@dinn, '')+')' .TYPE_ASSIGN(partner_code,@partner_code,4) .TYPE_ASSIGN(j_inn,@dinn,4) .TYPE_ASSIGN(tax_category_id,6,4) .TYPE_ASSIGN(postal_code,@dpostindex,4) .TYPE_ASSIGN(partner_post_address,@dpostaddress,4) .TYPE_ASSIGN(real_code,@dbaseindex,4) .TYPE_ASSIGN(partner_address,@dbaseaddress,4) .TYPE_ASSIGN(jur_code,@dbaseindex,4) .TYPE_ASSIGN(juraddress,@dbaseaddress,4) .TYPE_ASSIGN(partner_phone,(@dphone+' факс: '+@dfax),4) .TYPE_ASSIGN(partner_email,@demail,4) .TYPE_ASSIGN(okpo_code,@dokpo,4) .TYPE_ASSIGN(okonh_code,@dokonh,4) .TYPE_ASSIGN(cro,@dkpp,4) .TYPE_ASSIGN(regist_sertificate_no,@dudocnumber,4) .TYPE_ASSIGN(regist_sertificate_date,@dudocdate,4) .TYPE_ASSIGN(regist_organisation,@dudocdep,4) .TYPE_INSERT('PARTNERS_JUR','CRT',4) select @partner_id = @id4_1 --***************КОНЕЦ - Новый пайщик-юрик******************************************** end --лицевой счет пайщика в фонде - в классификатор .SET_CLASS_VALUES(@partner_id,'PARTNER_IMPORT_CODE','PAYER_ACC_NO',@daccname,100) --вставляем классификатор для пайщика --код фонда - в комментарий классификатора update t_item2class set remark=@fund_code from t_classvalues v, t_classes c where t_item2class.item_id=@partner_id and t_item2class.value_id=v.id and v.class_id=c.id and upper(c.code)='PARTNER_IMPORT_CODE' and upper(v.code)='PAYER_ACC_NO' and upper(t_item2class.code)=upper(@daccname) end --********************Импорт банковских реквизитов ****************** declare @partner_bank_acc_id numeric if .ITEM_TYPE_CODE(@partner_id)='PARTNERS_FIS' select @partner_bank_acc_id = t_bank_accounts.id from t_partners, t_bank_accounts where t_partners.id = @partner_id and ltrim(upper(t_bank_accounts.bank_account_no)) = ltrim(upper(@dpersonalaccount)) and .ITEMS_EXISTS_BY_TYPE(t_bank_accounts.id, 'BANK_ACCOUNTS') if .ITEM_TYPE_CODE(@partner_id)='PARTNERS_JUR' select @partner_bank_acc_id = t_bank_accounts.id from t_partners, t_bank_accounts where t_partners.id = @partner_id and ltrim(upper(t_bank_accounts.bank_account_no)) = ltrim(upper(@daccount)) and .ITEMS_EXISTS_BY_TYPE(t_bank_accounts.id, 'BANK_ACCOUNTS') if @partner_bank_acc_id is null begin .TYPE_INIT('BANK_ACCOUNTS',11) .TYPE_ASSIGN(partner_id,@partner_id,11) .TYPE_ASSIGN(corr_account,@dbankcorr,11) .TYPE_ASSIGN(bik,@dbic,11) .TYPE_ASSIGN(bank_name,@dbankname,11) .TYPE_ASSIGN(bank_city_name,@dbankcity,11) if .ITEM_TYPE_CODE(@partner_id)='PARTNERS_FIS' .TYPE_ASSIGN(bank_account_no,@dpersonalaccount,11) if .ITEM_TYPE_CODE(@partner_id)='PARTNERS_JUR' .TYPE_ASSIGN(bank_account_no,@daccount,11) .TYPE_INSERT('BANK_ACCOUNTS','CRT',11) end --******************** КОНЕЦ - Импорт банковских реквизитов ****************** --**********************КОНЕЦ - Импорт пайщика************************* --**********************НОВАЯ ЗАЯВКА*********************************** if @req_type in (1,3) begin -- Заявка на размещение (зачисление по обмену) паев - новая if exists(select 1 from tp_pif_queries, td_depo_docs where upper(tp_pif_queries.agent_regs_no) = upper(@req) and tp_pif_queries.agent_regs_date = @req_date and tp_pif_queries.id = td_depo_docs.id and tp_pif_queries.type_queries=@req_type and .ITEMS_EXISTS_BY_TYPE(tp_pif_queries.id, 'PIF_PAY_ALLOCATE')) .EXIT_MESSAGE('Заявка с такими реквизитами уже существует') .TYPE_INIT('PIF_PAY_ALLOCATE',12) .TYPE_ASSIGN(depo_doc_type,1,12) .DEPO_GEN_NO(@in_no12_1,@depo_doc_type12_1) .TYPE_ASSIGN(folder_id,@folder_id,12) .TYPE_ASSIGN(pif_pay_type_id,2,12) .TYPE_ASSIGN(agent_regs_date, @req_date, 12) .TYPE_ASSIGN(agent_regs_no, @req, 12) .TYPE_ASSIGN(pay_owner_id, @partner_id, 12) .TYPE_ASSIGN(agent_id, @agent_id, 12) .TYPE_ASSIGN(agent_dog_id, @agent_dog_id, 12) if .ITEM_TYPE_CODE(@partner_id)='PARTNERS_FIS' .TYPE_ASSIGN(bank_account_no,@dpersonalaccount,12) if .ITEM_TYPE_CODE(@partner_id)='PARTNERS_JUR' .TYPE_ASSIGN(bank_account_no,@daccount,12) .TYPE_ASSIGN(bank_name, @dbankname, 12) .TYPE_ASSIGN(bik, @dbic, 12) .TYPE_ASSIGN(corr_account, @dbankcorr, 12) .TYPE_ASSIGN(bank_city_name, @dbankcity, 12) .TYPE_ASSIGN(type_queries, @req_type, 12) .TYPE_INSERT('PIF_PAY_ALLOCATE','ED',12) --или 'PROV' end else if @req_type in (2,4) begin -- Заявка на выкуп (списание по обмену) паев - новая if exists(select 1 from tp_pif_queries, td_depo_docs where upper(tp_pif_queries.agent_regs_no) = upper(@req) and tp_pif_queries.agent_regs_date = @req_date and tp_pif_queries.id = td_depo_docs.id and tp_pif_queries.type_queries=@req_type and .ITEMS_EXISTS_BY_TYPE(tp_pif_queries.id, 'PIF_PAY_BUY')) .EXIT_MESSAGE('Заявка с такими реквизитами уже существует') .TYPE_INIT('PIF_PAY_BUY',22) .TYPE_ASSIGN(depo_doc_type,1,22) .DEPO_GEN_NO(@in_no22_1,@depo_doc_type22_1) .TYPE_ASSIGN(folder_id,@folder_id,22) .TYPE_ASSIGN(pif_pay_type_id,1,22) if @saldo is null .EXIT_MESSAGE('В заявке на погашение не указано количество паев') .TYPE_ASSIGN(stock_qty, @saldo, 22) .TYPE_ASSIGN(agent_regs_date, @req_date, 22) .TYPE_ASSIGN(agent_regs_no, @req, 22) .TYPE_ASSIGN(pay_owner_id, @partner_id, 22) .TYPE_ASSIGN(agent_id, @agent_id, 22) .TYPE_ASSIGN(agent_dog_id, @agent_dog_id, 22) if .ITEM_TYPE_CODE(@partner_id)='PARTNERS_FIS' .TYPE_ASSIGN(bank_account_no,@dpersonalaccount,22) if .ITEM_TYPE_CODE(@partner_id)='PARTNERS_JUR' .TYPE_ASSIGN(bank_account_no,@daccount,22) .TYPE_ASSIGN(bank_name, @dbankname, 22) .TYPE_ASSIGN(bik, @dbic, 22) .TYPE_ASSIGN(corr_account, @dbankcorr, 22) .TYPE_ASSIGN(bank_city_name, @dbankcity, 22) .TYPE_ASSIGN(type_queries, @req_type, 22) .TYPE_INSERT('PIF_PAY_BUY','ED',22) --или 'PROV' end else .EXIT_MESSAGE('Тип заявки не содержит слов Приобретение/выкуп/обмен') end --***********************КОНЕЦ - НОВЫЕ заявки************************* --if @partner_id is null .EXIT_MESSAGE('Пайщик не найден') --*******************ИСПОЛНЕННЫЕ заявки************************************ if @pdate='' select @pdate=null declare @p_date datetime select @p_date=convert(datetime,@pdate) .ID_VAR(@q_type_id) .INT_VAR(@is_cancel) --**********Проверка выбранных Отчетов регистратора************************* if @report_id_s='' select @report_id_s=null if @cancel_report_id_s='' select @cancel_report_id_s=null declare @report_id numeric, @cancel_report_id numeric select @report_id=convert(numeric,@report_id_s), @cancel_report_id=convert(numeric,@cancel_report_id_s) --**********КОНЕЦ - Проверка выбранных Отчетов регистратора************************* if charindex('ИСПОЛН', upper(@reqstatus))>0 begin if @report_id is null .EXIT_MESSAGE('Не задан отчет регистратора о принятых заявках!') if .ITEM_TYPE_CODE(@report_id)!='PIF_PAY_REPORT' .EXIT_MESSAGE('Выбранный документ не является Отчетом регистратора о принятых зявках!') select @is_cancel=0 if @req_type in (1,3) select @q_type_id=.TYPE_ID_FROM_CODE_FUNC('PIF_PAY_ALLOCATE') if @req_type in (2,4) select @q_type_id=.TYPE_ID_FROM_CODE_FUNC('PIF_PAY_BUY') if @q_type_id is null .EXIT_MESSAGE('Не определен тип исполненной заявки') if @saldo is null or @psumma is null .EXIT_MESSAGE('Не указана сумма или кол-во паев') if @req_type in (1,3) and (@p_date is null or @pnum is null) and @is_cancel=0 .EXIT_MESSAGE('Не указана дата или номер платежа для заявки на выдачу') if exists(select 1 from tp_pay2rep_imp where q_no=@req and q_date=@req_date and q_type_id=@q_type_id and @req_type in (1,3) and p_no=@pnum and p_date=@p_date) .EXIT_MESSAGE('Заявка уже была импортирована') begin tran .TYPE_INIT('PIF_PAY2REP_IMP',31) .TYPE_ASSIGN(extract_id,@report_id,31) .TYPE_ASSIGN(agent,@agent,31) .TYPE_ASSIGN(payer,@dname,31) .TYPE_ASSIGN(acc_no,@daccname,31) .TYPE_ASSIGN(q_type_id,@q_type_id,31) .TYPE_ASSIGN(q_date,@req_date,31) .TYPE_ASSIGN(q_no,@req,31) .TYPE_ASSIGN(p_date,@p_date,31) .TYPE_ASSIGN(p_no,@pnum,31) .TYPE_ASSIGN(q_sum,@psumma,31) .TYPE_ASSIGN(q_qty,@saldo,31) .TYPE_ASSIGN(agent_sum,@ppremiumagent,31) .TYPE_INSERT('PIF_PAY2REP_IMP','WAIT',31) if upper(.ITEM_STATE_CODE(@report_id))='ED_CLAIM' begin .ITEM_MOVE_STATE(@report_id,'WAIT_CHECK') end commit tran end --*******************КОНЕЦ - ИСПОЛНЕННЫЕ заявки***************************** --*******************ОТКАЗАННЫЕ заявки***************************** if charindex('ЗАПРЕЩ', upper(@reqstatus))>0 begin if @cancel_report_id is null .EXIT_MESSAGE('Не задан отчет регистратора об отказах!') if .ITEM_TYPE_CODE(@cancel_report_id)!='PIF_PAY_CANCEL' .EXIT_MESSAGE('Выбранный документ не является Отчетом регистратора об отказах!') select @is_cancel=1 if @req_type in (1,3) select @q_type_id=.TYPE_ID_FROM_CODE_FUNC('PIF_PAY_ALLOCATE') if @req_type in (2,4) select @q_type_id=.TYPE_ID_FROM_CODE_FUNC('PIF_PAY_BUY') if @q_type_id is null .EXIT_MESSAGE('Не определен тип отказанной заявки') if exists(select 1 from tp_pay2rep_imp where q_no=@req and q_date=@req_date and q_type_id=@q_type_id) .EXIT_MESSAGE('Заявка уже была импортирована') begin tran .TYPE_INIT('PIF_PAY2REP_IMP',32) .TYPE_ASSIGN(extract_id,@cancel_report_id,32) .TYPE_ASSIGN(agent,@agent,32) .TYPE_ASSIGN(payer,@dname,32) .TYPE_ASSIGN(acc_no,@daccname,32) .TYPE_ASSIGN(q_type_id,@q_type_id,32) .TYPE_ASSIGN(q_date,@req_date,32) .TYPE_ASSIGN(q_no,@req,32) .TYPE_ASSIGN(p_date,@p_date,32) .TYPE_ASSIGN(p_no,@pnum,32) .TYPE_ASSIGN(q_sum,@psumma,32) .TYPE_ASSIGN(q_qty,@saldo,32) .TYPE_ASSIGN(agent_sum,@ppremiumagent,32) .TYPE_INSERT('PIF_PAY2REP_IMP','WAIT',32) if upper(.ITEM_STATE_CODE(@cancel_report_id))='ED_CLAIM' begin .ITEM_MOVE_STATE(@cancel_report_id,'WAIT_CHECK') end commit tran end --*******************КОНЕЦ - ОТКАЗАННЫЕ заявки***************************** --***************Конец - Импорт заявок*********** select sid = convert(varchar, @id) end $ENDTEXT(11405187) $ENDACTION $STATE2ACTION(CRT.ACTION_IMPORT) state=CRT action=ACTION_IMPORT $ENDSTATE2ACTION $STATE2ACTION(CRT.ACTION_INSERT) state=CRT action=ACTION_INSERT $ENDSTATE2ACTION $STATE2ACTION(CRT.ED_PIF_PAY_REP_LIST) state=CRT action=ED_PIF_PAY_REP_LIST $ENDSTATE2ACTION $STATE2ACTION(CRT.FORM2) state=CRT action=FORM2 $ENDSTATE2ACTION $STATE2ACTION(CRT.PIF_PAY_REPS_LIST) state=CRT action=PIF_PAY_REPS_LIST $ENDSTATE2ACTION $STATE2ACTION(CRT.SBRF_REESTR_IMPORT) state=CRT action=SBRF_REESTR_IMPORT $ENDSTATE2ACTION $ENDDOC