Showing posts with label Order Management. Show all posts
Showing posts with label Order Management. Show all posts

Friday, October 4, 2013

API to Check the Available credit On a Sales Order.


 --Mainline Function that will read an Order Header and Determine if should be checked, Consumes available Credit and applies a credit hold if Appropriate

DECLARE
   l_header_id                                       NUMBER;
   l_calling_action                                  VARCHAR2 (200);
   l_msg_index                                       NUMBER;
   l_error_message                                   VARCHAR2 (2000);
   x_msg_count                                       NUMBER;
   x_msg_data                                        VARCHAR2 (200);
   x_result_out                                      VARCHAR2 (200);
   x_return_status                                   VARCHAR2 (200);
BEGIN
   l_header_id                                              := 885421;
   l_calling_action                                         := 'BOOKING';
   x_msg_count                                              := NULL;
   x_msg_data                                               := NULL;
   x_result_out                                             := NULL;
   x_return_status                                          := NULL;
   apps.oe_credit_pub.check_available_credit (p_header_id                   => l_header_id
                                            , p_calling_action              => l_calling_action
                                            , p_msg_count                   => x_msg_count
                                            , p_msg_data                    => x_msg_data
                                            , p_result_out                  => x_result_out
                                            , p_return_status               => x_return_status
                                             );

   IF x_return_status <> fnd_api.g_ret_sts_success
   THEN
      FOR i IN 1 .. x_msg_count
      LOOP
         apps.fnd_msg_pub.get (p_msg_index                   => i
                             , p_encoded                     => fnd_api.g_false
                             , p_data                        => x_msg_data
                             , p_msg_index_out               => l_msg_index
                              );

         IF l_error_message IS NULL
         THEN
            l_error_message                                          := SUBSTR (x_msg_data, 1, 250);
         ELSE
            l_error_message                                          :=
                                                                      l_error_message || ' /' || SUBSTR (x_msg_data, 1, 250);
         END IF;
      END LOOP;

      DBMS_OUTPUT.put_line ('*****************************************');
      DBMS_OUTPUT.put_line ('API Error : ' || l_error_message);
      DBMS_OUTPUT.put_line ('*****************************************');
      ROLLBACK;
   ELSE
      DBMS_OUTPUT.put_line ('*****************************************');
      DBMS_OUTPUT.put_line ('Resul Out For Header Id : ' || l_header_id || '---' || x_result_out);
      DBMS_OUTPUT.put_line ('*****************************************');
      COMMIT;
   END IF;
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line ('Error is ' || SQLCODE || '---' || SQLERRM);
END;

API to release the Hold on Order

DECLARE
   l_order_tbl                                       oe_holds_pvt.order_tbl_type;
   x_return_status                                   VARCHAR2 (30);
   x_msg_data                                        VARCHAR2 (256);
   x_msg_count                                       NUMBER;
   l_msg_index_out                                   NUMBER;
   l_error_message                                   VARCHAR2 (2000);
