oe_order_pub 创建 登记 销售订单

DECLARE
    l_api_version_number     CONSTANT NUMBER := 1.0;
    l_api_name               CONSTANT VARCHAR2(30) := 'cux_create_order';
    l_control_rec            oe_globals.control_rec_type;
    l_return_status          VARCHAR2(1);
    l_msg_count              NUMBER;
    l_line_con               NUMBER := 0;
    x_msg_data               VARCHAR2(1000);
    l_source_id              NUMBER := 0;
    l_header_rec             oe_order_pub.header_rec_type := oe_order_pub.g_miss_header_rec;
    o_header_rec             oe_order_pub.header_rec_type;
    l_header_val_rec         oe_order_pub.header_val_rec_type;
    l_header_adj_tbl         oe_order_pub.header_adj_tbl_type;
    l_header_adj_val_tbl     oe_order_pub.header_adj_val_tbl_type;
    l_header_price_att_tbl   oe_order_pub.header_price_att_tbl_type;
    l_header_adj_att_tbl     oe_order_pub.header_adj_att_tbl_type;
    l_header_adj_assoc_tbl   oe_order_pub.header_adj_assoc_tbl_type;
    l_header_scredit_tbl     oe_order_pub.header_scredit_tbl_type;
    l_header_scredit_val_tbl oe_order_pub.header_scredit_val_tbl_type;
    l_line_tbl               oe_order_pub.line_tbl_type := oe_order_pub.g_miss_line_tbl;
    o_line_tbl               oe_order_pub.line_tbl_type;
    l_line_adj_tbl           oe_order_pub.line_adj_tbl_type;
    l_line_price_att_tbl     oe_order_pub.line_price_att_tbl_type;
    l_line_adj_att_tbl       oe_order_pub.line_adj_att_tbl_type;
    l_line_adj_assoc_tbl     oe_order_pub.line_adj_assoc_tbl_type;
    l_line_scredit_tbl       oe_order_pub.line_scredit_tbl_type;
    l_lot_serial_tbl         oe_order_pub.lot_serial_tbl_type;
    l_line_val_tbl           oe_order_pub.line_val_tbl_type;
    l_line_adj_val_tbl       oe_order_pub.line_adj_val_tbl_type;
    l_line_scredit_val_tbl   oe_order_pub.line_scredit_val_tbl_type;
 
    l_lot_serial_val_tbl     oe_order_pub.lot_serial_val_tbl_type;
    l_action_qeq_tbl         oe_order_pub.request_tbl_type;
    x_action_qeq_tbl         oe_order_pub.request_tbl_type;
   
    v_count               NUMBER;
    l_customer_id         NUMBER;
    l_cust_acct_site_id   NUMBER;
    l_bill_site_use_id    NUMBER;
    l_ship_site_use_id    NUMBER;
    l_ship_from_org_id    NUMBER;
    l_order_type_id       NUMBER;
    l_price_list_id       NUMBER;
    l_payment_term_id     NUMBER;
    l_primary_salesrep_id NUMBER;
    l_salesrep_id         NUMBER;
    l_inventory_item_id   NUMBER;
    l_po_tax_price        NUMBER;
    l_price_list_price    NUMBER;
    l_msg_data            VARCHAR2(2000);
   
BEGIN
     
  fnd_global.APPS_INITIALIZE(1371,50627,660);
 
  mo_global.init('ONT');      
  mo_global.set_policy_context('S', 88);
  oe_msg_pub.initialize;
  oe_debug_pub.initialize;

--  fnd_request.set_org_id(88);
 
 /* SELECT oe_order_headers_s.NEXTVAL
    INTO l_header_rec.header_id
    FROM dual;
            */
  l_header_rec.order_source_id         := l_source_id;
  l_header_rec.orig_sys_document_ref   := '2010072762';
  l_header_rec.sold_to_org_id          := 37040;
  l_header_rec.ship_from_org_id        := 89;
  l_header_rec.salesrep_id             := 100005041;
 -- l_header_rec.version_number          := 0;
  l_header_rec.booked_flag             := 'N';
  l_header_rec.flow_status_code        := 'ENTERED';
 -- l_header_rec.booked_date             := NULL;
 -- l_header_rec.pricing_date            := trunc(SYSDATE);
 -- l_header_rec.transactional_curr_code := 'CNY';
  l_header_rec.operation               := oe_globals.g_opr_create;
 -- l_header_rec.cancelled_flag          := 'N';
 -- l_header_rec.created_by              := fnd_global.user_id;
--  l_header_rec.creation_date           := SYSDATE;
  l_header_rec.cust_po_number          := NULL;
  l_header_rec.ship_to_org_id          := 2081; --参数
  l_header_rec.invoice_to_org_id       := 2080; --参数
--  l_header_rec.last_updated_by         := fnd_global.user_id;
--  l_header_rec.last_update_date        := SYSDATE;
--  l_header_rec.last_update_login       := fnd_global.login_id;
  l_header_rec.order_category_code     := 'ORDER';
 -- l_header_rec.ordered_date            := to_date(SYSDATE,'YYYY-MM-DD');
  l_header_rec.order_type_id           := 1142; --参数
  l_header_rec.org_id                  := 88;
  l_header_rec.price_list_id           := 31010; --参数
