Tuesday 30 April 2013

SIMPLE EXAMPLE OF AP INVOICE INTERFACE


AP Invoice Interface

AP Invoice Interface

This interface helps us to import vendor invoices into Oracle applications from external systems into Oracle Applications.

Interface tables:
1] AP_INVOICES_INTERFACE

This is the open interface table for importing AP Invoices from external sources and stores header information about invoices. Invoice data comes from sources including:

EDI invoices from suppliers that are loaded through Oracle e-Commerce Gateway
Supplier invoices that are transferred through the Oracle XML Gateway
Invoices that are loaded using Oracle SQL*Loader
Lease invoices from Oracle Property Manager
Lease payments from Oracle Assets
Credit card transaction data that are loaded using the Credit Card Invoice Interface Summary
Expense Report invoices from Oracle Internet Expenses
Payment Requests from Receivables
Invoices that are entered through the Invoice Gateway.

There is one row for each invoice you import. Oracle Payables application uses this information to create invoice header information when Payables Open Interface program is submitted.

Data in the AP_INVOICES_INTERFACE table used in conjunction with AP_INVOICE_LINES_INTERFACE table to create Payables Invoice, Invoice lines, Distributions and Schedule payments. Data in this table can be viewed and edited using ‘Open Interface Invoices’ window. The Payables Open Interface program validates each record in this interface table selected for import, and if the record contains valid data then the program creates a Payables Invoice.

Important columns:

INVOICE_ID (Required) : Unique identifier for this invoice within this batch. Same value should be populated in invoice’s lines in the AP_INVOICE_LINES_INTERFACE table to identify the data as belonging to the same invoice.

INVOICE_NUM (Required) :  Enter the invoice number that needs to be assigned to the invoice created in Payables from this record.

INVOICE_TYPE_LOOKUP_CODE (Optional) : Type of invoice: Credit or Standard.

INVOICE DATE (Optional) : Date of the invoice. If you do not enter a value, the system uses the date you submit Payables Open Interface Import as the invoice date.

PO_NUMBER (Optional)  : Purchase order number from PO_HEADERS.SEGMENT1. This column needs to be populated if invoice to be matched with an purchase order.

VENDOR_ID & VENDOR_SITE_ID (Required) : VENDOR_ID is unique identifier for a supplier and VENDOR_SITE_ID is Internal supplier site identifier. Supplier of the invoice to be derived by value in one of the following columns in this table: VENDOR_ID, VENDOR_NUM, VENDOR_NAME, VENDOR_SITE_ID or PO_NUMBER.

VENDOR_NUM & VENDOR_NAME (Optional) : Supplier number and name. You must identify the supplier by entering a value for one of the following columns in this table: VENDOR_ID, VENDOR_NUM, VENDOR_SITE_ID, VENDOR_SITE CODE, or PO_NUMBER.

INVOICE_AMOUNT (Required) : Amount of the invoice.

INVOICE_CURRENCY_CODE (Optional)  : Currency code for the invoice. If you want to create foreign currency invoices, enter a currency code that is different from your functional currency.

EXCHANGE_RATE (Optional) :  This column is required if you enter a foreign currency code in the INVOICE_CURRENCY_CODE column and you enter User as the EXCHANGE_RATE_TYPE.

TERMS_ID (Optional) : Internal identifier for the payment terms.

DESCRIPTION (Optional) : Enter the description that you want to assign to the invoice created from this record.

SOURCE (Required) : Source of the invoice data. If you import EDI invoices from the Oracle EDI Gateway, the source is EDI Gateway. For invoices you import using SQL*Loader, use a QuickCode with the type Source that you have defined in the QuickCodes window in Payables.

2] AP_INVOICE_LINES_INTERFACE

This is the lines interface table for the AP Invoice Open Interface and it is used in conjunction with AP_INVOICE_INTERFACE table. AP_INVOICE_LINES_INTERFACE stores information used to create one or more invoice distributions. Note that one row in this table may create, during the import process, more than one invoice distribution.

Important columns:

INVOICE_ID (Required) :Enter the INVOICE_ID of the corresponding invoice in the AP_INVOICES_INTERFACE table.

INVOICE_LINE_ID : This value is not required. You can enter a unique number for each invoice line of an invoice.

LINE_NUMBER (Optional) : You can enter a unique number to identify the line.

LINE_TYPE_LOOKUP_CODE (Required) : Enter the lookup code for the type of invoice distribution that you want Payables Open Interface Import to create from this record. The code you enter must be ITEM, TAX, MISCELLANEOUS, or FREIGHT. These lookup codes are stored in the AP_LOOKUP_CODES table.

AMOUNT (Required) : The invoice distribution amount. If you are matching to a purchase order, the AMOUNT = QUANTITY_INVOICED x UNIT PRICE. If the total amount of all the invoice distributions does not equal the amount of the invoice that has the same INVOICE_ID, then Payables Open Interface Import will reject the invoice.

Concurrent program:

Payables Open Interface Import

Parameters:
Source: Choose the source of the invoices from the list of values. Use EDI Gateway, Credit Card, or a Source type QuickCode you defined in the Payables QuickCodes window.

Group: To limit the import to invoices with a particular Group ID, enter the Group ID. The Group must exactly match the GROUP_ID in the Payables Open Interface tables.

