API To Create Journal Voucher in oracle

/* Formatted on 2018/04/06 16:45 (Formatter Plus v4.8.8) */
/*CREATE OR REPLACE PROCEDURE ge_pro30 (errbuf OUT VARCHAR2, retcode OUT VARCHAR2)
IS*/
   -- cursor declaration

DECLARE   CURSOR gl_cur
   IS
   
/* Formatted on 2018/04/09 16:00 (Formatter Plus v4.8.8) */
SELECT   TO_CHAR (com_det.sob) set_of_books_id,
         SUM (com_det.amount_sale) entered, com_ac.entered_dr,
         com_ac.entered_cr, com_ac.accounted_dr, com_ac.accounted_cr,
         com_det.currency, 'Adjustment' CATEGORY, 14654 created_by,
         NULL GROUP_ID, com_ac.segment1, com_ac.segment2, com_ac.segment3,
         com_ac.segment4, com_ac.segment5, com_ac.segment6, com_ac.segment7,
         com_ac.segment8, 'User' curr_conversion, 'Manual' SOURCE,
         'A' actual_flag, date_to date_created,
         Date_to accounting_date, 'NEW' status, com_ac.agent_id,
         com_hd.ac_id,
         stm_cust.cust_agent_invoice_con (com_hd.ac_id, agent_id) invoices,
         LENGTH (stm_cust.cust_agent_invoice_con (com_hd.ac_id, agent_id)) l,rsa.NAME agent
    FROM stm_cust.cust_agent_commission_hd com_hd,
         stm_cust.cust_agent_commission_dt com_det,
         stm_cust.cust_agent_create_accounting com_ac,
         apps.ra_salesreps_all rsa
   WHERE com_hd.ac_id = com_det.ac_id
     AND com_ac.ac_id = com_hd.ac_id
     and rsa.salesrep_id = com_ac.AGENT_ID
     AND com_hd.date_from = '01-SEP-2017'
     AND com_hd.date_to = '30-SEP-2017'
     AND com_hd.organization_id = 114
     AND com_ac.agent_id NOT IN (-3,'100002125')
GROUP BY TO_CHAR (com_det.sob),
         com_ac.entered_dr,
         com_ac.entered_cr,
         com_ac.accounted_dr,
         com_ac.accounted_cr,
         com_det.currency,
         com_ac.segment1,
         com_ac.segment2,
         com_ac.segment3,
         com_ac.segment4,
         com_ac.segment5,
         com_ac.segment6,
         com_ac.segment7,
         com_ac.segment8,
         agent_id,date_to,
         line_num,
         com_hd.ac_id,rsa.NAME
ORDER BY agent_id, line_num;


   l_currencycode      VARCHAR2 (25);
   l_set_of_books_id   NUMBER ;
   l_flag              VARCHAR2 (2);
   l_error_msg         VARCHAR2 (100);
   l_err_flag          VARCHAR2 (10);
   l_category          VARCHAR2 (100);
   l_userid            NUMBER (10);
   l_count             NUMBER (9)     DEFAULT 0;
BEGIN
   DELETE FROM gl_interface;

   COMMIT;

   FOR rec_cur IN gl_cur
   LOOP
      l_count := l_count + 1;
      l_flag := 'A';

--Category Column Validation
      BEGIN
         SELECT user_je_category_name
           INTO l_category
           FROM gl_je_categories
          WHERE user_je_category_name = rec_cur.CATEGORY;
      EXCEPTION
         WHEN OTHERS
         THEN
            l_flag := 'E';
            l_error_msg := 'Category does not exist ';
            fnd_file.put_line (fnd_file.LOG,
                                  'Inserting data into the Interface TABLE'
                               || '-'
                               || l_count
                               || ' '
                               || l_error_msg
                              );
                              DBMS_OUTPUT.PUT_LINE(                                  'Inserting data into the Interface TABLE'
                               || '-'
                               || l_count
                               || ' '
                               || l_error_msg
);
      END;

      --End Category Column Validation
      --User ID column validation
      BEGIN
         SELECT user_id
           INTO l_userid
           FROM fnd_user
          WHERE user_id = rec_cur.created_by;
      EXCEPTION
         WHEN OTHERS
         THEN
            l_flag := 'E';
            l_error_msg := 'User ID does not exist ';
            fnd_file.put_line (fnd_file.LOG,
                                  'Inserting data into the Interface TABLE'
                               || '-'
                               || l_count
                               || ' '
                               || l_error_msg
                              );
                              DBMS_OUTPUT.PUT_LINE(                                'Inserting data into the Interface TABLE'
                               || '-'
                               || l_count
                               || ' '
                               || l_error_msg
                              );
 
      END;

      --End of Created_by OR UserID column Validation
      --Set of  books Validation
      BEGIN
         SELECT set_of_books_id
           INTO l_set_of_books_id
           FROM gl_sets_of_books
          WHERE set_of_books_id = rec_cur.set_of_books_id;
      EXCEPTION
         WHEN OTHERS
         THEN
            l_flag := 'E';
            l_error_msg := 'set of Books ID does not exist ';
            fnd_file.put_line (fnd_file.LOG,
                                  'Inserting data into the Interface TABLE'
                               || '-'
                               || l_count
                               || ' '
                               || l_error_msg
                              );
                                                        DBMS_OUTPUT.PUT_LINE(                                'Inserting data into the Interface TABLE'
                               || '-'
                               || l_count
                               || ' '
                               || l_error_msg
                              );
 
      END;

