EBS创建采购订单

安稳与你 提交于 2020-01-22 09:37:52

--初始化
/*
begin
  fnd_global.apps_initialize(user_id      => 8162,
                             resp_id      => 50692,
                             resp_appl_id => 20003);
  mo_global.init('M');
end;
*/


--上PA模块的采购合同导入代码--测试通过20170906,205采购订单--只导入单行,如果是多行,则需要加loop
DECLARE
    l_api_name CONSTANT VARCHAR2(30) := 'create_purchase_order';
    l_savepoint_name       VARCHAR2(30) := '';
    p_batch_id             NUMBER;
    l_header_iface_rec     po_headers_interface%ROWTYPE;
    l_line_iface_rec       po_lines_interface%ROWTYPE;
    l_dist_iface_rec       po_distributions_interface%ROWTYPE;
    l_line_num             NUMBER;
    l_task_id              NUMBER;
    l_chart_of_accounts_id NUMBER;
    l_segment1             VARCHAR2(30);
    l_segment2             VARCHAR2(30);
    l_segment3             VARCHAR2(30);
    l_segment4             VARCHAR2(30);
    l_segment5             VARCHAR2(100);
    l_segment6             VARCHAR2(30);
    l_segment7             VARCHAR2(30);
    l_segment8             VARCHAR2(30);
    l_segment9             VARCHAR2(30);
    l_segment10            VARCHAR2(30);
    l_line_type_id         NUMBER;
    l_expenditure_type     pa_expenditure_types.expenditure_type%TYPE;
    l_charge_account_id    NUMBER;
    l_agent_id             NUMBER;
    l_validate_status      VARCHAR2(1);
 
  BEGIN


    
      l_task_id              := 335351;--NULL;
      l_chart_of_accounts_id := NULL;
      l_segment1             := NULL;
      l_segment2             := NULL;
      l_segment3             := NULL;
      l_segment4             := NULL;
      l_segment6             := NULL;
      l_segment7             := NULL;
      l_segment8             := NULL;
      l_segment9             := NULL;
      l_segment10            := NULL;
      l_line_type_id         := 1;--NULL;
      l_expenditure_type     := NULL;
      l_charge_account_id    := NULL;
      l_agent_id             := NULL;
      
      --project_id=237441 org_id = 351 agent_id = 1034
    

    

    

        
      l_segment5 := 'GT-2016-JZ·G-702';--rec_progress.project_number;
    
      --如果是期初的劳务的应付暂估,将使用(期初应付暂估中转科目),且项目段为0 