Batch Name: Payables groups the invoices created from the invoices you import and creates an invoice batch with the batch name you enter. You can enter a batch name only if you have enabled the Use Batch Control Payables option, and if you have enabled the Use Batch Control Payables option, you must enter a batch name. If you use a batch name and some invoices are rejected during the import process, you can import the corrected invoices into the same batch if you enter the exact batch name during the subsequent import.

Hold Name: If you want to place all invoices on hold at the time of import, enter an Invoice Hold Reason. You can define your own hold reasons in the Invoice Approvals window.

Hold Reason: Payables displays the Invoice Hold Reason Description.

GL Date: If you want to assign a specific GL Date to all invoices, enter a GL Date. If you do not enter a value here, the system will assign a GL Date based on the GL Date Payables option.

Purge: Enter Yes if you want Payables to delete all successfully imported invoice records that match the Source and Group ID of this import. Payables does not delete any invoice data for which it has not yet created invoices. If you want to purge later, you can use the Payables Open Interface Purge Program.

Steps:
1] Firstly, let’s get a unique number to be used as INVOICE_ID to the invoice to be imported.  This method ensures that each invoice has a unique INVOICE_ID assignment.


                                                                   
                                                                   
                                                                   
select ap_invoices_interface_s.nextval from dual;
NEXTVAL
-------------
132277
2] Then, create records in the Invoice Open Interface tables through SQL queries.
                                           
insert into AP_INVOICES_INTERFACE (
            invoice_id,
            invoice_num,
            vendor_id,
            vendor_site_id,
            invoice_amount,
            INVOICE_CURRENCY_CODE,
            invoice_date,
            invoice_type_lookup_code,
            DESCRIPTION,      
            source,
            org_id,
            GL_date,
            terms_id        
                )
values (
            2288736,
            'INVSD0001',
            '7',
            '10',
            1200,
            'USD',
            sysdate,
            'STANDARD',
            'This Invoice is created for test purpose',        
            'MANUAL INVOICE ENTRY',
            204,
            '30-APR-2013',
            10002        
);

insert into AP_INVOICE_LINES_INTERFACE (
            invoice_id,
            invoice_line_id,
            line_number,
            line_type_lookup_code,
            amount
            )
values     (
            2288736,
            2288737,
            1,
            'ITEM',
            1200);



3] You can go to Payables > Invoices > Entry > Open Interface Invoices to check the details of Invoice and Invoice Lines from the front end. If required you can do any modifications here. Alternatively you can use these forms to put invoice data in AP_INVOICES_INTERFACE and AP_INVOICE_LINES_INTERFACE tables.

4] Go to the front end and run the concurrent program “Payables Open Interface Import”  to submit a request for Invoice Import.


out put:




5] The imported invoice becomes available for review in Invoices Workbench.






Monday 29 April 2013

AP INVOICE INTERFACE PROCEDURE


AP INVOICE INTERFACE PROCEDURE

AP_INVOICES_INTERFACE
-----------------------

1)INVOICE_ID not null Required, Primary key. This value is assigned in
the Invoice Gateway by the AP_INVOICES_INTERFACE_S sequence.

2) INVOICE_NUM Required if there is more than one invoice for the
supplier during import

3)VENDOR_ID or VENDOR_NAME or VENDOR_NUM  is reqd if not matched to PO

4)VENDOR_SITE_ID or VENDOR_SITE_CODE is reqd if not matched to PO

5)INVOICE_AMOUNT

6)PO_NUMBER

6)INVOICE_CURRENCY_CODE:if not eneterd defaulted to functional currency

7)EXCHANGE_RATE_TYPE :User,Spot, Corporate, EMU Fixed, and user–defined.for Spot, Corporate, or any user–defined rate type, the value you enter here is validated against
the GL Daily Rates table.If you use EMU Fixed,Payables will provide the exchange rate during import. If you use User as the exchange rate type,you must enter a value for EXCHANGE_RATE orthe record will be rejected during import.

8)TERMS_NAME or TERMS_ID.:Payables searches1)invoice record header 2)purchase order terms if invoice is matched to PO 3)supplier site.

9)SOURCE
10)DOC_CATEGORY_CODE  :
If you are using automatic sequential numbering, then Payables Open
Interface Import uses this column to assign a document category to the
invoice it creates.If the Sequential Numbering profile value is ”Always” and you do not
enter a value in this column, then during import Payables will use STANDARD as the category if the invoice amount is zero or positive,and CREDIT if the invoice amount is negative.
If you enable the Allow Document Category Override Payables option,you can enter the document category you want Open Interface Import to assign to the invoice created from this record

10)VOUCHER_NUM:If you use manual sequential numbering, then enter a unique value

11)PAYMENT_CURRENCY_CODE:Currency code for the payment. If you do not provide a value, then
during import PAYMENT_CURRENCY_CODE will be set to the same value as the INVOICE_CURRENCY_CODE,

12)PAYMENT_METHOD_LOOKUP_CODE:Method that will be used to pay the invoice.
The value must be a valid value for the PAYMENT_METHOD lookup code: Validation:

13)ACCTS_PAY_CODE_COMBINATION_ID:Liability account.
14)ORG_ID

AP_INVOICE_LINES_INTERFACE
----------------------------

