Advertisement
aadddrr

Ambil Harga Standar

Mar 6th, 2018
91
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) <= C.date_year_month
  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.date_year_month,
  22.         f_get_product_code(A.product_id), f_get_product_name(A.product_id), A.curr_code, A.nett_price_po
  23.     FROM tt_standard_price A
  24.     WHERE NOT EXISTS(
  25.         SELECT 1
  26.         FROM in_product_standard_cogs B
  27.         WHERE B.tenant_id = A.tenant_id
  28.             AND B.ou_id = A.ou_bu_id
  29.             AND B.year_month_date = A.date_year_month
  30.             AND B.product_id = A.product_id
  31.     )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement