Last active
February 1, 2022 13:25
-
-
Save nhwaani/0734ca7d47f2e47ceaea6d9c1cb80f44 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with container_item_qty as ( | |
SELECT itb.barcode as container, itl.barcode as barcode, itb.id_doc_source, count(itl.barcode) as qty | |
FROM noondwh.wms.item_box itb | |
LEFT JOIN noondwh.wms.item_box_contents ibc ON (ibc.id_item_box_container = itb.id_item_box) AND itb.id_state =4 | |
LEFT JOIN noondwh.wms.item itm ON (itm.id_item, itm.id_item_kind) = (ibc.id_item_inner, 1) | |
LEFT JOIN noondwh.wms.item_lot itl ON itm.id = itl.id_item_lot | |
LEFT JOIN noondwh.wms.doc d ON (d.id_doc = itb.id_doc_source) AND d.id_state = 5 | |
LEFT JOIN noondwh.wms.doc_tag dt USING (id_doc_tag) | |
LEFT JOIN noondwh.wms.warehouse w USING (id_warehouse) | |
WHERE 1=1 | |
AND itb.id_item_box_type = 2 | |
AND w.code = 'DXBG03' | |
AND dt.code like 'dispose%' | |
GROUP BY 1, 2, 3 | |
HAVING qty > 0 | |
) | |
SELECT d.id_doc, itl.barcode, itb.barcode as container, z_pck.code as zone_pick, z_put.code as zone_put, tt.code as tote, | |
upc.username as user_pick, upt.username as user_put, cci.qty | |
FROM noondwh.wms.stock_doc_line sdl | |
LEFT JOIN noondwh.wms.doc d USING (id_doc) | |
LEFT JOIN noondwh.wms.job j USING (id_doc) | |
LEFT JOIN noondwh.wms.doc_tag dt USING (id_doc_tag) | |
LEFT JOIN noondwh.wms.location l_pck ON l_pck.id_location = sdl.id_location_pick | |
LEFT JOIN noondwh.wms.zone z_pck ON z_pck.id_zone = l_pck.id_zone | |
LEFT JOIN noondwh.wms.warehouse w ON w.id_warehouse = d.id_warehouse | |
LEFT JOIN noondwh.wms.location l_put ON l_put.id_location = sdl.id_location_put | |
LEFT JOIN noondwh.wms.zone z_put ON z_put.id_zone = l_put.id_zone | |
LEFT JOIN noondwh.wms.job_pick jpc ON (j.id_job = jpc.id_job) | |
LEFT JOIN noondwh.wms.user upc ON (upc.id_user = jpc.id_user) | |
LEFT JOIN noondwh.wms.job_put jpt ON (j.id_job = jpt.id_job) | |
LEFT JOIN noondwh.wms.user upt ON (upt.id_user = jpt.id_user) | |
LEFT JOIN noondwh.wms.item itm ON (itm.id_item , itm.id_item_kind) = (sdl.id_item , 1) | |
LEFT JOIN noondwh.wms.item_lot itl ON (itm.id, itm.id_item_kind) = (itl.id_item_lot , 1) | |
LEFT JOIN noondwh.wms.item_box itb ON (itb.id_doc_source ,itb.id_item_box_type , itb.id_state) = (d.id_doc , 2 , 4) | |
LEFT JOIN noondwh.wms.tote tt ON (tt.id_tote, tt.id_warehouse) = (j.id_tote, d.id_warehouse) | |
LEFT JOIN container_item_qty cci ON (cci.container, cci.barcode, cci.id_doc_source) = (itb.barcode, itl.barcode, itb.id_doc_source) | |
WHERE 1=1 | |
AND sdl.id_doc = 143151921 | |
AND itb.id_doc_source = 143151921 | |
AND z_pck.code LIKE 'STOCK%' | |
AND z_put.code = 'DISPOSE' | |
AND j.id_state =4 | |
and dt.code like 'dispose%' | |
and w.code = 'DXBG03' | |
AND cci.qty IS NOT NULL | |
GROUP by 1, 2, 3, 4, 5, 6, 7, 8 , 9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment