Skip to content

Commit

Permalink
#6713 Fixed failing function due to wrong column name.
Browse files Browse the repository at this point in the history
  • Loading branch information
dragospodariu96 committed May 26, 2020
1 parent 5c9ed8b commit c35aac5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,58 +82,64 @@ $$
LANGUAGE SQL STABLE
;

DROP FUNCTION IF EXISTS de_metas_endcustomer_fresh_reports.Docs_Sales_DD_Order_Details_HU ( IN Record_ID numeric, IN AD_Language Character Varying (6) );
DROP TABLE IF EXISTS de_metas_endcustomer_fresh_reports.Docs_Sales_DD_Order_Details_HU;
DROP FUNCTION IF EXISTS de_metas_endcustomer_fresh_reports.Docs_Sales_DD_Order_Details_HU (IN Record_ID numeric, IN AD_Language Character Varying(6))
;

DROP TABLE IF EXISTS de_metas_endcustomer_fresh_reports.Docs_Sales_DD_Order_Details_HU
;

CREATE TABLE de_metas_endcustomer_fresh_reports.Docs_Sales_DD_Order_Details_HU
(
MovementQty numeric,
Name Character Varying,
UOMSymbol Character Varying (10),
Description Character Varying
);
MovementQty numeric,
Name Character Varying,
UOMSymbol Character Varying(10),
Description Character Varying
)
;


CREATE FUNCTION de_metas_endcustomer_fresh_reports.Docs_Sales_DD_Order_Details_HU ( IN Record_ID numeric, IN AD_Language Character Varying (6) )
RETURNS SETOF de_metas_endcustomer_fresh_reports.Docs_Sales_DD_Order_Details_HU AS
CREATE FUNCTION de_metas_endcustomer_fresh_reports.Docs_Sales_DD_Order_Details_HU(IN Record_ID numeric,
IN AD_Language Character Varying(6))
RETURNS SETOF de_metas_endcustomer_fresh_reports.Docs_Sales_DD_Order_Details_HU
AS
$$
SELECT
SUM(ddol.QtyEntered) AS MovementQty,
COALESCE(pt.Name, p.name) AS Name,
COALESCE(uomt.UOMSymbol, uom.UOMSymbol) AS UOMSymbol,
ddol.Description
FROM
DD_Order ddo
INNER JOIN DD_Orderline ddol ON ddo.DD_Order_ID = ddol.DD_Order_ID AND ddol.isActive = 'Y'
-- Product and its translation
LEFT OUTER JOIN M_Product p ON ddol.M_Product_ID = p.M_Product_ID AND p.isActive = 'Y'
LEFT OUTER JOIN M_Product_Trl pt ON ddol.M_Product_ID = pt.M_Product_ID AND pt.AD_Language = $2 AND pt.isActive = 'Y'
LEFT OUTER JOIN M_Product_Category pc ON p.M_Product_Category_ID = pc.M_Product_Category_ID AND pc.isActive = 'Y'
-- Unit of measurement and its translation
LEFT OUTER JOIN C_UOM uom ON ddol.C_UOM_ID = uom.C_UOM_ID AND uom.isActive = 'Y'
LEFT OUTER JOIN C_UOM_Trl uomt ON ddol.C_UOM_ID = uomt.C_UOM_ID AND uomt.AD_Language = $2 AND uomt.isActive = 'Y'
--ordering gebinde if config exists
LEFT OUTER JOIN C_BPartner bp ON ddo.C_BPartner_ID = bp.C_BPartner_ID AND bp.isActive = 'Y'
LEFT OUTER JOIN C_DocType dt ON ddo.C_DocType_ID = dt.C_DocType_ID and dt.isActive = 'Y'
LEFT OUTER JOIN C_DocLine_Sort dls ON dt.DocBaseType = dls.DocBaseType AND dls.isActive = 'Y'
AND EXISTS (
SELECT 0 FROM C_BP_DocLine_Sort bpdls
WHERE bpdls.C_DocLine_Sort_ID = dls.C_DocLine_Sort_ID AND bpdls.C_BPartner_ID = bp.C_BPartner_ID AND bpdls.isActive = 'Y'
)
LEFT OUTER JOIN C_DocLine_Sort_Item dlsi ON dls.C_DocLine_Sort_ID = dlsi.C_DocLine_Sort_ID AND dlsi.M_Product_ID = ddol.M_Product_ID AND dlsi.isActive = 'Y'

WHERE
ddo.DD_Order_ID = $1 AND ddo.isActive = 'Y'
AND pc.M_Product_Category_ID = getSysConfigAsNumeric('PackingMaterialProductCategoryID', ddol.AD_Client_ID, ddol.AD_Org_ID)
AND QtyEntered != 0 -- Don't display lines without a Qty. See 08293
GROUP BY
COALESCE(pt.Name, p.name), COALESCE(uomt.UOMSymbol, uom.UOMSymbol), dlsi.SeqNo, ddol.description
ORDER BY
dlsi.SeqNo NULLS LAST

SELECT SUM(ddol.QtyEntered) AS MovementQty,
COALESCE(pt.Name, p.name) AS Name,
COALESCE(uomt.UOMSymbol, uom.UOMSymbol) AS UOMSymbol,
ddol.Description
FROM DD_Order ddo
INNER JOIN DD_Orderline ddol ON ddo.DD_Order_ID = ddol.DD_Order_ID AND ddol.isActive = 'Y'
-- Product and its translation
LEFT OUTER JOIN M_Product p ON ddol.M_Product_ID = p.M_Product_ID AND p.isActive = 'Y'
LEFT OUTER JOIN M_Product_Trl pt ON ddol.M_Product_ID = pt.M_Product_ID AND pt.AD_Language = $2 AND pt.isActive = 'Y'
LEFT OUTER JOIN M_Product_Category pc ON p.M_Product_Category_ID = pc.M_Product_Category_ID AND pc.isActive = 'Y'
-- Unit of measurement and its translation
LEFT OUTER JOIN C_UOM uom ON ddol.C_UOM_ID = uom.C_UOM_ID AND uom.isActive = 'Y'
LEFT OUTER JOIN C_UOM_Trl uomt ON ddol.C_UOM_ID = uomt.C_UOM_ID AND uomt.AD_Language = $2 AND uomt.isActive = 'Y'
--ordering gebinde if config exists
LEFT OUTER JOIN C_BPartner bp ON ddo.C_BPartner_ID = bp.C_BPartner_ID AND bp.isActive = 'Y'
LEFT OUTER JOIN C_DocType dt ON ddo.C_DocType_ID = dt.C_DocType_ID AND dt.isActive = 'Y'
LEFT OUTER JOIN C_DocLine_Sort dls ON dt.DocBaseType = dls.DocBaseType AND dls.isActive = 'Y'
AND EXISTS(
SELECT 0
FROM C_BP_DocLine_Sort bpdls
WHERE bpdls.C_DocLine_Sort_ID = dls.C_DocLine_Sort_ID
AND bpdls.C_BPartner_ID = bp.C_BPartner_ID
AND bpdls.isActive = 'Y'
)
LEFT OUTER JOIN C_DocLine_Sort_Item dlsi ON dls.C_DocLine_Sort_ID = dlsi.C_DocLine_Sort_ID AND dlsi.M_Product_ID = ddol.M_Product_ID AND dlsi.isActive = 'Y'

WHERE ddo.DD_Order_ID = $1
AND ddo.isActive = 'Y'
AND pc.M_Product_Category_ID = getSysConfigAsNumeric('PackingMaterialProductCategoryID', ddol.AD_Client_ID, ddol.AD_Org_ID)
AND QtyEntered != 0 -- Don't display lines without a Qty. See 08293
GROUP BY COALESCE(pt.Name, p.name), COALESCE(uomt.UOMSymbol, uom.UOMSymbol), dlsi.SeqNo, ddol.description
ORDER BY dlsi.SeqNo NULLS LAST

$$
LANGUAGE sql STABLE
LANGUAGE SQL STABLE
;

DROP FUNCTION IF EXISTS de_metas_endcustomer_fresh_reports.Docs_Sales_DD_Order_Details (IN Record_ID numeric, IN AD_Language Character Varying(6))
;

Expand Down Expand Up @@ -279,6 +285,7 @@ $$
LANGUAGE SQL
STABLE
;

DROP FUNCTION IF EXISTS de_metas_endcustomer_fresh_reports.Docs_Sales_DD_Order_Description (IN Record_ID numeric, IN AD_Language Character Varying(6))
;

Expand Down Expand Up @@ -356,6 +363,7 @@ WHERE ddo.dd_order_id = $1
$$
LANGUAGE SQL STABLE
;

--DROP FUNCTION IF EXISTS de_metas_endcustomer_fresh_reports.Docs_DD_Order_Details_Footer( IN DD_Order_ID numeric, IN AD_Language Character Varying (6) );
CREATE OR REPLACE FUNCTION de_metas_endcustomer_fresh_reports.Docs_DD_Order_Details_Footer(IN DD_Order_ID numeric,
IN AD_Language Character Varying(6))
Expand Down Expand Up @@ -395,12 +403,12 @@ FROM (
--Docnote TRL
SELECT NULL AS textleft,
CASE
WHEN ddo.descriptionbottom IS NOT NULL
WHEN ddo.description IS NOT NULL
THEN E'\n\n\n'
ELSE ''
END || dt.documentnote AS textcenter,
dt.ad_language AS language,
ddo.dd_order_id AS dd_order_id,
ddo.dd_order_id AS dd_order_id,
'docnote' AS tag,
3 AS pozition
FROM dd_order ddo
Expand All @@ -409,12 +417,12 @@ FROM (
UNION
---------------------------------------------------------------------------------------------
--Descriptionbottom
SELECT ddo.descriptionbottom AS textleft,
NULL AS textcenter,
NULL AS language,
ddo.dd_order_id AS dd_order_id,
'descr' AS tag,
2 AS pozition
SELECT ddo.description AS textleft,
NULL AS textcenter,
NULL AS language,
ddo.dd_order_id AS dd_order_id,
'descr' AS tag,
2 AS pozition
FROM dd_order ddo
WHERE ddo.isActive = 'Y'
) footer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ FROM (
--Docnote TRL
SELECT NULL AS textleft,
CASE
WHEN ddo.descriptionbottom IS NOT NULL
WHEN ddo.description IS NOT NULL
THEN E'\n\n\n'
ELSE ''
END || dt.documentnote AS textcenter,
Expand All @@ -51,7 +51,7 @@ FROM (
UNION
---------------------------------------------------------------------------------------------
--Descriptionbottom
SELECT ddo.descriptionbottom AS textleft,
SELECT ddo.description AS textleft,
NULL AS textcenter,
NULL AS language,
ddo.dd_order_id AS dd_order_id,
Expand Down

0 comments on commit c35aac5

Please sign in to comment.