`
chengyue2007
  • 浏览: 1464553 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

详解EBS接口开发之应收INVOICE导入

    博客分类:
  • erp
 
阅读更多

(一)应收INVOICE常用标准表简介

1.1   常用标准表

如下表中列出了与应收INVOICE导入相关的表和说明:

表名

说明

其他信息

RA_BATCH_SOURCES_ALL

AR事务处理来源表

 

 

 

RA_BATCHES_ALL

AR事务处理批表

 

 

对应视图

RA_CUST_TRX_TYPES_ALL

AR事务处理类型

 

 

对应视图

RA_CUSTOMER_TRX_ALL

AR事务处理题头表

 

 

对应视图

RA_CUSTOMER_TRX_LINES_ALL

AR事务处理明细表

 

 

对应视图

RA_CUST_TRX_LINE_GL_DIST_ALL

AR事务处理分配表

 

 

对应视图

RA_CUST_TRX_LINE_SALESREPS_ALL

AR事务处理销售业绩表

 

 

对应视图

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1.2  接口表大体介绍

如下表中列出了与应收INVOICE导入相关的接口表和说明:

表名

说明

其他信息

ra_interface_lines_all

 

 

 

 

ra_interface_salescredits_all

 

 

 

 

ra_interface_distributions

 

 

 

 

ra_interface_errors_all

错误信息表

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1.3   说明

这里只列出了采购相关的大多数常用表。还有一些不经常用到的没有涉及,具体可以参考oracle网站上的

 

(二)应收INVOICE导入组成

应收INVOICE导入主要包括:INVOICE头信息,INVOICE行信息,INVOICE行税信息,INVOICE行分配信息

 

2.1   应收INVOICE导入组成

INVOICE头信息导入:导入INVOICE头信息

INVOICE行信息导入:导入INVOICE行具体信息

INVOICE行税信息导入:导入INVOICE行税信息

INVOICE行分配信息导入:INVOICE行分配信息

(三)应收INVOICE导入顺序及流程

3.1   应收INVOICE导入顺序

由于数据的先后关联依赖关系,同一供应收INVOICE导入必须按照一定的顺序进行:先导头信息,再行信息,接着导入行发运信息。最后发运的分配等信息。

 

3.2   应收INVOICE导入流程

应收INVOICE导入流程:

第一步:创建需要导入应收INVOICE的中间表,字段上提供供应收INVOICE相关信息。

第二步:向中间表中插入需要导入的应收INVOICE信息,验证需要插入的数据是否满足应收INVOICE信息规则,去除不合规范的数据。

第三步:对在第二部中验证及转化翻译的数据插入到接口中。

第四步:提交并发请求导入应收INVOICE信息。

 

(四)应收INVOICE导入API研究

3.1   应收INVOICE导入api

[sql] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. AR_INVOICE_API_PUB.create_invoice(  
  2.     p_api_version           IN          NUMBER,  
  3.     p_init_msg_list         IN          VARCHAR2 := FND_API.G_FALSE,  
  4.     p_commit                IN          VARCHAR2 := FND_API.G_FALSE,  
  5.     p_batch_source_rec      IN          batch_source_rec_type DEFAULT NULL,  
  6.     p_trx_header_tbl        IN          trx_header_tbl_type,  
  7.     p_trx_lines_tbl         IN          trx_line_tbl_type,  
  8.     p_trx_dist_tbl          IN          trx_dist_tbl_type,  
  9.     p_trx_salescredits_tbl  IN          trx_salescredits_tbl_type,  
  10.     x_return_status         OUT NOCOPY  VARCHAR2,  
  11.     x_msg_count             OUT NOCOPY  NUMBER,  
  12.     x_msg_data              OUT NOCOPY  VARCHAR2)  
  13.   
  14.   
  15.   
  16.   
  17. AR_INVOICE_API_PUB.CREATE_SINGLE_INVOICE(  
  18.     p_api_version           IN  NUMBER,  
  19.     p_init_msg_list         IN  VARCHAR2 := FND_API.G_FALSE,  
  20.     p_commit                IN  VARCHAR2 := FND_API.G_FALSE,  
  21.     p_batch_source_rec      IN  batch_source_rec_type DEFAULT NULL,  
  22.     p_trx_header_tbl        IN  trx_header_tbl_type,  
  23.     p_trx_lines_tbl         IN  trx_line_tbl_type,  
  24.     p_trx_dist_tbl          IN  trx_dist_tbl_type,  
  25.     p_trx_salescredits_tbl  IN  trx_salescredits_tbl_type,  
  26.     p_trx_contingencies_tbl IN  trx_contingencies_tbl_type,  
  27.     x_customer_trx_id       OUT NOCOPY  NUMBER,  
  28.     x_return_status         OUT NOCOPY  VARCHAR2,  
  29.     x_msg_count             OUT NOCOPY  NUMBER,  
  30.     x_msg_data              OUT NOCOPY  VARCHAR2);  


 

3.2   应收INVOICE导入api说明

create_invoice

Use the CREATE_INVOICE procedure to createmultiple invoices in a batch. The

procedure returns a global record typestructure which contains the batch_id to

retrieve the necessary data from thetransaction tables. The structure is defined in

the package specification of ar_invoice_api_pub.Please refer to Example for

Creating Multiple Invoices in a Batch, page6-17for usage.

CREATE_SINGLE_INVOICE

Use the CREATE_SINGLE_INVOICE procedure tocreate a single invoice. The

procedure returns customer_trx_id as an outparameter. Please refer to Example for

Creating a Single Invoice, page 6-19forusage

 

3.3   应收INVOICE导入api简单使用范例

Creating MultipleInvoices

[sql] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. 1.  DECLARE  
  2. l_return_status varchar2(1);  
  3. l_msg_count number;  
  4. l_msg_data varchar2(2000);  
  5. l_batch_id number;   
  6. l_batch_source_rec ar_invoice_api_pub.batch_source_rec_type;  
  7. l_trx_header_tbl ar_invoice_api_pub.trx_header_tbl_type;  
  8. l_trx_lines_tbl ar_invoice_api_pub.trx_line_tbl_type;  
  9. l_trx_dist_tbl ar_invoice_api_pub.trx_dist_tbl_type;  
  10. l_trx_salescredits_tbl   
  11. ar_invoice_api_pub.trx_salescredits_tbl_type;  
  12. CURSOR cBatch IS  
  13. select customer_trx_id   
  14. from ra_customer_trx_all  
  15. where batch_id = l_batch_id;  
  16. CURSOR cValidTxn IS  
  17. SELECT trx_header_id  
  18. From ar_trx_header_gt  
  19. WHERE trx_header_id not in (  
  20. SELECT trx_header_id  
  21. FROM ar_trx_errors_gt);  
  22. 2.  BEGIN  
  23. 1.  Set applications context if not already set.   
  24. fnd_global.apps_initialize(1318, 50559, 222,0);  
  25. 2.  Populate header information.  
  26. l_trx_header_tbl(1).trx_header_id := 101;  
  27. l_trx_header_tbl(1).trx_number := 'Test Invoice API';  
  28. l_trx_header_tbl(1).bill_to_customer_id := 1006;  
  29. l_trx_header_tbl(1).cust_trx_type_id := 2376;   
  30. 3.  Populate batch source information.  
  31. l_batch_source_rec.batch_source_id := 1188;   
  32. 4.  Populate line 1 information.  
  33. l_trx_lines_tbl(1).trx_header_id := 101;  
  34. l_trx_lines_tbl(1).trx_line_id := 101;  
  35. l_trx_lines_tbl(1).line_number := 1;  
  36. l_trx_lines_tbl(1).memo_line_id := 8;  
  37. l_trx_lines_tbl(1).quantity_invoiced := 10;  
  38. l_trx_lines_tbl(1).unit_selling_price := 12;  
  39. l_trx_lines_tbl(1).line_type := 'LINE';  
  40. 6-18   Oracle ReceivablesReference Guide  
  41. 5.  Populate line 2 information.  
  42. l_trx_lines_tbl(2).trx_header_id := 101;  
  43. l_trx_lines_tbl(2).trx_line_id := 102;  
  44. l_trx_lines_tbl(2).line_number := 2;  
  45. l_trx_lines_tbl(2).description := 'Test';  
  46. l_trx_lines_tbl(2).quantity_invoiced := 12;  
  47. l_trx_lines_tbl(2).unit_selling_price := 12;  
  48. l_trx_lines_tbl(2).line_type := 'LINE';  
  49. 6.  Populate freight information and link it to line 1.  
  50. l_trx_lines_tbl(3).trx_header_id := 101;  
  51. l_trx_lines_tbl(3).trx_line_id := 103;  
  52. l_trx_lines_tbl(3).link_to_trx_line_id := 101;  
  53. l_trx_lines_tbl(3).line_number := 1;  
  54. l_trx_lines_tbl(3).line_type := 'FREIGHT';  
  55. l_trx_lines_tbl(3). amount := 25;   
  56. 7.  Call the invoice api to create multiple invoices in a batch.  
  57. AR_INVOICE_API_PUB.create_invoice(  
  58. p_api_version => 1.0,  
  59. p_batch_source_rec => l_batch_source_rec,  
  60. p_trx_header_tbl => l_trx_header_tbl,  
  61. p_trx_lines_tbl => l_trx_lines_tbl,  
  62. p_trx_dist_tbl => l_trx_dist_tbl,  
  63. p_trx_salescredits_tbl => l_trx_salescredits_tbl,  
  64. x_return_status => l_return_status,  
  65. x_msg_count => l_msg_count,  
  66. x_msg_data => l_msg_data);   
  67. IF l_return_status = fnd_api.g_ret_sts_error OR   
  68. l_return_status = fnd_api.g_ret_sts_unexp_error THEN  
  69. dbms_output.put_line('unexpected errors found!');  
  70. ELSE  
  71. 8.  Check if there are record exist in error table. If no records exist for a   
  72. trx_header_id, then only Invoice will create in the system; otherwise not.  
  73. For cValidTxnRec IN cvalidTxn  
  74. loop  
  75. IF (ar_invoice_api_pub.g_api_outputs.batch_id IS NOT NULL)  
  76. THEN  
  77. dbms_output.put_line('Invoice(s) suceessfully created!') ;  
  78. dbms_output.put_line('Batch ID: ' ||   
  79. ar_invoice_api_pub.g_api_outputs.batch_id);  
  80. l_batch_id := ar_invoice_api_pub.g_api_outputs.batch_id;  
  81. 9.  To see all customer_trx_id for this batch:  
  82. Invoice Creation API User Notes    6-19  
  83. for cBatchRec in cBatch  
  84. loop  
  85. dbms_output.put_line ( 'Cust Trx Id '||   
  86. cBatchRec.customer_trx_id );  
  87. end loop;   
  88. ELSE  
  89. dbms_output.put_line('Errors found!');  
  90. END IF;  
  91. End loop;  
  92. END IF;  
  93. END;  
  94. /  
  95. 10. See all the validation errors.  
  96. SET LINESIZE 200  
  97. COLUMN trx_header_id HEADING 'Header ID'  
  98. COLUMN trx_line_id HEADING 'Line ID'  
  99. COLUMN error_message HEADING 'Message'  
  100. COLUMN invalid_value HEADING 'Invalid Value'  
  101. COLUMN trx_header_id FORMAT 9999999  
  102. COLUMN trx_line_id FORMAT 9999999  
  103. COLUMN error_message FORMAT a30  
  104. COLUMN invalid_value FORMAT a20  
  105. SELECT trx_header_id, trx_line_id, error_message, invalid_value  
  106. FROM ar_trx_errors_gt;  


 

Creating a SingleInvoice

[sql] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. 1.  DECLARE  
  2. l_return_status varchar2(1);  
  3. l_msg_count number;  
  4. l_msg_data varchar2(2000);  
  5. l_batch_id number;   
  6. l_cnt number := 0;  
  7. l_batch_source_rec ar_invoice_api_pub.batch_source_rec_type;  
  8. l_trx_header_tbl ar_invoice_api_pub.trx_header_tbl_type;  
  9. l_trx_lines_tbl ar_invoice_api_pub.trx_line_tbl_type;  
  10. l_trx_dist_tbl ar_invoice_api_pub.trx_dist_tbl_type;  
  11. l_trx_salescredits_tbl ar_invoice_api_pub.  
  12. l_customer_trx_id number;  
  13. 2.  BEGIN  
  14. 1.  Set applications context if not already set.   
  15. fnd_global.apps_initialize(1318, 50559, 222,0);  
  16. 2.  Populate header information.  
  17. 6-20   Oracle ReceivablesReference Guide  
  18. l_trx_header_tbl(1).trx_header_id := 101;  
  19. l_trx_header_tbl(1).trx_number := 'Test Invoice API';  
  20. l_trx_header_tbl(1).bill_to_customer_id := 1006;  
  21. l_trx_header_tbl(1).cust_trx_type_id := 2376;   
  22. 3.  Populate batch source information.  
  23. l_batch_source_rec.batch_source_id := 1188;   
  24. 4.  Populate line 1 information.  
  25. l_trx_lines_tbl(1).trx_header_id := 101;  
  26. l_trx_lines_tbl(1).trx_line_id := 101;  
  27. l_trx_lines_tbl(1).line_number := 1;  
  28. l_trx_lines_tbl(1).memo_line_id := 8;  
  29. l_trx_lines_tbl(1).quantity_invoiced := 10;  
  30. l_trx_lines_tbl(1).unit_selling_price := 12;  
  31. l_trx_lines_tbl(1).line_type := 'LINE';  
  32. 5.  Populate line 2 information.  
  33. l_trx_lines_tbl(2).trx_header_id := 101;  
  34. l_trx_lines_tbl(2).trx_line_id := 102;  
  35. l_trx_lines_tbl(2).line_number := 2;  
  36. l_trx_lines_tbl(2).description := 'Test';  
  37. l_trx_lines_tbl(2).quantity_invoiced := 12;  
  38. l_trx_lines_tbl(2).unit_selling_price := 12;  
  39. l_trx_lines_tbl(2).line_type := 'LINE';  
  40. 6.  Populate freight information and link it to line 1.  
  41. l_trx_lines_tbl(3).trx_header_id := 101;  
  42. l_trx_lines_tbl(3).trx_line_id := 103;  
  43. l_trx_lines_tbl(3).link_to_trx_line_id := 101;  
  44. l_trx_lines_tbl(3).line_number := 1;  
  45. l_trx_lines_tbl(3).line_type := 'FREIGHT';  
  46. l_trx_lines_tbl(3). amount := 25;   
  47. 7.  Call the invoice api to create multiple invoices in a batch.  
  48. AR_INVOICE_API_PUB.create_single_invoice(  
  49. p_api_version => 1.0,  
  50. p_batch_source_rec => l_batch_source_rec,  
  51. p_trx_header_tbl => l_trx_header_tbl,  
  52. p_trx_lines_tbl => l_trx_lines_tbl,  
  53. p_trx_dist_tbl => l_trx_dist_tbl,  
  54. p_trx_salescredits_tbl => l_trx_salescredits_tbl,  
  55. x_customer_trx_id => l_customer_trx_id,  
  56. x_return_status => l_return_status,  
  57. x_msg_count => l_msg_count,  
  58. x_msg_data => l_msg_data);   
  59. IF l_return_status = fnd_api.g_ret_sts_error OR   
  60. l_return_status = fnd_api.g_ret_sts_unexp_error THEN  
  61. dbms_output.put_line('unexpected errors found!');  
  62. ELSE  
  63. 8.  Check whether any record exist in error table  
  64. Invoice Creation API User Notes    6-21  
  65. SELECT count(*)  
  66. Into cnt  
  67. From ar_trx_errors_gt;  
  68. IF cnt = 0  
  69. THEN  
  70. dbms_output.put_line ( 'Customer Trx id '|| l_customer_trx_id);  
  71. ELSE  
  72. dbms_output.put_line ( 'Transaction not Created, Please check   
  73. ar_trx_errors_gt table');   
  74. END IF;  
  75. END;  
  76. /  
  77. 9.  See all the validation errors.   
  78. SET LINESIZE 200  
  79. COLUMN trx_header_id HEADING 'Header ID'  
  80. COLUMN trx_line_id HEADING 'Line ID'  
  81. COLUMN error_message HEADING 'Message'  
  82. COLUMN invalid_value HEADING 'Invalid Value'  
  83. COLUMN trx_header_id FORMAT 9999999  
  84. COLUMN trx_line_id FORMAT 9999999  
  85. COLUMN error_message FORMAT a30  
  86. COLUMN invalid_value FORMAT a20  
  87. SELECT trx_header_id, trx_line_id, error_message, invalid_value  
  88. FROM ar_trx_errors_gt;  


 

3.4   应收INVOICE导入api使用说明

对于API使用参数必输参数参考上面例子就可以知道,应收INVOICE行类型比较特殊有LINE类型,TAX类型等当行类型不同时各个字段的要求并不相同,具体使用参照120arrg.pdf。插入税行的时候行类型为TAX

(五)常用检验逻辑及大体检验语句

在将中间表中数据向标准表中导入时,需要检验这条应收INVOICE信息是否已经在系统中存在,这些检验要在程序中进行,并根据检验的结果进行导入或者更新

4.1   INVOICE号信息检验

[sql] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. SELECT COUNT(*)  
  2.   
  3.         INTO v_count_sys  
  4.   
  5.         FROM ra_customer_trx_all a  
  6.   
  7.        WHERE a.trx_number =rec_oa_ar_invoice.apply_number;  
  8.   
  9.       IF v_count_sys <> 0 THEN  
  10.   
  11.         cux_conc_utl.log_msg('此INVOICE号系统中已存在');  
  12.   
  13.         h_error_msg  := '此INVOICE号系统中已存在!';  
  14.   
  15.         h_error_flag := 'Y';  
  16.   
  17.         GOTO validate_header_end;  
  18.   
  19.       END IF;  


 

 

 

六)参考实例程序

5.1  接口表一些重要字段

 

 

[sql] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. 1.参数定义  
  2. --调用系统api需要的标准参数(这是single的Multiple的还需要多加一个)  
  3.     l_batch_source_rec     ar_invoice_api_pub.batch_source_rec_type; --提交并发请求需要  
  4.     l_trx_header_tbl       ar_invoice_api_pub.trx_header_tbl_type; --提交并发请求需要  
  5.     l_trx_lines_tbl        ar_invoice_api_pub.trx_line_tbl_type; --提交并发请求需要  
  6.     l_trx_dist_tbl         ar_invoice_api_pub.trx_dist_tbl_type; --提交并发请求需要  
  7. l_trx_salescredits_tbl ar_invoice_api_pub.trx_salescredits_tbl_type; --提交并发请求需要   
  8.   
  9.   
  10. 2.处理程序  
  11. FOR rec_trx_header IN cur_trx_header LOOP  
  12.       --头循环  
  13.       cux_conc_utl.log_msg('进入pvt,调用pvt。do_arFOR rec_trx_header IN cur_trx_header LOOP:');  
  14.       cux_log.debug('rec_trx_header loop begin:');  
  15.       dbms_output.put_line('rec_trx_header loop begin:');  
  16.       l_trx_count := 0; --初始化  
  17.       --按照客户和币种进行分组  
  18.       -- FOR rec_ar_group IN cur_ar_group(x_header_id => rec_trx_header.header_id) LOOP  
  19.       /*IF l_debug = 'Y' THEN  
  20.         cux_log.debug('rec_ar_group loop begin:');  
  21.         dbms_output.put_line('rec_ar_group loop begin:');  
  22.       END IF; --IF l_debug ='Y' THEN*/  
  23.       l_header_count := l_header_count + 1; --需要创建成功的INVOICE计数  
  24.       l_trx_count    := l_trx_count + 1;  
  25.       --参数初始化  
  26.       l_return_status    := NULL;  
  27.       l_msg_count        := NULL;  
  28.       l_msg_data         := NULL;  
  29.       l_batch_id         := NULL;  
  30.       l_cnt              := 0;  
  31.       l_batch_source_rec := NULL;  
  32.       l_trx_header_tbl.delete--清空  
  33.       l_trx_lines_tbl.delete--清空  
  34.       l_trx_dist_tbl.delete--清空  
  35.       l_trx_salescredits_tbl.delete--清空  
  36.       x_customer_trx_id := NULL;  
  37.       
  38.       l_line_count := 0;  
  39.       -- l_header_count      :=0;  
  40.       x_cust_site_use_id  := NULL;  
  41.       x_cust_acct_site_id := NULL;  
  42.       l_project_num       := NULL;  
  43.       l_line_num          := 0;  
  44.       x_payment_term_id   := NULL--付款条件  
  45.       
  46.       --设置多组织访问控制  
  47.       mo_global.init('AR');  
  48.       mo_global.set_policy_context('S', rec_trx_header.org_id);  
  49.       cux_conc_utl.log_msg('进入pvt,调用pvt。rec_trx_header.org_id ' ||  
  50.                            rec_trx_header.org_id);  
  51.       IF rec_trx_header.source_code = 'INV' THEN  
  52.         v_batch_name := 'INV INTERCOMPANY';  
  53.       ELSIF rec_trx_header.source_code IN ('OA''OMS'THEN  
  54.         v_batch_name := rec_trx_header.source_code;  
  55.       END IF;  
  56.       l_batch_source_rec.batch_source_id := get_batch_id(p_batch_name => v_batch_name,  
  57.                                                          p_org_id     => rec_trx_header.org_id); --redo  
  58.       
  59.       --给参数l_trx_header_tbl赋值 这里写死了应该把1换成count  
  60.       l_trx_header_tbl(l_header_count).trx_header_id := rec_trx_header.header_id; --头id  
  61.       l_trx_header_tbl(l_header_count).org_id := rec_trx_header.org_id; --OU id   
  62.       /*IF  rec_trx_header.source_code IN ('OA''OMS'THEN --当 v_batch_name := 'Intercompany';时系统自动填充事务处理编号  
  63.          l_trx_header_tbl(l_header_count).trx_number := rec_trx_header.trx_number; --(事务处理编号?)  
  64.       END IF;*/  
  65.       l_trx_header_tbl(l_header_count).trx_number := rec_trx_header.trx_number; --(事务处理编号?)  
  66.       l_trx_header_tbl(l_header_count).bill_to_customer_id := rec_trx_header.bill_to_customer_id; --收单客户id  
  67.       l_trx_header_tbl(l_header_count).bill_to_site_use_id := rec_trx_header.bill_to_site_use_id; --主要手单方地点用途  
  68.       l_trx_header_tbl(l_header_count).bill_to_address_id := rec_trx_header.bill_to_address_id; --收单地点id--不需要?  
  69.       --cux_log.debug('rec_ar_group.customer_id:' ||rec_ar_group.customer_id);  
  70.       l_trx_header_tbl(l_header_count).sold_to_customer_id := rec_trx_header.sold_to_customer_id; --采购方  
  71.        
  72.       l_trx_header_tbl(l_header_count).cust_trx_type_id := rec_trx_header.cust_trx_type_id; --事务处理类型id  
  73.         
  74.       l_trx_header_tbl(l_header_count).term_id := rec_trx_header.term_id; --付款条件id  
  75.       --事务处理日期  
  76.       --INVOICE            
  77. --cux_log.debug('rec_trx_header.gl_date:' ||rec_trx_header.gl_date);  
  78.       l_trx_header_tbl(l_header_count).gl_date := rec_trx_header.gl_date; --GL日期  
  79.       l_trx_header_tbl(l_header_count).trx_date := rec_trx_header.trx_date; --事务处理日期  
  80.       --参考字段(此项目用于INVOICE编号)  
  81.       l_trx_header_tbl(l_header_count).reference_number := rec_trx_header.reference_number;  
  82.       --销售人员  
  83.       l_trx_header_tbl(l_header_count).primary_salesrep_id := -3; --rec_trx_header.primary_salesrep_id; --销售人员id (取销售订单头的销售员)  
  84.       --汇率  
  85.       l_trx_header_tbl(l_header_count).exchange_date := rec_trx_header.conversion_date;  
  86.       l_trx_header_tbl(l_header_count).exchange_rate_type := rec_trx_header.conversion_type;  
  87.       l_trx_header_tbl(l_header_count).exchange_rate := rec_trx_header.conversion_rate;  
  88.         
  89.       --收入类型    
  90.       --l_trx_header_tbl(l_header_count).interface_header_context := 'CUX_SERVICE_INVOICE'; --INVOICE行弹性域上下文:服务结算INVOICE                               
  91.       l_trx_header_tbl(l_header_count).attribute1 := rec_trx_header.rev_type;  
  92.       --票种  
  93.       l_trx_header_tbl(l_header_count).attribute2 := rec_trx_header.tax_type;  
  94.       --INVOICE金额  
  95.       l_trx_header_tbl(l_header_count).attribute3 := rec_trx_header.invoice_amount;  
  96.       --摘要  
  97.       l_trx_header_tbl(l_header_count).attribute4 := rec_trx_header.remark; --interface_header_attribute1  
  98.       l_trx_header_tbl(l_header_count).interface_header_attribute1 := rec_trx_header.trx_number;  
  99.         
  100.       --cux_conc_utl.log_msg('进入pvt,调用pvt。do_ar XXX '|| attribute3);  
  101.       -- cux_conc_utl.log_msg('进入pvt,调用pvt。do_ar XXXXXX '|| attribute3);  
  102.       --追溯字段(将TRX_HEADER_ID写入到RA_CUSTOMER_TRX_ALL)  
  103.       --头信息处理完毕,处理行信息(在分组循环内处理)  
  104.       --应收INVOICE(行)         
  105.       FOR rec_trx_line IN cur_trx_line(x_header_id => rec_trx_header.header_id) LOOP  
  106.         --cux_log.debug('rec_trx_line loop begin:');  
  107.         cux_conc_utl.log_msg('进入pvt,调用pvt。do_ar FOR rec_trx_line IN cur_trx_line(x_header_id => rec_trx_header.header_id) LOOP:');  
  108.         l_line_count    := l_line_count + 1; --一个头多个行  
  109.         l_salesrep_id   := NULL--销售人员id  
  110.         l_item_uom_code := NULL--物料主单位  
  111.         l_tax_rate      := NULL;  
  112.         l_line_num      := l_line_num + 1;  
  113.         --INVOICE行信息  
  114.         l_trx_lines_tbl(l_line_count).trx_header_id := rec_trx_line.header_id; --行头id  
  115.         l_trx_lines_tbl(l_line_count).trx_line_id := rec_trx_line.line_id; --行id  
  116.         l_trx_lines_tbl(l_line_count).line_type := 'LINE'--rec_trx_line.line_type; --行类型  
  117.         l_trx_lines_tbl(l_line_count).amount := rec_trx_line.aomunt; --收入金额  
  118.         -- l_trx_lines_tbl(l_line_count).memo_line_id :=1;  
  119.         l_trx_lines_tbl(l_line_count).line_number := l_line_num; --行号  
  120.         -- l_trx_lines_tbl(l_line_count).sales_order := rec_trx_line.SALES_ORDER; --销售订单编号  
  121.         -- l_trx_lines_tbl(l_line_count).sales_order_date := rec_trx_line.SALES_ORDER_DATE; --销售订单日期  
  122.         l_trx_lines_tbl(l_line_count).quantity_invoiced := rec_trx_line.quantity_invoiced; --数量为1  
  123.         --IF p_ar_type_code = 'INV' THEN  
  124.         --INVOICE  
  125.         l_trx_lines_tbl(l_line_count).unit_selling_price := rec_trx_line.unit_selling_price; --实际应收金额  
  126.         -- ELSIF p_ar_type_code = 'CM' THEN  
  127.         --贷项通知单  
  128.         --l_trx_lines_tbl(l_line_count).unit_selling_price := (-1) *rec_trx_line.actual_ar_amount; --实际应收金额  
  129.         
  130.         -- END IF; --IF l_type_code = 'INV' THEN   
  131.         
  132.         -- l_trx_lines_tbl(l_line_count).inventory_item_id := rec_trx_line.INVENTORY_ITEM_ID;  
  133.         --l_trx_lines_tbl(l_line_count).warehouse_id := rec_trx_line.WAREHOUSE_ID;  
  134.         l_trx_lines_tbl(l_line_count).description := 'test'--rec_trx_line.line_description;  
  135.         --主物料  
  136.         -- l_trx_lines_tbl(l_line_count).uom_code := rec_trx_line.uom_code; --单位  
  137.         --l_trx_lines_tbl(l_line_count).amount := ROUND(rec_trx_line.amount,2);  
  138.         l_trx_lines_tbl(l_line_count).link_to_trx_line_id := rec_trx_line.link_to_trx_line_id;  
  139.           
  140.         --cux_conc_utl.log_msg('进入pvt,调用pvt。do_ar XXX '|| attribute3);  
  141.         l_trx_lines_tbl(l_line_count).interface_line_context := 'CUX_AR_INVOICE'--INVOICE行弹性域上下文:服务结算INVOICE  
  142.         l_trx_lines_tbl(l_line_count).interface_line_attribute1 := rec_trx_line.header_id; --项目ID  
  143.         l_trx_lines_tbl(l_line_count).interface_line_attribute2 := rec_trx_line.line_id; --任务ID     
  144.         l_trx_lines_tbl(l_line_count).interface_line_attribute3 := rec_trx_line.source_code; --服务结算头id  
  145.         l_trx_lines_tbl(l_line_count).interface_line_attribute4 := rec_trx_line.source_line_id; --服务结算行id                  
  146.         --插入分配行                 
  147.         l_trx_dist_tbl(l_line_count).trx_dist_id := rec_trx_line.line_id;  
  148.         l_trx_dist_tbl(l_line_count).trx_header_id := rec_trx_line.header_id;  
  149.         l_trx_dist_tbl(l_line_count).trx_line_id := rec_trx_line.line_id;  
  150.         l_trx_dist_tbl(l_line_count).account_class := 'REV'--收入--必输字段REDO  
  151.         l_trx_dist_tbl(l_line_count).amount := l_trx_lines_tbl(l_line_count)  
  152.                                                .quantity_invoiced * l_trx_lines_tbl(l_line_count)  
  153.                                                .unit_selling_price;  
  154.         l_trx_dist_tbl(l_line_count).acctd_amount := l_trx_dist_tbl(l_line_count)  
  155.                                                      .amount;  
  156.         l_trx_dist_tbl(l_line_count).percent := 100;  
  157.         --得到应收事务处理类型的收入账户  
  158.         l_trx_dist_tbl(l_line_count).code_combination_id := rec_trx_line.code_combination_id; --账户ID   
  159.         
  160.         --插入销售人员信息(行的销售人员)           
  161.         --得到销售人员下面的应收账款id               
  162.         l_trx_salescredits_tbl(l_line_count).trx_salescredit_id := rec_trx_line.line_id; --GT表的id   
  163.         l_trx_salescredits_tbl(l_line_count).trx_line_id := rec_trx_line.line_id; --行id             
  164.         l_trx_salescredits_tbl(l_line_count).salesrep_id := -3; --销售人员id (取销售订单头的销售员)  
  165.         l_trx_salescredits_tbl(l_line_count).sales_credit_type_id := 1; --1:Quota Sales Credit 2:Non-quota Sales Credit  REDO  
  166.         l_trx_salescredits_tbl(l_line_count).salescredit_percent_split := 100; --REDO  
  167.         --added by cxy@2013-03-07 begin   
  168.         ----(绕过自动计税)it is IMPORTANT to set the flag to N to flag that we want to bypass the tax engine           
  169.         l_trx_lines_tbl(l_line_count).taxable_flag := 'N';  
  170.         --added by cxy@2013-03-07 end   
  171.         cux_log.debug('rec_trx_line loop end:');  
  172.       END LOOP; --FOR rec_trx_line IN cur_trx_line ...  
  173.       --added by cxy@2013-03-15 begin   
  174.       --增加税行  
  175.       FOR rec_trx_line IN cur_trx_line(x_header_id => rec_trx_header.header_id  
  176.                                        -- x_customer_id   => rec_ar_group.customer_id,  
  177.                                        -- x_currency_code => rec_ar_group.currency_code  
  178.                                        ) LOOP  
  179.         --cux_log.debug('rec_trx_line loop begin:');  
  180.         cux_conc_utl.log_msg('进入pvt,调用pvt。do_ar FOR rec_trx_line IN cur_trx_line(x_header_id => rec_trx_header.header_id:');  
  181.         l_tax_rate           := NULL;  
  182.         l_inclusive_tax_flag := NULL;  
  183.         l_line_count         := l_line_count + 1;  
  184.         l_line_num           := l_line_num + 1;  
  185.         -- LINE 2 : line_type = TAX  
  186.         -- this is the MANUAL tax line you are creating  
  187.         -- unique value within this trx_header_id  
  188.         SELECT cux_ar_invoice_line_s.nextval  
  189.           INTO l_trx_line_tax_id  
  190.           FROM dual;  
  191.         --得到税值:  
  192.         l_tax_rate := cux_ar_invoice_utl.get_tax_rate(p_tax_rate_code => rec_trx_line.tax_rate_code);  
  193.         cux_conc_utl.log_msg('进入pvt,调用pvt。do_ar  --得到税值:' || l_tax_rate);  
  194.         IF l_tax_rate IS NULL THEN  
  195.           cux_api.set_message(p_app_name     => 'CUX',  
  196.                               p_msg_name     => 'CUX_COMMON_MSG',  
  197.                               p_token1       => 'TOKEN',  
  198.                               p_token1_value => '物料主单位为空!');  
  199.           RAISE fnd_api.g_exc_error;  
  200.         END IF; --IF l_item_uom_code IS NULL THEN               
  201.         l_inclusive_tax_flag := cux_ar_invoice_utl.get_inclusive_tax_flag(p_tax_rate_code => rec_trx_line.tax_rate_code);  
  202.         l_trx_lines_tbl(l_line_count).trx_line_id := l_trx_line_tax_id;  
  203.         -- this value needs to match the trx_header_id value provided in trx_header_tbl(1).trx_header_id  
  204.         l_trx_lines_tbl(l_line_count).trx_header_id := rec_trx_line.header_id;  
  205.         l_trx_lines_tbl(l_line_count).line_number := l_line_num; --行号都为1  
  206.         -- provide a description  
  207.         --l_trx_lines_tbl(l_line_count).description := 'Test Tax';  
  208.         -- pass in the tax amount and rate, these both have to be populated, if you pass only one of them  
  209.         -- you will get an error  
  210.         l_trx_lines_tbl(l_line_count).amount := rec_trx_line.tax_amount; --实际应收金额税值 redo primary_salesrep_id  
  211.         /* IF p_ar_type_code = 'INV' THEN  
  212.           --INVOICE  
  213.           l_trx_lines_tbl(l_line_count).amount := rec_trx_line.actual_ar_amount *  
  214.                                                   (l_tax_rate / 100); --实际应收金额税值  
  215.         ELSIF p_ar_type_code = 'CM' THEN  
  216.           --贷项通知单  
  217.           l_trx_lines_tbl(l_line_count).amount := (-1) *  
  218.                                                   rec_trx_line.actual_ar_amount *  
  219.                                                   (l_tax_rate / 100); --实际应收金额*税值  
  220.         END IF; --IF l_type_code = 'INV' THEN */  
  221.         -- pass in line_type = TAX  
  222.         l_trx_lines_tbl(l_line_count).line_type := 'TAX';  
  223.         -- pass in the value associated with the tax RATE  
  224.         l_trx_lines_tbl(l_line_count).tax_rate_code := rec_trx_line.tax_rate_code;  
  225.         cux_conc_utl.log_msg('进入pvt,rec_trx_line.TAX_RATE_code;' ||  
  226.                              rec_trx_line.tax_rate_code);  
  227.         --行上的金额是否含税  
  228.         l_trx_lines_tbl(l_line_count).amount_includes_tax_flag := nvl(l_inclusive_tax_flag,  
  229.                                                                       'N');  
  230.         -- pass in the value associated with the jurisdiction  
  231.         --l_trx_lines_tbl(l_line_count+1).tax_jurisdiction_code := 'CO-FL-DUVAL-11716';  
  232.         -- pass in the associated REGIME  
  233.         --l_trx_lines_tbl(l_line_count+1).tax_regime_code := 'US-SALES-TAX-101';  
  234.         -- pass in the associated TAX  
  235.         --l_trx_lines_tbl(l_line_count+1).tax := 'COUNTY';  
  236.         -- pass in the associated TAX STATUS  
  237.         --l_trx_lines_tbl(l_line_count+1).tax_status_code := 'STANDARD';  
  238.         -- link it to the line this tax is associated with            
  239.         l_trx_lines_tbl(l_line_count).link_to_trx_line_id := rec_trx_line.line_id;  
  240.         --added by cxy@2013-03-07 end              
  241.       END LOOP; --FOR rec_trx_line IN cur_trx_line...  
  242.       --added by cxy@2013-03-15 end   
  243.       --调用系统标准的API创建INVOICE           
  244.       cux_log.debug('ar_invoice_api_pub.create_single_invoice BEGIN');  
  245.       dbms_output.put_line('ar_invoice_api_pub.create_single_invoice BEGIN');  
  246.       ar_invoice_api_pub.create_single_invoice(p_api_version          => 1.0,  
  247.                                                p_batch_source_rec     => l_batch_source_rec,  
  248.                                                p_trx_header_tbl       => l_trx_header_tbl,  
  249.                                                p_trx_lines_tbl        => l_trx_lines_tbl,  
  250.                                                p_trx_dist_tbl         => l_trx_dist_tbl,  
  251.                                                p_trx_salescredits_tbl => l_trx_salescredits_tbl,  
  252.                                                x_customer_trx_id      => x_customer_trx_id,  
  253.                                                x_return_status        => l_return_status,  
  254.                                                x_msg_count            => l_msg_count,  
  255.                                                x_msg_data             => l_msg_data);  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics