Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WITH jurnal AS (
- SELECT SUBSTRING(B.doc_date, 1, 6) AS date_year_month, A.product_id,
- SUM(CASE WHEN A.sign_journal = 'D' THEN A.qty ELSE -1 * A.qty END) AS qty,
- SUM(CASE WHEN A.sign_journal = 'D' THEN A.gl_amount ELSE -1 * A.gl_amount END) AS gl_amount
- FROM gl_journal_trx_item A
- INNER JOIN gl_journal_trx B ON A.journal_trx_id = B.journal_trx_id
- WHERE SUBSTRING(B.doc_date, 1, 6) = '201709' AND
- B.tenant_id = 10 AND
- B.ou_bu_id = 10 AND
- doc_type_id = 311
- AND A.coa_id IN (
- SELECT coa_id
- FROM m_group_product
- )
- GROUP BY SUBSTRING(B.doc_date, 1, 6), A.product_id
- ), summary AS (
- SELECT date_year_month, product_id,
- SUM(qty) AS qty,
- SUM(gl_amount) AS gl_amount
- FROM in_summary_monthly_amount
- WHERE date_year_month = '201709' AND
- ou_bu_id = 10 AND
- tenant_id = 10 AND
- doc_type_id = 311
- GROUP BY date_year_month, product_id
- )
- SELECT A.date_year_month, A.product_id, A.qty, B.qty, A.gl_amount, B.gl_amount
- FROM summary A
- FULL OUTER JOIN jurnal B ON A.product_id = B.product_id AND
- A.date_year_month = B.date_year_month
- WHERE (B.qty IS NULL OR B.gl_amount IS NULL)
- OR (A.qty <> B.qty OR A.gl_amount <> B.gl_amount)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement