AP发票导入(发票头行)

     1.将发票头插入ap_invoices_interface中

     2.将发票行插入ap_invoice_lines_interface中

     3.运行发票导入请求 APXIIMPT


具体示例:

1.往接口表中插入数据

DECLARE
  l_iface_rec       ap_invoices_interface%ROWTYPE;
  l_iface_lines_rec ap_invoice_lines_interface%ROWTYPE;
  TYPE l_invoice_tbl_type IS TABLE OF cur_invoice%ROWTYPE INDEX BY BINARY_INTEGER;
  l_invoice_tbl l_invoice_tbl_type;
  CURSOR cur_invoice IS
  --1. 支付类型:非纯支付   收款方式:单收   
    SELECT temp.record_flag,
           temp.org_id,
           temp.req_number,
           temp.req_header_id,
           temp.vendor_id,
           temp.vendor_site_id,
           temp.req_coa_reg_code,
           temp.group_type_code,
           temp.doc_type_id,
           temp.req_apply_date,
           temp.req_emp_dept_code,
           temp.req_employee_id,
           temp.ebs_type_key,
           temp.doc_type_name,
           temp.src_system_id,
           temp.short_code,
           temp.src_system_name,
           temp.ap_terms_id,
           temp.terms_start_date,
           temp.currency_code,
           temp.comments,
           temp.payment_method_code,
           temp.pay_group_code,
           temp.payment_flag,
           temp.accts_pay_code_combination_id,
           temp.invoice_amount
      FROM (** ** 此处略去n行代码 ** **) temp
     ORDER BY temp.req_employee_id ASC;
