Sunday, August 17, 2014

API to account an AP invoice in Oracle Apps R12 AP_DRILLDOWN_PUB_PKG. INVOICE_ONLINE_ACCOUNTING















In my recent project, we have a requirement to account the AP Invoices via PLSQL. 
Hence, We have used the API AP_DRILLDOWN_PUB_PKG.INVOICE_ONLINE_ACCOUNTING
Script:

  ----------------------------------------------------------------------
  -- PROCEDURE account_imported_invoices 
  -- This procedure is to create Accounting for imported invoices in AP
  ---------------------------------------------------------------------- 
  PROCEDURE account_imported_invoices(pin_invoice_id   IN  NUMBER,
                                      pov_err_message OUT VARCHAR2
                                      )  
  IS
    CURSOR cur_imp_invoices IS
    SELECT *
      FROM ap_invoices_all xlpi
     WHERE xlpi.invoice_id  = pin_invoice_id
       AND ap_invoices_pkg.get_posting_status(xlpi.invoice_id) = 'N'; 
       -- This condition is to pick invoices which are un accounted
 
    ln_processed_cnt      NUMBER DEFAULT 0;
    ln_failed_cnt         NUMBER DEFAULT 0;  
    lv_error_buf          VARCHAR2(500);
    ln_retcode            NUMBER; 
  BEGIN
 
    FOR rec_imp_inv IN cur_imp_invoices
    LOOP
      BEGIN
 
        ln_retcode   := NULL;
        lv_error_buf := NULL;
 
        ap_drilldown_pub_pkg.invoice_online_accounting 
           (
             p_invoice_id         => rec_imp_inv.invoice_id,
             p_accounting_mode    => 'F',        
             p_errbuf             => lv_error_buf,
             p_retcode            => ln_retcode,
             p_calling_sequence   => 'XXyour_package.account_imported_invoices'
           );
 
        IF ln_retcode = 0 
        THEN
          DBMS_OUTPUT.put_line(rec_imp_inv.invoice_num 
                               ||'- Invoice Accounted Sucessfully' 
                               );
          ln_processed_cnt := ln_processed_cnt+1;
        ELSIF ln_retcode = 1 THEN
          DBMS_OUTPUT.put_line(rec_imp_inv.invoice_num  
                              ||'- Invoice Accounting ended in WARNING. Errbuf : '
                              ||lv_error_buf
                              );
          ln_processed_cnt := ln_processed_cnt+1;
        ELSIF ln_retcode = 2 THEN
          DBMS_OUTPUT.put_line(rec_imp_inv.invoice_num 
                               ||'- Invoice Accounting ended in ERROR. Errbuf : '
                               ||lv_error_buf 
                              );       
          ln_failed_cnt := ln_failed_cnt +1;          
        ELSE
          DBMS_OUTPUT.put_line(rec_imp_inv.invoice_num 
                               ||'- Invoice Accounting ended in ERROR. Errbuf : '
                               ||lv_error_buf
                               ||' Retcode: ' 
                               ||ln_retcode
                              );
          ln_failed_cnt := ln_failed_cnt +1;
        END IF;                 
 
        COMMIT;
 
      EXCEPTION
        WHEN OTHERS THEN
          DBMS_OUTPUT.put_line(rec_imp_inv.invoice_num
                              ||' Invoice Validation failed with unhandled exception.Error:'
                              ||SQLERRM
                              );
          ln_failed_cnt := ln_failed_cnt + 1;
      END;
    END LOOP;
    pov_err_message := 'PROCESSED: '||ln_processed_cnt||' FAILED: '||ln_failed_cnt;
  END account_imported_invoices; 
 
 

0 Responses to “API to account an AP invoice in Oracle Apps R12 AP_DRILLDOWN_PUB_PKG. INVOICE_ONLINE_ACCOUNTING”

Post a Comment

Disclaimer

The ideas, thoughts and concepts expressed here are my own. They, in no way reflect those of my employer or any other organization/client that I am associated. The articles presented doesn't imply to any particular organization or client and are meant only for knowledge Sharing purpose. The articles can't be reproduced or copied without the Owner's knowledge or permission.