Synchronize view with patch

This commit is contained in:
vpj-cd 2007-12-05 22:58:45 +00:00
parent 60904e151d
commit 5403811edc
4 changed files with 119 additions and 102 deletions

View File

@ -11,11 +11,11 @@ SELECT il.AD_Client_ID, il.AD_Org_ID,
i.C_BPartner_ID, il.M_Product_ID, i.C_BPartner_ID, il.M_Product_ID,
i.DocumentNo, i.DateInvoiced, i.DateAcct, i.DocumentNo, i.DateInvoiced, i.DateAcct,
i.IsSOTrx, i.DocStatus, i.IsSOTrx, i.DocStatus,
ROUND(i.Multiplier*il.LineNetAmt, 2) AS LineNetAmt, ROUND(i.Multiplier*LineNetAmt, 2) AS LineNetAmt,
ROUND(i.Multiplier*il.PriceList*il.QtyInvoiced, 2) AS LineListAmt, ROUND(i.Multiplier*PriceList*QtyInvoiced, 2) AS LineListAmt,
CASE WHEN COALESCE(il.PriceLimit, 0::numeric)=0::numeric THEN ROUND(i.Multiplier*il.LineNetAmt,2) ELSE ROUND(i.Multiplier*il.PriceLimit*il.QtyInvoiced,2) END AS LineLimitAmt, CASE WHEN COALESCE(il.PriceLimit, 0)=0 THEN ROUND(i.Multiplier*LineNetAmt,2) ELSE ROUND(i.Multiplier*il.PriceLimit*il.QtyInvoiced,2) END AS LineLimitAmt,
ROUND(i.Multiplier*il.PriceList*il.QtyInvoiced-il.LineNetAmt,2) AS LineDiscountAmt, ROUND(i.Multiplier*il.PriceList*ilQtyInvoiced-il.LineNetAmt,2) AS LineDiscountAmt,
CASE WHEN COALESCE(il.PriceLimit,0::numeric)=0::numeric THEN 0::numeric ELSE ROUND(i.Multiplier*il.LineNetAmt-il.PriceLimit*il.QtyInvoiced,2) END AS LineOverLimitAmt, CASE WHEN COALESCE(il.PriceLimit,0)=0 THEN 0 ELSE ROUND(i.Multiplier*il.LineNetAmt-il.PriceLimit*il.QtyInvoiced,2) END AS LineOverLimitAmt,
il.QtyInvoiced, il.QtyEntered, il.QtyInvoiced, il.QtyEntered,
il.Line, il.C_OrderLine_ID, il.C_UOM_ID, il.Line, il.C_OrderLine_ID, il.C_UOM_ID,
il.C_Campaign_ID, il.C_Project_ID, il.C_Activity_ID, il.C_ProjectPhase_ID, il.C_ProjectTask_ID il.C_Campaign_ID, il.C_Project_ID, il.C_Activity_ID, il.C_ProjectPhase_ID, il.C_ProjectTask_ID

View File

@ -7,7 +7,7 @@ CREATE OR REPLACE VIEW C_INVOICE_V
C_BPARTNER_LOCATION_ID, AD_USER_ID, POREFERENCE, DATEORDERED, C_CURRENCY_ID, C_BPARTNER_LOCATION_ID, AD_USER_ID, POREFERENCE, DATEORDERED, C_CURRENCY_ID,
C_CONVERSIONTYPE_ID, PAYMENTRULE, C_PAYMENTTERM_ID, C_CHARGE_ID, M_PRICELIST_ID, C_CONVERSIONTYPE_ID, PAYMENTRULE, C_PAYMENTTERM_ID, C_CHARGE_ID, M_PRICELIST_ID,
C_CAMPAIGN_ID, C_PROJECT_ID, C_ACTIVITY_ID, ISPRINTED, ISDISCOUNTPRINTED, C_CAMPAIGN_ID, C_PROJECT_ID, C_ACTIVITY_ID, ISPRINTED, ISDISCOUNTPRINTED,
ISPAID, ISINDISPUTE, ISPAYSCHEDULEVALID, C_INVOICEPAYSCHEDULE_ID, INVOICECOLLECTIONTYPE, DUNNINGGRACE, ISPAID, ISINDISPUTE, ISPAYSCHEDULEVALID, C_INVOICEPAYSCHEDULE_ID, INVOICECOLLECTIONTYPE,DUNNINGGRACE,
CHARGEAMT, TOTALLINES, GRANDTOTAL, MULTIPLIER, MULTIPLIERAP, CHARGEAMT, TOTALLINES, GRANDTOTAL, MULTIPLIER, MULTIPLIERAP,
DOCBASETYPE) DOCBASETYPE)
AS AS
@ -18,16 +18,16 @@ SELECT i.C_Invoice_ID, i.AD_Client_ID, i.AD_Org_ID, i.IsActive, i.Created, i.Cre
i.AD_User_ID, i.POReference, i.DateOrdered, i.C_Currency_ID, i.C_ConversionType_ID, i.PaymentRule, i.AD_User_ID, i.POReference, i.DateOrdered, i.C_Currency_ID, i.C_ConversionType_ID, i.PaymentRule,
i.C_PaymentTerm_ID, i.C_Charge_ID, i.M_PriceList_ID, i.C_Campaign_ID, i.C_Project_ID, i.C_PaymentTerm_ID, i.C_Charge_ID, i.M_PriceList_ID, i.C_Campaign_ID, i.C_Project_ID,
i.C_Activity_ID, i.IsPrinted, i.IsDiscountPrinted, i.IsPaid, i.IsInDispute, i.C_Activity_ID, i.IsPrinted, i.IsDiscountPrinted, i.IsPaid, i.IsInDispute,
i.IsPayScheduleValid, NULL::numeric) AS C_InvoicePaySchedule_ID, i.InvoiceCollectionType, i.dunninggrace, i.IsPayScheduleValid, cast(null as numeric) AS C_InvoicePaySchedule_ID, i.InvoiceCollectionType,i.DunningGrace
CASE WHEN charAt(d.DocBaseType::character varying, 3)::text ='C'::text THEN i.ChargeAmt*-1::numeric ELSE i.ChargeAmt END AS ChargeAmt, cast(CASE WHEN charAt(d.DocBaseType,3)='C' THEN i.ChargeAmt*-1 ELSE i.ChargeAmt END as numeric) AS ChargeAmt,
CASE WHEN charAt(d.DocBaseType::character varying,3)::text='C'::text THEN i.TotalLines*-1::numeric ELSE i.TotalLines END AS TotalLines, cast(CASE WHEN charAt(d.DocBaseType,3)='C' THEN i.TotalLines*-1 ELSE i.TotalLines END as numeric) AS TotalLines,
CASE WHEN charAt(d.DocBaseType::character varying,3)::text ='C'::text THEN i.GrandTotal*-1::numeric ELSE i.GrandTotal END AS GrandTotal, cast(CASE WHEN charAt(d.DocBaseType,3)='C' THEN i.GrandTotal*-1 ELSE i.GrandTotal END as numeric) AS GrandTotal,
CASE WHEN charAt(d.DocBaseType::character varying,3)::text ='C'::text THEN -1 ELSE 1 END::numeric AS Multiplier, cast(CASE WHEN charAt(d.DocBaseType,3)='C' THEN -1 ELSE 1 END as numeric) AS Multiplier,
CASE WHEN charAt(d.DocBaseType::character varying,2)::text ='P':;text THEN -1 ELSE 1 END::numeric AS MultiplierAP, cast(CASE WHEN charAt(d.DocBaseType,2)='P' THEN -1 ELSE 1 END AS numeric) as MultiplierAP,
d.DocBaseType d.DocBaseType
FROM C_Invoice i FROM C_Invoice i
INNER JOIN C_DocType d ON (i.C_DocType_ID=d.C_DocType_ID) INNER JOIN C_DocType d ON (i.C_DocType_ID=d.C_DocType_ID)
WHERE i.IsPayScheduleValid<>'Y'::bpchar WHERE i.IsPayScheduleValid<>'Y'
UNION UNION
SELECT i.C_Invoice_ID, i.AD_Client_ID, i.AD_Org_ID, i.IsActive, i.Created, i.CreatedBy, i.Updated, i.UpdatedBy, SELECT i.C_Invoice_ID, i.AD_Client_ID, i.AD_Org_ID, i.IsActive, i.Created, i.CreatedBy, i.Updated, i.UpdatedBy,
i.IsSOTrx, i.DocumentNo, i.DocStatus, i.DocAction, i.Processing, i.Processed, i.C_DocType_ID, i.IsSOTrx, i.DocumentNo, i.DocStatus, i.DocAction, i.Processing, i.Processed, i.C_DocType_ID,
@ -36,19 +36,18 @@ SELECT i.C_Invoice_ID, i.AD_Client_ID, i.AD_Org_ID, i.IsActive, i.Created, i.Cre
i.AD_User_ID, i.POReference, i.DateOrdered, i.C_Currency_ID, i.C_ConversionType_ID, i.PaymentRule, i.AD_User_ID, i.POReference, i.DateOrdered, i.C_Currency_ID, i.C_ConversionType_ID, i.PaymentRule,
i.C_PaymentTerm_ID, i.C_Charge_ID, i.M_PriceList_ID, i.C_Campaign_ID, i.C_Project_ID, i.C_PaymentTerm_ID, i.C_Charge_ID, i.M_PriceList_ID, i.C_Campaign_ID, i.C_Project_ID,
i.C_Activity_ID, i.IsPrinted, i.IsDiscountPrinted, i.IsPaid, i.IsInDispute, i.C_Activity_ID, i.IsPrinted, i.IsDiscountPrinted, i.IsPaid, i.IsInDispute,
i.IsPayScheduleValid, ips.C_InvoicePaySchedule_ID, i.InvoiceCollectionType, i.IsPayScheduleValid, ips.C_InvoicePaySchedule_ID, i.InvoiceCollectionType, i.DunningGrace
i.dunninggrace, null AS ChargeAmt,
NULL::"unknown" AS ChargeAmt, null AS TotalLines,
NULL::"unknown" AS TotalLines, CASE WHEN charAt(d.DocBaseType,3)='C' THEN ips.DueAmt*-1 ELSE ips.DueAmt END AS GrandTotal,
CASE WHEN charAt(d.DocBaseType::character varying,3)::text ='C'::text THEN ips.DueAmt*-1::numeric ELSE ips.DueAmt END AS GrandTotal, CASE WHEN charAt(d.DocBaseType,3)='C' THEN -1 ELSE 1 END AS Multiplier,
CASE WHEN charAt(d.DocBaseType::character varying,3)::text ='C'::text THEN -1 ELSE 1 END AS Multiplier, CASE WHEN charAt(d.DocBaseType,2)='P' THEN -1 ELSE 1 END AS MultiplierAP,
CASE WHEN charAt(d.DocBaseType::character varying,2)::text ='P'::text THEN -1 ELSE 1 END AS MultiplierAP,
d.DocBaseType d.DocBaseType
FROM C_Invoice i FROM C_Invoice i
JOIN C_DocType d ON (i.C_DocType_ID=d.C_DocType_ID) INNER JOIN C_DocType d ON (i.C_DocType_ID=d.C_DocType_ID)
JOIN C_InvoicePaySchedule ips ON (i.C_Invoice_ID=ips.C_Invoice_ID) INNER JOIN C_InvoicePaySchedule ips ON (i.C_Invoice_ID=ips.C_Invoice_ID)
WHERE i.IsPayScheduleValid='Y'::bpchar WHERE i.IsPayScheduleValid='Y'
AND ips.IsValid='Y'::bpchar; AND ips.IsValid='Y';

View File

@ -7,14 +7,14 @@ AS
SELECT i.AD_Client_ID,i.AD_Org_ID, i.IsActive, i.Created,i.CreatedBy,i.Updated,i.UpdatedBy, SELECT i.AD_Client_ID,i.AD_Org_ID, i.IsActive, i.Created,i.CreatedBy,i.Updated,i.UpdatedBy,
i.C_BPartner_ID, i.C_Currency_ID, i.C_BPartner_ID, i.C_Currency_ID,
i.GrandTotal*i.MultiplierAP AS Amt, i.GrandTotal*i.MultiplierAP AS Amt,
invoiceOpen (i.C_Invoice_ID, i.C_InvoicePaySchedule_ID)*MultiplierAP AS OpenAmt, invoiceOpen (i.C_Invoice_ID, i.C_InvoicePaySchedule_ID)*i.MultiplierAP AS OpenAmt,
i.DateInvoiced AS DateDoc, i.DateInvoiced AS DateDoc,
COALESCE(daysBetween(getdate(),ips.DueDate), paymentTermDueDays(C_PaymentTerm_ID,DateInvoiced,getdate())) AS DaysDue, COALESCE(daysBetween(getdate(),ips.DueDate), paymentTermDueDays(C_PaymentTerm_ID,DateInvoiced,getdate())) AS DaysDue,
i.C_Campaign_ID, i.C_Project_ID, i.C_Activity_ID i.C_Campaign_ID, i.C_Project_ID, i.C_Activity_ID
FROM C_Invoice_v i FROM C_Invoice_v i
LEFT OUTER JOIN C_InvoicePaySchedule ips ON (i.C_InvoicePaySchedule_ID=ips.C_InvoicePaySchedule_ID) LEFT OUTER JOIN C_InvoicePaySchedule ips ON (i.C_InvoicePaySchedule_ID=ips.C_InvoicePaySchedule_ID)
WHERE IsPaid='N' WHERE i.IsPaid='N'
AND DocStatus IN ('CO','CL') AND i.DocStatus IN ('CO','CL')
UNION UNION
SELECT p.AD_Client_ID,p.AD_Org_ID, p.IsActive, p.Created,p.CreatedBy,p.Updated,p.UpdatedBy, SELECT p.AD_Client_ID,p.AD_Org_ID, p.IsActive, p.Created,p.CreatedBy,p.Updated,p.UpdatedBy,
p.C_BPartner_ID, p.C_Currency_ID, p.C_BPartner_ID, p.C_Currency_ID,
@ -29,3 +29,10 @@ WHERE p.IsAllocated='N' AND p.C_BPartner_ID IS NOT NULL

