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;

API to Delete Price List Lines from Price List

DECLARE
   gpr_return_status                                 VARCHAR2 (1) := NULL;
   gpr_msg_count                                     NUMBER := 0;
   gpr_msg_data                                      VARCHAR2 (2000);
   gpr_price_list_rec                                qp_price_list_pub.price_list_rec_type;
   gpr_price_list_val_rec                            qp_price_list_pub.price_list_val_rec_type;
   gpr_price_list_line_tbl                           qp_price_list_pub.price_list_line_tbl_type;
   gpr_price_list_line_val_tbl                       qp_price_list_pub.price_list_line_val_tbl_type;
   gpr_qualifiers_tbl                                qp_qualifier_rules_pub.qualifiers_tbl_type;
   gpr_qualifiers_val_tbl                            qp_qualifier_rules_pub.qualifiers_val_tbl_type;
   gpr_pricing_attr_tbl                              qp_price_list_pub.pricing_attr_tbl_type;
   gpr_pricing_attr_val_tbl                          qp_price_list_pub.pricing_attr_val_tbl_type;
   ppr_price_list_rec                                qp_price_list_pub.price_list_rec_type;
   ppr_price_list_val_rec                            qp_price_list_pub.price_list_val_rec_type;
   ppr_price_list_line_tbl                           qp_price_list_pub.price_list_line_tbl_type;
   ppr_price_list_line_val_tbl                       qp_price_list_pub.price_list_line_val_tbl_type;
   ppr_qualifiers_tbl                                qp_qualifier_rules_pub.qualifiers_tbl_type;
   ppr_qualifiers_val_tbl                            qp_qualifier_rules_pub.qualifiers_val_tbl_type;
   ppr_pricing_attr_tbl                              qp_price_list_pub.pricing_attr_tbl_type;
   ppr_pricing_attr_val_tbl                          qp_price_list_pub.pricing_attr_val_tbl_type;
   k                                                 NUMBER := 1;
   j                                                 NUMBER := 1;
BEGIN
   oe_debug_pub.initialize;
   oe_debug_pub.setdebuglevel (5);
   oe_msg_pub.initialize;
   DBMS_OUTPUT.put_line ('Debug File = ' || oe_debug_pub.g_dir || '/' || oe_debug_pub.g_file);
--dbms_output.put_line('after get price list ');
   /* setup the list_header rec for update */
   gpr_price_list_rec.list_header_id                        := '<price_list_header_id>';
   gpr_price_list_rec.NAME                                  := '<price_list_name>';
   gpr_price_list_rec.list_type_code                        := 'PRL';
   gpr_price_list_rec.description                           := '<price_list_description>';
   gpr_price_list_rec.operation                             := qp_globals.g_opr_update;
-- delete the price list line rec
   gpr_price_list_line_tbl (k).list_header_id               := '<price_list_header_id>';
   gpr_price_list_line_tbl (k).list_line_id                 := '<price_list_line_id>';
   gpr_price_list_line_tbl (k).list_line_type_code          := 'PLL';
   gpr_price_list_line_tbl (k).operation                    := qp_globals.g_opr_delete;
--dbms_output.put_line('before process price list ');
   qp_price_list_pub.process_price_list (p_api_version_number          => 1
                                       , p_init_msg_list               => fnd_api.g_false
                                       , p_return_values               => fnd_api.g_false
                                       , p_commit                      => fnd_api.g_false
                                       , x_return_status               => gpr_return_status
                                       , x_msg_count                   => gpr_msg_count
                                       , x_msg_data                    => gpr_msg_data
                                       , p_price_list_rec              => gpr_price_list_rec
                                       , p_price_list_line_tbl         => gpr_price_list_line_tbl
                                       , p_pricing_attr_tbl            => gpr_pricing_attr_tbl
                                       , x_price_list_rec              => ppr_price_list_rec
                                       , x_price_list_val_rec          => ppr_price_list_val_rec
                                       , x_price_list_line_tbl         => ppr_price_list_line_tbl
                                       , x_price_list_line_val_tbl     => ppr_price_list_line_val_tbl
                                       , x_qualifiers_tbl              => ppr_qualifiers_tbl
                                       , x_qualifiers_val_tbl          => ppr_qualifiers_val_tbl
                                       , x_pricing_attr_tbl            => ppr_pricing_attr_tbl
                                       , x_pricing_attr_val_tbl        => ppr_pricing_attr_val_tbl
                                        );
   IF ppr_price_list_line_tbl.COUNT > 0
   THEN
      FOR k IN 1 .. ppr_price_list_line_tbl.COUNT
      LOOP
         DBMS_OUTPUT.put_line ('Record = ' || k || 'Return Status = ' || ppr_price_list_line_tbl (k).return_status);
      END LOOP;
   END IF;
   IF gpr_return_status <> fnd_api.g_ret_sts_success
   THEN
      RAISE fnd_api.g_exc_unexpected_error;
   END IF;
   DBMS_OUTPUT.put_line ('after process price list ');
   FOR k IN 1 .. gpr_msg_count
   LOOP
      gpr_msg_data                                             := oe_msg_pub.get (p_msg_index => k, p_encoded => 'F');
      DBMS_OUTPUT.put_line ('err msg ' || k || ' is: ' || gpr_msg_data);
      NULL;
   END LOOP;
EXCEPTION
   WHEN fnd_api.g_exc_error
   THEN
      gpr_return_status                                        := fnd_api.g_ret_sts_error;
-- Get message count and data
      DBMS_OUTPUT.put_line ('err msg 1 is : ' || gpr_msg_data);
   WHEN fnd_api.g_exc_unexpected_error
   THEN
      gpr_return_status                                        := fnd_api.g_ret_sts_unexp_error;
      DBMS_OUTPUT.put_line (' msg count 2 is : ' || gpr_msg_count);
      FOR k IN 1 .. gpr_msg_count
      LOOP
         gpr_msg_data                                             := oe_msg_pub.get (p_msg_index => k, p_encoded => 'F');
         -- Get message count and data
         DBMS_OUTPUT.put_line ('err msg ' || k || ' is: ' || gpr_msg_data);
         NULL;
      END LOOP;
   WHEN OTHERS
   THEN
      gpr_return_status                                        := fnd_api.g_ret_sts_unexp_error;
      -- Get message count and data
      DBMS_OUTPUT.put_line ('err msg 3 is : ' || gpr_msg_data);
END;
/