Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/adempiere/LVE
Browse files Browse the repository at this point in the history
  • Loading branch information
yamelsenih committed Sep 26, 2019
2 parents e57c683 + b3a5bb4 commit 50b73fe
Show file tree
Hide file tree
Showing 13 changed files with 6,827 additions and 362 deletions.
206 changes: 206 additions & 0 deletions db/ddlutils/postgresql/views/LVE_RV_Books.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
CREATE OR REPLACE VIEW LVE_RV_InvoiceBook AS
SELECT i.AD_Client_ID,
i.AD_Org_ID,
i.C_Invoice_ID,
CASE
WHEN dt.FiscalDocumentType IN ('02', '03') THEN i.DateInvoiced + '01:00:00'::inteRVal
ELSE i.DateInvoiced
End AS DateInvoiced,
i.DateAcct,
i.ControlNo,
i.DocumentNo,
dt.C_DocType_ID,
dt.FiscalDocumentType,
bp.C_BPartner_ID,
bp.Name,
bp.TaxID,
i.GrandTotal,
itsum.Exempt,
itsum.Taxable,
it.TaxAmt,
it.TaxBaseAmt,
it.Rate,
i.IsSOTrx,
i.C_Currency_ID,
asch.C_Currency_ID AS AcctSchemaCurrency_ID,
wt.Record_ID,
wt.Name AS WHTName,
CASE
WHEN wt.Record_ID = iwh.Record_ID THEN iwh.WHTaxAmt
ELSE NULL
End AS WHTaxAmt,
CASE
WHEN wt.Record_ID = iwh.Record_ID THEN iwh.whDocumentNo
ELSE NULL
End AS whDocumentNo,
CurrencyRate(i.C_Currency_ID, asch.C_Currency_ID, i.DateInvoiced, i.C_ConversionType_ID, i.AD_Client_ID, i.AD_Org_ID) AS CurrencyRate,
i.DocStatus,
i.IsFiscalDocument,
p.C_Period_ID,
p.StartDate,
p.EndDate,
iaffected.affectedDocumentNo,
dt.DocBaseType,
bp.PersonType AS PersonTypevalue,
c.Name AS ClientName,
oi.TaxID AS OrgTaxID,
NULL::VARCHAR ImportDocNo,
i.C_Invoice_ID AS Document_ID ,
COALESCE(it.C_Tax_ID, 0) AS C_Tax_ID,
(i.C_Invoice_ID::VARCHAR || COALESCE(it.C_Tax_ID, 0)::VARCHAR) AS DocumentTax_ID,
it.AliquotType
FROM C_Invoice i
LEFT JOIN C_Period p ON i.DateAcct >= p.StartDate AND i.DateAcct <= p.EndDate AND i.AD_Client_ID = p.AD_Client_ID
JOIN C_DocType dt ON i.C_DocType_ID = dt.C_DocType_ID
JOIN C_BPartner bp ON i.C_BPartner_ID = bp.C_BPartner_ID
JOIN AD_OrgInfo oi ON oi.AD_Org_ID = i.AD_Org_ID
JOIN AD_Client c ON i.AD_Client_ID = c.AD_Client_ID
JOIN AD_ClientInfo ci ON c.AD_Client_ID = ci.AD_Client_ID
JOIN C_AcctSchema asch ON ci.C_AcctSchema1_ID = asch.C_AcctSchema_ID
LEFT JOIN ( SELECT
sum(
CASE
WHEN t.Rate = 0 THEN it.TaxBaseAmt
ELSE 0
END) AS Exempt,
sum(CASE
WHEN t.Rate <> 0 THEN it.TaxBaseAmt
ELSE 0
End) AS Taxable,
it.C_Invoice_ID
FROM C_InvoiceTax it
JOIN C_Tax t ON it.C_Tax_ID = t.C_Tax_ID
GROUP BY it.C_Invoice_ID) itsum ON i.C_Invoice_ID = itsum.C_Invoice_ID
LEFT JOIN ( SELECT sum(it.TaxAmt) AS TaxAmt,
sum(it.TaxBaseAmt) AS TaxBaseAmt,
it.C_Invoice_ID,
t.Rate,
it.C_Tax_ID,
t.AliquotType
FROM C_InvoiceTax it
JOIN C_Tax t ON it.C_Tax_ID = t.C_Tax_ID
WHERE t.Rate <> 0
GROUP BY it.C_Invoice_ID, t.Rate, it.C_Tax_ID, t.AliquotType) it ON i.C_Invoice_ID = it.C_Invoice_ID
LEFT JOIN (SELECT il.LineNetAmt AS WHTaxAmt,
il.InvoiceToAllocate_ID AS C_Invoice_ID,
i.DocumentNo AS WHDocumentNo,
wt.WH_Type_ID AS Record_ID,
p.C_Period_ID,
CASE WHEN whd.WHThirdParty_ID > 0 THEN 'Y' ELSE 'N' END IsThirdParty
FROM C_Invoice i
LEFT JOIN C_Period p ON i.DateAcct >= p.StartDate AND i.DateAcct <= p.EndDate AND i.AD_Client_ID = p.AD_Client_ID
JOIN C_InvoiceLine il ON i.C_Invoice_ID = il.C_Invoice_ID
JOIN WH_Withholding whd ON (whd.C_InvoiceLine_ID = il.C_InvoiceLine_ID)
JOIN WH_Setting whs ON (whs.WH_Setting_ID = whd.WH_Setting_ID)
JOIN WH_Type wt ON whs.WH_Type_ID = wt.WH_Type_ID
WHERE i.DocStatus IN ('CO', 'CL')
GROUP BY
il.LineNetAmt,
il.InvoiceToAllocate_ID,
i.DocumentNo,
wt.WH_Type_ID,
p.C_Period_ID,
whd.WHThirdParty_ID) iwh ON i.C_Invoice_ID = iwh.C_Invoice_ID AND p.C_Period_ID = iwh.C_Period_ID
LEFT JOIN ( SELECT il.C_Invoice_ID,
max(i.DocumentNo) AS AffectedDocumentNo
FROM C_Invoice i
JOIN C_InvoiceLine il ON i.C_Invoice_ID = il.InvoiceToAllocate_ID
WHERE i.DocStatus IN ('CO', 'CL')
GROUP BY il.C_Invoice_ID) iaffected ON i.C_Invoice_ID = iaffected.C_Invoice_ID,
( SELECT wt.AD_Client_ID,
wt.AD_Org_ID,
wt.Name,
wt.WH_Type_ID AS Record_ID
FROM WH_Type wt
WHERE IsFiscalDocument = 'Y') wt
WHERE wt.AD_Client_ID = c.AD_Client_ID
UNION ALL
SELECT i.AD_Client_ID,
i.AD_Org_ID,
i.C_Invoice_ID,
i.DateInvoiced,
iwh.DateAcct,
i.ControlNo,
i.DocumentNo,
dt.C_DocType_ID,
dt.FiscalDocumentType,
bp.C_BPartner_ID,
bp.Name,
bp.TaxID,
0.00 AS GrandTotal,
0.00 AS Exempt,
0.00 AS Taxable,
0.00 AS TaxAmt,
0.00 AS TaxBaseAmt,
0.00 AS Rate,
i.IsSOTrx,
i.C_Currency_ID,
i.C_Currency_ID AS AcctSchemaCurrency_ID,
wt.Record_ID,
wt.Name AS WHTName,
CASE
WHEN wt.Record_ID = iwh.WH_Type_ID THEN iwh.WHTaxAmt
ELSE NULL
End AS WHTaxAmt,
CASE
WHEN wt.Record_ID = iwh.WH_Type_ID THEN iwh.whDocumentNo
ELSE NULL
End AS whDocumentNo,
1 AS CurrencyRate,
i.DocStatus,
i.IsFiscalDocument,
iwh.C_Period_ID,
iwh.StartDate,
iwh.EndDate,
NULL AS affectedDocumentNo,
dt.DocBaseType,
bp.PersonType AS PersonTypevalue,
c.Name AS ClientName,
oi.TaxID AS OrgTaxID,
NULL::VARCHAR ImportDocNo,
i.C_Invoice_ID AS Document_ID ,
0 AS C_Tax_ID,
(i.C_Invoice_ID::VARCHAR || '0') AS DocumentTax_ID,
'' AS AliquotType
FROM C_Invoice i
JOIN AD_Client c ON i.AD_Client_ID = c.AD_Client_ID
JOIN AD_OrgInfo oi ON oi.AD_Org_ID = i.AD_Org_ID
LEFT JOIN C_Period p ON i.DateAcct >= p.StartDate AND i.DateAcct <= p.EndDate AND i.AD_Client_ID = p.AD_Client_ID
JOIN C_DocType dt ON i.C_DocType_ID = dt.C_DocType_ID
JOIN C_BPartner bp ON i.C_BPartner_ID = bp.C_BPartner_ID
JOIN ( SELECT il.LineNetAmt AS WHTaxAmt,
il.InvoiceToAllocate_ID AS C_Invoice_ID,
i.DocumentNo AS whDocumentNo,
wt.WH_Type_ID,
p.C_Period_ID,
p.StartDate,
p.EndDate,
i.DateAcct,
i.DateInvoiced,
CASE WHEN whd.WHThirdParty_ID > 0 THEN 'Y' ELSE 'N' END IsThirdParty
FROM C_Invoice i
LEFT JOIN C_Period p ON i.DateAcct >= p.StartDate AND i.DateAcct <= p.EndDate AND i.AD_Client_ID = p.AD_Client_ID
JOIN C_InvoiceLine il ON i.C_Invoice_ID = il.C_Invoice_ID
JOIN WH_Withholding whd ON whd.C_InvoiceLine_ID = il.C_InvoiceLine_ID
JOIN WH_Setting whs ON (whs.WH_Setting_ID = whd.WH_Setting_ID)
JOIN WH_Type wt ON whs.WH_Type_ID = wt.WH_Type_ID
WHERE i.DocStatus IN ('CO', 'CL')
GROUP BY il.LineNetAmt,
il.InvoiceToAllocate_ID,
i.DocumentNo,
wt.WH_Type_ID,
p.C_Period_ID,
p.StartDate,
p.EndDate,
i.DateAcct,
i.DateInvoiced,
whd.WHThirdParty_ID
) iwh ON i.C_Invoice_ID = iwh.C_Invoice_ID AND p.C_Period_ID <> iwh.C_Period_ID,
( SELECT wt.AD_Client_ID,
wt.AD_Org_ID,
wt.Name,
wt.WH_Type_ID AS Record_ID
FROM WH_Type wt
WHERE IsFiscalDocument = 'Y') wt
WHERE wt.AD_Client_ID = c.AD_Client_ID
;
75 changes: 75 additions & 0 deletions db/ddlutils/postgresql/views/LVE_RV_WH_Invoice_Header.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
CREATE OR RepLACE VIEW LVE_RV_WH_Invoice_Header AS
SELECT i.AD_Client_ID,
i.AD_Org_ID,
i.IsActive,
i.Created,
i.CreatedBy,
i.Updated,
i.UpdatedBy,
i.C_Invoice_ID,
i.IsSOTrx,
i.DocumentNo,
i.DocStatus,
i.C_DocType_ID,
bp.C_BPartner_ID,
bp.Value AS bpvalue,
bp.TaxID AS bpTaxID,
bp.Naics,
bp.Duns,
oi.C_Location_ID AS org_Location_ID,
oi.TaxID,
dt.PrintName AS documentType,
dt.DocumentNote AS documentTypeNote,
i.C_Order_ID,
i.SalesRep_ID,
COALESCE(ubp.Name, u.Name) AS salesRep_Name,
i.DateInvoiced,
bpg.Greeting AS BPGreeting,
bp.Name,
bp.Name2,
bpcg.Greeting AS BPContactGreeting,
bpc.Title,
bpc.Phone,
NULLIF(bpc.Name::text, bp.Name::text) AS ContactName,
bpl.C_Location_ID,
bp.ReferenceNo,
l.Postal::text || l.Postal_Add::text AS postal,
i.Description,
i.POReference,
i.DateOrdered,
i.C_Currency_ID,
pt.Name AS PaymentTerm,
pt.DocumentNote AS PaymentTermNote,
i.C_Charge_ID,
i.ChargeAmt,
i.TotalLines,
i.GrandTotal,
i.GrandTotal AS AmtInWords,
i.M_PriceList_ID,
i.IsTaxIncluded,
i.C_Campaign_ID,
i.C_Project_ID,
i.C_Activity_ID,
i.IsPaid,
COALESCE(oi.logo_ID, ci.logo_ID) AS logo_ID,
bp.PersonType,
wh.WHThirdParty_ID
FROM c_Invoice i
INNER JOIN ( SELECT MAX(wh.WHThirdParty_ID) AS whthirdparty_ID,
wh.C_Invoice_ID
FROM wh_withholding wh
WHERE wh.C_Invoice_ID IS NOT NULL
GROUP BY wh.C_Invoice_ID) wh ON wh.C_Invoice_ID = i.C_Invoice_ID
INNER JOIN c_DocType dt ON i.C_DocType_ID = dt.C_DocType_ID
INNER JOIN c_PaymentTerm pt ON i.C_PaymentTerM_ID = pt.C_PaymentTerM_ID
INNER JOIN c_BPartner bp ON COALESCE(wh.WHThirdParty_ID,i.C_BPartner_ID) = bp.C_BPartner_ID
LEFT JOIN c_Greeting bpg ON bp.C_Greeting_ID = bpg.C_Greeting_ID
INNER JOIN c_BPartner_Location bpl ON i.C_BPartner_Location_ID = bpl.C_BPartner_Location_ID
INNER JOIN c_Location l ON bpl.C_Location_ID = l.C_Location_ID
LEFT JOIN AD_user bpc ON i.AD_user_ID = bpc.AD_user_ID
LEFT JOIN c_Greeting bpcg ON bpc.C_Greeting_ID = bpcg.C_Greeting_ID
INNER JOIN AD_Orginfo oi ON i.AD_Org_ID = oi.AD_Org_ID
INNER JOIN AD_Clientinfo ci ON i.AD_Client_ID = ci.AD_Client_ID
LEFT JOIN AD_user u ON i.SalesRep_ID = u.AD_user_ID
LEFT JOIN c_BPartner ubp ON u.C_BPartner_ID = ubp.C_BPartner_ID
;
Loading

0 comments on commit 50b73fe

Please sign in to comment.