1)INVOICE_ID :required
2)INVOICE_LINE_ID :not reqd,use AP_INVOICE_LINES_INTERFACE_S
3)LINE_NUMBER:unique ,reqd
4)LINE_TYPE_LOOKUP_CODE:valid values ITEM, TAX,MISCELLANEOUS, or FREIGHT.
5)AMOUNT :Invoice distribution amount
6)ACCOUNTING_DATE:The GL Date for the invoice distributions. The date must be in an open
or future period.
7)PO_HEADER_ID or PO_NUMBER
8)PO_LINE_ID or PO_LINE_NUMBER
9)dist_code_combination_id or DIST_CODE_CONCATENATED
10)ORG_ID



Document Category Assignment and Document Sequence Setup:
from fnd_doc_sequence_assignment,fnd_document_sequences

Now create both headers and line in one package:

Create or Replace Procedure  m_ap_invoices(ERRBUF out VARCHAR2, RETCODE out VARCHAR2)
IS
--starts the declaring variables for headers
v_invoice_id ap_invoices_interface.INVOICE_ID%TYPE ;
v_type ap_invoices_interface.INVOICE_TYPE_LOOKUP_CODE %TYPE ;
v_supplier ap_invoices_interface.VENDOR_NAME %TYPE ;
v_invoice_date ap_invoices_interface.INVOICE_DATE %TYPE;
v_invoice_num ap_invoices_interface.INVOICE_NUM %TYPE;
v_invoice_curr ap_invoices_interface.INVOICE_CURRENCY_CODE%TYPE;
v_invoice_amount ap_invoices_interface.INVOICE_AMOUNT %TYPE;
v_payment_cross_rate ap_invoices_interface.PAYMENT_CROSS_RATE%TYPE;
v_cross_payment_curr ap_invoices_interface.PAYMENT_CURRENCY_CODE%TYPE;
v_pay_rate_date ap_invoices_interface.PAYMENT_CROSS_RATE_DATE%TYPE;
v_payment_rate_type ap_invoices_interface.PAYMENT_CROSS_RATE_TYPE%TYPE;
v_description ap_invoices_interface.DESCRIPTION%TYPE;
v_rate_type ap_invoices_interface.EXCHANGE_RATE_TYPE%TYPE;
v_exchange_date ap_invoices_interface.EXCHANGE_DATE%TYPE;
v_exchange_rate ap_invoices_interface.EXCHANGE_RATE%TYPE;
v_terms_date ap_invoices_interface.TERMS_DATE%TYPE;
v_terms ap_invoices_interface.TERMS_ID%TYPE;
v_payment_method ap_invoices_interface.PAYMENT_METHOD_LOOKUP_CODE%TYPE;
v_discountable_amt ap_invoices_interface.AMOUNT_APPLICABLE_TO_DISCOUNT%TYPE;
v_invoice_recieved_date ap_invoices_interface.INVOICE_RECEIVED_DATE%TYPE;
v_recieved_goods_date ap_invoices_interface.GOODS_RECEIVED_DATE%TYPE;
v_pay_code_combination_id ap_invoices_interface.ACCTS_PAY_CODE_COMBINATION_ID%TYPE;
v_status ap_invoices_interface.STATUS%TYPE;
v_po_number ap_invoices_interface.PO_NUMBER%TYPE := NULL;
v_attribute1             ap_invoices_interface.attribute1%TYPE;
v_attribute2 ap_invoices_interface.attribute2%TYPE;
v_attribute3 ap_invoices_interface.attribute3%TYPE;
v_attribute4 ap_invoices_interface.attribute4%TYPE;
v_attribute5 ap_invoices_interface.attribute5%TYPE;
v_attribute6 ap_invoices_interface.attribute6%TYPE;
v_attribute7 ap_invoices_interface.attribute7%TYPE;
v_attribute8 ap_invoices_interface.attribute8%TYPE;
v_attribute9 ap_invoices_interface.attribute9%TYPE;
v_attribute10 ap_invoices_interface.attribute10%TYPE;
v_vendor_id po_vendors.vendor_id%TYPE;
v_vendor_site_cd po_vendor_sites.vendor_site_code%TYPE;
v_vendor_site_id po_vendor_sites.vendor_site_id%TYPE;
v_currency_code fnd_currencies.currency_code%TYPE;
v_lookup_code ap_lookup_codes.lookup_code%TYPE;
v_code_comb gl_code_combinations.code_combination_id%TYPE;
v_segment1 po_headers_all.segment1%TYPE;
v_term_name ap_terms.name%TYPE;
v_term_id ap_terms.term_id%TYPE;
v_closed_date            po_headers_all.closed_date%type;
v_process_flag char(1) := NULL;
v_last_date DATE;
v_count number;
--ends the declaring variables for headers
--statrts the declaring variables for lines
 --v_invoice_id ap_invoice_lines_interface.invoice_id%type;
 v_line_no ap_invoice_lines_interface.line_number%type;
 v_amount        ap_invoice_lines_interface.amount%type;
 v_expence_account ap_invoice_lines_interface.dist_code_combination_id%type;
 v_expence_Account1      ap_invoice_lines_interface.dist_code_concatenated%type;
 v_line_type ap_invoice_lines_interface.line_type_lookup_code%type;
 v_accounting_date ap_invoice_lines_interface.accounting_date%type;
 v_invoice_line_id ap_invoice_lines_interface.invoice_line_id%type;
 v_line_attribute1             ap_invoice_lines_interface.attribute1%TYPE;
 v_line_attribute2 ap_invoice_lines_interface.attribute2%TYPE;
 v_line_attribute3 ap_invoice_lines_interface.attribute3%TYPE;
 v_line_attribute4 ap_invoice_lines_interface.attribute4%TYPE;
 v_line_attribute5 ap_invoice_lines_interface.attribute5%TYPE;
 v_line_attribute6 ap_invoice_lines_interface.attribute6%TYPE;
 v_line_attribute7 ap_invoice_lines_interface.attribute7%TYPE;
 v_line_attribute8 ap_invoice_lines_interface.attribute8%TYPE;
 v_line_attribute9 ap_invoice_lines_interface.attribute9%TYPE;
 v_line_attribute10 ap_invoice_lines_interface.attribute10%TYPE;
 v_receipt_number ap_invoice_lines_interface.receipt_number%TYPE;
