You are on page 1of 11

DROP VIEW DGDEV.

S_CP_REQUEST_VOID_TRX_V;

/* Formatted on 11/6/2021 9:24:32 PM (QP5 v5.326) */


CREATE OR REPLACE FORCE VIEW DGDEV.S_CP_REQUEST_VOID_TRX_V
(
ID,
PROCESSED,
AD_TABLE_ID,
AD_WF_ACTIVITY_ID,
AD_CLIENT_ID,
AD_ORG_ID,
ISACTIVE,
CREATED,
CREATEDBY,
UPDATED,
UPDATEDBY,
AD_USER_ACCTMAKER,
AD_ROLE_ID,
C_BPARTNER_ID,
C_BPARTNER_LOCATION_ID,
LISTED,
SELF_TRADING_TYPE,
DOCUMENTNO,
C_DOCTYPE_ID,
C_DOCTYPE1_ID,
ASSET_TYPE,
PRODUCT_CATEGORY_ID,
PRODUCT_CATEGORY_NAME,
DATEACCT,
GRANDTOTAL,
DESCRIPTION,
REASON_REJECT,
C_SALESREGION_ID
)
BEQUEATH DEFINER
AS
SELECT req.id,
req.processed,
req.ad_table_id,
req.ad_wf_activity_id,
req.ad_client_id,
req.ad_org_id,
req.isactive,
req.created,
req.createdby,
req.updated,
req.updatedby,
req.ad_user_acctmaker, -- user ke toan
req.ad_role_id, -- role xu ly,
req.c_bpartner_id, -- role xu ly,
req.c_bpartner_location_id,
req.listed,
req.self_trading_type,
req.documentno, -- so chung tu,
req.c_doctype_id AS c_doctype_id, -- loai giao dich,
req.c_doctype1_id AS c_doctype1_id, -- loai giao dich,
req.asset_type, -- mmt.asset_type, -- muc dich nam giu
req.product_category_id, -- loai chung khoan
req.product_category_name, -- ten chung khoang
req.dateacct AS dateacct, -- m_in.dateacct, -- ngay hoach toan
req.grandtotal, -- m_in.grandtotal, -- so tien,
req.summary description,
req.reason_reject,
req.c_salesregion_id
FROM (SELECT rr.r_request_id AS id,
awac.processed,
awac.ad_table_id,
awac.ad_wf_activity_id,
awac.ad_client_id,
mi.ad_org_id,
awac.isactive,
awac.created,
awac.createdby,
mi.movementdate updated,
awac.updatedby,
mi.ad_user_id AS ad_user_acctmaker, -- user ke
toan
awr.ad_role_id, -- role xu ly,
rr.documentno, -- so chung tu,
awac.ad_table_id AS c_doctype_id, -- loai giao dich,
mi.c_doctype_id c_doctype1_id,
mi.c_bpartner_id,
mi.c_bpartner_location_id,
mi.listed,
mi.self_trading_type,
NULL AS asset_type, -- mmt.asset_type,
-- muc dich nam giu
mi.m_product_category_id AS product_category_id, -- loai
chung khoan
NULL AS product_category_name, -- ten
chung khoang
mi.dateacct, -- m_in.dateacct, -- ngay hoach toan
mi.grandtotal, -- m_in.grandtotal, -- so tien,
rr.summary,
mi.reason_reject,
mi.c_salesregion_id
FROM ad_wf_activity awac
JOIN ad_wf_responsible awr
ON awr.ad_wf_responsible_id =
awac.ad_wf_responsible_id
JOIN r_request rr
ON awac.ad_table_id = 417
AND awac.record_id = rr.r_request_id
JOIN m_inout mi
ON mi.m_inout_id = rr.record_id
AND rr.ad_table_id = 319
LEFT JOIN m_product_category mpc
ON mi.m_product_category_id =
mpc.m_product_category_id
WHERE awac.wfstate NOT IN ('CC', 'CT')
AND rr.docstatus NOT IN ('CO', 'CL', 'DR')
--and awac.processed = 'N'
AND mi.c_doctype_id IN (1000014, 1000011)
--danh gia lai, phan loai lai
UNION
SELECT rr.r_request_id AS id,
awac.processed,
awac.ad_table_id,
awac.ad_wf_activity_id,
awac.ad_client_id,
inv.ad_org_id,
awac.isactive,
awac.created,
awac.createdby,
inv.movementdate,
awac.updatedby,
inv.createdby AS ad_user_acctmaker, -- user
ke toan
awr.ad_role_id, -- role xu ly,
rr.documentno, -- so chung tu,
awac.ad_table_id AS c_doctype_id, -- loai giao
dich,
inv.c_doctype_id c_doctype1_id,
NULL c_bpartner_id,
NULL c_bpartner_location_id,
NULL listed,
inv.self_trading_type,
inv.asset_type AS asset_type, --
mmt.asset_type, -- muc dich nam giu
NULL AS product_category_id, --
loai chung khoan
NULL AS product_category_name, --
ten chung khoang
NULL AS dateacct, -- m_in.dateacct,
-- ngay hoach toan
inv.amount_revaluate_increase AS grandtotal, --
m_in.grandtotal, -- so tien,
rr.summary,
inv.reason_reject,
inv.c_salesregion_id
FROM ad_wf_activity awac
JOIN ad_wf_responsible awr
ON awr.ad_wf_responsible_id =
awac.ad_wf_responsible_id
JOIN r_request rr
ON awac.ad_table_id = 417
AND awac.record_id = rr.r_request_id
JOIN m_inventory inv
ON inv.m_inventory_id = rr.record_id
AND rr.ad_table_id = 321
WHERE awac.wfstate NOT IN ('CC', 'CT')
AND rr.docstatus NOT IN ('CO', 'CL', 'DR')
-- and awac.processed = 'N'
AND inv.c_doctype_id IN (1000412, 1000432) --danh gia lai, phan
loai lai
UNION
SELECT rr.r_request_id AS id,
awac.processed,
awac.ad_table_id,
awac.ad_wf_activity_id,
awac.ad_client_id,
ci.ad_org_id,
awac.isactive,
awac.created,
awac.createdby,
ci.dateinvoiced,
awac.updatedby,
ci.ad_user_id ad_user_acctmaker, -- user ke toan
awr.ad_role_id, -- role xu ly,
rr.documentno, -- so chung tu,
awac.ad_table_id c_doctype_id, -- loai giao dich,
ci.c_doctype_id c_doctype1_id,
ci.c_bpartner_id,
ci.c_bpartner_location_id,
NULL listed,
NULL self_trading_type,
NULL AS asset_type, -- mmt.asset_type,
-- muc dich nam giu
ci.m_product_category_id AS product_category_id, -- loai
chung khoan
NULL AS product_category_name, -- ten
chung khoang
ci.dateacct, -- ngay hoach toan
ci.grandtotal grandtotal, -- so tien,
rr.summary,
ci.reason_reject,
NULL c_salesregion_id
FROM ad_wf_activity awac
JOIN ad_wf_responsible awr
ON awr.ad_wf_responsible_id =
awac.ad_wf_responsible_id
JOIN r_request rr
ON awac.ad_table_id = 417
AND awac.record_id = rr.r_request_id
JOIN c_invoice ci
ON ci.c_invoice_id = rr.record_id
AND rr.ad_table_id = 318
LEFT JOIN m_product_category mpc
ON ci.m_product_category_id =
mpc.m_product_category_id
WHERE awac.wfstate NOT IN ('CC', 'CT')
AND rr.docstatus NOT IN ('CO', 'CL', 'DR')
--and awac.processed = 'N'
AND ci.c_doctype_id IN (1000002, 1000005)
UNION
SELECT rr.r_request_id AS id,
awac.processed,
awac.ad_table_id,
awac.ad_wf_activity_id,
awac.ad_client_id,
ci.ad_org_id,
awac.isactive,
awac.created,
awac.createdby,
ci.dateinvoiced,
awac.updatedby,
ci.createdby AS ad_user_acctmaker, -- user ke
toan
awr.ad_role_id, -- role xu ly,
rr.documentno, -- so chung tu,
awac.ad_table_id AS c_doctype_id, -- loai giao dich,
ci.c_doctype_id c_doctype1_id,
ci.c_bpartner_id,
ci.c_bpartner_location_id,
NULL listed,
NULL self_trading_type,
NULL AS asset_type, -- mmt.asset_type,
-- muc dich nam giu
ci.m_product_category_id AS product_category_id, -- loai
chung khoan
NULL AS product_category_name, -- ten
chung khoang
ci.dateacct, -- m_in.dateacct, -- ngay hoach toan
NULL AS grandtotal, -- m_in.grandtotal,
-- so tien,
rr.summary -- dien giai
,
ci.reason_reject,
NULL c_salesregion_id
FROM ad_wf_activity awac
JOIN ad_wf_responsible awr
ON awr.ad_wf_responsible_id =
awac.ad_wf_responsible_id
JOIN r_request rr
ON awac.ad_table_id = 417
AND awac.record_id = rr.r_request_id
JOIN c_invoice ci
ON ci.c_invoice_id = rr.record_id
AND rr.ad_table_id = 318
LEFT JOIN m_product_category mpc
ON ci.m_product_category_id =
mpc.m_product_category_id
WHERE awac.wfstate NOT IN ('CC', 'CT')
AND rr.docstatus NOT IN ('CO', 'CL', 'DR')
--and awac.processed = 'N'
AND ci.c_doctype_id IN (1001053, 1001052)
UNION
SELECT rr.r_request_id
AS id,
awac.processed,
awac.ad_table_id,
awac.ad_wf_activity_id,
awac.ad_client_id,
co.ad_org_id,
awac.isactive,
awac.created,
awac.createdby,
CASE
WHEN co.c_doctype_id IN (1000329, 1000330)
THEN
co.datepromised
ELSE
co.dateordered
END
dateordered,
awac.updatedby,
CASE
WHEN co.ad_user_ra_id IS NOT NULL
THEN
co.ad_user_ra_id
ELSE
co.createdby
END
ad_user_acctmaker, -- user ke toan
awr.ad_role_id, -- role xu ly,
rr.documentno, -- so chung tu,
awac.ad_table_id
AS c_doctype_id, -- loai giao dich,
co.c_doctype_id
c_doctype1_id,
co.c_bpartner_id,
co.c_bpartner_location_id,
co.listed,
co.self_trading_type,
co.asset_type, -- mmt.asset_type, -- muc dich nam giu
co.m_product_category_id
AS product_category_id, -- loai chung khoan
NULL
AS product_category_name, -- ten chung khoang
co.dateacct, -- m_in.dateacct, -- ngay hoach toan
co.grandtotal, -- m_in.grandtotal, -- so tien,
rr.summary,
co.reason_reject,
co.c_salesregion_id
FROM ad_wf_activity awac
JOIN ad_wf_responsible awr
ON awr.ad_wf_responsible_id =
awac.ad_wf_responsible_id
JOIN r_request rr
ON awac.ad_table_id = 417
AND awac.record_id = rr.r_request_id
JOIN c_order co
ON co.c_order_id = rr.record_id
AND rr.ad_table_id = 259
LEFT JOIN m_product_category mpc
ON co.m_product_category_id =
mpc.m_product_category_id
WHERE awac.wfstate NOT IN ('CC', 'CT')
AND rr.docstatus NOT IN ('CO', 'CL', 'DR')
--and awac.processed = 'N'
AND co.c_doctype_id IN (1000329,
1000330,
1000208,
1000209) -- pl mua, ban | hd ban , mua
UNION
SELECT rr.r_request_id AS id,
awac.processed,
awac.ad_table_id,
awac.ad_wf_activity_id,
awac.ad_client_id,
mm.ad_org_id,
awac.isactive,
awac.created,
awac.createdby,
awac.updated,
awac.updatedby,
mm.ad_user_ra_id AS ad_user_acctmaker, -- user ke toan
awr.ad_role_id, -- role xu ly,
rr.documentno, -- so chung tu,
awac.ad_table_id AS c_doctype_id, -- loai giao dich,
mm.c_doctype_id c_doctype1_id,
mm.c_bpartner_id,
mm.c_bpartner_location_id,
NULL,
NULL self_trading_type,
NULL, -- mmt.asset_type, -- muc dich nam giu
NULL AS product_category_id, -- loai chung khoan
NULL AS product_category_name, -- ten chung
khoang
mm.movementdate, -- m_in.dateacct, -- ngay hoach toan
NULL, -- m_in.grandtotal, -- so tien,
rr.summary -- dien giai
,
mm.reason_reject,
NULL c_salesregion_id
FROM ad_wf_activity awac
JOIN ad_wf_responsible awr
ON awr.ad_wf_responsible_id =
awac.ad_wf_responsible_id
JOIN r_request rr
ON awac.ad_table_id = 417
AND awac.record_id = rr.r_request_id
JOIN m_movement mm
ON mm.m_movement_id = rr.record_id
AND rr.ad_table_id = 259
WHERE awac.wfstate NOT IN ('CC', 'CT')
AND rr.docstatus NOT IN ('CO', 'CL', 'DR')
--and awac.processed = 'N'
AND mm.c_doctype_id IN (1000372, 1000732) -- chuyen kho, chuyen
trang thai
UNION
SELECT rr.r_request_id AS id,
awac.processed,
awac.ad_table_id,
awac.ad_wf_activity_id,
awac.ad_client_id,
cp.ad_org_id,
awac.isactive,
awac.created,
awac.createdby,
cp.dateacct,
awac.updatedby,
cp.ad_user_id AS ad_user_acctmaker, -- user ke toan
awr.ad_role_id, -- role xu ly,
rr.documentno, -- so chung tu,
awac.ad_table_id AS c_doctype_id, -- loai giao dich,
cp.c_doctype_id AS c_doctype1_id, -- loai giao dich,
cp.c_bpartner_id c_bpartner_id,
cp.c_bpartner_location_id,
NULL listed,
NULL self_trading_type,
NULL AS asset_type, -- mmt.asset_type, -- muc
dich nam giu
cp.m_product_id AS product_category_id, -- loai chung khoan
NULL AS product_category_name, -- ten chung
khoang
cp.dateacct, -- m_in.dateacct, -- ngay hoach toan
cp.payamt AS grandtotal, -- m_in.grandtotal, -- so
tien,
rr.summary, -- dien giai,
cp.reason_reject,
cp.c_salesregion_id
FROM ad_wf_activity awac
JOIN ad_wf_responsible awr
ON awr.ad_wf_responsible_id =
awac.ad_wf_responsible_id
JOIN r_request rr
ON awac.ad_table_id = 417
AND awac.record_id = rr.r_request_id
JOIN c_payment cp
ON cp.c_payment_id = rr.record_id
AND rr.ad_table_id = 335
WHERE awac.wfstate NOT IN ('CC', 'CT')
AND rr.docstatus NOT IN ('CO', 'CL', 'DR')
-- and awac.processed = 'N'
AND cp.c_doctype_id IN (1000008, 1000009)
UNION
SELECT rr.r_request_id AS id,
awac.processed,
awac.ad_table_id,
awac.ad_wf_activity_id,
awac.ad_client_id,
co.ad_org_id,
awac.isactive,
awac.created,
awac.createdby,
cp.datetrx,
awac.updatedby,
cp.ad_user_ra_id AS ad_user_acctmaker, -- user ke toan
awr.ad_role_id, -- role xu ly,
rr.documentno, -- so chung tu,
awac.ad_table_id AS c_doctype_id, -- loai giao dich,
cp.c_doctype_id c_doctype1_id,
co.c_bpartner_id c_bpartner_id,
co.c_bpartner_location_id,
co.listed listed,
co.self_trading_type self_trading_type,
NULL AS asset_type, -- mmt.asset_type, --
muc dich nam giu
NULL AS product_category_id, -- loai chung
khoan
NULL AS product_category_name, -- ten chung
khoang
cp.datetrx, -- m_in.dateacct, -- ngay hoach toan
cp.amount_int_due AS grandtotal, -- m_in.grandtotal, --
so tien,
rr.summary, -- dien giai,
cp.reason_reject,
co.c_salesregion_id
FROM ad_wf_activity awac
JOIN ad_wf_responsible awr
ON awr.ad_wf_responsible_id =
awac.ad_wf_responsible_id
JOIN r_request rr
ON awac.ad_table_id = 417
AND awac.record_id = rr.r_request_id
JOIN c_order_overdue cp
ON cp.c_order_overdue_id = rr.record_id
AND rr.ad_table_id = 1000000
LEFT JOIN c_order co ON (co.c_order_id = cp.c_order_id)
WHERE awac.wfstate NOT IN ('CC', 'CT')
AND rr.docstatus NOT IN ('CO', 'CL', 'DR')
-- and awac.processed = 'N'
AND cp.c_doctype_id IN (1001072, 1001073)
UNION
SELECT rr.r_request_id
AS id,
awac.processed,
rr.ad_table_id,
awac.ad_wf_activity_id,
awac.ad_client_id,
cpr.ad_org_id,
awac.isactive,
awac.created,
awac.createdby,
CASE
WHEN cpr.c_productright_type = 1
THEN
cpr.declare_date -- quyen co tuc bang phieu lenh
WHEN cpr.c_productright_type = 2
THEN
cpr.last_registration_date -- quyen mua co phieu
--when cpr.c_productright_type = 3 then
cpr.last_registration_date -- quyen chung quyen
WHEN cpr.c_productright_type = 4
THEN
cpr.record_date -- quyen co tuc bang tien | payment_date
(ngay thanh toan) | record_date (ngay dang ky cuoi cungt)
WHEN cpr.c_productright_type = 5
THEN
cpr.expected_exec_date -- quyen tach
WHEN cpr.c_productright_type = 6
THEN
cpr.expected_exec_date -- quyen gop
WHEN cpr.c_productright_type = 7
THEN
cpr.ex_swaps_date -- quyen quyen hoan doi
WHEN cpr.c_productright_type = 8
THEN
cpr.last_registration_date -- quyen quyen mua trai phieu
END
created,
awac.updatedby,
cpr.ad_user_ra_id
AS ad_user_acctmaker, -- user ke toan
awr.ad_role_id, -- role xu ly,
rr.documentno, -- so chung tu,
awac.ad_table_id, -- loai giao dich,
cpr.c_doctype_id
c_doctype1_id,
mp.c_bpartner_id
c_bpartner_id,
NULL, -- dia chi doi tac
mp.listed,
mca.self_trading_type,
NULL
AS asset_type, -- mmt.asset_type, -- muc dich nam giu
NULL
AS product_category_id, -- loai chung khoan
NULL, -- ten chung khoang
CASE
WHEN cpr.c_productright_type = 1
THEN
cpr.declare_date -- quyen co tuc bang phieu lenh
WHEN cpr.c_productright_type = 2
THEN
cpr.last_registration_date -- quyen mua co phieu
--when cpr.c_productright_type = 3 then
cpr.last_registration_date -- quyen chung quyen
WHEN cpr.c_productright_type = 4
THEN
cpr.record_date -- quyen co tuc bang tien | payment_date
(ngay thanh toan) | record_date (ngay dang ky cuoi cungt)
WHEN cpr.c_productright_type = 5
THEN
cpr.expected_exec_date -- quyen tach
WHEN cpr.c_productright_type = 6
THEN
cpr.expected_exec_date -- quyen gop
WHEN cpr.c_productright_type = 7
THEN
cpr.ex_swaps_date -- quyen quyen hoan doi
WHEN cpr.c_productright_type = 8
THEN
cpr.last_registration_date -- quyen quyen mua trai phieu
END
datetrx, -- m_in.dateacct, -- ngay hoach toan
NULL,
rr.summary,
rr.reason_reject,
cpr.c_salesregion_id
FROM ad_wf_activity awac
JOIN ad_wf_responsible awr
ON awr.ad_wf_responsible_id =
awac.ad_wf_responsible_id
JOIN r_request rr
ON awac.ad_table_id = 417
AND awac.record_id = rr.r_request_id
JOIN c_productrightheader cpr
ON cpr.c_productrightheader_id = rr.record_id
AND rr.ad_table_id = 1000608
LEFT JOIN m_product mp
ON mp.m_product_id = cpr.m_product_id
LEFT JOIN m_product_category mca
ON mca.m_product_category_id =
mp.m_product_category_id
WHERE awac.wfstate NOT IN ('CC', 'CT')
AND rr.docstatus NOT IN ('CO', 'CL', 'DR')
UNION
SELECT rr.r_request_id AS id,
awac.processed,
rr.ad_table_id,
awac.ad_wf_activity_id,
awac.ad_client_id,
cpl.ad_org_id,
awac.isactive,
awac.created,
awac.createdby,
cpl.datetrx,
awac.updatedby,
cpl.ad_user_ra_id AS ad_user_acctmaker, -- user ke toan
awr.ad_role_id, -- role xu ly,
rr.documentno, -- so chung tu,
awac.ad_table_id AS c_doctype_id, -- loai giao dich,
cpr.c_doctype_id AS c_doctype1_id, -- loai giao dich,
mp.c_bpartner_id c_bpartner_id,
NULL, -- dia chi doi tac
mp.listed,
mca.self_trading_type,
NULL AS asset_type, -- mmt.asset_type, -- muc
dich nam giu
NULL AS product_category_id, -- loai chung
khoan
NULL, -- ten chung khoang
cpl.datetrx, -- m_in.dateacct, -- ngay hoach toan
cpl.right_amount,
rr.summary,
rr.reason_reject,
cpl.c_salesregion_id
FROM ad_wf_activity awac
JOIN ad_wf_responsible awr
ON awr.ad_wf_responsible_id =
awac.ad_wf_responsible_id
JOIN r_request rr
ON awac.ad_table_id = 417
AND awac.record_id = rr.r_request_id
JOIN c_productrightline cpl
ON cpl.c_productrightline_id = rr.record_id
AND rr.ad_table_id = 1000587
LEFT JOIN c_productrightheader cpr
ON cpr.c_productrightheader_id =
cpl.c_productrightheader_id
LEFT JOIN m_product mp
ON mp.m_product_id = cpr.m_product_id
LEFT JOIN m_product_category mca
ON mca.m_product_category_id =
mp.m_product_category_id
WHERE awac.wfstate NOT IN ('CC', 'CT')
AND rr.docstatus NOT IN ('CO', 'CL', 'DR') -- and awac.processed
= 'N'
-- AND
cpr.c_productright_type IN ('02', '07')
) req
WHERE req.ad_role_id <> 0;

You might also like