Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WITH so_brand AS (
- SELECT A.so_id, B.group_brand, string_agg(f_get_brand_code(A.brand_id), ', ') AS brand
- FROM sl_so_brand_item A
- INNER JOIN m_brand_ext B ON A.brand_id = B.brand_id
- GROUP BY A.so_id, B.group_brand
- )
- 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,
- 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,
- f_get_role_name(D.current_role_id) AS current_role, B.status_doc, A.status_settlement, A.so_settlement_id, A.status_picking,
- A.status_do, A.do_id, A.status_log_book, A.log_book_id, A.status_invoice, A.invoice_id, E.flg_auto_settle,
- G.brand AS brand_code, G.group_brand, B.ext_doc_no,
- 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,
- f_get_status_cetak_report(A.so_id, B.doc_type_id, 'FormDeliveryOrderFromInvoiceEscp' ) AS status_print_do,
- COALESCE(H.doc_no, '-') AS log_book_no, COALESCE(H.doc_date, '-') AS log_book_date,
- CASE WHEN (E.flg_type_so = 'REG')
- THEN 'REGULAR'
- WHEN (E.flg_type_so = 'TRL')
- THEN 'TRIAL'
- WHEN (E.flg_type_so = 'FOC')
- THEN 'FOC'
- WHEN (E.flg_type_so = 'SMP')
- THEN 'SAMPEL'
- WHEN (E.flg_type_so = 'RVS')
- THEN 'REVISI'
- WHEN (E.flg_type_so = 'CON')
- THEN 'KONSINYASI'
- END AS type_so, f_get_username(B.create_user_id) AS create_username, COALESCE(I.doc_no, '-') AS delivery_order_no,
- f_get_total_jenis_sku_of_so(B.tenant_id, A.so_id) AS total_jenis_sku_so, E.remark_internal, E.remark_settlement,
- CASE WHEN EXISTS ( SELECT TRUE FROM in_do_receipt WHERE ref_id = A.do_id )
- THEN 'Y'
- ELSE 'N'
- END AS flg_do_receipt,
- f_get_total_qty_do_sob_by_so_id(A.so_id)
- FROM sl_so_status A
- INNER JOIN sl_so B ON A.so_id = B.so_id
- INNER JOIN awe_currdoc_status D ON B.tenant_id = D.tenant_id AND D.scheme = 'FA98' AND B.so_id = D.doc_id
- INNER JOIN sl_so_info E ON A.so_id = E.so_id
- INNER JOIN so_brand G ON B.so_id = G.so_id
- LEFT JOIN in_log_book H ON A.log_book_id = H.log_book_id
- LEFT JOIN sl_do I ON B.so_id = I.ref_id AND B.doc_type_id = I.ref_doc_type_id
- WHERE A.tenant_id = 10
- AND A.ou_id = 10
- AND A.doc_date BETWEEN '20210426' AND '20210427'
- AND ( UPPER(f_get_partner_code(A.partner_id)) LIKE '%GAYA BARU%'
- OR
- UPPER(f_get_partner_name(A.partner_id)) LIKE '%GAYA BARU%')
- ORDER BY B.doc_date, B.doc_no ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement