--以下代码于20181002在Tony环境测试通过
/*
BEGIN
--mo_global.init('SQLAP');
apps.fnd_global.apps_initialize(user_id => 1110, resp_id => 50597, resp_appl_id => 20003);
--mo_global.set_policy_context('S', 0);
mo_global.init('M');--务必加上这个语句
END;
-- ALTER SESSION SET NLS_LANGUAGE = 'SIMPLIFIED CHINESE';
*/
/*select * from ap_checks;
select * from po_headers_all
*/
DECLARE
g_user_id CONSTANT NUMBER := fnd_global.user_id;
g_login_id CONSTANT NUMBER := fnd_global.login_id;
--
l_invoice_id NUMBER := 10103;
l_period_name VARCHAR2(20) := '2018-10';
l_set_of_books_id NUMBER;
l_exchange_rate NUMBER;
l_exchange_date DATE;
l_when_payment_accounted ap_system_parameters_all.when_to_account_pmt%TYPE;
l_count NUMBER;
l_stock_name VARCHAR2(50);
l_in_use_by VARCHAR2(20);
l_doc_category_code VARCHAR2(30);
l_last_document_num NUMBER;
l_quick_check VARCHAR2(200);
l_hold_all_payments_flag VARCHAR2(1);
l_payment_type_flag VARCHAR2(1) := 'Q'; --人工M,快速Q,退款R
l_status_lookup_code VARCHAR2(20) := 'NEGOTIABLE';
--
l_row_id VARCHAR2(240);
l_invoice_amount NUMBER; -- 付款额
l_bank_account_id NUMBER;
l_bank_account_name VARCHAR2(120);
l_gl_date DATE := last_day(trunc(SYSDATE));
l_check_id NUMBER;
l_check_number NUMBER;
l_invoice_currency_code VARCHAR2(10);
l_payment_method_lookup_code VARCHAR2(25);
l_address_line1 VARCHAR2(240);
l_address_line2 VARCHAR2(240);
l_address_line3 VARCHAR2(240);
l_checkrun_name VARCHAR2(50); -- 批名
l_check_format_id NUMBER;
l_check_stock_id NUMBER;
l_city VARCHAR2(25);
l_country VARCHAR2(25);
l_bank_account_num VARCHAR2(30);
l_bank_account_type VARCHAR2(30);
l_zip VARCHAR2(20);
l_province VARCHAR2(150);
l_state VARCHAR2(150);
l_address_line4 VARCHAR2(240);
l_county VARCHAR2(25);
l_address_style VARCHAR2(30);
l_org_id NUMBER;
l_vendor_id NUMBER;
l_vendor_site_id NUMBER;
l_VENDOR_SITE_CODE VARCHAR2(30);
l_VENDOR_NAME VARCHAR2(3000);
l_exchange_rate_type VARCHAR2(30);
l_party_site_id number;
l_party_id number;
l_ap_checks_all_row ap_checks_all%ROWTYPE;
--
l_accounting_event_id NUMBER;
--
l_invoice_payment_id NUMBER;
--
l_msg_count NUMBER;
l_msg_data VARCHAR2(1000);
l_err_msg VARCHAR2(10000);
PROCEDURE log(p_msg IN VARCHAR2) IS
BEGIN
dbms_output.put_line(p_msg);
END;
PROCEDURE get_msg(x_msg_count OUT NUMBER, x_msg_data OUT VARCHAR2) IS
BEGIN
fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false,
p_count => x_msg_count,
p_data => x_msg_data);
IF x_msg_count > 1 THEN
x_msg_data := fnd_msg_pub.get_detail(p_msg_index => fnd_msg_pub.g_first,
p_encoded => fnd_api.g_false);
END IF;
END;
BEGIN
dbms_output.enable(100000);
-- 1.0 获取发票信息
log('Step1.0 获取付款发票信息');
SELECT aia.invoice_amount,
aia.invoice_currency_code,
aia.set_of_books_id,
aia.org_id,
aia.vendor_id,
aia.vendor_site_id,
aia.exchange_rate,
aia.exchange_rate_type,
aia.exchange_date,
(SELECT pv.VENDOR_NAME from po_vendors pv where pv.VENDOR_ID = aia.vendor_id )
INTO l_invoice_amount,
l_invoice_currency_code,
l_set_of_books_id,
l_org_id,
l_vendor_id,
l_vendor_site_id,
l_exchange_rate,
l_exchange_rate_type,
l_exchange_date,
l_VENDOR_NAME
FROM ap_invoices_all aia
WHERE aia.invoice_id = l_invoice_id;
SELECT t.party_site_id, a.party_id
into l_party_site_id, l_party_id
FROM ap_supplier_sites_all t, ap_suppliers a
WHERE a.vendor_id = t.vendor_id
AND t.vendor_site_id = l_vendor_site_id; --p_vendor_site_id;
-- 1.2 获取GL_DATE
log('Step1.2 获取检查应付款选项设置参数 BEGIN');
-- 对应路径 应付超级职责 -> 设置 -> 选项 -> 应付款
-- 页签 本位币, 付款会计.将付款记账: 发放付款时, 币种.使用多币种
BEGIN
SELECT t.when_to_account_pmt
INTO l_when_payment_accounted
FROM ap_system_parameters_all t
WHERE t.set_of_books_id = l_set_of_books_id
AND t.org_id = l_org_id;
EXCEPTION
WHEN OTHERS THEN
l_err_msg := '获取业务实体信息(' || l_org_id || ')异常!' || SQLCODE || ',' ||
SQLERRM;
log(l_err_msg);
--RETURN;
END;
log('Step1.2 获取检查应付款选项设置参数 END WHEN[' || l_when_payment_accounted || ']');
-- 1.3 获取银行信息
log('Step1.3 获取付款银行信息 begin');
BEGIN
/* SELECT aba.bank_account_id, aba.bank_account_num, aba.bank_account_name, aba.bank_account_type
INTO l_bank_account_id, l_bank_account_num, l_bank_account_name, l_bank_account_type
FROM ap_bank_accounts_all aba
WHERE aba.bank_account_name = '虚拟银行'
AND aba.org_id = l_org_id;*/
SELECT ibybanks.bank_account_id,
ibybanks.bank_account_number,
ibybanks.bank_account_name,
ibybanks.bank_account_type
/* ibybanks.bank_name, --银行
ibybanks.bank_branch_name, --分行
ibybanks.bank_account_num_electronic, --银行帐号
ibybanks.**/
INTO l_bank_account_id,
l_bank_account_num,
l_bank_account_name,
l_bank_account_type
FROM iby_external_payers_all iepa,
iby_pmt_instr_uses_all ipiua,
iby_ext_bank_accounts_v ibybanks
WHERE 1 = 1 --iepa.payment_function = 'CUSTOMER_PAYMENT'
-- AND iepa.cust_account_id = p_customer_id --客户帐号ID
AND ibybanks.bank_account_id = ipiua.instrument_id
-- AND ipiua.instrument_type = 'BANKACCOUNT'
AND ipiua.ext_pmt_party_id = iepa.EXT_PAYER_ID
--AND ipiua.payment_function = 'CUSTOMER_PAYMENT'
AND sysdate BETWEEN ibybanks.start_date AND
nvl(ibybanks.end_date, sysdate + 1);
EXCEPTION
WHEN OTHERS THEN
l_err_msg := '获取付款银行 虚拟银行 异常!' || SQLCODE || ',' || SQLERRM;
log(l_err_msg);
RAISE fnd_api.g_exc_error;
END;
log('Step1.3.1 验证付款单据');
/* IF l_bank_account_id IS NOT NULL THEN
SELECT COUNT(1)
INTO l_count
FROM ap_check_stocks_all acs
WHERE acs.bank_account_id = l_bank_account_id;
IF l_count = 0 THEN
log('虚拟银行有误,找不到付款单据');
RAISE fnd_api.g_exc_error;
END IF;
END IF;*/
log('Step1.4.1 获取付款单据号');
/* BEGIN
SELECT NAME,
in_use_by,
check_stock_id,
check_format_id,
payment_method_lookup_code,
doc_category_code,
last_available_document_num
INTO l_stock_name,
l_in_use_by,
l_check_stock_id,
l_check_format_id,
l_payment_method_lookup_code,
l_doc_category_code,
l_last_document_num
FROM ap_check_stocks_active_v acs
WHERE (acs.format_currency_code = 'CNY' OR
(acs.format_currency_code IS NULL AND acs.format_multi_currency_flag = 'Y' AND
acs.bank_multi_currency_flag = 'Y'))
AND acs.disbursement_type_lookup_code != 'RECORDED'
AND SYSDATE < nvl(acs.inactive_date, SYSDATE + 1)
AND acs.payment_method_lookup_code = 'CHECK'
AND acs.bank_account_id = l_bank_account_id;
EXCEPTION
WHEN OTHERS THEN
l_err_msg := '获取付款银行帐号异常:' || SQLCODE || ',' || SQLERRM;
log(l_err_msg);
--RETURN;
END;*/
log('Step1.4.1 获取付款单据[ID: ' || l_check_stock_id || ']');
IF l_in_use_by IS NOT NULL THEN
log('Step1.4.1 付款单据---------------------------END l_in_use_by:' ||
l_in_use_by);
fnd_message.set_name('SQLAP', 'AP_PAY_DOCUMENT_ALREADY_IN_USE');
l_err_msg := '错误: ' || fnd_message.get;
log(l_err_msg);
--RETURN;
END IF;
log('Step1.4.2 锁定银行付款单据----------------------------------------BEGIN');
--锁定银行付款单据
/* BEGIN
SELECT last_document_num + 1
INTO l_check_number
FROM ap_check_stocks_all
WHERE check_stock_id = l_check_stock_id
FOR UPDATE OF last_document_num NOWAIT;
EXCEPTION
WHEN OTHERS THEN
log('锁定单据[' || l_stock_name || ']时异常[' || SQLERRM || ']');
--RETURN;
END;
--检查银行付款单据
IF nvl(l_check_number, 0) > nvl(l_last_document_num, 0) THEN
l_err_msg := '付款单据:' || l_stock_name || '的编号已经超过最大允许值.';
log(l_err_msg);
--RETURN;
END IF;*/
l_check_number := to_number(TO_CHAR(SYSDATE,'yyyymmddhh24miss'));
--检查付款编号是否重复
SELECT COUNT(1)
INTO l_count
FROM ap_checks_all aca
WHERE aca.check_stock_id = l_check_stock_id
AND aca.check_number = l_check_number;
log('l_duplicate:' || l_count);
IF (l_count > 0) THEN
fnd_message.set_name('SQLAP', 'AP_ALL_DUPLICATE_VALUE');
l_err_msg := chr(10) || '错误: 付款编号' || l_check_number || ' ' ||
fnd_message.get;
log(l_err_msg);
--RETURN;
END IF;
log('Step1.4.3 检查付款编号是否重复------------------------------------END');
log('Step1.4 付款单据号[' || l_check_number ||
']---------------------------END');
--check id
SELECT ap_checks_s.nextval INTO l_check_id FROM dual;
--checkrun name
IF l_payment_type_flag = 'Q' THEN
log('Step1.5 获取批名 --------------BEGIN');
BEGIN
SELECT alc.displayed_field
INTO l_quick_check
FROM ap_lookup_codes alc
WHERE alc.lookup_type = 'NLS TRANSLATION'
AND alc.lookup_code = 'QUICKCHECK ID';
EXCEPTION
WHEN OTHERS THEN
log('获取批名前缀时异常[' || SQLERRM || ']');
END;
l_checkrun_name := substrb(l_quick_check,
1,
30 - nvl(lengthb(to_char(l_check_id)), 0)) ||
to_char(l_check_id);
log('Step1.5 获取批名[' || l_checkrun_name || '] --------------END');
END IF;
log('Step1.6 获取供应商信息------------------------------------------BEGIN');
--获取供应商信息
BEGIN
SELECT pvs.address_line1,
pvs.address_line2,
pvs.address_line3,
pvs.address_line4,
nvl(pvs.address_style, 'DEFAULT') address_style,
pvs.city,
pvs.county,
pvs.state,
pvs.province,
pvs.zip,
pvs.country,
pvs.hold_all_payments_flag,
pvs.VENDOR_SITE_CODE
INTO l_address_line1,
l_address_line2,
l_address_line3,
l_address_line4,
l_address_style,
l_city,
l_county,
l_state,
l_province,
l_zip,
l_country,
l_hold_all_payments_flag,
l_VENDOR_SITE_CODE
FROM po_vendor_sites_all pvs
WHERE pvs.org_id = l_org_id
AND pvs.vendor_site_id = l_vendor_site_id;
EXCEPTION
WHEN OTHERS THEN
log('获取供应商地点[' || l_vendor_site_id || ']信息时异常[' || SQLERRM || ']');
END;
IF l_hold_all_payments_flag = 'Y' THEN
l_err_msg := '错误: ' || '当前供应商地点设置了"暂挂所有付款",不能创建付款.';
log(l_err_msg);
--RETURN;
END IF;
log('Step4.2.5 获取供应商信息------------------------------------------END');
----RETURN;
-- 2.1 插入供应商付款
log('Step2.1 插入供应商付款-------------------------------------------BEGIN');
BEGIN
/* ap_checks_pkg.insert_row(x_rowid => l_row_id,
x_amount => l_invoice_amount,
x_bank_account_id => l_bank_account_id,
x_bank_account_name => l_bank_account_name,
x_check_date => l_gl_date,
x_check_id => l_check_id,
x_check_number => l_check_number,
x_currency_code => l_invoice_currency_code,
x_last_updated_by => g_user_id,
x_last_update_date => SYSDATE,
x_payment_method_lookup_code => l_payment_method_lookup_code,
x_payment_type_flag => l_payment_type_flag,
x_address_line1 => l_address_line1,
x_address_line2 => l_address_line2,
x_address_line3 => l_address_line3,
x_checkrun_name => l_checkrun_name,
x_check_format_id => l_check_format_id,
x_check_stock_id => l_check_stock_id,
x_city => l_city,
x_country => l_country,
x_created_by => g_user_id,
x_creation_date => SYSDATE,
x_last_update_login => g_login_id,
x_status_lookup_code => l_status_lookup_code,
x_external_bank_account_id => NULL,
x_zip => l_zip,
x_bank_account_num => l_bank_account_num,
x_bank_account_type => l_bank_account_type,
x_doc_category_code => l_doc_category_code,
x_province => l_province,
x_state => l_state,
x_address_line4 => l_address_line4,
x_county => l_county,
x_address_style => l_address_style,
x_org_id => l_org_id,
x_vendor_id => l_vendor_id,
x_vendor_site_id => l_vendor_site_id,
x_exchange_rate_type => l_exchange_rate_type,
x_calling_sequence => 'CUX_API');*/
--参考广田cux_ce_req_pay_pub
ap_checks_pkg.insert_row(x_rowid => l_row_id,
x_amount => 200, --rec.amount,
x_ce_bank_acct_use_id => 10002, --l_bank_acct_use_id, --l_bank_account_id, --ce_bank_acct_use_id 替换 bank_account_id
x_bank_account_name => '00303_上海浦东发展银行深圳凤凰大厦支行_人民币一般户',/*substr('00303_上海浦东发展银行深圳凤凰大厦支行_人民币一般户',
1,
25), */--rec.bank_account_name,
/* SELECT cbau.bank_acct_use_id, cba.bank_account_name --银行账户 --状态
FROM ce_bank_accounts cba, --银行相关
ce_bank_acct_uses_all cbau --银行相关
WHERE cbau.bank_account_id = cba.bank_account_id(+)*/
x_check_date => trunc(sysdate),
x_check_id => l_check_id,
x_check_number => l_check_number,
x_currency_code => 'CNY',
x_last_updated_by => g_user_id,
x_last_update_date => SYSDATE,
x_payment_type_flag => l_payment_type_flag, --类型 M:Manual,Q:quick,R:refunds
x_address_line1 => l_address_line1,
x_address_line2 => l_address_line2,
x_address_line3 => l_address_line3,
x_checkrun_name => l_checkrun_name, --batch_name
x_check_format_id => NULL,
x_check_stock_id => NULL, --l_check_stock_id,
x_city => l_city,
x_country => l_country,
x_created_by => g_user_id,
x_creation_date => SYSDATE,
x_last_update_login => g_login_id,
x_status_lookup_code => l_status_lookup_code, --'NEGOTIABLE'; --状态,可转让
x_vendor_name => NULL, /*rec.vendor_name,*/
x_vendor_site_code => l_vendor_site_code,
x_external_bank_account_id => NULL,
x_zip => l_zip,
x_bank_account_num => '79030155100000303', --select t.bank_account_num,t.* from CE.CE_BANK_ACCOUNTS t
x_bank_account_type => NULL,
x_bank_num => NULL,
x_check_voucher_num => NULL,
x_cleared_amount => NULL,
x_cleared_date => NULL,
x_doc_category_code => NULL,
x_doc_sequence_id => NULL,
x_doc_sequence_value => NULL,
x_province => l_province,
x_released_date => NULL,
x_released_by => NULL,
x_state => l_state,
x_stopped_date => NULL,
x_stopped_by => NULL,
x_void_date => NULL,
x_attribute1 => NULL,
x_attribute10 => NULL,
x_attribute11 => NULL,
x_attribute12 => NULL,
x_attribute13 => NULL,
x_attribute14 => NULL,
x_attribute15 => NULL,
x_attribute2 => NULL,
x_attribute3 => NULL,
x_attribute4 => NULL,
--update by feng.han start
--)[32655]修改付款申请创建付款逻辑并修复已生成的付款
--x_attribute5 => NULL,
x_attribute5 => NULL,
--update end;
x_attribute6 => NULL,
x_attribute7 => NULL,
x_attribute8 => NULL,
x_attribute9 => NULL,
x_attribute_category => NULL,
x_future_pay_due_date => NULL, --rec.end_date,--rec.pay_date,
x_treasury_pay_date => NULL,
x_treasury_pay_number => NULL,
x_withholding_status_lkup_code => NULL,
x_reconciliation_batch_id => NULL,
x_cleared_base_amount => NULL,
x_cleared_exchange_rate => NULL,
x_cleared_exchange_date => NULL,
x_cleared_exchange_rate_type => NULL,
x_address_line4 => L_address_line4,
x_county => l_county,
x_address_style => NULL,--l_address_style,
x_org_id => L_org_id,
x_vendor_id => L_vendor_id,
x_vendor_site_id => L_vendor_site_id,
x_exchange_rate => null,--1, --rec.conversion_rate,
x_exchange_date => TRUNC(SYSDATE), --rec.conversion_date,
x_exchange_rate_type => null,--'Coporate', --rec.conversion_type,
x_base_amount => null,--200,
x_checkrun_id => NULL,
x_global_attribute_category => NULL,
x_global_attribute1 => NULL,
x_global_attribute2 => NULL,
x_global_attribute3 => NULL,
x_global_attribute4 => NULL,
x_global_attribute5 => NULL,
x_global_attribute6 => NULL,
x_global_attribute7 => NULL,
x_global_attribute8 => NULL,
x_global_attribute9 => NULL,
x_global_attribute10 => NULL,
x_global_attribute11 => NULL,
x_global_attribute12 => NULL,
x_global_attribute13 => NULL,
x_global_attribute14 => NULL,
x_global_attribute15 => NULL,
x_global_attribute16 => NULL,
x_global_attribute17 => NULL,
x_global_attribute18 => NULL,
x_global_attribute19 => NULL,
x_global_attribute20 => NULL,
x_transfer_priority => NULL,
x_maturity_exchange_rate_type => NULL,
x_maturity_exchange_date => NULL,
x_maturity_exchange_rate => NULL,
x_description => '测试描述',
x_anticipated_value_date => NULL,
x_actual_value_date => NULL,
x_payment_method_code => 'EFT', --rec.pay_method,
--update by feng.han 2014-2-12 start
--)[32581]数据修复
x_payment_profile_id => 99, --l_payment_profile_id,
--x_payment_profile_id => 162, ---付款处理文件
--update end;
x_bank_charge_bearer => NULL, ---
x_settlement_priority => NULL, ---
x_payment_document_id => NULL, ---
x_party_id => l_party_id, ---
x_party_site_id => l_party_site_id, ---
x_legal_entity_id => 23274, --rec.legal_context_id, ---
x_payment_id => NULL, ---
x_calling_sequence => 'CREATE_AP_PAYMENT', -- VARCHAR2
x_remit_to_supplier_name => l_vendor_name,--NULL, ---
x_remit_to_supplier_id => l_vendor_id,--NULL, ---
x_remit_to_supplier_site => l_vendor_site_code,--null ---
x_remit_to_supplier_site_id => l_vendor_site_id,--NULL, ---
x_relationship_id => -1,--NULL, ---
x_paycard_authorization_number => NULL, ---
x_paycard_reference_id => NULL ---
);
-- commit;
EXCEPTION
WHEN OTHERS THEN
log('Step2.1 插入供应商付款异常: ');
l_err_msg := SQLERRM;
WHILE lengthb(l_err_msg) > 0 LOOP
log(substrb(l_err_msg, 1, 255));
l_err_msg := substrb(l_err_msg, 256);
END LOOP;
--RETURN;
END;
SELECT COUNT(1)
INTO l_count
FROM ap_checks_all aca
WHERE aca.check_id = l_check_id;
IF l_count = 0 THEN
log('插入供应商付款失败');
--RETURN;
END IF;
log('Step2.1 插入供应商付款-------------------------------------------END');
-- 创建会计事件
log('Step2.2 创建会计事件------------------------------------------BEGIN');
IF l_when_payment_accounted = 'ALWAYS' THEN
-- 发放付款时
BEGIN
/* ap_accounting_events_pkg.create_events(p_event_type => 'PAYMENT',
p_doc_id => l_check_id,
p_accounting_date => l_gl_date, --SYSDATE, 2014-11-10
p_accounting_event_id => l_accounting_event_id,
p_checkrun_name => NULL,
p_calling_sequence => 'CUX_API');*/
ap_accounting_events_pkg.create_events(p_event_type => 'PAYMENT',
p_doc_type => l_payment_type_flag,
p_doc_id => l_check_id,
p_accounting_date => trunc(sysdate),
p_accounting_event_id => l_accounting_event_id,
p_checkrun_name => NULL,
p_calling_sequence => 'CREATE_AP_PAYMENT');
EXCEPTION
WHEN OTHERS THEN
log('ap_accounting_events_pkg.create_events' || SQLERRM);
END;
SELECT COUNT(1)
INTO l_count
FROM ap_accounting_events_all aae
WHERE aae.accounting_event_id = l_accounting_event_id
AND aae.source_table = 'AP_CHECKS'
AND aae.source_id = l_check_id;
IF l_count = 0 THEN
log('创建付款会计事件失败');
--RETURN;
END IF;
log('l_check_id ' || l_check_id || ' x_accounting_event_id ' ||
l_accounting_event_id);
END IF;
--更新 ap_check_stocks 最后单据号
log('Step2.3 更新 ap_check_stocks 最后单据号----------------------BEGIN');
UPDATE ap_check_stocks_all acs
SET acs.last_document_num = l_check_number,
acs.last_update_date = SYSDATE,
acs.last_updated_by = g_user_id,
acs.last_update_login = g_login_id
WHERE acs.check_stock_id = l_check_stock_id;
--创建付款历史记录
BEGIN
ap_reconciliation_pkg.insert_payment_history(x_check_id => l_check_id,
x_transaction_type => 'PAYMENT CREATED',
x_accounting_date => trunc(sysdate),
x_trx_bank_amount => NULL,
x_errors_bank_amount => NULL,
x_charges_bank_amount => NULL,
x_bank_currency_code => NULL,
x_bank_to_base_xrate_type => NULL,
x_bank_to_base_xrate_date => NULL,
x_bank_to_base_xrate => NULL,
x_trx_pmt_amount => 200 --p_check_rec.amount
,
x_errors_pmt_amount => NULL,
x_charges_pmt_amount => NULL,
x_pmt_currency_code => 'CNY', --rec.currency_code,
x_pmt_to_base_xrate_type => 'Coporate', --rec.conversion_type,
x_pmt_to_base_xrate_date => trunc(sysdate), --rec.conversion_date,
x_pmt_to_base_xrate => 1, --rec.conversion_rate,
x_trx_base_amount => 200, --rec.amount, --p_check_rec.base_amount
x_errors_base_amount => NULL,
x_charges_base_amount => NULL,
x_matched_flag => NULL,
x_rev_pmt_hist_id => NULL,
x_org_id => l_org_id,
x_creation_date => SYSDATE,
x_created_by => fnd_global.user_id,
x_last_update_date => SYSDATE,
x_last_updated_by => fnd_global.user_id,
x_last_update_login => fnd_global.login_id,
x_program_update_date => NULL,
x_program_application_id => NULL,
x_program_id => NULL,
x_request_id => NULL,
x_calling_sequence => 'CREATE_AP_PAYMENT_HIS',
x_accounting_event_id => l_accounting_event_id);
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.put_line('exception 付款申请头ID req_header_id =' ||
'错误1' ||
'的需要进行中部付款的付款申请未能成功完成P3。' || SQLERRM);
-->如果导入付款有问题那么就把之前写入的数据删除,(为了不进行回滚,让其它正确数据正常执行完成)
--update 2014-2-24 start
--DELETE FROM ap_checks_all aca WHERE aca.check_id = l_check_id;
--DELETE FROM ap_payment_history_all aph WHERE aph.check_id = l_check_id;
--GOTO end_main;
RAISE fnd_api.g_exc_error;
--update end;
END;
-- 创建付款发票
log('Step2.4 创建付款发票 ----------------------BEGIN');
SELECT ap_invoice_payments_s.nextval INTO l_invoice_payment_id FROM dual;
log('Step2.4.1 付款发票ID[' || l_invoice_payment_id ||
'] ----------------------BEGIN');
BEGIN
/* ap_pay_invoice_pkg.ap_pay_invoice(p_invoice_id => l_invoice_id,
p_check_id => l_check_id,
p_payment_num => 1,
p_invoice_payment_id => l_invoice_payment_id,
p_old_invoice_payment_id => NULL,
p_period_name => l_period_name,
p_accounting_date => l_gl_date,
p_amount => l_invoice_amount,
p_discount_taken => NULL,
p_invoice_base_amount => l_invoice_amount,
p_payment_base_amount => l_invoice_amount,
p_accrual_posted_flag => 'N',
p_cash_posted_flag => 'N',
p_posted_flag => 'N',
p_set_of_books_id => l_set_of_books_id,
p_payment_mode => 'PAY', --不能为空
p_last_updated_by => g_user_id,
p_last_update_login => g_login_id,
p_exchange_rate => l_exchange_rate,
p_exchange_rate_type => l_exchange_rate_type,
p_exchange_date => l_exchange_date,
p_accounting_event_id => l_accounting_event_id);*/
/* SELECT aps.amount_remaining req_amount, aps.payment_num
FROM ap_invoices_all aia, ap_payment_schedules_all aps
WHERE aia.invoice_id = aps.invoice_id
AND aia.invoice_id = 10097
--add by feng.han 2014-2-13
--)[32637]修改付款申请生成多计划行付款逻辑
AND aps.amount_remaining <> 0 --changed at 20140819
--add end;
ORDER BY aps.payment_priority ASC, aps.due_date ASC; */
BEGIN
SELECT *
INTO l_ap_checks_all_row
FROM ap_checks_all
WHERE check_id = L_check_id;
END;
ap_pay_invoice_pkg.ap_pay_invoice(p_invoice_id => l_invoice_id,
p_check_id => l_check_id,
p_payment_num => 1, --aps.payment_num, --计划付款行号
p_invoice_payment_id => l_invoice_payment_id,
p_old_invoice_payment_id => NULL,
p_period_name => l_period_name,
p_invoice_type => 'STANDARD', --rec_invoice.invoice_type, --l_ap_inv_ready_to_pay_v_row.invoice_type,
p_accounting_date => l_gl_date,
p_amount => 200, --rec_invoice.req_amount,
p_discount_taken => 0,
p_discount_lost => '',
p_invoice_base_amount => NULL,
p_payment_base_amount => NULL,
p_accrual_posted_flag => 'N',
p_cash_posted_flag => 'N',
p_posted_flag => 'N',
p_set_of_books_id => l_set_of_books_id,
p_last_updated_by => g_user_id,
p_last_update_login => g_login_id,
p_currency_code => 'CNY', --rec.currency_code, --rec_apply.currency_code,
p_base_currency_code => 'CNY',
p_exchange_rate => l_ap_checks_all_row.exchange_rate, --rec_apply.exchange_rate,
p_exchange_rate_type => l_ap_checks_all_row.exchange_rate_type, --rec_apply.exchange_rate_type,
p_exchange_date => l_ap_checks_all_row.exchange_date, --rec_apply.exchange_rate_date,
p_ce_bank_acct_use_id => l_ap_checks_all_row.ce_bank_acct_use_id, --rec_apply.bank_acct_id,
p_bank_account_num => l_ap_checks_all_row.bank_account_num, --rec_apply.bank_account_num,
p_bank_account_type => l_ap_checks_all_row.bank_account_type,
p_bank_num => l_ap_checks_all_row.bank_num,
p_future_pay_posted_flag => NULL,
p_exclusive_payment_flag => 'N',
p_accts_pay_ccid => 1015, --rec_invoice.accts_pay_code_combi_id, -- l_ap_inv_ready_to_pay_v_row.accts_pay_code_combi_id,
p_gain_ccid => '',
p_loss_ccid => '',
p_future_pay_ccid => NULL,
p_asset_ccid => NULL,
p_payment_dists_flag => 'N',
p_payment_mode => 'PAY',
p_replace_flag => 'N',
p_attribute1 => NULL,
p_attribute2 => NULL,
p_attribute3 => NULL,
p_attribute4 => NULL,
p_attribute5 => NULL,
p_attribute6 => NULL,
p_attribute7 => NULL,
p_attribute8 => NULL,
p_attribute9 => NULL,
p_attribute10 => NULL,
p_attribute11 => NULL,
p_attribute12 => NULL,
p_attribute13 => NULL,
p_attribute14 => NULL,
p_attribute15 => NULL,
p_attribute_category => NULL,
p_global_attribute1 => NULL,
p_global_attribute2 => NULL,
p_global_attribute3 => NULL,
p_global_attribute4 => NULL,
p_global_attribute5 => NULL,
p_global_attribute6 => NULL,
p_global_attribute7 => NULL,
p_global_attribute8 => NULL,
p_global_attribute9 => NULL,
p_global_attribute10 => NULL,
p_global_attribute11 => NULL,
p_global_attribute12 => NULL,
p_global_attribute13 => NULL,
p_global_attribute14 => NULL,
p_global_attribute15 => NULL,
p_global_attribute16 => NULL,
p_global_attribute17 => NULL,
p_global_attribute18 => NULL,
p_global_attribute19 => NULL,
p_global_attribute20 => NULL,
p_global_attribute_category => NULL,
p_calling_sequence => 'cux_ce_req_pay_pub <- ap_pay_invoice_pkg.ap_pay_invoice',
p_accounting_event_id => l_accounting_event_id,
p_org_id => L_org_id);
SELECT COUNT(1)
INTO l_count
FROM ap_invoice_payments_all aip
WHERE aip.invoice_payment_id = l_invoice_payment_id
AND aip.invoice_id = l_invoice_id
AND aip.check_id = l_check_id;
IF l_count = 0 THEN
log('创建发票付款失败');
--RETURN;
END IF;
IF l_count > 0 THEN
log('创建发票付款成功');
--RETURN;
END IF;
EXCEPTION
WHEN OTHERS THEN
l_err_msg := SQLERRM;
WHILE lengthb(l_err_msg) > 0 LOOP
log(substrb(l_err_msg, 1, 255));
l_err_msg := substrb(l_err_msg, 256);
END LOOP;
--get_msg(l_msg_count, l_msg_data);
--log(l_msg_data);
END;
END;