2013-03-19 01:50:27 +07:00
|
|
|
CREATE OR REPLACE FUNCTION get1099bucket (
|
2013-03-06 01:40:43 +07:00
|
|
|
p_cbpartner_id IN numeric,
|
|
|
|
p_cut_date IN timestamp with time zone,
|
|
|
|
p_bucket IN numeric
|
|
|
|
)
|
|
|
|
RETURNS numeric
|
|
|
|
AS
|
|
|
|
$BODY$
|
|
|
|
DECLARE
|
|
|
|
tmpvar numeric;
|
|
|
|
/******************************************************************************
|
2013-03-19 01:50:27 +07:00
|
|
|
NAME: get1099bucket
|
2013-03-06 01:40:43 +07:00
|
|
|
PURPOSE:
|
|
|
|
|
|
|
|
REVISIONS:
|
|
|
|
Ver Date Author Description
|
|
|
|
--------- ---------- --------------- ------------------------------------
|
|
|
|
1.0 04/01/2008 Carlos Ruiz 1. Created this function.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
BEGIN
|
|
|
|
SELECT SUM ( (COALESCE (linenetamt, 0) + COALESCE (taxamt, 0))
|
|
|
|
* (CASE WHEN docbasetype = 'API' THEN 1
|
|
|
|
WHEN docbasetype = 'APC' THEN -1
|
|
|
|
ELSE 0
|
|
|
|
END)
|
|
|
|
) -- +API->AP Invoice / -APC->AP Credit Memo
|
|
|
|
INTO tmpvar
|
2013-03-19 01:50:27 +07:00
|
|
|
FROM C_INVOICE i, C_INVOICELINE il, C_1099BOX b, C_DOCTYPE dt
|
2013-03-06 01:40:43 +07:00
|
|
|
WHERE i.c_invoice_id = il.c_invoice_id
|
|
|
|
AND i.issotrx = 'N'
|
2013-03-19 01:50:27 +07:00
|
|
|
AND il.c_1099box_id = b.c_1099box_id
|
2013-03-06 01:40:43 +07:00
|
|
|
AND i.dateacct BETWEEN TRUNC (p_cut_date, 'YEAR') AND p_cut_date
|
|
|
|
AND c_bpartner_id = p_cbpartner_id
|
|
|
|
AND b.bucket = p_bucket
|
|
|
|
AND i.c_doctype_id = dt.c_doctype_id
|
|
|
|
AND i.docstatus IN ('CO', 'CL');
|
|
|
|
|
|
|
|
RETURN tmpvar;
|
|
|
|
END;
|
|
|
|
$BODY$
|
2014-05-31 00:11:20 +07:00
|
|
|
LANGUAGE plpgsql STABLE
|
2013-03-06 01:40:43 +07:00
|
|
|
;
|
|
|
|
|