IF (EXISTS (select proc_name from sysprocedure where LCase(proc_name)=LCase('VaucherArticlesByVidSmetka'))) THEN Drop procedure VaucherArticlesByVidSmetka END IF GO create procedure DBA.VaucherArticlesByVidSmetka(in @VidSmetka integer,in @oldRate double,in @newRate double,in @NewCurrency integer) // Ako se smeni vida na smetkata tazi procedura zapisva korektnite stojnosti // i promenia imeto, ako e vuvedeno begin declare @NewName varchar(40); declare @Season varchar(40); declare @ExtraBed varchar(40); // declare @ExtraBedN integer; declare @Price double; declare @Total double; declare @NightsTotal double; declare @ExtresTotal double; message '@oldRate=' || @oldRate || ' @newRate=' || @newRate type info to console; // if @oldRate=@newRate then // return // end if set @price=0; for f0 as curs0 scroll cursor for select ArticleNumber as @ArticleNumber,VaucherN as @VaucherNo,SinglePrice as @ArtPrice, ArticleName as @ArticleName,VaucherSeason as @VaucherSeason,VaucherBedType as @VaucherBedType, ExtraBed as @ExtraBedN, GrandTotal as @ArticleSum,ServiceNo as @ServiceNo,Nights as @Nights from #VaucherArticles do //message '@ArtPrice >> '||@ArtPrice; set @NewName=null; set @Season=null; set @ExtraBed=null; if @oldRate = @newRate then set @Price=@Artprice; set @total=@ArticleSum else set @Price=@Artprice*@oldRate; set @price=@price/@newRate; set @total=@ArticleSum*@oldRate; set @total=@total/@newRate end if; if(@VaucherNo <> 0) then select SS.Stoinost into @NewName from VidSmetki as VS,SvoServicesStn as SS where VS.N = @VidSmetka and VS.SvoService = SS.Svoistvo and SS.Glava = @ServiceNo; if(@NewName is null) then set @NewName=@ArticleName end if; select SS.Stoinost into @Season from SvoVaucherStn as SS,PriceSeasons as PS,VidSmetki as VS where PS.SeasonNo = SS.Glava and SS.Svoistvo = VS.SvoService and SS.SvoKind = 'sea' and VS.N = @VidSmetka and PS.Description = @VaucherSeason; if(@Season is null) then set @Season=@VaucherSeason end if; select SS.Stoinost into @ExtraBed from SvoVaucherStn as SS,ExtraBed as EB,VidSmetki as VS where EB.N = SS.Glava and SS.Svoistvo = VS.SvoService and SS.SvoKind = 'bed' and VS.N = @VidSmetka and EB.N = @ExtraBedN; if(@ExtraBed is null) then set @ExtraBed=@VaucherBedType end if; update #VaucherArticles set TranslateName = @NewName,TranslateSeason = @Season,TranslateBed = @ExtraBed, SinglePrice = @Price,GrandTotal = @Total,Currency = @NewCurrency where ArticleNumber = @ArticleNumber and VaucherN <> 0 else select SS.Stoinost into @NewName from VidSmetki as VS,SvoVaucherStn as SS where VS.N = @VidSmetka and VS.SvoService = SS.Svoistvo and SS.Glava = @ServiceNo and SS.SvoKind = 'srv'; if(@NewName is null) then set @NewName=@ArticleName end if; update #VaucherArticles set TranslateName = @NewName,SinglePrice = @Price,GrandTotal = @Total, Currency = @NewCurrency where ArticleNumber = @ArticleNumber end if end for //call RefreshPersentTotal() end //[v. 01.07.05] //[v. 23.05.2003] Jorko //[v. 03.06.2003] Joracio //[v. 28.06.2003] Jorko poveche sezoni se otchitat