/*following variables for PO related invoices*/
 v_found  char(1) := NULL;
 v_po_header_id ap_invoice_lines_interface.po_header_id%TYPE;
 v_po_line_id ap_invoice_lines_interface.po_line_id%TYPE;
 v_po_line_num ap_invoice_lines_interface.po_line_number%TYPE;
 v_po_segment ap_invoice_lines_interface.po_number%TYPE;
 v_line_location_id ap_invoice_lines_interface.po_line_location_id%TYPE;
 v_shipment_num ap_invoice_lines_interface.po_shipment_num%TYPE;
 v_po_distribution_id ap_invoice_lines_interface.po_distribution_id%TYPE;
 v_po_distribution_num ap_invoice_lines_interface.po_distribution_num%TYPE;
--ends the declaring variables for lines
--declaring cursor for fetching header,Lines values from staging table.
  CURSOR invoice_cur
  IS
  SELECT INVH.REC_ID,
INVH.TYPE,
   INVH.SUPPLIER,
   INVH.SITE,
   INVH.INVOICE_DATE ,
   INVH.INVOICE_NUM INVOICE_NUM,
   INVH.INVOICE_CURR,
  INVH.INVOICE_AMOUNT,
   INVH.AMOUNT_PAID,
   INVH.PAYMENT_CROSS_RATE,
   INVH.PAYMENT_CROSS_CURR,
   INVH.PAY_RATE_DATE,
   INVH.PAYMENT_RATE_TYPE,
   INVH.PAYMENT_RATE,
   INVH.PAYMENT_AMT,
   INVH.DESCRIPTION,    
   INVH.TRANCTION_CODE ,        
   INVH.RATE_TYPE,            
   INVH.EXCHANGE_DATE,            
   INVH.EXCHANGE_RATE,                
   INVH.FUNCTIONAL_AMOUNT,          
   INVH.TERMS_DATE,                
   INVH.TERMS,                        
   INVH.PAYMENT_METHOD,              
   INVH.DISCOUNTABLE_AMT,            
   INVH.INVOICE_RECIEVED_DATE,        
   INVH.RECIEVED_GOODS_DATE,          
   INVH.ACCTS_PAY_CODE_COMBINATION_ID,
   INVH.STATUS,                      
   INVH.PO_NUMBER,                    
   INVH.ATTRIBUTE1 HEADATTR1,                  
   INVH.ATTRIBUTE2 HEADATTR2,                  
   INVH.ATTRIBUTE3 HEADATTR3,                  
   INVH.ATTRIBUTE4 HEADATTR4,                  
   INVH.ATTRIBUTE5 HEADATTR5,                  
   INVH.ATTRIBUTE6 HEADATTR6,                  
   INVH.ATTRIBUTE7 HEADATTR7,                  
   INVH.ATTRIBUTE8 HEADATTR8,                  
   INVH.ATTRIBUTE9 HEADATTR9,                  
   INVH.ATTRIBUTE10 HEADATTR10,                  
   INVH.PROCESS_FLAG,                
INVL.INVOICE_NUM LINE_INVOICE_NUM,
   INVL.LINE_NO,
   INVL.AMOUNT,
   INVL.EXPENCE_ACCOUNT,
   INVL.EXPENCE_ACCOUNT1,
   INVL.ACCOUNTING_DATE,
   INVL.ATTRIBUTE1 LINEATTR1,
   INVL.ATTRIBUTE2 LINEATTR2,
   INVL.ATTRIBUTE3 LINEATTR3,
   INVL.ATTRIBUTE4 LINEATTR4,
   INVL.ATTRIBUTE5 LINEATTR5,
   INVL.ATTRIBUTE6 LINEATTR6,
   INVL.ATTRIBUTE7 LINEATTR7,
   INVL.ATTRIBUTE8 LINEATTR8,
   INVL.ATTRIBUTE9 LINEATTR9,
   INVL.ATTRIBUTE10  LINEATTR10
  FROM M_INVOICE_HEADERS_INT INVH, M_INVOICE_LINES_INT INVL
  WHERE INVH.REC_ID = INVL.REC_ID;
BEGIN
  FOR cur_invoice  IN invoice_cur
  LOOP
  begin