BEGIN
   fnd_global.apps_initialize (1318, 21623, 660);   -- pass in user_id, responsibility_id, and application_id
   oe_debug_pub.initialize;
   oe_debug_pub.setdebuglevel (5);
   oe_msg_pub.initialize;
   l_order_tbl (1).header_id                                := '<order header id>';
   oe_debug_pub.ADD ('Just before calling OE_Holds_PUB.Apply_Holds:');
   oe_holds_pub.release_holds (p_api_version                 => 1.0
                             , p_order_tbl                   => l_order_tbl
                             , p_hold_id                     => '<hold id>'
                             , p_release_reason_code         => '<Hold Release reason Code>'
                             , p_release_comment             => '<Hold release Addiotnal Commnent if any>'
                             , x_return_status               => x_return_status
                             , x_msg_count                   => x_msg_count
                             , x_msg_data                    => x_msg_data
                              );
   oe_debug_pub.ADD ('Just after calling OE_Holds_PUB.Apply_Holds:');

   IF x_return_status <> fnd_api.g_ret_sts_success
   THEN
      FOR i IN 1 .. x_msg_count
      LOOP
         apps.fnd_msg_pub.get (p_msg_index                   => i
                             , p_encoded                     => fnd_api.g_false
                             , p_data                        => x_msg_data
                             , p_msg_index_out               => l_msg_index_out
                              );

         IF l_error_message IS NULL
         THEN
            l_error_message                                          := SUBSTR (x_msg_data, 1, 250);
         ELSE
            l_error_message                                          :=
                                                                      l_error_message || ' /' || SUBSTR (x_msg_data, 1, 250);
         END IF;
      END LOOP;

      DBMS_OUTPUT.put_line ('*****************************************');
      DBMS_OUTPUT.put_line ('API Error : ' || l_error_message);
      DBMS_OUTPUT.put_line ('*****************************************');
      ROLLBACK;
   ELSE
      DBMS_OUTPUT.put_line ('*****************************************');
      DBMS_OUTPUT.put_line ('Hold Released Successfully ');
      DBMS_OUTPUT.put_line ('*****************************************');
      COMMIT;
   END IF;

   oe_debug_pub.debug_off;
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line ('Error is ' || SQLCODE || '---' || SQLERRM);
END;

API to Apply the Hold on Order


This script can be used on Version 12.0 and later

DECLARE
   l_file                VARCHAR2 (100);
   l_data                VARCHAR2 (2000);
   l_hold_source_rec     oe_holds_pvt.hold_source_rec_type;
   l_org                 NUMBER := 204;
   l_file_val            VARCHAR2 (100);
   l_error_message       VARCHAR2 (2000);
   l_msg_index_out       NUMBER (10);
   x_return_status       VARCHAR2 (2000);
   x_msg_count           NUMBER;
   x_msg_data            VARCHAR2 (2000);
   x_debug_file          VARCHAR2 (100);
BEGIN
-- Source the Environment variables
   fnd_global.apps_initialize (
                          user_id  => '<user_id>'
                        , resp_id   => '<resp_id>'
                        , resp_appl_id => '<resp_appl_id>'
                        , security_group_id => '<security_group_id>'
                              );
   DBMS_OUTPUT.ENABLE (1000000);
   oe_debug_pub.initialize;
   oe_debug_pub.setdebuglevel (5);
   oe_debug_pub.debug_on;
   l_file_val   := oe_debug_pub.set_debug_mode ('FILE');
   DBMS_OUTPUT.put_line ('.');
   DBMS_OUTPUT.put_line (' Log File Name and Location :- ' ||                 oe_debug_pub.g_dir || '/' || oe_debug_pub.g_file);
   DBMS_OUTPUT.put_line ('.');
   mo_global.set_policy_context ('S', l_org);
   l_hold_source_rec   := oe_holds_pvt.g_miss_hold_source_rec;
   l_hold_source_rec.hold_id := '<hold_id>';
   l_hold_source_rec.hold_entity_code := 'O';   -- order level hold
   l_hold_source_rec.hold_entity_id:= '<header_id of the order>';
   l_hold_source_rec.header_id := '<header_id of the order>';
   x_return_status   := NULL;
   x_msg_data        := NULL;
   x_msg_count        := NULL;
   oe_debug_pub.ADD ('Just Before calling OE_Holds_PUB.Apply_Holds:');
   oe_holds_pub.apply_holds (p_api_version  => 1.0
                           , p_init_msg_list=> fnd_api.g_true
                           , p_commit=> fnd_api.g_true
                           , p_hold_source_rec => l_hold_source_rec
                           , x_return_status => x_return_status
                           , x_msg_count => x_msg_count
                           , x_msg_data  => x_msg_data
                            );
   oe_debug_pub.ADD ('Just After calling OE_Holds_PUB.Apply_Holds:');

   IF x_return_status <> fnd_api.g_ret_sts_success
   THEN
      FOR i IN 1 .. x_msg_count
      LOOP
         apps.fnd_msg_pub.get (p_msg_index  => i
                             , p_encoded   => fnd_api.g_false
                             , p_data      => x_msg_data
                             , p_msg_index_out => l_msg_index_out
                              );

         IF l_error_message IS NULL
         THEN
            l_error_message  := SUBSTR (x_msg_data, 1, 250);
         ELSE
            l_error_message :=                                                   l_error_message || ' /' || SUBSTR (x_msg_data, 1, 250);
         END IF;
      END LOOP;
      DBMS_OUTPUT.put_line ('API Error : ' || l_error_message);
      ROLLBACK;
   ELSE
      DBMS_OUTPUT.put_line ('Hold Applied Successfully ');
      COMMIT;
   END IF;
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line ('Error is ' || SQLCODE || '---' || SQLERRM);
END;

