# Date: 12/07/06 # Version: 105 $DOC(SD_OVERVALUE_LIST) name=ЦБ для переоценки class=1 product=ALD_FUND name_formula=null remark_formula=null $STATE(CREATE) name=Создан class=0 $ENDSTATE $STATE(NEW) name=Начальный class=1 $ENDSTATE $PROP(STOCK_ID) name=ЦБ field_name=stock_id table_name=ts_sd_stock_overvalue_st field_type=numeric field_length=9 field_scale=0 field_prec=18 page=1 order=2 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(STOCK_QTY) name=Кол-во ЦБ field_name=stock_qty table_name=ts_sd_stock_overvalue_st field_type=money field_length=8 field_scale=null field_prec=null 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(SUM_ONE_STOCK) name=Сумма на 1 цб field_name=sum_one_stock table_name=ts_sd_stock_overvalue_st field_type=decimal field_length=9 field_scale=8 field_prec=18 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(SUM_MAIN) name=Общая сумма field_name=sum_main table_name=ts_sd_stock_overvalue_st field_type=money field_length=8 field_scale=null field_prec=null page=1 order=5 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(SUM_NKD_ONE_STOCK) name=Сумма НКД на 1 цб field_name=sum_nkd_one_stock table_name=ts_sd_stock_overvalue_st field_type=decimal field_length=9 field_scale=8 field_prec=18 page=1 order=6 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(SUM_NKD_MAIN) name=Общая сумма НКД field_name=sum_nkd_main table_name=ts_sd_stock_overvalue_st field_type=money field_length=8 field_scale=null field_prec=null page=1 order=7 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(DOC_ID) name=Документ переоценки field_name=doc_id table_name=ts_sd_stock_overvalue_st field_type=numeric field_length=9 field_scale=0 field_prec=18 page=1 order=1 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(IS_GET_RATE) name=Брать котировку field_name=is_get_rate table_name=ts_sd_stock_overvalue_st field_type=int field_length=4 field_scale=null field_prec=null page=1 order=9 init_class=1 init_formula=0 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(CUR_ID) name=Валюта field_name=cur_id table_name=ts_sd_stock_overvalue_st field_type=numeric field_length=9 field_scale=0 field_prec=18 page=1 order=8 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(RATE_DATE) name=Дата котировки field_name=rate_date table_name=ts_sd_stock_overvalue_st field_type=datetime field_length=8 field_scale=null field_prec=null 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(MARGIN_SUM) name=Прибыль field_name=margin_sum table_name=ts_sd_stock_overvalue_st field_type=money field_length=8 field_scale=null field_prec=null page=1 order=11 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(REL2) class=0 type=cur form=null prop=CUR_ID idname=null order=2 $ENDRELATION $RELATION(REL1) class=0 type=td_stock_emis form=null prop=STOCK_ID idname=null order=1 $ENDRELATION $FORM(FORM1) name=Редактор ЦБ class=5 filter=null target_state= uo=uo_edit dw=d_sdepo_overvalue_st_item procedure=ap_60995000000150819 patterns=GENERIC_VIEW_ITEM_O user_define=0 isvisible=1 istab=0 posx=0 posy=0 width=0 height=0 proc_text=$TEXT(11052110) create procedure dbo.%PROC% @sid varchar(30) = null as .BEGIN('N') .CHECK_USER .CHECK_VIEW if @id = -1 begin .VIEW_INIT end else begin .VIEW_ITEM end .END $ENDTEXT(11052110) $ACTION2RELATION(REL1.STOCK_CODE) relation=REL1 where=null prop=STOCK_CODE order=null alias=stock_code $ENDACTION2RELATION $ACTION2RELATION(REL1.STOCK_NAME) relation=REL1 where=null prop=STOCK_NAME order=null alias=stock_name $ENDACTION2RELATION $ENDFORM $FORM(FORM2) name=Список ЦБ class=4 filter=null target_state= uo=uo_list dw=d_sdepo_overvalue_st_list procedure=ap_60995000000150821 patterns=GENERIC_VIEW_LIST user_define=0 isvisible=1 istab=0 posx=0 posy=0 width=0 height=0 proc_text=$TEXT(11052110) create procedure dbo.%PROC% @sid varchar(30) = null .ARGLIST_FILTER as .BEGIN('N') .CHECK_USER .CHECK_VIEW .ARGCONVERT_FILTER .VIEW_LIST .END $ENDTEXT(11052110) $ACTION2RELATION(REL1.STOCK_CODE) relation=REL1 where=null prop=STOCK_CODE order=null alias=stock_code $ENDACTION2RELATION $ACTION2RELATION(REL1.STOCK_NAME) relation=REL1 where=null prop=STOCK_NAME order=null alias=stock_name $ENDACTION2RELATION $ACTION2RELATION(REL2.CUR_CODE) relation=REL2 where=null prop=CUR_CODE order=15 alias=cur_code $ENDACTION2RELATION $FILTER(DOC_ID) type=11 label=ID док prop=DOC_ID arg_code=null arg_type=null arg_length=null arg_prec=null arg_scale=null $ENDFILTER $ENDFORM $ACTION(ACTION_DELETE) name=Удалить class=9 form=null target_state=null procedure=ap_60995000000150825 patterns=GENERIC_MOVE user_define=0 isvisible=0 istab=0 posx=0 posy=0 width=1888 height=932 proc_text=$TEXT(11052110) create procedure dbo.%PROC% @sid varchar(30) = null as .BEGIN('N') .CHECK_USER .CHECK_UPDATE begin tran .GET_PROPS if upper(.ITEM_STATE_CODE(@doc_id)) not in ('ED') .EXIT_MESSAGE('Нельзя удалить ЦБ из документа в текущем статусе') .TYPE_DELETE commit tran .END $ENDTEXT(11052110) $ENDACTION $ACTION(ACTION_INSERT) name=Добавить class=1 form=FORM1 target_state=CREATE procedure=ap_60995000000150826 patterns=GENERIC_INSERT_O user_define=0 isvisible=0 istab=0 posx=0 posy=0 width=2144 height=956 proc_text=$TEXT(11052110) create procedure dbo.%PROC% @sid varchar(30) = null, .ARGLIST as .BEGIN('N') .CHECK_USER .CHECK_INSERT .ARGCONVERT .INIT_VARS if exists(select 1 from ts_sd_stock_overvalue_st st where st.doc_id=@doc_id and st.id<>@id and st.stock_id=@stock_id) .EXIT_MESSAGE('Данная ЦБ уже выбрана') if upper(.ITEM_STATE_CODE(@doc_id)) not in ('ED') .EXIT_MESSAGE('Нельзя добавить ЦБ в документ в текущем статусе') select @sum_main=round(@sum_main,2) select @sum_nkd_main=round(@sum_nkd_main,2) begin tran .INSERT_ITEMS .INSERT .UPDATE_STATE select @sid=convert(varchar, @id) .EXEC_ACTION(@sid,'SD_OVERVALUE_LIST','GET_RATE') commit tran select sid = convert(varchar, @id) .END $ENDTEXT(11052110) $ENDACTION $ACTION(ACTION_UPDATE) name=Изменить class=2 form=FORM1 target_state=null procedure=ap_60995000000150827 patterns=GENERIC_UPDATE user_define=0 isvisible=0 istab=0 posx=0 posy=0 width=2176 height=988 proc_text=$TEXT(11052110) create procedure dbo.%PROC% @sid varchar(30) = null, .ARGLIST as .BEGIN('N') .CHECK_USER .CHECK_UPDATE .ARGCONVERT if exists(select 1 from ts_sd_stock_overvalue_st st where st.doc_id=@doc_id and st.id<>@id and st.stock_id=@stock_id) .EXIT_MESSAGE('Данная ЦБ уже выбрана') if upper(.ITEM_STATE_CODE(@doc_id)) not in ('ED') .EXIT_MESSAGE('Нельзя изменить ЦБ в документе в текущем статусе') select @sum_main=round(@sum_main,2) select @sum_nkd_main=round(@sum_nkd_main,2) begin tran .UPDATE_ITEMS .UPDATE .UPDATE_STATE .EXEC_ACTION(@sid,'SD_OVERVALUE_LIST','GET_RATE') commit tran .END $ENDTEXT(11052110) $ENDACTION $ACTION(ACT_DEL_ALL) name=Удалить все class=9 form=null target_state=null procedure=ap_60995000000150828 patterns=GENERIC_MOVE user_define=0 isvisible=0 istab=0 posx=0 posy=0 width=0 height=0 proc_text=$TEXT(11052110) create procedure dbo.%PROC% @sid varchar(30) = null as .BEGIN('N') .CHECK_USER .CHECK_UPDATE begin tran .GET_PROPS if upper(.ITEM_STATE_CODE(@doc_id)) not in ('ED') .EXIT_MESSAGE('Нельзя удалить ЦБ из документа в текущем статусе') delete t_items from ts_sd_stock_overvalue_st st where st.id=t_items.id and st.doc_id=@doc_id delete ts_sd_stock_overvalue_st where doc_id=@doc_id commit tran .END $ENDTEXT(11052110) $ENDACTION $ACTION(GET_RATE) name=Определить котировку class=9 form=null target_state=null procedure=ap_get_rate4overvalue patterns=GENERIC_MOVE user_define=1 isvisible=1 istab=0 posx=0 posy=0 width=0 height=0 proc_text=$TEXT(11052112) create procedure dbo.%PROC% @id numeric = null as begin tran .ID_VAR(@stock_id) .ID_VAR(@owner_id) .ID_VAR(@place_id) .ID_VAR(@rate_cur_id) .ID_VAR(@type_overvalue_id) .INT_VAR(@is_get_rate) .INT_VAR(@is_fix_rate_date) .NAME_VAR(@class_value_code) .NAME_VAR(@class_comment) declare @in_date datetime, @rate_date datetime, @get_date datetime declare @stock_rate decimal(18,8), @coupon_rate decimal(18,8), @class_round int select @owner_id=o.owner_id, @in_date=o.in_date, @type_overvalue_id=isnull(o.type_overvalue_id,0), @is_fix_rate_date=isnull(o.is_fix_rate_date,0), @is_get_rate=isnull(st.is_get_rate,0), @stock_id=st.stock_id, @get_date=st.rate_date, @place_id=o.place_id from ts_sd_stock_overvalue_st st, ts_sd_stock_overvalue o where o.id=st.doc_id and st.id=@id if @is_get_rate=1 and @type_overvalue_id<>0 begin select @get_date=isnull(@get_date,@in_date) if @place_id is null begin exec ap_getclassvalue_code @stock_id,'STOCK_RATE_PLACE',null,@owner_id, @class_value_code out, @class_comment out if @class_value_code is not null begin select @place_id = max(td_rate_places.id) from td_rate_places where upper(td_rate_places.place_code) = upper(@class_value_code) and .ITEMS_EXISTS(td_rate_places.id) if isnull(@class_comment,'')<>'' select @class_round=convert(int,@class_comment) end end if @place_id is not null begin if @is_fix_rate_date=0 begin select @stock_rate=tb_stock_rates.stock_rate, @rate_date=tb_stock_rates.rate_date, @rate_cur_id=tb_stock_rates.rate_cur_id from tb_stock_rates where tb_stock_rates.rate_place_id = @place_id and tb_stock_rates.stock_id = @stock_id and tb_stock_rates.rate_date = (select max(tb_stock_rates.rate_date) from tb_stock_rates where tb_stock_rates.rate_place_id = @place_id and tb_stock_rates.rate_date <= @get_date and tb_stock_rates.stock_rate<>0 and tb_stock_rates.stock_id = @stock_id and .ITEMS_EXISTS(tb_stock_rates.id)) and .ITEMS_EXISTS(tb_stock_rates.id) if @stock_rate is null ------ Если котировки не найдена, поиск ближайшей максимальной по всем площадкам ---- select @stock_rate=tb_stock_rates.stock_rate, @rate_date=tb_stock_rates.rate_date, @rate_cur_id=tb_stock_rates.rate_cur_id, @place_id=tb_stock_rates.rate_place_id from tb_stock_rates where tb_stock_rates.stock_id = @stock_id and tb_stock_rates.stock_rate = (select max(a.stock_rate) from tb_stock_rates a where a.stock_id = @stock_id and .ITEMS_EXISTS(a.id) and a.rate_date = (select max(b.rate_date) from tb_stock_rates b where b.rate_date <= @get_date and isnull(b.stock_rate,0)<>0 and b.stock_id = @stock_id and .ITEMS_EXISTS(b.id)) ) and .ITEMS_EXISTS(tb_stock_rates.id) and tb_stock_rates.rate_date = (select max(tb_stock_rates.rate_date) from tb_stock_rates where tb_stock_rates.rate_date <= @get_date and isnull(tb_stock_rates.stock_rate,0)<>0 and tb_stock_rates.stock_id = @stock_id and .ITEMS_EXISTS(tb_stock_rates.id)) ----------------------------------------------------------------------------------- end if @is_fix_rate_date=1 begin select @stock_rate=tb_stock_rates.stock_rate, @rate_date=tb_stock_rates.rate_date, @rate_cur_id=tb_stock_rates.rate_cur_id from tb_stock_rates where tb_stock_rates.rate_place_id = @place_id and tb_stock_rates.stock_id = @stock_id and tb_stock_rates.rate_date = @get_date and .ITEMS_EXISTS(tb_stock_rates.id) if @stock_rate is null ------ Если котировки не найдена, поиск ближайшей максимальной по всем площадкам ---- select @stock_rate=tb_stock_rates.stock_rate, @rate_date=tb_stock_rates.rate_date, @rate_cur_id=tb_stock_rates.rate_cur_id, @place_id=tb_stock_rates.rate_place_id from tb_stock_rates where tb_stock_rates.stock_id = @stock_id and tb_stock_rates.stock_rate = (select max(a.stock_rate) from tb_stock_rates a where a.stock_id = @stock_id and .ITEMS_EXISTS(a.id) and a.rate_date = @get_date ) and .ITEMS_EXISTS(tb_stock_rates.id) and tb_stock_rates.rate_date = @get_date ----------------------------------------------------------------------------------- end end -- НКД select @coupon_rate=tb_stock_rates.coupon_rate from tb_stock_rates where tb_stock_rates.rate_place_id = @place_id and tb_stock_rates.stock_id = @stock_id and tb_stock_rates.rate_date = @get_date and .ITEMS_EXISTS(tb_stock_rates.id) if @rate_cur_id is null select @rate_cur_id=(select td_rate_places.cur_id from td_rate_places where id=@place_id) if @rate_cur_id is null select @rate_cur_id=.CUR('RUR') if @class_round is not null select @stock_rate = round(@stock_rate,@class_round) update ts_sd_stock_overvalue_st set sum_one_stock=@stock_rate, sum_nkd_one_stock=@coupon_rate, cur_id=@rate_cur_id, rate_date=@rate_date where id=@id end else update ts_sd_stock_overvalue_st set rate_date=null where id=@id commit tran $ENDTEXT(11052112) $ENDACTION $STATE2ACTION(CREATE.ACTION_DELETE) state=CREATE action=ACTION_DELETE is_available=1 $ENDSTATE2ACTION $STATE2ACTION(CREATE.ACTION_INSERT) state=CREATE action=ACTION_INSERT is_available=0 $ENDSTATE2ACTION $STATE2ACTION(CREATE.ACTION_UPDATE) state=CREATE action=ACTION_UPDATE is_available=1 $ENDSTATE2ACTION $STATE2ACTION(CREATE.ACT_DEL_ALL) state=CREATE action=ACT_DEL_ALL is_available=1 $ENDSTATE2ACTION $STATE2ACTION(CREATE.FORM1) state=CREATE action=FORM1 is_available=1 $ENDSTATE2ACTION $STATE2ACTION(CREATE.FORM2) state=CREATE action=FORM2 is_available=1 $ENDSTATE2ACTION $STATE2ACTION(CREATE.GET_RATE) state=CREATE action=GET_RATE is_available=0 $ENDSTATE2ACTION $STATE2ACTION(NEW.ACTION_DELETE) state=NEW action=ACTION_DELETE is_available=0 $ENDSTATE2ACTION $STATE2ACTION(NEW.ACTION_INSERT) state=NEW action=ACTION_INSERT is_available=1 $ENDSTATE2ACTION $STATE2ACTION(NEW.ACTION_UPDATE) state=NEW action=ACTION_UPDATE is_available=0 $ENDSTATE2ACTION $STATE2ACTION(NEW.ACT_DEL_ALL) state=NEW action=ACT_DEL_ALL is_available=0 $ENDSTATE2ACTION $STATE2ACTION(NEW.FORM1) state=NEW action=FORM1 is_available=0 $ENDSTATE2ACTION $STATE2ACTION(NEW.FORM2) state=NEW action=FORM2 is_available=0 $ENDSTATE2ACTION $STATE2ACTION(NEW.GET_RATE) state=NEW action=GET_RATE is_available=0 $ENDSTATE2ACTION $STATE2PROP(CREATE.CUR_ID) state=CREATE prop=CUR_ID enable=1 mandatory=0 visible=1 $ENDSTATE2PROP $STATE2PROP(CREATE.DOC_ID) state=CREATE prop=DOC_ID enable=1 mandatory=1 visible=1 $ENDSTATE2PROP $STATE2PROP(CREATE.IS_GET_RATE) state=CREATE prop=IS_GET_RATE enable=1 mandatory=0 visible=1 $ENDSTATE2PROP $STATE2PROP(CREATE.MARGIN_SUM) state=CREATE prop=MARGIN_SUM enable=0 mandatory=0 visible=0 $ENDSTATE2PROP $STATE2PROP(CREATE.RATE_DATE) state=CREATE prop=RATE_DATE enable=1 mandatory=0 visible=1 $ENDSTATE2PROP $STATE2PROP(CREATE.STOCK_ID) state=CREATE prop=STOCK_ID enable=1 mandatory=1 visible=1 $ENDSTATE2PROP $STATE2PROP(CREATE.STOCK_QTY) state=CREATE prop=STOCK_QTY enable=0 mandatory=0 visible=0 $ENDSTATE2PROP $STATE2PROP(CREATE.SUM_MAIN) state=CREATE prop=SUM_MAIN enable=1 mandatory=0 visible=1 $ENDSTATE2PROP $STATE2PROP(CREATE.SUM_NKD_MAIN) state=CREATE prop=SUM_NKD_MAIN enable=1 mandatory=0 visible=1 $ENDSTATE2PROP $STATE2PROP(CREATE.SUM_NKD_ONE_STOCK) state=CREATE prop=SUM_NKD_ONE_STOCK enable=1 mandatory=0 visible=1 $ENDSTATE2PROP $STATE2PROP(CREATE.SUM_ONE_STOCK) state=CREATE prop=SUM_ONE_STOCK enable=1 mandatory=0 visible=1 $ENDSTATE2PROP $STATE2PROP(NEW.CUR_ID) state=NEW prop=CUR_ID enable=1 mandatory=0 visible=1 $ENDSTATE2PROP $STATE2PROP(NEW.DOC_ID) state=NEW prop=DOC_ID enable=1 mandatory=1 visible=1 $ENDSTATE2PROP $STATE2PROP(NEW.IS_GET_RATE) state=NEW prop=IS_GET_RATE enable=1 mandatory=0 visible=1 $ENDSTATE2PROP $STATE2PROP(NEW.MARGIN_SUM) state=NEW prop=MARGIN_SUM enable=0 mandatory=0 visible=0 $ENDSTATE2PROP $STATE2PROP(NEW.RATE_DATE) state=NEW prop=RATE_DATE enable=1 mandatory=0 visible=1 $ENDSTATE2PROP $STATE2PROP(NEW.STOCK_ID) state=NEW prop=STOCK_ID enable=1 mandatory=1 visible=1 $ENDSTATE2PROP $STATE2PROP(NEW.STOCK_QTY) state=NEW prop=STOCK_QTY enable=0 mandatory=0 visible=0 $ENDSTATE2PROP $STATE2PROP(NEW.SUM_MAIN) state=NEW prop=SUM_MAIN enable=1 mandatory=0 visible=1 $ENDSTATE2PROP $STATE2PROP(NEW.SUM_NKD_MAIN) state=NEW prop=SUM_NKD_MAIN enable=1 mandatory=0 visible=1 $ENDSTATE2PROP $STATE2PROP(NEW.SUM_NKD_ONE_STOCK) state=NEW prop=SUM_NKD_ONE_STOCK enable=1 mandatory=0 visible=1 $ENDSTATE2PROP $STATE2PROP(NEW.SUM_ONE_STOCK) state=NEW prop=SUM_ONE_STOCK enable=1 mandatory=0 visible=1 $ENDSTATE2PROP $ENDDOC