Search This Blog

Monday, July 30, 2018

Oracle Apps R12 AR Invoice Transaction API for Single


With Cursor : Oracle Apps R12 AR Invoice Transaction API (With Cursor) Multiple

DECLARE
   v_customer_id             NUMBER := 8980620;
   v_service_name            VARCHAR2(200) := 'XX- Customer Name';
   v_costshare_value         NUMBER := 1000;
   v_user_id                 NUMBER := 26051;
   v_resp_id                 NUMBER := 55556;
   v_org_id                  NUMBER := 1300;
   v_date                    DATE := TO_DATE('30-JUL-2018');
   --v_trx_number        OUT   NUMBER
   v_trx_number           NUMBER;
--)AS
   l_return_status           VARCHAR2 (1);
   l_msg_count               NUMBER;
   l_msg_data                VARCHAR2 (2000);
   l_batch_id                NUMBER;
   l_batch_source_rec        ar_invoice_api_pub.batch_source_rec_type;
   l_trx_header_tbl          ar_invoice_api_pub.trx_header_tbl_type;
   l_trx_lines_tbl           ar_invoice_api_pub.trx_line_tbl_type;
   l_trx_dist_tbl            ar_invoice_api_pub.trx_dist_tbl_type;
   l_trx_salescredits_tbl    ar_invoice_api_pub.trx_salescredits_tbl_type;
   l_trx_contingencies_tbl   ar_invoice_api_pub.trx_contingencies_tbl_type;
   trx_header_id_v           NUMBER;
   trx_line_id_v             NUMBER;
   trx_dist_id_v             NUMBER;
   CURSOR cbatch
   IS
      SELECT customer_trx_id
        FROM ra_customer_trx_all
       WHERE batch_id = l_batch_id;
   CURSOR cvalidtxn
   IS
      SELECT trx_header_id
        FROM ar_trx_header_gt
       WHERE trx_header_id NOT IN (SELECT trx_header_id
                                     FROM ar_trx_errors_gt);
 

BEGIN
     SELECT xx_invoice_header.NEXTVAL
     INTO trx_header_id_v
     FROM DUAL;
   SELECT xx_invoice_line.NEXTVAL
     INTO trx_line_id_v
     FROM DUAL;
   SELECT xx_invoice_dist.NEXTVAL
     INTO trx_dist_id_v
     FROM DUAL;
   fnd_global.apps_initialize (v_user_id, v_resp_id, 222);
   mo_global.init ('AR');
   mo_global.set_policy_context ('S', v_org_id);
   xla_security_pkg.set_security_context (222);
   l_batch_source_rec.batch_source_id := 4048;
   l_trx_header_tbl (1).trx_header_id := trx_header_id_v;
   l_trx_header_tbl (1).bill_to_customer_id := v_customer_id;           --1042
   l_trx_header_tbl (1).cust_trx_type_id := 1420;
   l_trx_header_tbl (1).trx_date := v_date;   --'10-AUG-2006';--'30-MAY-2006';
   l_trx_header_tbl (1).trx_currency := 'AED';
   l_trx_header_tbl (1).term_id := 5;
   --l_trx_header_tbl (1).default_tax_exempt_flag := 'E';
   l_trx_header_tbl (1).legal_entity_id := 21178;
   l_trx_header_tbl (1).finance_charges := NULL;
   l_trx_header_tbl (1).status_trx := 'OP';
   l_trx_header_tbl (1).printing_option := 'PRI';
   --l_trx_header_tbl (1).set_of_books_id := 12345;
   --l_trx_header_tbl (1).complete_flag := 'Y';
   l_trx_lines_tbl (1).trx_header_id := trx_header_id_v;
   l_trx_lines_tbl (1).trx_line_id := trx_line_id_v;
   l_trx_lines_tbl (1).line_number := 1;
   l_trx_lines_tbl (1).description := v_service_name;
   l_trx_lines_tbl (1).quantity_invoiced := 1;
   l_trx_lines_tbl (1).unit_selling_price := v_costshare_value;
   l_trx_lines_tbl (1).line_type := 'LINE';
   --l_trx_lines_tbl (1).tax_exempt_flag := 'E';
   --l_trx_lines_tbl (1).TAX_EXEMPT_REASON_CODE := 'E';
   --l_trx_lines_tbl (1).TAX_EXEMPT_REASON_CODE_MEANING := 'E';
   l_trx_lines_tbl (1).memo_line_id := 46160;
--   l_trx_lines_tbl (1).TAX_PRECEDENCE := 10;
--   l_trx_lines_tbl (1).TAX_RATE := 10;
   l_trx_dist_tbl (1).trx_dist_id := trx_dist_id_v;
   l_trx_dist_tbl (1).trx_line_id := trx_line_id_v;
   l_trx_dist_tbl (1).account_class := 'REV';
   l_trx_dist_tbl (1).PERCENT := 100;
   l_trx_dist_tbl (1).code_combination_id := 3361155;
   ar_invoice_api_pub.create_invoice
                            (p_api_version               => 1.0,
                             p_batch_source_rec          => l_batch_source_rec,
                             p_trx_header_tbl            => l_trx_header_tbl,
                             p_trx_lines_tbl             => l_trx_lines_tbl,
                             p_trx_dist_tbl              => l_trx_dist_tbl,
                             p_trx_salescredits_tbl      => l_trx_salescredits_tbl,
                             x_return_status             => l_return_status,
                             x_msg_count                 => l_msg_count,
                             x_msg_data                  => l_msg_data
                            );
   DBMS_OUTPUT.put_line (l_return_status);
   DBMS_OUTPUT.put_line (l_msg_data);
   IF    l_return_status = fnd_api.g_ret_sts_error
      OR l_return_status = fnd_api.g_ret_sts_unexp_error
   THEN
      DBMS_OUTPUT.put_line ('unexpected errors found!');
   ELSE
      FOR cvalidtxnrec IN cvalidtxn
      LOOP
         IF (ar_invoice_api_pub.g_api_outputs.batch_id IS NOT NULL)
         THEN
            DBMS_OUTPUT.put_line ('Invoice(s) suceessfully created!');
            DBMS_OUTPUT.put_line (   'Batch ID: '
                                  || ar_invoice_api_pub.g_api_outputs.batch_id
                                 );
            l_batch_id := ar_invoice_api_pub.g_api_outputs.batch_id;
            FOR cbatchrec IN cbatch
            LOOP
               DBMS_OUTPUT.put_line (   'Cust Trx Id '
                                     || cbatchrec.customer_trx_id
                                    );
               v_trx_number := cbatchrec.customer_trx_id;
            END LOOP;
         ELSE
            DBMS_OUTPUT.put_line ('Errors found!');
         END IF;
      END LOOP;
   END IF;
END;
/

No comments:

Post a Comment