--Loop starts here to process invoice headers data
 --fetching sequence value for invoice_id
   SELECT ap_invoices_interface_s.nextval INTO v_invoice_id FROM dual;
     v_type := cur_invoice.type ;
     v_supplier := cur_invoice.supplier;
     v_invoice_date             := cur_invoice.invoice_date;
     v_invoice_num              :=  cur_invoice.invoice_num;
     v_invoice_curr             := cur_invoice.invoice_curr;
     v_invoice_amount           := cur_invoice.invoice_amount;
     v_payment_cross_rate       := cur_invoice.payment_cross_rate;
     v_cross_payment_curr       := cur_invoice.payment_cross_curr;
     v_pay_rate_date            := cur_invoice.pay_rate_date;
     v_payment_rate_type        := cur_invoice.payment_rate_type;
     v_description              := cur_invoice.description;
     v_rate_type := cur_invoice.rate_type;
     v_exchange_date := cur_invoice.exchange_date;
     v_exchange_rate := cur_invoice.exchange_rate;
     v_terms_date := cur_invoice.terms_date;
     v_terms := cur_invoice.terms;
     v_payment_method := cur_invoice.payment_method;
     v_discountable_amt         := cur_invoice.discountable_amt;
     v_invoice_recieved_date    := cur_invoice.invoice_recieved_date;
     v_recieved_goods_date      := cur_invoice.recieved_goods_date;
     v_pay_code_combination_id := cur_invoice.accts_pay_code_combination_id;
     v_status := cur_invoice.status;
     v_po_number := cur_invoice.po_number;
     v_attribute1               := cur_invoice.HEADATTR1;
     v_attribute2 := cur_invoice.HEADATTR2;
     v_attribute3 := cur_invoice.HEADATTR3;
     v_attribute4 := cur_invoice.HEADATTR4;
     v_attribute5 := cur_invoice.HEADATTR5;
     v_attribute6 := cur_invoice.HEADATTR6;
     v_attribute7 := cur_invoice.HEADATTR7;
     v_attribute8 := cur_invoice.HEADATTR8;
     v_attribute9 := cur_invoice.HEADATTR9;
     v_attribute10 := cur_invoice.HEADATTR10;
     v_process_flag := cur_invoice.process_flag;
/* Validate  invoice  number  if null then assign invoice number equal to week_end_date.*/
IF v_invoice_num is  null THEN
   SELECT    NEXT_DAY(SYSDATE,'FRIDAY')
   INTO V_LAST_DATE
   FROM DUAL;
v_invoice_num := v_last_date;
END IF;
/* validate invoice type*/
IF v_type<>'STANDARD' OR v_type <>'CREDIT' OR v_type <>'DEBIT'  THEN
  V_TYPE :=NULL ;
END IF;
/* validating vendor id */
    BEGIN
     select VENDOR_ID
     into v_vendor_id
  from PO_VENDORS
  where vendor_name = ltrim(rtrim(upper(v_supplier)))
  and         sysdate >= start_date_active
  AND      sysdate <   end_date_active;
    EXCEPTION
      WHEN NO_DATA_FOUND THEN
        FND_FILE.PUT_LINE(FND_FILE.LOG,'No vendor id found OR vendor status is not active  = ');
      WHEN OTHERS THEN
FND_FILE.PUT_LINE(FND_FILE.LOG,'Exception'||SQLERRM);
    END;
/* Validation for VENDOR_SITE_CODE */
BEGIN
select vendor_site_code, vendor_site_id  into v_vendor_site_cd,v_vendor_site_id from PO_VENDOR_SITES where VENDOR_ID = v_vendor_id;
EXCEPTION
      WHEN NO_DATA_FOUND THEN
        FND_FILE.PUT_LINE(FND_FILE.LOG,'No vendor site code  found for this vendor - '||v_supplier);
      WHEN OTHERS THEN
FND_FILE.PUT_LINE(FND_FILE.LOG,'Exception'||SQLERRM);
END;
/* Invoice currecy code  */
BEGIN
  SELECT  currency_code
  INTO  v_currency_code
  FROM FND_CURRENCIES
  WHERE currency_code =  ltrim(rtrim(upper(v_invoice_curr)))
  and sysdate between nvl(start_date_Active,sysdate) and  nvl(end_date_active,sysdate);
EXCEPTION
      WHEN NO_DATA_FOUND THEN
          FND_FILE.PUT_LINE(FND_FILE.LOG,'Currency Code Does not Exist for '||v_invoice_curr);
      WHEN OTHERS THEN
FND_FILE.PUT_LINE(FND_FILE.LOG,'Exception'||SQLERRM);
END;
/* validating term id */
BEGIN
SELECT TERM_ID ,NAME
INTO V_TERM_ID ,V_TERM_NAME
FROM AP_TERMS
WHERE TERM_ID = v_terms
and    v_terms_date  between nvl(start_date_Active,sysdate) and nvl(end_date_active,sysdate);  -- v_term_date not in ver 11.5.0
EXCEPTION
      WHEN NO_DATA_FOUND THEN
         FND_FILE.PUT_LINE(FND_FILE.LOG,'Term id  OR Term name Does not Exist for '||v_terms);
      WHEN OTHERS THEN
