First create solution

This commit is contained in:
2017-03-08 11:21:27 +01:00
commit a2fb86bacf
5508 changed files with 1082238 additions and 0 deletions
@@ -0,0 +1,185 @@
DROP TABLE IF EXISTS vv_GLAccountRowsforBookEntry;
DROP VIEW IF EXISTS vv_GLAccountRowsforBookEntry;
CREATE VIEW 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 ifnull(t1.IsReinvoice,0)=0 THEN t3.ChartOfAccounts
ELSE t3.ChartOfAccounts2
END DebitChartOfAccounts,
t5.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,
ifnull(t1.IsReinvoice,0) IsReinvoice,
t1.ContractRows ContractRows,
ifnull(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
WHERE t1.GCRecord IS NULL AND
ifnull(t2.IsEditable,0)=0 AND
t2.F_GLAccounts IS NULL AND
ifnull(t1.F_ReadyforBookEntryRows,0)=0
UNION ALL
SELECT 1 PartnerType,
1 GLRowsTypeVAT,
t1.Oid Oid,
t2.CustomersFrom CustomersFrom,
t2.Customers Customers,
ifnull(ifnull(t1.DateVAT,t2.F_DateVAT),t2.F_DateExecution) DateExecution,
t2.DocumentNumber DocumentNumber,
t2.RegistryNumber RegistryNumber,
t3.ChartOfAccountsIn DebitChartOfAccounts,
case when ifnull(t3.InversState,0)=1 then t3.ChartOfAccountsOut
else t5.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*t3.InversKeyValue,0) end
END AmountHUF,
0 AmountDEV,
t2.ShortName Note1,
'' Note2,
t1.VAT VAT,
NULL ChartOfAccounts2,
0 IsReinvoice,
NULL ContractRows,
ifnull(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
WHERE t1.GCRecord IS NULL AND
ifnull(t2.IsEditable,0)=0 AND
t2.F_GLAccounts IS NULL AND
ifnull(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,
t5.ChartOfAccountsOut DebitChartOfAccounts,
ifnull(t9.ChartOfAccounts,t3.ChartOfAccounts) CreditChartOfAccounts,
ifnull(t8.Controlling,t1.Controlling) Controlling,
ifnull(t8.JobNumberObjects,t1.JobNumberObjects) JobNumberObjects,
ifnull(t8.UniqueObjects,t1.UniqueObjects) UniqueObjects,
ifnull(t8.CostPlace,t1.CostPlace) CostPlace,
ifnull(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,
ifnull(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
WHERE t1.GCRecord IS NULL AND
ifnull(t2.IsEditable,0)=0 AND
t2.GLAccounts IS NULL AND
ifnull(t1.ReadyforBookEntryRows,0)=0 AND
t7.InvoiceTypeBase in (1,2,3) and
ifnull(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,
t5.ChartOfAccountsOut DebitChartOfAccounts,
t3.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,
ifnull(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 t7 ON
t2.InvoiceType=t7.Oid
WHERE t1.GCRecord IS NULL AND
ifnull(t2.IsEditable,0)=0 AND
t2.GLAccounts IS NULL AND
ifnull(t1.ReadyforBookEntryRows,0)=0 AND
ifnull(t2.IsProforma,0)=0 AND
t7.InvoiceTypeBase in (1,2,3)
@@ -0,0 +1,83 @@
DROP TABLE IF EXISTS vv_PartnerConnectionInfoAccount;
DROP VIEW IF EXISTS vv_PartnerConnectionInfoAccount;
CREATE view vv_PartnerConnectionInfoAccount
as
select '01-Account' MainType,
t2.Oid Oid,
t2.CustomersFrom CustomersFrom,
t1.Customer Customers,
t1.PartnerType PartnerType,
t2.DocumentNumber ConnectInfo,
t2.CurrencyName CurrencyName,
sum(t1.AmountHUF) BallanceHUF,
sum(t1.AmountDEV) BallanceDEV,
t3.ShortName Currency,
t2.DatePayment DatePayment,
t2.DateCreated DateCreated,
t2.DateExecution DateExecution,
t2.CurrencyRate CurrencyRate,
t2.DocumentNumber DocumentNumber,
max(t2.RegistryNumber) RegistryNumber
from GLRows t1 join GLHeader t2 on
t1.GLHeader=t2.Oid left join CurrencyName t3 on
t2.CurrencyName=t3.Oid
where t2.GCRecord is null and
t2.GLDocumentType=1 and
ifnull(t2.IsEditable,0)=0 and
t1.PartnerType in (0,1) and
t1.GCRecord is null
group by t2.Oid,t2.CustomersFrom,t1.Customer,t1.PartnerType,
t2.DocumentNumber,t2.CurrencyName,t3.ShortName,t2.DateExecution,t2.DatePayment,
t2.DateCreated,t2.DateExecution,t2.CurrencyRate
union all
select '01-Account' MainType,
t1.Oid Oid,
t1.CustomersFrom CustomersFrom,
t1.Customers Customers,
0 PartnerType,
t1.DocumentNumber ConnectInfo,
t1.CurrencyName CurrencyName,
t1.TotalBruttoHUF BallanceHUF,
t1.TotalBruttoDEV BallanceDEV,
t3.ShortName Currency,
t1.DatePayment DatePayment,
t1.DateCreated DateCreated,
t1.DateExecution DateExecution,
t1.CurrencyRate CurrencyRate,
t1.DocumentNumber DocumentNumber,
t1.DocumentNumber RegistryNumber
from InvoiceHeader t1 left join CurrencyName t3 on
t1.CurrencyName=t3.Oid
where t1.GLAccounts is null and
t1.IsEditable=0 and
t1.GCRecord is null
union all
select '01-Account' MainType,
t1.Oid Oid,
t1.CustomersFrom CustomersFrom,
t1.Customers Customers,
1 PartnerType,
t1.DocumentNumber ConnectInfo,
t1.F_CurrencyName CurrencyName,
t1.F_AmountBruttoHUF BallanceHUF,
t1.F_AmountBruttoDEV BallanceDEV,
t3.ShortName Currency,
t1.F_DatePayment DatePayment,
t1.F_DateCreated DateCreated,
t1.F_DateExecution DateExecution,
t1.F_CurrencyRate CurrencyRate,
t1.DocumentNumber DocumentNumber,
t1.RegistryNumber RegistryNumber
from RegistryHeader t1 left join RegistryType t2 on
t1.RegistryType=t2.Oid left join CurrencyName t3 on
t1.F_CurrencyName=t3.Oid
where t1.GCRecord is null and
t1.F_GLAccounts is null and
t1.IsEditable=0 and
t1.IsStorno=0 and
t2.RegistryMainType=0 and
t1.RegistryAcceptState=0
@@ -0,0 +1,24 @@
DROP TABLE IF EXISTS vv_PartnerConnectionInfoAged;
DROP VIEW IF EXISTS vv_PartnerConnectionInfoAged;
CREATE view vv_PartnerConnectionInfoAged
as
select t1.Oid Oid,
t1.CustomersFrom CustomersFrom,
t1.Customers Customers,
t1.PartnerType PartnerType,
t1.ConnectInfo ConnectInfo,
t2.DocumentNumber DocumentNumber,
t2.RegistryNumber RegistryNumber,
t1.DateExecution_Account DateExecution,
t1.DatePayment_Account DatePayment,
t1.CurrencyName_Account CurrencyName_Account,
t1.AmountHUF_Account AmountHUF,
t1.AmountDEV_Account AmountDEV,
t1.BallanceHUF BallanceHUF,
t1.BallanceDEV BallanceDEV
from PCIDetail t1 join
vv_PartnerConnectionInfoAccount t2 on
t1.CustomersFrom=t2.CustomersFrom and
t1.Customers=t2.Customers and
t1.PartnerType=t2.PartnerType and
t1.ConnectInfo=t2.ConnectInfo
@@ -0,0 +1,38 @@
DROP TABLE IF EXISTS vv_PartnerConnectionInfoConnect;
DROP VIEW IF EXISTS vv_PartnerConnectionInfoConnect;
CREATE view vv_PartnerConnectionInfoConnect
as
select
t1.MainType MainType,
t1.Oid Oid,
t1.CustomersFrom CustomersFrom,
t1.Customers Customers,
t1.PartnerType PartnerType,
t1.ConnectInfo ConnectInfo,
t1.CurrencyName CurrencyName,
t1.DebitTotalHUF DebitTotalHUF,
t1.CreditTotalHUF CreditTotalHUF,
t1.DebitTotalDEV DebitTotalDEV,
t1.CreditTotalDEV CreditTotalDEV,
t1.BallanceHUF BallanceHUF,
t1.BallanceDEV BallanceDEV,
t1.ShortName ShortName,
t1.Description Description,
t1.DateExecution DateExecution,
t1.DateCreated DateCreated,
t1.DatePayment DatePayment,
t1.DelayedDay DelayedDay,
t1.DelayedRange DelayedRange,
t1.CurrencyName_Account CurrencyName_Account,
t1.AmountHUF_Account AmountHUF_Account,
t1.AmountDEV_Account AmountDEV_Account,
t1.DateExecution_Account DateExecution_Account,
t2.BallanceState BallanceState,
t2.BallanceRateDiff BallanceRateDiff
from vv_PartnerConnectionInfoDetail t1
join vv_PartnerConnectionInfoDetailGroup t2 on
t1.CustomersFrom=t2.CustomersFrom and
t1.Customers=t2.Customers and
t1.PartnerType=t2.PartnerType and
t1.ConnectInfo=t2.ConnectInfo
@@ -0,0 +1,407 @@
DROP TABLE IF EXISTS vv_PartnerConnectionInfoDetail;
DROP VIEW IF EXISTS vv_PartnerConnectionInfoDetail;
CREATE view vv_PartnerConnectionInfoDetail
as
select '01-Account' MainType,
t2.Oid Oid,
t2.CustomersFrom CustomersFrom,
t1.Customer Customers,
t1.PartnerType PartnerType,
t1.ConnectInfo ConnectInfo,
t2.CurrencyName CurrencyName,
max(t3.AmountHUFBrutto) DebitTotalHUF,
0 CreditTotalHUF,
max(t3.AmountDEVBrutto) DebitTotalDEV,
0 CreditTotalDEV,
max(t3.AmountHUFBrutto) BallanceHUF,
max(t3.AmountDEVBrutto) BallanceDEV,
'' ShortName,
'' Description,
t2.DateExecution DateExecution,
t2.DateCreated DateCreated,
t2.DatePayment DatePayment,
DATEDIFF(t2.DatePayment,curdate()) DelayedDay,
case when DATEDIFF(t2.DatePayment,curdate())<=0 then 0
when DATEDIFF(t2.DatePayment,curdate())>0 and DATEDIFF(t2.DatePayment,curdate())<=15 then 1
when DATEDIFF(t2.DatePayment,curdate())>15 and DATEDIFF(t2.DatePayment,curdate())<=30 then 2
when DATEDIFF(t2.DatePayment,curdate())>30 and DATEDIFF(t2.DatePayment,curdate())<=60 then 3
when DATEDIFF(t2.DatePayment,curdate())>60 and DATEDIFF(t2.DatePayment,curdate())<=90 then 4
when DATEDIFF(t2.DatePayment,curdate())>90 and DATEDIFF(t2.DatePayment,curdate())<=180 then 5
when DATEDIFF(t2.DatePayment,curdate())>180 and DATEDIFF(t2.DatePayment,curdate())<=360 then 6
when DATEDIFF(t2.DatePayment,curdate())>360 then 7
end DelayedRange,
t2.CurrencyName CurrencyName_Account,
sum(t1.AmountHUF) AmountHUF_Account,
sum(t1.AmountDEV) AmountDEV_Account,
t2.DateExecution DateExecution_Account
from GLRows t1 join GLHeader t2 on
t1.GLHeader=t2.Oid join GLAccounts t3 on
t1.GLHeader=t3.Oid
where t2.GCRecord is null and
t2.GLDocumentType=1 and
t2.IsEditable=0 and
t1.PartnerType in (0,1) and
t1.GCRecord is null
group by t2.Oid,t2.CustomersFrom,t1.Customer,t1.PartnerType,
t1.ConnectInfo,t2.CurrencyName,t2.DateExecution,t2.DateCreated,t2.DatePayment
union all
select '02-Bank' MainType,
t1.Oid Oid,
t2.CustomersFrom CustomersFrom,
t1.Customer Customers,
t1.PartnerType PartnerType,
t1.ConnectInfo ConnectInfo,
t3.CurrencyName CurrencyName,
0 DebitTotalHUF,
case when t1.PartnerType=0 and sum(t1.InAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountHUF)
when t1.PartnerType=0 and sum(t1.OutAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountHUF)*-1
when t1.PartnerType=1 and sum(t1.OutAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountHUF)
when t1.PartnerType=1 and sum(t1.InAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountHUF)*-1
when t1.PartnerType=0 and sum(t1.InAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.InAmountDEV2)
when t1.PartnerType=0 and sum(t1.OutAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.OutAmountDEV2)*-1
when t1.PartnerType=1 and sum(t1.OutAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.OutAmountDEV2)
when t1.PartnerType=1 and sum(t1.InAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.InAmountDEV2)*-1
end CreditTotalHUF,
0 DebitTotalDEV,
case when t1.PartnerType=0 and sum(t1.InAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountDEV)
when t1.PartnerType=0 and sum(t1.OutAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountDEV)*-1
when t1.PartnerType=1 and sum(t1.OutAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountDEV)
when t1.PartnerType=1 and sum(t1.InAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountDEV)*-1
when t1.PartnerType=0 and sum(t1.InAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.InAmountDEV2)
when t1.PartnerType=0 and sum(t1.OutAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.OutAmountDEV2)*-1
when t1.PartnerType=1 and sum(t1.OutAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.OutAmountDEV2)
when t1.PartnerType=1 and sum(t1.InAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.InAmountDEV2)*-1
end CreditTotalDEV,
(case when t1.PartnerType=0 and sum(t1.InAmountHUF)<>0 then sum(t1.AmountHUF)
when t1.PartnerType=0 and sum(t1.OutAmountHUF)<>0 then sum(t1.AmountHUF)*-1
when t1.PartnerType=1 and sum(t1.OutAmountHUF)<>0 then sum(t1.AmountHUF)
when t1.PartnerType=1 and sum(t1.InAmountHUF)<>0 then sum(t1.AmountHUF)*-1
end)*-1 BallanceHUF,
(case when t1.PartnerType=0 and sum(t1.InAmountDEV)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.InAmountDEV)
when t1.PartnerType=0 and sum(t1.OutAmountDEV)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.OutAmountDEV)*-1
when t1.PartnerType=1 and sum(t1.OutAmountDEV)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.OutAmountDEV)
when t1.PartnerType=1 and sum(t1.InAmountDEV)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.InAmountDEV)*-1
when t1.PartnerType=0 and sum(t1.InAmountDEV2)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName and t4.Currency<>'HUF' then sum(t1.InAmountDEV2)
when t1.PartnerType=0 and sum(t1.OutAmountDEV2)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName and t4.Currency<>'HUF' then sum(t1.OutAmountDEV2)*-1
when t1.PartnerType=1 and sum(t1.OutAmountDEV2)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName and t4.Currency<>'HUF' then sum(t1.OutAmountDEV2)
when t1.PartnerType=1 and sum(t1.InAmountDEV2)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName and t4.Currency<>'HUF'then sum(t1.InAmountDEV2)*-1
else 0
end)*-1 BallanceDEV,
max(t3.ShortName+', '+ifnull(t2.DocumentNumber,'')) ShortName,
'' Description,
t2.DateExecution DateExecution,
t2.DateExecution DateCreated,
t4.DatePayment DatePayment,
0 DelayedDay,
'' DelayedRange,
t4.CurrencyName CurrencyName_Account,
0 AmountHUF_Account,
0 AmountDEV_Account,
max(t4.DateExecution) DateExecution_Account
from GLRows t1
join GLHeader t2 on t1.GLHeader=t2.Oid
left join GLBank t5 on t2.Oid=t5.Oid
left join LiquidAssets t3 on t5.LiquidAssets_Main=t3.Oid
left join vv_PartnerConnectionInfoAccount t4 on t2.CustomersFrom=t4.CustomersFrom
and t1.Customer=t4.Customers and t1.PartnerType=t4.PartnerType and t1.ConnectInfo=t4.ConnectInfo
where t2.GCRecord is null and
t2.GLDocumentType=2 and
t1.PartnerType in (0,1) and
t1.GCRecord is null
group by t1.Oid,t2.CustomersFrom,t1.Customer,t1.PartnerType,
t1.ConnectInfo,t3.CurrencyName,t4.Currency,t2.DateExecution,t4.DatePayment,t4.CurrencyName
union all
select '03-Cassa' MainType,
t1.Oid Oid,
t2.CustomersFrom CustomersFrom,
t1.Customer Customers,
t1.PartnerType PartnerType,
t1.ConnectInfo ConnectInfo,
t3.CurrencyName CurrencyName,
0 DebitTotalHUF,
case when t1.PartnerType=0 and sum(t1.InAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountHUF)
when t1.PartnerType=0 and sum(t1.OutAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountHUF)*-1
when t1.PartnerType=1 and sum(t1.OutAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountHUF)
when t1.PartnerType=1 and sum(t1.InAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountHUF)*-1
when t1.PartnerType=0 and sum(t1.InAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.InAmountDEV2)
when t1.PartnerType=0 and sum(t1.OutAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.OutAmountDEV2)*-1
when t1.PartnerType=1 and sum(t1.OutAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.OutAmountDEV2)
when t1.PartnerType=1 and sum(t1.InAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.InAmountDEV2)*-1
end CreditTotalHUF,
0 DebitTotalDEV,
case when t1.PartnerType=0 and sum(t1.InAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountDEV)
when t1.PartnerType=0 and sum(t1.OutAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountDEV)*-1
when t1.PartnerType=1 and sum(t1.OutAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountDEV)
when t1.PartnerType=1 and sum(t1.InAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountDEV)*-1
when t1.PartnerType=0 and sum(t1.InAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.InAmountDEV2)
when t1.PartnerType=0 and sum(t1.OutAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.OutAmountDEV2)*-1
when t1.PartnerType=1 and sum(t1.OutAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.OutAmountDEV2)
when t1.PartnerType=1 and sum(t1.InAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.InAmountDEV2)*-1
end CreditTotalDEV,
(case when t1.PartnerType=0 and sum(t1.InAmountHUF)<>0 then sum(t1.AmountHUF)
when t1.PartnerType=0 and sum(t1.OutAmountHUF)<>0 then sum(t1.AmountHUF)*-1
when t1.PartnerType=1 and sum(t1.OutAmountHUF)<>0 then sum(t1.AmountHUF)
when t1.PartnerType=1 and sum(t1.InAmountHUF)<>0 then sum(t1.AmountHUF)*-1
end)*-1 BallanceHUF,
(case when t1.PartnerType=0 and sum(t1.InAmountDEV)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountDEV)
when t1.PartnerType=0 and sum(t1.OutAmountDEV)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountDEV)*-1
when t1.PartnerType=1 and sum(t1.OutAmountDEV)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountDEV)
when t1.PartnerType=1 and sum(t1.InAmountDEV)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountDEV)*-1
when t1.PartnerType=0 and sum(t1.InAmountDEV2)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName and t4.Currency<>'HUF' then sum(t1.InAmountDEV2)
when t1.PartnerType=0 and sum(t1.OutAmountDEV2)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName and t4.Currency<>'HUF' then sum(t1.OutAmountDEV2)*-1
when t1.PartnerType=1 and sum(t1.OutAmountDEV2)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName and t4.Currency<>'HUF' then sum(t1.OutAmountDEV2)
when t1.PartnerType=1 and sum(t1.InAmountDEV2)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName and t4.Currency<>'HUF'then sum(t1.InAmountDEV2)*-1
end)*-1 BallanceDEV,
max(t3.ShortName+', '+ifnull(t2.DocumentNumber,'')) ShortName,
'' Description,
t2.DateExecution DateExecution,
t2.DateExecution DateCreated,
t4.DatePayment DatePayment,
0 DelayedDay,
'' DelayedRange,
t4.CurrencyName CurrencyName_Account,
0 AmountHUF_Account,
0 AmountDEV_Account,
max(t4.DateExecution) DateExecution_Account
from GLRows t1
join GLHeader t2 on t1.GLHeader=t2.Oid
left join GLCassa t5 on t2.Oid=t5.Oid
left join LiquidAssets t3 on t5.LiquidAssets_Cassa=t3.Oid
left join vv_PartnerConnectionInfoAccount t4 on t2.CustomersFrom=t4.CustomersFrom and
t1.Customer=t4.Customers and t1.PartnerType=t4.PartnerType and t1.ConnectInfo=t4.ConnectInfo
where t2.GCRecord is null and
t2.GLDocumentType=3 and
t1.PartnerType in (0,1) and
t1.GCRecord is null
group by t1.Oid,t2.CustomersFrom,t1.Customer,t1.PartnerType,
t1.ConnectInfo,t3.CurrencyName,t4.Currency,t2.DateExecution,t4.DatePayment,t4.CurrencyName
union all
select '05-Ratediff' MainType,
t1.Oid Oid,
t2.CustomersFrom CustomersFrom,
t1.Customer Customers,
t1.PartnerType PartnerType,
t1.ConnectInfo ConnectInfo,
t2.CurrencyName CurrencyName,
0 DebitTotalHUF,
case when t1.PartnerType=0 and sum(t1.InAmountHUF)<>0 then sum(t1.AmountHUF)
when t1.PartnerType=0 and sum(t1.OutAmountHUF)<>0 then sum(t1.AmountHUF)*-1
when t1.PartnerType=1 and sum(t1.OutAmountHUF)<>0 then sum(t1.AmountHUF)
when t1.PartnerType=1 and sum(t1.InAmountHUF)<>0 then sum(t1.AmountHUF)*-1
end CreditTotalHUF,
0 DebitTotalDEV,
0 CreditTotalDEV,
(case when t1.PartnerType=0 and sum(t1.InAmountHUF)<>0 then sum(t1.AmountHUF)
when t1.PartnerType=0 and sum(t1.OutAmountHUF)<>0 then sum(t1.AmountHUF)*-1
when t1.PartnerType=1 and sum(t1.OutAmountHUF)<>0 then sum(t1.AmountHUF)
when t1.PartnerType=1 and sum(t1.InAmountHUF)<>0 then sum(t1.AmountHUF)*-1
end)*-1 BallanceHUF,
0 BallanceDEV,
max(ifnull(t7.ShortName,'')+', '++ifnull(t8.DocumentNumber,'')+', '+ifnull(t2.DocumentNumber,'')) ShortName,
'' Description,
t2.DateExecution DateExecution,
t2.DateExecution DateCreated,
Null DatePayment,
0 DelayedDay,
'' DelayedRange,
t4.CurrencyName CurrencyName_Account,
0 AmountHUF_Account,
0 AmountDEV_Account,
max(t4.DateExecution) DateExecution_Account
from GLRows t1
join GLHeader t2 on t1.GLHeader=t2.Oid
left join LiquidAssets t3 on t1.LiquidAssets=t3.Oid
left join vv_PartnerConnectionInfoAccount t4 on t2.CustomersFrom=t4.CustomersFrom and
t1.Customer=t4.Customers and t1.PartnerType=t4.PartnerType and t1.ConnectInfo=t4.ConnectInfo
left join GLRows t6 on
t1.GLRowsRateDiff=t6.Oid left join LiquidAssets t7 on
t6.LiquidAssets=t7.oid left join GLHeader t8 on
t6.GLHeader=t8.oid
where t2.GCRecord is null and
t2.GLDocumentType=5 and
t1.PartnerType in (0,1) and
t1.GCRecord is null
group by t1.Oid,t2.CustomersFrom,t1.Customer,t1.PartnerType,
t1.ConnectInfo,t2.CurrencyName,t2.DateExecution,t2.DatePayment,t4.CurrencyName
union all
select case when max(t2.GLDocumentType)=4 then '04-Compensation'
when max(t2.GLDocumentType)=0 then '06-Mixed'
end MainType,
t1.Oid Oid,
t2.CustomersFrom CustomersFrom,
t1.Customer Customers,
t1.PartnerType PartnerType,
t1.ConnectInfo ConnectInfo,
t3.CurrencyName CurrencyName,
0 DebitTotalHUF,
case when t1.PartnerType=0 and sum(t1.InAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountHUF)
when t1.PartnerType=0 and sum(t1.OutAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountHUF)*-1
when t1.PartnerType=1 and sum(t1.OutAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountHUF)
when t1.PartnerType=1 and sum(t1.InAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountHUF)*-1
when t1.PartnerType=0 and sum(t1.InAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.InAmountDEV2)
when t1.PartnerType=0 and sum(t1.OutAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.OutAmountDEV2)*-1
when t1.PartnerType=1 and sum(t1.OutAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.OutAmountDEV2)
when t1.PartnerType=1 and sum(t1.InAmountHUF)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.InAmountDEV2)*-1
end CreditTotalHUF,
0 DebitTotalDEV,
case when t1.PartnerType=0 and sum(t1.InAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountDEV)
when t1.PartnerType=0 and sum(t1.OutAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountDEV)*-1
when t1.PartnerType=1 and sum(t1.OutAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountDEV)
when t1.PartnerType=1 and sum(t1.InAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountDEV)*-1
when t1.PartnerType=0 and sum(t1.InAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.InAmountDEV2)
when t1.PartnerType=0 and sum(t1.OutAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.OutAmountDEV2)*-1
when t1.PartnerType=1 and sum(t1.OutAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.OutAmountDEV2)
when t1.PartnerType=1 and sum(t1.InAmountDEV)<>0 and ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName then sum(t1.InAmountDEV2)*-1
end CreditTotalDEV,
(case when t1.PartnerType=0 and sum(t1.InAmountHUF)<>0 then sum(t1.AmountHUF)
when t1.PartnerType=0 and sum(t1.OutAmountHUF)<>0 then sum(t1.AmountHUF)*-1
when t1.PartnerType=1 and sum(t1.OutAmountHUF)<>0 then sum(t1.AmountHUF)
when t1.PartnerType=1 and sum(t1.InAmountHUF)<>0 then sum(t1.AmountHUF)*-1
end)*-1 BallanceHUF,
(case when t1.PartnerType=0 and sum(t1.InAmountDEV)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountDEV)
when t1.PartnerType=0 and sum(t1.OutAmountDEV)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountDEV)*-1
when t1.PartnerType=1 and sum(t1.OutAmountDEV)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountDEV)
when t1.PartnerType=1 and sum(t1.InAmountDEV)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)=t3.CurrencyName then sum(t1.AmountDEV)*-1
when t1.PartnerType=0 and sum(t1.InAmountDEV2)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName and t4.Currency<>'HUF' then sum(t1.InAmountDEV2)
when t1.PartnerType=0 and sum(t1.OutAmountDEV2)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName and t4.Currency<>'HUF' then sum(t1.OutAmountDEV2)*-1
when t1.PartnerType=1 and sum(t1.OutAmountDEV2)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName and t4.Currency<>'HUF' then sum(t1.OutAmountDEV2)
when t1.PartnerType=1 and sum(t1.InAmountDEV2)<>0 and
ifnull(t4.CurrencyName,t3.CurrencyName)<>t3.CurrencyName and t4.Currency<>'HUF'then sum(t1.InAmountDEV2)*-1
else 0
end)*-1 BallanceDEV,
max(t3.ShortName+', '+t2.DocumentNumber) ShortName,
'' Description,
t2.DateExecution DateExecution,
t2.DateExecution DateCreated,
t2.DateExecution DatePayment,
0 DelayedDay,
'' DelayedRange,
t4.CurrencyName CurrencyName_Account,
0 AmountHUF_Account,
0 AmountDEV_Account,
max(t4.DateExecution) DateExecution_Account
from GLRows t1
join GLHeader t2 on t1.GLHeader=t2.Oid
left join GLCompensation t5 on t2.Oid=t5.Oid left
join LiquidAssets t3 on t5.LiquidAssets_Main=t3.Oid
left join vv_PartnerConnectionInfoAccount t4 on t2.CustomersFrom=t4.CustomersFrom and
t1.Customer=t4.Customers and t1.PartnerType=t4.PartnerType and t1.ConnectInfo=t4.ConnectInfo
where t2.GCRecord is null and
t2.GLDocumentType in (4,0) and
t1.PartnerType in (0,1) and
t1.GCRecord is null
group by t1.Oid,t2.CustomersFrom,t1.Customer,t1.PartnerType,
t1.ConnectInfo,t3.CurrencyName,t4.Currency,t2.DateExecution,t4.DatePayment,t4.CurrencyName
union all
select '01-Account' MainType,
t1.Oid Oid,
t1.CustomersFrom CustomersFrom,
t1.Customers Customers,
0 PartnerType,
t1.ConnectInfo ConnectInfo,
t1.CurrencyName CurrencyName,
t1.TotalBruttoHUF DebitTotalHUF,
0 CreditTotalHUF,
t1.TotalBruttoDEV DebitTotalDEV,
0 CreditTotalDEV,
t1.TotalBruttoHUF BallanceHUF,
t1.TotalBruttoDEV BallanceDEV,
'' ShortName,
t1.Description Description,
t1.DateExecution DateExecution,
t1.DateCreated DateCreated,
t1.DatePayment DatePayment,
DATEDIFF(t1.DatePayment,curdate()) DelayedDay,
case when DATEDIFF(t1.DatePayment,curdate())<=0 then 0
when DATEDIFF(t1.DatePayment,curdate())>0 and DATEDIFF(t1.DatePayment,curdate())<=15 then 1
when DATEDIFF(t1.DatePayment,curdate())>15 and DATEDIFF(t1.DatePayment,curdate())<=30 then 2
when DATEDIFF(t1.DatePayment,curdate())>30 and DATEDIFF(t1.DatePayment,curdate())<=60 then 3
when DATEDIFF(t1.DatePayment,curdate())>60 and DATEDIFF(t1.DatePayment,curdate())<=90 then 4
when DATEDIFF(t1.DatePayment,curdate())>90 and DATEDIFF(t1.DatePayment,curdate())<=180 then 5
when DATEDIFF(t1.DatePayment,curdate())>180 and DATEDIFF(t1.DatePayment,curdate())<=360 then 6
when DATEDIFF(t1.DatePayment,curdate())>360 then 7
end DelayedRange,
t1.CurrencyName CurrencyName_Account,
t1.TotalBruttoHUF AmountHUF_Account,
t1.TotalBruttoDEV AmountDEV_Account,
t1.DateExecution DateExecution_Account
from InvoiceHeader t1
where t1.GLAccounts is null and
t1.IsEditable=0 and
t1.GCRecord is null
union all
select '01-Account' MainType,
t1.Oid Oid,
t1.CustomersFrom CustomersFrom,
t1.Customers Customers,
1 PartnerType,
t1.DocumentNumber ConnectInfo,
t1.F_CurrencyName CurrencyName,
t1.F_AmountBruttoHUF DebitTotalHUF,
0 CreditTotalHUF,
t1.F_AmountBruttoDEV DebitTotalDEV,
0 CreditTotalDEV,
t1.F_AmountBruttoHUF BallanceHUF,
t1.F_AmountBruttoDEV BallanceDEV,
'' ShortName,
'' Description,
t1.F_DateExecution DateExecution,
t1.F_DateCreated DateCreated,
t1.F_DatePayment DatePayment,
DATEDIFF(t1.F_DatePayment,curdate()) DelayedDay,
case when DATEDIFF(t1.F_DatePayment,curdate())<=0 then 0
when DATEDIFF(t1.F_DatePayment,curdate())>0 and DATEDIFF(t1.F_DatePayment,curdate())<=15 then 1
when DATEDIFF(t1.F_DatePayment,curdate())>15 and DATEDIFF(t1.F_DatePayment,curdate())<=30 then 2
when DATEDIFF(t1.F_DatePayment,curdate())>30 and DATEDIFF(t1.F_DatePayment,curdate())<=60 then 3
when DATEDIFF(t1.F_DatePayment,curdate())>60 and DATEDIFF(t1.F_DatePayment,curdate())<=90 then 4
when DATEDIFF(t1.F_DatePayment,curdate())>90 and DATEDIFF(t1.F_DatePayment,curdate())<=180 then 5
when DATEDIFF(t1.F_DatePayment,curdate())>180 and DATEDIFF(t1.F_DatePayment,curdate())<=360 then 6
when DATEDIFF(t1.F_DatePayment,curdate())>360 then 7
end DelayedRange,
t1.F_CurrencyName CurrencyName_Account,
t1.F_AmountBruttoHUF AmountHUF_Account,
t1.F_AmountBruttoDEV AmountDEV_Account,
t1.F_DateExecution DateExecution_Account
from RegistryHeader t1
left join RegistryType t2 on t1.RegistryType=t2.Oid
where t1.GCRecord is null and
t1.F_GLAccounts is null and
t1.IsEditable=0 and
t1.IsStorno=0 and
t2.RegistryMainType=0 and
t1.RegistryAcceptState=0
@@ -0,0 +1,56 @@
DROP TABLE IF EXISTS vv_PartnerConnectionInfoDetailGroup;
DROP VIEW IF EXISTS vv_PartnerConnectionInfoDetailGroup;
CREATE view vv_PartnerConnectionInfoDetailGroup
as
SELECT MAX(CAST(t1.Oid AS CHAR(100))) Oid, /*varchart nem ismeri???*/
t1.CustomersFrom CustomersFrom,
t1.Customers Customers,
t1.PartnerType PartnerType,
t1.ConnectInfo ConnectInfo,
max(t2.ShortName) Currency,
sum(t1.DebitTotalHUF) DebitTotalHUF,
SUM(t1.CreditTotalHUF) CreditTotalHUF,
sum(t1.DebitTotalDEV) DebitTotalDEV,
SUM(t1.CreditTotalDEV) CreditTotalDEV,
SUM(t1.BallanceHUF) BallanceHUF,
SUM(t1.BallanceDEV) BallanceDEV,
case when t1.PartnerType=1 then SUM(t1.BallanceHUF)*-1 else 0 end BallanceHUF_P,
case when t1.PartnerType=1 then SUM(t1.BallanceDEV)*-1 else 0 end BallanceDEV_P,
case when t1.PartnerType=0 then SUM(t1.BallanceHUF) else 0 end BallanceHUF_R,
case when t1.PartnerType=0 then SUM(t1.BallanceDEV) else 0 end BallanceDEV_R,
(case when t1.PartnerType=0 then SUM(t1.BallanceHUF) else 0 end) -
(case when t1.PartnerType=1 then SUM(t1.BallanceHUF)*-1 else 0 end) BallanceHUF_B,
(case when t1.PartnerType=0 then SUM(t1.BallanceDEV) else 0 end) -
(case when t1.PartnerType=1 then SUM(t1.BallanceDEV)*-1 else 0 end) BallanceDEV_B,
max(t3.ShortName) Currency_Account,
sum(t1.AmountHUF_Account) AmountHUF_Account,
sum(t1.AmountDEV_Account) AmountDEV_Account,
case when max(t3.ShortName)='HUF' then
case when round(SUM(t1.BallanceHUF),0)=0 then 1
else 0
end
else
case when round(SUM(t1.BallanceDEV),2)=0 then 1
else 0
end
end BallanceState,
case when max(t3.ShortName)='HUF' then -1
when t1.CurrencyName_Account IS null then -1
else
case when round(SUM(t1.BallanceDEV),2)=0 and round(SUM(t1.BallanceHUF),0)<>0 then 1
else 0
end
end BallanceRateDiff,
max(t4.DateExecution) DateExecution_Account,
MAX(t4.DateCreated) DateCreated_Account
from vv_PartnerConnectionInfoDetail t1
left join CurrencyName t2 on t1.CurrencyName=t2.Oid
left join CurrencyName t3 on t1.CurrencyName_Account=t3.Oid
left join vv_PartnerConnectionInfoAccount t4 on
t1.CustomersFrom=t4.CustomersFrom and
t1.Customers=t4.Customers and
t1.PartnerType=t4.PartnerType and
t1.ConnectInfo=t4.ConnectInfo and
t4.MainType='01-Account'
group by t1.CustomersFrom,t1.Customers,t1.PartnerType,t1.ConnectInfo,t1.CurrencyName_Account
@@ -0,0 +1,10 @@
DROP TABLE IF EXISTS vv_ProductSelect;
DROP VIEW IF EXISTS vv_ProductSelect;
CREATE VIEW vv_ProductSelect
AS
SELECT CASE WHEN t2.Oid IS NULL THEN t1.Oid ELSE t2.Oid END Oid,
t1.Oid Products,
t2.oid StorageComputed
FROM Products t1 LEFT JOIN StorageComputed t2 ON
t1.Oid=t2.Products
WHERE t1.GCRecord IS NULL AND t2.GCRecord IS NULL;
@@ -0,0 +1,28 @@
CREATE view vv_RegistryBankTransfer
as
select t1.Oid Oid,
t1.RegistryHeader RegistryHeader,
t1.AmountHUF AmountHUF,
t1.AmountDEV AmountDEV,
t1.DatePayment DatePayment,
t1.IsBlocked IsBlocked,
t1.Note Note,
t1.BankSavedFileName BankSavedFileName,
ifnull(t3.BallanceHUF,t2.F_AmountBruttoHUF) BallanceHUF,
ifnull(t3.BallanceDEV,t2.F_AmountBruttoDEV) BallanceDEV,
t1.AmountHUF-ifnull(t3.BallanceHUF,t2.F_AmountBruttoHUF) DifferenceHUF,
t1.AmountDEV-ifnull(t3.BallanceDEV,t2.F_AmountBruttoDEV) DifferenceDEV,
case when round(ifnull(t3.BallanceHUF,t2.F_AmountBruttoHUF),2)=0 then 0
when ifnull(t3.BallanceHUF,t2.F_AmountBruttoHUF)>=t1.AmountHUF then t1.AmountHUF
when ifnull(t3.BallanceHUF,t2.F_AmountBruttoHUF)<=t1.AmountHUF then ifnull(t3.BallanceHUF,t2.F_AmountBruttoHUF)
end OfferedHUF,
case when round(ifnull(t3.BallanceDEV,t2.F_AmountBruttoDEV),2)=0 then 0
when ifnull(t3.BallanceDEV,t2.F_AmountBruttoDEV)>=t1.AmountDEV then t1.AmountDEV
when ifnull(t3.BallanceDEV,t2.F_AmountBruttoDEV)<=t1.AmountDEV then ifnull(t3.BallanceDEV,t2.F_AmountBruttoDEV)
end OfferedDEV,
t1.BankPrepareName BankPrepareName
from RegistryBankTransfer t1
join RegistryHeader t2 on t1.RegistryHeader=t2.Oid
left join PCIGroup t3 on t2.CustomersFrom=t3.CustomersFrom
and t2.Customers=t3.Customers and t3.PartnerType=1 and t2.DocumentNumber=t3.ConnectInfo
where t1.GCRecord is null and t2.RegistryAcceptState=0
@@ -0,0 +1,7 @@
CREATE view vv_RegistryBankTransferPrepareName
as
select MAX(CAST(Oid AS CHAR(100))) Oid,
BankPrepareName
from RegistryBankTransfer
where Ifnull(BankPrepareName,'')<>''
group by BankPrepareName
@@ -0,0 +1,70 @@
CREATE view vv_WaitforRateDiff
as
select t1.Oid Oid,
t2.CustomersFrom CustomersFrom,
t1.PartnerType PartnerType,
t1.Customer Customers,
t1.ConnectInfo ConnectInfo,
t3.DateExecution DateExecution_Account,
t3.CurrencyName CurrencyName_Account,
round(t4.AmountDEV_Account,2) AmountDEV_Account,
round(t4.AmountHUF_Account,2) AmountHUF_Account,
round(t4.BallanceDEV,2) BallanceDEV_Account,
case when round(t4.AmountDEV_Account,2)<>0 then round(round(t4.AmountHUF_Account,2)/round(t4.AmountDEV_Account,2),2) else 0 end CurrencyRate_Account,
t1.LiquidAssets LiquidAssets,
t2.DateExecution DateExecution,
round(t1.InAmountDEV,2) InAmountDEV,
round(t1.OutAmountDEV,2) OutAmountDEV,
round(t1.InAmountDEV2,2) InAmountDEV2,
round(t1.OutAmountDEV2,2) OutAmountDEV2,
case when InAmountHUF>0 then
case when t1.InAmountDEV <>0 then round(t1.InAmountHUF,2)/round(t1.InAmountDEV,2)
else 0
end
else
case when t1.OutAmountDEV <>0 then round(t1.OutAmountHUF,2)/round(t1.OutAmountDEV,2)
else 0
end
end CurrencyRate,
round(t1.InAmountHUF,2) InAmountHUF,
round(t1.OutAmountHUF,2) OutAmountHUF,
case when t3.CurrencyName=t5.CurrencyName then round(t1.InAmountDEV,2)* round(t3.CurrencyRate,2)
else round(t1.InAmountDEV2,2)* round(t3.CurrencyRate,2)
end InAmountHUF_Account,
case when t3.CurrencyName=t5.CurrencyName then round(t1.OutAmountDEV,2)*round(t3.CurrencyRate,2)
else round(t1.OutAmountDEV2,2)*round(t3.CurrencyRate,2)
end OutAmountHUF_Account,
case when t3.CurrencyName=t5.CurrencyName then round(t1.InAmountDEV,2)* round(t3.CurrencyRate,2)
else round(t1.InAmountDEV2,2)* round(t3.CurrencyRate,2)
end - round(t1.InAmountHUF,2) InAmountHUF_Diff,
case when t3.CurrencyName=t5.CurrencyName then round(t1.OutAmountDEV,2)*round(t3.CurrencyRate,2)
else round(t1.OutAmountDEV2,2)*round(t3.CurrencyRate,2)
end - round(t1.OutAmountHUF,2) OutAmountHUF_Diff,
t1.GLRowsRatediff GLRowsRatediff,
case when t1.PartnerType = 0 Then
case when case when t3.CurrencyName=t5.CurrencyName then round(t1.InAmountDEV,2)* round(t3.CurrencyRate,2)
else round(t1.InAmountDEV2,2)* round(t3.CurrencyRate,2)
end - round(t1.InAmountHUF,2) > 0 Then -1
else 1
end
when t1.PartnerType = 1 Then
case when case when t3.CurrencyName=t5.CurrencyName then round(t1.OutAmountDEV,2)*round(t3.CurrencyRate,2)
else round(t1.OutAmountDEV2,2)*round(t3.CurrencyRate,2)
end - round(t1.OutAmountHUF,2) > 0 Then 1
else -1
end
else 0
end RateDiffState
from GLRows t1
left join GLHeader t2 on t1.GLHeader=t2.Oid
join vv_PartnerConnectionInfoAccount t3 on t2.CustomersFrom=t3.CustomersFrom
and t1.PartnerType=t3.PartnerType and t1.Customer=t3.Customers and t1.ConnectInfo=t3.ConnectInfo
left join PCIGroup t4 on t2.CustomersFrom=t4.CustomersFrom
and t1.PartnerType=t4.PartnerType and t1.Customer=t4.Customers and t1.ConnectInfo=t4.ConnectInfo
left join LiquidAssets t5 on t1.LiquidAssets=t5.Oid
left join CurrencyName t6 on t5.CurrencyName=t6.Oid
left join CurrencyName t7 on t3.CurrencyName=t7.Oid
where t2.GCRecord is null and
t2.GLDocumentType in (2,3,4) and
t6.ShortName <> 'HUF' and ifnull(t7.ShortName,'HUF')<>'HUF' and
((t1.PartnerType=0 and t1.InAmountHUF>0) or (t1.PartnerType=1 and t1.OutAmountHUF>0))