View File

@ -130,82 +130,93 @@ ALTER TABLE C_BPartner ADD DunningGrace date NULL;
ALTER TABLE C_Invoice ADD DunningGrace date NULL; ALTER TABLE C_Invoice ADD DunningGrace date NULL;
DROP VIEW c_invoiceline_v; DROP VIEW c_invoiceline_v;
DROP VIEW rv_bpartneropen; --DROP VIEW rv_bpartneropen;
DROP VIEW c_invoice_v; DROP VIEW c_invoice_v;
CREATE OR REPLACE VIEW c_invoice_v AS CREATE OR REPLACE VIEW C_INVOICE_V
SELECT i.c_invoice_id, i.ad_client_id, i.ad_org_id, i.isactive, i.created, i.createdby, i.updated, i.updatedby, i.issotrx, i.documentno, i.docstatus, i.docaction, i.processing, i.processed, i.c_doctype_id, i.c_doctypetarget_id, i.c_order_id, AS
i.description, i.isapproved, i.istransferred, i.salesrep_id, i.dateinvoiced, i.dateprinted, i.dateacct, i.c_bpartner_id, i.c_bpartner_location_id, i.ad_user_id, i.poreference, i.dateordered, i.c_currency_id, i.c_conversiontype_id, i.paymentrule, SELECT i.C_Invoice_ID, i.AD_Client_ID, i.AD_Org_ID, i.IsActive, i.Created, i.CreatedBy, i.Updated, i.UpdatedBy,
i.c_paymentterm_id, i.c_charge_id, i.m_pricelist_id, i.c_campaign_id, i.c_project_id, i.c_activity_id, i.isprinted, i.isdiscountprinted, i.ispaid, i.isindispute, i.ispayschedulevalid, NULL::numeric AS c_invoicepayschedule_id, i.invoicecollectiontype, i.dunninggrace, i.IsSOTrx, i.DocumentNo, i.DocStatus, i.DocAction, i.Processing, i.Processed, i.C_DocType_ID,
CASE i.C_DocTypeTarget_ID, i.C_Order_ID, i.Description, i.IsApproved, i.IsTransferred,
WHEN charat(d.docbasetype::character varying, 3)::text = 'C'::text THEN i.chargeamt * -1::numeric i.SalesRep_ID, i.DateInvoiced, i.DatePrinted, i.DateAcct, i.C_BPartner_ID, i.C_BPartner_Location_ID,
ELSE i.chargeamt i.AD_User_ID, i.POReference, i.DateOrdered, i.C_Currency_ID, i.C_ConversionType_ID, i.PaymentRule,
END AS chargeamt, i.C_PaymentTerm_ID, i.C_Charge_ID, i.M_PriceList_ID, i.C_Campaign_ID, i.C_Project_ID,
CASE i.C_Activity_ID, i.IsPrinted, i.IsDiscountPrinted, i.IsPaid, i.IsInDispute,
WHEN charat(d.docbasetype::character varying, 3)::text = 'C'::text THEN i.totallines * -1::numeric i.IsPayScheduleValid, cast(null as numeric) AS C_InvoicePaySchedule_ID, i.InvoiceCollectionType,i.DunningGrace
ELSE i.totallines cast(CASE WHEN charAt(d.DocBaseType,3)='C' THEN i.ChargeAmt*-1 ELSE i.ChargeAmt END as numeric) AS ChargeAmt,
END AS totallines, cast(CASE WHEN charAt(d.DocBaseType,3)='C' THEN i.TotalLines*-1 ELSE i.TotalLines END as numeric) AS TotalLines,
CASE cast(CASE WHEN charAt(d.DocBaseType,3)='C' THEN i.GrandTotal*-1 ELSE i.GrandTotal END as numeric) AS GrandTotal,
WHEN charat(d.docbasetype::character varying, 3)::text = 'C'::text THEN i.grandtotal * -1::numeric cast(CASE WHEN charAt(d.DocBaseType,3)='C' THEN -1 ELSE 1 END as numeric) AS Multiplier,
ELSE i.grandtotal cast(CASE WHEN charAt(d.DocBaseType,2)='P' THEN -1 ELSE 1 END AS numeric) as MultiplierAP,
END AS grandtotal, d.DocBaseType
CASE FROM C_Invoice i
WHEN charat(d.docbasetype::character varying, 3)::text = 'C'::text THEN -1 INNER JOIN C_DocType d ON (i.C_DocType_ID=d.C_DocType_ID)
ELSE 1 WHERE i.IsPayScheduleValid<>'Y'
END::numeric AS multiplier, UNION
CASE SELECT i.C_Invoice_ID, i.AD_Client_ID, i.AD_Org_ID, i.IsActive, i.Created, i.CreatedBy, i.Updated, i.UpdatedBy,
WHEN charat(d.docbasetype::character varying, 2)::text = 'P'::text THEN -1 i.IsSOTrx, i.DocumentNo, i.DocStatus, i.DocAction, i.Processing, i.Processed, i.C_DocType_ID,
ELSE 1 i.C_DocTypeTarget_ID, i.C_Order_ID, i.Description, i.IsApproved, i.IsTransferred,
END::numeric AS multiplierap, d.docbasetype i.SalesRep_ID, i.DateInvoiced, i.DatePrinted, i.DateAcct, i.C_BPartner_ID, i.C_BPartner_Location_ID,
FROM c_invoice i i.AD_User_ID, i.POReference, i.DateOrdered, i.C_Currency_ID, i.C_ConversionType_ID, i.PaymentRule,
JOIN c_doctype d ON i.c_doctype_id = d.c_doctype_id i.C_PaymentTerm_ID, i.C_Charge_ID, i.M_PriceList_ID, i.C_Campaign_ID, i.C_Project_ID,
WHERE i.ispayschedulevalid <> 'Y'::bpchar i.C_Activity_ID, i.IsPrinted, i.IsDiscountPrinted, i.IsPaid, i.IsInDispute,
UNION i.IsPayScheduleValid, ips.C_InvoicePaySchedule_ID, i.InvoiceCollectionType, i.DunningGrace
SELECT i.c_invoice_id, i.ad_client_id, i.ad_org_id, i.isactive, i.created, i.createdby, i.updated, i.updatedby, i.issotrx, i.documentno, i.docstatus, i.docaction, i.processing, i.processed, i.c_doctype_id, i.c_doctypetarget_id, i.c_order_id, null AS ChargeAmt,
i.description, i.isapproved, i.istransferred, i.salesrep_id, i.dateinvoiced, i.dateprinted, i.dateacct, i.c_bpartner_id, i.c_bpartner_location_id, i.ad_user_id, i.poreference, i.dateordered, i.c_currency_id, i.c_conversiontype_id, i.paymentrule, null AS TotalLines,
i.c_paymentterm_id, i.c_charge_id, i.m_pricelist_id, i.c_campaign_id, i.c_project_id, i.c_activity_id, i.isprinted, i.isdiscountprinted, i.ispaid, i.isindispute, i.ispayschedulevalid, ips.c_invoicepayschedule_id, i.invoicecollectiontype, i.dunninggrace, CASE WHEN charAt(d.DocBaseType,3)='C' THEN ips.DueAmt*-1 ELSE ips.DueAmt END AS GrandTotal,
NULL::"unknown" AS chargeamt, NULL::"unknown" AS totallines, CASE WHEN charAt(d.DocBaseType,3)='C' THEN -1 ELSE 1 END AS Multiplier,
CASE CASE WHEN charAt(d.DocBaseType,2)='P' THEN -1 ELSE 1 END AS MultiplierAP,
WHEN charat(d.docbasetype::character varying, 3)::text = 'C'::text THEN ips.dueamt * -1::numeric d.DocBaseType
ELSE ips.dueamt FROM C_Invoice i
END AS grandtotal, INNER JOIN C_DocType d ON (i.C_DocType_ID=d.C_DocType_ID)
CASE INNER JOIN C_InvoicePaySchedule ips ON (i.C_Invoice_ID=ips.C_Invoice_ID)
WHEN charat(d.docbasetype::character varying, 3)::text = 'C'::text THEN -1 WHERE i.IsPayScheduleValid='Y'
ELSE 1 AND ips.IsValid='Y';
END AS multiplier,
CASE CREATE OR REPLACE VIEW C_INVOICELINE_V AS
WHEN charat(d.docbasetype::character varying, 2)::text = 'P'::text THEN -1 SELECT il.AD_Client_ID, il.AD_Org_ID,
ELSE 1 il.C_InvoiceLine_ID, i.C_Invoice_ID, i.SalesRep_ID,
END AS multiplierap, d.docbasetype i.C_BPartner_ID, il.M_Product_ID,
FROM c_invoice i i.DocumentNo, i.DateInvoiced, i.DateAcct,
JOIN c_doctype d ON i.c_doctype_id = d.c_doctype_id i.IsSOTrx, i.DocStatus,
JOIN c_invoicepayschedule ips ON i.c_invoice_id = ips.c_invoice_id ROUND(i.Multiplier*LineNetAmt, 2) AS LineNetAmt,
WHERE i.ispayschedulevalid = 'Y'::bpchar AND ips.isvalid = 'Y'::bpchar; ROUND(i.Multiplier*PriceList*QtyInvoiced, 2) AS LineListAmt,
CASE WHEN COALESCE(il.PriceLimit, 0)=0 THEN ROUND(i.Multiplier*LineNetAmt,2) ELSE ROUND(i.Multiplier*il.PriceLimit*il.QtyInvoiced,2) END AS LineLimitAmt,
ROUND(i.Multiplier*il.PriceList*ilQtyInvoiced-il.LineNetAmt,2) AS LineDiscountAmt,
CASE WHEN COALESCE(il.PriceLimit,0)=0 THEN 0 ELSE ROUND(i.Multiplier*il.LineNetAmt-il.PriceLimit*il.QtyInvoiced,2) END AS LineOverLimitAmt,
il.QtyInvoiced, il.QtyEntered,
il.Line, il.C_OrderLine_ID, il.C_UOM_ID,
il.C_Campaign_ID, il.C_Project_ID, il.C_Activity_ID, il.C_ProjectPhase_ID, il.C_ProjectTask_ID
FROM C_Invoice_v i, C_InvoiceLine il
WHERE i.C_Invoice_ID=il.C_Invoice_ID;
--COMMENT ON TABLE C_INVOICELINE_V IS 'Invoice Line Summary for Reporting Views - Corrected for Credit Memos';
CREATE OR REPLACE VIEW c_invoiceline_v AS CREATE OR REPLACE VIEW RV_BPARTNEROPEN
SELECT il.ad_client_id, il.ad_org_id, il.c_invoiceline_id, i.c_invoice_id, i.salesrep_id, i.c_bpartner_id, il.m_product_id, i.documentno, i.dateinvoiced, i.dateacct, i.issotrx, i.docstatus, round(i.multiplier * il.linenetamt, 2) AS linenetamt, round(i.multiplier * il.pricelist * il.qtyinvoiced, 2) AS linelistamt, (AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
CASE UPDATED, UPDATEDBY, C_BPARTNER_ID, C_CURRENCY_ID, AMT,
WHEN COALESCE(il.pricelimit, 0::numeric) = 0::numeric THEN round(i.multiplier * il.linenetamt, 2) OPENAMT, DATEDOC, DAYSDUE, C_CAMPAIGN_ID, C_PROJECT_ID,
ELSE round(i.multiplier * il.pricelimit * il.qtyinvoiced, 2) C_ACTIVITY_ID)
END AS linelimitamt, round(i.multiplier * il.pricelist * il.qtyinvoiced - il.linenetamt, 2) AS linediscountamt, AS
CASE SELECT i.AD_Client_ID,i.AD_Org_ID, i.IsActive, i.Created,i.CreatedBy,i.Updated,i.UpdatedBy,
WHEN COALESCE(il.pricelimit, 0::numeric) = 0::numeric THEN 0::numeric i.C_BPartner_ID, i.C_Currency_ID,
ELSE round(i.multiplier * il.linenetamt - il.pricelimit * il.qtyinvoiced, 2) i.GrandTotal*i.MultiplierAP AS Amt,
END AS lineoverlimitamt, il.qtyinvoiced, il.qtyentered, il.line, il.c_orderline_id, il.c_uom_id, il.c_campaign_id, il.c_project_id, il.c_activity_id, il.c_projectphase_id, il.c_projecttask_id invoiceOpen (i.C_Invoice_ID, i.C_InvoicePaySchedule_ID)*i.MultiplierAP AS OpenAmt,
FROM c_invoice_v i, c_invoiceline il i.DateInvoiced AS DateDoc,
WHERE i.c_invoice_id = il.c_invoice_id; COALESCE(daysBetween(getdate(),ips.DueDate), paymentTermDueDays(C_PaymentTerm_ID,DateInvoiced,getdate())) AS DaysDue,
i.C_Campaign_ID, i.C_Project_ID, i.C_Activity_ID
FROM C_Invoice_v i
CREATE OR REPLACE VIEW rv_bpartneropen AS LEFT OUTER JOIN C_InvoicePaySchedule ips ON (i.C_InvoicePaySchedule_ID=ips.C_InvoicePaySchedule_ID)
SELECT i.ad_client_id, i.ad_org_id, i.isactive, i.created, i.createdby, i.updated, i.updatedby, i.c_bpartner_id, i.c_currency_id, i.grandtotal * i.multiplierap AS amt, invoiceopen(i.c_invoice_id, i.c_invoicepayschedule_id) * i.multiplierap AS openamt, i.dateinvoiced AS datedoc, COALESCE(daysbetween(getdate(), ips.duedate::timestamp with time zone), paymenttermduedays(i.c_paymentterm_id, i.dateinvoiced::timestamp with time zone, getdate())) AS daysdue, i.c_campaign_id, i.c_project_id, i.c_activity_id WHERE i.IsPaid='N'
FROM c_invoice_v i AND i.DocStatus IN ('CO','CL')
LEFT JOIN c_invoicepayschedule ips ON i.c_invoicepayschedule_id = ips.c_invoicepayschedule_id UNION
WHERE i.ispaid = 'N'::bpchar AND (i.docstatus = ANY (ARRAY['CO'::bpchar, 'CL'::bpchar])) SELECT p.AD_Client_ID,p.AD_Org_ID, p.IsActive, p.Created,p.CreatedBy,p.Updated,p.UpdatedBy,
UNION p.C_BPartner_ID, p.C_Currency_ID,
SELECT p.ad_client_id, p.ad_org_id, p.isactive, p.created, p.createdby, p.updated, p.updatedby, p.c_bpartner_id, p.c_currency_id, p.payamt * p.multiplierap::numeric * -1::numeric AS amt, paymentavailable(p.c_payment_id) * p.multiplierap::numeric * -1::numeric AS openamt, p.datetrx AS datedoc, NULL::"unknown" AS daysdue, p.c_campaign_id, p.c_project_id, p.c_activity_id p.PayAmt*MultiplierAP*-1 AS Amt,
FROM c_payment_v p paymentAvailable(p.C_Payment_ID)*p.MultiplierAP*-1 AS OpenAmt,
WHERE p.isallocated = 'N'::bpchar AND p.c_bpartner_id IS NOT NULL AND (p.docstatus = ANY (ARRAY['CO'::bpchar, 'CL'::bpchar])); p.DateTrx AS DateDoc,
null,
p.C_Campaign_ID, p.C_Project_ID, p.C_Activity_ID
COMMIT ; FROM C_Payment_v p
WHERE p.IsAllocated='N' AND p.C_BPartner_ID IS NOT NULL