BEGIN
  OPEN cur_invoice;
  LOOP
    FETCH cur_invoice BULK COLLECT
      INTO l_invoice_tbl LIMIT 5000;
    EXIT WHEN l_invoice_tbl.count = 0;
  
    FOR k IN l_invoice_tbl.first .. l_invoice_tbl.last
    LOOP
      --头
      l_iface_rec.org_id                   := l_invoice_tbl(k).org_id;
      l_iface_rec.invoice_type_lookup_code := l_invoice_type_lookup_code; --发票类型(CREDIT/STANDARD/PREPAYMENT/MIXED)
      l_iface_rec.invoice_date             := l_invoice_tbl(k)
                                              .req_apply_date;
      l_iface_rec.gl_date                  := to_date(to_char(l_invoice_tbl(k)
                                                              .req_apply_date,
                                                              'YYYY-MM-DD'), --GL日期
                                                      'YYYY-MM-DD');
      l_iface_rec.terms_id                 := l_invoice_tbl(k).ap_terms_id; --付款条件
      l_iface_rec.terms_date               := l_invoice_tbl(k)
                                              .terms_start_date; --付款条件日期
    
      l_iface_rec.payment_method_lookup_code := l_invoice_tbl(k)
                                                .payment_method_code; --预付款方法 
      l_iface_rec.vendor_id                  := l_invoice_tbl(k).vendor_id;
      l_iface_rec.vendor_site_id             := l_invoice_tbl(k)
                                                .vendor_site_id;
      l_iface_rec.invoice_amount             := round(l_invoice_tbl(k)
                                                      .invoice_amount,
                                                      2);
      l_iface_rec.invoice_currency_code      := l_invoice_tbl(k)
                                                .currency_code;
      l_iface_rec.control_amount             := NULL;
      l_iface_rec.exchange_rate_type         := NULL;
      l_iface_rec.exchange_date              := NULL;
      l_iface_rec.exchange_rate              := NULL;
      l_iface_rec.source                     := 'FINREQ'; --来源(提请求参数)
      l_iface_rec.group_id                   := l_group_id; --组 (提请求参数)
      l_iface_rec.pay_group_lookup_code      := l_invoice_tbl(k)
                                                .pay_group_code;
      l_iface_rec.attribute_category         := 'JD_AP_Settlement_Header'; --弹性域上下文
      l_iface_rec.attribute1                 := l_invoice_tbl(k).req_number;
      l_iface_rec.attribute2                 := l_invoice_tbl(k)
                                                .src_system_name;
      l_iface_rec.attribute3                 := l_invoice_tbl(k)
                                                .doc_type_name;
      l_iface_rec.attribute4                 := l_invoice_tbl(k)
                                                .req_coa_reg_code;
      l_iface_rec.attribute5                 := l_invoice_tbl(k)
                                                .group_type_code;
      l_iface_rec.attribute6                 := get_empolyee_name(l_invoice_tbl(k)
                                                                  .req_employee_id);
      l_iface_rec.attribute7                 := get_person_dept_code(l_invoice_tbl(k)
                                                                     .req_employee_id);
      l_iface_rec.attribute8                 := l_attribute8;
    
      l_iface_rec.accts_pay_code_combination_id := l_invoice_tbl(k)
                                                   .accts_pay_code_combination_id; --负债账户
      l_iface_rec.description                   := substrb(l_invoice_tbl(k)
                                                           .comments,
                                                           1,
                                                           240);
      l_iface_rec.last_update_date              := SYSDATE;
      l_iface_rec.last_updated_by               := g_user_id;
      l_iface_rec.creation_date                 := SYSDATE;
      l_iface_rec.created_by                    := g_user_id;
      l_iface_rec.last_update_login             := fnd_global.login_id;
      INSERT INTO ap_invoice_lines_interface VALUES l_iface_lines_rec;
      --行 略去循环游标
      l_iface_lines_rec.org_id     := l_iface_rec.org_id;
      l_iface_lines_rec.invoice_id := l_iface_rec.invoice_id;
    
      l_iface_lines_rec.accounting_date       := SYSDATE;
      l_iface_lines_rec.line_number           := n;
      l_iface_lines_rec.line_type_lookup_code := 'ITEM';
      l_iface_lines_rec.amount                := round(line_record.line_amount -
                                                       line_record.tax_amount,
                                                       2);
    
      l_iface_lines_rec.tax_code := '0%_VAT'; --税码,发票验证时根据该税码生成税额
    
      l_iface_lines_rec.dist_code_combination_id := l_ccid; --分配账户
    
      l_iface_lines_rec.description        := line_record.purchase_reason || ',' ||
                                              line_record.comments;
      l_iface_lines_rec.quantity_invoiced  := line_record.quantity;
      l_iface_lines_rec.last_update_date   := SYSDATE;
      l_iface_lines_rec.last_updated_by    := l_user_id;
      l_iface_lines_rec.creation_date      := SYSDATE;
      l_iface_lines_rec.created_by         := l_user_id;
      l_iface_lines_rec.last_update_login  := l_login_id;
      l_iface_lines_rec.attribute_category := 'JD_AP_Settlement_Line';
      l_iface_lines_rec.attribute1         := line_record.cash_flow_code;
      l_iface_lines_rec.attribute2         := line_record.line_type_name;
      l_iface_lines_rec.attribute3         := line_record.line_number;
      l_iface_lines_rec.attribute4         := line_record.project_code;
      l_iface_lines_rec.attribute5         := cux_common_utl.get_lookup_meaning(line_record.process_type_code,
                                                                                'CUX_FIN_LINE_PROCESS_TYPE');
    
      l_iface_lines_rec.attribute6 := line_record.cost_flag;
      INSERT INTO ap_invoice_lines_interface VALUES l_iface_lines_rec_tax;
    END LOOP;
  END LOOP;
  CLOSE cur_invoice;
END;

2.运行发票导入请求

p_req_id := fnd_request.submit_request(        'SQLAP', --应用简称
                                               'APXIIMPT', --应用程序
                                               '', --请求说明(可选)
                                               '', --start time,
                                               FALSE, --sub request
                                               NULL, --Operating Unit
                                               'FINREQ', --'结算申请记录', --Source  (请求会根据Source和group_id)
                                               record_array(j).group_id, --Group       
                                               record_array(j).batch_name, --Batch Name
                                               NULL, --Hold Name 
                                               NULL, --Hold Reason
                                               NULL, --GL
                                               'N', --Purge  是否清除
                                               'N', --Trace Switch 是否启用Trace,隐藏的参数
                                               'N', --Debug Switch 是否启用调式信息,隐藏的参数
                                               'N', --Summarize Report 是否打印汇总报表
                                               NULL, --Commit Batch Size
                                               l_user_id, --User id
                                               l_login_id, --Login id
                                               chr(0));
 运行发票导入的时候,会根据批名自动生成发票批,如果
 'N', --Purge  是否清除
设置为'Y'的话,请求运行完成之后会删除接口头行表中的数据。



你可能感兴趣的:(AP发票导入(发票头行))