# Date: 16/02/06 # Version: 105 $PATTERN(.PIF_AGENT_PROC4PARTION) name=Процент скидки при погашении партии паев class=2 product=ALD_UKPIF pattern_text=$TEXT(15222643) -------------------------start .PIF_AGENT_PROC4PARTION------------------------------ DECLARE @io_d int SELECT @io_d = DATEDIFF(Day,%PART_DATE%,%OP_DATE%) SELECT c.id , lol = CASE comission_date_type WHEN 1 THEN (isnull(c.comission_date_level,0) / @io_d) ELSE ( DATEDIFF(Day,%PART_DATE%,(dateadd(mm,isnull(c.comission_date_level,0),%PART_DATE%))) / @io_d) END INTO #new_table from t_pif_comis c, tb_contracts d where d.id=%DOG% and c.settings_id=d.id and c.profit_type_id=2 and .ITEMS_EXISTS(c.id) if not exists (Select 1 from #new_table where lol>1) begin DELETE from #new_table where lol <> (select max(lol) from #new_table) select %LOL%=max(isnull(c.comission_percent,0)) from t_pif_comis c where id=(select id from #new_table) end else begin DELETE from #new_table where lol <1 DELETE from #new_table where lol <> (Select min(lol) from #new_table) select %LOL%=max(isnull(c.comission_percent,0)) from t_pif_comis c where id=(select id from #new_table) end if not exists(Select 1 from #new_table) select %LOL%=0 /* ( select max(isnull(c.comission_percent,0)) from t_pif_comis c, tb_contracts d where d.id=%DOG% and c.settings_id=d.id and c.profit_type_id=2 and .ITEMS_EXISTS(c.id) and dateadd(mm,(-1)*isnull(c.comission_date_level,0),%OP_DATE%) = (select min(dateadd(mm,(-1)*isnull(cc.comission_date_level,0),%OP_DATE%)) from t_pif_comis cc, tb_contracts dd where dd.id=%DOG% and cc.settings_id=dd.id and cc.profit_type_id=2 and dateadd(mm,(-1)*isnull(cc.comission_date_level,0),%OP_DATE%) >= %PART_DATE% and .ITEMS_EXISTS(cc.id)) ) */ -------------------------end .PIF_AGENT_PROC4PARTION------------------------------ $ENDTEXT(15222643) $PATTERNARG(%DOG%) name=Агентский договор order=1 comment=null mandatory=1 default=null choose_type=null choose_action=null choose_field=null $ENDPATTERNARG $PATTERNARG(%OP_DATE%) name=Дата получения order=2 comment=null mandatory=1 default=null choose_type=null choose_action=null choose_field=null $ENDPATTERNARG $PATTERNARG(%PART_DATE%) name=Дата партии order=3 comment=null mandatory=1 default=null choose_type=null choose_action=null choose_field=null $ENDPATTERNARG $PATTERNARG(%LOL%) name=Процент вознаграждения order=4 comment=null mandatory=1 default=0 choose_type=null choose_action=null choose_field=null $ENDPATTERNARG $ENDPATTERN