Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
820 B
1
Indexable
Never
SELECT
    pmp.product_id AS id,
    pmp.brand,
    pmp.item_code,
    pmp.product,
    MAX(pmp.onhand) AS onhand,
    MAX(pmp.incoming) AS incoming,
    MAX(pmp.outgoing) AS outgoing,
    pmp.action,
    sub.vendor_id,
    MAX(pjs.status_apo) AS status_apo
FROM v_procurement_monitoring_by_product pmp
LEFT JOIN purchasing_job_state pjs ON pjs.purchasing_job_id = pmp.product_id
LEFT JOIN (
    SELECT
        vso.product_id,
        rp.id AS vendor_id
    FROM v_sales_outstanding vso
    LEFT JOIN sale_order_line sol ON sol.id = vso.sale_line_id
    LEFT JOIN res_partner rp ON rp.id = sol.vendor_id
) AS sub ON sub.product_id = pmp.product_id
WHERE pmp.action = 'kurang'
GROUP BY
    pmp.product_id,
    pmp.brand,
    pmp.item_code,
    pmp.product,
    pmp.action,
    sub.vendor_id;
Leave a Comment