Advertisement
aadddrr

Untitled

Feb 15th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. WITH jurnal AS (
  2.     SELECT SUBSTRING(B.doc_date, 1, 6) AS date_year_month, A.product_id,
  3.         SUM(CASE WHEN A.sign_journal = 'D' THEN A.qty ELSE -1 * A.qty END) AS qty,
  4.         SUM(CASE WHEN A.sign_journal = 'D' THEN A.gl_amount ELSE -1 * A.gl_amount END) AS gl_amount
  5.     FROM gl_journal_trx_item A
  6.     INNER JOIN gl_journal_trx B ON A.journal_trx_id = B.journal_trx_id
  7.     WHERE SUBSTRING(B.doc_date, 1, 6)  = '201709' AND
  8.           B.tenant_id = 10 AND
  9.           B.ou_bu_id = 10  AND
  10.           doc_type_id = 311
  11.         AND A.coa_id IN (
  12.             SELECT coa_id
  13.             FROM m_group_product
  14.         )
  15.     GROUP BY SUBSTRING(B.doc_date, 1, 6), A.product_id
  16. ), summary AS (
  17.     SELECT date_year_month, product_id,
  18.         SUM(qty) AS qty,
  19.         SUM(gl_amount) AS gl_amount
  20.     FROM in_summary_monthly_amount
  21.     WHERE date_year_month  = '201709' AND
  22.           ou_bu_id = 10 AND
  23.           tenant_id = 10 AND
  24.           doc_type_id = 311
  25.     GROUP BY date_year_month, product_id
  26. )
  27. SELECT A.date_year_month, A.product_id, A.qty, B.qty, A.gl_amount, B.gl_amount
  28. FROM summary A
  29. FULL OUTER JOIN jurnal B ON A.product_id = B.product_id AND
  30.      A.date_year_month = B.date_year_month
  31. WHERE (B.qty IS NULL OR B.gl_amount IS NULL)
  32.     OR (A.qty <> B.qty OR A.gl_amount <> B.gl_amount)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement