IF (EXISTS(Select * from sys.sysprocedure where LCase(proc_name) = LCase('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,VatRate as @VatRate 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 set @ArticlePrice = @ArticlePrice/(1+@VatRate); set @TipDDS = 2 end if; insert into #Articles( ArticleNumber,ArticleName,Measure,ArticleQty,MaxQty,MinQty,ArticlePrice,Discount, RegNo,CreditNo,ArticleSum,TipDDS,ServiceNo,PriceInvWithDDS,ArticleSumWithDDS,VatRate,DDSType ) 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),@VatRate,@DDSType ) ; set @ArticleNumber = @ArticleNumber+1 end for end //[v 18.02.2003] Jorko