Vous êtes sur la page 1sur 10

CREATE OR REPLACE package body APPS.XX_AP_INT_PACK as l_user_id FND_USER.user_id%Type := fnd_global.user_id; l_login_id FND_LOGINS.login_id%Type := fnd_global.

login_id; /*************** STRATING HERE PROCEDURE *************/ Procedure XX_AP_INT_PROC ( errbuff Out Varchar2, retcode Out Number ) As v_error_message varchar2(2000) := Null; v_error_flag char(2); v_vendor_site_id po_vendor_sites_all.vendor_site_id%type; v_vendor_id po_vendors.vendor_id%type; v_vendor_site_code po_vendor_sites_all.vendor_site_code%type; v_vendor_name po_vendors.vendor_name%type; v_vendor_num po_vendors.segment1%type; v_invoice_currency_code fnd_currencies.currency_code%type; V_payment_method_lookup_code ap_lookup_codes.lookup_code%type; v_terms_ID ap_terms.term_id%type; v_terms_name ap_terms.name%type; v_invoice_type_lookup_code ap_lookup_codes.lookup_code%type; l_invoice_seq ap_invoices_all.invoice_id%type; l_invoice_line_seq ap_invoice_distributions.invoice_distribution_id%type; v_attribute_category ap_invoice_distributions_all.attribute_category%type := Null; v_code_combination_id gl_code_combinations.code_combination_id%type; v_category_code fnd_doc_sequence_assignments.category_code%type; v_voucher_num ap_invoices_all.voucher_num%type; v_count number(9) default 0; v_invoice_count ap_invoices_all.invoice_num%type; v_org_id number:= fnd_global.org_id; lv_group_id number(15) := fnd_global.conc_request_id; /* v_tax_name ja_in_tax_codes.tax_name%type; v_tax_id ja_in_tax_codes.tax_id%type; */

cursor cus_headers is

select SRNO

,SOURCE ,INVOICE_TYPE_LOOKUP_CODE ,PO_NUMBER ,VENDOR_NUM ,(select vendor_id from ap_suppliers where segment1 = vendor_num) vnedor_id ,(select vendor_name from ap_suppliers where segment1 = vendor_num) vendor_name /* ,(select apsa.vendor_site_id from ap_suppliers aps, ap_supplier_sites_All apsa where aps.vendor_id = apsa.vendor_id and aps.segment1 = vendor_num) vendor_site_id ,(select apsa.vendor_site_code from ap_suppliers aps, ap_supplier_sites_All apsa where aps.vendor_id = apsa.vendor_id and aps.segment1 = vendor_num) vendor_site_code */ ,INVOICE_DATE ,GL_DATE ,INVOICE_NUM ,INVOICE_CURRENCY_CODE ,INVOICE_AMOUNT ,EXCHANGE_RATE from XXAP_INVOICEINT_TEMP where SRNO is not null; -- and batch_id is null; Cursor cur_invoice_detail ( l_srno Varchar, l_vendor_name Varchar2, l_VENDOR_NUM Varchar2, l_invoice_date Varchar2 ) Is select SRNO2 ,LINE_TYPE_LOOKUP_CODE ,AMOUNT ,VAT_CODE ,SEGMENT1 ,SEGMENT2 ,SEGMENT3 ,SEGMENT4

,SEGMENT5 ,SEGMENT6 ,SEGMENT7 ,INVOICE_DESCRIPTION from XXAP_INVOICEINT_TEMP Where SRNO2 = l_srno; -- and batch_id is null; begin For rec_invoice_ins In cus_headers Loop --delete from ap_invoices_interface where creation_date like sysdate; v_error_flag:='Y'; v_count:=v_count+1;