--  l_header_rec.payment_term_id         := 5; --参数
  --l_header_rec.shipping_method_code := p_shipping_method_code; --参数
  
   
  l_line_tbl.DELETE;
  l_line_con := 1;
    
  l_line_tbl(l_line_con) := oe_order_pub.g_miss_line_rec;
 /* SELECT oe_order_lines_s.NEXTVAL
    INTO l_line_tbl(l_line_con).line_id
    FROM dual;*/
       
  l_line_tbl(l_line_con).operation := oe_globals.g_opr_create;
  l_line_tbl(l_line_con).booked_flag := 'N';
--  l_line_tbl(l_line_con).cancelled_flag := 'N';
  l_line_tbl(l_line_con).created_by := fnd_global.user_id;
 -- l_line_tbl(l_line_con).creation_date := SYSDATE;
    
  l_line_tbl(l_line_con).orig_sys_document_ref := '2010072762';
  l_line_tbl(l_line_con).inventory_item_id := 206015;
  l_line_tbl(l_line_con).ship_from_org_id := 89;
--  l_line_tbl(l_line_con).last_updated_by := fnd_global.user_id;
--  l_line_tbl(l_line_con).last_update_date := SYSDATE;
--  l_line_tbl(l_line_con).last_update_login := fnd_global.login_id;
--  l_line_tbl(l_line_con).line_category_code := 'ORDER';
  l_line_tbl(l_line_con).line_number := l_line_con; --c_lines.line_num;
--  l_line_tbl(l_line_con).schedule_ship_date    := to_date('2010-07-22','YYYY-MM-DD');
--  l_line_tbl(l_line_con).unit_selling_price    := 150;
--  l_line_tbl(l_line_con).unit_list_price       := 150;
--  l_line_tbl(l_line_con).unit_selling_price_per_pqty := l_po_tax_price; --j.unit_price;
  l_line_tbl(l_line_con).ordered_quantity      := 20;
--  l_line_tbl(l_line_con).pricing_quantity      := 20;
  --l_line_tbl(l_line_con).order_quantity_uom := l_uom;
--  l_line_tbl(l_line_con).ordered_item_id       := 183010;
--  l_line_tbl(l_line_con).open_flag := 'Y';
  l_line_tbl(l_line_con).org_id := 88;
  --l_line_tbl(l_line_con).shipping_method_code := NULL;
  --l_line_tbl(l_line_con).payment_term_id := NULL; --参数
  l_line_tbl(l_line_con).schedule_arrival_date := SYSDATE;
  l_line_tbl(l_line_con).calculate_price_flag := 'Y';
  l_line_tbl(l_line_con).subinventory := NULL;

  --登记销售订单
  l_action_qeq_tbl(1).Entity_code      :=   OE_GLOBALS.G_ENTITY_HEADER;
  l_action_qeq_tbl(1).request_type     :=   OE_GLOBALS.G_BOOK_ORDER;


  --调用 api 生成销售订单
  --log('xxxxxxxxxxx-a');
  oe_order_pub.process_order(p_api_version_number     => l_api_version_number
                            ,p_init_msg_list          => fnd_api.g_false
                            ,p_return_values          => fnd_api.g_false
                            ,p_action_commit          => fnd_api.g_false
                            ,x_return_status          => l_return_status
                            ,x_msg_count              => l_msg_count
                            ,x_msg_data               => x_msg_data
                            ,p_header_rec             => l_header_rec
                            ,p_line_tbl               => l_line_tbl
                            ,p_line_adj_tbl           => l_line_adj_tbl
                            ,p_action_request_tbl     => l_action_qeq_tbl
                            ,x_header_rec             => o_header_rec
                            ,x_header_val_rec         => l_header_val_rec
                            ,x_header_adj_tbl         => l_header_adj_tbl
                            ,x_header_adj_val_tbl     => l_header_adj_val_tbl
                            ,x_header_price_att_tbl   => l_header_price_att_tbl
                            ,x_header_adj_att_tbl     => l_header_adj_att_tbl
                            ,x_header_adj_assoc_tbl   => l_header_adj_assoc_tbl
                            ,x_header_scredit_tbl     => l_header_scredit_tbl
                            ,x_header_scredit_val_tbl => l_header_scredit_val_tbl
                            ,x_line_tbl               => o_line_tbl
                            ,x_line_val_tbl           => l_line_val_tbl
                            ,x_line_adj_tbl           => l_line_adj_tbl
                            ,x_line_adj_val_tbl       => l_line_adj_val_tbl
                            ,x_line_price_att_tbl     => l_line_price_att_tbl
                            ,x_line_adj_att_tbl       => l_line_adj_att_tbl
                            ,x_line_adj_assoc_tbl     => l_line_adj_assoc_tbl
                            ,x_line_scredit_tbl       => l_line_scredit_tbl
                            ,x_line_scredit_val_tbl   => l_line_scredit_val_tbl
                            ,x_lot_serial_tbl         => l_lot_serial_tbl
                            ,x_lot_serial_val_tbl     => l_lot_serial_val_tbl
                            ,x_action_request_tbl     => x_action_qeq_tbl);
  --返回错误信息
  IF l_return_status <> fnd_api.g_ret_sts_success THEN
    FOR l_index IN 1 .. l_msg_count LOOP
      x_msg_data := oe_msg_pub.get(p_msg_index => l_msg_count
                                  ,p_encoded   => 'F');
         
       dbms_output.put_line(x_msg_data); --substr(trim(nvl(o_msg_data,' ')||'~'||x_msg_data),1,500);
    END LOOP;
   
  ELSE
      COMMIT;
      dbms_output.put_line('S');
      dbms_output.put_line(x_action_qeq_tbl(1).return_status);
   -- END IF;
  END IF;
   -- END LOOP;
END;

你可能感兴趣的:(ORACLE,EBS)