First create solution
This commit is contained in:
@@ -0,0 +1,210 @@
|
||||
|
||||
/****** Object: View [dbo].[vv_GLAccountRowsforBookEntry] Script Date: 05/18/2012 09:18:32 ******/
|
||||
SET ANSI_NULLS ON
|
||||
GO
|
||||
|
||||
SET QUOTED_IDENTIFIER ON
|
||||
GO
|
||||
|
||||
|
||||
|
||||
|
||||
CREATE VIEW [dbo].[vv_GLAccountRowsforBookEntry]
|
||||
AS
|
||||
SELECT 1 PartnerType,
|
||||
0 GLRowsTypeVAT,
|
||||
t1.Oid Oid,
|
||||
t2.CustomersFrom CustomersFrom,
|
||||
t2.Customers Customers,
|
||||
t2.F_DateExecution DateExecution,
|
||||
t2.DocumentNumber DocumentNumber,
|
||||
t2.RegistryNumber RegistryNumber,
|
||||
CASE WHEN isnull(t1.IsReinvoice,0)=0 THEN t8.ChartOfAccounts
|
||||
ELSE t8.ChartOfAccounts2
|
||||
END DebitChartOfAccounts,
|
||||
t9.ChartOfAccountsIn CreditChartOfAccounts,
|
||||
t1.Controlling Controlling,
|
||||
t1.JobNumberObjects JobNumberObjects,
|
||||
t7.UniqueObjects UniqueObjects,
|
||||
t1.CostPlace CostPlace,
|
||||
t1.CostHolder CostHolder,
|
||||
t2.F_CurrencyRate CurrencyRate,
|
||||
t1.Amount AmountHUF,
|
||||
CASE WHEN t2.F_CurrencyRate<>0 and t6.ShortName<>'HUF' THEN ROUND(t1.Amount/t2.F_CurrencyRate,2) ELSE 0 END AmountDEV,
|
||||
t2.ShortName Note1,
|
||||
'' Note2,
|
||||
NULL VAT,
|
||||
t1.ChartofAccounts ChartOfAccounts2,
|
||||
isnull(t1.IsReinvoice,0) IsReinvoice,
|
||||
t1.ContractRows ContractRows,
|
||||
isnull(t1.F_ReadyforBookEntryRows,0) ReadyforBookEntryRows,
|
||||
t2.Oid RegistryHeader,
|
||||
Null InvoiceHeader,
|
||||
t2.CurrentWorkflowSystemSteps WorkflowSystemSteps,
|
||||
t1.WorkflowMessage WorkflowMessage
|
||||
from RegistryRowsFinancialControlling t1 join RegistryHeader t2 on
|
||||
t1.RegistryHeader=t2.Oid LEFT JOIN Controlling t3 ON
|
||||
t1.Controlling=t3.Oid LEFT JOIN Customers t4 ON
|
||||
t2.Customers=t4.Oid LEFT JOIN CustomersGLParameters t5 ON
|
||||
t4.CustomersGLParameters=t5.Oid LEFT JOIN CurrencyName t6 ON
|
||||
t2.F_CurrencyName=t6.Oid LEFT JOIN ContractRows t7 ON
|
||||
t1.ContractRows=t7.Oid left join ControllingYear t8 on
|
||||
t3.Oid=t8.Controlling and Year(t2.F_DateExecution)=t8.AccountYear left join CustomersGLParametersYear t9 on
|
||||
t5.Oid=t9.CustomersGLParameters and Year(t2.F_DateExecution)=t9.AccountYear
|
||||
WHERE t1.GCRecord IS NULL AND
|
||||
isnull(t2.IsEditable,0)=0 AND
|
||||
t2.F_GLAccounts IS NULL AND
|
||||
isnull(t1.F_ReadyforBookEntryRows,0)=0
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT 1 PartnerType,
|
||||
1 GLRowsTypeVAT,
|
||||
t1.Oid Oid,
|
||||
t2.CustomersFrom CustomersFrom,
|
||||
t2.Customers Customers,
|
||||
isnull(isnull(t1.DateVAT,t2.F_DateVAT),t2.F_DateExecution) DateExecution,
|
||||
t2.DocumentNumber DocumentNumber,
|
||||
t2.RegistryNumber RegistryNumber,
|
||||
t7.ChartOfAccountsIn DebitChartOfAccounts,
|
||||
case when ISNULL(t3.InversState,0)=1 then t7.ChartOfAccountsOut
|
||||
else t9.ChartOfAccountsIn end CreditChartOfAccounts,
|
||||
NULL Controlling,
|
||||
NULL JobNumberObjects,
|
||||
NULL UniqueObjects,
|
||||
NULL CostPlace,
|
||||
NULL CostHolder,
|
||||
1 CurrencyRate,
|
||||
CASE WHEN t1.VAT IS NULL THEN 0
|
||||
WHEN t1.VAT IS NOT NULL THEN
|
||||
case when t3.InversState=0 then ROUND(t1.BruttoAmount/(1+t3.KeyValue)*t3.KeyValue,0)
|
||||
else ROUND(t1.BruttoAmount/(1+t3.InversKeyValue)*t3.InversKeyValue,0) end
|
||||
END AmountHUF,
|
||||
0 AmountDEV,
|
||||
t2.ShortName Note1,
|
||||
'' Note2,
|
||||
t1.VAT VAT,
|
||||
NULL ChartOfAccounts2,
|
||||
0 IsReinvoice,
|
||||
NULL ContractRows,
|
||||
isnull(t1.F_ReadyforBookEntryRows,0) ReadyforBookEntryRows,
|
||||
t2.Oid RegistryHeader,
|
||||
NULL InvoiceHeader,
|
||||
t2.CurrentWorkflowSystemSteps WorkflowSystemSteps,
|
||||
'' WorkflowMessage
|
||||
from RegistryRowsFinancial t1 join RegistryHeader t2 on
|
||||
t1.RegistryHeader=t2.Oid LEFT JOIN VAT t3 ON
|
||||
t1.VAT=t3.oid LEFT JOIN Customers t4 ON
|
||||
t2.Customers=t4.Oid LEFT JOIN CustomersGLParameters t5 ON
|
||||
t4.CustomersGLParameters=t5.Oid LEFT JOIN CurrencyName t6 ON
|
||||
t2.F_CurrencyName=t6.Oid left join VATYear t7 on
|
||||
t3.Oid=t7.VAT and Year(t2.F_DateExecution)=t7.AccountYear left join CustomersGLParametersYear t9 on
|
||||
t5.Oid=t9.CustomersGLParameters and Year(t2.F_DateExecution)=t9.AccountYear
|
||||
WHERE t1.GCRecord IS NULL AND
|
||||
isnull(t2.IsEditable,0)=0 AND
|
||||
t2.F_GLAccounts IS NULL AND
|
||||
isnull(t1.F_ReadyforBookEntryRows,0)=0
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT 0 PartnerType,
|
||||
0 GLRowsTypeVAT,
|
||||
t1.Oid Oid,
|
||||
t2.CustomersFrom CustomersFrom,
|
||||
t2.Customers Customers,
|
||||
t2.DateExecution DateExecution,
|
||||
t2.DocumentNumber DocumentNumber,
|
||||
'' RegistryNumber,
|
||||
t11.ChartOfAccountsOut DebitChartOfAccounts,
|
||||
isnull(t12.ChartOfAccounts,t10.ChartOfAccounts) CreditChartOfAccounts,
|
||||
isnull(t8.Controlling,t1.Controlling) Controlling,
|
||||
isnull(t8.JobNumberObjects,t1.JobNumberObjects) JobNumberObjects,
|
||||
isnull(t8.UniqueObjects,t1.UniqueObjects) UniqueObjects,
|
||||
isnull(t8.CostPlace,t1.CostPlace) CostPlace,
|
||||
isnull(t8.CostHolder,t1.CostHolder) CostHolder,
|
||||
t2.CurrencyRate CurrencyRate,
|
||||
(t1.ListPriceHUF-t1.DiscountPriceHUF)*t1.QTT AmountHUF,
|
||||
(t1.ListPriceDEV-t1.DiscountPriceDEV)*t1.QTT AmountDEV,
|
||||
t2.Description Note1,
|
||||
'' Note2,
|
||||
NULL VAT,
|
||||
t1.ChartofAccounts ChartOfAccounts2,
|
||||
0 IsReinvoice,
|
||||
t1.ContractRows ContractRows,
|
||||
isnull(t1.ReadyforBookEntryRows,0) ReadyforBookEntryRows,
|
||||
NULL RegistryHeader,
|
||||
t2.Oid InvoiceHeader,
|
||||
t1.WorkflowSystemSteps WorkflowSystemSteps,
|
||||
'' WorkflowMessage
|
||||
FROM InvoiceRows t1 JOIN InvoiceHeader t2 ON
|
||||
t1.InvoiceHeader=t2.Oid LEFT JOIN Controlling t3 ON
|
||||
t1.Controlling=t3.Oid LEFT JOIN Customers t4 ON
|
||||
t2.Customers=t4.Oid LEFT JOIN CustomersGLParameters t5 ON
|
||||
t4.CustomersGLParameters=t5.Oid LEFT JOIN CurrencyName t6 ON
|
||||
t2.CurrencyName=t6.Oid LEFT JOIN InvoiceType t7 ON
|
||||
t2.InvoiceType=t7.Oid LEFT JOIN ContractRows t8 ON
|
||||
t1.ContractRows=t8.Oid LEFT JOIN Controlling t9 ON
|
||||
t8.Controlling=t9.Oid left join ControllingYear t10 on
|
||||
t3.Oid=t10.Controlling and Year(t2.DateExecution)=t10.AccountYear left join CustomersGLParametersYear t11 on
|
||||
t5.Oid=t11.CustomersGLParameters and Year(t2.DateExecution)=t11.AccountYear left join ControllingYear t12 on
|
||||
t9.Oid=t12.Controlling and Year(t2.DateExecution)=t12.AccountYear
|
||||
WHERE t1.GCRecord IS NULL AND
|
||||
isnull(t2.IsEditable,0)=0 AND
|
||||
t2.GLAccounts IS NULL AND
|
||||
isnull(t1.ReadyforBookEntryRows,0)=0 AND
|
||||
t7.InvoiceTypeBase in (1,2,3) and
|
||||
isnull(t2.IsProforma,0)=0
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT 0 PartnerType,
|
||||
1 GLRowsTypeVAT,
|
||||
t1.Oid Oid,
|
||||
t2.CustomersFrom CustomersFrom,
|
||||
t2.Customers Customers,
|
||||
t2.DateExecution DateExecution,
|
||||
t2.DocumentNumber DocumentNumber,
|
||||
'' RegistryNumber,
|
||||
t9.ChartOfAccountsOut DebitChartOfAccounts,
|
||||
t7.ChartOfAccountsOut CreditChartOfAccounts,
|
||||
NULL Controlling,
|
||||
NULL JobNumberObjects,
|
||||
NULL UniqueObjects,
|
||||
NULL CostPlace,
|
||||
NULL CostHolder,
|
||||
1 CurrencyRate,
|
||||
t1.AmountVATHUF AmountHUF,
|
||||
t1.AmountVATDEV AmountDEV,
|
||||
t2.Description Note1,
|
||||
'' Note2,
|
||||
t1.VAT VAT,
|
||||
NULL ChartOfAccounts2,
|
||||
0 IsReinvoice,
|
||||
NULL ContractRows,
|
||||
isnull(t1.ReadyforBookEntryRows,0) ReadyforBookEntryRows,
|
||||
NULL RegistryHeader,
|
||||
t2.Oid InvoiceHeader,
|
||||
Null WorkflowSystemSteps,
|
||||
'' WorkflowMessage
|
||||
from InvoiceVATRows t1 join InvoiceHeader t2 on
|
||||
t1.InvoiceHeader=t2.Oid LEFT JOIN VAT t3 ON
|
||||
t1.VAT=t3.oid LEFT JOIN Customers t4 ON
|
||||
t2.Customers=t4.Oid LEFT JOIN CustomersGLParameters t5 ON
|
||||
t4.CustomersGLParameters=t5.Oid LEFT JOIN CurrencyName t6 ON
|
||||
t2.CurrencyName=t6.Oid LEFT JOIN InvoiceType t10 ON
|
||||
t2.InvoiceType=t10.Oid left join VATYear t7 on
|
||||
t3.Oid=t7.VAT and Year(t2.DateExecution)=t7.AccountYear left join CustomersGLParametersYear t9 on
|
||||
t5.Oid=t9.CustomersGLParameters and Year(t2.DateExecution)=t9.AccountYear
|
||||
WHERE t1.GCRecord IS NULL AND
|
||||
isnull(t2.IsEditable,0)=0 AND
|
||||
t2.GLAccounts IS NULL AND
|
||||
isnull(t1.ReadyforBookEntryRows,0)=0 AND
|
||||
isnull(t2.IsProforma,0)=0 AND
|
||||
t10.InvoiceTypeBase in (1,2,3) --and
|
||||
--t2.GLAccounts is null
|
||||
|
||||
|
||||
|
||||
|
||||
GO
|
||||
|
||||
Reference in New Issue
Block a user