所有接口的注意事项
1、验证数据的准确性,也就是各个字段进行数据校验,包括金额正负数等的验证
2、验证数据的重复性,也就是已经传过的数据不允许再传送,否则造成数据重复导入
3、并发的控制,如果前端系统无法保证数据的并发处理,那么需要在接口环境进行控制,否则一旦并发还是会造成数据重复,甚至错误。
4、性能,如果数据量大的时候如果保证快速进行传送也是接口需要考虑的问题。
5、日记账导入无法也是按照以上规则进行,再就是会有特殊要求,导入之后进行过账。或者进行一些分组等特殊逻辑。
日记账导入详细介绍
1 接口表 gl_interface
字段
|
说明
|
|
|
group_id
|
可以放空,也可以从 gl_interface_control_s 取,也可自己指定
|
status
|
固定给 NEW
|
set_of_books_id
|
账套 ID
|
code_combination_id
|
帐户 ID
|
user_je_category_name
|
日记帐类别名称
|
user_je_source_name
|
日记帐分录来源名称
|
accounting_date
|
凭证日期、会计结算日期
|
period_name
|
会计期间
|
currency_code
|
币种代码
|
date_created
|
日记帐分录行的创建日期
|
actual_flag
|
类别表示,一般导总账都是导入实际金额 A表示实际金额,保留款和预算也由此标记控制
|
entered_dr
|
借方金额
|
entered_cr
|
贷方金额
|
accounted_dr
|
借方本位币金额
|
accounted_cr
|
贷方本位币金额
|
created_by
|
创建人
|
reference1
|
批名
|
reference2
|
批说明
|
reference3
|
请勿在此列输入值
|
reference4
|
日记账名称
|
reference5
|
日记账说明
|
reference6
|
日记帐分录参考
|
reference7
|
日记帐分录冲销标志
|
|
|
reference9
|
日记帐冲销方法
|
reference10
|
日记帐分录行说明
|
reference11 至 reference20
|
请勿在此列输入值
|
je_batch_id
|
请勿在此列输入值
|
je_header_id
|
请勿在此列输入值
|
je_line_num
|
请勿在此列输入值
|
chart_of_accounts_id
|
请勿在此列输入值
|
date_created_in_gl
|
请勿在此列输入值
|
warning_code
|
请勿在此列输入值
|
status_descr īption
|
请勿在此列输入值
|
desc_flex_error_message
|
请勿在此列输入值
|
request_id
|
请勿在此列输入值
|
subledger_doc_sequence_id
|
请勿在此列输入值
|
subledger_doc_sequence_value
|
用于总帐与子分类帐间的数据传递。请勿填入您自己的数据。
|
3、数据导入
4、提交导入请求
5、过账
具体程序如下:
程序背景:
含有两个客户化接口表cux_gl_interface_header,cux_gl_interface_line 因为采用了新旧系统同时存在,所以需要新旧系统凭证进行传送,所以会有各个段值的映射关系。如果有其他需要核心内容不变更,程序仅当做参考。
CREATE OR REPLACE PACKAGE BODY cux_gl_interface_imp_pkg AS
g_package_name CONSTANT VARCHAR2(100) := 'CUX_GL_INTERFACE_imp_pkg';
g_user_id NUMBER := fnd_global.user_id;
g_login_id NUMBER := fnd_global.login_id;
g_conc_program_id NUMBER := fnd_global.conc_program_id;
g_prog_appl_id NUMBER := fnd_global.prog_appl_id;
g_request_id NUMBER := fnd_global.conc_request_id;
g_gl_request_id NUMBER;
g_ledger_id NUMBER := fnd_profile.value('GL_SET_OF_BKS_ID');
g_session_id NUMBER;
l_msg_data VARCHAR2(4000);
g_return_status VARCHAR2(120) := 'S';
g_line_err_msg VARCHAR2(4000);
g_line_return_status VARCHAR2(120);
g_debug_flag VARCHAR2(30) := 'N' /* nvl(fnd_profile.value('AFLOG_ENABLED'),
'N')*/
;
PROCEDURE log_msg(p_log_msg IN VARCHAR2) IS
BEGIN
fnd_file.put_line(fnd_file.log, p_log_msg);
END log_msg;
PROCEDURE output(p_message VARCHAR2) IS
BEGIN
fnd_file.put_line(fnd_file.output, p_message);
END output;
PROCEDURE stack_message(p_msg IN VARCHAR2) IS
BEGIN
cux_api.set_message(upper('fnd'),
upper('conc-places message on stack'),
upper('message'),
p_msg);
END stack_message;
PROCEDURE raise_exception(x_return_status VARCHAR2) IS
BEGIN
IF (x_return_status = fnd_api.g_ret_sts_unexp_error) THEN
RAISE fnd_api.g_exc_unexpected_error;
ELSIF (x_return_status = fnd_api.g_ret_sts_error) THEN
RAISE fnd_api.g_exc_error;
ELSE
NULL;
END IF;
END raise_exception;
FUNCTION get_org_id(p_org_code IN VARCHAR2) RETURN NUMBER IS
l_org_id NUMBER;
BEGIN
SELECT hou.organization_id
INTO l_org_id
FROM xle_entity_profiles p,
hr_operating_units hou,
gl_legal_entities_bsvs gl
WHERE 1 = 1
AND hou.default_legal_context_id = p.legal_entity_id
AND p.legal_entity_id = gl.legal_entity_id
AND gl.flex_segment_value = p_org_code
AND hou.set_of_books_id = g_ledger_id;
RETURN l_org_id;
EXCEPTION
WHEN no_data_found THEN
RETURN - 1;
WHEN OTHERS THEN
RETURN - 3;
END get_org_id;
--获取值集
FUNCTION get_flex_desc(p_flex_value_set IN VARCHAR2,
p_flex_value IN VARCHAR2) RETURN VARCHAR2 IS
l_segment_value VARCHAR2(120);
BEGIN
SELECT flv.description
INTO l_segment_value
FROM fnd_flex_values_vl flv, fnd_flex_value_sets ffs
WHERE flv.flex_value_set_id = ffs.flex_value_set_id
AND ffs.flex_value_set_name = p_flex_value_set
AND flv.flex_value = p_flex_value
--AND flv.enabled_flag = 'Y'
/*AND SYSDATE BETWEEN nvl(flv.start_date_active, SYSDATE - 1) AND
nvl(flv.end_date_active, SYSDATE + 1)*/
;
RETURN nvl(l_segment_value, 'N');
EXCEPTION
WHEN no_data_found THEN
RETURN 'N';
WHEN too_many_rows THEN
RETURN 'M';
WHEN OTHERS THEN
RETURN 'O';
END get_flex_desc;
--获取各段段值
FUNCTION get_old_segment_value(p_flex_value_set IN VARCHAR2,
p_flex_value IN VARCHAR2)
RETURN VARCHAR2 IS
l_segment_value VARCHAR2(120);
BEGIN
SELECT flv.attribute1
INTO l_segment_value
FROM fnd_flex_values_vl flv, fnd_flex_value_sets ffs
WHERE flv.flex_value_set_id = ffs.flex_value_set_id
AND ffs.flex_value_set_name = p_flex_value_set
AND flv.flex_value = p_flex_value
AND flv.enabled_flag = 'Y'
AND SYSDATE BETWEEN nvl(flv.start_date_active, SYSDATE - 1) AND
nvl(flv.end_date_active, SYSDATE + 1);
RETURN nvl(l_segment_value, 'N');
EXCEPTION
WHEN no_data_found THEN
RETURN 'N';
WHEN too_many_rows THEN
RETURN 'M';
WHEN OTHERS THEN
RETURN 'O';
END get_old_segment_value;
PROCEDURE get_old_segment_special(p_new_account IN VARCHAR2,
p_new_manacc IN VARCHAR2,
p_new_unit_code IN VARCHAR2,
p_new_produce IN VARCHAR2,
x_old_account IN OUT VARCHAR2,
x_old_manacc IN OUT VARCHAR2, --新科目
x_old_produce IN OUT VARCHAR2) IS
BEGIN
SELECT flv.attribute5, flv.attribute6, flv.attribute7
INTO x_old_account, x_old_manacc, x_old_produce
FROM apps.fnd_flex_values_vl flv, apps.fnd_flex_value_sets ffs
WHERE flv.flex_value_set_id = ffs.flex_value_set_id
AND ffs.flex_value_set_name = 'CUX_GL_ACCOUNT_PRODUCT'
AND flv.attribute1 = p_new_account
AND flv.attribute2 = p_new_manacc
AND nvl(flv.attribute3, '0') = nvl(p_new_unit_code, '1')
AND nvl(flv.attribute4, '0') = substr(p_new_produce, 1, 2)
AND flv.enabled_flag = 'Y'
AND SYSDATE BETWEEN nvl(flv.start_date_active, SYSDATE - 1) AND
nvl(flv.end_date_active, SYSDATE + 1);
EXCEPTION
WHEN no_data_found THEN
NULL;
WHEN OTHERS THEN
x_old_account := 'N';
x_old_produce := 'N';
END get_old_segment_special;
FUNCTION get_employee_id(p_email_name VARCHAR2) RETURN NUMBER IS
l_user_id NUMBER;
BEGIN
SELECT t.employee_id
INTO l_user_id
FROM fnd_user t
WHERE t.email_address = p_email_name
AND SYSDATE BETWEEN nvl(t.start_date, SYSDATE - 1) AND
nvl(t.end_date, SYSDATE + 1);
RETURN nvl(l_user_id, -1);
EXCEPTION
WHEN no_data_found THEN
RETURN '-1';
WHEN too_many_rows THEN
RETURN '-2';
WHEN OTHERS THEN
RETURN '-3';
END;
--获取人员信息
FUNCTION get_user_id(p_email_name VARCHAR2) RETURN NUMBER IS
l_user_id NUMBER;
BEGIN
SELECT t.user_id
INTO l_user_id
FROM fnd_user t
WHERE t.email_address = p_email_name
AND SYSDATE BETWEEN nvl(t.start_date, SYSDATE - 1) AND
nvl(t.end_date, SYSDATE + 1);
RETURN nvl(l_user_id, -1);
EXCEPTION
WHEN no_data_found THEN
RETURN '-1';
WHEN too_many_rows THEN
RETURN '-2';
WHEN OTHERS THEN
RETURN '-3';
END get_user_id;
FUNCTION get_code_combination_id(p_concatenated_segments IN VARCHAR2,
p_chart_of_accounts_id IN NUMBER,
x_posting_allowed_flag OUT VARCHAR2)
RETURN NUMBER IS
l_code_combination_id NUMBER NULL;
BEGIN
l_code_combination_id := apps.fnd_flex_ext.get_ccid(application_short_name => 'SQLGL',
key_flex_code => 'GL#',
structure_number => p_chart_of_accounts_id,
validation_date => to_char(SYSDATE,
apps.fnd_flex_ext.date_format),
concatenated_segments => p_concatenated_segments);
BEGIN
SELECT t.detail_posting_allowed
INTO x_posting_allowed_flag
FROM gl_code_combinations_kfv t
WHERE t.code_combination_id = l_code_combination_id;
EXCEPTION
WHEN OTHERS THEN
x_posting_allowed_flag := 'N';
END;
RETURN nvl(l_code_combination_id, -1);
EXCEPTION
WHEN OTHERS THEN
IF fnd_flex_keyval.validate_segs(operation => 'CREATE_COMBINATION',
appl_short_name => 'SQLGL',
key_flex_code => 'GL#',
structure_number => p_chart_of_accounts_id,
concat_segments => p_concatenated_segments) THEN
l_code_combination_id := fnd_flex_ext.get_ccid('SQLGL',
'GL#',
p_chart_of_accounts_id,
to_char(SYSDATE,
'YYYY-MM-DD'),
p_concatenated_segments);
BEGIN
SELECT t.detail_posting_allowed
INTO x_posting_allowed_flag
FROM gl_code_combinations_kfv t
WHERE t.code_combination_id = l_code_combination_id;
EXCEPTION
WHEN OTHERS THEN
x_posting_allowed_flag := 'N';
END;
ELSE
l_code_combination_id := -1;
x_posting_allowed_flag := 'N';
END IF;
RETURN l_code_combination_id;
END get_code_combination_id;
FUNCTION lock_data(p_source_code VARCHAR2, p_source_header_id NUMBER)
RETURN NUMBER IS
CURSOR cur_data IS
SELECT 1 flag
FROM cux_gl_interface_header t
WHERE t.source_code = p_source_code
AND t.source_header_id = p_source_header_id
AND nvl(t.process_status, 'NEW') IN ('NEW', 'VALID-ERROR')
FOR UPDATE NOWAIT;
l_count NUMBER;
l_lock NUMBER;
BEGIN
BEGIN
FOR i IN cur_data LOOP
l_count := i.flag;
END LOOP;
l_lock := 1;
EXCEPTION
WHEN OTHERS THEN
l_lock := 0; --没有锁住
END;
IF l_lock = 0 THEN
RETURN 0;
ELSE
RETURN 1;
END IF;
EXCEPTION
WHEN OTHERS THEN
RETURN 0;
END;
--模拟职责
PROCEDURE moac_init(p_org_id NUMBER, p_user_id NUMBER, p_resp_id NUMBER) IS
l_api_name VARCHAR2(32) := 'moac_init';
l_resp_appl_id NUMBER;
l_org_id NUMBER;
BEGIN
fnd_global.apps_initialize(user_id => p_user_id, --
resp_id => p_resp_id, --
resp_appl_id => 101); --GL
IF p_org_id IS NOT NULL THEN
mo_global.set_policy_context('S', p_org_id);
END IF;
END moac_init;
PROCEDURE check_je_source(p_user_je_source_name IN VARCHAR2,
x_je_source_name OUT VARCHAR2,
x_return_status OUT VARCHAR2,
x_msg_data OUT VARCHAR2) IS
BEGIN
x_return_status := 'S';
SELECT gs.je_source_name
INTO x_je_source_name
FROM gl_je_sources_vl gs
WHERE gs.user_je_source_name = p_user_je_source_name;
--log('p_user_je_source_name = ' || p_user_je_source_name);
--log('x_je_source_name = ' || x_je_source_name);
EXCEPTION
WHEN no_data_found THEN
x_msg_data := '来源: ' || p_user_je_source_name || ' 不存在!';
x_return_status := 'E';
WHEN OTHERS THEN
x_msg_data := SQLCODE || ':' || SQLERRM;
x_return_status := 'U';
END check_je_source;
FUNCTION submit_request(p_interface_run_id IN NUMBER,
p_ledger_id IN NUMBER) RETURN BOOLEAN IS
p_request_id NUMBER;
p_wait BOOLEAN;
p_phase VARCHAR2(80);
p_status VARCHAR2(80);
p_dev_phase VARCHAR2(80);
p_dev_status VARCHAR2(80);
p_message VARCHAR2(80);
BEGIN
p_request_id := fnd_request.submit_request(application => 'SQLGL', --应用简称
program => 'GLLEZL', --并发简称:日记帐导入
description => '', --说明
start_time => '', --请求开始时间,格式为标准日期格式,为空表示立即开始
sub_request => FALSE, --是否子请求
argument1 => to_char(p_interface_run_id), --接口运行标识
argument2 => to_char(p_ledger_id), --帐套标识或者数据访问权限集
argument3 => 'N', --将误差过帐至暂记帐,Y-是,N-否
argument4 => NULL, --日期范围,入帐日期开始
argument5 => NULL, --日期范围,入帐日期结束
argument6 => 'N', --创建汇总日记帐,Y-是,N-否
argument7 => 'O', --导入说明性弹性域,N-否,W-验证,O-没验证
argument8 => 'N', -- --Data security mode flag,Y--argument2为gl_access_set_id(default -602),N--argument2为ledger_id
argument9 => chr(0) --参数结束
);
COMMIT;
IF p_request_id = 0 THEN
RETURN FALSE;
END IF;
g_gl_request_id := p_request_id;
-- wait request
p_wait := fnd_concurrent.wait_for_request(request_id => p_request_id,
INTERVAL => 1, -- interval second for check
max_wait => 360, -- max_wait, Max amount of time to wait (in seconds)
phase => p_phase,
status => p_status,
dev_phase => p_dev_phase,
dev_status => p_dev_status,
message => p_message);
IF p_wait AND p_dev_phase = 'COMPLETE' AND p_dev_status = 'NORMAL' THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
END submit_request;
PROCEDURE autopost(p_set_of_books_id IN NUMBER,
p_je_batch_id IN NUMBER DEFAULT NULL,
p_je_source_name IN VARCHAR2,
p_je_category_name IN VARCHAR2,
x_return_status OUT NOCOPY VARCHAR2,
x_error_message OUT NOCOPY VARCHAR2) IS
l_api_name CONSTANT VARCHAR2(100) := 'Autopost';
l_gl_access_set_id NUMBER := fnd_profile.value('GL_ACCESS_SET_ID');
l_request_id NUMBER;
l_count_sel_bat NUMBER;
l_phase VARCHAR2(100);
l_status VARCHAR2(100);
l_dev_phase VARCHAR2(100);
l_dev_status VARCHAR2(100);
l_message VARCHAR2(2000);
BEGIN
x_error_message := NULL;
x_return_status := 'S';
log_msg('Cux_fin_bank_transfer_pub.autopost(+) ');
log_msg('Call procedure gl_autopost_pkg.post_batches -> ');
gl_autopost_pkg.post_batches(x_request_id => l_request_id,
x_count_sel_bat => l_count_sel_bat,
x_access_set_id => l_gl_access_set_id,
x_ledger_id => p_set_of_books_id,
x_je_batch_id => p_je_batch_id,
x_je_source_name => p_je_source_name,
x_je_category_name => p_je_category_name);
COMMIT;
--等待过账
IF fnd_concurrent.wait_for_request(l_request_id,
5, --检查间隔时间
0, --maxwait
l_phase,
l_status,
l_dev_phase,
l_dev_status,
l_message) THEN
IF l_dev_phase = 'COMPLETE' AND l_dev_status = 'NORMAL' THEN
NULL;
ELSE
x_return_status := 'E';
x_error_message := '等待报错';
END IF;
END IF;
log_msg('AutoPost batch argument: ');
log_msg('Ledger_id --->' || p_set_of_books_id);
log_msg('Je_batch_id --->' || p_je_batch_id);
log_msg('Je_source_name --->' || p_je_source_name);
log_msg('Je_category_name --->' || p_je_category_name);
log_msg('X_request_id --->' || l_request_id);
log_msg('X_count_sel_bat --->' || l_count_sel_bat);
EXCEPTION
WHEN fnd_api.g_exc_error THEN
x_return_status := fnd_api.g_ret_sts_error;
x_error_message := '自动过账失败' || l_msg_data;
WHEN fnd_api.g_exc_unexpected_error THEN
x_return_status := fnd_api.g_ret_sts_unexp_error;
x_error_message := '自动过账失败' || l_msg_data;
WHEN OTHERS THEN
x_return_status := fnd_api.g_ret_sts_unexp_error;
x_error_message := g_package_name || '.' || l_api_name ||
' execute error : ' ||
dbms_utility.format_error_stack;
END autopost;
PROCEDURE process_request(p_source_code IN VARCHAR2, --外部系统
p_batch_id IN NUMBER, --外部系统批ID
p_org_code IN VARCHAR2 DEFAULT NULL,
p_je_source IN VARCHAR2 DEFAULT NULL,
p_je_category IN VARCHAR2 DEFAULT NULL,
p_ispost IN VARCHAR2 DEFAULT 'N',
x_return_status OUT NOCOPY VARCHAR2,
x_error_message OUT NOCOPY VARCHAR2) IS
--头信息的游标
CURSOR cur_headers IS
SELECT h.interface_id,
h.batch_id,
l.line_num,
h.source_code,
l.source_id,
h.source_header_id,
l.source_line_num,
h.status,
h.ledger_id,
h.ledger_name,
h.accounting_date,
h.actual_flag,
h.user_je_category_name,
h.user_je_source_name user_je_source_name,
h.currency_code,
h.currency_conversion_date,
h.user_currency_conversion_type,
h.currency_conversion_rate,
h.accrual_rev_period_name,
h.accrual_rev_status,
h.accrual_rev_je_header_id,
h.accrual_rev_change_sign_flag,
h.reference1,
h.reference2,
h.reference3,
h.reference4,
h.reference5,
h.reference6,
h.reference7,
h.reference8,
h.reference9,
l.reference10,
l.reference11,
l.reference12,
l.reference13,
l.reference14,
l.reference15,
l.reference16,
l.reference17,
l.reference18,
l.reference19,
l.reference20,
l.reference21,
l.reference22,
l.reference23,
l.reference24,
l.reference25,
l.reference26,
l.reference27,
l.reference28,
l.reference29,
l.reference30,
h.set_of_books_id,
h.group_id,
l.code_combination_id,
l.segment1,
l.new_segment2,
l.old_segment3,
l.new_segment3,
l.old_segment2,
l.new_segment4,
l.old_segment5,
l.new_segment5,
l.old_segment4,
l.new_segment6,
l.old_segment6,
l.new_segment7,
l.old_segment7,
l.new_segment8,
l.old_segment8,
l.new_segment9,
l.new_segment10,
l.new_segment11,
l.entered_dr,
l.entered_cr,
l.accounted_dr,
l.accounted_cr,
l.context,
h.je_header_id,
h.request_id,
h.create_user_id,
h.approve_user_id,
h.post_user_id
FROM cux_gl_interface_header h, cux_gl_interface_line l
WHERE h.interface_id = l.interface_id
AND h.batch_id = l.batch_id
AND h.process_status = 'V'
AND (p_source_code IS NULL OR h.source_code = p_source_code)
AND (p_je_category IS NULL OR
h.user_je_category_name = p_je_category)
AND (p_je_source IS NULL OR h.user_je_source_name = p_je_source)
AND (p_batch_id IS NULL OR h.batch_id = p_batch_id)
AND (p_org_code IS NULL OR l.segment1 = p_org_code);
l_api_name CONSTANT VARCHAR2(30) := 'process_request'; ---- procedure的名称
l_savepoint_name CONSTANT VARCHAR2(30) := 'sp_process_request01'; ---- 断点名字
l_request_id NUMBER DEFAULT NULL; --并发请求的id
l_process VARCHAR2(4000);
l_return_status VARCHAR2(240);
l_error_message VARCHAR2(4000);
l_h_error_flag VARCHAR2(1); --头信息错误标识
l_count NUMBER;
l_retcode NUMBER;
l_period_name VARCHAR2(120);
l_flag NUMBER := 0;
l_batch_id NUMBER;
l_group_id NUMBER;
l_je_source_name VARCHAR2(240);
l_interface_run_id NUMBER;
l_post_run_id NUMBER;
l_int_rec gl_interface%ROWTYPE;
l_int_ctl_rec gl_interface_control%ROWTYPE;
l_chart_of_accounts_id NUMBER;
l_wait_req BOOLEAN;
l_child_phase VARCHAR2(100);
l_child_status VARCHAR2(100);
l_dev_phase VARCHAR2(100);
l_dev_status VARCHAR2(100);
l_message VARCHAR2(100);
l_ledger_id NUMBER;
l_post_user_id NUMBER;
l_post_request_id NUMBER;
l_coa_id NUMBER;
BEGIN
x_error_message := NULL;
x_return_status := 'S';
l_group_id := gl_interface_control_s.nextval;
l_count := 0;
log_msg('------------2.数据插入gl_interface--------------' || l_group_id);
FOR rec IN cur_headers LOOP
l_flag := 1;
l_count := l_count + 1;
-- insert gl_interface
l_int_rec.status := 'NEW';
l_int_rec.ledger_id := rec.ledger_id;
l_int_rec.user_je_source_name := rec.user_je_source_name;
l_int_rec.user_je_category_name := rec.user_je_category_name;
l_int_rec.accounting_date := rec.accounting_date;
l_int_rec.actual_flag := rec.actual_flag;
l_int_rec.currency_code := rec.currency_code;
l_int_rec.currency_conversion_date := rec.currency_conversion_date;
l_int_rec.user_currency_conversion_type := rec.user_currency_conversion_type;
l_int_rec.currency_conversion_rate := rec.currency_conversion_rate;
l_int_rec.set_of_books_id := -1;
l_int_rec.date_created := SYSDATE;
l_int_rec.created_by := g_user_id;
l_int_rec.reference1 := '[' || rec.reference1 || ']'; -- 批名
l_int_rec.reference2 := rec.reference2; --批次的详细说明
l_int_rec.reference3 := rec.reference3;
l_int_rec.reference4 := rec.reference4; -- 日记账名称
l_int_rec.reference5 := rec.reference5; --日分账记录的详细说明
l_int_rec.reference6 := rec.reference6;
l_int_rec.reference7 := rec.reference7; --冲销标志
l_int_rec.reference8 := rec.reference8;
l_int_rec.reference9 := rec.reference9; --冲销方法
l_int_rec.reference10 := rec.reference10; --行说明
l_int_rec.reference11 := rec.reference11;
l_int_rec.reference12 := rec.reference12;
l_int_rec.reference13 := rec.reference13;
l_int_rec.reference14 := rec.reference14;
l_int_rec.reference15 := rec.reference15;
l_int_rec.reference16 := rec.reference16;
l_int_rec.reference17 := rec.reference17;
l_int_rec.reference18 := rec.reference18;
l_int_rec.reference19 := rec.reference19;
l_int_rec.reference20 := rec.reference20;
l_int_rec.reference21 := rec.reference21;
l_int_rec.reference22 := rec.reference22;
l_int_rec.reference23 := rec.reference23;
l_int_rec.reference24 := rec.reference24;
l_int_rec.reference25 := rec.reference25;
l_int_rec.reference26 := rec.reference26;
l_int_rec.reference27 := rec.reference27;
l_int_rec.reference28 := rec.reference28;
l_int_rec.reference29 := rec.reference29;
l_int_rec.reference30 := rec.reference30;
l_int_rec.period_name := to_char(rec.accounting_date,
'YYYY-MM',
'NLS_DATE_LANGUAGE = American');
l_int_rec.group_id := l_group_id;
l_int_rec.gl_sl_link_id := rec.source_id;
l_int_rec.gl_sl_link_table := 'CUX_GL_INTERFACE_LINE';
--行
l_int_rec.entered_dr := rec.entered_dr;
l_int_rec.entered_cr := rec.entered_cr;
l_int_rec.accounted_dr := rec.accounted_dr;
l_int_rec.accounted_cr := rec.accounted_cr;
l_int_rec.code_combination_id := rec.code_combination_id;
INSERT INTO gl_interface VALUES l_int_rec;
UPDATE cux_gl_interface_header h
SET h.group_id = l_group_id
WHERE h.interface_id = rec.interface_id;
END LOOP;
---------------------------------------------
-- 处理gl_interface 数据
----------------------------------------------
IF l_count > 0 THEN
-- =============================
-- 提交标准请求
-- =============================
FOR rec_sub IN (SELECT t.user_je_source_name, t.group_id, t.ledger_id
FROM gl.gl_interface t
WHERE t.status = 'NEW'
AND t.gl_sl_link_table = 'CUX_GL_INTERFACE_LINE'
AND t.group_id = l_group_id
GROUP BY t.user_je_source_name,
t.group_id,
t.ledger_id) LOOP
l_ledger_id := rec_sub.ledger_id;
log_msg('------------3.数据插入control--------------');
check_je_source(p_user_je_source_name => rec_sub.user_je_source_name,
x_je_source_name => l_je_source_name,
x_return_status => l_return_status,
x_msg_data => l_msg_data);
--来源不同创建不同的control
l_interface_run_id := gl_journal_import_s.nextval;
l_int_ctl_rec.interface_run_id := l_interface_run_id;
l_int_ctl_rec.je_source_name := l_je_source_name;
l_int_ctl_rec.set_of_books_id := rec_sub.ledger_id;
l_int_ctl_rec.group_id := l_group_id; -- lt_int.group_id ;
l_int_ctl_rec.status := 'S';
INSERT INTO gl_interface_control VALUES l_int_ctl_rec;
IF NOT submit_request(p_interface_run_id => l_interface_run_id,
p_ledger_id => rec_sub.ledger_id) THEN
-- Import failed
log_msg('-----------4.submit request failure------------');
FOR gi_rec IN (SELECT *
FROM gl_interface
WHERE group_id = l_group_id
AND user_je_source_name =
rec_sub.user_je_source_name
AND ledger_id = rec_sub.ledger_id
AND gl_sl_link_table = 'CUX_GL_INTERFACE_LINE') LOOP
IF gi_rec.status NOT IN ('PROCESSED', 'P') THEN
log_msg('-----------4.1 更新失败状态------------');
x_error_message := substr(x_error_message ||
gi_rec.descr_flex_error_message,
1,
4000);
x_return_status := fnd_api.g_ret_sts_error;
UPDATE cux_gl_interface_line cg
SET cg.request_id = g_gl_request_id,
cg.created_by = fnd_global.user_id,
cg.last_update_date = SYSDATE,
cg.last_updated_by = fnd_global.user_id,
cg.process_status = 'FAILURE',
cg.error_message = 'submit request failure' ||
gi_rec.status || ';' ||
gi_rec.descr_flex_error_message
WHERE cg.source_code = p_source_code
AND cg.source_id = gi_rec.gl_sl_link_id
AND cg.process_status = 'V';
UPDATE cux_gl_interface_header h
SET h.request_id = g_gl_request_id,
h.created_by = fnd_global.user_id,
h.last_update_date = SYSDATE,
h.last_updated_by = fnd_global.user_id,
h.process_status = 'FAILURE',
h.error_message = 'submit request failure' ||
gi_rec.status || ';' ||
gi_rec.descr_flex_error_message
WHERE EXISTS (SELECT 1
FROM cux_gl_interface_line l
WHERE l.interface_id = h.interface_id
AND l.batch_id = h.batch_id
AND l.source_code = p_source_code
AND l.source_id = gi_rec.gl_sl_link_id
AND l.process_status = 'FAILURE');
ELSE
log_msg('-----------4.1 更新失败状态------------');
UPDATE cux_gl_interface_line cg
SET cg.request_id = g_gl_request_id,
cg.last_update_login = fnd_global.user_id,
cg.last_update_date = SYSDATE,
cg.last_updated_by = fnd_global.user_id,
cg.process_status = 'NEW'
WHERE (p_source_code IS NULL OR
cg.source_code = p_source_code)
AND (p_org_code IS NULL OR cg.segment1 = p_org_code)
AND (p_batch_id IS NULL OR cg.batch_id = p_batch_id)
AND cg.source_id = gi_rec.gl_sl_link_id
AND cg.process_status = 'V';
UPDATE cux_gl_interface_header h
SET h.request_id = g_gl_request_id,
h.created_by = fnd_global.user_id,
h.last_update_date = SYSDATE,
h.last_updated_by = fnd_global.user_id,
h.process_status = 'NEW'
WHERE EXISTS (SELECT 1
FROM cux_gl_interface_line l
WHERE l.interface_id = h.interface_id
AND l.batch_id = h.batch_id
AND (p_source_code IS NULL OR
l.source_code = p_source_code)
AND (p_batch_id IS NULL OR
l.source_code = p_batch_id)
AND (p_org_code IS NULL OR
l.segment1 = p_source_code)
AND l.source_id = gi_rec.gl_sl_link_id
AND l.process_status = 'V');
END IF;
END LOOP;
ELSE
log_msg('------------4.submit request success-------------');
IF x_error_message IS NULL THEN
-- Import success
UPDATE cux_gl_interface_header cg
SET cg.request_id = g_gl_request_id,
cg.je_header_id =
(SELECT MAX(gjr.je_header_id)
FROM gl_je_lines gjr, cux_gl_interface_line l
WHERE gjr.gl_sl_link_id = l.source_id
AND cg.interface_id = l.interface_id
AND gjr.gl_sl_link_table = 'CUX_GL_INTERFACE_LINE'),
cg.created_by = fnd_global.user_id,
cg.last_update_date = SYSDATE,
cg.last_updated_by = fnd_global.user_id,
cg.process_status = 'SUCCESS'
WHERE cg.user_je_source_name = rec_sub.user_je_source_name
AND cg.batch_id = nvl(p_batch_id, cg.batch_id)
AND cg.source_code = nvl(p_source_code, cg.source_code)
AND cg.process_status = 'V'
AND EXISTS
(SELECT 1
FROM gl_je_lines t1, cux_gl_interface_line l1
WHERE t1.gl_sl_link_table = 'CUX_GL_INTERFACE_LINE'
AND t1.gl_sl_link_id = l1.source_id
AND cg.interface_id = l1.interface_id
AND (p_org_code IS NULL OR l1.segment1 = p_org_code));
--行
UPDATE cux_gl_interface_line cg
SET cg.request_id = g_gl_request_id,
cg.created_by = fnd_global.user_id,
cg.last_update_date = SYSDATE,
cg.last_updated_by = fnd_global.user_id,
cg.process_status = 'SUCCESS'
WHERE cg.user_je_source_name = rec_sub.user_je_source_name
AND cg.batch_id = nvl(p_batch_id, cg.batch_id)
AND cg.source_code = nvl(p_source_code, cg.source_code)
AND (p_org_code IS NULL OR cg.segment1 = p_org_code)
AND cg.process_status = 'V'
AND EXISTS
(SELECT 1
FROM gl_je_lines t1
WHERE t1.gl_sl_link_table = 'CUX_GL_INTERFACE_LINE'
AND t1.gl_sl_link_id = cg.source_id);
/*--过账
IF nvl(p_ispost, 'N') = 'Y' THEN
log_msg('------------5.过账-------------');
l_post_run_id := gl_je_batches_post_pkg.get_unique_id;
l_post_request_id := fnd_request.submit_request('SQLGL',
'GLPPOSS',
'',
'',
FALSE,
to_char(fnd_profile.value('GL_SET_OF_BKS_ID')),
to_char(fnd_profile.value('GL_ACCESS_SET_ID')),
to_char(l_coa_id),
to_char(l_post_run_id),
chr(0));
IF l_post_request_id IS NULL OR l_post_request_id <= 0 THEN
UPDATE cux_gl_interface_header t
SET t.process_status = 'POST-FAIL',
t.error_message = '过账失败'
WHERE (p_batch_id IS NULL OR t.batch_id = p_batch_id)
AND (p_source_code IS NULL OR
t.source_code = p_source_code)
AND t.group_id = l_group_id;
ELSE
UPDATE gl_je_batches b
SET b.posting_run_id = l_post_run_id, b.status = 'S'
WHERE b.group_id = l_group_id;
COMMIT;
l_wait_req := fnd_concurrent.wait_for_request(l_post_request_id,
1,
0,
l_child_phase,
l_child_status,
l_dev_phase,
l_dev_status,
l_message);
IF l_child_status <> '正常' THEN
UPDATE cux_gl_interface_header t
SET t.process_status = 'POST-FAIL',
t.error_message = '过账请求运行失败,请联系系统管理员;'
WHERE (p_batch_id IS NULL OR t.batch_id = p_batch_id)
AND (p_source_code IS NULL OR
t.source_code = p_source_code)
AND t.group_id = l_group_id;
END IF;
END IF;
END IF;*/
ELSE
UPDATE cux.cux_gl_interface_header cgi
SET cgi.process_status = 'FAILURE',
cgi.error_message = x_error_message
WHERE (p_source_code IS NULL OR
cgi.source_code = p_source_code)
AND (p_batch_id IS NULL OR cgi.batch_id = p_batch_id)
AND cgi.process_status = 'V'
AND EXISTS
(SELECT 1
FROM cux_gl_interface_line l
WHERE cgi.interface_id = l.interface_id
AND cgi.batch_id = l.batch_id
AND (p_org_code IS NULL OR l.segment1 = p_org_code));
UPDATE cux.cux_gl_interface_line cgi
SET cgi.process_status = 'FAILURE',
cgi.error_message = x_error_message
WHERE (p_source_code IS NULL OR
cgi.source_code = p_source_code)
AND (p_batch_id IS NULL OR cgi.batch_id = p_batch_id)
AND (p_org_code IS NULL OR cgi.segment1 = p_org_code)
AND cgi.process_status = 'V';
END IF;
DELETE gl_interface_control f
WHERE f.interface_run_id = l_int_ctl_rec.interface_run_id;
END IF;
END LOOP;
--过账
--过账
IF nvl(p_ispost, 'N') = 'Y' THEN
log_msg('------------5.过账-------------');
FOR rec IN (SELECT DISTINCT /*b.je_batch_id,*/ h.ledger_id,
h.je_source
FROM gl_je_batches b, gl_je_headers h
WHERE b.je_batch_id = h.je_batch_id
AND b.group_id = l_group_id) LOOP
l_return_status := NULL;
l_error_message := NULL;
autopost(p_set_of_books_id => rec.ledger_id,
p_je_batch_id => NULL,
p_je_source_name => rec.je_source,
p_je_category_name => NULL,
x_return_status => l_return_status,
x_error_message => l_error_message);
IF l_return_status <> 'S' THEN
UPDATE cux_gl_interface_header t
SET t.process_status = 'POST-FAIL',
t.error_message = '过账失败' || l_error_message
WHERE (p_batch_id IS NULL OR t.batch_id = p_batch_id)
AND (p_source_code IS NULL OR t.source_code = p_source_code)
AND t.process_status = 'S'
AND t.group_id = l_group_id
AND EXISTS
(SELECT 1
FROM gl_je_headers h
WHERE h.je_source = rec.je_source
AND h.je_header_id = t.je_header_id);
x_error_message := substr(x_error_message || l_error_message,
1,
4000);
END IF;
END LOOP;
END IF;
--更新制单人,审核人和过账人信息
log_msg('------------6.更新人员信息-------------');
BEGIN
FOR rec IN (SELECT h.je_header_id,
h.post_user_id,
h.create_user_id,
h.approve_user_id,
h.accrual_rev_period_name,
h.accrual_rev_status,
h.accrual_rev_je_header_id,
h.accrual_rev_change_sign_flag
FROM cux_gl_interface_header h
WHERE h.process_status = 'SUCCESS'
AND (p_batch_id IS NULL OR h.batch_id = p_batch_id)
AND (p_source_code IS NULL OR
h.source_code = p_source_code)
AND EXISTS
(SELECT 1
FROM cux_gl_interface_line l,
gl_je_batches b,
gl_je_headers jh,
gl_je_lines jl
WHERE jl.gl_sl_link_table =
'CUX_GL_INTERFACE_LINE'
AND jl.gl_sl_link_id = l.source_id
AND jl.je_header_id = jh.je_header_id
AND jh.je_batch_id = b.je_batch_id
AND (p_org_code IS NULL OR
l.segment1 = p_org_code))) LOOP
--更新创建人
UPDATE gl_je_headers t
SET t.created_by = rec.create_user_id,
t.last_updated_by = rec.create_user_id,
t.accrual_rev_change_sign_flag = rec.accrual_rev_change_sign_flag,
t.accrual_rev_period_name = rec.accrual_rev_period_name,
t.accrual_rev_status = rec.accrual_rev_status
WHERE t.je_header_id = rec.je_header_id;
IF p_ispost = 'Y' THEN
l_post_user_id := rec.post_user_id;
ELSE
l_post_user_id := NULL;
END IF;
UPDATE gl_je_batches b
SET b.posted_by = nvl(l_post_user_id, b.posted_by),
b.approver_employee_id = nvl(rec.approve_user_id,
b.approver_employee_id)
WHERE EXISTS (SELECT 1
FROM gl_je_headers h
WHERE h.je_batch_id = b.je_batch_id
AND h.je_header_id = rec.je_header_id);
END LOOP;
EXCEPTION
WHEN OTHERS THEN
x_return_status := fnd_api.g_ret_sts_error;
x_error_message := '更新人员信息失败' || SQLERRM;
END;
END IF;
log_msg(x_error_message);
--如果出现异常,则事务回滚
EXCEPTION
WHEN fnd_api.g_exc_error THEN
x_return_status := fnd_api.g_ret_sts_error;
x_error_message := '并发请求提交失败' || SQLERRM;
log_msg(x_error_message);
ROLLBACK;
WHEN fnd_api.g_exc_unexpected_error THEN
x_return_status := fnd_api.g_ret_sts_unexp_error;
x_error_message := '并发请求提交失败' || SQLERRM;
log_msg(x_error_message);
ROLLBACK;
WHEN OTHERS THEN
x_return_status := fnd_api.g_ret_sts_unexp_error;
x_error_message := g_package_name || '.' || l_api_name ||
' execute error : ' ||
dbms_utility.format_error_stack;
log_msg(x_error_message);
ROLLBACK;
END process_request;
PROCEDURE validate_data(p_source_code IN VARCHAR2, --外部系统
p_batch_id IN NUMBER, --外部系统批ID
p_org_code IN VARCHAR2 DEFAULT NULL,
p_je_source IN VARCHAR2 DEFAULT NULL,
p_je_category IN VARCHAR2 DEFAULT NULL,
x_return_status OUT NOCOPY VARCHAR2,
x_error_message OUT NOCOPY VARCHAR2) IS
l_api_name VARCHAR2(32) := 'validate_data';
l_exist_count NUMBER;
l_local_currency_code VARCHAR2(120);
l_rec_h cux_gl_interface_header%ROWTYPE;
l_rec_l cux_gl_interface_line%ROWTYPE;
l_h_error_flag VARCHAR2(1); --头信息错误标识
l_l_error_flag VARCHAR2(1); --头信息错误标识
l_errbuf VARCHAR2(240);
l_retcode NUMBER;
l_period_name VARCHAR2(120);
l_org_id NUMBER;
l_h_msg_data VARCHAR2(4000);
l_l_msg_data VARCHAR2(4000);
l_currency_code VARCHAR2(120);
l_lock_flag NUMBER;
l_closing_status VARCHAR2(240);
l_base_currency_code VARCHAR2(240);
l_show_inverse_con_rate NUMBER;
l_chart_of_accounts_id NUMBER;
l_ledger_id NUMBER;
l_je_source_name VARCHAR2(240);
l_je_category_name VARCHAR2(240);
l_segment VARCHAR2(240);
l_line_count NUMBER;
l_exists_count NUMBER;
l_posting_allowed_flag VARCHAR2(10);
l_new_to_old_segment4 VARCHAR2(30);
l_new_to_old_segment9 VARCHAR2(30);
CURSOR cur_h IS
SELECT t.interface_id,
t.batch_id,
t.source_code,
t.source_header_id,
t.source_count,
t.status,
t.ledger_id,
t.ledger_name,
t.accounting_date,
t.actual_flag,
t.user_je_category_name,
t.user_je_source_name user_je_source_name,
t.currency_code,
t.currency_conversion_date,
t.user_currency_conversion_type,
t.currency_conversion_rate,
t.accrual_rev_period_name,
t.accrual_rev_status,
t.accrual_rev_je_header_id,
t.accrual_rev_change_sign_flag,
t.reference1,
t.reference2,
t.reference3,
t.reference4,
t.reference5,
t.reference6,
t.reference7,
t.reference8,
t.reference9,
t.create_user_name,
t.create_user_id,
t.approve_user_name,
t.approve_user_id,
t.post_user_name,
t.post_user_id,
t.set_of_books_id,
t.group_id,
t.je_header_id,
t.request_id,
t.process_status,
t.error_message,
t.creation_date,
t.created_by,
t.last_updated_by,
t.last_update_date,
t.last_update_login,
t.attribute_category,
t.attribute1,
t.attribute2,
t.attribute3,
t.attribute4,
t.attribute5,
t.attribute6,
t.attribute7,
t.attribute8,
t.attribute9,
t.attribute10,
t.attribute11,
t.attribute12,
t.attribute13,
t.attribute14,
t.attribute15
FROM cux_gl_interface_header t
WHERE nvl(t.process_status, 'NEW') IN ('NEW', 'VALID-ERROR')
AND (p_source_code IS NULL OR t.source_code = p_source_code)
AND (p_je_category IS NULL OR
t.user_je_category_name = p_je_category)
AND (p_je_source IS NULL OR t.user_je_source_name = p_je_source)
AND ((p_batch_id IS NULL AND
nvl(t.process_status, 'NEW') = 'VALID-ERROR') OR
t.batch_id = p_batch_id)
AND EXISTS
(SELECT 1
FROM cux_gl_interface_line l
WHERE t.interface_id = l.interface_id
AND t.batch_id = l.batch_id
AND (p_org_code IS NULL OR l.segment1 = p_org_code));
CURSOR cur_l(p_interface_id NUMBER, p_batch_id NUMBER) IS
SELECT *
FROM cux_gl_interface_line l
WHERE l.interface_id = p_interface_id
AND l.batch_id = p_batch_id;
BEGIN
x_return_status := fnd_api.g_ret_sts_success;
g_return_status := 'V';
FOR rec_h IN cur_h LOOP
l_h_msg_data := NULL;
l_h_error_flag := 'N';
l_l_error_flag := 'N';
l_h_msg_data := NULL;
l_rec_h.create_user_id := NULL;
l_rec_h.approve_user_id := NULL;
l_rec_h.post_user_id := NULL;
--0 验证是否已经导入系统
l_exist_count := 0;
--锁表
l_lock_flag := lock_data(rec_h.source_code, rec_h.source_header_id);
IF l_lock_flag = 0 THEN
l_h_msg_data := l_h_msg_data || ';锁表失败,数据正在处理';
x_return_status := fnd_api.g_ret_sts_error;
--x_error_message := x_error_message || l_h_msg_data;
l_h_error_flag := 'Y';
END IF;
--获取账套
l_ledger_id := fnd_profile.value_wnps('GL_SET_OF_BKS_ID');
BEGIN
SELECT gl.currency_code, gl.chart_of_accounts_id
INTO l_base_currency_code, l_chart_of_accounts_id
FROM gl_ledgers gl
WHERE gl.ledger_id = l_ledger_id;
EXCEPTION
WHEN OTHERS THEN
l_h_msg_data := l_h_msg_data || '账套信息获取失败';
x_return_status := fnd_api.g_ret_sts_error;
/*x_error_message := substr(x_error_message || l_h_msg_data,
1,
4000);*/
l_h_error_flag := 'Y';
END;
--验证汇率(本位币和传送币种不一致验证汇率)
IF l_base_currency_code <> rec_h.currency_code THEN
IF rec_h.currency_conversion_date IS NULL OR
rec_h.user_currency_conversion_type IS NULL THEN
l_h_msg_data := l_h_msg_data || '汇率日期或者汇率类型为空';
x_return_status := fnd_api.g_ret_sts_error;
/*x_error_message := substr(x_error_message || l_h_msg_data,
1,
4000);*/
l_h_error_flag := 'Y';
ELSE
--获取汇率信息
IF rec_h.user_currency_conversion_type IN ('Spot', 'Corporate') THEN
BEGIN
SELECT t.show_inverse_con_rate
INTO l_show_inverse_con_rate
FROM gl_daily_rates_v t
WHERE t.from_currency = l_base_currency_code
AND t.to_currency = rec_h.currency_code
AND t.conversion_date = rec_h.currency_conversion_date
AND t.user_conversion_type =
rec_h.user_currency_conversion_type;
IF l_show_inverse_con_rate <> rec_h.currency_conversion_rate THEN
l_h_msg_data := l_h_msg_data || '汇率类型' ||
rec_h.user_currency_conversion_type ||
'汇率日期' ||
to_char(rec_h.currency_conversion_date,
'yyyy-mm-dd') || '汇率维护不一致';
x_return_status := fnd_api.g_ret_sts_error;
/*x_error_message := substr(x_error_message || l_h_msg_data,
1,
4000);*/
l_h_error_flag := 'Y';
END IF;
EXCEPTION
WHEN no_data_found THEN
l_h_msg_data := l_h_msg_data || '汇率类型' ||
rec_h.user_currency_conversion_type ||
'汇率日期' ||
to_char(rec_h.currency_conversion_date,
'yyyy-mm-dd') || '没有维护汇率';
x_return_status := fnd_api.g_ret_sts_error;
/*x_error_message := substr(x_error_message || l_h_msg_data,
1,
4000);*/
l_h_error_flag := 'Y';
WHEN OTHERS THEN
l_h_msg_data := l_h_msg_data || '汇率类型' ||
rec_h.user_currency_conversion_type ||
'汇率日期' ||
to_char(rec_h.currency_conversion_date,
'yyyy-mm-dd') || '获取失败';
x_return_status := fnd_api.g_ret_sts_error;
/*x_error_message := substr(x_error_message || l_h_msg_data,
1,
4000);*/
l_h_error_flag := 'Y';
END;
END IF;
END IF;
END IF;
--验证来源
BEGIN
SELECT gjs.je_source_name
INTO l_je_source_name
FROM gl_je_sources_vl gjs
WHERE gjs.user_je_source_name = rec_h.user_je_source_name;
EXCEPTION
WHEN OTHERS THEN
l_h_msg_data := l_h_msg_data || '日记账来源错误';
x_return_status := fnd_api.g_ret_sts_error;
/*x_error_message := substr(x_error_message || l_h_msg_data,
1,
4000);*/
l_h_error_flag := 'Y';
END;
--验证类别
BEGIN
SELECT gjc.je_category_name
INTO l_je_category_name
FROM gl_je_categories gjc
WHERE gjc.user_je_category_name = rec_h.user_je_category_name;
EXCEPTION
WHEN OTHERS THEN
l_h_msg_data := l_h_msg_data || '日记账类别错误';
x_return_status := fnd_api.g_ret_sts_error;
/* x_error_message := substr(x_error_message || l_h_msg_data,
1,
4000);*/
l_h_error_flag := 'Y';
END;
--期间是否打开
BEGIN
SELECT 'Y'
INTO l_closing_status
FROM gl_period_statuses gps
WHERE gps.set_of_books_id = l_ledger_id
AND gps.period_name = to_char(rec_h.accounting_date, 'yyyy-mm')
AND gps.closing_status = 'O'
AND gps.application_id = 101;
EXCEPTION
WHEN OTHERS THEN
l_h_msg_data := l_h_msg_data || '总账期间没打开';
x_return_status := fnd_api.g_ret_sts_error;
/* x_error_message := substr(x_error_message || l_h_msg_data,
1,
4000);*/
l_h_error_flag := 'Y';
END;
--创建人
IF rec_h.create_user_name IS NOT NULL THEN
l_rec_h.create_user_id := get_user_id(rec_h.create_user_name);
IF l_rec_h.create_user_id IN (-1, -2, -3) THEN
l_h_msg_data := l_h_msg_data || '创建人不存在';
x_return_status := fnd_api.g_ret_sts_error;
/*x_error_message := substr(x_error_message || l_h_msg_data,
1,
4000);*/
l_h_error_flag := 'Y';
END IF;
END IF;
--审核人
IF rec_h.approve_user_name IS NOT NULL THEN
l_rec_h.approve_user_id := get_employee_id(rec_h.approve_user_name);
IF l_rec_h.approve_user_id IN (-1, -2, -3) THEN
l_h_msg_data := l_h_msg_data || '审核人不存在';
x_return_status := fnd_api.g_ret_sts_error;
/*x_error_message := substr(x_error_message || l_h_msg_data,
1,
4000);*/
l_h_error_flag := 'Y';
END IF;
END IF;
--过账人
IF rec_h.post_user_name IS NOT NULL THEN
l_rec_h.post_user_id := get_user_id(rec_h.post_user_name);
IF l_rec_h.post_user_id IN (-1, -2, -3) THEN
l_h_msg_data := l_h_msg_data || '过账人不存在';
x_return_status := fnd_api.g_ret_sts_error;
/*x_error_message := substr(x_error_message || l_h_msg_data,
1,
4000);*/
l_h_error_flag := 'Y';
END IF;
END IF;
--验证数据
BEGIN
SELECT COUNT(1)
INTO l_line_count
FROM cux_gl_interface_line l
WHERE l.interface_id = rec_h.interface_id
AND l.batch_id = rec_h.batch_id;
IF l_line_count <> rec_h.source_count THEN
l_h_msg_data := l_h_msg_data || '头数量' || rec_h.source_count ||
'和行数量' || l_line_count || '不一致';
x_return_status := fnd_api.g_ret_sts_error;
/*x_error_message := substr(x_error_message || l_h_msg_data,
1,
4000);*/
l_h_error_flag := 'Y';
END IF;
EXCEPTION
WHEN OTHERS THEN
l_h_msg_data := l_h_msg_data || '行数量获取错误';
x_return_status := fnd_api.g_ret_sts_error;
/*x_error_message := substr(x_error_message || l_l_msg_data,
1,
4000);*/
l_h_error_flag := 'Y';
END;
FOR rec_l IN cur_l(rec_h.interface_id, rec_h.batch_id) LOOP
l_l_msg_data := NULL;
l_exist_count := 0;
l_rec_l.old_segment1 := NULL;
l_rec_l.old_segment2 := NULL;
l_rec_l.old_segment3 := NULL;
l_rec_l.old_segment4 := NULL;
l_rec_l.old_segment5 := NULL;
l_rec_l.old_segment6 := NULL;
l_rec_l.old_segment7 := NULL;
l_rec_l.old_segment8 := NULL;
l_rec_l.code_combination_id := NULL;
--判断是否已经存在
BEGIN
SELECT COUNT(1)
INTO l_exist_count
FROM gl_je_lines l
WHERE l.gl_sl_link_table = 'CUX_GL_INTERFACE_LINE'
AND l.gl_sl_link_id =
to_number(rec_h.source_header_id || rec_l.source_line_num);
IF l_exist_count >= 1 THEN
l_l_msg_data := l_l_msg_data || '改单已经导入系统';
x_return_status := fnd_api.g_ret_sts_error;
/* x_error_message := substr(x_error_message || l_l_msg_data,
1,
4000);*/
l_l_error_flag := 'Y';
END IF;
EXCEPTION
WHEN OTHERS THEN
l_l_msg_data := l_l_msg_data ||'查看存在性报错' || l_rec_l.old_segment3;
x_return_status := fnd_api.g_ret_sts_error;
/*x_error_message := substr(x_error_message || l_l_msg_data,
1,
4000);*/
l_l_error_flag := 'Y';
END;
--公司
l_rec_l.old_segment1 := get_old_segment_value('GZ_COA_COMPANY_NEW',
rec_l.segment1);
IF l_rec_l.old_segment1 IN ('M', 'O', 'N') THEN
l_l_msg_data := l_l_msg_data ||'公司映射错误' || l_rec_l.old_segment1;
x_return_status := fnd_api.g_ret_sts_error;
/*x_error_message := substr(x_error_message || l_l_msg_data,
1,
4000);*/
l_l_error_flag := 'Y';
ELSIF l_rec_l.old_segment1 <> rec_l.segment1 AND
l_rec_l.old_segment1 <> '8888' THEN
l_l_msg_data :=l_l_msg_data || '公司映射错误' || l_rec_l.old_segment1;
x_return_status := fnd_api.g_ret_sts_error;
/*x_error_message := substr(x_error_message || l_l_msg_data,
1,
4000);*/
l_l_error_flag := 'Y';
END IF;
--成本中心
IF rec_l.new_segment2 = '0' THEN
l_rec_l.old_segment3 := '0';
ELSE
l_rec_l.old_segment3 := get_old_segment_value('GZ_COA_DEPARTMENT_NEW',
rec_l.new_segment2);
IF l_rec_l.old_segment3 IN ('M', 'O', 'N') THEN
l_l_msg_data := l_l_msg_data ||'成本中心映射错误' || l_rec_l.old_segment3;
x_return_status := fnd_api.g_ret_sts_error;
/*x_error_message := substr(x_error_message || l_l_msg_data,
1,
4000);*/
l_l_error_flag := 'Y';
END IF;
END IF;
--会计科目
l_rec_l.old_segment2 := get_old_segment_value('GZ_COA_ACCOUNT_NEW',
rec_l.new_segment3);
--管理科目(不允许为0)
l_rec_l.old_segment4 := get_old_segment_value('GZ_COA_MANAGEACC_NEW',
rec_l.new_segment5);
--明细段(特殊处理)
l_new_to_old_segment4 := get_old_segment_value('GZ_COA_SUBACC_NEW',
rec_l.new_segment4);
l_new_to_old_segment9 := get_old_segment_value('GZ_COA_BRU_NEW',
rec_l.new_segment9);
IF l_new_to_old_segment4 NOT IN ('M', 'O', 'N', '0') AND
l_new_to_old_segment9 NOT IN ('M', 'O', 'N', '0') THEN
l_l_msg_data := l_l_msg_data ||'明细段与往来段同时存在';
x_return_status := fnd_api.g_ret_sts_error;
/*x_error_message := substr(x_error_message || l_l_msg_data,
1,
4000);*/
l_l_error_flag := 'Y';
ELSIF l_new_to_old_segment4 <> '0' THEN
l_rec_l.old_segment5 := l_new_to_old_segment4;
IF l_rec_l.old_segment5 IN ('M', 'O', 'N') THEN
l_l_msg_data :=l_l_msg_data || '明细段映射错误' || l_rec_l.old_segment5;
x_return_status := fnd_api.g_ret_sts_error;
/* x_error_message := substr(x_error_message || l_l_msg_data,
1,
4000);*/
l_l_error_flag := 'Y';
END IF;
ELSIF l_new_to_old_segment9 <> '0' THEN
l_rec_l.old_segment5 := l_new_to_old_segment9;
IF l_rec_l.old_segment5 IN ('M', 'O', 'N') THEN
l_l_msg_data := l_l_msg_data ||'明细段映射错误' || l_rec_l.old_segment5;
x_return_status := fnd_api.g_ret_sts_error;
/*x_error_message := substr(x_error_message || l_l_msg_data,
1,
4000);*/
l_l_error_flag := 'Y';
END IF;
ELSE
l_rec_l.old_segment5 := '0';
END IF;
--区域段
IF rec_l.new_segment6 = '0' THEN
l_rec_l.old_segment6 := '0';
ELSE
l_rec_l.old_segment6 := get_old_segment_value('GZ_COA_REGION_NEW',
rec_l.new_segment6);
IF l_rec_l.old_segment6 IN ('M', 'O', 'N') THEN
l_l_msg_data := l_l_msg_data ||'区域段映射错误' || l_rec_l.old_segment6;
x_return_status := fnd_api.g_ret_sts_error;
/* x_error_message := substr(x_error_message || l_l_msg_data,
1,
4000);*/
l_l_error_flag := 'Y';
END IF;
END IF;
--产品段
IF rec_l.new_segment7 = '0' THEN
l_rec_l.old_segment7 := '0';
ELSE
l_rec_l.old_segment7 := get_old_segment_value('GZ_COA_PRODUCT_NEW',
rec_l.new_segment7);
END IF;
--岗位段
IF rec_l.new_segment8 = '0' THEN
l_rec_l.old_segment8 := '0';
ELSE
l_rec_l.old_segment8 := get_old_segment_value('GZ_COA_POSITION_NEW',
rec_l.new_segment8);
IF l_rec_l.old_segment8 IN ('M', 'O', 'N') THEN
l_l_msg_data :=l_l_msg_data || '岗位段映射错误' || l_rec_l.old_segment8;
x_return_status := fnd_api.g_ret_sts_error;
/*x_error_message := substr(x_error_message || l_l_msg_data,
1,
4000);*/
l_l_error_flag := 'Y';
END IF;
END IF;
--------------------------金融特殊逻辑----------------------
--金融特殊逻辑
get_old_segment_special(p_new_account => rec_l.new_segment3, --新科目
p_new_manacc => rec_l.new_segment5, --新科目
p_new_unit_code => rec_l.new_segment9, --新往来
p_new_produce => rec_l.new_segment7, --新产品
x_old_account => l_rec_l.old_segment2, --老科目
x_old_manacc => l_rec_l.old_segment4, --老科目
x_old_produce => l_rec_l.old_segment7); --老产品
--------------------------------------------------------------
--判断错误
--2 4 7
IF l_rec_l.old_segment2 IN ('M', 'O', 'N') THEN
l_l_msg_data := l_l_msg_data ||'会计科目映射错误' || l_rec_l.old_segment2;
x_return_status := fnd_api.g_ret_sts_error;
/*x_error_message := substr(x_error_message || l_l_msg_data,
1,
4000);*/
l_l_error_flag := 'Y';
END IF;
IF l_rec_l.old_segment4 IN ('M', 'O', 'N') THEN
l_l_msg_data := l_l_msg_data ||'管理科目映射错误' || l_rec_l.old_segment4;
x_return_status := fnd_api.g_ret_sts_error;
/* x_error_message := substr(x_error_message || l_l_msg_data,
1,
4000);*/
l_l_error_flag := 'Y';
END IF;
IF l_rec_l.old_segment7 IN ('M', 'O', 'N') THEN
l_l_msg_data := l_l_msg_data ||'产品段映射错误' || l_rec_l.old_segment7;
x_return_status := fnd_api.g_ret_sts_error;
/*x_error_message := substr(x_error_message || l_l_msg_data,
1,
4000);*/
l_l_error_flag := 'Y';
END IF;
IF l_l_msg_data IS NULL THEN
--获取ccid
l_segment := TRIM(l_rec_l.old_segment1 || '.' ||
l_rec_l.old_segment2 || '.' ||
l_rec_l.old_segment3 || '.' ||
l_rec_l.old_segment4 || '.' ||
l_rec_l.old_segment5 || '.' ||
l_rec_l.old_segment6 || '.' ||
l_rec_l.old_segment7 || '.' ||
l_rec_l.old_segment8);
l_rec_l.code_combination_id := get_code_combination_id(l_segment,
l_chart_of_accounts_id,
l_posting_allowed_flag);
IF l_rec_l.code_combination_id = -1 THEN
l_l_msg_data := l_l_msg_data ||'账户组合错误:' || l_segment;
x_return_status := fnd_api.g_ret_sts_error;
/* x_error_message := substr(x_error_message || l_l_msg_data,
1,
4000);*/
l_l_error_flag := 'Y';
ELSIF l_posting_allowed_flag = 'N' THEN
l_l_msg_data := l_l_msg_data ||'账户组合不允许过账:' || l_segment;
x_return_status := fnd_api.g_ret_sts_error;
/*x_error_message := substr(x_error_message || l_l_msg_data,
1,
4000);*/
l_l_error_flag := 'Y';
END IF;
END IF;
--更新行数据
IF l_l_msg_data IS NULL THEN
UPDATE cux_gl_interface_line t
SET t.old_segment3 = l_rec_l.old_segment3,
t.old_segment2 = l_rec_l.old_segment2,
t.old_segment4 = l_rec_l.old_segment4,
t.old_segment5 = l_rec_l.old_segment5,
t.old_segment6 = l_rec_l.old_segment6,
t.old_segment7 = l_rec_l.old_segment7,
t.old_segment8 = l_rec_l.old_segment8,
t.old_segment1 = l_rec_l.old_segment1,
t.code_combination_id = l_rec_l.code_combination_id,
t.source_id = to_number(rec_h.source_header_id ||
rec_l.source_line_num),
t.user_je_category_name = rec_h.user_je_category_name,
t.user_je_source_name = rec_h.user_je_source_name,
t.process_status = 'V',
t.last_update_date = SYSDATE,
t.last_updated_by = fnd_global.user_id,
t.last_update_login = -1,
t.error_message = l_l_msg_data
WHERE t.interface_line_id = rec_l.interface_line_id;
ELSE
UPDATE cux_gl_interface_line t
SET t.old_segment3 = l_rec_l.old_segment3,
t.old_segment2 = l_rec_l.old_segment2,
t.old_segment4 = l_rec_l.old_segment4,
t.old_segment5 = l_rec_l.old_segment5,
t.old_segment6 = l_rec_l.old_segment6,
t.old_segment7 = l_rec_l.old_segment7,
t.old_segment8 = l_rec_l.old_segment8,
t.old_segment1 = l_rec_l.old_segment1,
t.source_id = to_number(rec_h.source_header_id ||
rec_l.source_line_num),
t.user_je_category_name = rec_h.user_je_category_name,
t.user_je_source_name = rec_h.user_je_source_name,
t.process_status = 'VALID-ERROR',
t.last_update_date = SYSDATE,
t.last_updated_by = fnd_global.user_id,
t.last_update_login = -1,
t.error_message = l_l_msg_data
WHERE t.interface_line_id = rec_l.interface_line_id;
END IF;
END LOOP;
--判断行是否存在错误,如果存在,更新头状态
IF l_h_error_flag = 'Y' OR l_l_error_flag = 'Y' THEN
UPDATE cux_gl_interface_header t
SET t.process_status = 'VALID-ERROR',
t.error_message = nvl(l_h_msg_data, '行存在错误'),
t.last_update_date = SYSDATE,
t.last_updated_by = fnd_global.user_id,
t.last_update_login = -1
WHERE t.interface_id = rec_h.interface_id;
UPDATE cux_gl_interface_line t
SET t.process_status = 'VALID-ERROR',
t.error_message = nvl(error_message,
decode(l_h_error_flag,
'Y',
'头存在错误',
'')),
t.last_update_date = SYSDATE,
t.last_updated_by = fnd_global.user_id,
t.last_update_login = -1
WHERE t.interface_id = rec_h.interface_id;
ELSE
UPDATE cux_gl_interface_header t
SET t.ledger_id = l_ledger_id,
t.create_user_id = nvl(l_rec_h.create_user_id, 0), --默认系统管理员
t.approve_user_id = l_rec_h.approve_user_id,
t.post_user_id = l_rec_h.post_user_id,
t.user_je_source_name = rec_h.user_je_source_name,
t.process_status = 'V',
t.last_update_date = SYSDATE,
t.last_updated_by = fnd_global.user_id,
t.last_update_login = -1,
t.error_message = l_h_msg_data
WHERE t.interface_id = rec_h.interface_id;
END IF;
log_msg('验证结果:' || l_l_msg_data);
log_msg('验证结果:' || l_msg_data);
END LOOP;
--TODO
EXCEPTION
WHEN fnd_api.g_exc_error THEN
x_return_status := fnd_api.g_ret_sts_error;
x_error_message := '验证失败' || x_error_message;
log_msg(x_error_message);
WHEN fnd_api.g_exc_unexpected_error THEN
x_return_status := fnd_api.g_ret_sts_unexp_error;
x_error_message := '验证失败' || x_error_message;
log_msg(x_error_message);
WHEN OTHERS THEN
x_return_status := fnd_api.g_ret_sts_unexp_error;
x_error_message := g_package_name || '.' || l_api_name ||
' execute error : ' ||
dbms_utility.format_error_stack;
log_msg(x_error_message);
END validate_data;
--输出报表
PROCEDURE print_data(errbuf OUT VARCHAR2,
retcode OUT NUMBER,
p_org_code IN VARCHAR2 DEFAULT NULL,
p_start_date IN VARCHAR2,
p_end_date IN VARCHAR2) IS
CURSOR cur_headers(p_start_date DATE, p_end_date DATE) IS
SELECT h.interface_id,
h.batch_id,
l.line_num,
h.source_code,
l.source_id,
h.source_header_id,
l.source_line_num,
h.status,
h.ledger_id,
h.ledger_name,
h.accounting_date,
h.actual_flag,
h.user_je_category_name,
h.user_je_source_name,
h.currency_code,
h.currency_conversion_date,
h.user_currency_conversion_type,
h.currency_conversion_rate,
h.accrual_rev_period_name,
h.accrual_rev_status,
h.accrual_rev_je_header_id,
h.accrual_rev_change_sign_flag,
h.reference1 batch_name,
h.reference2,
h.reference3,
h.reference4 je_name,
h.reference5,
h.reference6,
h.reference7,
h.reference8,
h.reference9,
l.reference10,
l.reference11,
l.reference12,
l.reference13,
l.reference14,
l.reference15,
l.reference16,
l.reference17,
l.reference18,
l.reference19,
l.reference20,
l.reference21,
l.reference22,
l.reference23,
l.reference24,
l.reference25,
l.reference26,
l.reference27,
l.reference28,
l.reference29,
l.reference30,
h.set_of_books_id,
h.group_id,
l.code_combination_id,
l.segment1,
l.old_segment1,
l.new_segment2,
l.old_segment3,
l.new_segment3,
l.old_segment2,
l.new_segment4,
l.old_segment5,
l.new_segment5,
l.old_segment4,
l.new_segment6,
l.old_segment6,
l.new_segment7,
l.old_segment7,
l.new_segment8,
l.old_segment8,
l.new_segment9,
l.new_segment10,
l.new_segment11,
l.segment1 || '.' || l.new_segment2 || '.' || l.new_segment3 || '.' ||
l.new_segment4 || '.' || l.new_segment5 || '.' ||
l.new_segment6 || '.' || l.new_segment7 || '.' ||
l.new_segment8 || '.' || l.new_segment9 || '.' ||
l.new_segment10 || '.' || l.new_segment11 new_segment,
get_flex_desc('GZ_COA_COMPANY_NEW', l.segment1) segment1_desc,
get_flex_desc('GZ_COA_DEPARTMENT_NEW', l.new_segment2) segment2_desc,
get_flex_desc('GZ_COA_ACCOUNT_NEW', l.new_segment3) segment3_desc,
get_flex_desc('GZ_COA_SUBACC_NEW', l.new_segment4) segment4_desc,
get_flex_desc('GZ_COA_MANAGEACC_NEW', l.new_segment5) segment5_desc,
get_flex_desc('GZ_COA_REGION_NEW', l.new_segment6) segment6_desc,
get_flex_desc('GZ_COA_PRODUCT_NEW', l.new_segment7) segment7_desc,
get_flex_desc('GZ_COA_POSITION_NEW', l.new_segment8) segment8_desc,
get_flex_desc('GZ_COA_BRU_NEW', l.new_segment9) segment9_desc,
l.old_segment1 || '.' || l.old_segment2 || '.' ||
l.old_segment3 || '.' || l.old_segment4 || '.' ||
l.old_segment5 || '.' || l.old_segment6 || '.' ||
l.old_segment7 || '.' || l.old_segment8 old_segment,
get_flex_desc('GZ_COA_COMPANY', l.old_segment1) old_segment1_desc,
get_flex_desc('GZ_COA_ACCOUNT', l.old_segment2) old_segment2_desc,
get_flex_desc('GZ_COA_DEPARTMENT', l.old_segment3) old_segment3_desc,
get_flex_desc('GZ_COA_MANAGEACC', l.old_segment4) old_segment4_desc,
get_flex_desc('GZ_COA_SUBACC', l.old_segment5) old_segment5_desc,
get_flex_desc('GZ_COA_REGION', l.old_segment6) old_segment6_desc,
get_flex_desc('GZ_COA_PRODUCT', l.old_segment7) old_segment7_desc,
get_flex_desc('GZ_COA_POSITION', l.old_segment8) old_segment8_desc,
l.entered_dr,
l.entered_cr,
l.accounted_dr,
l.accounted_cr,
l.process_status,
h.error_message || ';' || l.error_message error_message
FROM cux_gl_interface_header h, cux_gl_interface_line l
WHERE h.interface_id = l.interface_id
AND h.batch_id = l.batch_id
AND h.process_status <> 'SUCCESS'
AND h.accounting_date BETWEEN
nvl(p_start_date, h.accounting_date - 1) AND
nvl(p_end_date, h.accounting_date + 1)
AND (p_org_code IS NULL OR l.segment1 = p_org_code);
--l_org_name VARCHAR2(240);
l_user_name VARCHAR2(120);
l_line_num NUMBER := 0;
l_msg_count NUMBER;
l_msg_data VARCHAR2(2000);
l_start_date DATE;
l_end_date DATE;
BEGIN
--Init
retcode := 0;
errbuf := NULL;
l_start_date := fnd_conc_date.string_to_date(p_start_date);
l_end_date := fnd_conc_date.string_to_date(p_end_date);
cux_fnd_conc_utl.log_header;
output(' xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel">');
output('
序号 | 批次 | 批名 | 日记账名 | 日记账说明 | 来源 | 类别 | GL日期 | 币种 | 借方金额-本位币 | 贷方金额-本位币 | 借方金额-原币 | 贷方金额-原币 | 新erp科目组合 | 新-公司段 | 新-成本中心段 | 新-会计科目段 | 新-明细段 | 新-管理科目段 | 新-区域段 | 新-产品段 | 新-岗位段 | 新-往来段 | 老erp科目组合 | 老-公司段 | 老-会计科目段 | 老-成本中心段 | 老-管理科目段 | 老-明细科目段 | 老-区域段 | 老-产品段 | 老-岗位段 | 状态 | 错误信息 |
' || l_line_num || ' | ');' || rec_con.batch_id || ' | ');' || rec_con.batch_name || ' | ');' || rec_con.je_name || ' | ');' || rec_con.reference5 || ' | ');' || rec_con.user_je_source_name || ' | ');' || rec_con.user_je_category_name || ' | ');' || to_char(rec_con.accounting_date, 'YYYY-MM-DD') || ' | ');' || rec_con.currency_code || ' | ');' || rec_con.accounted_dr || ' | ');' || rec_con.accounted_cr || ' | ');' || rec_con.entered_dr || ' | ');' || rec_con.entered_cr || ' | ');' || rec_con.new_segment || ' | ');' || rec_con.segment1_desc || ' | ');' || rec_con.segment2_desc || ' | ');' || rec_con.segment3_desc || ' | ');' || rec_con.segment4_desc || ' | ');' || rec_con.segment5_desc || ' | ');' || rec_con.segment6_desc || ' | ');' || rec_con.segment7_desc || ' | ');' || rec_con.segment8_desc || ' | ');' || rec_con.segment9_desc || ' | ');' || rec_con.old_segment || ' | ');' || rec_con.old_segment1_desc || ' | ');' || rec_con.old_segment2_desc || ' | ');' || rec_con.old_segment3_desc || ' | ');' || rec_con.old_segment4_desc || ' | ');' || rec_con.old_segment5_desc || ' | ');' || rec_con.old_segment6_desc || ' | ');' || rec_con.old_segment7_desc || ' | ');' || rec_con.old_segment8_desc || ' | ');' || rec_con.process_status || ' | ');' || rec_con.error_message || ' | ');