API to Apply the Hold on Order


This script can be used on Version 12.0 and later

DECLARE
   l_file                VARCHAR2 (100);
   l_data                VARCHAR2 (2000);
   l_hold_source_rec     oe_holds_pvt.hold_source_rec_type;
   l_org                 NUMBER := 204;
   l_file_val            VARCHAR2 (100);
   l_error_message       VARCHAR2 (2000);
   l_msg_index_out       NUMBER (10);
   x_return_status       VARCHAR2 (2000);
   x_msg_count           NUMBER;
   x_msg_data            VARCHAR2 (2000);
   x_debug_file          VARCHAR2 (100);
BEGIN
-- Source the Environment variables
   fnd_global.apps_initialize (
                          user_id  => '<user_id>'
                        , resp_id   => '<resp_id>'
                        , resp_appl_id => '<resp_appl_id>'
                        , security_group_id => '<security_group_id>'
                              );
   DBMS_OUTPUT.ENABLE (1000000);
   oe_debug_pub.initialize;
   oe_debug_pub.setdebuglevel (5);
   oe_debug_pub.debug_on;
   l_file_val   := oe_debug_pub.set_debug_mode ('FILE');
   DBMS_OUTPUT.put_line ('.');
   DBMS_OUTPUT.put_line (' Log File Name and Location :- ' ||                 oe_debug_pub.g_dir || '/' || oe_debug_pub.g_file);
   DBMS_OUTPUT.put_line ('.');
   mo_global.set_policy_context ('S', l_org);
   l_hold_source_rec   := oe_holds_pvt.g_miss_hold_source_rec;
   l_hold_source_rec.hold_id := '<hold_id>';
   l_hold_source_rec.hold_entity_code := 'O';   -- order level hold
   l_hold_source_rec.hold_entity_id:= '<header_id of the order>';
   l_hold_source_rec.header_id := '<header_id of the order>';
   x_return_status   := NULL;
   x_msg_data        := NULL;
   x_msg_count        := NULL;
   oe_debug_pub.ADD ('Just Before calling OE_Holds_PUB.Apply_Holds:');
   oe_holds_pub.apply_holds (p_api_version  => 1.0
                           , p_init_msg_list=> fnd_api.g_true
                           , p_commit=> fnd_api.g_true
                           , p_hold_source_rec => l_hold_source_rec
                           , x_return_status => x_return_status
                           , x_msg_count => x_msg_count
                           , x_msg_data  => x_msg_data
                            );
   oe_debug_pub.ADD ('Just After calling OE_Holds_PUB.Apply_Holds:');

   IF x_return_status <> fnd_api.g_ret_sts_success
   THEN
      FOR i IN 1 .. x_msg_count
      LOOP
         apps.fnd_msg_pub.get (p_msg_index  => i
                             , p_encoded   => fnd_api.g_false
                             , p_data      => x_msg_data
                             , p_msg_index_out => l_msg_index_out
                              );

         IF l_error_message IS NULL
         THEN
            l_error_message  := SUBSTR (x_msg_data, 1, 250);
         ELSE
            l_error_message :=                                                   l_error_message || ' /' || SUBSTR (x_msg_data, 1, 250);
         END IF;
      END LOOP;
      DBMS_OUTPUT.put_line ('API Error : ' || l_error_message);
      ROLLBACK;
   ELSE
      DBMS_OUTPUT.put_line ('Hold Applied Successfully ');
      COMMIT;
   END IF;
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line ('Error is ' || SQLCODE || '---' || SQLERRM);
END;

Friday, September 20, 2013

Data flow for Order-to-Cash cycle





1. Order Entry
This is first stage, When the order is entered in the system, it creates a record in order headers and Order Lines table.
·        Enter header details: Once you enter details on the order header and save it or move it to  
         lines, record goes to one table oe_order_headers_all.
             .        No record exists in any other table for this order till now.
·        Enter Line details for this order: Enter different item numbers, quantity and other details
         in line tab. When the record gets saved, it goes to one table. Order header details will be
         linked with line details by order HEADER_ID.
2. Order Booking
This is next stage, when Order is booked then the Flow status changed from Entered to Booked. At this stage, these below table get affected.
·        oe_order_headers_alL
·        oe_order_lines_all
·        wsh_delivery_details
·        wsh_delivery_assignments
*In shipping transaction form order status remains “Ready to Release”.
At the same time, Demand interface program runs in background and insert into inventory tables mtl_demand.
3. Reservation
This step is required for doing reservations SCHEDULE ORDER PROGRAM runs in the background and quantities are reserved. Once this program get successfully get completed, the mtl_demand and mtl_reservations table get updated.
4. Pick Release
Pick Release is the process of putting reservation on on-hand quantity available in the inventory and pick them for particular sales order.
Pick release can be done from ‘Release Sales Order’ form or ‘Pick release SRS’ program can be scheduled in background. In both of these cases all lines of the order gets pick released depending on the Picking rule used. If specific line/s needs to be pick release it can be done from ‘Shipping Transaction form. For this case Pick Release is done from ‘Release Sales Order’ form with Pick Confirm=NO.
Once pick release is done these are the tables get affected:
·        If step 3 is not done then MTL_RESERVATIONS gets updated now.
·        wsh_new_deliveries
·        wsh_delivery_assignments
·        wsh_delivery_details
·        MTL_TXN_REQUEST_HEADERS
·        MTL_TXN_REQUEST_LINES
·        Mtl_material_transactions_temp
·        MTL_SERIAL_NUMBERS_TEMP
·        MTL_SERIAL_NUMBERS
*In shipping transaction form order status remains “Released to Warehouse” and all the material still remains in source sub-inventory. We need to do Move Order Transaction for this order. Till this no material transaction has been posted to MTL_MATERIAL_TRANSACTIONS
5. Pick Confirm/ Move Order Transaction
Items are transferred from source sub-inventory to staging Sub-inventory. Here material transaction occurs.
Order line status becomes ‘Picked’ on Sales Order and ‘Staged/Pick Confirmed’ on Shipping Transaction Form.
·        MTL_MATERIAL_TRANSACTIONS_TEMP
·        oe_order_lines_all
·        MTL_MATERIAL_TRANSACTIONS
·        mtl_transaction_accounts
·        wsh_delivery_details
·        wsh_delivery_assignments
·        MTL_ONHAND_QUANTITIES
·        MTL_SERIAL_NUMBERS_TEMP
·        MTL_SERIAL_NUMBERS
* This step can be eliminated if we set Pick Confirm=YES at the time of Pick Release 
6. Ship Confirm
Here ship confirm interface program runs in background. Data removed from wsh_new_deliveries. 
The items on the delivery gets shipped to customer at this stage.
·        oe_order_lines_all
·        wsh_delivery_details
·        WSH_SERIAL_NUMBERS
·        mtl_transaction_interface
·        mtl_material_TRANSACTIONS
·        mtl_transaction_accounts
·        mtl_demand, MTL_reservations
·        MTL_ONHAND_QUANTITIES
·        MTL_SERIAL_NUMBERS_TEMP
·        MTL_SERIAL_NUMBERS
7. Enter Invoice 
After shipping the order the order lines gets eligible to get transferred to RA_INTERFACE_LINES_ALL. Workflow background engine picks those records and post it to RA_INTERFACE_LINES_ALL. This is also called Receivables interface, that mean information moved to accounting area for invoicing details. Invoicing workflow activity transfers shipped item information to Oracle Receivables. At the same time records also goes in the table RA_INTERFACE_SALESCREDITS_ALL which hold details of sales credit for the particular order.
ra_interface_lines_all (interface table into which the data is transferred from order management) Then Auto-invoice program imports data from this table which get affected into this stage are receivables base table. At the same time records goes in ra_customer_trx_all and ra_customer_trx_lines_all
8. Complete Line
In this stage order line level table get updated with Flow status and open flag.
oe_order_lines_all
9. Close Order
This is last step of Order Processing. In this stage only oe_order_lines_all table get updated. These are the table get affected in this step.

