12

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 65

CREATE OR REPLACE PROCEDURE arcip1c (ERRBUF OUT VARCHAR2,

RETCODE OUT NUMBER,


p_organization_id IN NUMBER,
p_list_id IN VARCHAR2,
p_fo_number IN VARCHAR2,
p_transaction_type_id IN NUMBER,
p_bill_cust_id IN NUMBER,
p_bill_cust_site_id IN NUMBER,
p_trx_number IN VARCHAR2,
p_trx_date IN DATE,
p_inv_create_date IN VARCHAR2,
p_region_name IN VARCHAR2,
p_new_all IN VARCHAR2,
p_draft_final IN VARCHAR2,
p_mail_flag IN VARCHAR2,
p_dist_org IN VARCHAR2,
p_banner_page IN VARCHAR2,
p_message IN VARCHAR2,
p_imaging_flag IN VARCHAR2,
p_invoice_print_queue IN VARCHAR2) AS
/* **********************************************************************
* ARCIP1.sql *
*----------------------------------------------------------------------*
* This script will populate the invoice print tables with invoice *
* information from the selected invoices. The invoices will be *
* selected based on the users input of the following parameters : *
* organization id, list id, transaction type, bill to customer number *
* and tag, invoice number, and new or reprint. The concurrent *
* request id will also be passed in as a parameter. *
* *
* The first to parameters are required by the Oracle Financials *
* Application Object Library. *
*----------------------------------------------------------------------*
* Created by : P. Chmelik (BTG) *
* 26-JUN-1998 *
* RNSG Systems 2000 Project *
*----------------------------------------------------------------------*
* >>>>> HISTORY OF CHANGES <<<<< *
*----------------------------------------------------------------------*
* P. Chmelik (BTG) 24-JUL-1998 - Modified the get_inv_hdrs cursor *
* to get the vat registration number *
* for the bill to customer. *
* Fix for ISSUE0002 dated 7/22/98 *
* *
* P. Chmelik (BTG) 24-JUL-1998 - Added logic before insert into *
* arc_ip_headers to compute freight, *
* insurance, and tax amounts. Modi- *
* fied insert statement to populate *
* those fields. *
* Fix for ISSUE0005 dated 7/22/98 *
* *
* P. Chmelik (BTG) 28-JUL-1998 - Added logic at the end to spawn the*
* invoice print process for this *
* request. *
* P. Chmelik (BTG) 28-JUL-1998 - Modified the get_inv_hdrs cursor to*
* ensure that the invoice has at *
* least one item line that is not an *
* internal option. Also modified the*
* get_inv_lines cursor to exclude the*
* internal option lines from being *
* inserted into the lines table. *
* This was done because internal *
* options are not to print on an inv.*
* *
* P. Chmelik (BTG) 29-JUL-1998 - Modified the get_tax_lines cursor *
* to select the tax ratei. Also *
* modified the insert into ar_ip_ *
* headers table to include the rate. *
* *
* P. Chmelik (BTG) 29-JUL-1998 - Modified the get_inv_hdrs cursor *
* by adding ra_cust_trx_types_all to *
* the from and joining to the table *
* for printable transacition types. *
* *
* P. Chmelik (BTG) 30-JUL-1998 - Modified the get_inv_pack_list *
* cursor to get packing list number from *
* attribute10 of the invoice line. *
* *
* P. Chmelik (BTG) 03-AUG-1998 - Added a parameter in the procedure *
* definition for the trx date. Also *
* added a condition to the get inv *
* hdrs cursor to select based on that*
* parameter. *
* FIX for ISSUE0022 *
* *
* P. Chmelik (BTG) 10-AUG-1998 - Added logic in insert into arc_ip *
* headers to include the ultimate *
* destination country and the fob *
* point description. Also added a *
* insert loop into arc_ip_info to *
* include fo numbers. This was done *
* because the information is required*
* on the invoice. *
* *
* P. Chmelik (BTG) 13-AUG-1998 - Modified the get_inv_lines cursor. *
* Added a decode to ctl.interface_ *
* line_attribute5. If it is '000', *
* it will return null, otherwise it *
* will return a value. *
* *
* P. Chmelik (BTG) 20-AUG-1998 - Added a parameter for the lead fo *
* number. This was requested in *
* ISSUE0036. *
* *
* P. Chmelik (BTG) 24-AUG-1998 - Modified procedure to make "org *
* specific". This was done by *
* removing all _all tables and using *
* the views. *
* *
* P. Chmelik (BTG) 27-AUG-1998 - Changed the source of the invoice *
* format code from the additional *
* customer trx table to attribute5 *
* of ra customer trx. *
* *
* P. Chmelik (BTG) 28-AUG-1998 - Modified the serial numbers insert *
* logic. *
* *
* P. Chmelik (BTG) 31-AUG-1998 - Added a cursor to get "info" *
* to print in addl info box on inv. *
* Called cursor from within the head-*
* ers loop. Added insert for info *
* values into arc ip info. *
* *
* P. Chmelik (BTG) 08-SEP-1998 - Modified get_inv_hdrs and get_inv_ *
* lines cursors to fix bugs with *
* manual invoices. *
* ISSUE0061 *
* *
* P. Chmelik (BTG) 08-SEP-1998 - Added calls to fnd_concurrent get_ *
* request_print_options and fnd_ *
* request set_print_options to pass *
* printer information to new request.*
* *
* P. Chmelik (BTG) 10-SEP-1998 - Added a function to get ship to *
* address information since it is *
* optional on manual invoices. *
* *
* P. Chmelik (BTG) 14-SEP-1998 - Modified the get_udc_desc cursor to*
* go from the cof country code to the*
* territory code and return a desc. *
* *
* P. Chmelik (BTG) 14-SEP-1998 - Modified the get inv hdrs cursor *
* select term id. Passed the term id*
* to the new function calc due date. *
* Added insert of due date field into*
* arc_ip_headers. *
* *
* P. Chmelik (BTG) 15-SEP-1998 - Made changes to put country *
* description in headers table *
* instead of country code. Also *
* added to decode of option number to*
* not print if 000,00,or 0. Also *
* added logic to calculate a due date*
* and populate that in the headers *
* table. *
* *
* P. Chmelik (BTG) 16-SEP-1998 - Added a function (get_tax_desc) *
* called from within the headers loop*
* that gets the tax code description.*
* The tax code description is popul- *
* ated in arc_ip_headers. *
* *
* P. Chmelik (BTG) 25-SEP-1998 - Added fields to get inv hdrs cursor*
* to get decimal separator and group *
* separator for the currency. *
* *
* P. Chmelik (BTG) 06-OCT-1998 - Added type to the inv hdr cursor. *
* *
* P. Chmelik (BTG) 06-OCT-1998 - Added logic to pull sold from cust *
* information from overrides table or*
* hr locations table. *
* *
* P. Chmelik (BTG) 07-OCT-1998 - Added default of lead fo number *
* (from header attribute4) to sales *
* order number at the invoice line *
* in get fo nums cursor. *
* FIX for ISSUE 0105 *
* *
* P. Chmelik (BTG) 07-OCT-1998 - Right trimmed any address related *
* fields for bill to, ship to, sold *
* to, and sold_from addresses. *
* FIX for ISSUE 0105 *
* *
* P. Chmelik (BTG) 11-OCT-1998 - Added a check for invalid values in*
* the inc_pos serail number sequence *
* function. *
* *
* P. Chmelik (BTG) 11-OCT-1998 - Added an insert into arc ip line *
* details for line level notes. *
* *
* P. Chmelik (BTG) 12-OCT-1998 - Added an insert into arc ip info to*
* populate header level notes. Also *
* added a cursor to get header level *
* notes. *
* *
* P. Chmelik (BTG) 19-OCT-1998 - Added sales order line to the *
* fields that source the line number *
* variable. *
* *
* P. Chmelik (BTG) 19-OCT-1998 - Removed the complete flag = Y cond-*
* ition in the get inv hdrs cursor. *
* Added complete flag to the values *
* selected, and inserted into arc ip *
* headers. *
* *
* P. Chmelik (BTG) 22-OCT-1998 - Added new parameter called p draft *
* final. This will be used to *
* populate the complete flag field in*
* arc ip headers. Expected values *
* are F for final and D for draft. *
* *
* P. Chmelik (BTG) 01-DEC-1998 - Modified the get inv lines, get inv*
* ser nums, and get inv freqs cursors*
* to accommodate customer view and *
* CDA order types. *
* *
* P. Chmelik (BTG) 01-DEC-1998 - Modified the insert into arc ip *
* headers to include the po release *
* number, and the insert into arc ip *
* line details to include the waybill*
* numbers. *
* *
* P. Chmelik (BTG) 10-DEC-1998 - Added logic at the end of the *
* procedure to submit different *
* report programs based on the value *
* of attribute1 in hr organization *
* units. *
* *
* P. Chmelik (BTG) 14-DEC-1998 - Modified the get inv hdrs cursor to*
* select location id, pay by wire *
* address, and pay by check address. *
* *
* P. Chmelik (BTG) 20-DEC-1998 - Modified the get tax lines cursor. *
* Also added logic with tax lines *
* loop to separate out state, cty, *
* and city tax amounts. *
* *
* P. Chmelik (BTG) 27-JAN-1999 - Added condition to exclude COF line*
* types of 24 from printing. That is*
* stored in ra customer trx lines *
* attribute5. *
* *
* P. Chmelik (BTG) 27-JAN-1999 - Added function, variables to get *
* the ultimate destination address *
* information from the invoice. *
* This was added into the insert into*
* arc ip headers. *
* *
* P. Chmelik (BTG) 27-JAN-1999 - Added bill contact name and ship *
* contact name to the insert into *
* arc ip headers. *
* *
* P. Chmelik (BTG) 03-FEB-1999 - Added ready to invoice flag to get *
* inv hdr cursor. Added condition to*
* that cursor that evaluates the *
* ready to invoice flag. Added a *
* decode to the insert into arc ip *
* headers around the complete flag. *
* *
* P. Chmelik (BC) 01-MAR-1999 - Added a third select to the get inv*
* lines cursor. The third select is *
* to correctly handle purchase order *
* view. The second select was modif-*
* to exclude purchase order view. *
* *
* P. Chmelik (BC) 02-MAR-1999 - Modified the get inv lines cursor *
* to exclude manual tax line types of*
* T1, T2, T3. Modified the get tax *
* lines cursor to select manual tax *
* line types. *
* *
* P. Chmelik (BC) 04-MAR-1999 - Modified the get inv headers cursor*
* to compare p region name to cpc *
* attribute7 instead of attribute2. *
* *
* P. Chmelik (BC) 22-MAR-1999 - Added mail flag and print flag to *
* the headers cursor and the insert *
* stmt into arc ip headers. *
* *
* P. Chmelik (BC) 23-MAR-1999 - Added condition to not put serial *
* numbers in a range if the invoice *
* format code is EDI. *
* *
* P. Chmelik (BC) 29-MAR-1999 - Made two changes to the lines cur- *
* sor. For CV lines, pass the cv ref*
* text field for line number if *
* code is EDI. For regular lines, if*
* option code is numeric, prefix the *
* option code with a period. *
* *
* P. Chmelik (BC) 15-APR-1999 - Modified the get inv lines cursor. *
* For CDA items, the cursor now re- *
* turns the exploded lines for all *
* regions. The line item number and *
* line item option code are now *
* sourced from line attributes 3,4. *
* J. Strociak 21-APR-1999 - Added number of invoice copies to *
* print as an input parameter into *
* the invoice format programs. *
* *
* P. Chmelik (BC) 27-APR-1999 - Added logic inside the lines cursor*
* loop to parse notes into blocks of *
* a default note size (defined in the*
* variable v note size). *
* *
* P. Chmelik (BC) 14-MAY-1999 - Added parameters for mail flag, *
* dist org, banner page, and message.*
* The first two are criteria in the *
* headers cursor. The last two are *
* used by the export report program. *
* *
* P. Chmelik (BC) 17-MAY-1999 - Modified the get ult function to *
* join to the customer table by the *
* orig system reference (xref) *
* instead of customer number (cof *
* customer number). *
* *
* J. Strociak 03-JUN-1999 - For customer view invoices that are*
* not CDA or POV, print the cv_ref_tx*
* number on the invoice as the line *
* *
* J. Strociak 07-JUN-1999 - Select note type of '*' for *
* Canadian parts orders. *
* *
* J. Strociak 07-SEP-1999 - The distribution org must default *
* to upper case. *
* J. Strociak 28-SEP-1999 - Fixed the determination of the last*
* day of the month in the due_date *
* function. *
* J. Strociak 15-FEB-2000 - Separate header notes from comments*
* J. Strociak 02-MAR-2000 - Extract Cof note type S as SNOTE *
* J. Strociak 23-JUL-1999 - Call program ARCIPTEX for US Export*
* Imaging. *
* J. Strociak 20-APR-2000 - Modified get_inv_hdrs cursor to *
* print manual invoices by looking at*
* the last_update_date of invoice *
* approval (complete_flag = 'Y') *
* J. Strociak 15-NOV-2000 - Internal options are not identified*
* correctly. Should be line_item_type*
* 24 only. *
* J. Strociak 27-DEC-2000 - Print special comments on federal *
* invoices for credit card payments. *
* TNOTEs. *
* L. Pendleton 13-FEB-2001 - CAC Request 618: Suppress the *
* printing of CDA line items when *
* the Invoice line item description *
* begins with CRTDATA or K000DATA *
* and the List, Customer, and *
* Production prices ALL equal zero. *
* J. Strociak 20-FEB-2001 - Printrak changes. *
* J. Strociak 26-JUL-2001 - For billing terms BPJ, load special*
* instructions SNOTE. *
* J. Strociak 05-OCT-2001 - Print Euro on participating *
* invoices as of 1/1/2002. ITCR2444 *
* J. Strociak 02-AUG-2002 - Fix duplicate serial number problem*
* CQ3658. *
* J. Strociak 17-JAN-2003 - CQ4402 accept unit price up to 5 *
* decimal places for PLNT and SCH_BRO*
* J. Strociak 05-JUN-2003 - CQ3654 VAT ID changes to pass ISO *
* country code and EU flag. *
* J. Strociak 09-OCT-2003 - CQ6539 Populate Optio tables for *
* Canada Invoices.
************************************************************************ */
v_inv_print_prog fnd_concurrent_programs.concurrent_program_name%type;
v_old_serial_number arc_serial_numbers.serial_number%type;
v_old_waybill_number arc_serial_numbers.waybill_number%type;
v_start_serial_number arc_serial_numbers.serial_number%type;
v_seq_serial_number arc_serial_numbers.serial_number%type;
v_serial_count NUMBER;
v_concurrent_request_id NUMBER;
v_concurrent_user_id NUMBER;
v_err_text VARCHAR2(2000);
ftp_filename_v VARCHAR2(50);
ftp_hoststring_v CONSTANT VARCHAR2(20) := 'crcimg1';
ftp_region_v VARCHAR2(3);
v_freight_total NUMBER;
v_insurance_total NUMBER;
v_tax_state_total NUMBER;
v_tax_county_total NUMBER;
v_tax_city_total NUMBER;
v_tax_rate NUMBER;
v_submit_request_id NUMBER;
v_fob_point_desc ar_lookups.description%type;
v_ult_dest_country_desc fnd_territories.territory_short_name%type;
v_printer varchar2(100);
v_number_of_copies NUMBER;
v_invoice_copies NUMBER;
v_print_style fnd_concurrent_requests.print_style%TYPE;
v_cc_printer fnd_concurrent_requests.printer%TYPE;
v_save_output fnd_concurrent_requests.save_output_flag%TYPE;
v_get_printer_format BOOLEAN;
v_set_printer_format BOOLEAN;
v_save_output_b BOOLEAN;
v_ship_name ra_customers.customer_name%TYPE;
v_ship_add1 ra_addresses.address1%TYPE;
v_ship_add2 ra_addresses.address2%TYPE;
v_ship_add3 ra_addresses.address3%TYPE;
v_ship_add4 ra_addresses.address4%TYPE;
v_ship_city ra_addresses.city%TYPE;
v_ship_state ra_addresses.state%TYPE;
v_ship_pc ra_addresses.postal_code%TYPE;
v_ship_cty ra_addresses.county%TYPE;
v_ship_ctry_iso ra_addresses.country%TYPE;
v_bill_ctry_iso ra_addresses.country%TYPE;
v_eu_flag varchar2(1);
v_ship_ctry fnd_territories.territory_short_name%TYPE;
v_ship_prov ra_addresses.province%TYPE;
v_ship_contact ra_addresses.attribute4%TYPE;
v_ship_get BOOLEAN;
v_ult_name ra_customers.customer_name%TYPE;
v_ult_add1 ra_addresses.address1%TYPE;
v_ult_add2 ra_addresses.address2%TYPE;
v_ult_add3 ra_addresses.address3%TYPE;
v_ult_add4 ra_addresses.address4%TYPE;
v_ult_city ra_addresses.city%TYPE;
v_ult_state ra_addresses.state%TYPE;
v_ult_pc ra_addresses.postal_code%TYPE;
v_ult_cty ra_addresses.county%TYPE;
v_ult_ctry fnd_territories.territory_short_name%TYPE;
v_ult_prov ra_addresses.province%TYPE;
v_ult_get BOOLEAN;
v_due_date DATE;
v_tax_desc arc_ip_headers.vat_tax_desc%TYPE;
v_shipto_customer_xref_nbr ra_customers.orig_system_reference%TYPE;
v_shipto_customer_xref_tag ra_addresses.orig_system_reference%TYPE;
v_ship_cust_tag ra_addresses.attribute1%TYPE;
v_current_org_name hr_locations.location_code%type;
v_line_item_number arc_ip_lines.line_item_number%type;
v_item_number arc_ip_lines.item_number%type;
v_temp_note VARCHAR2(50);
v_curr_note arc_notes.note_text%TYPE;
v_curr_cred_note VARCHAR2(340);
v_cred_note VARCHAR2(340):='********************************
******************* FEDERAL DIVISION CREDIT CARD SALE INVOICE FOR ** REFERENCE
ONLY. *******************************************
********';
v_cred_note2 VARCHAR2(340):='********************************
******************* FEDERAL DIVISION CREDIT CARD SALE INVOICE FOR ** REFERENCE
ONLY. A PROMPT PAYMENT DISCOUNT WILL ** BE APPLIED TO THIS INVOICE WHEN IT IS CH
ARGED ** TO YOUR CREDIT CARD. ***********************
****************************';
v_note_type arc_notes.note_type_code%TYPE;
v_note_size NUMBER:=50;
v_cut_note_position NUMBER;
v_note_length NUMBER;
v_inv_create_date DATE;
v_inv_grand_total NUMBER;
v_inv_head_total NUMBER;
v_inv_line_total NUMBER;
v_exchange_date DATE;
v_euro_grand_total NUMBER(20,2);
v_inv_conversion_rate NUMBER;
v_euro_conversion_rate NUMBER;
v_inv_freight_total NUMBER;
freight_count NUMBER;
extended_total NUMBER;
inv_conversion_rate NUMBER;
currency_code VARCHAR2(10);
v_euro_rate_conversion NUMBER;
v_euro_flag VARCHAR2(1);
v_invoice_currency_code VARCHAR2(10);
v_unit_price NUMBER;
v_list_price NUMBER;
v_extended_price NUMBER;
v_currency_dec_sep VARCHAR2(1);
v_currency_group_sep VARCHAR2(1);
v_document_type VARCHAR2(2);
v_invoice_class VARCHAR2(20);
v_bill_cust_tag ra_site_uses.location%TYPE;
v_remit_add1 VARCHAR2(50);
v_remit_add2 VARCHAR2(50);
v_remit_add3 VARCHAR2(50);
v_remit_add4 VARCHAR2(50);
v_remit_get BOOLEAN;
v_ultimate_cust_tag ra_addresses.attribute1%TYPE;
v_cof_ult_cust_tag ra_addresses.attribute1%TYPE;
v_ship_via org_freight.description%TYPE;
v_ip_header_id NUMBER;
v_lead_fo VARCHAR2(13);
v_phone_number arc_ip_info.ip_info_value%TYPE;
v_gst_tax_reg_number arc_ip_info.ip_info_value3%TYPE;
v_pst_tax_reg_number arc_ip_info.ip_info_value4%TYPE;
v_ship_date arc_ip_info.ip_info_value2%TYPE;
v_note_count NUMBER;
v_header_note VARCHAR2(2000);
v_inv_note VARCHAR2(2000);
v_line_note VARCHAR2(2000);
v_gst_hst_desc VARCHAR2(60);
v_pst_desc VARCHAR2(60);
v_additional_note_nbr VARCHAR2(150);
v_print_server_queue VARCHAR2(200);
v_line_sequence_nbr NUMBER;
CURSOR get_can_header IS
select ip_header_id,
customer_trx_id,
trx_number,
trx_date,
purchase_order_number,
purchase_order_date,
fob_point_desc,
payment_term_desc,
due_date,
bill_customer_number,
bill_customer_tag,
process_area_code,
remit_address1,
remit_address2,
remit_address3,
remit_address4,
bill_customer_name,
bill_address1,
bill_address4,
bill_address2,
bill_address3,
bill_city,
bill_state,
bill_postal_code,
bill_country,
ship_customer_name,
ship_address1,
ship_address4,
ship_address2,
ship_address3,
ship_city,
ship_state,
ship_postal_code,
ship_country,
shipto_customer_xref_tag,
ult_customer_name,
ult_address4,
ult_customer_tag,
ult_address2,
ult_address3,
ult_city,
ult_state,
ult_postal_code,
ult_country,
inv_grand_total - inv_tax_state_total - inv_tax_county_total -
inv_freight_total equip_inv_total,
inv_grand_total - inv_tax_state_total - inv_tax_county_total -
inv_freight_total invoice_sub_total,
inv_grand_total,
ship_via,
inv_freight_total,
print_flag,
mail_flag,
creation_date,
inv_tax_state_total,
inv_tax_county_total,
invoice_language_code,
invoice_currency_code,
concurrent_request_id
FROM arc_ip_headers
WHERE concurrent_request_id = v_concurrent_request_id
ORDER BY trx_number;
CURSOR get_can_notes (v_ip_header_id number) IS
SELECT ip_info_value
FROM arc_ip_info
WHERE ip_header_id = v_ip_header_id
AND ip_info_type_code in ('CNOTE', 'HNOTE')
ORDER BY ip_info_type_code DESC;
CURSOR get_can_lines (v_cust_trx_id number,
v_concurrent_request_id number) IS
SELECT ip_line_id,
ip_header_id,
concurrent_request_id,
customer_trx_id,
customer_trx_line_id,
line_type_code,
line_item_number,
invoice_quantity,
unit_price,
extended_price,
substr(item_description,(instr(item_description, '|') +1),
length(item_description)) item_description,
substr(item_description,1,(instr(item_description,
'|') -1)) part_number,
item_number,
apc_code,
creation_date
FROM arc_ip_lines
WHERE concurrent_request_id = v_concurrent_request_id
AND customer_trx_id = v_cust_trx_id
ORDER BY to_number(line_item_number), item_number;
CURSOR get_can_fo_packlist(v_cust_trx_id number, v_cust_trx_line_id number) IS
SELECT substr(interface_line_attribute3,1,13) order_nbr,
substr(interface_line_attribute13,1,20) pack_list,
substr(attribute15,1,9) pack_ship_date
FROM ra_customer_trx_lines_all
WHERE customer_trx_id = v_cust_trx_id
AND customer_trx_line_id = v_cust_trx_line_id;
CURSOR get_can_line_notes (v_ip_line_id number) IS
SELECT note_text
FROM arc_ip_line_details
WHERE ip_line_id = v_ip_line_id
AND detail_type_code = 'LNOTE'
and note_type_code in ('^', '*');
CURSOR get_can_sernum (v_ip_line_id number) IS
SELECT ip_line_id,
serial_number_from,
serial_number_to,
waybill_number,
detail_type_code,
creation_date
FROM arc_ip_line_details
WHERE ip_line_id = v_ip_line_id
AND detail_type_code = 'SERNUM'
ORDER BY serial_number_from;
CURSOR get_inv_hdrs IS
SELECT ct.customer_trx_id,
ct.bill_to_customer_id,
ct.bill_to_site_use_id,
ct.ship_to_customer_id,
ct.ship_to_site_use_id,
rtrim(nvl(o.remit_address1, nvl(pipe_cut(cpc.attribute6,1),remit.address1
))) remit_add1,
rtrim(nvl(o.remit_address2, nvl(pipe_cut(cpc.attribute6,2),remit.address2
))) remit_add2,
rtrim(nvl(o.remit_address3, nvl(pipe_cut(cpc.attribute6,3),remit.address3
))) remit_add3,
rtrim(nvl(o.remit_address4, nvl(pipe_cut(cpc.attribute6,4),remit.address4
))) remit_add4,
-- rtrim(nvl(o.remit_city, remit.city)) remit_city,
'x' remit_city,
-- rtrim(nvl(o.remit_state, remit.state)) remit_state,
null remit_state,
-- rtrim(nvl(o.remit_postal_code, remit.postal_code)) remit_pc,
null remit_pc,
-- rtrim(nvl(o.remit_county, remit.county)) remit_ct
y,
null remit_cty,
-- rtrim(nvl(o.remit_country, remit_terr.territory_short_name))
remit_ctry,
null remit_ctry,
-- rtrim(nvl(o.remit_province, remit.province)) remit_prov,
null remit_prov,
bill_cust.customer_name bill_cust_name,
bill_cust.customer_number bill_cust_num,
bill_site.location bill_cust_tag,
bill_site.tax_code tax_code_v,
-- rtrim(nvl(o.bill_address1, bill_add.address1)) bill_add1,
rtrim(nvl(o.bill_address1, bill_cust.customer_name)) bill_add1,
rtrim(nvl(o.bill_address2, bill_add.address2)) bill_add2,
rtrim(nvl(o.bill_address3, bill_add.address3)) bill_add3,
rtrim(nvl(o.bill_address4, bill_add.address4)) bill_add4,
rtrim(nvl(o.bill_city, bill_add.city)) bill_city,
rtrim(nvl(o.bill_state, bill_add.state)) bill_state,
rtrim(nvl(o.bill_postal_code, bill_add.postal_code)) bill_pc,
rtrim(nvl(o.bill_county, bill_add.county)) bill_cty,
rtrim(nvl(o.bill_country, bill_terr.territory_short_name))
bill_ctry,
rtrim(nvl(o.bill_province, bill_add.province)) bill_prov,
rtrim(bill_add.attribute4) bill_contact,
bill_cust.tax_reference bill_vat_reg,
-- ship_cust.customer_name ship_cust_name,
-- nvl(o.ship_address1, ship_add.address1) ship_add1,
-- nvl(o.ship_address2, ship_add.address2) ship_add2,
-- nvl(o.ship_address3, ship_add.address3) ship_add3,
-- nvl(o.ship_address4, ship_add.address4) ship_add4,
-- nvl(o.ship_city, ship_add.city) ship_city,
-- nvl(o.ship_state, ship_add.state) ship_state,
-- nvl(o.ship_postal_code, ship_add.postal_code) ship_pc,
-- nvl(o.ship_county, ship_add.county) ship_cty,
-- nvl(o.ship_country, ship_add.country) ship_ctry,
-- nvl(o.ship_province, ship_add.province) ship_prov,
ct.trx_number,
ct.trx_date,
ct.purchase_order,
ct.purchase_order_date,
nvl(o.payment_terms_desc, t.description) description,
ct.attribute5 invoice_language_code,
ct.invoice_currency_code,
ct.attribute6,
ct.attribute7,
ct.attribute8,
ct.term_id,
ct.org_id,
nvl(cur.attribute1, '.') currency_dec_sep,
nvl(cur.attribute2, ',') currency_group_sep,
rtrim(nvl(o.sold_from_address1, pipe_cut(cpc.attribute5,1))) ship_fro
m_add1,
-- rtrim(nvl(o.sold_from_address1, loc.address_line_1)) ship_from_add1,
rtrim(nvl(o.sold_from_address2, pipe_cut(cpc.attribute5,2))) ship_fro
m_add2,
-- rtrim(nvl(o.sold_from_address2, loc.address_line_2)) ship_from_add2,
rtrim(nvl(o.sold_from_address3, pipe_cut(cpc.attribute5,3))) ship_fro
m_add3,
rtrim(nvl(o.sold_from_address4, pipe_cut(cpc.attribute5,4))) ship_fro
m_add4,
-- rtrim(nvl(o.sold_from_address3, loc.address_line_3)) ship_from_add3,
-- rtrim(nvl(o.sold_from_city, loc.town_or_city)) ship_from_city,
-- rtrim(nvl(o.sold_from_state, loc.region_2)) ship_from_state,
-- rtrim(nvl(o.sold_from_postal_code, loc.postal_code)) ship_from_pc,
-- rtrim(nvl(o.sold_from_province, loc.region_1)) ship_from_prov,
-- rtrim(nvl(o.sold_from_country, sf_terr.territory_short_name))
ship_from_ctry,
null ship_from_city,
null ship_from_state,
null ship_from_pc,
null ship_from_prov,
null ship_from_ctry,
ctt.type,
cur.attribute3 remit_acct_num,
ct.complete_flag comp_flag,
DECODE(sign(nvl(ct.printing_count,0)),1,'Printed','Never') print_status,
act.po_release_nbr,
ofr.description ship_via,
ofr.freight_code,
loc.location_id,
cpc.attribute9 pay_by_check_address,
cpc.attribute10 pay_by_wire_address,
bill_cust.orig_system_reference billto_customer_xref_nbr,
substr(bill_add.orig_system_reference,12,4) billto_customer_xref_tag,
substr(bill_add.attribute1,1,4) billto_customer_cof_tag,
nvl(cpc.attribute4, 'N') ser_range_ok,
loc.location_code,
ct.attribute12 process_area_code,
substr(ct.attribute1,1,10) ult_cust_num,
substr(ct.attribute1,12,4) ult_cust_tag,
ct.attribute15 ready_to_inv_flag,
ct.attribute10 print_flag,
ct.attribute11 mail_flag,
ct.attribute13 owners_div_grp_code,
act.billing_terms_code,
act.cv_list_description,
t.name,
bill_add.country bill_ctry_iso
FROM hr_organization_units ou,
hr_locations loc,
org_freight ofr,
ra_terms t,
ar_customer_profiles cp,
ar_customer_profile_classes cpc,
ra_cust_trx_types ctt,
arc_overrides o,
arc_addl_customer_trx act,
ra_addresses remit,
fnd_territories remit_terr,
fnd_territories bill_terr,
fnd_territories sf_terr,
fnd_currencies cur,
-- ra_customers ship_cust,
-- ra_addresses ship_add,
-- ra_site_uses ship_site,
ra_customers bill_cust,
ra_addresses bill_add,
ra_site_uses bill_site,
ra_customer_trx ct
WHERE ct.term_id = t.term_id (+)
AND ct.complete_flag = DECODE(p_draft_final, 'F', 'Y', ct.complete_flag)
AND nvl(ct.attribute15, 'Y') =
DECODE(p_draft_final, 'F', 'Y', nvl(ct.attribute15, 'Y'))
AND ct.customer_trx_id = o.customer_trx_id (+)
AND ct.customer_trx_id = act.customer_trx_id (+)
AND ct.bill_to_site_use_id = bill_site.site_use_id
AND ct.ship_via = ofr.freight_code (+)
AND bill_site.address_id = bill_add.address_id
AND bill_add.customer_id = bill_cust.customer_id
AND bill_cust.customer_id = cp.customer_id
AND cp.site_use_id is null
AND cp.customer_profile_class_id = cpc.customer_profile_class_id
AND nvl(cpc.attribute7, 'xxx') = nvl(p_region_name, nvl(cpc.attribute7, 'xxx'
))
AND bill_add.country = bill_terr.territory_code
AND ct.invoice_currency_code = cur.currency_code (+)
-- AND ct.ship_to_site_use_id = ship_site.site_use_id (+)
-- AND ct.ship_to_customer_id = ship_cust.customer_id (+)
-- -- AND ship_site.address_id = ship_add.address_id
--AND nvl(ship_add.customer_id,-1) = nvl(ship_cust.customer_id,-1)
AND ct.cust_trx_type_id = ctt.cust_trx_type_id
AND ctt.default_printing_option = 'PRI'
AND ct.remit_to_address_id = remit.address_id
AND remit.country = remit_terr.territory_code
AND ct.org_id = nvl(p_organization_id, ct.org_id)
AND nvl(upper(ct.interface_header_attribute2), 'XxX') =
nvl(p_list_id, nvl(upper(ct.interface_header_attribute2), 'XxX'))
AND ct.cust_trx_type_id = nvl(p_transaction_type_id, ct.cust_trx_type_id)
AND ct.bill_to_customer_id = nvl(p_bill_cust_id, ct.bill_to_customer_id)
AND ct.bill_to_site_use_id = nvl(p_bill_cust_site_id, ct.bill_to_site_use_id)
AND ct.trx_number = nvl(p_trx_number, ct.trx_number)
AND nvl(ct.attribute4, 'XxX') = nvl(p_fo_number, nvl(ct.attribute4, 'XxX'))
AND nvl(ct.printing_count,0) = DECODE(p_new_all, null, nvl(ct.printing_count,
0), 'New', 0, nvl(ct.printing_count,0))
AND ct.trx_date = DECODE(p_trx_date, null, ct.trx_date, p_trx_date)
AND nvl(ct.attribute11, 'x') =
DECODE(p_mail_flag, null, nvl(ct.attribute11, 'x'), p_mail_flag)
AND cpc.name = UPPER(DECODE(p_dist_org, null, cpc.name, p_dist_org))
AND ct.org_id = ou.organization_id
AND ou.location_id = loc.location_id
AND loc.country = sf_terr.territory_code (+)
AND ((trunc(ct.creation_date) = nvl(v_inv_create_date,
trunc(ct.creation_date))) OR (trunc(ct.last_update_date) =
trunc(sysdate-1)))
AND exists
(SELECT 'at least one line that is not an internal option'
FROM ra_customer_trx_lines ctl
WHERE ct.customer_trx_id = ctl.customer_trx_id
AND ctl.line_type = 'LINE'
/* AND nvl(ltrim(substr(ctl.description, instr(ctl.description, '|') + 1)),
'x') not like 'INT:%' */
AND nvl(attribute5, '1') not in ('24'));
CURSOR get_inv_pack_list (v_cust_trx_id NUMBER) IS
SELECT DISTINCT ctl.attribute10 packing_list_nbr,
ctl.attribute15 ship_date_actual
FROM ra_customer_trx_lines ctl
WHERE ctl.customer_trx_id = v_cust_trx_id
AND ctl.line_type = 'LINE'
AND ctl.attribute10 is not null;
CURSOR get_fo_nums (v_cust_trx_id NUMBER) IS
SELECT DISTINCT nvl(ctl.sales_order, ct.attribute4) sales_order
FROM ra_customer_trx_lines ctl,
ra_customer_trx ct
WHERE ct.customer_trx_id = v_cust_trx_id
AND ct.customer_trx_id = ctl.customer_trx_id
AND ctl.line_type = 'LINE';
CURSOR get_info (v_bill_to_id NUMBER, v_bill_site_id NUMBER, v_loc_id NUMBER) IS
/* Cursor before the modification on 14-DEC-1998
SELECT c.telephone_number,
c.attribute1 fax_number,
nvl(cp.attribute3, cpc.attribute3) registered_number,
nvl(cp.attribute4, cpc.attribute4) vat_reg_number,
nvl(cp.attribute5, cpc.attribute5) reg_off1,
nvl(cp.attribute6, cpc.attribute6) reg_off2,
nvl(cp.attribute7, cpc.attribute7) reg_off3
FROM ar_collectors c,
ar_customer_profile_classes cpc,
ar_customer_profiles cp
WHERE cp.customer_id = v_bill_to_id
AND cp.site_use_id is null
AND cp.collector_id = c.collector_id
AND cp.customer_profile_class_id = cpc.customer_profile_class_id;
*/
SELECTDECODE(c2.collector_id, null, c.telephone_number, c2.telephone_number)
telephone_number,
DECODE(c2.collector_id, null, c.attribute1, c2.attribute1)
fax_number,
loc.attribute2 registered_number,
loc.attribute3 vat_reg_number,
substr(loc.attribute5,1,(instr(loc.attribute5, '|', 1, 1) - 1)) reg_off1,
substr(loc.attribute5,(instr(loc.attribute5, '|', 1, 1) + 1),
(instr(loc.attribute5, '|', 1, 2) -1) -
(instr(loc.attribute5, '|', 1, 1) + 1)) reg_off2,
substr(loc.attribute5,(instr(loc.attribute5, '|', 1, 2) + 1 )) reg_off3,
DECODE(c2.collector_id, null, c.description, c2.description)
collector_name
FROM ar_collectors c,
ra_site_uses su,
ra_addresses a,
ar_collectors c2,
hr_locations loc,
ar_customer_profile_classes cpc,
ar_customer_profiles cp
WHERE cp.customer_id = v_bill_to_id
AND cp.site_use_id is null
AND cp.collector_id = c.collector_id
AND cp.customer_profile_class_id = cpc.customer_profile_class_id
AND loc.location_id = v_loc_id
AND su.site_use_id = v_bill_site_id
AND su.address_id = a.address_id
AND a.customer_id = v_bill_to_id
AND a.attribute4 = c2.name (+);

