12
12
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;
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. */
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 );