/*      IF rec_progress.is_qichu = 'QICHU' THEN
        l_segment3 := '9006';
        l_segment5 := '0';
      END IF;*/
    
      --获取PO借记账户--取不到,待测试
      BEGIN
        l_charge_account_id := cux_gl_utl.get_coa_ccid(p_chart_of_accounts_id => 50388,
                                                       p_seg1                 => '1027',
                                                       p_seg2                 => '0',
                                                       p_seg3                 => '0',
                                                       p_seg4                 => '0',
                                                       p_seg5                 => '0',
                                                       p_seg6                 => '0',
                                                       p_seg7                 => '0',
                                                       p_seg8                 => '0',
                                                       p_seg9                 => '0',
                                                       p_seg10                => '0');
      EXCEPTION
        WHEN others THEN
          dbms_output.put_line('empty1');--null;
      END;
      IF l_charge_account_id IS NULL THEN
        dbms_output.put_line('empty2');--null;
      END IF;
      l_line_type_id := 1;--货物--get_line_type_id(rec_progress.currency_code);

    
      l_agent_id := 1034;--get_agent_id(rec_progress.created_by);

    
      l_header_iface_rec                     := NULL;
      l_header_iface_rec.interface_header_id := po_headers_interface_s.nextval;
      IF p_batch_id IS NULL THEN
        p_batch_id := l_header_iface_rec.interface_header_id;
      END IF;
      l_header_iface_rec.batch_id              := p_batch_id;
      l_header_iface_rec.interface_source_code := 'PO';
      l_header_iface_rec.process_code          := 'PENDING';
      l_header_iface_rec.action                := 'ORIGINAL';
      l_header_iface_rec.document_type_code    := 'STANDARD';
      l_header_iface_rec.document_subtype      := NULL;
      l_header_iface_rec.approval_status       := 'APPROVED';
      l_header_iface_rec.vendor_id             := 326957;--2352;--rec_progress.vendor_id;
      l_header_iface_rec.vendor_site_id        := 598395;--279463;--rec_progress.vendor_site_id;
      l_header_iface_rec.terms_id              := 10100;--10060;--rec_progress.terms_id;
      l_header_iface_rec.ship_to_location_id   := 10888;--rec_progress.ship_to_location_id;
      l_header_iface_rec.bill_to_location_id   := 10888;--rec_progress.bill_to_location_id;
      l_header_iface_rec.agent_id              := l_agent_id;
      l_header_iface_rec.currency_code         := 'CNY';--rec_progress.currency_code;
      l_header_iface_rec.org_id                := 295;--rec_progress.org_id;
    
      l_header_iface_rec.attribute_category := 'STANDARD';
        --材料
        l_header_iface_rec.attribute2 := '10';

      l_header_iface_rec.attribute3 := '30';
      l_header_iface_rec.attribute4 := 'FB12345';--rec_progress.contract_number;
      --l_line_iface_rec.attribute5 := rec_progress.work_progress_id;
      l_header_iface_rec.interface_source_code := 'WORK_PROGRESS';
    
      l_header_iface_rec.creation_date          := SYSDATE;
      l_header_iface_rec.created_by             := 8162;
      l_header_iface_rec.last_update_date       := SYSDATE;
      l_header_iface_rec.last_updated_by        := 8162;
      l_header_iface_rec.last_update_login      := -1;
      l_header_iface_rec.program_application_id := 20003;
      l_header_iface_rec.program_id             := -1;
      l_header_iface_rec.program_update_date    := SYSDATE;
      l_header_iface_rec.request_id             := -1;
    
      INSERT INTO po_headers_interface VALUES l_header_iface_rec;
    
      l_line_num := 0;
      
        l_line_num       := l_line_num + 1;
        l_line_iface_rec := NULL;
        --LINES
      
        l_line_iface_rec.interface_header_id := l_header_iface_rec.interface_header_id;
        l_line_iface_rec.interface_line_id   := po_lines_interface_s.nextval;
        l_line_iface_rec.process_code        := 'PENDING';
        l_line_iface_rec.action              := 'ORIGINAL';
        l_line_iface_rec.line_num            := 1;
        l_line_iface_rec.line_type_id        := l_line_type_id;
       -- l_line_iface_rec.item_description    := rec_line.line_entity;
        l_line_iface_rec.item_id             := 231102;--rec_line.line_entity;
        l_line_iface_rec.quantity            := 100;--rec_line.amount; ---增值税上线修改
        l_line_iface_rec.unit_price          := 1;--
        l_line_iface_rec.need_by_date        := SYSDATE;
        l_line_iface_rec.line_attribute15    := 222222;--rec_line.progress_line_id;
      
        --SHIPMENTS
        l_line_iface_rec.shipment_num            := 1;
        l_line_iface_rec.ship_to_organization_id := 315;--rec_progress.inventory_organization_id;
        l_line_iface_rec.receiving_routing_id    := 3; --直接交货 
      
        l_line_iface_rec.creation_date     := SYSDATE;
        l_line_iface_rec.created_by        := 8162;
        l_line_iface_rec.last_update_date  := SYSDATE;
        l_line_iface_rec.last_updated_by   := 8162;
        l_line_iface_rec.last_update_login := -1;
      
        INSERT INTO po_lines_interface VALUES l_line_iface_rec;
        --distributions
        l_dist_iface_rec                             := NULL;
        l_dist_iface_rec.interface_header_id         := l_header_iface_rec.interface_header_id;
        l_dist_iface_rec.interface_line_id           := l_line_iface_rec.interface_line_id;
        l_dist_iface_rec.interface_distribution_id   := po_distributions_interface_s.nextval;
        l_dist_iface_rec.distribution_num            := 1;
        l_dist_iface_rec.charge_account_id           := 226694;--226697l_charge_account_id; --PO借记账户对应form界面的CODE_COMBINATION_ID
        l_dist_iface_rec.project_id                  := 237441;--rec_progress.project_id;
      --  l_dist_iface_rec.task_id                     := l_task_id;--不必添加task_id不然会在入库的时候匹配不上货位信息,可测试
        --l_dist_iface_rec.expenditure_type            := l_expenditure_type;
       -- l_dist_iface_rec.expenditure_organization_id := 315;--rec_progress.inventory_organization_id;
        --l_dist_iface_rec.expenditure_item_date       := SYSDATE;
        l_dist_iface_rec.quantity_ordered            := 100;--rec_line.amount;
      
        l_dist_iface_rec.creation_date     := SYSDATE;
        l_dist_iface_rec.created_by        := 8162;
        l_dist_iface_rec.last_update_date  := SYSDATE;
        l_dist_iface_rec.last_updated_by   := 8162;
        l_dist_iface_rec.last_update_login := -1;
      
        INSERT INTO po_distributions_interface VALUES l_dist_iface_rec;
      


    DECLARE
      l_count NUMBER;
    BEGIN
      IF p_batch_id IS NOT NULL THEN
        po_docs_interface_sv5.process_po_headers_interface(x_selected_batch_id          => p_batch_id,
                                                           x_buyer_id                   => NULL,
                                                           x_document_type              => 'STANDARD',
                                                           x_document_subtype           => NULL,
                                                           x_create_items               => 'N',
                                                           x_create_sourcing_rules_flag => NULL,
                                                           x_rel_gen_method             => NULL,
                                                           x_approved_status            => 'APPROVED',
                                                           x_commit_interval            => 10,
                                                           x_process_code               => 'PENDING',
                                                           x_interface_header_id        => NULL,
                                                           x_org_id_param               => 295,--org_id
                                                           x_ga_flag                    => NULL,
                                                           p_sourcing_level             => NULL,
                                                           p_inv_org_id                 => NULL);
      END IF;
    
    EXCEPTION
      WHEN OTHERS THEN
        null;

    END;
  

  
  EXCEPTION
    WHEN others THEN
      
    dbms_output.put_line('ERRPR1');

  END create_purchase_order;

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!