oe_order_lines_all
oe_order_HEADERS_all


1. Order Entry
This is first stage, When the order is entered in the system, it creates a record in order headers and Order Lines table.
·        Enter header details: Once you enter details on the order header and save it or move it to lines, record goes to one table oe_order_headers_all flow_status_code = ENTERED, booked_flag = N), Primary key=HEADER_ID
o        No record exist in any other table for this order till now.
·        Enter Line details for this order: Enter different item numbers, quantity and other details in line tab. When the record gets saved, it goes to one table. Order header details will be linked with line details by order HEADER_ID. oe_order_lines_all (flow_status_code = ENTERED, booked_flag = N, open_flag = Y) Primary key= LINE_ID
2.Order Booking
This is next stage, when Order is booked then the Flow status changed from Entered to Booked. At this stage, these below table get affected.
·        oe_order_headers_alL (flow_status_code as BOOKED, booked_flag updated to Y)
·        oe_order_lines_all (flow_status_code as AWAITING_SHIPPING, booked_flag updated Y)
·        wsh_delivery_details (DELIVERY_DETAIL_ID is assigned here, released_status ‘R’ ready to release, LINE_ID comes as SOURCE_LINE_ID)
·        wsh_delivery_assignments (DELIVERY_ASSIGNMENT_ID is assigned for DELIVERY_DETAIL_ID present in wsh_delivery_details, DELIVERY_ID remains blank till this stage)
*In shipping transaction form order status remains "Ready to Release".
At the same time, Demand interface program runs in background And insert into inventory tables mtl_demand, here LINE_ID come as a reference in DEMAND_SOURCE_LINE
3. Reservation
This step is required for doing reservations SCHEDULE ORDER PROGRAM runs in the background and quantities are reserved. Once this program get successfully get completed, the mtl_demand and mtl_reservations table get updated. LINE_ID gets updated in DEMAND_SOURCE_LINE_ID in both the tables.
4. Pick Release
Pick Release is the process of putting reservation on on-hand quantity available in the inventory and pick them for particular sales order.
Pick release can be done from 'Release Sales Order' form or 'Pick release SRS' program can be scheduled in background. In both of these cases all lines of the order gets pick released depending on the Picking rule used. If specific line/s needs to be pick release it can be done from 'Shipping Transaction form. For this case Pick Release is done from 'Release Sales Order' form with Pick Confirm=NO.
Once pick release is done these are the tables get affected:
·        If step 3 is not done then MTL_RESERVATIONS gets updated now.
·        wsh_new_deliveries (one record gets inserted with SOURCE_HEADER_ID= order header ID, status_code=OP =>open)
·        wsh_delivery_assignments (DELIVERY_ID gets assigned which comes from wsh_new_deliveries)
·        wsh_delivery_details (released_status ‘S’ ‘submitted for release’)
·        MTL_TXN_REQUEST_HEADERS
·        MTL_TXN_REQUEST_LINES (LINE_ID goes as TXN_SOURCE_LINE_ID)
·        (move order tables. Here request is generated to move item from Source (RM or FG) sub-inventory to staging sub-inventory)
·        Mtl_material_transactions_temp (link to above tables through move_order_header_id/line_id, this table holds the record temporally)
·        MTL_SERIAL_NUMBERS_TEMP (if item is serial controlled at receipt then record goes in this table)
·        MTL_SERIAL_NUMBERS (enter value in GROUP_MARK_ID )
*In shipping transaction form order status remains "Released to Warehouse" and all the material still remains in source sub-inventory. We need to do Move Order Transaction for this order. Till this no material transaction has been posted to MTL_MATERIAL_TRANSACTIONS
5.Pick Confirm/ Move Order Transaction
Items are transferred from source sub-inventory to staging Sub-inventory. Here material transaction occurs.
Order line status becomes 'Picked' on Sales Order and 'Staged/Pick Confirmed' on Shipping Transaction Form.
·        MTL_MATERIAL_TRANSACTIONS_TEMP (Record gets deleted from here and gets posted to MTL_MATERIAL_TRANSACTIONS)
·        oe_order_lines_all (flow_status_code ‘PICKED’ )
·        MTL_MATERIAL_TRANSACTIONS (LINE_ID goes as TXN_SOURCE_LINE_ID)
·        mtl_transaction_accounts
·        wsh_delivery_details (released_status becomes ‘Y’ => ‘Released’ )
·        wsh_delivery_assignments
·        MTL_ONHAND_QUANTITIES
·        MTL_SERIAL_NUMBERS_TEMP (record gets inserted after putting details for the item which are serial controlled at 'Sales order issue')
·        MTL_SERIAL_NUMBERS (record gets inserted after putting details for the item which are serial controlled at 'Sales order issue')
* This step can be eliminated if we set Pick Confirm=YES at the time of Pick Release

