aadddrr

Ambil Harga Standar

Feb 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. WITH tt_standard_price AS (
  2.         SELECT DISTINCT ON (C.date_year_month, C.product_id) B.doc_date, f_get_product_code(C.product_id) AS product_code,
  3.             f_get_product_name(C.product_id) AS product_name,
  4.             C.product_id, C.date_year_month,
  5.             A.curr_code, A.nett_price_po,
  6.             C.tenant_id, C.ou_bu_id
  7.         FROM in_summary_monthly_amount C
  8.         INNER JOIN pu_po_item A ON A.product_id = C.product_id AND A.tenant_id = C.tenant_id
  9.         INNER JOIN pu_po B ON A.po_id = B.po_id AND C.ou_bu_id = B.ou_id AND SUBSTR(B.doc_date, 1, 6) <= TO_CHAR(TO_DATE(C.date_year_month,'YYYYMM') - INTERVAL '1 Month','YYYYMM')
  10.         WHERE C.qty <> 0
  11.             AND C.gl_amount = 0
  12.             AND C.doc_type_id = 311
  13.         and not exists (
  14.             select 1 from in_summary_monthly_cogs B
  15.             where C.product_id = B.product_id
  16.                 and C.date_year_month = B.date_year_month
  17.                 and B.qty_total <> 0)
  18.         ORDER BY C.date_year_month, C.product_id, B.doc_date DESC
  19.  
  20.     )
  21.     SELECT A.tenant_id, A.ou_bu_id, A.date_year_month,
  22.         A.product_id, A.curr_code, A.nett_price_po, 0, '20180213152301', -1,
  23.         '20180213152301', -1
  24.     FROM tt_standard_price A
  25.     WHERE NOT EXISTS(
  26.         SELECT 1
  27.         FROM in_product_standard_cogs B
  28.         WHERE B.tenant_id = A.tenant_id
  29.             AND B.ou_id = A.ou_bu_id
  30.             AND B.year_month_date = A.date_year_month
  31.             AND B.product_id = A.product_id
  32.     )
Add Comment
Please, Sign In to add comment