inf get_info%rowtype;
/* This cursor will move line records from ra customer trx lines if */
/* there is no corresponding customer view record and it will move */
/* records from arc customer views if they exist for this invoice. */
/* The records will be moved into arc ip lines. */
CURSOR get_inv_lines (v_cust_trx_id NUMBER, v_inv_format_code VARCHAR2) IS
SELECT ctl.customer_trx_id customer_trx_id,
ctl.customer_trx_line_id customer_trx_line_id,
DECODE(ctl.attribute5, 'ML', 'ML', 'MI') line_type_code,
-2 cv_grp_nbr,
-- nvl(ctl.interface_line_attribute4, to_char(ctl.line_number))
ctl.attribute3 line_item_number,
ctl.line_number ar_line_number,
ctl.quantity_invoiced invoice_quantity,
ctl.attribute2 country_of_origin,
-- nvl(ctl.interface_line_attribute4, nvl(ctl.sales_order_line, to_char(ct
l.line_number))) || DECODE(ctl.interface_line_attribute5, '000', null, '00', nu
ll, '0', null, ctl.interface_line_attribute5) item_number,
-- nvl(ctl.interface_line_attribute4, nvl(ctl.sales_order_line, to_char(ct
l.line_number))) || DECODE(ctl.interface_line_attribute5, null, null, '000', nu
ll, '00', null, '0', null, DECODE(instr(translate(ctl.interface_line_attribute5,
'0123456789', '^^^^^^^^^^'), '^'), 0, ctl.interface_line_attribute5, '.' || lpa
d(ctl.interface_line_attribute5, 2, '0'))) item_number,
ctl.attribute3 || DECODE(ctl.attribute4, null, null, '000', null, '00', n
ull, '0', null, DECODE(instr(translate(ctl.attribute4, '0123456789', '^^^^^^^^^^
'), '^'), 0, ctl.attribute4, '.' || lpad(ctl.attribute4, 2, '0'))) item_number,
rtrim(ctl.description) item_description,
ctl.unit_selling_price unit_price,
ctl.unit_standard_price list_price,
ctl.attribute10 pack_list_num,
ctl.attribute1 apc_code,
ctl.attribute15 ship_date,
ctl.extended_amount extended_price,
ctl.attribute11 order_type_code
FROM ra_customer_trx_lines ctl
WHERE ctl.customer_trx_id = v_cust_trx_id
AND ctl.line_type = 'LINE'
AND nvl(ctl.attribute5, '-6') not in ('15','88', 'T1', 'T2', 'T3')
-- freight line types and manual tax line types
/* AND nvl(ltrim(substr(ctl.description, instr(ctl.description, '|') + 2)),
'XxXx') not like 'INT:%' */
AND nvl(attribute5, '1') not in ('24')
------------------------------------------------------
-- The line item is not a CDA zero value line item --
AND ((ctl.unit_standard_price != 0
or ctl.unit_selling_price != 0)
and (ctl.description like 'CRTDATA%'
or ctl.description like 'K000DATA%')
OR (ctl.description not like 'CRTDATA%'
AND ctl.description not like 'K000DATA%'))
------------------------------------------------------
AND not exists
(SELECT 'there is a related non-CDA customer view item'
FROM arc_customer_views cv
WHERE cv.customer_trx_id = ctl.customer_trx_id
AND to_char(cv.cv_grp_nbr) = ctl.attribute7
AND nvl(cv.cv_ref_text,'x') != 'CDA')
UNION ALL
SELECT cv.customer_trx_id customer_trx_id,
-1 customer_trx_line_id,
'CV' line_type_code,
cv.cv_grp_nbr cv_grp_nbr,
DECODE(v_inv_format_code, 'EDI', cv.cv_ref_text,
to_char(cv.cv_grp_nbr)) line_item_number,
cv.cv_grp_nbr ar_line_number,
cv.cv_item_quantity invoice_quantity,
null country_of_origin,
-- DECODE(v_inv_format_code, 'EDI', cv.cv_ref_text,
-- to_char(cv.cv_grp_nbr)) item_number,
cv.cv_ref_text item_number,
rtrim(cv.cv_item_description) item_description,
cv.cv_unit_price unit_price,
cv.cv_unit_price list_price,
null pack_list_num,
null apc_code,
max(ctl.attribute15) ship_date,
sum(ctl.extended_amount) extended_price,
max(ctl.attribute11) order_type_code
FROM ra_customer_trx_lines ctl,
arc_customer_views cv
WHERE cv.customer_trx_id = v_cust_trx_id
AND cv.customer_trx_id = ctl.customer_trx_id
AND nvl(cv.cv_ref_text,'x') != 'CDA'
AND to_char(cv.cv_grp_nbr) = ctl.attribute7
AND ctl.line_type = 'LINE'
AND nvl(ctl.attribute5, '-6') not in ('15','88', 'T1', 'T2', 'T3')
-- freight line types and manual tax line types
AND v_inv_format_code != 'POV'
GROUP BY cv.customer_trx_id,
null,
'CV',
cv.cv_grp_nbr,
DECODE(v_inv_format_code, 'EDI',
cv.cv_ref_text, to_char(cv.cv_grp_nbr)),
cv.cv_grp_nbr,
cv.cv_item_quantity,
null,
-- cv.cv_grp_nbr,
cv.cv_ref_text,
cv.cv_item_description,
cv.cv_unit_price,
cv.cv_unit_price,
null,
null
UNION ALL
SELECT cv.customer_trx_id customer_trx_id,
-1 customer_trx_line_id,
DECODE(cv.cv_item_quantity, null, 'ML',
0, 'ML', 'CV') line_type_code,
cv.cv_grp_nbr cv_grp_nbr,
to_char(cv.cv_grp_id) line_item_number,
cv.cv_grp_id ar_line_number,
cv.cv_item_quantity invoice_quantity,
null country_of_origin,
to_char(cv.cv_grp_id) item_number,
rtrim(cv.cv_item_description) item_description,
cv.cv_unit_price unit_price,
cv.cv_unit_price list_price,
null pack_list_num,
null apc_code,
max(ctl.attribute15) ship_date,
cv.cv_extended_price extended_price,
max(ctl.attribute11) order_type_code
FROM ra_customer_trx_lines ctl,
arc_customer_views cv
WHERE cv.customer_trx_id = v_cust_trx_id
AND cv.customer_trx_id = ctl.customer_trx_id
AND to_char(cv.cv_grp_nbr) = ctl.attribute7
AND ctl.line_type = 'LINE'
AND nvl(ctl.attribute5, '-6') not in ('15','88', 'T1', 'T2', 'T3')
-- freight line types and manual tax line types
AND v_inv_format_code = 'POV'
GROUP BY cv.customer_trx_id,
null,
'CV',
cv.cv_grp_nbr,
cv.cv_grp_id,
cv.cv_grp_id,
cv.cv_item_quantity,
null,
cv.cv_grp_id,
cv.cv_item_description,
cv.cv_unit_price,
cv.cv_unit_price,
null,
null,
cv.cv_extended_price;
/* For this cursor, only one part of the union will return a */
/* value for a given invoice print line. */
CURSOR get_inv_ser_nums (v_cust_trx_line_id NUMBER,
v_line_item_number VARCHAR2,
v_cust_trx_id NUMBER) IS
/* This part of the union retrieves serial numbers related to */
/* the standard Motorola Item that is being extracted for */
/* printing. */
SELECT sn.serial_number,
sn.waybill_number
FROM arc_serial_numbers sn
WHERE sn.customer_trx_line_id = v_cust_trx_line_id
AND sn.customer_trx_id = v_cust_trx_id
UNION ALL
/* This part of the union retrieves serial numbers related to */
/* the Motorola items that make up the Customer View item that*/
/* is being extracted for printing. */
SELECT sn.serial_number,
sn.waybill_number
FROM arc_serial_numbers sn,
ra_customer_trx_lines ctl
WHERE v_cust_trx_line_id = -1
AND ctl.customer_trx_id = v_cust_trx_id
AND ctl.attribute7 = v_line_item_number
AND ctl.customer_trx_line_id = sn.customer_trx_line_id
ORDER BY 1;
/* For this cursor, only one part of the union will return a */
/* value for a given invoice print line. */
CURSOR get_inv_freqs (v_cust_trx_line_id NUMBER,
v_line_item_number VARCHAR2,
v_cust_trx_id NUMBER) IS
/* This part of the union retrieves the frequency information*/
/* related to the Motorola Item that is being extracted for */
/* printing. */
SELECT f.freq_zone,
f.transmit_freq_number,
f.receive_freq_number,
f.transmit_squelch_code,
f.receive_squelch_code
FROM arc_frequencies f
WHERE f.customer_trx_line_id = v_cust_trx_line_id
AND f.customer_trx_id = v_cust_trx_id
UNION ALL
/* This part of the union retrieves the frequency information*/
/* related to the Motorola Items that make up the Customer */
/* View item that is being extracted for printing. */
SELECT f.freq_zone,
f.transmit_freq_number,
f.receive_freq_number,
f.transmit_squelch_code,
f.receive_squelch_code
FROM ra_customer_trx_lines ctl,
arc_frequencies f
WHERE v_cust_trx_line_id = -1
AND ctl.customer_trx_id = v_cust_trx_id
AND ctl.attribute7 = v_line_item_number
AND ctl.customer_trx_line_id = f.customer_trx_line_id;
CURSOR get_tax_lines (v_cust_trx_id NUMBER) IS
SELECT nvl(vt.tax_type, 'LOCATION') tax_type,
nvl(upper(vt.tax_code), 'VERTEX') tax_code,
ctl.location_segment_id,
ctl.extended_amount,
nvl(vt.tax_rate, ctl.tax_rate) tax_rate,
ctl.line_number
FROM ra_customer_trx_lines ctl,
ar_vat_tax vt
WHERE ctl.customer_trx_id = v_cust_trx_id
AND ctl.line_type = 'TAX'
AND ctl.vat_tax_id = vt.vat_tax_id(+)
UNION ALL
SELECT 'SALES_TAX' tax_type,
DECODE(ctl.attribute5, 'T1', 'STATE TAX',
'T2', 'COUNTY TAX',
'T3', 'CITY TAX') tax_code,
0,
ctl.extended_amount,
0,
ctl.line_number
FROM ra_customer_trx_lines ctl
WHERE ctl.customer_trx_id = v_cust_trx_id
AND ctl.line_type = 'LINE'
AND ctl.attribute5 in ('T1','T2','T3');
CURSOR get_header_notes(v_cust_trx_id NUMBER) IS
SELECT internal_notes note
FROM ra_customer_trx
WHERE customer_trx_id = v_cust_trx_id
AND internal_notes is not null;
--UNION ALL
--SELECT internal_notes note
--FROM ra_customer_trx
--WHERE customer_trx_id = v_cust_trx_id
--AND internal_notes is not null;
CURSOR get_comments(v_cust_trx_id NUMBER) IS
SELECT comments note
FROM ra_customer_trx
WHERE customer_trx_id = v_cust_trx_id
AND comments is not null;
CURSOR get_snote(v_cust_trx_id NUMBER) IS
SELECT distinct rtrim(note_text) note
FROM arc_notes
WHERE customer_trx_id = v_cust_trx_id
AND note_type_code = 'S';
CURSOR get_line_notes(v_cust_trx_line_id NUMBER) IS
SELECT rtrim(note_text) note_text,
note_type_code
FROM arc_notes
WHERE customer_trx_line_id = v_cust_trx_line_id
AND note_type_code in ('^', '*')
-- UNION ALL
-- SELECT attribute6 note_text
-- FROM ra_customer_trx_lines
-- WHERE customer_trx_line_id = v_cust_trx_line_id
-- AND attribute6 is not null
ORDER BY notes_line_number;
v_descr ar_lookups.description%type;
v_terr_name fnd_territories.territory_short_name%type;
exch_date DATE;
invoice_conversion_rate NUMBER;
euro_conversion_rate NUMBER;
v_currency_code VARCHAR2(15);
FUNCTION get_fob_desc(v_cust_trx_id number)
RETURN varchar2 IS
BEGIN
SELECT l.description
INTO v_descr
FROM ra_customer_trx ct,
ar_lookups l
WHERE ct.customer_trx_id = v_cust_trx_id
AND ct.fob_point = l.lookup_code
AND l.lookup_type = 'FOB';
RETURN v_descr;
EXCEPTION
WHEN OTHERS THEN
RETURN null;
END;
FUNCTION get_frc_fob_desc(v_cust_trx_id number)
RETURN varchar2 IS
BEGIN
SELECT t.word_value
INTO v_descr
FROM arc_lang_translations t,
ra_customer_trx ct
WHERE ct.customer_trx_id = v_cust_trx_id
AND ct.fob_point = rtrim(t.orig_value)
AND t.lang_code = 'FRC';
RETURN v_descr;
EXCEPTION
WHEN OTHERS THEN
RETURN null;
END;
FUNCTION get_exchange_date(v_cust_trx_id NUMBER)
RETURN DATE IS
BEGIN
SELECT r.exchange_date
INTO exch_date
FROM ra_customer_trx_all r
WHERE r.customer_trx_id = v_cust_trx_id;
RETURN exch_date;
EXCEPTION
WHEN OTHERS THEN
RETURN null;
END;
Function get_currency_rate_invoice(exch_date DATE, v_cust_trx_id NUMBER)
RETURN NUMBER IS
BEGIN
SELECT r.exchange_rate
INTO invoice_conversion_rate
FROM ra_customer_trx_all r
WHERE r.exchange_date = exch_date
AND r.customer_trx_id = v_cust_trx_id;
RETURN invoice_conversion_rate;
EXCEPTION
WHEN OTHERS THEN
RETURN null;
END;
Function get_currency_rate_euro(exch_date DATE)
RETURN NUMBER IS
BEGIN
SELECT l.conversion_rate
INTO euro_conversion_rate
FROM gl_daily_conversion_rates l
WHERE l.conversion_date = exch_date
AND l.from_currency_code = 'EUR';
RETURN euro_conversion_rate;
EXCEPTION
WHEN OTHERS THEN
RETURN null;
END;
/* Get total of the invoice */
FUNCTION get_extended_amount_total(v_cust_trx_id NUMBER)
RETURN NUMBER IS
BEGIN
SELECT sum(extended_amount)
INTO extended_total
FROM ra_customer_trx_lines l
WHERE l.customer_trx_id = v_cust_trx_id;
RETURN extended_total;
EXCEPTION
WHEN OTHERS THEN
RETURN null;
END;

Function get_currency_code(v_cust_trx_id NUMBER)


RETURN VARCHAR2 IS
BEGIN
select r.invoice_currency_code
into v_currency_code
from ra_customer_trx_all r
where r.customer_trx_id = v_cust_trx_id;
return v_currency_code;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END;
Function get_euro_currency_rate(currency_code VARCHAR2)
Return NUMBER is
Begin
Select r.conversion_rate
Into inv_conversion_rate
From ARC_EURO_CONVERSION_RATE r
Where Currency_code = r.euro_currency_literal;
return inv_conversion_rate;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END;
Function get_eu_flag(v_trx_date DATE,
v_ship_ctry_iso VARCHAR2)
Return VARCHAR2 is
Begin
Select u.eu_flag
Into v_eu_flag
From ARC_EURO_CONVERSION_RATE u
Where u.iso_country_code = v_ship_ctry_iso
AND trunc(v_trx_date) between u.eu_eff_date and
nvl(u.eu_end_date, sysdate);
return v_eu_flag;
EXCEPTION
WHEN OTHERS THEN
RETURN 'N';
END;
FUNCTION get_udc_desc(v_cust_trx_id number)
RETURN varchar2 IS
BEGIN
SELECT t.territory_short_name
INTO v_terr_name
FROM ra_customer_trx ct,
rtr_country_maps cm,
fnd_territories t
WHERE ct.customer_trx_id = v_cust_trx_id
AND ct.attribute9 = cm.cof_country_code
AND cm.iso_country_code = t.territory_code;
RETURN v_terr_name;
EXCEPTION
WHEN OTHERS THEN
RETURN null;
END;
FUNCTION calc_due_date(v_term_id number, v_trx_date date)
RETURN date IS
CURSOR get_term_info IS
SELECT due_days,
due_date,
due_day_of_month,
due_months_forward
FROM ra_terms_lines
WHERE term_id = v_term_id
AND sequence_num = 1;
v_new_due DATE:=v_trx_date;
v_dom number;
v_max_dom number;
v_mon number;
v_yr number;
BEGIN
FOR ti IN get_term_info LOOP
IF (ti.due_days is not null) THEN
SELECT v_trx_date + ti.due_days
INTO v_new_due
FROM dual;
RETURN(v_new_due);
END IF;
IF (ti.due_date is not null) THEN
v_new_due := ti.due_date;
RETURN(v_new_due);
END IF;
IF ((ti.due_day_of_month is not null) AND
(ti.due_months_forward is not null)) THEN
SELECT to_number(to_char(v_trx_date, 'DD')),
to_number(to_char(v_trx_date, 'MM')),
to_number(to_char(v_trx_date, 'YYYY'))
INTO v_dom,
v_mon,
v_yr
FROM dual;
IF ((v_mon + ti.due_months_forward) > 12) THEN
v_mon := (v_mon + ti.due_months_forward) - 12;
v_yr := v_yr + 1;
ELSE
v_mon := v_mon + ti.due_months_forward;
END IF;
SELECT to_char(last_day(to_date('01-' || lpad(to_char(v_mon), 2, '0') ||
'-' || to_char(v_yr), 'DD-MM-YYYY')), 'DD')
INTO v_max_dom
FROM dual;
IF (ti.due_day_of_month > v_max_dom) THEN
/* If day is greater than last day in month, due date has to be */
/* in the next month. */
v_dom := ti.due_day_of_month - v_max_dom;
v_mon := v_mon + 1;
IF (v_mon > 12) THEN
v_mon := v_mon - 12;
v_yr := v_yr + 1;
END IF;
ELSE
/* If day is less than last day in month, use the day to */
/* calculate the due date. */
v_dom := ti.due_day_of_month;
END IF;
SELECT to_date(lpad(to_char(v_dom), 2, '0') || '-' ||
lpad(to_char(v_mon), 2, '0') || '-' ||
to_char(v_yr), 'DD-MM-YYYY')
INTO v_new_due
FROM dual;
RETURN(v_new_due);
END IF;
END LOOP;
/* If no term line information found, return trx date as due date */
RETURN(v_trx_date);
END; -- end calc due date
FUNCTION get_ship_to(v_cust_trx_id number,
v_ship_cust_id number,
v_ship_site_id number)
RETURN boolean IS
BEGIN
SELECT c.customer_name ship_name,
rtrim(DECODE(o.ship_address1, null, a.address1,
o.ship_address1)) ship_add1,
rtrim(DECODE(o.ship_address1, null, a.address2,
o.ship_address2)) ship_add2,
rtrim(DECODE(o.ship_address1, null, a.address3,
o.ship_address3)) ship_add3,
rtrim(DECODE(o.ship_address1, null, a.address4,
o.ship_address4)) ship_add4,
rtrim(DECODE(o.ship_address1, null, a.city,
o.ship_city)) ship_city,
rtrim(DECODE(o.ship_address1, null, a.state,
o.ship_state)) ship_state,
rtrim(DECODE(o.ship_address1, null, a.postal_code,
o.ship_postal_code)) ship_pc,
rtrim(DECODE(o.ship_address1, null, a.county,
o.ship_county)) ship_county,
rtrim(DECODE(o.ship_address1, null, t.territory_short_name,
o.ship_country)) ship_ctry,
rtrim(DECODE(o.ship_address1, null, a.province,
o.ship_province)) ship_prov,
-- rtrim(nvl(o.ship_address1, a.address1)) ship_add1,
-- rtrim(nvl(o.ship_address2, a.address2)) ship_add2,
-- rtrim(nvl(o.ship_address3, a.address3)) ship_add3,
-- rtrim(nvl(o.ship_address4, a.address4)) ship_add4,
-- rtrim(nvl(o.ship_city, a.city)) ship_city,
-- rtrim(nvl(o.ship_state, a.state)) ship_state,
-- rtrim(nvl(o.ship_postal_code, a.postal_code)) ship_pc,
-- rtrim(nvl(o.ship_county, a.county)) ship_cty,
-- rtrim(nvl(o.ship_country, t.territory_short_name)) ship_ctry,
-- rtrim(nvl(o.ship_province, a.province)) ship_prov,
c.orig_system_reference,
substr(a.orig_system_reference,12,4),
substr(a.attribute1,1,4) ship_cust_tag,
rtrim(a.attribute4) ship_contact,
a.country ship_ctry_iso
INTO v_ship_name,
v_ship_add1,
v_ship_add2,
v_ship_add3,
v_ship_add4,
v_ship_city,
v_ship_state,
v_ship_pc,
v_ship_cty,
v_ship_ctry,
v_ship_prov,
v_shipto_customer_xref_nbr,
v_shipto_customer_xref_tag,
v_ship_cust_tag,
v_ship_contact,
v_ship_ctry_iso
FROM ra_customer_trx ct,
ra_site_uses su,
fnd_territories t,
ra_addresses a,
arc_overrides o,
ra_customers c
WHERE su.site_use_id = v_ship_site_id
AND su.address_id = a.address_id
AND a.country = t.territory_code
AND a.customer_id = c.customer_id
AND c.customer_id = v_ship_cust_id
AND ct.customer_trx_id = v_cust_trx_id
AND ct.customer_trx_id = o.customer_trx_id (+);
RETURN(TRUE);
EXCEPTION
WHEN OTHERS THEN
v_ship_name := null;
v_ship_add1 := null;
v_ship_add2 := null;
v_ship_add3 := null;
v_ship_add4 := null;
v_ship_city := null;
v_ship_state := null;
v_ship_pc := null;
v_ship_cty := null;
v_ship_ctry := null;
v_ship_prov := null;
v_shipto_customer_xref_nbr := null;
v_shipto_customer_xref_tag := null;
v_ship_cust_tag := null;
v_ship_ctry_iso := v_bill_ctry_iso;
RETURN(FALSE);
END;
FUNCTION get_ult(v_cust_trx_id number,
v_ult_cust_num varchar2,
v_ult_cust_tag varchar2)
RETURN boolean IS
BEGIN
SELECT c.customer_name ult_name,
rtrim(nvl(o.ultimate_address1, a.address1)) ult_add1,
rtrim(nvl(o.ultimate_address2, a.address2)) ult_add2,
rtrim(nvl(o.ultimate_address3, a.address3)) ult_add3,
rtrim(nvl(o.ultimate_address4, a.address4)) ult_add4,
rtrim(nvl(o.ultimate_city, a.city)) ult_city,
rtrim(nvl(o.ultimate_state, a.state)) ult_state,
rtrim(nvl(o.ultimate_postal_code, a.postal_code)) ult_pc,
rtrim(nvl(o.ultimate_county, a.county)) ult_cty,
rtrim(nvl(o.ultimate_country, t.territory_short_name)) ult_ctry,
rtrim(nvl(o.ultimate_province, a.province)) ult_prov,
substr(a.attribute1,1,4) ultimate_cust_tag
INTO v_ult_name,
v_ult_add1,
v_ult_add2,
v_ult_add3,
v_ult_add4,
v_ult_city,
v_ult_state,
v_ult_pc,
v_ult_cty,
v_ult_ctry,
v_ult_prov,
v_cof_ult_cust_tag
FROM ra_site_uses su,
fnd_territories t,
ra_addresses a,
arc_overrides o,
ra_customers c,
ra_customer_trx ct
WHERE ct.customer_trx_id = v_cust_trx_id
AND c.orig_system_reference = v_ult_cust_num
AND c.customer_id = a.customer_id
AND su.address_id = a.address_id
AND su.location = v_ult_cust_tag
AND su.site_use_code = 'SHIP_TO'
AND a.country = t.territory_code (+)
AND ct.customer_trx_id = o.customer_trx_id (+);
RETURN(TRUE);
EXCEPTION
WHEN OTHERS THEN
/* If no record found, default ultimate destination to ship to */
v_ult_name := v_ship_name;
v_ult_add1 := v_ship_add1;
v_ult_add2 := v_ship_add2;
v_ult_add3 := v_ship_add3;
v_ult_add4 := v_ship_add4;
v_ult_city := v_ship_city;
v_ult_state := v_ship_state;
v_ult_pc := v_ship_pc;
v_ult_cty := v_ship_cty;
v_ult_ctry := v_ship_ctry;
v_ult_prov := v_ship_prov;
v_cof_ult_cust_tag := v_ship_cust_tag;
RETURN(FALSE);
END;
FUNCTION get_remit(v_invoice_language_code varchar,
v_invoice_currency_code varchar,
v_remit_address1 varchar,
v_remit_address2 varchar,
v_remit_address3 varchar,
v_remit_address4 varchar)
RETURN boolean IS
BEGIN
SELECT word_value
into v_remit_add1
from arc_lang_translations
where rtrim(orig_value) = v_remit_address1
and lang_code = v_invoice_language_code;
SELECT word_value
into v_remit_add2
from arc_lang_translations
where rtrim(orig_value) = v_remit_address2
and lang_code = v_invoice_language_code;
/* IF v_invoice_currency_code = 'USD' THEN
v_remit_add2 := v_remit_add2||' 980651';
ELSE
v_remit_add2 := v_remit_add2||' 80651';
END IF; */
SELECT word_value
into v_remit_add3
from arc_lang_translations
where rtrim(orig_value) = v_remit_address3
and lang_code = v_invoice_language_code;
SELECT word_value
into v_remit_add4
from arc_lang_translations
where rtrim(orig_value) = v_remit_address4
and lang_code = v_invoice_language_code;
RETURN(TRUE);
EXCEPTION
WHEN OTHERS THEN
/* If no record found, default remit to null. */
v_remit_add1 := null;
v_remit_add2 := null;
v_remit_add3 := null;
v_remit_add4 := null;
RETURN(FALSE);
END;
FUNCTION get_tax_desc(v_cust_trx_id number)
RETURN varchar2 IS
v_desc arc_ip_headers.vat_tax_desc%TYPE;
BEGIN
/* Get tax code description from the first line. In Oracle it is */
/* possible to have multiple tax codes per invoice. Here, there */
/* should only be one, so we are only getting the desc from line 1*/
SELECT vt.attribute1
INTO v_desc
FROM ra_customer_trx_lines ctl,
ra_customer_trx_lines ctl_tax,
ar_vat_tax vt
WHERE ctl.customer_trx_id = v_cust_trx_id
AND ctl.line_type = 'LINE'
AND ctl.line_number = 1
AND ctl.customer_trx_line_id = ctl_tax.link_to_cust_trx_line_id
AND ctl_tax.vat_tax_id = vt.vat_tax_id;
RETURN(v_desc);
EXCEPTION
WHEN OTHERS THEN
v_tax_desc := null;
RETURN(v_desc);
END; -- get tax desc
FUNCTION inc_pos(v_value varchar2)
RETURN varchar2 IS
v_value2 varchar2(1);
BEGIN
IF (v_value in ('0','1', 'A','E','I','O','U','Y')) THEN
/* These are invalid values for this serial number format, */
/* Return the value passed in, so it forces the serials */
/* numbers to appear out of sequence. */
v_value2 := v_value;
ELSIF (v_value = 'Z') THEN
/* Z is the last value in the sequence, Return 2 which is the */
/* first value in the sequence. */
v_value2 := '2';
ELSIF (v_value = '9') THEN
/* 9 is the last numeric value in the sequence. Return B which */
/* is the first character value in the sequence. */
v_value2 := 'B';
ELSIF (v_value in ('D','H','N','T','X')) THEN
/* Vowels and Y are not used in serial numbers. For the letters */
/* prior to a vowel or Y, you must add 2 to get next value. */
SELECT chr(ascii(v_value) + 2)
INTO v_value2
FROM dual;
ELSE
SELECT chr(ascii(v_value) + 1)
INTO v_value2
FROM dual;
END IF;
RETURN(v_value2);
EXCEPTION
WHEN OTHERS THEN
RETURN(v_value);
END; -- increment serial number position value
FUNCTION get_next_ser(v_curr_ser varchar2)
RETURN varchar2 IS
v_rtr_value arc_ip_line_details.serial_number_from%TYPE;
v_ser_num_type VARCHAR2(20);
v_ser_num_len NUMBER;
v_base_f1 VARCHAR2(4);
v_pos1_f1 VARCHAR2(1);
v_pos2_f1 VARCHAR2(1);
v_pos3_f1 VARCHAR2(1);
v_pos4_f1 VARCHAR2(1);
v_pos5_f1 VARCHAR2(1);
v_pos6_f1 VARCHAR2(1);
chk_pos BOOLEAN;
start_pos NUMBER;
chk_value VARCHAR2(1);
v_char6_o VARCHAR2(6);
v_num4_o VARCHAR2(4);
BEGIN
/* Determine serial number format. Currently there are two formats */
/* Format 1 is NNNAAAAAAA where position four is B, X, or E */
/* Other is NNNAAANNNN where the first three positions are the APC, */
/* positions 4-6 are the supplier code, and the last four are numbers. */
SELECT DECODE(substr(v_curr_ser,4,1), 'B', 'format1', 'X', 'format1',
'E', 'format1', 'other'),
length(v_curr_ser)
INTO v_ser_num_type,
v_ser_num_len
FROM dual;
IF (v_ser_num_len = 10) THEN
IF (v_ser_num_type = 'format1') THEN
/* For this format, the last six positions are numbers or */
/* characters. Below is a table of the sequence values. */
/* */
/* Current Value Next Value */
/* 2 3 */
/* 3 4 */
/* 4 5 */
/* 5 6 */
/* 6 7 */
/* 7 8 */
/* 8 9 */
/* 9 B */
/* B C */
/* C D */
/* D F */
/* F G */
/* G H */
/* H J */
/* J K */
/* K L */
/* L M */
/* M N */
/* N P */
/* P Q */
/* Q R */
/* R S */
/* S T */
/* T V */
/* V W */
/* W X */
/* X Z */
/* Z 2 */
/* Build new serial number */
SELECT substr(v_curr_ser,1,4),
substr(v_curr_ser,5,1),
substr(v_curr_ser,6,1),
substr(v_curr_ser,7,1),
substr(v_curr_ser,8,1),
substr(v_curr_ser,9,1),
substr(v_curr_ser,10,1),
6
INTO v_base_f1,
v_pos1_f1,
v_pos2_f1,
v_pos3_f1,
v_pos4_f1,
v_pos5_f1,
v_pos6_f1,
start_pos
FROM dual;
chk_pos := TRUE;
WHILE chk_pos LOOP
IF (start_pos = 6) THEN
v_pos6_f1 := inc_pos(v_pos6_f1);
/* If the new value equals 2, then the previous position */
/* also needs to be incremented. Otherwise, exit loop. */
IF (v_pos6_f1 = '2') THEN
start_pos := start_pos - 1;
ELSE
chk_pos := FALSE;
END IF;
ELSIF (start_pos = 5) THEN
v_pos5_f1 := inc_pos(v_pos5_f1);
/* If the new value equals 2, then the previous position */
/* also needs to be incremented. Otherwise, exit loop. */
IF (v_pos5_f1 = '2') THEN
start_pos := start_pos - 1;
ELSE
chk_pos := FALSE;
END IF;
ELSIF (start_pos = 4) THEN
v_pos4_f1 := inc_pos(v_pos4_f1);
/* If the new value equals 2, then the previous position */
/* also needs to be incremented. Otherwise, exit loop. */
IF (v_pos4_f1 = '2') THEN
start_pos := start_pos - 1;
ELSE
chk_pos := FALSE;
END IF;
ELSIF (start_pos = 3) THEN
v_pos3_f1 := inc_pos(v_pos3_f1);
/* If the new value equals 2, then the previous position */
/* also needs to be incremented. Otherwise, exit loop. */
IF (v_pos3_f1 = '2') THEN
start_pos := start_pos - 1;
ELSE
chk_pos := FALSE;
END IF;
ELSIF (start_pos = 2) THEN
v_pos2_f1 := inc_pos(v_pos2_f1);
/* If the new value equals 2, then the previous position */
/* also needs to be incremented. Otherwise, exit loop. */
IF (v_pos2_f1 = '2') THEN
start_pos := start_pos - 1;
ELSE
chk_pos := FALSE;
END IF;
ELSIF (start_pos = 1) THEN
v_pos1_f1 := inc_pos(v_pos1_f1);
/* If the new value equals 2, then the previous position */
/* also needs to be incremented. For this position that */
/* is not valid. Return the original serial number sent */
/* to this function. */
IF (v_pos1_f1 = '2') THEN
RETURN(v_curr_ser);
ELSE
chk_pos := FALSE;
END IF;
END IF;
END LOOP;
v_rtr_value := v_base_f1 || v_pos1_f1 || v_pos2_f1 || v_pos3_f1 ||
v_pos4_f1 || v_pos5_f1 || v_pos6_f1;
ELSE
/* The other format has numbers in the last four positions. Add 1 to */
/* the number, and return the first six positions || (last four + 1) */

BEGIN
SELECT substr(v_curr_ser,1,6),
lpad((to_number(substr(v_curr_ser,7,4)) + 1), 4, '0')
INTO v_char6_o,
v_num4_o
FROM dual;
v_rtr_value := v_char6_o || v_num4_o;
EXCEPTION
WHEN OTHERS THEN
/* Error breaking up serial number, return the original serial */
/* number passed in. */
v_rtr_value := v_curr_ser;
END;
END IF; -- serial number type is format1 or other
ELSE
/* Serial number is in an unexpected format because length is not 10. */
/* Return the same value that was sent in. */
v_rtr_value := v_curr_ser;
END IF; -- length equals 10
RETURN(v_rtr_value);
END; -- get next serial number
BEGIN
v_err_text := 'Invalid print queue specified';
select print_server_queue
into v_print_server_queue
from arc_print_queues
where print_queue = p_invoice_print_queue;
/* Review invoice creation date parameter. If it is 01-JAN-2100, it is */
/* the default value from a scheduled concurrent request, change it */
/* to sysdate. (This is a work around because you can't schedule jobs in*/
/* the concurrent manager with the default of sysdate). If it is not */
/* that date but has a value, set the variable to that user specified */
/* value. If it has no value, set the variable to null. */
IF (p_inv_create_date = '01-JAN-2100') THEN
v_inv_create_date := trunc(sysdate);
ELSIF (p_inv_create_date is not null) THEN
v_inv_create_date := to_date(p_inv_create_date, 'DD-MON-YYYY');
ELSE
v_inv_create_date := null;
END IF;
v_concurrent_request_id := fnd_global.conc_request_id;
IF (v_concurrent_request_id is null) THEN
v_concurrent_request_id := -999;
END IF;
v_concurrent_user_id := fnd_global.user_id;
IF (v_concurrent_user_id is null) THEN
v_concurrent_user_id := -6;
END IF;
DBMS_OUTPUT.PUT_LINE('The concurrent request id is : ' || v_concurrent_request
_id);
SELECT l.location_code
INTO v_current_org_name
FROM hr_organization_units ou,
hr_locations l
WHERE ou.organization_id = p_organization_id
AND ou.location_id = l.location_id;
/* Open Main Cursor */
FOR x IN get_inv_hdrs LOOP
v_freight_total := 0;
v_insurance_total := 0;
v_tax_state_total := 0;
v_tax_county_total := 0;
v_tax_city_total := 0;
v_tax_rate := null;
v_inv_grand_total :=0;
v_inv_head_total := 0;
v_euro_grand_total := 0;
v_inv_line_total := 0;
v_err_text := 'Program inside invoice headers loop';
/* Get ship address information */
v_ship_name := null;
v_ship_add1 := null;
v_ship_add2 := null;
v_ship_add3 := null;
v_ship_add4 := null;
v_ship_city := null;
v_ship_state := null;
v_ship_pc := null;
v_ship_cty := null;
v_ship_ctry := null;
v_ship_prov := null;
v_bill_ctry_iso := x.bill_ctry_iso;
v_ship_get := get_ship_to(x.customer_trx_id,
x.ship_to_customer_id,
x.ship_to_site_use_id);
v_ult_get := get_ult(x.customer_trx_id,
x.ult_cust_num,
x.ult_cust_tag);
v_remit_add1 := x.remit_add1;
v_remit_add2 := x.remit_add2;
v_remit_add3 := x.remit_add3;
v_remit_add4 := x.remit_add4;
IF x.org_id = 134 THEN
v_remit_get := get_remit(x.invoice_language_code,
x.invoice_currency_code,
x.remit_add1,
x.remit_add2,
x.remit_add3,
x.remit_add4);
END IF;
/* Is the ship to within the EU */
v_eu_flag := get_eu_flag(x.trx_date,
v_ship_ctry_iso);
/* Get Euro Conversion Rates. EURO. */
currency_code :=get_currency_code(x.customer_trx_id);
v_euro_rate_conversion := get_euro_currency_rate(currency_code);
IF get_euro_currency_rate(currency_code) is not null THEN
v_euro_flag := 'Y';
ELSE
v_euro_flag := 'N';
END IF;
/* Get tax code description */
v_tax_desc := null;
v_tax_desc := get_tax_desc(x.customer_trx_id);
/* Compute invoice totals for tax, freight, and insurance */
BEGIN
SELECT COUNT(ct.extended_amount)
INTO freight_count
FROM ra_customer_trx_lines ct
WHERE nvl(ct.attribute5, '-6') in ('15','88')
AND ct.customer_trx_id = x.customer_trx_id;
/*-- Line types for a freight line */
EXCEPTION
WHEN NO_DATA_FOUND THEN
freight_count :=0;
END;
IF freight_count = 0 THEN
v_freight_total := 0;
ELSE
BEGIN
SELECT sum (ctl.extended_amount)
INTO v_freight_total
FROM ra_customer_trx_lines ctl
WHERE ctl.customer_trx_id = x.customer_trx_id
AND nvl(ctl.attribute5, '-6') in ('15','88');
/*-- Line types for a freight line */
EXCEPTION
WHEN OTHERS THEN
v_freight_total := 0;
END;
END IF;
FOR tl IN get_tax_lines(x.customer_trx_id) LOOP
v_err_text := 'Program inside tax lines loop';
IF (v_tax_rate is null) THEN
v_tax_rate := tl.tax_rate;
END IF;
IF (tl.tax_type = 'VAT') THEN
v_tax_state_total := v_tax_state_total + tl.extended_amount;
ELSIF (tl.tax_type = 'LOCATION') THEN
IF (tl.line_number = '1') THEN
v_tax_city_total := v_tax_city_total + tl.extended_amount;
ELSIF (tl.line_number = '2') THEN
v_tax_county_total := v_tax_county_total + tl.extended_amount;
ELSE
v_tax_state_total := v_tax_state_total + tl.extended_amount;
END IF;
ELSIF (tl.tax_type = 'SALES_TAX') THEN
IF (tl.tax_code = 'CITY TAX') THEN
v_tax_city_total := v_tax_city_total + tl.extended_amount;
ELSIF (tl.tax_code = 'COUNTY TAX') THEN
v_tax_county_total := v_tax_county_total + tl.extended_amount;
ELSE
v_tax_state_total := v_tax_state_total + tl.extended_amount;
END IF;
END IF;
END LOOP; -- end tax lines
/* For Poland we need to retrieve the tax rate and description even if no
tax is on the invoice for printing purposes */
If (x.org_id = 293) and (v_tax_rate is null) THEN
select tax_rate, attribute1
into v_tax_rate,
v_tax_desc
from ar_vat_tax_all
where x.org_id = 293 and tax_code = x.tax_code_v
and rownum = 1;
end if;
/* Need to add logic for insurance amount */
/* Add all the freight, tax, insurance */
v_invoice_currency_code := x.invoice_currency_code;
v_currency_dec_sep := x.currency_dec_sep;
v_currency_group_sep := x.currency_group_sep;
IF v_euro_flag = 'Y' THEN
v_invoice_currency_code := 'EUR';
v_currency_dec_sep := ',';
v_currency_group_sep := '.';
v_inv_head_total := v_inv_head_total/v_euro_rate_conversion;
v_freight_total := v_freight_total/v_euro_rate_conversion;
v_insurance_total := v_insurance_total/v_euro_rate_conversion;
v_tax_state_total := v_tax_state_total/v_euro_rate_conversion;
v_tax_county_total := v_tax_county_total/v_euro_rate_conversion;
v_tax_city_total := v_tax_city_total/v_euro_rate_conversion;
END IF;
v_inv_head_total := v_inv_head_total+ v_freight_total + v_insurance_total
+ v_tax_state_total +v_tax_county_total + v_tax_city_total;
IF v_euro_flag = 'Y' THEN
v_inv_head_total := round(v_inv_head_total, 2);
v_freight_total := round(v_freight_total, 2);
v_insurance_total := round(v_insurance_total, 2);
v_tax_state_total := round(v_tax_state_total, 2);
v_tax_county_total := round(v_tax_county_total, 2);
v_tax_city_total := round(v_tax_city_total, 2);
END IF;
/* Get ultimate destination country description and */
/* fob point description and due date. */
v_ult_dest_country_desc := get_udc_desc(x.customer_trx_id);
v_fob_point_desc := get_fob_desc(x.customer_trx_id);
IF x.org_id = 134 and x.invoice_language_code = 'FRC' THEN
v_fob_point_desc := get_frc_fob_desc(x.customer_trx_id);
END IF;
v_due_date := calc_due_date(x.term_id, x.trx_date);
v_bill_cust_tag := x.bill_cust_tag;
v_ultimate_cust_tag := x.ult_cust_tag;
IF x.org_id = 134 THEN
v_bill_cust_tag := x.billto_customer_cof_tag;
v_shipto_customer_xref_tag := v_ship_cust_tag;
v_ultimate_cust_tag := v_cof_ult_cust_tag;
END IF;
v_ship_via := x.ship_via;
IF x.org_id = 134 and x.invoice_language_code = 'FRC' THEN
BEGIN
select word_value
into v_ship_via
from arc_lang_translations
where rtrim(orig_value) = x.freight_code
and lang_code = x.invoice_language_code;
EXCEPTION
WHEN OTHERS THEN
v_ship_via := x.ship_via;
END;
END IF;
/* Load invoice header record into invoice print table */
INSERT INTO arc_ip_headers (ip_header_id,
concurrent_request_id,
remit_address1,
remit_address2,
remit_address3,
remit_address4,
remit_city,
remit_state,
remit_postal_code,
remit_county,
remit_country,
remit_province,
bill_customer_name,
bill_customer_number,
bill_customer_tag,
bill_address1,
bill_address2,
bill_address3,
bill_address4,
bill_city,
bill_state,
bill_postal_code,
bill_county,
bill_country,
bill_province,
bill_vat_reg_number,
ship_customer_name,
ship_address1,
ship_address2,
ship_address3,
ship_address4,
ship_city,
ship_state,
ship_postal_code,
ship_county,
ship_country,
ship_province,
customer_trx_id,
trx_number,
trx_date,
purchase_order_number,
purchase_order_date,
invoice_language_code,
invoice_currency_code,
payment_term_desc,
creation_date,
created_by,
last_update_date,
last_updated_by,
inv_freight_total,
inv_insurance_total,
inv_tax_state_total,
inv_tax_county_total,
inv_tax_city_total,
suppress_frequencies_flag,
suppress_serial_num_flag,
suppress_country_flag,
vat_tax_rate,
ult_dest_country_desc,
fob_point_desc,
invoice_format_code,
due_date,
vat_tax_desc,
currency_dec_sep,
currency_group_sep,
ship_from_address1,
ship_from_address2,
ship_from_address3,
ship_from_address4,
ship_from_city,
ship_from_state,
ship_from_postal_code,
ship_from_province,
ship_from_country,
type,
remit_acct_num,
complete_flag,
po_release_nbr,
ship_via,
pay_by_check_address,
pay_by_wire_address,
billto_customer_xref_nbr,
billto_customer_xref_tag,
shipto_customer_xref_nbr,
shipto_customer_xref_tag,
location_code,
process_area_code,
ult_customer_name,
ult_address1,
ult_address2,
ult_address3,
ult_address4,
ult_city,
ult_state,
ult_postal_code,
ult_county,
ult_country,
ult_province,
ult_customer_number,
ult_customer_tag,
bill_contact_name,
ship_contact_name,
print_flag,
mail_flag,
billing_terms_code,
cv_list_description,
inv_grand_total,
euro_grand_total,
owners_div_grp_code,
ship_ctry_iso,
eu_flag)
/* add one field */
( SELECT arc_ip_headers_s.nextval,
v_concurrent_request_id,
nvl(v_remit_add1, x.remit_add1),
nvl(v_remit_add2, x.remit_add2),
nvl(v_remit_add3, x.remit_add3),
nvl(v_remit_add4, x.remit_add4),
-- x.remit_city,
null,
-- x.remit_state,
null,
-- x.remit_pc,
null,
-- x.remit_cty,
null,
-- x.remit_ctry,
null,
-- x.remit_prov,
null,
x.bill_cust_name,
x.bill_cust_num,
v_bill_cust_tag,
x.bill_add1,
x.bill_add2,
x.bill_add3,
x.bill_add4,
x.bill_city,
x.bill_state,
x.bill_pc,
x.bill_cty,
x.bill_ctry,
x.bill_prov,
x.bill_vat_reg,
v_ship_name,
v_ship_add1,
v_ship_add2,
v_ship_add3,
v_ship_add4,
v_ship_city,
v_ship_state,
v_ship_pc,
v_ship_cty,
v_ship_ctry,
v_ship_prov,
x.customer_trx_id,
x.trx_number,
x.trx_date,
x.purchase_order,
x.purchase_order_date,
x.invoice_language_code,
v_invoice_currency_code,
x.description,
sysdate,
v_concurrent_user_id,
sysdate,
v_concurrent_user_id,
v_freight_total,
v_insurance_total,
v_tax_state_total,
v_tax_county_total,
v_tax_city_total,
substr(x.attribute7,1,1),
substr(x.attribute8,1,1),
'N',
v_tax_rate,
v_ult_dest_country_desc,
v_fob_point_desc,
x.attribute6,
v_due_date,
v_tax_desc,
v_currency_dec_sep,
v_currency_group_sep,
x.ship_from_add1,
x.ship_from_add2,
x.ship_from_add3,
x.ship_from_add4,
-- x.ship_from_city,
null,
-- x.ship_from_state,
null,
-- x.ship_from_pc,
null,
-- x.ship_from_prov,
null,
-- x.ship_from_ctry,
null,
x.type,
x.remit_acct_num,
DECODE(x.ready_to_inv_flag, 'N', 'D', DECODE(x.p
rint_status, 'Printed', 'F', DECODE(p_draft_final, 'F', DECODE(x.comp_flag, 'Y',
'F', 'D'), 'D'))),
-- x.comp_flag
x.po_release_nbr,
v_ship_via,
x.pay_by_check_address,
x.pay_by_wire_address,
x.billto_customer_xref_nbr,
x.billto_customer_xref_tag,
v_shipto_customer_xref_nbr,
v_shipto_customer_xref_tag,
x.location_code,
x.process_area_code,
v_ult_name,
v_ult_add1,
v_ult_add2,
v_ult_add3,
v_ult_add4,
v_ult_city,
v_ult_state,
v_ult_pc,
v_ult_cty,
v_ult_ctry,
v_ult_prov,
x.ult_cust_num,
v_ultimate_cust_tag,
null,
null,
x.print_flag,
x.mail_flag,
x.billing_terms_code,
x.cv_list_description,
v_inv_grand_total,
v_euro_grand_total,
x.owners_div_grp_code,
v_ship_ctry_iso,
v_eu_flag
FROM dual );
COMMIT; /*test purpose */
/* Load invoice additional information table. This table holds the packing */
/* list information, factory order number information, and contact info. */
/* It also holds header level notes. */
/* Insert note type T for dist_orgs FSLS and FISLS and payment term 76
for Credit Card Payments */
If (p_organization_id = 108) and (x.name like '%76%') and
(substr(x.process_area_code,1,2) in ('12', '90')) THEN
BEGIN
SELECT distinct note_type_code
INTO v_note_type
FROM arc_notes
WHERE customer_trx_id = x.customer_trx_id
AND note_type_code = 'Z';
EXCEPTION
WHEN NO_DATA_FOUND THEN
v_note_type := null;
END;
/* The note field is 255 characters. Can only pass 50 */
/* characters to print programs, so note records need to */
/* be parsed into chunks of 50. */
If v_note_type = 'Z' THEN
v_curr_cred_note := v_cred_note2;
else
v_curr_cred_note := v_cred_note;
end if;
v_temp_note := null;
v_cut_note_position := 0;
v_note_length := length(v_curr_cred_note);
/* If the note size is greater than the default size, it */
/* must be parsed. */
WHILE (v_note_length > v_note_size) LOOP
v_cut_note_position := instr(substr(v_curr_cred_note, 1,
v_note_size), 1);
/* If there is no space in the substrung text, cut the */
/* note at the default size. */
IF (v_cut_note_position = 0) THEN
v_cut_note_position := v_note_size;
END IF;
v_temp_note := substr(v_curr_cred_note, 1, v_cut_note_position);
/* If the user enters an @ in the first position, pass */
/* a blank line for the note. */
IF (substr(v_temp_note,1,1) = '@') THEN
v_temp_note := ' ';
END IF;
INSERT INTO arc_ip_info (ip_info_id,
ip_header_id,
ip_info_type_code,
ip_info_value11,
creation_date,
created_by,
last_update_date,
last_updated_by)
( SELECT arc_ip_info_s.nextval,
arc_ip_headers_s.currval,
'TNOTE',
v_temp_note,
sysdate,
v_concurrent_user_id,
sysdate,
v_concurrent_user_id
FROM dual );
/* Reset note text variable and note length variable */
v_curr_cred_note := substr(v_curr_cred_note,
(v_cut_note_position + 1));
v_temp_note := null;
v_note_length := length(v_curr_cred_note);
END LOOP; -- end while loop
v_temp_note := v_curr_cred_note;
INSERT INTO arc_ip_info (ip_info_id,
ip_header_id,
ip_info_type_code,
ip_info_value11,
creation_date,
created_by,
last_update_date,
last_updated_by)
( SELECT arc_ip_info_s.nextval,
arc_ip_headers_s.currval,
'TNOTE',
v_temp_note,
sysdate,
v_concurrent_user_id,
sysdate,
v_concurrent_user_id
FROM dual );
END IF;
/* Load packing list numbers */
FOR pl IN get_inv_pack_list(x.customer_trx_id) LOOP
v_err_text := 'Program inside invoice packing list loop';
INSERT INTO arc_ip_info (ip_info_id,
ip_header_id,
ip_info_type_code,
ip_info_value,
ip_info_value2,
ip_info_value3,
ip_info_value4,
ip_info_value5,
creation_date,
created_by,
last_update_date,
last_updated_by)
( SELECT arc_ip_info_s.nextval,
arc_ip_headers_s.currval,
'PACK_LIST',
pl.packing_list_nbr,
pl.ship_date_actual,
null,
null,
null,
sysdate,
v_concurrent_user_id,
sysdate,
v_concurrent_user_id
FROM dual );
END LOOP; -- end get invoice packing information loop
/* Load Motorola Reference Numbers (FO Numbers) */
FOR fo IN get_fo_nums(x.customer_trx_id) LOOP
v_err_text := 'Program inside invoice fo number loop';
INSERT INTO arc_ip_info (ip_info_id,
ip_header_id,
ip_info_type_code,
ip_info_value,
ip_info_value2,
ip_info_value3,
ip_info_value4,
ip_info_value5,
creation_date,
created_by,
last_update_date,
last_updated_by)
( SELECT arc_ip_info_s.nextval,
arc_ip_headers_s.currval,
'FO_NUMBER',
fo.sales_order,
null,
null,
null,
null,
sysdate,
v_concurrent_user_id,
sysdate,
v_concurrent_user_id
FROM dual );
END LOOP; -- end get fo number loop
/* Load info line, which contains phone number, fax number */
/* vat registered number, and registered number */
-- FOR inf IN get_info (x.bill_to_customer_id, x.bill_to_site_use_id) LOOP
OPEN get_info(x.bill_to_customer_id, x.bill_to_site_use_id, x.location_id);
FETCH get_info INTO inf;
IF (get_info%FOUND) THEN
v_err_text := 'Program inside of info loop';
INSERT INTO arc_ip_info (ip_info_id,
ip_header_id,
ip_info_type_code,
ip_info_value,
ip_info_value2,
ip_info_value3,
ip_info_value4,
ip_info_value5,
ip_info_value6,
ip_info_value7,
ip_info_value8,
ip_info_value9,
ip_info_value10,
creation_date,
created_by,
last_update_date,
last_updated_by)
( SELECT arc_ip_info_s.nextval,
arc_ip_headers_s.currval,
'INFO',
inf.telephone_number,
inf.fax_number,
inf.registered_number,
inf.vat_reg_number,
inf.reg_off1,
inf.reg_off2,
inf.reg_off3,
inf.collector_name,
null,
null,
sysdate,
v_concurrent_user_id,
sysdate,
v_concurrent_user_id
FROM dual );
ELSE
/* If profile information not found, insert an 'INFO' record */
/* anyway. 'INFO' record is required for printing. */

INSERT INTO arc_ip_info (ip_info_id,


ip_header_id,
ip_info_type_code,
ip_info_value,
ip_info_value2,
ip_info_value3,
ip_info_value4,
ip_info_value5,
creation_date,
created_by,
last_update_date,
last_updated_by)
( SELECT arc_ip_info_s.nextval,
arc_ip_headers_s.currval,
'INFO',
null,
null,
null,
null,
null,
sysdate,
v_concurrent_user_id,
sysdate,
v_concurrent_user_id
FROM dual );
END IF; -- end get_info found
CLOSE get_info;
-- END LOOP; -- end get info loop
/* Insert header level notes */
/* Header level notes are sourced from arc notes (where customer */
/* trx line id is null and from ra customer trx comments and/or */
/* internal notes. */
FOR hn IN get_header_notes(x.customer_trx_id) LOOP
INSERT INTO arc_ip_info (ip_info_id,
ip_header_id,
ip_info_type_code,
ip_info_value,
creation_date,
created_by,
last_update_date,
last_updated_by)
( SELECT arc_ip_info_s.nextval,
arc_ip_headers_s.currval,
'HNOTE',
hn.note,
sysdate,
v_concurrent_user_id,
sysdate,
v_concurrent_user_id
FROM dual );
END LOOP; -- end header notes loop
/* Insert comments */
/* Comments are sourced from arc notes (where customer */
/* trx line id is null and from ra customer trx comments and/or */
/* internal notes. Comments are now separated from header notes. */
/* JLS */
FOR cn IN get_comments(x.customer_trx_id) LOOP
INSERT INTO arc_ip_info (ip_info_id,
ip_header_id,
ip_info_type_code,
ip_info_value,
creation_date,
created_by,
last_update_date,
last_updated_by)
( SELECT arc_ip_info_s.nextval,
arc_ip_headers_s.currval,
'CNOTE',
cn.note,
sysdate,
v_concurrent_user_id,
sysdate,
v_concurrent_user_id
FROM dual );
END LOOP; -- end comments loop
/* Insert note type S for dist_orgs FSLS and FISLS */
/* Note type S is sourced from arc notes JLS */
If (p_organization_id = 108 and
substr(x.process_area_code,1,2) in ('12', '90')) OR
(x.billing_terms_code = 'BPJ') THEN
FOR ss IN get_snote(x.customer_trx_id) LOOP
/* The note field is 255 characters. Can only pass 50 */
/* characters to print programs, so note records need to */
/* be parsed into chunks of 50. */
v_temp_note := null;
v_curr_note := ss.note;
v_cut_note_position := 0;
v_note_length := length(v_curr_note);
/* If the note size is greater than the default size, it */
/* must be parsed. */
WHILE (v_note_length > v_note_size) LOOP
v_cut_note_position := instr(substr(v_curr_note, 1, v_note_size),
' ', -1);
/* If there is no space in the substrung text, cut the */
/* note at the default size. */
IF (v_cut_note_position = 0) THEN
v_cut_note_position := v_note_size;
END IF;
v_temp_note := substr(v_curr_note, 1, v_cut_note_position);
/* If the user enters an @ in the first position, pass */
/* a blank line for the note. */
IF (substr(v_temp_note,1,1) = '@') THEN
v_temp_note := ' ';
END IF;
INSERT INTO arc_ip_info (ip_info_id,
ip_header_id,
ip_info_type_code,
ip_info_value,
creation_date,
created_by,
last_update_date,
last_updated_by)
( SELECT arc_ip_info_s.nextval,
arc_ip_headers_s.currval,
'SNOTE',
v_temp_note,
sysdate,
v_concurrent_user_id,
sysdate,
v_concurrent_user_id
FROM dual );
/* Reset note text variable and note length variable */
v_curr_note := substr(v_curr_note, (v_cut_note_position + 1));
v_temp_note := null;
v_note_length := length(v_curr_note);
END LOOP; -- end while loop
v_temp_note := v_curr_note;
INSERT INTO arc_ip_info (ip_info_id,
ip_header_id,
ip_info_type_code,
ip_info_value,
creation_date,
created_by,
last_update_date,
last_updated_by)
( SELECT arc_ip_info_s.nextval,
arc_ip_headers_s.currval,
'SNOTE',
v_temp_note,
sysdate,
v_concurrent_user_id,
sysdate,
v_concurrent_user_id
FROM dual );
END LOOP; -- end snote loop
END IF;
/* Insert note type P for dist_orgs FSLS and FISLS and payment term 76
for Credit Card Payments */
/* If (p_organization_id = 108) and (x.name like '%76%') and
(substr(x.process_area_code,1,2) in ('12', '90')) THEN
BEGIN
SELECT distinct note_type_code
INTO v_note_type
FROM arc_notes
WHERE customer_trx_id = x.customer_trx_id
AND note_type_code = 'Z';
EXCEPTION
WHEN NO_DATA_FOUND THEN
v_note_type := null;
END;

If v_note_type = 'Z' THEN


v_curr_note := v_cred_note2;
else
v_curr_note := v_cred_note;
end if;
v_temp_note := null;
v_cut_note_position := 0;
v_note_length := length(v_curr_note);
WHILE (v_note_length > v_note_size) LOOP
v_cut_note_position := instr(substr(v_curr_note, 1, v_note_size),
1);
IF (v_cut_note_position = 0) THEN
v_cut_note_position := v_note_size;
END IF;
v_temp_note := substr(v_curr_note, 1, v_cut_note_position);
IF (substr(v_temp_note,1,1) = '@') THEN
v_temp_note := ' ';
END IF;
INSERT INTO arc_ip_info (ip_info_id,
ip_header_id,
ip_info_type_code,
ip_info_value,
creation_date,
created_by,
last_update_date,
last_updated_by)
( SELECT arc_ip_info_s.nextval,
arc_ip_headers_s.currval,
'TNOTE',
v_temp_note,
sysdate,
v_concurrent_user_id,
sysdate,
v_concurrent_user_id
FROM dual );
v_curr_note := substr(v_curr_note, (v_cut_note_position + 1));
v_temp_note := null;
v_note_length := length(v_curr_note);
END LOOP; -- end while loop
v_temp_note := v_curr_note;

INSERT INTO arc_ip_info (ip_info_id,


ip_header_id,
ip_info_type_code,
ip_info_value,
creation_date,
created_by,
last_update_date,
last_updated_by)
( SELECT arc_ip_info_s.nextval,
arc_ip_headers_s.currval,
'TNOTE',
v_temp_note,
sysdate,
v_concurrent_user_id,
sysdate,
v_concurrent_user_id
FROM dual );
END IF; */
/* */
/* Load invoice item lines */
/* */
FOR l IN get_inv_lines(x.customer_trx_id, x.attribute6) LOOP
v_err_text := 'Program inside invoice lines loop';
/* Make sure the line item number field retrieved by the cursor */
/* does not have an asterisk in it. That is possible for */
/* exploded CDA lines. In that case return the value after the */
/* asterisk. */
/* Same for item_number. */
IF (instr(l.line_item_number, '*') > 0) THEN
v_line_item_number :=
substr(l.line_item_number, instr(l.line_item_number, '*') + 1);
ELSE
v_line_item_number := l.line_item_number;
END IF;
IF (instr(l.item_number, '*') > 0) THEN
v_item_number :=
substr(l.item_number, instr(l.item_number, '*') + 1);
ELSE
v_item_number := l.item_number;
END IF;
v_unit_price := l.unit_price;
v_extended_price := l.extended_price;
v_list_price := l.list_price;
IF v_euro_flag = 'Y' THEN
v_unit_price := round(v_unit_price/v_euro_rate_conversion, 2);
v_extended_price := round(v_extended_price/v_euro_rate_conversion,2);
v_list_price := round(v_list_price/v_euro_rate_conversion,2);
END IF;
INSERT INTO arc_ip_lines (ip_line_id,
ip_header_id,
concurrent_request_id,
customer_trx_id,
customer_trx_line_id,
line_type_code,
line_item_number,
ar_line_number,
invoice_quantity,
country_of_origin,
item_number,
item_description,
unit_price,
extended_price,
creation_date,
created_by,
last_update_date,
last_updated_by,
order_type_code,
ship_date,
list_price,
packing_list_number,
apc_code)
( SELECT arc_ip_lines_s.nextval,
arc_ip_headers_s.currval,
v_concurrent_request_id,
l.customer_trx_id,
l.customer_trx_line_id,
l.line_type_code,
v_line_item_number,
l.ar_line_number,
l.invoice_quantity,
l.country_of_origin,
v_item_number,
l.item_description,
v_unit_price,
v_extended_price,
sysdate,
v_concurrent_user_id,
sysdate,
v_concurrent_user_id,
l.order_type_code,
l.ship_date,
v_list_price,
l.pack_list_num,
l.apc_code
FROM dual );
IF ( l.customer_trx_line_id is not null ) THEN
/* Load supporting information for this invoice line */
/* Supporting information includes serial numbers and */
/* frequencies. */
v_old_serial_number := null;
v_start_serial_number := null;
v_old_waybill_number := null;
IF (l.customer_trx_line_id = -1) THEN
/* Determine how many serial numbers there are for this */
/* customer view or purchase order view line. */
SELECT count(*)
INTO v_serial_count
FROM arc_serial_numbers sn,
ra_customer_trx_lines ctl
WHERE ctl.customer_trx_id = l.customer_trx_id
AND ctl.attribute7 = l.cv_grp_nbr
AND ctl.customer_trx_line_id = sn.customer_trx_line_id;
ELSE
/* Determine how many serial numbers there are for this */
/* equipment line. */
SELECT count(*)
INTO v_serial_count
FROM arc_serial_numbers sn
WHERE sn.customer_trx_line_id = l.customer_trx_line_id
AND sn.customer_trx_id = l.customer_trx_id;
END IF;
FOR sn IN get_inv_ser_nums(l.customer_trx_line_id,
l.cv_grp_nbr,
l.customer_trx_id) LOOP
v_err_text := 'Program inside serial numbers loop';
/* */
/* Check to see if the serial numbers are sequential */
/* */
IF (get_inv_ser_nums%ROWCOUNT = 1) THEN
v_old_serial_number := sn.serial_number;
v_start_serial_number := sn.serial_number;
v_old_waybill_number := sn.waybill_number;
ELSE
/* Determine what the next serial number in the sequence */
/* should be. */

/* Serial number ranges are only allowed for certain dist */


/* orgs (customer profile classes). Check the flag for */
/* the dist org this customer is in. If yes, call the */
/* function to get what the next serial number should be. */
/* Otherwise, set the varaible to the last value, which */
/* forces the serial numbers to look out of sequence. */
IF ((x.ser_range_ok = 'Y') AND
(x.attribute6 != 'EDI')) THEN
v_seq_serial_number := get_next_ser(v_old_serial_number);
ELSE
v_seq_serial_number := v_old_serial_number;
END IF;
IF ( v_seq_serial_number = sn.serial_number) THEN
/* serial numbers are in sequence, keep looping */
v_old_serial_number := sn.serial_number;
v_old_waybill_number := sn.waybill_number;
ELSE
/* the most recent two serial numbers are not in */
/* sequence, insert previous serial number record */
INSERT INTO arc_ip_line_details (ip_line_detail_id,
ip_line_id,
detail_type_code,
serial_number_from,
serial_number_to,
creation_date,
created_by,
last_update_date,
last_updated_by,
waybill_number)
( SELECT arc_ip_line_details_s.nextval,
arc_ip_lines_s.currval,
'SERNUM',
v_start_serial_number,
DECODE(v_old_serial_number, v_
start_serial_number, null, v_old_serial_number),
sysdate,
v_concurrent_user_id,
sysdate,
v_concurrent_user_id,
v_old_waybill_number
FROM dual );
v_old_serial_number := sn.serial_number;
v_start_serial_number := sn.serial_number;
v_old_waybill_number := sn.waybill_number;
END IF; -- end serial number comparison
END IF; -- end rowcount is 1
IF (get_inv_ser_nums%ROWCOUNT = v_serial_count) THEN
/* This is the last record, need to insert a record */
v_err_text := 'Program inside serial numbers loop';
INSERT INTO arc_ip_line_details (ip_line_detail_id,
ip_line_id,
detail_type_code,
serial_number_from,
serial_number_to,
creation_date,
created_by,
last_update_date,
last_updated_by,
waybill_number)
( SELECT arc_ip_line_details_s.nextval,
arc_ip_lines_s.currval,
'SERNUM',
v_start_serial_number,
DECODE(v_old_serial_number, v_st
art_serial_number, null, v_old_serial_number),
sysdate,
v_concurrent_user_id,
sysdate,
v_concurrent_user_id,
v_old_waybill_number
FROM dual );
END IF; -- end rowcount is last row
END LOOP; -- end get serial numbers loop
/* Load frequency records */
v_err_text := 'Program inside frequencies loop'|| l.customer_trx_line_id;

FOR f IN get_inv_freqs(l.customer_trx_line_id,
l.cv_grp_nbr,
l.customer_trx_id) LOOP
INSERT INTO arc_ip_line_details (ip_line_detail_id,
ip_line_id,
detail_type_code,
freq_zone,
freq_transmit_number,
freq_receive_number,
freq_transmit_squelch_code,
freq_receive_squelch_code,
creation_date,
created_by,
last_update_date,
last_updated_by )
( SELECT arc_ip_line_details_s.nextval,
arc_ip_lines_s.currval,
'FREQ',
f.freq_zone,
f.transmit_freq_number,
f.receive_freq_number,
f.transmit_squelch_code,
f.receive_squelch_code,
sysdate,
v_concurrent_user_id,
sysdate,
v_concurrent_user_id
FROM dual );
END LOOP; -- end frequencies loop
/* Load Line Level Notes */
/* Line notes are stored in the arc notes table where */
/* the customer trx line id is not null and in */
/* customer trx lines attribute6. */
FOR n in get_line_notes(l.customer_trx_line_id) LOOP
/* The note field is 255 characters. Can only pass 50 */
/* characters to print programs, so note records need to */
/* be parsed into chunks of 50. */
v_temp_note := null;
v_curr_note := n.note_text;
v_cut_note_position := 0;
v_note_length := length(v_curr_note);
/* If the note size is greater than the default size, it */
/* must be parsed. */
WHILE (v_note_length > v_note_size) LOOP
/* Substring the note to the default length. Then find*/
/* the first space from the end of the substrung note. */
/* That is the first note. This should eliminate */
/* cutting words up. */
/* If note type is ^, the note was entered in AR1. It */
/* will be space padded in 50 character blocks. */
IF (n.note_type_code = '^') THEN
v_cut_note_position := 50;
ELSE
v_cut_note_position := instr(substr(v_curr_note, 1, v_note_size),
' ', -1);
END IF;
/* If there is no space in the substrung text, cut the */
/* note at the default size. */
IF (v_cut_note_position = 0) THEN
v_cut_note_position := v_note_size;
END IF;
v_temp_note := substr(v_curr_note, 1, v_cut_note_position);
/* If the user enters an @ in the first position, pass */
/* a blank line for the note. */
IF (substr(v_temp_note,1,1) = '@') THEN
v_temp_note := ' ';
END IF;
INSERT INTO arc_ip_line_details (ip_line_detail_id,
ip_line_id,
detail_type_code,
note_text,
creation_date,
created_by,
last_update_date,
last_updated_by,
note_type_code)
( SELECT arc_ip_line_details_s.nextval,
arc_ip_lines_s.currval,
'LNOTE',
v_temp_note,
sysdate,
v_concurrent_user_id,
sysdate,
v_concurrent_user_id,
n.note_type_code
FROM dual );
/* Reset note text variable and note length variable */
v_curr_note := substr(v_curr_note, (v_cut_note_position + 1));
v_temp_note := null;
v_note_length := length(v_curr_note);
END LOOP; -- end note size while
/* Insert either the remainder of the note or the */
/* original note if it was less than the defaul size. */
v_temp_note := v_curr_note;
INSERT INTO arc_ip_line_details (ip_line_detail_id,
ip_line_id,
detail_type_code,
note_text,
creation_date,
created_by,
last_update_date,
last_updated_by,
note_type_code)
( SELECT arc_ip_line_details_s.nextval,
arc_ip_lines_s.currval,
'LNOTE',
v_temp_note,
sysdate,
v_concurrent_user_id,
sysdate,
v_concurrent_user_id,
n.note_type_code
FROM dual );

END LOOP; -- end line notes cursor

END IF; -- end customer trx line is null


v_err_text := 'Program left if' || l.customer_trx_line_id;
v_inv_line_total := v_inv_line_total + v_extended_price;

END LOOP; -- end get invoice item lines loop


v_err_text := 'Program left lines loop';
If (p_organization_id = 108) and (x.name like '%76%') and
(substr(x.process_area_code,1,2) in ('12', '90')) THEN
v_inv_grand_total := 0;
else
v_inv_grand_total :=v_inv_grand_total +v_inv_head_total +v_inv_line_total;
end if;
/* Move Euro conversion to after first cursor. EURO. */
/* currency_code :=get_currency_code(x.customer_trx_id);
v_euro_rate_conversion := get_euro_currency_rate(currency_code);
IF( (get_currency_code(x.customer_trx_id) = 'ATS') or
(get_currency_code(x.customer_trx_id) = 'BEF') or
(get_currency_code(x.customer_trx_id) = 'DEM') or
(get_currency_code(x.customer_trx_id) = 'ESP') or
(get_currency_code(x.customer_trx_id) = 'FIM') or
(get_currency_code (x.customer_trx_id) = 'FRF') or
(get_currency_code(x.customer_trx_id) = 'IEP') or
(get_currency_code (x.customer_trx_id)= 'ITL') or
(get_currency_code (x.customer_trx_id)= 'LUF') or
(get_currency_code(x.customer_trx_id) = 'NLG') or
(get_currency_code(x.customer_trx_id) = 'PTE') ) THEN */
v_euro_grand_total := v_inv_grand_total/v_euro_rate_conversion;
--END IF;
/* update the grand total price */
UPDATE arc_ip_headers
SET inv_grand_total = v_inv_grand_total,
euro_grand_total=v_euro_grand_total
WHERE customer_trx_id = x.customer_trx_id;
END LOOP; -- end get invoice headers loop
v_err_text := 'Program left headers loop';
COMMIT;
If p_organization_id = 134 THEN
BEGIN
v_err_text := 'Entering get_can_header loop';
FOR ch IN get_can_header LOOP
IF ch.inv_grand_total < 0 THEN
v_document_type := 'CM';
v_invoice_class := 'CM';
ELSE
v_document_type := 'PR';
v_invoice_class := 'INV';
END IF;
IF ch.payment_term_desc like '%90%' THEN
v_additional_note_nbr := '1';
ELSE
v_additional_note_nbr := null;
END IF;
BEGIN
select ip_info_value
into v_lead_fo
from arc_ip_info
where ip_header_id = ch.ip_header_id
and ip_info_type_code = 'FO_NUMBER'
and rownum = 1;
EXCEPTION
WHEN OTHERS THEN
v_lead_fo := null;
END;
BEGIN
select ip_info_value, ip_info_value3, ip_info_value4
into v_phone_number,
v_gst_tax_reg_number,
v_pst_tax_reg_number
from arc_ip_info
where ip_header_id = ch.ip_header_id
and ip_info_type_code = 'INFO';
EXCEPTION
WHEN OTHERS THEN
v_phone_number := null;
v_gst_tax_reg_number := null;
v_pst_tax_reg_number := null;
END;
/* Get Canada tax descriptions */
select word_value
into v_gst_hst_desc
from arc_lang_translations
where rtrim(orig_value) = 'GST/HST'
and lang_code = ch.invoice_language_code;
IF ch.ship_state = 'PQ' THEN
select word_value
into v_pst_desc
from arc_lang_translations
where rtrim(orig_value) = 'PST PQ'
and lang_code = ch.invoice_language_code;
ELSE
select word_value
into v_pst_desc
from arc_lang_translations
where rtrim(orig_value) = 'PST'
and lang_code = ch.invoice_language_code;
END IF;
BEGIN
select ip_info_value2 into v_ship_date
from arc_ip_info
where ip_header_id = ch.ip_header_id
and ip_info_type_code = 'PACK_LIST'
and rownum = 1;
EXCEPTION
WHEN OTHERS THEN
v_ship_date := null;
END;
v_note_count := 0;
v_header_note := null;
v_inv_note := null;
v_err_text := 'Entering get_can_notes loop';
FOR gcn IN get_can_notes(ch.ip_header_id) LOOP
IF v_note_count < 9 THEN
v_header_note := v_header_note || gcn.ip_info_value || ' ';
v_note_count := v_note_count + 1;
ELSE
v_inv_note := v_inv_note || gcn.ip_info_value || ' ';
END IF;
END LOOP; /* end can notes loop */
v_err_text := 'Inserting into motinvm_header';
INSERT INTO motinvm_header
(ip_header_id,
customer_trx_id,
document_type,
invoice_number,
original_invoice_number,
invoice_type,
invoice_class,
sales_order_number,
additional_so,
organization_id,
document_date,
purchase_order_number,
purchase_order_date,
fob_point_desc,
payment_term_desc,
payment_due_date,
bill_contact_name,
bill_phone_number,
customer_code,
location_tag,
price_level_code,
process_area,
original_invoice_date,
remit_customer_name,
remit_address1,
remit_city,
remit_state,
remit_postal_code,
remit_country,
bill_customer_number,
bill_customer_tag,
bill_customer_name,
bill_location_name,
bill_attn_line,
bill_address1,
bill_address2,
bill_city,
bill_state,
bill_postal_code,
bill_country,
ship_customer_number,
ship_customer_tag,
ship_customer_name,
ship_location_name,
ship_attn_line,
ship_address1,
ship_address2,
ship_city,
ship_state,
ship_postal_code,
ship_country,
ult_customer_number,
ult_location_name,
ult_attn_line,
ult_customer_tag,
ult_address1,
ult_address2,
ult_city,
ult_state,
ult_postal_code,
ult_country,
equip_inv_total,
invoice_sub_total,
total_amount_due,
ship_via,
waybill_number,
inv_freight_total,
inv_tax_state_total,
inv_tax_county_total,
inv_tax_city_total,
inv_tax_total,
print_flag,
cof_payment_terms,
mail_flag,
restock_amount,
prompt_pay_amount,
order_header_notes,
inv_header_notes,
inv_mgr_flag,
ar2_flag,
rpg_flag,
dom_or_int,
impact_customer,
impact_flag,
date_created,
bill_to_province,
ship_to_province,
inv_tax_gst_hst_total,
inv_tax_pst_total,
language_code,
tax_gst_hst_desc,
tax_pst_desc,
set_of_books_id,
ship_date_actual,
shipping_terms,
currency_code,
concurrent_request_id,
tax_registration_number,
additional_note_number)
(select ch.ip_header_id,
ch.customer_trx_id,
v_document_type,
ch.trx_number,
null,
null,
v_invoice_class,
v_lead_fo,
null,
null,
ch.trx_date,
substr(ch.purchase_order_number,1,30),
ch.purchase_order_date,
ch.fob_point_desc,
ch.payment_term_desc,
ch.due_date,
null,
v_phone_number,
ch.bill_customer_number,
ch.bill_customer_tag,
null,
ch.process_area_code,
null,
ch.remit_address1,
ch.remit_address2,
ch.remit_address3,
null,
null,
ch.remit_address4,
ch.bill_customer_number,
ch.bill_customer_tag,
substr(ch.bill_customer_name,1,25),
substr(ch.bill_address1,1,25),
ch.bill_address4,
ch.bill_address2,
ch.bill_address3,
ch.bill_city,
ch.bill_state,
ch.bill_postal_code,
ch.bill_country,
ch.bill_customer_number,
ch.shipto_customer_xref_tag,
substr(ch.ship_customer_name,1,25),
substr(ch.ship_address1,1,25),
ch.ship_address4,
ch.ship_address2,
ch.ship_address3,
ch.ship_city,
ch.ship_state,
ch.ship_postal_code,
ch.ship_country,
ch.bill_customer_number,
substr(ch.ult_customer_name,1,25),
ch.ult_address4,
ch.ult_customer_tag,
ch.ult_address2,
ch.ult_address3,
ch.ult_city,
ch.ult_state,
ch.ult_postal_code,
ch.ult_country,
ch.equip_inv_total,
ch.invoice_sub_total,
ch.inv_grand_total,
ch.ship_via,
null,
ch.inv_freight_total,
null,
null,
null,
null,
ch.print_flag,
null,
ch.mail_flag,
null,
null,
v_header_note,
v_inv_note,
null,
null,
null,
'INT',
null,
null,
ch.creation_date,
ch.bill_state,
ch.ship_state,
ch.inv_tax_state_total,
ch.inv_tax_county_total,
decode(ch.invoice_language_code, 'CAE', 'ENG', 'FRC', 'FRN'),
v_gst_hst_desc,
v_pst_desc,
null,
v_ship_date,
ch.fob_point_desc,
ch.invoice_currency_code,
ch.concurrent_request_id,
null,
v_additional_note_nbr
from dual);
COMMIT;
v_err_text := 'Entering get_can_lines loop';
v_old_waybill_number := null;
v_line_sequence_nbr := 0;
FOR cl IN get_can_lines(ch.customer_trx_id,
ch.concurrent_request_id) LOOP
v_line_sequence_nbr := v_line_sequence_nbr + 1;
v_err_text := 'Entering get_can_fo_packlist loop';
FOR cf IN get_can_fo_packlist(cl.customer_trx_id,
cl.customer_trx_line_id) LOOP
v_line_note := null;
v_err_text := 'Entering get_can_line_notes loop';
FOR cln IN get_can_line_notes(cl.ip_line_id) LOOP
v_line_note := v_line_note || cln.note_text || ' ';
END LOOP; /* end line note loop */
INSERT into motinvm_lines
(customer_trx_id,
customer_trx_line_id,
invoice_number,
line_number,
line_sequence_number,
line_sub_number,
sales_order_number,
so_line_id,
quantity_invoiced,
unit_selling_price,
extended_amount,
inventory_item_id,
description,
motorola_part_number,
original_item,
unit_of_measure,
credit_quantity,
line_note,
from_serial_number,
to_serial_number,
frequency_att1,
frequency_att2,
frequency_att3,
frequency_att4,
frequency_att7,
frequency_att8,
frequency_att9,
frequency_att10,
apc_code,
inv_mgr_flag,
impact_flag,
restock_amount,
prompt_pay_amount,
date_created,
packing_list_number,
ship_date,
concurrent_request_id,
UNIT_PRICE_PP_RES,
EXTENDED_AMOUNT_PP_RES,
LINE_SORT_1,
LINE_SORT_2,
LINE_SORT_3,
LINE_SORT_4,
LINE_SORT_5,
LINE_SORT_6,
LINE_SORT_7)
(select cl.customer_trx_id,
cl.customer_trx_line_id,
ch.trx_number,
cl.line_item_number,
v_line_sequence_nbr,
decode(cl.line_type_code, 'ML', null, cl.item_number),
cf.order_nbr,
null,
decode(cl.line_type_code, 'ML', null,
decode(v_invoice_class, 'CM', null, cl.invoice_quantity)),
decode(cl.line_type_code, 'ML', null, cl.unit_price),
decode(cl.line_type_code, 'ML', null, cl.extended_price),
null,
cl.item_description,
cl.part_number,
null,
null,
decode(cl.line_type_code, 'ML', null,
decode(v_invoice_class, 'INV', null, cl.invoice_quantity)),
v_line_note,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
cl.apc_code,
null,
null,
null,
null,
cl.creation_date,
cf.pack_list,
cf.pack_ship_date,
cl.concurrent_request_id,
null,
null,
v_line_sequence_nbr,
0,
0,
0,
0,
0,
0
from dual);
v_err_text := 'Entering get_can_sernum loop';
FOR cs IN get_can_sernum(cl.ip_line_id) LOOP
IF cs.waybill_number is not null THEN
v_old_waybill_number := cs.waybill_number;
END IF;
INSERT INTO motar_serial_numbers
(invoice_number,
line_number,
so_line_id,
from_serial_number,
to_serial_number,
waybill_number,
inv_mgr_flag,
impact_flag,
date_created,
concurrent_request_id)
(select ch.trx_number,
cl.line_item_number,
null,
cs.serial_number_from,
cs.serial_number_to,
cs.waybill_number,
null,
null,
cs.creation_date,
cl.concurrent_request_id
from dual);
END LOOP; /* end serial number loop */
END LOOP; /* end fo packlist loop */
END LOOP; /* end line loop */
UPDATE motinvm_header
set waybill_number = v_old_waybill_number
where customer_trx_id = ch.customer_trx_id
and concurrent_request_id = ch.concurrent_request_id;
COMMIT;
END LOOP; /* end can headers loop */
COMMIT;
END;
end if;
/* Submit the print invoices job */
IF (nvl(p_region_name, 'X') = 'US EXP') THEN
ftp_region_v := 'MTI';
ELSE
IF (nvl(p_region_name, 'X') = 'PTRK EXP') THEN
ftp_region_v := 'PTR';
END IF;
END IF;
IF (SQL%ROWCOUNT > 0) THEN
IF (nvl(p_region_name, 'X') in ('US EXP', 'PTRK EXP') and
nvl(p_imaging_flag, 'N') = 'Y') THEN
v_inv_print_prog := 'ARCIPTEX';
v_set_printer_format := fnd_request.set_print_options('teams2',
'LANDSCAPE',
0,
v_save_output_b,
'N');
v_submit_request_id := fnd_request.submit_request('ARC',
v_inv_print_prog,
null,
null,
null,
v_concurrent_request_id,
1);
IF (nvl(v_submit_request_id,0) = 0) THEN
RETCODE := 2;
ERRBUF := ('Unable to submit program ' || v_inv_print_prog || '.');
END IF;
ftp_filename_v := 'o' || v_submit_request_id || '.out';
v_submit_request_id := fnd_request.submit_request('ARC',
'ARCFTPIMG',
null,
null,
null,
ftp_filename_v,
ftp_hoststring_v,
ftp_region_v);
IF (nvl(v_submit_request_id,0) = 0) THEN
RETCODE := 2;
ERRBUF := ('Unable to FTP file ARCFTPIMG.');
END IF;
END IF;
fnd_profile.get('PRINTER', v_printer);
v_get_printer_format := fnd_concurrent.get_request_print_options
(v_concurrent_request_id,
v_number_of_copies,
v_print_style,
v_cc_printer,
v_save_output);
IF (v_save_output = 'Y') THEN
v_save_output_b := TRUE;
ELSE
v_save_output_b := FALSE;
END IF;
IF (v_number_of_copies = 0) THEN
v_set_printer_format := fnd_request.set_print_options(v_cc_printer,
v_print_style,
0,
v_save_output_b,
'N');
ELSE
v_set_printer_format := fnd_request.set_print_options(v_cc_printer,
v_print_style,
1,
v_save_output_b,
'N');
END IF;
BEGIN
SELECT attribute1
INTO v_inv_print_prog
FROM hr_organization_units
WHERE organization_id = p_organization_id
AND attribute1 is not null;
EXCEPTION
WHEN OTHERS THEN
v_inv_print_prog := 'ARCIP2';
END;
IF (nvl(p_region_name, 'X') in ('US DOM', 'PTRK DOM')) THEN
v_inv_print_prog := 'ARCEXINM';
END IF;
IF (v_number_of_copies = 0) THEN
v_invoice_copies := 1;
ELSE
v_invoice_copies := v_number_of_copies;
END IF;
IF p_organization_id = 134 THEN
IF p_invoice_print_queue is not null THEN
v_err_text := 'Invalid print queue';
select print_server_queue
into v_print_server_queue
from arc_print_queues
where print_queue = p_invoice_print_queue;
END IF;
v_set_printer_format := fnd_request.set_print_options('ORCCI1',
'LANDSCAPE',
v_invoice_copies,
v_save_output_b,
'N');
v_printer := 'ORCCI1';
v_submit_request_id := fnd_request.submit_request('ARC',
v_inv_print_prog,
null,
null,
null,
v_concurrent_request_id,
p_draft_final,
v_invoice_copies,
v_print_server_queue,
v_printer);
ELSE
v_submit_request_id := fnd_request.submit_request('ARC',
v_inv_print_prog,
null,
null,
null,
v_concurrent_request_id,
v_printer,
v_invoice_copies);
END IF;
IF (nvl(v_submit_request_id,0) = 0) THEN
RETCODE := 2;
ERRBUF := ('Unable to submit program ' || v_inv_print_prog || '.');
END IF;
END IF;
EXCEPTION
WHEN OTHERS THEN
RETCODE := 2;
ERRBUF := ('The program errored with the following error :' || v_err_te
xt || ' >>> Oracle error of : ' || SQLERRM );
END;
/

You might also like