6.Ship Confirm
Here ship confirm interface program runs in background. Data removed from wsh_new_deliveries.
 
The items on the delivery gets shipped to customer at this stage.
·        oe_order_lines_all (flow_status_code ‘shipped’)
·        wsh_delivery_details (released_status ‘C’ ‘Shipped’, SERIAL_NUMBER if quantity is ONE)
·        WSH_SERIAL_NUMBERS (records gets inserted with the DELIVERY_DETAIL_ID reference, only in case of shipped quantity is two or more)
·        mtl_transaction_interface
·        mtl_material_TRANSACTIONS (linked through Transaction source header id)
·        mtl_transaction_accounts
·        Data deleted from mtl_demand, MTL_reservations
·        Item deducted from MTL_ONHAND_QUANTITIES
·        MTL_SERIAL_NUMBERS_TEMP (records gets deleted from this table)
·        MTL_SERIAL_NUMBERS (Serial number stauts gets updated CURRENT_STATUS=4 , 'Issued out of store')
7.Enter Invoice
After shipping the order the order lines gets eligible to get transfered to RA_INTERFACE_LINES_ALL. Workflow background engine picks those records and post it to RA_INTERFACE_LINES_ALL. This is also called Receivables interface, that mean information moved to accounting area for invoicing details. Invoicing workflow activity transfers shipped item information to Oracle Receivables. At the same time records also goes in the table RA_INTERFACE_SALESCREDITS_ALL which hold details of sales credit for the particular order.
ra_interface_lines_all (interface table into which the data is transferred from order management) Then Autoinvoice program imports data from this table which get affected into this stage are receivables base table. At the same time records goes in
ra_customer_trx_all (cust_trx_id is primary key to link it to trx_lines table and trx_number is the invoice number)
ra_customer_trx_lines_all (line_attribute_1 and line_attribute_6 are linked to order number and line_id of the orders)
8.Complete Line
In this stage order line level table get updated with Flow status and open flag.
oe_order_lines_all (flow_status_code ‘shipped’, open_flag “N”)
9.Close Order
This is last step of Order Processing. In this stage only oe_order_lines_all table get updated. These are the table get affected in this step.

oe_order_lines_all (flow_status_code ‘closed’, open_flag “N”)
oe_order_HEADERS_all