if (select count(*) from VidSmetki where SmetkaIme='Опростена Сметка договор-ваучер')=0 then insert into VidSmetki(N,SmetkaIme,KodCurrency,SmetkaFile,IsFaktura,SvoService,TextPrint,SlujSmetka,Language) values (100,'Опростена Сметка договор-ваучер',1,'OprFaktura.qri', 1,0,0,4,0) end if; GO IF (EXISTS (select proc_name from sysprocedure where LCase(proc_name)=LCase('VTDTaxableArticles'))) THEN Drop procedure VTDTaxableArticles END IF GO CREATE PROCEDURE "DBA"."VTDTaxableArticles"() // Tazi procedure se vika ot formata za smetki kato se uncheckne Neoblagaema stojnost // za da promeni TipDDS na uslugite, koito sa oblagaemi begin for f as curs scroll cursor for select A.ArticleNumber as @ArticleNo from #VaucherArticles as A,Services as S,VidSdelki as V where A.ServiceNo=S.ServiceNo and S.TipSdelka=V.N do update #VaucherArticles set GrandTotal=(TotalNights*SinglePrice/(1.07))*(100-Discount)/100, SinglePrice=SinglePrice/(1.07) where ArticleNumber=@ArticleNo and RowType=1; update #VaucherArticles set GrandTotal=(GrandTotal/(1.07)) where ArticleNumber=@ArticleNo and SinglePrice=0 and RowType=2; update #VaucherArticles set GrandTotal=(GrandTotal/(1.07))*(100-Discount)/100, SinglePrice=SinglePrice/(1.07) where ArticleNumber=@ArticleNo and RowType=2 and SinglePrice<>0; end for; update #VaucherArticles set GrandTotal=(GrandTotal/(1.07)) where RowType in (3,4,5); end