/*************** To Get Vendor Site Code *************/ IF (v_vendor_id) IS NOT NULL THEN BEGIN SELECT pvsa.VENDOR_SITE_ID,pvsa.VENDOR_SITE_CODE INTO V_VENDOR_SITE_ID,V_VENDOR_SITE_CODE FROM PO_VENDOR_SITES_ALL pvsa ,po_vendors pvs WHERE pvsa.vendor_id = pvs.vendor_id and pvs.vendor_name = REC_INVOICE_INS.vendor_name and pvs.vendor_id = V_VENDOR_ID; --UPPER(LTRIM(VENDOR_SITE_CODE)) = UPPER(LTRIM(REC_INVOICE_INS.VENDOR_SITE_CODE))

Exception When NO_DATA_FOUND Then v_error_flag:= 'N'; v_error_message := 'Vendor_site is Invaild' || rec_invoice_ins.vendor_name; fnd_file.put_line (fnd_file.Log, v_error_message); When too_many_rows Then v_error_flag:= 'N'; v_error_message := 'more than one Vendor Site found for the invoice issuer code.'

|| rec_invoice_ins.vendor_name; fnd_file.put_line (fnd_file.Log, v_error_message); When Others Then v_error_flag:= 'N'; v_error_message := 'Error at Vendor Site ' || rec_invoice_ins.vendor_name; fnd_file.put_line (fnd_file.Log, v_error_message); End; end if; /*************** Vaildation Invoice Number *************/ Begin select count(*) into v_invoice_count from ap_invoices_all apia where apia.vendor_id=v_vendor_id and apia.INVOICE_NUM=rec_invoice_ins.invoice_num; if v_invoice_count>=1 then v_error_flag:='N'; v_error_message:='Invoice number should not be same for one supplier'; fnd_file.put_line (fnd_file.Log,v_invoice_count+1||' '||v_error_message); else v_error_flag:='Y'; end if; End; /*************** To Get Invoice Currency Code *************/ Begin Select currency_code Into v_invoice_currency_code From fnd_currencies Where enabled_flag = 'Y' AND CURRENCY_CODE=rec_invoice_ins.invoice_currency_code; Exception When NO_DATA_FOUND Then v_error_flag:='N';

v_error_message := 'Currency Code is Invaild' || rec_invoice_ins.invoice_currency_code; fnd_file.put_line (fnd_file.Log, v_error_message); When Others Then v_error_flag:='N'; v_error_message := 'Error at Currency Code' || rec_invoice_ins.invoice_currency_code; fnd_file.put_line (fnd_file.Log, v_error_message); End; /*************** To Get Invoice_Type_Lookup_Code *************/ Begin Select decode (lookup_code,'Credit','Credit Memo','Debit','Debit Memo',lookup_code) Into v_invoice_type_lookup_code From ap_lookup_codes Where LOOKUP_TYPE = 'INVOICE TYPE' And UPPER (TRIM (lookup_code)) = UPPER (TRIM (rec_invoice_ins.invoice_type_lookup_code)) And enabled_flag = 'Y'; Exception When NO_DATA_FOUND Then v_error_flag:='N'; v_error_message := 'Invoice Type Lookup Code is Invaild' || rec_invoice_ins.invoice_type_lookup_code; fnd_file.put_line (fnd_file.Log, v_error_message); When Others Then v_error_flag:='N'; v_error_message := 'Error at Invoice Type Lookup Code' || rec_invoice_ins.invoice_type_lookup_code; fnd_file.put_line (fnd_file.Log, v_error_message); End; /*************** TO Get Invoice Id *************/ Begin

