Sunday, January 24, 2021

Ap_Suppliers Create Ap_Suppliers api - AP_VENDOR_PUB_PKG.Create_Vendor

 /* Formatted on 10/12/2020 4:16:48 PM (QP5 v5.277) */

DECLARE

   l_vendor_rec      ap_vendor_pub_pkg.r_vendor_rec_type;

   l_return_status   VARCHAR2 (10);

   l_msg_count       NUMBER;

   l_msg_data        VARCHAR2 (1000);

   l_vendor_id       NUMBER;

   l_party_id        NUMBER;

   p_count           NUMBER;

   v_api_error       VARCHAR2 (500);

   v_error_msg       VARCHAR2 (500) := NULL;

   l_msg             VARCHAR2 (200);

   x_party_id        NUMBER;


   CURSOR l_data

   IS

      SELECT vendor_id,

             vendor_name,

             segment1,

             --new_person_id,

             TRIM (vendor_type_lookup_code) vendor_type_lookup_code,

             one_time_flag,

             terms_id terms_id_old,

             (SELECT DISTINCT term_id

                FROM ap_terms_tl

               WHERE name = aps.term_name)

                terms_id,

             term_name,

             PAY_DATE_BASIS_LOOKUP_CODE,

             PAY_GROUP_LOOKUP_CODE,

             PAYMENT_PRIORITY,

             INVOICE_CURRENCY_CODE,

             PAYMENT_CURRENCY_CODE,

             start_date_active,

             TERMS_DATE_BASIS,

             match_option,

             new_vendor_id,

             new_party_id,

             status,

            (select new_person_id from XX.XX_PERSON_CREATE_TMP where person_id=aps.employee_id) employee_id,

             num_1099,

            attribute1,

            attribute2,

            attribute7,

            attribute8,

            attribute9,

            attribute10,

            attribute11,

            attribute12,

            attribute13,

            attribute14,

            attribute15,

            ALLOW_AWT_FLAG,

            VAT_REGISTRATION_NUM

        FROM xx.xx_ap_suppliers aps where status is null;


BEGIN

   fnd_global.apps_initialize(

                                user_id=>1110,

                                resp_id=>50779,

                                resp_appl_id=>200);

   mo_global.init ('SQLAP');

  --- fnd_client_info.set_org_context (101);


   FOR n_data IN l_data

   LOOP

      -- --------------

      -- Required

      -- --------------

      l_vendor_rec.segment1 := n_data.segment1;

      l_vendor_rec.vendor_name := n_data.vendor_name;

      l_vendor_rec.vendor_type_lookup_code := n_data.vendor_type_lookup_code;

      l_vendor_rec.ONE_TIME_FLAG := n_data.ONE_TIME_FLAG;

      l_vendor_rec.TERMS_ID := n_data.TERMS_ID;

      l_vendor_rec.PAY_DATE_BASIS_LOOKUP_CODE :=n_data.PAY_DATE_BASIS_LOOKUP_CODE;

      l_vendor_rec.PAY_GROUP_LOOKUP_CODE := n_data.PAY_GROUP_LOOKUP_CODE;

      l_vendor_rec.PAYMENT_PRIORITY := n_data.PAYMENT_PRIORITY;

      l_vendor_rec.INVOICE_CURRENCY_CODE := n_data.INVOICE_CURRENCY_CODE;

      l_vendor_rec.PAYMENT_CURRENCY_CODE := n_data.PAYMENT_CURRENCY_CODE;

      l_vendor_rec.START_DATE_ACTIVE := n_data.START_DATE_ACTIVE;

      l_vendor_rec.TERMS_DATE_BASIS := n_data.TERMS_DATE_BASIS;

      l_vendor_rec.MATCH_OPTION := n_data.MATCH_OPTION;

      l_vendor_rec.EMPLOYEE_ID := n_data.employee_id;

      l_vendor_rec.attribute1 :=    n_data.attribute1;

      l_vendor_rec.attribute2 :=   n_data.attribute2;

      l_vendor_rec.attribute7 :=    n_data.attribute7;

      l_vendor_rec.attribute8 :=   n_data.attribute8;

      l_vendor_rec.attribute9 :=   n_data.attribute9;

      l_vendor_rec.attribute10 :=   n_data.attribute10;

      l_vendor_rec.attribute11 :=   n_data.attribute11;

      l_vendor_rec.attribute12 :=   n_data.attribute12;

      l_vendor_rec.attribute13 :=  n_data.attribute13;

      l_vendor_rec.attribute14 :=  n_data.attribute14;

      l_vendor_rec.attribute15 :=  n_data.attribute15;

      l_vendor_rec.ALLOW_AWT_FLAG :=  n_data.ALLOW_AWT_FLAG;

      l_vendor_rec.jgzz_fiscal_code := n_data.num_1099;

      l_vendor_rec.VAT_REGISTRATION_NUM :=n_data.VAT_REGISTRATION_NUM;

      l_vendor_rec.ext_payee_rec.default_pmt_method  := 'EFT'; --SOR

      -- -------------

      -- Optional

   

      AP_VENDOR_PUB_PKG.Create_Vendor (p_api_version     => 1,

                                       p_init_msg_list   => FND_API.G_TRUE,

                                       x_return_status   => l_return_status,

                                       x_msg_count       => l_msg_count,

                                       x_msg_data        => l_msg_data,

                                       p_vendor_rec      => l_vendor_rec,

                                       x_vendor_id       => l_vendor_id,

                                       x_party_id        => l_party_id);


      IF l_return_status ='S' THEN

      

      UPDATE xx.xx_ap_suppliers

         SET new_vendor_id = l_vendor_id,new_party_id=l_party_id, status = 'UPDATE'

       WHERE vendor_id = n_data.vendor_id;


      COMMIT;

      

      DBMS_OUTPUT.put_line ('l_vendor_id = ' || l_vendor_id);

      DBMS_OUTPUT.put_line ('l_return_status = ' || l_return_status);

      DBMS_OUTPUT.put_line ('l_msg_count = ' || l_msg_count);

      DBMS_OUTPUT.put_line ('l_msg_data = ' || l_msg_data);

      

      END IF;

      -- fnd_msg_pub.initialize;

      


      IF (l_return_status != 'S')

      THEN

         DBMS_OUTPUT.put_line (' Error in Creating Employee Type Supplier..');


         IF (l_msg_count = 1)

         THEN

            DBMS_OUTPUT.put_line ('x_msg_data ' || l_msg_data);

         ELSIF (l_msg_count > 1)

         THEN

            LOOP

               p_count := p_count + 1;

               l_msg_data :=

                  fnd_msg_pub.get (fnd_msg_pub.g_next, fnd_api.g_false);


               IF (l_msg_data IS NULL)

               THEN

                  EXIT;

               END IF;


               DBMS_OUTPUT.put_line (

                  ' Error Message' || p_count || ' —' || l_msg_data);

            END LOOP;

         END IF;

      ELSE

         DBMS_OUTPUT.put_line ('Vendor_id:' || l_vendor_id);

      END IF;

   END LOOP;

EXCEPTION

   WHEN OTHERS

   THEN

      ROLLBACK;


      v_api_error := SQLERRM;

      v_error_msg := v_error_msg || ' ' || v_api_error;

      DBMS_OUTPUT.PUT_LINE (SQLERRM);

END;

/

No comments:

Post a Comment