FND_FILE.PUT_LINE(FND_FILE.LOG,'Exception'||SQLERRM);
END;
/*validating payment method */
BEGIN
SELECT  lookup_code
INTO  v_lookup_code
FROM ap_lookup_codes
WHERE  lookup_code =upper(v_payment_method) ;
EXCEPTION
      WHEN NO_DATA_FOUND THEN
         FND_FILE.PUT_LINE(FND_FILE.LOG,' Payment Method are not exist
in lookup table');
      WHEN OTHERS THEN
FND_FILE.PUT_LINE(FND_FILE.LOG,'Exception'||SQLERRM);
END;
/* validating GL Code Combination validation  */
BEGIN
SELECT code_combination_id
INTO v_code_comb
FROM gl_code_combinations
WHERE code_combination_id = v_pay_code_combination_id ;
EXCEPTION
      WHEN NO_DATA_FOUND THEN
         FND_FILE.PUT_LINE(FND_FILE.LOG,' Code Combination id not exist in table');
      WHEN OTHERS THEN
FND_FILE.PUT_LINE(FND_FILE.LOG,'Exception'||SQLERRM);
END;
/* validating po number  */
BEGIN
IF v_po_number is not null  THEN
SELECT  segment1 , closed_date
INTO v_segment1 , v_closed_date
FROM po_headers_all
WHERE  segment1 = v_po_number;
IF v_closed_date is not null  THEN
  FND_FILE.PUT_LINE(FND_FILE.LOG,' P O Staus is inactive');
    END IF;
END IF;
EXCEPTION
      WHEN NO_DATA_FOUND THEN
          FND_FILE.PUT_LINE(FND_FILE.LOG,' P O number not found');
       WHEN OTHERS THEN
 FND_FILE.PUT_LINE(FND_FILE.LOG,'Exception'||SQLERRM);
END;
/*Validating Payment cross rate  */
BEGIN
IF  v_invoice_curr = v_cross_payment_curr THEN
    v_payment_cross_rate := 1;
ELSE
SELECT  conversion_rate
INTO v_payment_cross_rate  --v_conversion_rate
FROM gl_daily_rates
WHERE from_currency = v_invoice_curr
and  to_currency=v_cross_payment_curr
and conversion_date= v_pay_rate_date
and conversion_type=v_payment_rate_type;
END IF;
EXCEPTION
      WHEN NO_DATA_FOUND THEN
         FND_FILE.PUT_LINE(FND_FILE.LOG,' Conversion rates not found');
      WHEN OTHERS THEN
FND_FILE.PUT_LINE(FND_FILE.LOG,'Exception'||SQLERRM);
END;
/* validating exchange rate */
IF v_rate_type = 'USER'  and  v_exchange_rate is not null THEN
NULL;
ELSIF  v_rate_type = 'USER'  and  v_exchange_rate is  null THEN
    FND_FILE.PUT_LINE(FND_FILE.LOG,' Exchange rate is  null for the invoice number  -'||v_invoice_num);
ELSIF  v_rate_type <> 'USER'  and  v_exchange_rate is  not null THEN
v_exchange_rate :=0 ;
END IF;
/* validating duplication of invoice */
SELECT COUNT(*)
INTO v_count
FROM AP_INVOICES_ALL
WHERE  INVOICE_NUM = V_INVOICE_NUM
AND VENDOR_ID     = v_vendor_id;
IF  v_count > 0  THEN
   FND_FILE.PUT_LINE(FND_FILE.LOG,' Invocie already Exists - '||v_invoice_num);
   UPDATE M_INVOICE_HEADERS_INT
   SET process_flag ='N'
   WHERE  invoice_num = v_invoice_num
   and  supplier = v_supplier;
Else
--inserting validated values to interface table(headers)
INSERT INTO ap_invoices_interface (
invoice_id,
invoice_num,
invoice_type_lookup_code,
invoice_date,
po_number,
vendor_id,
vendor_name,
vendor_site_id,
vendor_site_code,
invoice_amount,
invoice_currency_code,
exchange_rate,
exchange_rate_type,
exchange_date,
terms_id,
terms_name,
terms_date ,
description,
status,
source,
  payment_cross_rate_type,
payment_cross_rate_date,
payment_cross_rate,
payment_currency_code,
payment_method_lookup_code,
goods_received_date,
invoice_received_date,
gl_date,
accts_pay_code_combination_id,
amount_applicable_to_discount,
attribute1,
attribute2,
attribute3,
attribute4,
attribute5,
attribute6,
attribute7,
attribute8,
attribute9,
attribute10,
creation_date,
created_by,
last_update_date,
last_updated_by
)
VALUES
(
v_invoice_id,
v_invoice_num,
v_type,
v_invoice_date,
v_po_number,
v_vendor_id,
v_supplier,
v_vendor_site_id,
v_vendor_site_cd,
       nvl(v_invoice_amount,0),
        v_invoice_curr,
      v_exchange_rate,
     v_rate_type,
     v_exchange_date,
     v_terms,
     v_term_name,
v_terms_date,
    v_description,
    v_status,
        'InvoiceGateway',
        v_payment_rate_type,
        v_pay_rate_date,
        v_payment_cross_rate,
        v_cross_payment_curr,
        v_payment_method,
        v_recieved_goods_date,
        v_invoice_recieved_date,
'30-NOV-2003',
v_pay_code_combination_id,
        v_discountable_amt,
v_attribute1,
    v_attribute2,
v_attribute3,
v_attribute4,
v_attribute5,
v_attribute6,
v_attribute7,
v_attribute8,
v_attribute9,
v_attribute10,
sysdate,
        FND_GLOBAL.user_id,
        sysdate,
FND_GLOBAL.user_id
);
 --starts here to process invoice lines data
   --fetching sequence value for invoice_line_id
select ap_invoice_lines_interface_s.nextval into v_invoice_line_id from dual;
--assigning values from staging table(lines)
   --v_invoice_num                      :=cur_invoice.invoice_num;      
   v_line_no                          :=cur_invoice.line_no;                
   v_amount                           :=cur_invoice.amount;                  
   v_expence_account                  :=cur_invoice.expence_account;                
   v_expence_account1                 :=cur_invoice.expence_account1;                    
   v_accounting_date    :=cur_invoice.accounting_date;
   v_line_type    :='Item';--(Item, Fright,Tax,Miscellaneous)
v_line_attribute1  :=cur_invoice.LINEATTR1;
v_line_attribute2  :=cur_invoice.LINEATTR2;
v_line_attribute3  :=cur_invoice.LINEATTR3;
v_line_attribute4  :=cur_invoice.LINEATTR4;
v_line_attribute5  :=cur_invoice.LINEATTR5;
v_line_attribute6  :=cur_invoice.LINEATTR6;
v_line_attribute7  :=cur_invoice.LINEATTR7;
v_line_attribute8  :=cur_invoice.LINEATTR8;
v_line_attribute9  :=cur_invoice.LINEATTR9;
v_line_attribute10  :=cur_invoice.LINEATTR10;
-- Validate Line Level Accounting Date
BEGIN
        SELECT 'Y'
        INTO   v_found
        FROM   gl_period_statuses
        WHERE  application_id  = 200--ASSUMTION
        AND    set_of_books_id = 3--ASSUMTION
        AND    SYSDATE between start_date AND end_date
        AND    closing_status IN ('O', 'F')
AND    NVL(adjustment_period_flag, 'N') = 'N'
        AND    ROWNUM = 1;
EXCEPTION
   WHEN NO_DATA_FOUND THEN
             FND_FILE.PUT_LINE(FND_FILE.log,'Accounting Date Is Not In Open');
    END;
/*------start to Validate Line Level for po_number matching/validating----------*/
-- get the info of header (if invoice is related to  po_number)
BEGIN
Select po_header_id,segment1
into v_po_header_id, v_po_segment
From po_headers_all
where Vendor_ID = vendor_id;
EXCEPTION
   WHEN NO_DATA_FOUND THEN
             FND_FILE.PUT_LINE(FND_FILE.log,'PO not found in Headers');
    END;
-- get the info line(if invoice is related to po_number)
BEGIN
Select po_line_id,line_num
into v_po_line_id, v_po_line_num
From po_lines_all
where
Po_Header_ID = v_po_header_id;
EXCEPTION
   WHEN NO_DATA_FOUND THEN
             FND_FILE.PUT_LINE(FND_FILE.log,'PO not found in Lines');
    END;
-- get the info location (if invoice is related to po_number)
BEGIN
Select line_location_id,shipment_num
into v_line_location_id, v_shipment_num
From po_line_locations_all
where
Po_Header_ID = v_po_header_id
and
Po_Line_ID = v_po_line_id;
EXCEPTION
   WHEN NO_DATA_FOUND THEN
             FND_FILE.PUT_LINE(FND_FILE.log,'PO not found in Locations');
    END;
-- get the info of distributions(if invoice is related to po_number)
BEGIN
Select po_distribution_id,distribution_num
into v_po_distribution_id, v_po_distribution_num
From po_distributions_all
where
Po_Header_ID = v_po_header_id
and
Po_Line_ID = v_po_line_id
and
Line_Location_ID = v_line_location_id;
EXCEPTION
   WHEN NO_DATA_FOUND THEN
             FND_FILE.PUT_LINE(FND_FILE.log,'PO not found in distributionss');
    END;
/*------end to Validate Line Level for po_number matching/validating----------*/
/*start to inserting invoice line*/
INSERT INTO ap_invoice_lines_interface (
invoice_id,
invoice_line_id,
line_number,
line_type_lookup_code,
amount,
accounting_date,
dist_code_concatenated,
dist_code_combination_id,
po_header_id,
po_number,
po_line_id,
po_line_number,
po_line_location_id,
po_shipment_num,
po_distribution_id,
po_distribution_num,
receipt_number,
attribute1,
attribute2,
attribute3,
attribute4,
attribute5,
attribute6,
attribute7,
attribute8,
attribute9,
attribute10,
creation_date,
created_by,
last_update_date,
last_updated_by
)
  VALUES(v_invoice_id,
                 v_invoice_line_id,
                 v_line_no,
 v_line_type,
 v_amount,
                 v_accounting_date,
 v_expence_account1,
 v_expence_account,
 v_po_header_id,
                 v_po_segment,
 v_po_line_id,
 v_po_line_num,
 v_line_location_id,
 v_shipment_num,
 v_po_distribution_id,
 v_po_distribution_num,
 v_receipt_number,
 v_line_attribute1,
     v_line_attribute2,
 v_line_attribute3,
 v_line_attribute4,
 v_line_attribute5,
 v_line_attribute6,
 v_line_attribute7,
 v_line_attribute8,
 v_line_attribute9,
 v_line_attribute10,
 sysdate,
          FND_GLOBAL.user_id,
          sysdate,
 FND_GLOBAL.user_id
);
/*end to inserting invoice line*/              
-- ends here to process invoice lines data
END IF;
EXCEPTION
     WHEN NO_DATA_FOUND THEN
        commit;
        exit;
     WHEN OTHERS THEN
FND_FILE.PUT_LINE(FND_FILE.LOG,'Exception'||SQLERRM);
rollback;
exit;
  end;
  END LOOP;--Loop ends here to process invoice headers data
--FND_FILE.PUT_LINE(FND_FILE.log,'Data Transfer is Successfull');
END;    
/

If this notes is useful for any one please submit your comments
thank you

Monday 22 April 2013

Displaying Header information in each of the Page in BI Publisher


Displaying Header information in each of the Page in BI Publisher

Last week, i had issue where I wanted to display the Header column information in all the pages in BI publisher. The output was displaying the header information only in first page and not in all the pages.



I found an interesting solution for this from one of post in net.

I am just repeating the same here.

Step1 : This is the RTF which i was used :



Step 2 : Select the first two rows (header columns to be displayed in multiple pages)


Step 3 : Right click


Step 4 : Select Table properties and select Row Tab. In options select the second checkbox : "Repeat as Header row at the top of each page"

Step 5 : Click OK and Save the RTF File.

That's it. I could achieve my required functionality. Output displayed header information in all the pages.

Hope this helps..

This is the URL, where i got the solution  : Site URL.

Tons of thanks for the author.

Sample example for DataLoad - Part 1&2&3


Sample example for DataLoad - Part 1

Before, I provide sample example for DataLoad, would like to provide some background information on this Tool.

DataLoad

This is one of the very useful tool for end users/technical developers used across Oracle Ebusiness Suite for entering large number of records.Say for example, If you want to enter 1000's of records into Sales Order screen, then using the DataLoad tool will be much faster and quicker. The tool provides other functionality too. Please refer the DataLoad which provides more information. Free version of the tool is available at the site.

Here is a sample example/script with the minimum functionality for DataLoad to load data into Sales Order Screen in Oracle EBS application.

                     Source: Order Items Data in Excel Sheet

                     Destination: Oracle EBS application

Steps to prepare the DataLoader file : Order_Lines_Load.dld 

1. Launch the DataLoad Tool.



2. Enter the Following :
      a) Window : Oracle Applications
      b) Command Group : EBS - R12
      c)  Notes : Load Order Line Information into Sales Order Form in Oracle EBIS


 3. Click the Data Tab, select the first column in the tab and double click.


4. In the Column Titles -> Main Load section, enter the desired column titles.


5. Click on Save & Close button.

6. Enter the Sample Data in the file.


 Note  :
        TAB indicates after entering the item number, simulate the Tab out functionlity
        *DN indicates Down arrow and simulating the script to move to the next record
        *SL(1) indicates wait for 1 second

7. Save the file with the extension : Order_Lines_Load.dld.

Thats it, your sample script is ready.
My next post on the same, will show you how to load the entire data from the Excel spreadsheet into Order_Lines_Load.dld file and Load the data into Oracle EBS application.







Sample example for DataLoad - Part 2

In my last previous post, we have successfully created a DataLoader script file. This post will resume loading data from that script to the actual destination ie. Oracle Applications.



Here are the steps :

1. Open the Excel Spreadsheet that contains full list of Item Numbers

2. Open the DataLoad (Classic) tool
    Open the file Order_Lines_Load.dld  in DataLoad (Classic) tool
    Navigation:  File -> Open -> Select the Order_Lines_Load.dld file and Click Open button

  

3.Place the Cursor in Item Number column in Data Load Tool.
   Select Tools -> Excel Import
 
4. You can see, that All the Item Number records from Excel Spreadsheet are copied into the Data Loader File.
   
5. Select second column : TAB

Use Keys CTRL + D, to fill down command to copy the topmost cell into the cells below.
Or
Select second column: TAB and navigate to Edit -> Fill -> Down Ctrl + D

6. You can see that the spreadsheet for the column TAB is filled with values
       

7. Select third column : *DN in Data Loader

Use Keys CTRL + D, to fill down command to copy the topmost cell into the cells below.
Or
Select second column: TAB and navigate to Edit -> Fill -> Down Ctrl + D


8. You can see that the third column *DN is filled for all the records

9. The same step(no 7) will be repeated for the fourth column - *SL(1)

10. Save the file.

11.Go to the Last record in the file and replace the value in third column *DN to *LR to signify that this is the last record in the file.
 
12. Save the record.

13. Data Loader script is ready with the full data which needs to be loaded into the Oracle Applications.






Sample example for DataLoad - Part 3

This is last part of the DataLoad example.



Here are the final steps for loading the data from the Dataloader file(Order_Lines_Load.dld) into the Oracle EBS application.

1. Before running the Dataloader file ensure the following present in the file  :Order_Lines_Load.dld

  • Ensure *LR is present for the last record in the data load file.
  • Ensure that there are no additional records like NULL in Item Number column and data being present in other columns like TAB, *DN and *SL(1)  
 2. Open Oracle Applications and Navigate to Quick Sales Order Screen and place the cursor in Ordered  Item column
      
3. Go to Data Load Tool. Click on Tools ->  Start Load
   
4. Select the Command Group : EBS - 12 and select the appropriate Oracle Applications Front end in the Window name


5. Click on ‘OK’ Button

6. Data Loading process starts and the records will start loading.

7. Wait till the confirmation of successful loading.

8. Save the window, if everything is loaded.


That's It.... 

With help of DataLoad tool, we are now able to enter hundred's of records into the Oracle applications.


Hope this was useful. Please feel free to comment.