Select ap_invoices_interface_s.Nextval Into l_invoice_seq From DUAL; end; /*************** Inserting into AP_INVOICES_INTERFACE Tables *************/ -- Begin if v_error_flag='Y' then insert into ap_invoices_interface (invoice_id ,invoice_num ,source ,vendor_site_id ,vendor_site_code ,vendor_id ,vendor_name ,vendor_num ,invoice_currency_code ,gl_date ,invoice_date ,invoice_amount ,invoice_type_lookup_code ,exchange_rate ,org_id ,INVOICE_RECEIVED_DATE ,creation_date ,created_by ,last_update_date ,last_updated_by ,last_update_login ) values (l_invoice_seq ,rec_invoice_ins.invoice_num ,'MANUAL INVOICE ENTRY'--rec_invoice_ins.Source ,v_vendor_site_id ,v_vendor_site_code ,v_vendor_id

,rec_invoice_ins.vendor_name ,rec_invoice_ins.vendor_num ,rec_invoice_ins.invoice_currency_code ,rec_invoice_ins.gl_date ,rec_invoice_ins.invoice_date ,rec_invoice_ins.invoice_amount ,upper(rec_invoice_ins.invoice_type_lookup_code) ,rec_invoice_ins.exchange_rate ,v_org_id--fnd_profile.Value ('ORG_ID') ,sysdate ,sysdate ,l_user_id ,sysdate ,l_user_id ,l_login_id); FND_FILE.PUT_LINE (FND_FILE.Log,v_count||' '|| 'Rows inserted into the AP INVOICE INTERFACE table'); else FND_FILE.PUT_LINE (FND_FILE.Log, 'Unable Inserting into the HEADER interface table'); end if; commit;

/*************** End of the Header Vaildation *************/ /*************** Here Starting Line Vaildation *************/ For c_detail In cur_invoice_detail(rec_invoice_ins.srno, rec_invoice_ins.vendor_name, rec_invoice_ins .vendor_num, sysdate) loop

--delete from ap_invoice_lines_interface where creation_date like sysdate; Exit When cur_invoice_detail%Notfound; /*************** To Get Invoice Line Id *************/ BEGIN Select AP_INVOICE_LINES_INTERFACE_S.Nextval Into l_invoice_line_seq From DUAL; END; /*************** To Get Code Combination ID *************/

BEGIN SELECT CODE_COMBINATION_ID INTO V_CODE_COMBINATION_ID FROM GL_CODE_COMBINATIONS where SEGMENT1=c_detail.SEGMENT1 and SEGMENT2=c_detail.SEGMENT2 and SEGMENT3=c_detail.SEGMENT3 and SEGMENT4=c_detail.SEGMENT4 and SEGMENT5=c_detail.SEGMENT5 and SEGMENT6=c_detail.SEGMENT6 and SEGMENT7=c_detail.SEGMENT7; Exception When NO_DATA_FOUND Then v_error_flag:='N'; v_error_message := 'Segment Columns is Invaild' || c_detail.segment1||' '||c_detail.segment2||' '||c_detail.segment3||' '||c_detail.segment4||' '||c_detail.segment5||' '||c_detail.segment6||' '||c_detail.segment7; fnd_file.put_line (fnd_file.Log, v_error_message); When Others Then v_error_flag:='N'; v_error_message := 'Error at segment columns'; fnd_file.put_line (fnd_file.Log, v_error_message);

End; /*************** Inserting into Ap_lines_interface Tables *************/ Begin

if v_error_flag='Y' then Insert Into ap_invoice_lines_interface ( invoice_id ,invoice_line_id ,line_type_lookup_code ,amount ,tax_classification_code ,dist_code_combination_id --,tax_code_id ,creation_date ,created_by ,last_update_date ,last_updated_by ,description ) Values ( l_invoice_seq ,l_invoice_line_seq ,c_detail.line_type_lookup_code ,c_detail.amount ,c_detail.vat_code ,v_code_combination_id --,tax_code_id ,SYSDATE ,l_user_id ,SYSDATE ,l_login_id ,c_detail.invoice_description ); FND_FILE.PUT_LINE(FND_FILE.Log,v_count||' '|| 'Rows inserted into the AP INVOICE LINE INTERFACE table');

/* elsif v_error_flag='N' then delete from ap_invoices_interface where invoice_id=rec_invoice_ins.vendor_num; */ else FND_FILE.PUT_LINE (FND_FILE.Log, 'Unable Inserting into the AP INVOICE LINE INTERFACE table'); end if;

End; end loop; end loop; commit; begin update XXAP_INVOICEINT_TEMP set batch_id=lv_group_id where batch_id is null; end; COMMIT; end XX_AP_INT_PROC; end XX_AP_INT_PACK; /

Vous aimerez peut-être aussi