ALTER VIEW "DBA"."v_ProdajbiPoUslugi" as select OtchetNumber=GetOtchetNumber(ART.InvoiceNo), SmetkaNo=ART.InvoiceNo, FakturaNo=if((INV.TrueInvoiceNo<>0) and(INV.TrueInvoiceNo<1000000000)) then INV.MaskaFaktura||substr('0000000000',1,9-length(INV.TrueInvoiceNo))||INV.TrueInvoiceNo endif, DokData=INV.InvoiceDateDt, Service=Services.ServiceName, /*Kol=if INV.CancelInvoiceNo>0 then(-1)*ART.Qty else ART.Qty endif,*/ /*Kol=if (ART.totalsum < 0 ) then ((-1)*ART.Qty) else ART.Qty endif,*/ Kol=if(ART.totalsum>0) then ART.Qty else if(ART.Qty<0) then ART.Qty else // Yanko + // dobaveno, za da ne se pokazva "-" pred kolichestvoto, ako kol.>0, a cenata e 0 // ((-1)*ART.Qty) if (ART.Totalsum=0) then ART.QTY else ((-1)*ART.Qty) endif // Yanko - endif endif, EdCena=round(abs(ART.Price)*(1+bvrDDSPart*(if TipDDS=2 then 1 else 0 endif)),4), Stoinost=round(Kol*EdCena,4), StoinostBDDS=round(Kol*abs(ART.Price),4), Discount=ART.Discount, EdCenaWithDisc=round(CalcPriceWithDiscount(Discount,EdCena),4), StoinostWithDisc=round(Kol*EdCenaWithDisc,4), Klient=INV.Whom, DanNo=INV.WhomDanNum, GuestNum=G.GuestNum, GuestName=G."Name", Komentar=String(DateRegDt,' - ',"Date"(Days(DateRegDt,NumLodgings))), Operator=ADMIN.ShortName, ContractName=(if(Inv.ContractNo<>0) then (select CC.ShortName from "dba".Contracts as CC where CC.ContractNo=Inv.ContractNo) else Contracts.ShortName endif), Country=Countries.Description, Nationality=HK.Description, RoomNo=convert(varchar,BK.Room) from "DBA".Articles as ART,"dba".Services,"DBA".Invoices as INV,"DBA".Book as BK,"DBA".Guests as G ,"dba".Admin as ADMIN,"dba".Contracts,"dba".Countries,"dba".HumanKinds as HK where ART.InvoiceNo=INV.InvoiceNo and Abs(RegNo)=BK.RegNum and BK.RegNum<>0 and INV.InvoiceDateDt>=bvrData1 and INV.InvoiceDateDt<=bvrData2 and BK.Guest=G.GuestNum and INV.KodAdmin=ADMIN.AdminNo and ART.ServiceNo=Services.ServiceNo and G.Contract=Contracts.ContractNo and G.HumanKind=HK.HumanKindNo and G.NativeCountry=Countries.CountryKod union all select OtchetNumber=GetOtchetNumber(ART.InvoiceNo), SmetkaNo=ART.InvoiceNo, FakturaNo=if((INV.TrueInvoiceNo<>0) and(INV.TrueInvoiceNo<1000000000)) then INV.MaskaFaktura||substr('0000000000',1,9-length(INV.TrueInvoiceNo))||INV.TrueInvoiceNo endif, DokData=INV.InvoiceDateDt, Service=Services.ServiceName, Kol=if INV.CancelInvoiceNo>0 then(-1)*ART.Qty else ART.Qty endif, EdCena=round(abs(ART.Price)*(1+bvrDDSPart*(if ART.TipDDS=2 then 1 else 0 endif)),4), Stoinost=round(Kol*EdCena,4), StoinostBDDS=round(Kol*abs(ART.Price),4), Discount=ART.Discount, EdCenaWithDisc=round(CalcPriceWithDiscount(Discount,EdCena),4), StoinostWithDisc=round(Kol*EdCenaWithDisc,4), Klient=INV.Whom, DanNo=INV.WhomDanNum, GuestNum=G.GuestNum, GuestName=G."Name",Komentar='', Operator=ADMIN.ShortName, ContractName=(if(Inv.ContractNo<>0) then (select CC.ShortName from "dba".Contracts as CC where CC.ContractNo=Inv.ContractNo) else Contracts.ShortName endif), Country=Countries.Description, Nationality=HK.Description, RoomNo=(if(G.GuestNum<>0) then convert(varchar,(select distinct LastRoom from "dba".v_ArriveStayLeaveGuestBook where GuestNum=G.GuestNum)) else null endif) /* RoomNo=(if(G.GuestNum<>0) then convert(varchar,(select distinct Max(B.Room) from "dba".Book as B,"dba".Guests as G where B.WhoPays=G.GuestNum and INV.Whom=G."Name" and G.GuestNum<>0)) else null endif)*/ from "DBA".Articles as ART,"dba".Services,"DBA".Invoices as INV,"DBA".ServiceCredits as SC,"DBA".Guests as G ,"dba".Admin as ADMIN,"dba".Contracts,"dba".Countries,"dba".HumanKinds as HK where ART.InvoiceNo=INV.InvoiceNo and ART.CreditNo=SC.CreditNo and ART.CreditNo<>0 and SC.GuestNo=G.GuestNum and INV.KodAdmin=ADMIN.AdminNo and INV.InvoiceDateDt>=bvrData1 and INV.InvoiceDateDt<=bvrData2 /* and ART.ServiceNo not in(1004,1005)*/ and ART.ServiceNo=Services.ServiceNo and G.Contract=Contracts.ContractNo and G.NativeCountry=Countries.CountryKod and G.HumanKind=HK.HumanKindNo union all select OtchetNumber=GetOtchetNumber(ART.InvoiceNo), SmetkaNo=ART.InvoiceNo, FakturaNo=if((max(INV.TrueInvoiceNo)<>0) and(max(INV.TrueInvoiceNo)<1000000000)) then max(INV.MaskaFaktura)||substr('0000000000',1,9-length(max(INV.TrueInvoiceNo)))||max(INV.TrueInvoiceNo) endif, DokData=Max(INV.InvoiceDateDt), Service=Max(Services.ServiceName), Kol=if INV.CancelInvoiceNo>0 then(-1)*max(ART.Qty) else max(ART.Qty) endif, EdCena=round(Max(abs(ART.Price)*(1+bvrDDSPart*(if ART.TipDDS=2 then 1 else 0 endif))),4), Stoinost=round(Kol*EdCena,4), StoinostBDDS=round(Kol*Max(abs(ART.Price)),4), Discount=ART.Discount, EdCenaWithDisc=round(CalcPriceWithDiscount(Discount,EdCena),4), StoinostWithDisc=round(Kol*EdCenaWithDisc,4), Klient=Max(INV.Whom), DanNo=Max(INV.WhomDanNum), GuestNum=Max(RM.GuestNo), GuestName=Max(G."Name"),Komentar='', Operator=Max(ADMIN.ShortName), ContractName=Max(if(Inv.ContractNo<>0) then (select CC.ShortName from "dba".Contracts as CC where CC.ContractNo=Inv.ContractNo) else Contracts.ShortName endif), Country=Max(Countries.Description), Nationality=Max(HK.Description), RoomNo=max(if(G.GuestNum<>0) then convert(varchar,(select distinct LastRoom from "dba".v_ArriveStayLeaveGuestBook where GuestNum=G.GuestNum)) else null endif) /* RoomNo=Max((if(G.GuestNum<>0) then convert(varchar,(select distinct Max(B.Room) from "dba".Book as B,"dba".Guests as G where B.WhoPays=G.GuestNum and INV.Whom=G."Name" and G.GuestNum<>0)) else null endif))*/ from "DBA".Articles as ART,"dba".Services,"DBA".Invoices as INV,"dba".Guests as G ,"dba".Admin as ADMIN,"dba".Contracts,"dba".Countries,"dba".ResMoney as RM,"dba".HumanKinds as HK where ART.InvoiceNo=INV.InvoiceNo and ART.CreditNo=0 and ART.RegNo=0 and RM.InvoiceNo=INV.InvoiceNo and G.GuestNum=RM.GuestNo and INV.InvoiceDateDt>=bvrData1 and INV.InvoiceDateDt<=bvrData2 and G.Contract=Contracts.ContractNo and G.NativeCountry=Countries.CountryKod and INV.KodAdmin=ADMIN.AdminNo and ART.ServiceNo=Services.ServiceNo and G.HumanKind=HK.HumanKindNo and ART.ServiceNo in(1004,1005) group by ART.InvoiceNo,ART.ArticleNo,INV.CancelInvoiceNo,Discount /*[v 01.06.29]*/ //[v 27.01.2003] niky dobaven e filtyr za smetki po dogovor za da pokazva imeto na dogovora ako ima takiva //[v 03.04.2003] Jorko opraveni kolichestvata pri anuliranite smetki //[v 16.12.2003] Jorko //[v 16.07.2004] Jorko //[v 16.07.2004] Jorko Mahnah GuestNo<>0 ot poslednia select //[v 11.02.2005] Jorko and ART.CreditNo<>0 i and BK.RegNum<>0 v razlichnite selecti //[v 31.03.2005] Safa modify Kol, Edcena //[v 12.05.2005] Jorko komentar na reda /* and ART.ServiceNo not in(1004,1005)*/ //[v 17.08.2006] Yanko, modify Kol