if (select count(*) from "DBA".PermissionTypes where Name='Експорт към Конто') = 0 then Delete from "DBA".PermissionTypes Where N=5200; Insert Into "DBA".PermissionTypes Values(5200,'Експорт към Конто',1); Delete from "DBA".PermissionTags Where TagNo=5200; Insert Into "DBA".PermissionTags Values(5200,5200,'Експорт към Конто'); Delete from "DBA".Permissions Where PermissionNo=5200; for f1 as curs scroll cursor for Select N from AdminGroups do if N=1 then Insert Into "DBA".Permissions Values(N,5200,0) //Admin else Insert Into "DBA".Permissions Values(N,5200,1) //ostanalite niamat prava end if; end for; end if; Go if (Select Count(*) from "DBA".SvoServices where Ime='Код обект')=0 then Insert Into "DBA".SvoServices Values((Select Max(N) from SvoServices)+1,'Код обект', 'Код сметка за обект при Експорт по обекти; Ако свойството не е зададено се подразбира 7021. (пример: 7031 за SPA)','T','',10,''); end if; Go if exists (select * from systable where lcase(table_name)=lcase('v_ExportKonto')) then drop view v_ExportKonto end if Go create view v_ExportKonto as select NN=I.InvoiceNo, VidClient=I.VidSmetka, PL_KOD=I.PayHow, NOMER_DO=1, VID_OSN=if I.VidSmetka=2 then 901 else if I.VidSmetka=7 then 926 else 0 endif endif, NOM_OSN=AlignRightStr(convert(integer,I.TrueInvoiceNo),10,'0'), KOD_OP=3, DATA_OSN=DATEFORMAT(I.TrueInvoiceDate,'DD.MM.YYYY'), SumaDDS=Round(I.VAT,2), SumaAll=Round(I.GrandTotal,2), SumaBezDDS=Round(I.TotalNoVAT,2), PARTIDA=if LENGTH(TRIM(I.Bulstat))<13 then AlignLeftStr(TRIM(I.Bulstat),13,'0') else TRIM(I.Bulstat) endif||NOM_OSN, KEY_L=LENGTH(PARTIDA), SKLAD=0 from "DBA".Invoices as I where I.InvoiceType=2 and (I.VidSmetka in (2,7)) and I.TrueInvoiceDate>=bvrData1 and I.TrueInvoiceDate<=bvrData2 union all select NN=I.InvoiceNo, VidClient=I.VidSmetka, PL_KOD=I.PayHow, NOMER_DO=1, VID_OSN=if I.VidSmetka=2 then 901 else if I.VidSmetka=7 then 926 else 0 endif endif, NOM_OSN=AlignRightStr(convert(integer,I.TrueInvoiceNo),10,'0'), KOD_OP=3, DATA_OSN=DATEFORMAT(I.TrueInvoiceDate,'DD.MM.YYYY'), SumaDDS=Round(I.VAT,2), SumaAll=Round(I.GrandTotal,2), SumaBezDDS=Round(I.TotalNoVAT,2), PARTIDA=if LENGTH(TRIM(I.Bulstat))<13 then AlignLeftStr(TRIM(I.Bulstat),13,'0') else TRIM(I.Bulstat) endif||NOM_OSN, KEY_L=LENGTH(PARTIDA), SKLAD=0 from "DBA".SpaInvoices as I where I.InvoiceType=2 and (I.VidSmetka in (2,7)) and I.TrueInvoiceDate>=bvrData1 and I.TrueInvoiceDate<=bvrData2 union all select NN=0, VidClient=0, PL_KOD=0, NOMER_DO=1, VID_OSN=928, NOM_OSN=AlignRightStr('0',10,'0'), KOD_OP=3, DATA_OSN=DATEFORMAT(bvrData2,'DD.MM.YYYY'), SumaDDS=(Select Round(Sum(VAT),2) from Invoices where VidSmetka=1 and InvoiceDateDt>=bvrData1 and InvoiceDateDt<=bvrData2) +(Select Round(Sum(VAT),2) from SpaInvoices where VidSmetka=1 and InvoiceDateDt>=bvrData1 and InvoiceDateDt<=bvrData2), SumaAll=(Select Round(Sum(GrandTotal),2) from Invoices where VidSmetka=1 and InvoiceDateDt>=bvrData1 and InvoiceDateDt<=bvrData2) +(Select Round(Sum(GrandTotal),2) from SpaInvoices where VidSmetka=1 and InvoiceDateDt>=bvrData1 and InvoiceDateDt<=bvrData2), SumaBezDDS=SumaAll-SumaDDS, PARTIDA='', KEY_L=0, SKLAD=0 // [v 04.Sep.2006] Yanko, ostavil sam niakoi izlishni poleta, samo za da sa ednakvi imenata na poletata s // analogichnoto View v Riscont, i da ne se promeniat Fields na tablicite vav formite Go if exists (select * from systable where lcase(table_name)=lcase('v_ExportKontoRedove')) then drop view v_ExportKontoRedove end if Go Create View "DBA".v_ExportKontoRedove as select InvoiceNo=I.InvoiceNo, VidSmetka=I.VidSmetka, ServiceNo=S.ServiceNo, ServiceName=S.ServiceName, SvoistvoNo=(Select N from SvoServices where Ime='Код обект'), // 7021 e kod smetka za obekt po podrazbirane (kogato ne e zadadeno svoistvo 'Kod obekt') Obekt=IsNull((Select Stoinost from SvoServicesStn where Glava=ServiceNo and Svoistvo=SvoistvoNo),'7021'), SumAll=A.TotalSum from "DBA".Services as S, Invoices as I, Articles as A where A.InvoiceNo = I.InvoiceNo and S.ServiceNo = A.ServiceNo and I.InvoiceDateDt>=bvrData1 and I.InvoiceDateDt<=bvrData2 union all select InvoiceNo=I.InvoiceNo, VidSmetka=I.VidSmetka, ServiceNo=S.ServiceNo, ServiceName=S.ServiceName, SvoistvoNo=(Select N from SvoServices where Ime='Код обект'), Obekt=IsNull((Select Stoinost from SvoServicesStn where Glava=ServiceNo and Svoistvo=SvoistvoNo),'7021'), SumAll=A.TotalSum from "DBA".Services as S, SpaInvoices as I, SpaArticles as A where A.InvoiceNo = I.InvoiceNo and S.ServiceNo = A.ServiceNo and I.InvoiceDateDt>=bvrData1 and I.InvoiceDateDt<=bvrData2 // [v 04.Sep.2006] Yanko