IF (EXISTS (select proc_name from sysprocedure where proc_name='PreparePrintAgainProform')) THEN Drop procedure PreparePrintAgainProform; END IF; GO create procedure "DBA".PreparePrintAgainProform(in @ProformNo integer,in @place varchar(50)) // Tazi procedura se izpolzva za napylwane na wremennata tablica #Articles za povtoren pe4at na proforma begin declare @ArticleNumber integer; declare @Deposit double; declare @Disc double; declare @PrWithDisc double; declare @IsForAlServices integer; declare @HumanKind integer; declare @MaxQty integer; declare @MinQty integer; declare @ArticlePrWithDDS double; //Izprazva vremennata tablica za uslugi i noshtuvki delete from #Articles; select Max(ArticleNumber)+1 into @ArticleNumber from #Articles; if @ArticleNumber is null then set @ArticleNumber=1 end if ; for f as curs scroll cursor for select ArticleName as @ArticleName,Qty as @Qty,Price as @ArticlePrice,Discount as @Discount,RegNo as @RegNo, CreditNo as @CreditNo,TipDDS as @TipDDS,ServiceNo as @ServiceNo,DDSType as @DDSType from ProArticles where ProformNo=@ProformNo do if(@Qty<0) then set @MaxQty=0; set @MinQty=@Qty else set @MaxQty=@Qty; set @MinQty=0 end if ; set @ArticlePrWithDDS=@ArticlePrice; if @TipDDS=1 then if @DDSType=1 then set @ArticlePrice=@ArticlePrice/(bvrDDSPart+1); else set @ArticlePrice=@ArticlePrice/(1.07); end if; set @TipDDS=2 end if ; insert into #Articles(ArticleNumber,ArticleName,Measure,ArticleQty,MaxQty,MinQty,ArticlePrice,Discount, RegNo,CreditNo,ArticleSum,TipDDS,ServiceNo,PriceInvWithDDS,ArticleSumWithDDS) values( @ArticleNumber,@ArticleName,'απ.',@Qty,@MaxQty,@MinQty,@ArticlePrice,@Discount,@RegNo, @CreditNo,((@ArticlePrice*@Qty)-((@ArticlePrice*@Qty)*@Discount)/100),@TipDDS,@ServiceNo,@ArticlePrWithDDS, ((@ArticlePrWithDDS*@Qty)-((@ArticlePrWithDDS*@Qty)*@Discount)/100)); set @ArticleNumber=@ArticleNumber+1 end for end //[v 18.02.2003] Jorko