Skip to content

Commit

Permalink
Corrección de agrupación de resumen de facturas diarias
Browse files Browse the repository at this point in the history
  • Loading branch information
yamelsenih committed Jul 15, 2020
1 parent 6b0dfbc commit 6b0229f
Show file tree
Hide file tree
Showing 3 changed files with 418 additions and 291 deletions.
7 changes: 4 additions & 3 deletions db/ddlutils/oracle/views/LVE_RV_C_Invoice_Day_Summary.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CREATE OR REPLACE VIEW LVE_RV_C_Invoice_Day_Summary
(AD_Client_ID, AD_Org_ID, DateInvoiced, LineNetAmt,
LineListAmt, LineLimitAmt, LineDiscountAmt, LineDiscount, LineOverLimitAmt,
LineOverLimit, IsSOTrx, C_DocTypeTarget_ID, DocStatus, IsFiscalDocument, BeginingDocumentNo, EndingDocumentNo, BeginingControlNo, EndingControlNo)
LineOverLimit, IsSOTrx, DocStatus, DocNoSequence_ID, ControlNoSequence_ID, IsFiscalDocument, BeginingDocumentNo, EndingDocumentNo, BeginingControlNo, EndingControlNo)
AS
SELECT il.AD_Client_ID, il.AD_Org_ID,
firstOf(il.DateInvoiced, 'DD') AS DateInvoiced, -- DD Day, DY Week, MM Month
Expand All @@ -14,12 +14,13 @@ SELECT il.AD_Client_ID, il.AD_Org_ID,
SUM(il.LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(il.LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(il.LineNetAmt)-SUM(il.LineOverLimitAmt))/SUM(il.LineNetAmt)*100,2) END AS LineOverLimit,
il.IsSOTrx, il.C_DocTypeTarget_ID, il.DocStatus,
il.IsSOTrx, il.DocStatus, COALESCE(dt.DefiniteSequence_ID, dt.DocNoSequence_ID) AS DocNoSequence_ID, dt.ControlNoSequence_ID,
i.IsFiscalDocument,
MIN(i.DocumentNo) AS BeginingDocumentNo,
MAX(i.DocumentNo) AS EndingDocumentNo,
MIN(i.ControlNo) AS BeginingControlNo,
MAX(i.ControlNo) AS EndingControlNo
FROM RV_C_InvoiceLine il
INNER JOIN C_Invoice i ON(i.C_Invoice_ID = il.C_Invoice_ID)
GROUP BY il.AD_Client_ID, il.AD_Org_ID, firstOf(il.DateInvoiced, 'DD'), il.IsSOTrx, il.C_DocTypeTarget_ID, il.DocStatus, i.IsFiscalDocument;
INNER JOIN C_DocType dt ON(dt.C_DocType_ID = il.C_DocTypeTarget_ID)
GROUP BY il.AD_Client_ID, il.AD_Org_ID, firstOf(il.DateInvoiced, 'DD'), il.IsSOTrx, COALESCE(dt.DefiniteSequence_ID, dt.DocNoSequence_ID), dt.ControlNoSequence_ID, il.DocStatus, i.IsFiscalDocument;
7 changes: 4 additions & 3 deletions db/ddlutils/postgresql/views/LVE_RV_C_Invoice_Day_Summary.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CREATE OR REPLACE VIEW LVE_RV_C_Invoice_Day_Summary
(AD_Client_ID, AD_Org_ID, DateInvoiced, LineNetAmt,
LineListAmt, LineLimitAmt, LineDiscountAmt, LineDiscount, LineOverLimitAmt,
LineOverLimit, IsSOTrx, C_DocTypeTarget_ID, DocStatus, IsFiscalDocument, BeginingDocumentNo, EndingDocumentNo, BeginingControlNo, EndingControlNo)
LineOverLimit, IsSOTrx, DocStatus, DocNoSequence_ID, ControlNoSequence_ID, IsFiscalDocument, BeginingDocumentNo, EndingDocumentNo, BeginingControlNo, EndingControlNo)
AS
SELECT il.AD_Client_ID, il.AD_Org_ID,
firstOf(il.DateInvoiced, 'DD') AS DateInvoiced, -- DD Day, DY Week, MM Month
Expand All @@ -14,12 +14,13 @@ SELECT il.AD_Client_ID, il.AD_Org_ID,
SUM(il.LineOverLimitAmt) AS LineOverLimitAmt,
CASE WHEN SUM(il.LineNetAmt)=0 THEN 0 ELSE
100-ROUND((SUM(il.LineNetAmt)-SUM(il.LineOverLimitAmt))/SUM(il.LineNetAmt)*100,2) END AS LineOverLimit,
il.IsSOTrx, il.C_DocTypeTarget_ID, il.DocStatus,
il.IsSOTrx, il.DocStatus, COALESCE(dt.DefiniteSequence_ID, dt.DocNoSequence_ID) AS DocNoSequence_ID, dt.ControlNoSequence_ID,
i.IsFiscalDocument,
MIN(i.DocumentNo) AS BeginingDocumentNo,
MAX(i.DocumentNo) AS EndingDocumentNo,
MIN(i.ControlNo) AS BeginingControlNo,
MAX(i.ControlNo) AS EndingControlNo
FROM RV_C_InvoiceLine il
INNER JOIN C_Invoice i ON(i.C_Invoice_ID = il.C_Invoice_ID)
GROUP BY il.AD_Client_ID, il.AD_Org_ID, firstOf(il.DateInvoiced, 'DD'), il.IsSOTrx, il.C_DocTypeTarget_ID, il.DocStatus, i.IsFiscalDocument;
INNER JOIN C_DocType dt ON(dt.C_DocType_ID = il.C_DocTypeTarget_ID)
GROUP BY il.AD_Client_ID, il.AD_Org_ID, firstOf(il.DateInvoiced, 'DD'), il.IsSOTrx, COALESCE(dt.DefiniteSequence_ID, dt.DocNoSequence_ID), dt.ControlNoSequence_ID, il.DocStatus, i.IsFiscalDocument;
Loading

0 comments on commit 6b0229f

Please sign in to comment.