diff --git a/db/ddlutils/postgresql/views/LVE_RV_Books.sql b/db/ddlutils/postgresql/views/LVE_RV_InvoiceBook.sql similarity index 97% rename from db/ddlutils/postgresql/views/LVE_RV_Books.sql rename to db/ddlutils/postgresql/views/LVE_RV_InvoiceBook.sql index 7895e17..9e3c5a5 100644 --- a/db/ddlutils/postgresql/views/LVE_RV_Books.sql +++ b/db/ddlutils/postgresql/views/LVE_RV_InvoiceBook.sql @@ -92,7 +92,7 @@ CREATE OR REPLACE VIEW LVE_RV_InvoiceBook AS 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 + JOIN WH_Type wt ON (whs.WH_Type_ID = wt.WH_Type_ID AND wt.IsFiscalDocument = 'Y') WHERE i.DocStatus IN ('CO', 'CL') GROUP BY il.LineNetAmt, @@ -183,7 +183,7 @@ UNION ALL 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 + JOIN WH_Type wt ON (whs.WH_Type_ID = wt.WH_Type_ID AND wt.IsFiscalDocument = 'Y') WHERE i.DocStatus IN ('CO', 'CL') GROUP BY il.LineNetAmt, il.InvoiceToAllocate_ID, diff --git a/xml/migration/062_AddViewBook.xml b/xml/migration/062_AddViewBook.xml index 7c2d20c..4c28152 100644 --- a/xml/migration/062_AddViewBook.xml +++ b/xml/migration/062_AddViewBook.xml @@ -54,7 +54,7 @@ (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 + 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 @@ -68,7 +68,7 @@ ELSE 0 END) AS Exempt, sum(CASE - WHEN t.Rate <> 0 THEN it.TaxBaseAmt + WHEN t.Rate <> 0 THEN it.TaxBaseAmt ELSE 0 End) AS Taxable, it.C_Invoice_ID @@ -83,20 +83,20 @@ t.AliquotType FROM C_InvoiceTax it JOIN C_Tax t ON it.C_Tax_ID = t.C_Tax_ID - WHERE t.Rate <> 0 + 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 + 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 + 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 + JOIN WH_Type wt ON (whs.WH_Type_ID = wt.WH_Type_ID AND wt.IsFiscalDocument = 'Y') WHERE i.DocStatus IN ('CO', 'CL') GROUP BY il.LineNetAmt, @@ -169,7 +169,7 @@ UNION ALL 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 + 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, @@ -181,13 +181,13 @@ UNION ALL p.EndDate, i.DateAcct, i.DateInvoiced, - CASE WHEN whd.WHThirdParty_ID > 0 THEN 'Y' ELSE 'N' END IsThirdParty + 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 + 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 + JOIN WH_Type wt ON (whs.WH_Type_ID = wt.WH_Type_ID AND wt.IsFiscalDocument = 'Y') WHERE i.DocStatus IN ('CO', 'CL') GROUP BY il.LineNetAmt, il.InvoiceToAllocate_ID, @@ -199,7 +199,7 @@ UNION ALL 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, + ) 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,