--Cuurency Code Validation
      BEGIN
         SELECT currency_code
           INTO l_currencycode
           FROM fnd_currencies
          WHERE currency_code = rec_cur.currency ;
      EXCEPTION
         WHEN OTHERS
         THEN
            l_flag := 'E';
            l_error_msg := 'currency code does not exists';
            fnd_file.put_line (fnd_file.LOG,
                                  'Inserting data into the Interface TABLE'
                               || '-'
                               || l_count
                               || ' '
                               || l_error_msg
                              );
                                                        DBMS_OUTPUT.PUT_LINE(                                'Inserting data into the Interface TABLE'
                               || '-'
                               || l_count
                               || ' '
                               || l_error_msg
                              );
 
      END;

      IF l_flag != 'E'
      THEN
         fnd_file.put_line (fnd_file.LOG,
                            'Inserting data into the Interface TABLE'
                           );
                          DBMS_OUTPUT.PUT_LINE(                                'Inserting data into the Interface TABLE'
                             
                              );
            DBMS_OUTPUT.PUT_LINE('TEST ');
         INSERT INTO gl_interface
                     (status, set_of_books_id,ledger_id,
                      accounting_date, currency_code,
                      date_created, created_by,
                      actual_flag, user_je_category_name,
                      user_je_source_name, user_currency_conversion_type,
                      segment1, segment2, segment3,
                      segment4, segment5,segment6,Segment7,segment8, entered_dr,
                      entered_cr, accounted_dr,
                      accounted_cr, GROUP_ID,attribute3,attribute4,reference1,REFERENCE2,REFERENCE4,REFERENCE10
                     )
              VALUES (rec_cur.status, rec_cur.set_of_books_id,2002,
                      rec_cur.accounting_date, rec_cur.currency,
                      rec_cur.date_created, rec_cur.created_by,
                      rec_cur.actual_flag, rec_cur.CATEGORY,
                      rec_cur.SOURCE, rec_cur.curr_conversion,
                      rec_cur.segment1, rec_cur.segment2, rec_cur.segment3,
                      rec_cur.segment4, rec_cur.segment5,rec_cur.segment6,rec_cur.segment7,rec_cur.segment8,rec_cur.entered_dr,
                      rec_cur.entered_cr, rec_cur.accounted_dr,
                      rec_cur.accounted_cr, rec_cur.GROUP_ID,rec_cur.ac_id,rec_cur.agent_id,'ACCRUED LOCAL COMM M/Y'||TO_CHAR(TRUNC(SYSDATE),'MON-YYYY'),'ACCRUED LOCAL COMM M/Y'||TO_CHAR(TRUNC(SYSDATE),'MON-YYYY'),
                      'Accrued Local Commission M/O'||to_char(trunc(sysdate),'MON-YYYY')  ,
                        'LOCAL AGENT COMM'||to_char(trunc(sysdate),'MON-YYYY')||'('||rec_cur.agent||')'||' '||rec_cur.invoices
                     );
      END IF;
COMMIT;
      l_flag := NULL;
      l_error_msg := NULL;
   END LOOP;

   COMMIT;
END;

Comments

Popular posts from this blog

API Procedure to inactive Items in oracle apps

API To update Oracle Items

Graph Setting in Oracle Report Builder