Saturday, September 6, 2014

AR API: Apply Receipt (ar_receipt_api_pub.APPLY)

DECLARE
   v_err                     VARCHAR2 (1000);
   v_trx_date                DATE;
   p_customer_number         VARCHAR2 (240);
   p_receipt_method_name     VARCHAR2 (240);
   p_receipt_number          VARCHAR2 (240);

   p_receipt_method_id       NUMBER;
   x_return_status           VARCHAR2 (1);
   x_msg_count               NUMBER;
   x_msg_data                VARCHAR2 (240);
   p_trx_number              VARCHAR2 (100);
   p_customer_trx_id         ra_customer_trx.customer_trx_id%TYPE;
   p_amount_applied          ar_receivable_applications.amount_applied%TYPE;
   p_trans_to_receipt_rate   ar_receivable_applications.trans_to_receipt_rate%TYPE;
   p_apply_date              ar_receivable_applications.apply_date%TYPE;
BEGIN
   v_trx_date := SYSDATE;
   fnd_global.apps_initialize (1695, 20678, 222);
   FOR i IN (SELECT *
               FROM xx_imported_receipts xx
              WHERE xx.receipt_created = 'Y')
   LOOP
      BEGIN
         BEGIN
            p_cash_receipt_id := i.receipt_created_err;
            p_amount_applied := i.netsett;
            p_trx_number := 26475;                                 --'10020';
            p_trans_to_receipt_rate := i.excrate;
            p_apply_date := v_trx_date;
            ar_receipt_api_pub.APPLY
                         (p_api_version                => 1.0,
                          p_init_msg_list              => fnd_api.g_true,
                          p_commit                     => fnd_api.g_true,
                          p_validation_level           => fnd_api.g_valid_level_full,
                          p_cash_receipt_id            => 17952,
                          p_trx_number                 => p_trx_number,
                          p_amount_applied             => p_amount_applied,
                          p_trans_to_receipt_rate      => p_trans_to_receipt_rate,
                          p_apply_date                 => p_apply_date,
                          x_return_status              => x_return_status,
                          x_msg_count                  => x_msg_count,
                          x_msg_data                   => x_msg_data
                         );
            IF (x_return_status = 'S')
            THEN
               DBMS_OUTPUT.put_line ('SUCCESS');
            ELSE
               DBMS_OUTPUT.put_line
                  (apps.fnd_msg_pub.get
                                      (p_msg_index      => apps.fnd_msg_pub.g_last,
                                       p_encoded        => apps.fnd_api.g_false
                                      )
                  );
            END IF;
         EXCEPTION
            WHEN OTHERS
            THEN
               DBMS_OUTPUT.put_line ('Exception :' || SQLERRM);
         /*     v_err := NULL;
              v_err := SQLERRM;
              p_receipt_number := NULL;
              p_amount := NULL;
              p_amount_applied := NULL;
              p_customer_number := NULL;
              p_currency_code := NULL;
              p_usr_currency_code := NULL;
              p_trx_number := NULL;
              p_trans_to_receipt_rate := NULL;
              p_receipt_method_name := NULL;
              p_receipt_date := NULL;
              p_gl_date := NULL;
              p_deposit_date := NULL;
              p_apply_date := NULL;
              x_return_status := NULL;
              x_msg_count := NULL;
              x_msg_data := NULL;
              p_cr_id := NULL;
              p_call_payment_processor := NULL;
              app_global_attribute_rec := NULL;*/
         END;
         EXCEPTION
         WHEN OTHERS THEN
         V_ERR := NULL;
         V_ERR := 'Invoice Not Found';
      END;
   END LOOP;
   COMMIT;
END;