Search This Blog

Sunday, May 20, 2018

Inventory Move Order API oracle apps R12

 PROCEDURE pos_create_move_order
(
P_POS_ID VARCHAR2,
P_organization_id NUMBER,
P_REQUEST_NUMBER VARCHAR2, --generate seq
P_transaction_type_id NUMBER DEFAULT 63,--move order issue
P_move_order_type NUMBER DEFAULT 1 --Requisition
,x_return_status out varchar2
,x_header_id out number
)
   IS
      l_hdr_rec         inv_move_order_pub.trohdr_rec_type              := inv_move_order_pub.g_miss_trohdr_rec;
      l_line_tbl        inv_move_order_pub.trolin_tbl_type              := inv_move_order_pub.g_miss_trolin_tbl;
      --x_return_status   VARCHAR2 (1);
      x_msg_count       NUMBER;
      x_msg_data        VARCHAR2 (4000);
      x_hdr_rec         inv_move_order_pub.trohdr_rec_type              := inv_move_order_pub.g_miss_trohdr_rec;
      x_hdr_val_rec     inv_move_order_pub.trohdr_val_rec_type;
      x_line_tbl        inv_move_order_pub.trolin_tbl_type;
      x_line_val_tbl    inv_move_order_pub.trolin_val_tbl_type;
      v_msg_index_out   NUMBER;
      l_rsr_type        inv_reservation_global.mtl_reservation_tbl_type;
      v_line number := 1;
      v_line_count number :=0;
     
     CURSOR C1 IS
      SELECT inventory_item_id,COST_OF_SALES_ACCOUNT,xxfuj.quantity quantity, xxfuj.uom uom
      from mtl_system_items_b mtl,
      xxfuj_pos_d xxfuj
      where xxfuj.item_id =inventory_item_id
      and organization_id = P_organization_id
      and xxfuj.pos_id =  P_POS_ID
      --and rownum =1
      ;
     
   BEGIN

      l_line_tbl.DELETE;
      x_line_tbl.DELETE;
      l_hdr_rec.date_required := SYSDATE;
      l_hdr_rec.REQUEST_NUMBER := P_REQUEST_NUMBER;--'1232';
      l_hdr_rec.header_status := inv_globals.g_to_status_preapproved;
      l_hdr_rec.organization_id := P_organization_id;--1770 ; ---- fill in the values for ORganization_ID
      l_hdr_rec.status_date := SYSDATE;
      l_hdr_rec.transaction_type_id := P_transaction_type_id;--63;--inv_globals.g_type_transfer_order_issue;
      l_hdr_rec.move_order_type := P_move_order_type;--1;--inv_globals.g_move_order_requisition;
      l_hdr_rec.db_flag := fnd_api.g_true;
      l_hdr_rec.operation := inv_globals.g_opr_create;
     
         for i in c1 loop
   v_line_count := v_line_count + v_line;
   dbms_output.put_line(v_line_count);
      l_line_tbl (v_line_count).date_required := SYSDATE;
      l_line_tbl (v_line_count).inventory_item_id := I.inventory_item_id;--95081;
      l_line_tbl (v_line_count).line_id := fnd_api.g_miss_num;
      l_line_tbl (v_line_count).line_number := v_line_count; --line number
      l_line_tbl (v_line_count).line_status := inv_globals.g_to_status_preapproved;
      l_line_tbl (v_line_count).transaction_type_id := inv_globals.g_type_transfer_order_issue;
      l_line_tbl (v_line_count).organization_id := P_organization_id ;
      l_line_tbl (v_line_count).quantity := i.quantity;  --quantity
      l_line_tbl (v_line_count).status_date := SYSDATE;
      l_line_tbl (v_line_count).uom_code := upper(I.UOM);  -- UOM code
      l_line_tbl (v_line_count).db_flag := fnd_api.g_true;
      l_line_tbl (v_line_count).operation := inv_globals.g_opr_create;
      l_line_tbl (v_line_count).to_account_id := i.COST_OF_SALES_ACCOUNT;--3348167; --ask moamen
           end loop; 
      inv_move_order_pub.process_move_order (p_api_version_number      => 1.0
                                           , p_init_msg_list           => fnd_api.g_false
                                           , p_return_values           => fnd_api.g_false
                                           , p_commit                  => fnd_api.g_false
                                           , x_return_status           => x_return_status
                                           , x_msg_count               => x_msg_count
                                           , x_msg_data                => x_msg_data
                                           , p_trohdr_rec              => l_hdr_rec
                                           , p_trolin_tbl              => l_line_tbl
                                           , x_trohdr_rec              => x_hdr_rec
                                           , x_trohdr_val_rec          => x_hdr_val_rec
                                           , x_trolin_tbl              => x_line_tbl
                                           , x_trolin_val_tbl          => x_line_val_tbl
                                            );
                                         
      DBMS_OUTPUT.put_line ('Return Status is :' || x_return_status);
      DBMS_OUTPUT.put_line ('Message Count is :' || x_msg_count);
      DBMS_OUTPUT.put_line ('Move Order Number is :' || x_hdr_rec.request_number);
      DBMS_OUTPUT.put_line ('Move Order Number is :' || x_hdr_rec.header_id);
      DBMS_OUTPUT.put_line ('Number of Lines Created are :' || x_line_tbl.COUNT);
     
      x_header_id := x_hdr_rec.header_id;
     
      IF x_return_status = 'S'
      THEN
              UPDATE XXFUJ_POS_H
        SET MOVE_ORDER_ISSUE_ID = x_hdr_rec.header_id
        WHERE POS_ID = P_POS_ID;
        COMMIT;
         COMMIT;
      ELSE
         ROLLBACK;
      END IF;

      IF x_msg_count > 0
      THEN
         FOR v_index IN 1 .. x_msg_count
         LOOP
            fnd_msg_pub.get (p_msg_index => v_index, p_encoded => 'F', p_data => x_msg_data, p_msg_index_out => v_msg_index_out);
            x_msg_data := SUBSTR (x_msg_data, 1, 200);
            DBMS_OUTPUT.put_line (x_msg_data);
            DBMS_OUTPUT.put_line ('============================================================');
         END LOOP;
      END IF;
   END;

No comments:

Post a Comment