数据库表:
-- Create table DROP TABLE CUX.cux_ap_invoice_interface; create table CUX.cux_ap_invoice_interface ( OU_NAME VARCHAR2(240), --组织 invoice_type VARCHAR2(240), --发票类型 vendor_name VARCHAR2(240), --供应商名称 site_name VARCHAR2(240), --供应商地点 invoice_date VARCHAR2(240), --发票日期 gl_date VARCHAR2(240), --GL日期 invoice_num VARCHAR2(240), --发票编号 currency_code VARCHAR2(240), --发票币种 invoice_amount VARCHAR2(240), --发票金额 exchange_rate_type VARCHAR2(240), --汇率类型 exchange_rate VARCHAR2(240), --汇率 pay_group VARCHAR2(240), --支付组 pay_method VARCHAR2(240), --付款方法 terms_date VARCHAR2(240), --条件日期 terms_name VARCHAR2(240), --条件 --ap_code_combination varchar2(240), --应付账款帐户() --header_att8 VARCHAR2(240), --头弹性8() header_global_att19 VARCHAR2(240), --头弹性global_19 line_num VARCHAR2(240), --行号 line_amount VARCHAR2(240), --行金额 project_name VARCHAR2(240), --采购项目号 expenditure_type VARCHAR2(240), --支出类型 expenditure_item_date VARCHAR2(240), --支出项日期 expenditure_organization VARCHAR2(240), --支出组织 line_gl_date VARCHAR2(240), --行GL日期 dist_code_combination VARCHAR2(240), --分配行账户 org_id VARCHAR2(240), vendor_id VARCHAR2(240), vendor_site_id VARCHAR2(240), dist_ccid VARCHAR2(240), ap_ccid VARCHAR2(240), project_id VARCHAR2(240), task_id VARCHAR2(240), is_success VARCHAR2(1) ) tablespace APPS_TS_TX_DATA;
验证程序:
-- ALTER SESSION SET NLS_LANGUAGE='SIMPLIFIED CHINESE'; /* alter table cux.cux_ap_invoice_interface add org_id number; alter table cux.cux_ap_invoice_interface add vendor_id number; alter table cux.cux_ap_invoice_interface add vendor_site_id number; alter table cux.cux_ap_invoice_interface add dist_ccid number; alter table cux.cux_ap_invoice_interface add ap_ccid number; alter table cux.cux_ap_invoice_interface add project_id number; alter table cux.cux_ap_invoice_interface add task_id number; */ --1、导入数据 /*select * from CUX.cux_ap_invoice_interface for update*/ --2.为数据分配编号 /*DECLARE CURSOR cur IS SELECT ap.rowid, ap.* FROM cux.cux_ap_invoice_interface ap; l_num NUMBER := 0; BEGIN FOR i IN cur LOOP l_num := l_num + 1; UPDATE cux.cux_ap_invoice_interface ap SET ap.row_id = l_num WHERE ap.rowid = i.rowid; END LOOP; COMMIT; END; */ --3.校验数据 DECLARE CURSOR cur IS SELECT * FROM cux.cux_ap_invoice_interface; l_count NUMBER := 0; l_org_id NUMBER; l_vendor_id NUMBER; l_vendor_site_id NUMBER; l_dist_ccid NUMBER; l_ap_ccid NUMBER; l_project_id NUMBER; l_task_id NUMBER; l_flag VARCHAR2(1); BEGIN FOR i IN cur LOOP l_flag := 'T'; BEGIN SELECT hou.organization_id INTO l_org_id FROM hr_operating_units hou WHERE hou.name = i.ou_name; EXCEPTION WHEN OTHERS THEN l_flag := 'F'; l_org_id := NULL; dbms_output.put_line(i.row_id || 'OU不存在;'); END; BEGIN SELECT pv.vendor_id INTO l_vendor_id FROM po_vendors pv WHERE pv.vendor_name = rtrim(i.vendor_name); EXCEPTION WHEN OTHERS THEN l_flag := 'F'; l_vendor_id := NULL; dbms_output.put_line(i.row_id || '供应商不存在;'); END; BEGIN /*SELECT max(pvs.vendor_site_id) INTO l_vendor_site_id FROM po_vendor_sites_all pvs, po_vendors pv WHERE pv.vendor_name = rtrim(i.vendor_name) AND pv.vendor_id = pvs.vendor_id AND pvs.org_id = l_org_id;*/ SELECT pvs.vendor_site_id INTO l_vendor_site_id FROM po_vendor_sites_all pvs, po_vendors pv WHERE pv.vendor_name = rtrim(i.vendor_name) AND pv.vendor_id = pvs.vendor_id AND pvs.org_id = l_org_id AND pvs.vendor_site_code = i.site_name; EXCEPTION WHEN OTHERS THEN l_flag := 'F'; l_vendor_site_id := NULL; dbms_output.put_line(i.row_id || '供应商在该OU下不存在地点;'); END; IF i.currency_code <> 'CNY' AND (i.exchange_rate_type IS NULL OR i.exchange_rate IS NULL) THEN l_flag := 'F'; dbms_output.put_line(i.row_id || '该外币发票没有汇率或者汇率类型;'); END IF; BEGIN SELECT gcc.code_combination_id INTO l_dist_ccid FROM gl_code_combinations_kfv gcc WHERE gcc.concatenated_segments = i.dist_code_combination; EXCEPTION WHEN OTHERS THEN l_flag := 'F'; l_dist_ccid := NULL; dbms_output.put_line(i.row_id || '分配帐户不存在或不唯一;'); END; /* IF i.ap_code_combination IS NOT NULL THEN BEGIN SELECT gcc.code_combination_id INTO l_ap_ccid FROM gl_code_combinations_kfv gcc WHERE gcc.concatenated_segments = i.ap_code_combination; EXCEPTION WHEN OTHERS THEN l_flag := 'F'; l_ap_ccid := NULL; dbms_output.put_line(i.invoice_num || '负债帐户不存在或不唯一;'); END; ELSE l_ap_ccid := NULL; END IF;*/ BEGIN SELECT ppa.project_id INTO l_project_id FROM pa_projects_all ppa WHERE ppa.segment1 = rtrim(i.project_name) AND ppa.org_id = l_org_id; EXCEPTION WHEN OTHERS THEN l_flag := 'F'; l_project_id := NULL; dbms_output.put_line(i.row_id || '采购项目不存在或不唯一;'); END; BEGIN SELECT pt.task_id INTO l_task_id FROM pa_projects_all ppa, pa_tasks pt WHERE ppa.segment1 = rtrim(i.project_name) AND ppa.org_id = l_org_id AND ppa.project_id = pt.project_id; EXCEPTION WHEN OTHERS THEN l_flag := 'F'; l_task_id := NULL; dbms_output.put_line(i.row_id || '采购项目对应的任务号不存在;'); END; /*SELECT COUNT(1) INTO l_count FROM fnd_flex_values_vl ffvv, fnd_flex_value_sets ffvs WHERE ffvv.flex_value_set_id = ffvs.flex_value_set_id AND ffvs.flex_value_set_name = 'CUX_HR_PEOPLE_GRADE' AND ffvv.flex_value = i.header_att8; IF l_count < 1 THEN l_flag := 'F'; dbms_output.put_line(i.invoice_num || '事业部板块信息错误;'); END IF;*/ IF l_flag = 'T' THEN UPDATE cux.cux_ap_invoice_interface a SET a.org_id = l_org_id, a.vendor_id = l_vendor_id, a.vendor_site_id = l_vendor_site_id, a.dist_ccid = l_dist_ccid, a.ap_ccid = l_ap_ccid, a.project_id = l_project_id, a.task_id = l_task_id, a.is_success = 'T' WHERE a.row_id = i.row_id; END IF; END LOOP; COMMIT; END; --4.导入数据 --5,运行请求:应付款管理系统开放接口导入
AP数据导入程序:
-- ALTER SESSION SET NLS_LANGUAGE='SIMPLIFIED CHINESE'; DECLARE CURSOR cur IS SELECT * FROM cux.cux_ap_invoice_interface; rec_ap_invoice ap_invoices_interface%ROWTYPE; rec_ap_invoice_line ap_invoice_lines_interface%ROWTYPE; l_Tax_Rec Ap_Invoice_Lines_Interface%ROWTYPE; l_invoice_id NUMBER; l_org_id NUMBER; l_group_id VARCHAR2(80); l_request_id NUMBER; l_flag NUMBER := 0; l_Tax_Code VARCHAR2(30); l_Line_Group_Number number; BEGIN l_group_id := 'QC201312021532'; FOR i IN cur LOOP SELECT ap_invoices_interface_s.nextval INTO l_invoice_id FROM dual; rec_ap_invoice.invoice_id := l_invoice_id; rec_ap_invoice.org_id := i.org_id; BEGIN /*SELECT alc.lookup_code INTO rec_ap_invoice.invoice_type_lookup_code FROM ap_lookup_codes alc WHERE alc.lookup_type = 'INVOICE TYPE' AND alc.displayed_field = i.invoice_type;*/ SELECT lookup_code INTO rec_ap_invoice.invoice_type_lookup_code FROM (SELECT lv.lookup_type, lv.lookup_code, lv.meaning, lv.description, lv.enabled_flag, lv.start_date_active, lv.end_date_active FROM fnd_lookup_values lv WHERE lv.language = 'ZHS' AND lv.view_application_id = 200 AND lv.security_group_id = fnd_global.lookup_security_group(lv.lookup_type, lv.view_application_id)) WHERE lookup_type = 'INVOICE TYPE' AND lookup_code NOT IN ('INTEREST', 'QUICKMATCH', 'QUICKDEFAULT', 'ADJUSTMENT', 'PO PRICE ADJUST') AND meaning = i.invoice_type; EXCEPTION WHEN OTHERS THEN dbms_output.put_line('第' || i.row_id || '行,取invoice_type_lookup_code不存在!'); RAISE; END; rec_ap_invoice.vendor_id := i.vendor_id; rec_ap_invoice.vendor_site_id := i.vendor_site_id; rec_ap_invoice.invoice_date := to_date(i.invoice_date, 'YYYY-MM-DD'); rec_ap_invoice.gl_date := to_date(i.gl_date, 'YYYY-MM-DD'); rec_ap_invoice.invoice_num := i.invoice_num; rec_ap_invoice.invoice_currency_code := i.currency_code; rec_ap_invoice.payment_currency_code := i.currency_code; rec_ap_invoice.invoice_amount := i.invoice_amount; rec_ap_invoice.exchange_rate_type := i.exchange_rate_type; rec_ap_invoice.exchange_rate := i.exchange_rate; rec_ap_invoice.exchange_date := rec_ap_invoice.invoice_date; BEGIN SELECT lookup_code paygroup into rec_ap_invoice.pay_group_lookup_code FROM fnd_lookup_values lv WHERE LANGUAGE = 'ZHS' AND view_application_id = 201 AND lookup_type = 'PAY GROUP' AND enabled_flag = 'Y' AND meaning = i.pay_group AND security_group_id = fnd_global.lookup_security_group(lv.lookup_type, lv.view_application_id) AND trunc(SYSDATE) BETWEEN nvl(start_date_active, SYSDATE - 1) AND nvl(end_date_active, SYSDATE + 1) ORDER BY upper(lookup_code); EXCEPTION WHEN OTHERS THEN dbms_output.put_line('第' || i.row_id || '行,支付组不存在!'); END; BEGIN SELECT ip.payment_method_code INTO rec_ap_invoice.payment_method_code FROM iby_payment_methods_vl ip WHERE ip.payment_method_name = i.pay_method; EXCEPTION WHEN OTHERS THEN dbms_output.put_line('第' || i.row_id || '行,取payment_method_code不存在!'); RAISE; END; BEGIN /*SELECT apt.term_id INTO rec_ap_invoice.terms_id FROM ap_terms apt WHERE apt.name = i.terms_name;*/ SELECT b.term_id INTO rec_ap_invoice.terms_id FROM ap_terms_tl b WHERE b.language = 'ZHS' AND b.name = i.terms_name; EXCEPTION WHEN OTHERS THEN dbms_output.put_line('第' || i.row_id || '行,取term_id不存在!'); RAISE; END; rec_ap_invoice.terms_date := to_date(i.terms_date, 'YYYY-MM-DD'); rec_ap_invoice.source := 'INITIALIMPORT'; rec_ap_invoice.exclusive_payment_flag := 'Y'; --attribute --rec_ap_invoice.attribute8 := i.header_att8; rec_ap_invoice.global_attribute19 := i.header_global_att19; rec_ap_invoice.accts_pay_code_combination_id := i.ap_ccid; --who rec_ap_invoice.last_update_date := SYSDATE; rec_ap_invoice.last_updated_by := fnd_global.user_id; rec_ap_invoice.creation_date := SYSDATE; rec_ap_invoice.created_by := fnd_global.user_id; rec_ap_invoice.last_update_login := fnd_global.login_id; -- 不自动计税, 不然不能把税行导入接口 rec_ap_invoice.Calc_Tax_During_Import_Flag := 'N'; -- rec_ap_invoice.Add_Tax_To_Inv_Amt_Flag := 'N'; rec_ap_invoice.group_id := l_group_id; INSERT INTO ap_invoices_interface VALUES rec_ap_invoice; --行 SELECT ap_invoice_lines_interface_s.nextval INTO rec_ap_invoice_line.invoice_line_id FROM dual; rec_ap_invoice_line.org_id := l_org_id; rec_ap_invoice_line.invoice_id := l_invoice_id; rec_ap_invoice_line.accounting_date := to_date(i.line_gl_date, 'YYYY-MM-DD'); rec_ap_invoice_line.line_number := i.line_num; rec_ap_invoice_line.Line_Group_Number := i.line_num; rec_ap_invoice_line.line_type_lookup_code := 'ITEM'; rec_ap_invoice_line.amount := i.line_amount; rec_ap_invoice_line.dist_code_combination_id := i.dist_ccid; rec_ap_invoice_line.project_id := i.project_id; rec_ap_invoice_line.task_id := i.task_id; rec_ap_invoice_line.expenditure_type := i.expenditure_type; rec_ap_invoice_line.expenditure_item_date := to_date(i.expenditure_item_date, 'YYYY-MM-DD'); SELECT hou.organization_id INTO rec_ap_invoice_line.expenditure_organization_id FROM hr_operating_units hou WHERE hou.name = i.expenditure_organization; --who rec_ap_invoice_line.last_update_date := SYSDATE; rec_ap_invoice_line.last_updated_by := fnd_global.user_id; rec_ap_invoice_line.creation_date := SYSDATE; rec_ap_invoice_line.created_by := fnd_global.user_id; rec_ap_invoice_line.last_update_login := fnd_global.login_id; INSERT INTO ap_invoice_lines_interface VALUES rec_ap_invoice_line; --导入税 l_Tax_Code := Cux_Payreq_Utl.Get_Tax_Code('SERVCE0'); IF l_Tax_Code IS NULL THEN dbms_output.put_line('根据发票类型取税码错误!'); RAISE no_data_found; END IF; l_Tax_Rec.Line_Type_Lookup_Code := 'TAX'; SELECT Ap_Invoice_Lines_Interface_s.Nextval INTO l_Tax_Rec.Invoice_Line_Id FROM Dual; l_Tax_Rec.Invoice_Id := l_invoice_id; l_Tax_Rec.Org_Id := l_org_id; l_Tax_Rec.Line_Number := i.line_num+1; l_Tax_Rec.Line_Group_Number := i.line_num; --l_Tax_Rec.Tax_Code := 'VAT 0'; l_Tax_Rec.Amount := '0'; l_Tax_Rec.Accounting_Date := SYSDATE; --l_Tax_Rec.Description := r.Description; --l_Tax_Rec.Attribute2 := i.invoice_num; --l_Tax_Rec.Attribute4 := r.Customs_Id; l_Tax_Rec.Prorate_Across_Flag := 'Y'; l_Tax_Rec.Project_Id := i.project_id; l_Tax_Rec.tax_rate_code := l_Tax_Code; l_Tax_Rec.Task_Id := i.task_id; l_Tax_Rec.Expenditure_Type := i.expenditure_type; -- 支出类型 l_Tax_Rec.Expenditure_Organization_Id := rec_ap_invoice_line.expenditure_organization_id; l_Tax_Rec.Expenditure_Item_Date := to_date(i.expenditure_item_date, 'YYYY-MM-DD'); INSERT INTO Ap_Invoice_Lines_Interface VALUES l_Tax_Rec; END LOOP; /*IF l_flag = 0 THEN COMMIT; ELSE ROLLBACK; END IF;*/ NULL; END;