work
This commit is contained in:
parent
397b309a55
commit
85e288cf11
@ -81,37 +81,96 @@ GROUP BY
|
|||||||
)
|
)
|
||||||
-----------since joining to the item master will be differnt for the last bulk columm---------------
|
-----------since joining to the item master will be differnt for the last bulk columm---------------
|
||||||
-----------must first pivot the data out then join based on the type of row-------------------------
|
-----------must first pivot the data out then join based on the type of row-------------------------
|
||||||
|
,unpivot AS (
|
||||||
|
SELECT
|
||||||
|
pc.stlc
|
||||||
|
,pc.coltier
|
||||||
|
,pc.branding
|
||||||
|
,pc.accs
|
||||||
|
,pc.suffix
|
||||||
|
,pc.pckg1 pckg
|
||||||
|
,pc.vol1_uom vol_uom
|
||||||
|
FROM
|
||||||
|
pc
|
||||||
|
UNION
|
||||||
|
SELECT
|
||||||
|
pc.stlc
|
||||||
|
,pc.coltier
|
||||||
|
,pc.branding
|
||||||
|
,pc.accs
|
||||||
|
,pc.suffix
|
||||||
|
,pc.pckg2 pckg
|
||||||
|
,pc.vol2_uom vol_uom
|
||||||
|
FROM
|
||||||
|
pc
|
||||||
|
UNION
|
||||||
|
SELECT
|
||||||
|
pc.stlc
|
||||||
|
,pc.coltier
|
||||||
|
,pc.branding
|
||||||
|
,pc.accs
|
||||||
|
,pc.suffix
|
||||||
|
,pc.pckg3 pckg
|
||||||
|
,pc.vol3_uom vol_uom
|
||||||
|
FROM
|
||||||
|
pc
|
||||||
|
)
|
||||||
|
----link to actual part numbers, tag the sequence so a single item can be chosen-----
|
||||||
,items_init AS (
|
,items_init AS (
|
||||||
SELECT
|
SELECT
|
||||||
pc.STLC
|
up.STLC
|
||||||
,pc.coltier
|
,up.coltier
|
||||||
,pc.branding
|
,up.branding
|
||||||
,pc.accs
|
,up.accs
|
||||||
,pc.suffix
|
,up.suffix
|
||||||
,row_number() OVER (PARTITION BY pc.stlc, pc.coltier, pc.branding, pc.accs, pc.suffix ORDER BY item DESC) seq
|
,up.pckg
|
||||||
|
,up.vol_uom
|
||||||
|
,row_number() OVER (PARTITION BY up.stlc, up.coltier, up.branding, up.accs, up.suffix ORDER BY item DESC) seq
|
||||||
,item
|
,item
|
||||||
,vol1_uom
|
|
||||||
,vol2_uom
|
|
||||||
,vol3_uom
|
|
||||||
,'PC' to_uom
|
|
||||||
FROM
|
FROM
|
||||||
pc
|
unpivot up
|
||||||
LEFT OUTER JOIN RLARP.ITEMMv i ON
|
LEFT OUTER JOIN RLARP.ITEMMv i ON
|
||||||
i.STLC = pc.stlc
|
i.STLC = up.stlc
|
||||||
--AND i.COLTIER = pc.coltier
|
--AND i.COLTIER = pc.coltier
|
||||||
AND COALESCE(i.BRANDING,'') = pc.branding
|
AND i.uomp ? up.pckg
|
||||||
AND COALESCE(i.ACCS,'') = pc.ACCS
|
AND COALESCE(i.BRANDING,'') = up.branding
|
||||||
AND COALESCE(i.SUFFIX,'') = pc.suffix
|
AND COALESCE(i.ACCS,'') = up.ACCS
|
||||||
|
AND COALESCE(i.SUFFIX,'') = up.suffix
|
||||||
AND APLNT <> 'I'
|
AND APLNT <> 'I'
|
||||||
)
|
)
|
||||||
|
----compile all the conversions into a single json object
|
||||||
,items AS (
|
,items AS (
|
||||||
SELECT * FROM items_init where seq = 1
|
SELECT
|
||||||
|
jsonb_agg( DISTINCT
|
||||||
|
jsonb_build_object(
|
||||||
|
'partn', item
|
||||||
|
,'fu', vol_uom
|
||||||
|
,'tu','PC'
|
||||||
|
)
|
||||||
|
) conv
|
||||||
|
FROM
|
||||||
|
items_init
|
||||||
|
WHERE
|
||||||
|
seq = 1
|
||||||
|
AND COALESCE(item,'') <> ''
|
||||||
)
|
)
|
||||||
,uom AS (
|
, conversion AS (
|
||||||
SELECT item partn, vol1_uom from_uom, 'pc' to_uom FROM items_init
|
SELECT
|
||||||
UNION ALL
|
rslt.*
|
||||||
SELECT item partn, vol2_uom from_uom, 'pc' to_uom FROM items_init
|
FROM
|
||||||
UNION ALL
|
items
|
||||||
SELECT item partn, vol3_uom from_uom, 'pc' to_uom FROM items_init
|
JOIN LATERAL rlarp.uom_array(conv) rslt ON true
|
||||||
)
|
)
|
||||||
SELECT * FROM uom
|
--SELECT * FROM conversion
|
||||||
|
SELECT
|
||||||
|
i.*
|
||||||
|
,c.*
|
||||||
|
FROM
|
||||||
|
items_init i
|
||||||
|
LEFT OUTER JOIN conversion c ON
|
||||||
|
c.p = i.item
|
||||||
|
WHERE
|
||||||
|
i.seq = 1
|
||||||
|
ORDER BY
|
||||||
|
stlc
|
||||||
|
,coltier
|
||||||
|
Loading…
Reference in New Issue
Block a user