Advertisement
henikseptiana15

Query yg dijalankan untuk case video dari lina

Apr 27th, 2021
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. WITH so_brand AS (
  2.     SELECT A.so_id, B.group_brand, string_agg(f_get_brand_code(A.brand_id), ', ') AS brand
  3.     FROM sl_so_brand_item A
  4.     INNER JOIN m_brand_ext B ON A.brand_id = B.brand_id
  5.     GROUP BY A.so_id, B.group_brand
  6.  )
  7. SELECT A.so_id, A.tenant_id, A.ou_id, B.doc_no, B.doc_date, B.partner_id, f_get_partner_code(B.partner_id) AS partner_code,
  8.  f_get_partner_name(B.partner_id) AS partner_name, B.remark, f_get_total_brand_amount_include_tax_sob_by_so_id(A.so_id) AS so_amount,
  9.  f_get_role_name(D.current_role_id) AS current_role, B.status_doc, A.status_settlement, A.so_settlement_id, A.status_picking,
  10.  A.status_do, A.do_id, A.status_log_book, A.log_book_id, A.status_invoice, A.invoice_id, E.flg_auto_settle,
  11.  G.brand AS brand_code, G.group_brand, B.ext_doc_no,
  12.  f_get_partner_code(B.salesman_id) AS salesman_code, f_get_partner_name(B.salesman_id) AS salesman_name, A.version AS version_so_status,
  13.  f_get_status_cetak_report(A.so_id, B.doc_type_id, 'FormDeliveryOrderFromInvoiceEscp' ) AS status_print_do,
  14.  COALESCE(H.doc_no, '-') AS log_book_no, COALESCE(H.doc_date, '-') AS log_book_date,
  15.  CASE WHEN (E.flg_type_so = 'REG')  
  16.             THEN 'REGULAR'
  17.         WHEN (E.flg_type_so = 'TRL')  
  18.             THEN 'TRIAL'
  19.         WHEN (E.flg_type_so = 'FOC')  
  20.             THEN 'FOC'
  21.         WHEN (E.flg_type_so = 'SMP')  
  22.             THEN 'SAMPEL'
  23.         WHEN (E.flg_type_so = 'RVS')  
  24.             THEN 'REVISI'
  25.         WHEN (E.flg_type_so = 'CON')  
  26.             THEN 'KONSINYASI'
  27.  END AS type_so, f_get_username(B.create_user_id) AS create_username, COALESCE(I.doc_no, '-') AS delivery_order_no,
  28.  f_get_total_jenis_sku_of_so(B.tenant_id, A.so_id) AS total_jenis_sku_so, E.remark_internal, E.remark_settlement,
  29.  CASE WHEN EXISTS ( SELECT TRUE FROM in_do_receipt WHERE ref_id = A.do_id )
  30.  THEN 'Y'
  31.  ELSE 'N'
  32.  END AS flg_do_receipt,
  33.  f_get_total_qty_do_sob_by_so_id(A.so_id)
  34.  FROM sl_so_status A
  35.  INNER JOIN sl_so B ON A.so_id = B.so_id
  36.  INNER JOIN awe_currdoc_status D ON B.tenant_id = D.tenant_id AND D.scheme = 'FA98' AND B.so_id = D.doc_id
  37.  INNER JOIN sl_so_info E ON A.so_id = E.so_id
  38.  INNER JOIN so_brand G ON B.so_id = G.so_id
  39.  LEFT JOIN in_log_book H ON A.log_book_id = H.log_book_id
  40.  LEFT JOIN sl_do I ON B.so_id = I.ref_id AND B.doc_type_id = I.ref_doc_type_id
  41.  WHERE A.tenant_id = 10
  42.  AND A.ou_id = 10
  43.  AND A.doc_date BETWEEN '20210426' AND '20210427'
  44.  AND ( UPPER(f_get_partner_code(A.partner_id)) LIKE '%GAYA BARU%'
  45.        OR
  46.        UPPER(f_get_partner_name(A.partner_id)) LIKE '%GAYA BARU%')
  47.  ORDER BY B.doc_date, B.doc_no ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement