IF (EXISTS(Select * from sys.sysprocedure where LCase(proc_name) = LCase('TaxableArticles')))
THEN Drop procedure TaxableArticles
END IF

GO

create procedure DBA.TaxableArticles()
// 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,vr.Rate as @VatRate from #Articles as A,Services as S join VATRates as VR on Services.VatRateN = VR.ID,VidSdelki as V
      where A.ServiceNo = S.ServiceNo and S.TipSdelka = V.N and V.TipDDS <> 3 do
    update #Articles set ArticleSum = (ArticleQty*ArticlePrice/(1+@VatRate))*(100-Discount)/100,TipDDS = 2,
      ArticlePrice = ArticlePrice/(1+@VatRate) where ArticleNumber = @ArticleNo
  end for
end