Vous êtes sur la page 1sur 122

REM +======================================================================+

REM | Copyright (c) 1996, 2014 Oracle Corporation Redwood Shores, California, US
A|
REM |
All rights reserved.
|
REM +======================================================================+
REM NAME
JAI_OM_TAX_PROCESSING_PKG
REM
REM DESCRIPTION Package
REM
REM NOTES
REM---------------------------------------------------------------------------------REM This package comes from JAI_OE_OLA_TRIGGER_PKG for JAI Trigger Elimination p
roject.
REM Some fnd log information is added.
REM----------------------------------------------------------------------------------REM HISTORY
REM
REM+======================================================================+
REM dbdrv: sql ~PROD ~PATH ~FILE none none none sqlplus &phase=plb+1 checkfile(1
20.0.12010000.37=120.0.12020000.30):~PROD:~PATH:~FILE
SET VERIFY OFF
WHENEVER SQLERROR EXIT FAILURE ROLLBACK;
WHENEVER OSERROR EXIT FAILURE ROLLBACK;
CREATE OR REPLACE PACKAGE BODY JAI_OM_TAX_PROCESSING_PKG AS
/* $Header: jai_om_tax_p.plb 120.0.12020000.30 2014/03/25 10:16:11 mmurtuza no
ship $ */
--+===========================================================================
=================================+
--| Fixed History
|
--|
16/Oct/2012 Zhiwei.Xin
Modified for bug 14669425
|
--|
Fixed Details:
|
--|
Modifed cursor c_get_quantity for fetching shi
pped line quantity.
|
--+=============================================================================
===============================*/
G_PKG_NAME
G_CURRENT_RUNTIME_LEVEL
G_LEVEL_UNEXPECTED
G_LEVEL_ERROR
G_LEVEL_EXCEPTION
G_LEVEL_EVENT
G_LEVEL_PROCEDURE
G_LEVEL_STATEMENT
G_MODULE_NAME
NG_PKG.';

CONSTANT
CONSTANT
CONSTANT
CONSTANT
CONSTANT
CONSTANT
CONSTANT
CONSTANT
CONSTANT

VARCHAR2(30) := 'JAI_OM_TAX_PROCESSING_PKG';
NUMBER := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
NUMBER := FND_LOG.LEVEL_UNEXPECTED;
NUMBER := FND_LOG.LEVEL_ERROR;
NUMBER := FND_LOG.LEVEL_EXCEPTION;
NUMBER := FND_LOG.LEVEL_EVENT;
NUMBER := FND_LOG.LEVEL_PROCEDURE;
NUMBER := FND_LOG.LEVEL_STATEMENT;
VARCHAR2(60) := 'JA.PLSQL.JAI_OM_TAX_PROCESSI

/*
REM +======================================================================+
REM NAME
ORDER_LINE_VALIDATION
REM
REM DESCRIPTION Called from jai_oe_ola_trigger_pkg.ariu_t2 and
REM
jai_om_tax_processing_pkg.populate_tax

REM
REM NOTES
Come from JAI_OM_WDD_TRIGGER_PKG.ARU_T2
REM
REM +======================================================================+
*/
PROCEDURE ORDER_LINE_VALIDATION (p_rec_old t_rec%type,
p_rec_new t_rec%type,
p_action varchar2,
px_return_code out nocopy varchar2,
px_return_message out nocopy varchar2) IS
v_api_name CONSTANT VARCHAR2(30) := 'ORDER_LINE_VALIDATION';
v_inventory_item_id
v_organization_id
v_subinventory
v_source_header_type_id
v_trading_flag
v_bonded
lv_allow_shipment_wo_excise
v_trad_register_code
v_location_id
v_exe_flag
v_mod_flag
v_container_item_flag
lv_inventory_item_flag
ln_ship_from_location_id

NUMBER;
NUMBER;
VARCHAR2(10);
NUMBER;
VARCHAR2(1);
JAI_INV_SUBINV_DTLS.bonded%TYPE;
VARCHAR2(1);
VARCHAR2(30);
NUMBER;
VARCHAR2(150);
VARCHAR2(150);
mtl_system_items.container_item_flag%type;
mtl_system_items.inventory_item_flag%type;
WSH_DELIVERY_DETAILS.ship_from_location_id%type

;
/* variables used in debug package */
lv_object_name
jai_cmn_debug_contexts.LOG_CONTEXT%TYPE ;
lv_member_name
jai_cmn_debug_contexts.LOG_CONTEXT%TYPE;
lv_context
jai_cmn_debug_contexts.LOG_CONTEXT%TYPE;
ln_reg_id
NUMBER
;
le_error
EXCEPTION
;
v_mtl_line_exists
NUMBER
; -- added for b
ug 17211552
CURSOR Location_Cursor
IS
SELECT
NVL(Location_id,0),
trading,
NVL(bonded,'N') bonded
FROM
JAI_INV_SUBINV_DTLS
WHERE
Sub_Inventory_Name
= v_subinventory AND
organization_id
= v_organization_id;
cursor
select
from
where
and

c_orgn_Null_site_info is
exc_shpt_wo_exc_tax_flag
JAI_CMN_INVENTORY_ORGS
organization_id = p_rec_new.ship_from_org_id
location_id = 0;

CURSOR Trading_register_code_cur(p_organization_id
p_location_id
p_order_type_id
IS

NUMBER ,
NUMBER ,
NUMBER)

SELECT
A.register_code
FROM
JAI_OM_OE_BOND_REG_HDRS A, JAI_OM_OE_BOND_REG_DTLS b
WHERE
a.organization_id
a.location_id
a.register_id
b.order_flag
b.order_type_id

=
=
=
=
=

p_organization_id
p_location_id
b.register_id
'Y'
p_order_type_id;

CURSOR get_item_attributes
IS
SELECT
excise_flag ,
modvat_flag ,
nvl(container_item_flag,'N'),
nvl(inventory_item_flag,'N')
FROM
mtl_system_items msi,
JAI_INV_ITM_SETUPS jmsi
WHERE msi.organization_id
=
AND msi.inventory_item_id
=
AND jmsi.inventory_item_id
=
AND jmsi.organization_id
=

AND
AND
AND
AND

jmsi.organization_id
jmsi.inventory_item_id
v_Inventory_Item_Id
v_organization_id;

-- The following cursor gets the tax amount for the line_id from JAI_OM_OE_SO_
LINES table
CURSOR c_ja_in_so_lines_tax_amt
IS
SELECT
tax_amount
FROM
JAI_OM_OE_SO_LINES
WHERE
line_id = p_rec_new.line_id
AND
header_id = p_rec_new.header_id;
-- The following cursor gets the sum of tax amount for the line_id from JAI_OM
_OE_SO_TAXES table
CURSOR c_ja_in_so_tax_lines_tax_amt
IS
SELECT
nvl(sum(so_tax.tax_amount),0)
FROM
JAI_OM_OE_SO_TAXES so_tax
, jai_cmn_taxes_all tax
WHERE
line_id = p_rec_new.line_id
AND
header_id = p_rec_new.header_id
AND so_tax.tax_id = tax.tax_id
AND NVL(tax.inclusive_tax_flag,'N') = 'N' ;
v_line_tax_amount Number;
v_sum_tax_amount Number;
CURSOR c_chk_exc_exmpt_rule
IS
SELECT
a.excise_exempt_type

a.line_number
a.shipment_line_number
quantity

,
,

FROM
JAI_OM_OE_SO_LINES

WHERE
a.line_id = p_rec_new.line_id AND
a.header_id = p_rec_new.header_id ;
lv_excise_exempt_type
JAI_OM_OE_SO_LINES.EXCISE_EXEMPT_TYPE%TYPE
ln_line_number
JAI_OM_OE_SO_LINES.LINE_NUMBER%TYPE
ln_shipment_line_number
JAI_OM_OE_SO_LINES.SHIPMENT_LINE_NUMBER%TYPE
lv_ret_flag
VARCHAR2(10)
;
lv_error_msg
VARCHAR2(1996)
;
v_quantity
number;
ln_vat_cnt
NUMBER DEFAULT 0 ;
ln_exc_cnt
NUMBER DEFAULT 0 ;
ln_cnt_org_loc_setup NUMBER DEFAULT 0 ;
lv_applicable
JAI_RGM_ITM_TMPL_ATTRS.ATTRIBUTE_CODE%TYPE;
lv_process_flag
VARCHAR2 (2);
lv_process_message VARCHAR2 (1000);

;
;
;

CURSOR cur_chk_vat_exists (cp_line_id JAI_OM_OE_SO_TAXES.LINE_ID%TYPE,


cp_header_id JAI_OM_OE_SO_TAXES.HEADER_ID%TYPE)
IS
SELECT 1
FROM JAI_OM_OE_SO_TAXES
jstl
,
JAI_CMN_TAXES_ALL
jtc
,
jai_regime_tax_types_v tax_types
WHERE jstl.line_id = cp_line_id
AND
jstl.header_id = cp_header_id
AND
jtc.tax_id
= jstl.tax_id
AND
jtc.tax_type = tax_types.tax_type
AND
tax_types.regime_code = jai_constants.vat_regime;
CURSOR cur_chk_excise_exists (cp_line_id JAI_OM_OE_SO_TAXES.LINE_ID%TYPE,
cp_header_id JAI_OM_OE_SO_TAXES.HEADER_ID%TYPE
)
IS
SELECT 1
FROM JAI_OM_OE_SO_TAXES
jstl
,
JAI_CMN_TAXES_ALL
jtc
WHERE jstl.line_id = cp_line_id
AND
jstl.header_id = cp_header_id
AND
jtc.tax_id
= jstl.tax_id
AND
jtc.tax_type in ( jai_constants.tax_type_excise,
jai_constants.tax_type_exc_additional,
jai_constants.tax_type_exc_other,
jai_constants.tax_type_exc_edu_cess,
jai_constants.tax_type_sh_exc_edu_cess);
CURSOR cur_chk_org_loc_setup (cp_organization_id JAI_OM_WSH_LINES_ALL.LOCATIO
N_ID%TYPE,
cp_location_id
JAI_OM_WSH_LINES_ALL.ORGANIZAT
ION_ID%TYPE
)
IS
SELECT 1
FROM jai_rgm_parties rgmpt,
JAI_RGM_DEFINITIONS
rgms

WHERE
AND
AND
AND

rgmpt.regime_id
rgmpt.location_id
rgmpt.organization_id
rgms.regime_code

=
=
=
=

rgms.regime_id
cp_location_id
cp_organization_id
jai_constants.vat_regime;

tab_ooh OE_ORDER_HEADERS_ALL%ROWTYPE ;
CURSOR cur_get_org_hdr (cp_header_id OE_ORDER_HEADERS_ALL.HEADER_ID%TYPE)
IS
SELECT
*
FROM
oe_order_headers_all
WHERE
header_id = cp_header_id ;
CURSOR c_ato_line_id IS
SELECT
oel.ato_line_id
FROM
oe_order_headers_all oeh,
oe_order_lines_all oel
WHERE
oeh.header_id
= p_rec_new.header_id
AND oeh.header_id
= oel.header_id
AND item_type_code
= 'CONFIG' ;
CURSOR c_model_item_id(cp_ato_line_id oe_order_lines_all.line_id%TYPE) IS
SELECT
oel.inventory_item_id
FROM
oe_order_lines_all oel
WHERE
oel.line_id
= cp_ato_line_id
AND item_type_code = 'MODEL' ;
ln_ato_line_id NUMBER ;
ln_model_item_id NUMBER ;
/*mmurtuza for Bug 16793509 -- Start*/
v_source_line_id number;
v_source_header_id number;
-- additions for the bug 17211552 starts
CURSOR mtl_trx_line_exist
IS
SELECT 1
FROM mtl_material_transactions
WHERE trx_source_line_id= p_rec_new.line_id;
-- additions for the bug 17211552 ends
CURSOR get_conv_detail_cur
IS
SELECT
transactional_curr_code
conversion_type_code
conversion_rate
nvl(b.actual_shipment_date,sysdate)
FROM

,
,
,
actual_shipment_date

oe_order_headers_all a ,
oe_order_lines_all b
WHERE
a.header_id = b.header_id
AND
b.line_id = v_source_line_id AND
a.header_id = v_source_header_id ;
v_currency_code
v_set_of_books_id
v_conv_type_code
v_conv_rate
v_conv_date

GL_SETS_OF_BOOKS.CURRENCY_CODE%TYPE
;
HR_OPERATING_UNITS.SET_OF_BOOKS_ID%TYPE ;
oe_order_headers_all.conversion_type_code%TYPE;
NUMBER;
DATE;

v_curr_conv_rate NUMBER;
l_func_curr_det jai_plsql_cache_pkg.func_curr_details;
/*mmurtuza for Bug 16793509 -- End*/
/*Added function get_subinventory by mmurtuza for bug 16975882*/
FUNCTION get_subinventory RETURN VARCHAR2 IS
PRAGMA AUTONOMOUS_TRANSACTION;
CURSOR
SELECT
FROM
WHERE
and
and
and

cur_get_subinventory IS
subinventory
wsh_delivery_details
source_line_id = p_rec_new.line_id
source_header_id = p_rec_new.Header_id
transaction_id is not null /*Added by mmurtuza for bug 17650577*/
move_order_line_id is not null; /*Added by mmurtuza for bug 17338712*

/
ln_subinventory wsh_delivery_details.subinventory%type;
BEGIN
OPEN cur_get_subinventory;
FETCH cur_get_subinventory
INTO ln_subinventory;
CLOSE cur_get_subinventory;
return ln_subinventory;
END get_subinventory;

BEGIN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_VALID
ATION','begin of ORDER_LINE_VALIDATION procedure');
/* *****************************************************************************
*************************
Change History
1. 17/May/2013 mmurtuza for bug 16793509
issue: FULFILLED ORDER (LOCALIZED ) FORM NOT SHOWING THE LINE DETAILS
Fix: Added currency conversion validation before firing ITS itself
2. 31/May/2013 mmurtuza for bug 16861879
issue: ERROR MESSAGE SHOULD BE SHOWN WHEN THE NON EXCISE ITEM IS SHIPPING W

ITH EXCISE T
Fix: Added AWAITING_SHIPPING while validating flow status code for vali
dating the setups
3. 19/May/2013 mmurtuza for bug 16975882
issue: ON SHIPCONFIRM SYSTEM VALIDATE SUB INV FRM ORDER LINES INSTEAD OF PI
CKING SUBINV
Fix: Added function get_subinventory to fetch sub inventory from wsh_de
livery_details
4. 2/AUG/2013 nkodakan for bug 17211552
Issue: NOT ABLE TO ALLOCATE THE MV ORDER ERR:MANDATORY SUB INV SETUP NOT DEFINE
D EXCEP
Fix: Added a if condition to check the trx_source_line_id from the table mtl_m
aterial_transactions
5. 24/AUG/2013 mmurtuza for bug 17338712
Issue: MANDATORY INDIA LOCALIZATION SUB-INVENTORY SETUP NOT DONE FOR THIS LOCATI
ON FROM
Fix: Added condition of move_order_line_id in CURSOR cur_get_subinventory
6. 11/Sep/2013 mmurtuza for bug 17407826
Issue: VAT TEMPLATE VALIDATION FAILED IN SHIPPING TRANSACTION FORM
Fix: Merged the conditions of VAT and Excise
7. 29/Oct/2013 mmurtuza for bug 17650577
Issue: CANNOT PICK RELEASE IN DIFFERENT LOCATIONS IN INDIA
Fix: Added condition of transaction_id in CURSOR cur_get_subinventory
********************************************************************************
***********************/
px_return_code := jai_constants.successful ;
v_inventory_item_id
:=p_rec_new.inventory_item_id
;
v_organization_id
:=p_rec_new.ship_from_org_id
;
--v_subinventory
:=p_rec_new.subinventory
;
v_subinventory
:=get_subinventory()
; /*Comm
ented above and added this line by mmurtuza for bug 16975882*/
lv_object_name
:='TRIGGER.ARAA.AFTER.JA_IN_WSH_DLRY_AU_REL_S
TAT_TRG' ;
v_line_tax_amount
:=0;
v_sum_tax_amount
:=0;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_VALID
ATION','365 v_subinventory='||v_subinventory);
-- additions for the bug 17211552 starts
OPEN mtl_trx_line_exist;
FETCH mtl_trx_line_exist INTO v_mtl_line_exists;
CLOSE mtl_trx_line_exist;
-- additions for the bug ends
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_VALID
ATION','371 v_mtl_line_exists='||v_mtl_line_exists);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_VALID
ATION','372 p_rec_new.line_category_code='||p_rec_new.line_category_code);
--Skip 'RETURN' type, just process 'RETURN' cycle.
IF NVL(p_rec_new.line_category_code, 'RETURN') <> 'ORDER' THEN
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' This procedure just process type is ORDER, skip it for
line_id' || p_rec_new.line_id);

END IF;
px_return_code := jai_constants.successful ;
px_return_message := 'This procedure just process type is ORDER, skip it
for line_id' || p_rec_new.line_id ;
return;
END IF;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_VALID
ATION','384 p_rec_new.header_id='||p_rec_new.header_id);
OPEN cur_get_org_hdr (cp_header_id => p_rec_new.header_id);
FETCH cur_get_org_hdr INTO tab_ooh ;
CLOSE cur_get_org_hdr ;
v_source_header_type_id
ln_ship_from_location_id
ip_from_org_id, TRUE);

:= tab_ooh.order_type_id;
:= WSH_UTIL_CORE.Org_To_Location(p_rec_new.sh

OPEN c_ja_in_so_lines_tax_amt;
FETCH c_ja_in_so_lines_tax_amt INTO v_line_tax_amount;
CLOSE c_ja_in_so_lines_tax_amt;
OPEN c_ja_in_so_tax_lines_tax_amt;
FETCH c_ja_in_so_tax_lines_tax_amt INTO v_sum_tax_amount;
CLOSE c_ja_in_so_tax_lines_tax_amt;
IF NVL(v_line_tax_amount,0) <> NVL(v_sum_tax_amount,0) THEN
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' Taxes are not matching in JAI_OM_OE_SO_LINES and JA_IN_
SO_TAX_LINE FOR LINE_ID ' || p_rec_new.line_id);
END IF;
px_return_code := jai_constants.expected_error ;
px_return_message := 'Taxes are not matching in JAI_OM_OE_SO_LINES and JA_
IN_SO_TAX_LINE FOR LINE_ID ' || p_rec_new.line_id ;
return ;
END IF;
/*mmurtuza for Bug 16793509 -- Start*/
v_source_line_id := p_rec_new.line_id;
v_source_header_id := p_rec_new.header_id;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LIN
E_VALIDATION','415 p_rec_new.header_id='||p_rec_new.header_id);
IF p_rec_new.org_id IS NOT NULL THEN
l_func_curr_det := jai_plsql_cache_pkg.return_sob_curr
(p_org_id => p_rec_new.org_id);
v_currency_code := l_func_curr_det.currency_code;
v_set_of_books_id := l_func_curr_det.ledger_id;
END IF;
OPEN get_conv_detail_cur;
FETCH get_conv_detail_cur INTO v_currency_code, v_conv_type_code,v_conv_rate
, v_conv_date;
IF get_conv_detail_cur%FOUND THEN
v_curr_conv_rate := jai_cmn_utils_pkg.currency_conversion (
v_set_of_books_id
v_currency_code
v_conv_date

,
,
,

v_conv_type_code
v_conv_rate

);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE
_VALIDATION','435 v_curr_conv_rate='||v_curr_conv_rate);
IF v_curr_conv_rate IS NULL
THEN
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
'Currency Conversion on shipment date not setup.');
END IF;
px_return_code := jai_constants.expected_error ;
px_return_message := 'Currency Conversion on shipment date not setup.' ;
return ;
END IF;
END IF;
CLOSE get_conv_detail_cur;
/*mmurtuza for Bug 16793509 -- End*/
OPEN c_chk_exc_exmpt_rule;
FETCH c_chk_exc_exmpt_rule INTO lv_excise_exempt_type,ln_line_number,ln_ship
ment_line_number,v_quantity;
CLOSE c_chk_exc_exmpt_rule ;
lv_ret_flag :=

jai_om_utils_pkg.validate_excise_exemption (
p_line_id
=> p_rec_new.l

ine_id,
p_excise_exempt_type

=> lv_excise_e

p_line_number

=> ln_line_num

xempt_type,
ber,
p_shipment_line_number => ln_shipment
_line_number,
p_error_msg

=> lv_error_ms

g
) ;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_VA
LIDATION','466 lv_ret_flag='||lv_ret_flag);
IF nvl(lv_ret_flag,'S') = 'EE' THEN
px_return_code := jai_constants.expected_error ;
px_return_message := lv_error_msg;
return ;
ELSIF nvl(lv_ret_flag,'S') = 'UE' THEN
px_return_code := jai_constants.expected_error ;
px_return_message := lv_error_msg;
return ;
END IF ;
OPEN location_cursor;
FETCH location_cursor INTO
v_location_id, v_trading_flag , v_bonded;
CLOSE location_cursor;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_VA
LIDATION','480 v_location_id='||v_location_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_VA

LIDATION','481 v_trading_flag='||v_trading_flag);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_VA
LIDATION','482 v_bonded='||v_bonded);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_VA
LIDATION','484 v_organization_id='||v_organization_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_VA
LIDATION','485 v_source_header_type_id='||v_source_header_type_id);
OPEN trading_register_code_cur(
v_organization_id
,
v_location_id
,
v_source_header_type_id
);
FETCH trading_register_code_cur INTO v_trad_register_code;
CLOSE trading_register_code_cur;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_VA
LIDATION','492 v_trad_register_code='||v_trad_register_code);
OPEN get_item_attributes;
FETCH get_item_attributes INTO v_exe_flag,v_mod_flag,v_container_item_flag,l
v_inventory_item_flag;
CLOSE get_item_attributes;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_VA
LIDATION','497 v_exe_flag='||v_exe_flag);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_VA
LIDATION','498 v_mod_flag='||v_mod_flag);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_VA
LIDATION','499 v_container_item_flag='||v_container_item_flag);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_VA
LIDATION','500 lv_inventory_item_flag='||lv_inventory_item_flag);
-- if nvl(p_rec_new.flow_status_code,'ENTERED') in ('ENTERED', 'AWAITING_SHI
PPING') then /*Added AWAITING_SHIPPING by mmurtuza for bug 16861879*/
-- commented above and added below for the bug 17211552
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_VA
LIDATION','503 v_mtl_line_exists='||v_mtl_line_exists);
IF /*nvl(p_rec_new.flow_status_code,'ENTERED') = 'ENTERED' or */ /*Commente
d by mmurtuza for bug 17358641*/
v_mtl_line_exists IS NOT NULL THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LI
NE_VALIDATION','507 p_rec_new.line_id='||p_rec_new.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LI
NE_VALIDATION','508 p_rec_new.header_id='||p_rec_new.header_id);
OPEN cur_chk_excise_exists(cp_line_id
=> p_rec_new.line_id,
cp_header_id => p_rec_new.header_id
);
FETCH cur_chk_excise_exists INTO ln_exc_cnt;
CLOSE cur_chk_excise_exists ;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_
VALIDATION','514 ln_exc_cnt='||ln_exc_cnt);
IF nvl (ln_exc_cnt,0) > 0 AND nvl(v_exe_flag,'N') = 'N' THEN
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
'An item which is not Excisable has Excise Taxes attach
ed.' ||
'Please correct the item attribute or remove the Excise
type of taxes');
END IF;
px_return_code := jai_constants.expected_error ;
px_return_message := 'An item which is not Excisable has Excise Taxes a

ttached.' ||
'Please correct the item attribute or remove the E
xcise type of taxes' ;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LIN
E_VALIDATION','525 px_return_code'||px_return_code);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LIN
E_VALIDATION','525 before return');
return ;
END IF;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_
VALIDATION','530 v_bonded'||v_bonded);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_
VALIDATION','531 v_trading_flag'||v_trading_flag);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_
VALIDATION','532 v_exe_flag'||v_exe_flag);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_
VALIDATION','533 v_trad_register_code'||v_trad_register_code);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_
VALIDATION','534 ln_exc_cnt'||ln_exc_cnt);
IF (
(
NVL(v_bonded,'N') = 'Y'
OR
NVL(v_trading_flag,'N') = 'Y'
)
AND
NVL(v_exe_flag,'N') = 'Y'
AND
v_trad_register_code IN (
'23D_DOMESTIC_EXCISE' ,
'23D_EXPORT_EXCISE'
,
'DOMESTIC_EXCISE'
,
'EXPORT_EXCISE'
,
'BOND_REG'
,
'23D_EXPORT_WITHOUT_EXCISE'
)
AND
nvl(ln_exc_cnt,0) = 0
)
THEN
OPEN c_orgn_null_site_info;
FETCH c_orgn_null_site_info INTO lv_allow_shipment_wo_excise;
CLOSE c_orgn_null_site_info;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LIN
E_VALIDATION','556 lv_allow_shipment_wo_excise'||lv_allow_shipment_wo_excise);
IF NVL(lv_allow_shipment_wo_excise,'N') = 'Y' THEN
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' Delivery can not be ship confirmed as Excisable I
tem in the shipment does not have Excise taxes');
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.OR
DER_LINE_VALIDATION','562 IN IF NVL(lv_allow_shipment_wo_excise,N) = Y THEN');
END IF;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER
_LINE_VALIDATION','564 Before raise_application_error');
raise_application_error(-20412, 'Delivery can not be ship confirmed
as Excisable Item in the shipment does not have Excise taxes' );
END IF;

END IF;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_
VALIDATION','569 v_location_id'||v_location_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_
VALIDATION','570 v_container_item_flag'||v_container_item_flag);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_
VALIDATION','571 lv_inventory_item_flag'||lv_inventory_item_flag);
IF v_location_id IS NULL and v_container_item_flag ='N' and lv_inventory_
item_flag = 'Y' then
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' Mandatory India Localization Sub-inventory Setup not
done for this Location from where shipment is made');
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LI
NE_VALIDATION','577 before error message Mandatory India Localization Sub-invent
ory Setup not done.... ');
END IF;
px_return_code := jai_constants.expected_error ;
px_return_message := 'Mandatory India Localization Sub-inventory Setup
not done for this Location from where shipment is made' ;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LIN
E_VALIDATION','581 px_return_code'||px_return_code);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LIN
E_VALIDATION','582 px_return_message'||px_return_message);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LIN
E_VALIDATION','583 before return statement');
return ;
end if ;
/*end if;*/ /*Commented by mmurtuza for bug 17407826*/
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_V
ALIDATION','587 v_location_id'||v_location_id);
if v_location_id is null then
v_location_id := ln_ship_from_location_id;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_
VALIDATION','590 v_location_id'||v_location_id);
end if;
/*IF nvl(p_rec_new.flow_status_code,'ENTERED') = 'ENTERED' THEN*/ /*Commen
ted by mmurtuza for bug 17407826*/
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_
VALIDATION','594 p_rec_new.line_id'||p_rec_new.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_
VALIDATION','595 p_rec_new.header_id'||p_rec_new.header_id);
OPEN cur_chk_vat_exists ( cp_line_id
=> p_rec_new.line_id,
cp_header_id => p_rec_new.header_id
);
FETCH cur_chk_vat_exists INTO ln_vat_cnt;
CLOSE cur_chk_vat_exists ;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_
VALIDATION','601 ln_vat_cnt'||ln_vat_cnt);
IF nvl (ln_vat_cnt,0) > 0 THEN
OPEN cur_chk_org_loc_setup (cp_organization_id => v_organization_id ,
cp_location_id
=> v_location_id
);
FETCH cur_chk_org_loc_setup INTO ln_cnt_org_loc_setup;
CLOSE cur_chk_org_loc_setup ;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LIN

E_VALIDATION','609 ln_cnt_org_loc_setup'||ln_cnt_org_loc_setup);
IF nvl(ln_cnt_org_loc_setup,0) = 0 THEN
/*
|| For vat regime organization-location specific setup does not exist in
|| jai_rgm_parties (Regime Organization Registration)
*/
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' Organization-Location setup does not exist at regime
level');
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_L
INE_VALIDATION','619 Organization-Location setup does not exist at regime level'
);
END IF;
app_exception.raise_exception( EXCEPTION_TYPE => 'APP'
,EXCEPTION_CODE => NULL
,EXCEPTION_TEXT => 'Organization-Locatio
n setup does not exist at regime level'
);
END IF;
ln_ato_line_id := NULL ;
ln_model_item_id := NULL ;
OPEN c_ato_line_id ;
FETCH c_ato_line_id INTO ln_ato_line_id ;
CLOSE c_ato_line_id ;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LIN
E_VALIDATION','632 ln_ato_line_id'||ln_ato_line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LIN
E_VALIDATION','635 jai_constants.vat_regime'||jai_constants.vat_regime);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LIN
E_VALIDATION','636 p_rec_new.ship_from_org_id'||p_rec_new.ship_from_org_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LIN
E_VALIDATION','638 jai_constants.rgm_attr_item_applicable'||jai_constants.rgm_at
tr_item_applicable);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LIN
E_VALIDATION','639 lv_applicable'||lv_applicable);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LIN
E_VALIDATION','640 lv_process_flag'||lv_process_flag);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LIN
E_VALIDATION','641 lv_process_message'||lv_process_message);
IF ln_ato_line_id IS NOT NULL THEN
OPEN c_model_item_id(ln_ato_line_id) ;
FETCH c_model_item_id INTO ln_model_item_id ;
CLOSE c_model_item_id ;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_L
INE_VALIDATION','646 ln_model_item_id'||ln_model_item_id);
jai_inv_items_pkg.jai_get_attrib (
nts.vat_regime
,
ship_from_org_id
,
tem_id
,

p_regime_code

=> jai_consta

p_organization_id

=> p_rec_new.

p_inventory_item_id => ln_model_i


p_attribute_code

=> jai_consta

nts.rgm_attr_item_applicable
, p_attribute_value

=> lv_applica

, p_process_flag

=> lv_process

, p_process_msg

=> lv_process

ble
_flag
_message
);
ELSE
jai_inv_items_pkg.jai_get_attrib ( p_regime_code
nts.vat_regime
, p_organization_id
ship_from_org_id
, p_inventory_item_id
inventory_item_id
, p_attribute_code
nts.rgm_attr_item_applicable
, p_attribute_value
ble
, p_process_flag
_flag
, p_process_msg
_message
);
END IF;

=> jai_consta
=> p_rec_new.
=> p_rec_new.
=> jai_consta
=> lv_applica
=> lv_process
=> lv_process

jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LIN
E_VALIDATION','669 lv_process_flag'||lv_process_flag);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LIN
E_VALIDATION','670 lv_applicable'||lv_applicable);
IF lv_process_flag = jai_constants.successful
AND nvl(lv_applicable,'N') = 'N' THEN
/*
||item is not vatable
*/
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' An item which is not Vatable has VAT Taxes attached
.Please correct the item attribute or remove the VAT type of taxes');
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER
_LINE_VALIDATION','680 After the message An item which is not Vatable has VAT Ta
xes attached.Please correct the item attribute.....');
END IF;
app_exception.raise_exception( EXCEPTION_TYPE => 'APP'
,EXCEPTION_CODE => NULL
,EXCEPTION_TEXT => 'An item which is no
t Vatable has VAT Taxes attached.Please correct the item attribute or remove the
VAT type of taxes'
);
ELSIF lv_process_flag <> jai_constants.successful THEN
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
lv_process_message);
END IF;
app_exception.raise_exception( EXCEPTION_TYPE => 'APP'
,EXCEPTION_CODE => NULL
,EXCEPTION_TEXT => substr (lv_process_m

essage,1,999)
);
END IF;
END IF;
END IF;

jai_ar_tcs_rep_pkg.process_transactions
,

( p_ooh

=> tab_ooh

p_event

=> jai_con

p_process_flag

=> lv_proc

p_process_message

=> lv_proc

stants.wsh_ship_confirm ,
ess_flag

ess_message
);
IF lv_process_flag = jai_constants.expected_error
OR
lv_process_flag = jai_constants.unexpected_error
THEN
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
lv_process_message);
END IF;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_
VALIDATION','720 before le_error exception');
raise le_error;
END IF;
jai_cmn_debug_contexts_pkg.deregister (pn_reg_id => ln_reg_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_VA
LIDATION','726 before the EXCEPTION block');
EXCEPTION
WHEN le_error THEN
IF lv_process_flag = jai_constants.unexpected_error THEN
lv_process_message := substr (lv_process_message || ' Object = JAI_OM_TA
X_PROCESSING_PKG.ORDER_LINE_VALIDATION ', 1,1999) ;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LIN
E_VALIDATION','731 excepton handled in le_error exception ');
END IF;
fnd_message.set_name (application => 'JA',
name
=> 'JAI_GENERIC_MSG'
);
fnd_message.set_token ( token => 'MSG_TEXT',
value => lv_process_message
);
app_exception.raise_exception;

WHEN others THEN


jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_VA
LIDATION','747 in when others excepton block ');
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_VA
LIDATION','748 sqlcode '||sqlcode);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.ORDER_LINE_VA
LIDATION','749 sqlerrm '||sqlerrm);
fnd_message.set_name ( application => 'JA',
name
=> 'JAI_GENERIC_MSG'
);
fnd_message.set_token ( token => 'MSG_TEXT',
value => 'Exception Occured in ' || ' Object = JAI
_OM_TAX_PROCESSING_PKG.ORDER_LINE_VALIDATION'||fnd_global.local_chr(10)||SQLERRM
);
app_exception.raise_exception;
END ORDER_LINE_VALIDATION ;
/*
REM +======================================================================+
REM NAME
COPY_ORDER_TO_ORDER
REM
REM DESCRIPTION COPY ORDER LINES FROM ORIGINAL ORDER
REM
REM NOTES
Call from procdure COPY_SOURCE_ORDER
REM
REM +======================================================================+
*/
PROCEDURE COPY_ORDER_TO_ORDER(pr_copy
get_copy_order_line%ROWT
YPE,
pr_order_line
t_rec%type,
pr_header_info
get_header_info%ROWTYPE)
IS
v_api_name CONSTANT VARCHAR2(30) := 'COPY_ORDER_TO_ORDER';
CURSOR
SELECT
FROM
WHERE
AND

get_so_tax_lines_count_cur(p_header_id NUMBER, p_line_id NUMBER) IS


COUNT(1)
JAI_OM_OE_SO_TAXES
header_id = p_header_id
line_id = p_line_id;

CURSOR so_tax_lines_cur(p_header_id NUMBER, p_line_id NUMBER) IS


SELECT tax_line_no,
tax_id,
tax_rate,
qty_rate,
uom,
precedence_1,
precedence_2,
precedence_3,
precedence_4,
precedence_5,
precedence_6,
precedence_7,
precedence_8,
precedence_9,
precedence_10,

tax_amount,
base_tax_amount,
func_tax_amount,
tax_category_id
FROM JAI_OM_OE_SO_TAXES
WHERE header_id = p_header_id
AND line_id = p_line_id;
c_source_line_id
v_so_tax_lines_count
v_tax_line_count
r_get_copy_order_line
l_func_curr_det
v_set_of_books_id
v_converted_rate

NUMBER;
NUMBER;
NUMBER;
get_copy_order_line%ROWTYPE;
jai_plsql_cache_pkg.func_curr_details;
NUMBER;
NUMBER;

/*Start by mmurtuza for bug 17358641 */


CURSOR bind_cur(p_header_id NUMBER) IS
SELECT sold_to_org_id,
conversion_type_code,
nvl(ordered_date, creation_date)
FROM oe_order_headers_all
WHERE header_id = p_header_id;
v_ship_to_site_use_id NUMBER
:= NVL(pr_order_line.ship_to_ORG_id,0);
v_inventory_item_id NUMBER
:= pr_order_line.inventory_item_id;
v_uom_code VARCHAR2(3)
:= pr_order_line.ORDER_QUANTITY_UOM;
v_assessable_value NUMBER;
ln_vat_assessable_value NUMBER;
v_customer_id NUMBER;
v_conv_type_code VARCHAR2(30);
v_date_ordered DATE;
/*End by mmurtuza for bug 17358641 */
BEGIN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_TO_O
RDER','835 begin of COPY_ORDER_TO_ORDER procedure');
/*Start by mmurtuza for bug 17358641 */
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_TO_O
RDER','837 pr_order_line.header_id '||pr_order_line.header_id);
OPEN bind_cur(pr_order_line.header_id);
FETCH bind_cur INTO
v_customer_id,
v_conv_type_code,
v_date_ordered;
CLOSE bind_cur;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER
_TO_ORDER','845 v_customer_id '||v_customer_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER
_TO_ORDER','846 v_conv_type_code '||v_conv_type_code);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER
_TO_ORDER','847 v_date_ordered '||v_date_ordered);
l_func_curr_det := jai_plsql_cache_pkg.return_sob_curr(p_org_id => pr_
order_line.ORG_ID);
v_set_of_books_id := l_func_curr_det.ledger_id;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_TO

_ORDER','853 v_set_of_books_id '||v_set_of_books_id);


jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_TO
_ORDER','854 pr_header_info.currency_code '||pr_header_info.currency_code);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_TO
_ORDER','855 pr_header_info.conv_date '||pr_header_info.conv_date);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_TO
_ORDER','856 pr_header_info.conv_type_code '||pr_header_info.conv_type_code);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_TO
_ORDER','857 pr_header_info.conv_rate '||pr_header_info.conv_rate);
v_converted_rate := jai_cmn_utils_pkg.currency_conversion(v_set_of_books_
id,
pr_header_info.
currency_code,
pr_header_info.
conv_date,
pr_header_info.
conv_type_code,
pr_header_info.
conv_rate);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.
COPY_ORDER_TO_ORDER','865 v_converted_rate '||v_converted_rate);

v_assessable_value := jai_om_utils_pkg.get_oe_assessable_value
(
p_customer_id
=> v_customer_id,
p_ship_to_site_use_id => v_ship_to_site_use_id,
p_inventory_item_id => v_inventory_item_id,
p_uom_code
=> v_uom_code,
p_default_price
=> pr_order_line.unit_sell
ing_price,
p_ass_value_date
p_sob_id
p_curr_conv_code
p_conv_rate

=>
=>
=>
=>

v_date_ordered,
v_set_of_books_id ,
v_conv_type_code ,
v_converted_rate

);
ln_vat_assessable_value := jai_general_pkg.ja_in_vat_assessabl
e_value
(
p_party_id
p_party_site_id
p_inventory_item_id
p_uom_code
p_default_price

=>
=>
=>
=>
=>

v_customer_id
,
v_ship_to_site_use_id ,
v_inventory_item_id
,
v_uom_code
,
pr_order_line.unit_selling_pric

e,
p_ass_value_date
=> v_date_ordered
,
p_party_type
=> 'C'
);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDE
R_TO_ORDER','890 ln_vat_assessable_value '||ln_vat_assessable_value);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDE
R_TO_ORDER','891 pr_order_line.ordered_quantity '||pr_order_line.ordered_quantit
y);
ln_vat_assessable_value := nvl(ln_vat_assessable_value,0) * pr_order_li
ne.ordered_quantity;

/*End by mmurtuza for bug 17358641 */


SELECT COUNT(*)
INTO c_source_line_id
FROM JAI_OM_OE_SO_LINES
WHERE LINE_ID = pr_order_line.line_id;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_TO
_ORDER','900 c_source_line_id '||c_source_line_id);
IF c_source_line_id = 0 THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER','903 INSERT INTO JAI_OM_OE_SO_LINES pr_order_line.line_number '||pr_or
der_line.line_number);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER','904 INSERT INTO JAI_OM_OE_SO_LINES pr_order_line.line_id '||pr_order_
line.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER','905 INSERT INTO JAI_OM_OE_SO_LINES pr_order_line.header_id '||pr_orde
r_line.header_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER','906 INSERT INTO JAI_OM_OE_SO_LINES pr_order_line.ordered_quantity '||
pr_order_line.ordered_quantity);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER','907 INSERT INTO JAI_OM_OE_SO_LINES pr_order_line.unit_selling_price '
||pr_order_line.unit_selling_price);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER','908 INSERT INTO JAI_OM_OE_SO_LINES pr_copy.tax_amount '||pr_copy.tax_
amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER','909 INSERT INTO JAI_OM_OE_SO_LINES pr_copy.line_tot_amount '||pr_copy
.line_tot_amount);
INSERT INTO JAI_OM_OE_SO_LINES
(line_number,
line_id,
header_id,
inventory_item_id,
unit_code,
quantity,
tax_category_id,
ato_flag,
selling_price,
line_amount,
assessable_value,
tax_amount,
line_tot_amount,
shipment_line_number,
excise_exempt_type,
excise_exempt_refno,
excise_exempt_date,
vat_exemption_flag,
vat_exemption_type,
vat_exemption_date,
vat_exemption_refno,
vat_assessable_value,
vat_reversal_price,
creation_date,
created_by,
last_update_date,
last_updated_by,

last_update_login,
service_type_code,
ship_to_org_id)
VALUES
(pr_order_line.line_number,
pr_order_line.line_id,
pr_order_line.header_id,
pr_order_line.inventory_item_id,
pr_copy.unit_code,
pr_order_line.ordered_quantity,
pr_copy.tax_category_id,
'Y',
pr_order_line.unit_selling_price,
nvl(pr_order_line.unit_selling_price * pr_order_line.ordered_quantity,
0),
/*pr_copy.assessable_value,*/ /*17358641 */
v_assessable_value, /*17358641 */
pr_copy.tax_amount,
pr_copy.line_tot_amount,
pr_order_line.shipment_number,
pr_copy.excise_exempt_type,
pr_copy.excise_exempt_refno,
pr_copy.excise_exempt_date,
pr_copy.vat_exemption_flag,
pr_copy.vat_exemption_type,
pr_copy.vat_exemption_date,
pr_copy.vat_exemption_refno,
/*pr_copy.vat_assessable_value,*/ /*17358641 */
ln_vat_assessable_value, /*17358641 */
nvl(pr_copy.vat_reversal_price, 0) * NVL(pr_order_line.ordered_quantity
, 0),
pr_order_line.creation_date,
pr_order_line.created_by,
pr_order_line.last_update_date,
pr_order_line.last_updated_by,
pr_order_line.last_update_login,
pr_copy.service_type_code,
pr_order_line.ship_to_org_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORD
ER_TO_ORDER','number of rows inserted are '||sql%rowcount);
END IF;
/********************* Order TO Order tax lines computation ***************
***********/
OPEN Get_So_Tax_Lines_Count_Cur(pr_order_line.SOURCE_DOCUMENT_ID,
pr_order_line.SOURCE_DOCUMENT_LINE_ID);
FETCH Get_So_Tax_Lines_Count_Cur
INTO v_so_tax_lines_count;
CLOSE Get_So_Tax_Lines_Count_Cur;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_TO
_ORDER','983 v_so_tax_lines_count '||v_so_tax_lines_count);
IF NVL(v_so_tax_lines_count, 0) > 0 THEN
FOR Rec IN So_Tax_Lines_Cur(pr_order_line.SOURCE_DOCUMENT_ID,
pr_order_line.SOURCE_DOCUMENT_LINE_ID) LOOP
SELECT COUNT(1)
INTO v_tax_line_count
FROM JAI_OM_OE_SO_TAXES
WHERE line_id = pr_order_line.line_id
AND tax_id = rec.tax_id;

jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDE
R_TO_ORDER','993 v_tax_line_count '||v_tax_line_count);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDE
R_TO_ORDER','994 pr_order_line.line_id '||pr_order_line.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDE
R_TO_ORDER','995 rec.tax_id '||rec.tax_id);
IF v_tax_line_count = 0 THEN
/*
|| call to the ja_in_calc_Taxes_ato would do the trick thru re-calcula
ting the taxes.
*/
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_OR
DER_TO_ORDER','1002 INSERT INTO JAI_OM_OE_SO_TAXES pr_order_line.header_id '||pr
_order_line.header_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_OR
DER_TO_ORDER','1003 INSERT INTO JAI_OM_OE_SO_TAXES pr_order_line.line_id '||pr_o
rder_line.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_OR
DER_TO_ORDER','1004 INSERT INTO JAI_OM_OE_SO_TAXES rec.base_tax_amount '||rec.ba
se_tax_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_OR
DER_TO_ORDER','1005 INSERT INTO JAI_OM_OE_SO_TAXES rec.tax_amount '||rec.tax_amo
unt);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_OR
DER_TO_ORDER','1006 INSERT INTO JAI_OM_OE_SO_TAXES rec.qty_rate '||rec.qty_rate)
;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_OR
DER_TO_ORDER','1007 INSERT INTO JAI_OM_OE_SO_TAXES rec.tax_line_no '||rec.tax_li
ne_no);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_OR
DER_TO_ORDER','1008 INSERT INTO JAI_OM_OE_SO_TAXES rec.tax_id '||rec.tax_id);
INSERT INTO JAI_OM_OE_SO_TAXES
(header_id,
line_id,
tax_line_no,
tax_id,
tax_rate,
qty_rate,
uom,
precedence_1,
precedence_2,
precedence_3,
precedence_4,
precedence_5,
precedence_6,
precedence_7,
precedence_8,
precedence_9,
precedence_10,
tax_amount,
base_tax_amount,
func_tax_amount,
creation_date,
created_by,
last_update_date,
last_updated_by,
last_update_login,
tax_category_id)

VALUES
(pr_order_line.header_id,
pr_order_line.line_id,
rec.tax_line_no,
rec.tax_id,
rec.tax_rate,
rec.qty_rate,
rec.uom,
rec.precedence_1,
rec.precedence_2,
rec.precedence_3,
rec.precedence_4,
rec.precedence_5,
rec.precedence_6,
rec.precedence_7,
rec.precedence_8,
rec.precedence_9,
rec.precedence_10,
rec.tax_amount,
rec.base_tax_amount,
rec.func_tax_amount,
pr_order_line.creation_date,
pr_order_line.created_by,
pr_order_line.last_update_date,
pr_order_line.last_updated_by,
pr_order_line.last_update_login,
rec.tax_category_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY
_ORDER_TO_ORDER','1063 number of rows INSERT INTO JAI_OM_OE_SO_TAXES are '||sql%
rowcount);
END IF;
END LOOP;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER','1067 pr_order_line.header_id '||pr_order_line.header_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER','1068 pr_order_line.line_id '||pr_order_line.line_id);
-- get newly copied order line
OPEN get_copy_order_line(pr_order_line.header_id, pr_order_line.line_id);
FETCH get_copy_order_line
INTO r_get_copy_order_line;
CLOSE get_copy_order_line;
/*
|| The variable r_get_copy_order_line has the details of the current line
from JAI_OM_OE_SO_LINES table
*/
/*Start commenting by mmurtuza for bug 17358641 -- MOved this code in
beginning of procedure*/
/*l_func_curr_det := jai_plsql_cache_pkg.return_sob_curr(p_org_id =>
pr_order_line.ORG_ID);
v_set_of_books_id := l_func_curr_det.ledger_id;
v_converted_rate := jai_cmn_utils_pkg.currency_conversion(v_set_of_books_
id,
pr_header_info.
currency_code,
pr_header_info.
conv_date,
pr_header_info.

conv_type_code,
pr_header_info.
conv_rate);*/
/*End commenting by mmurtuza for bug 17358641 */
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' jai_om_tax_pkg.calculate_ato_taxes :' ||
TO_CHAR(pr_order_line.header_id) || ' ~ ' ||
TO_CHAR(pr_order_line.line_id));
END IF;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER','1098 pr_order_line.header_id '||pr_order_line.header_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER','1099 pr_order_line.line_id '||pr_order_line.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER','1100 pr_order_line.ordered_quantity '||pr_order_line.ordered_quantity
);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER','1101 v_assessable_value '||v_assessable_value);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER','1102 r_get_copy_order_line.line_amount '||r_get_copy_order_line.line_
amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER','1103 v_converted_rate '||v_converted_rate);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER','1104 pr_order_line.inventory_item_id '||pr_order_line.inventory_item_
id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER','1105 pr_order_line.pricing_quantity_uom '||pr_order_line.pricing_quan
tity_uom);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER','1106 ln_vat_assessable_value '||ln_vat_assessable_value);
jai_om_tax_pkg.calculate_ato_taxes('OE_LINES_UPDATE',
NULL,
pr_order_line.header_id,
pr_order_line.line_id,
/*r_get_copy_order_line.assessable_valu
e*/ v_assessable_value * /*17358641 */
(pr_order_line.ordered_quantity),
r_get_copy_order_line.line_amount,
v_converted_rate,
pr_order_line.inventory_item_id,
pr_order_line.ordered_quantity,
pr_order_line.ordered_quantity,
pr_order_line.pricing_quantity_uom,
NULL,
NULL,
NULL,
NULL,
pr_order_line.last_update_date,
pr_order_line.last_updated_by,
pr_order_line.last_update_login,
/*r_get_copy_order_line.vat_assessable_
value*/

ln_vat_assessable_value); /*17358641 */
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER','1129 before update JAI_OM_OE_SO_LINES');
update JAI_OM_OE_SO_LINES
set tax_amount
= NVL(r_get_copy_order_line.line_amount,
0),
line_tot_amount
= line_amount + NVL(r_get_copy_order_line.line
_amount,
0),
assessable_value = v_assessable_value, /*17358641*/
vat_assessable_Value = /*r_get_copy_order_line.vat_assessable_value
*/ ln_vat_assessable_value /*17358641*/
where header_id = pr_order_line.header_id
and line_id = pr_order_line.line_id;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORD
ER_TO_ORDER','1139 after update JAI_OM_OE_SO_LINES');
END IF;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_TO
_ORDER','1038 after the end if');
EXCEPTION
WHEN OTHERS THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER','1145 Exception occured in COPY_ORDER_TO_ORDER procedure ');
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER',' 1146 sqlcode '||sqlcode);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_ORDER',' 1147 sqlerrm '||sqlerrm);
RAISE;
END COPY_ORDER_TO_ORDER;
/*
REM +======================================================================+
REM NAME
COPY_RETURN_TO_ORDER
REM
REM DESCRIPTION COPY ORDER LINES FROM ORIGINAL RETURN ORDER
REM
REM NOTES
Call from procdure COPY_SOURCE_ORDER
REM
REM +======================================================================+
*/
PROCEDURE COPY_RETURN_TO_ORDER(pr_order_line
t_rec%type,
pr_header_info
get_header_info%ro
wtype) IS
/*
Get the details from the JAI_OM_OE_RMA_LINES table.
*/
CURSOR cur_get_rma_entry_lines(p_header_id JAI_OM_OE_RMA_LINES.RMA_HEADER_ID%T
YPE,
p_Line_Id JAI_OM_OE_RMA_LINES.RMA_LINE_ID%TYP
E) IS
SELECT *
FROM JAI_OM_OE_RMA_LINES
WHERE rma_header_id = p_header_id
AND rma_line_id = p_Line_Id;
CURSOR cur_source_line_id_exists(p_line_id OE_ORDER_LINES_ALL.LINE_ID%TYPE,
p_header_id OE_ORDER_LINES_ALL.HEADER_ID%TYPE
) IS
SELECT 'X'

FROM JAI_OM_OE_SO_LINES
WHERE line_id = p_line_id
AND header_id = p_header_id;
/*
Get the rma trax lines detail from the table JAI_OM_OE_RMA_TAXES
*/
CURSOR cur_get_JAI_OM_OE_RMA_TAXES(p_line_id OE_ORDER_LINES_ALL.SOURCE_DOCUMEN
T_LINE_ID%TYPE) IS
SELECT tax_line_no,
tax_id,
tax_rate,
qty_rate,
uom,
precedence_1,
precedence_2,
precedence_3,
precedence_4,
precedence_5,
precedence_6,
precedence_7,
precedence_8,
precedence_9,
precedence_10,
tax_amount,
base_tax_amount,
func_tax_amount
FROM JAI_OM_OE_RMA_TAXES
WHERE rma_line_id = p_line_id;
/*
code to check whether a record exists in the table JAI_OM_OE_SO_TAXES for a
given line_id and tax_id.
*/
CURSOR cur_chk_tax_lines_exists(p_line_id1 OE_ORDER_LINES_ALL.LINE_ID%TYPE,
p_tax_id JAI_OM_OE_SO_TAXES.TAX_ID%TYPE) IS
SELECT 'X'
FROM JAI_OM_OE_SO_TAXES
WHERE line_id = p_line_id1
AND tax_id = p_tax_id;
rec_get_rma_tax_lines
l_tax_lines_exist
rec_cur_get_rma_entry_lines
l_exists
l_tax_exists
l_func_curr_det
v_set_of_books_id
v_converted_rate
v_assessable_value
v_assessable_amount
v_line_amount
v_line_tax_amount
ln_vat_assessable_value

cur_get_JAI_OM_OE_RMA_TAXES%ROWTYPE;
VARCHAR2(10);
cur_get_rma_entry_lines%ROWTYPE;
VARCHAR2(1);
VARCHAR2(2);
jai_plsql_cache_pkg.func_curr_details;
NUMBER;
NUMBER;
NUMBER;
NUMBER;
NUMBER;
NUMBER;
JAI_OM_OE_SO_LINES.VAT_ASSESSABLE_VALUE%TYPE;

BEGIN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN_T
O_ORDER','begin of COPY_RETURN_TO_ORDER procedure');
v_line_amount := (NVL(pr_order_line.ordered_quantity, 0) * NVL(pr_order_line

.UNIT_SELLING_PRICE, 0));
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN_T
O_ORDER','1234 v_line_amount '||v_line_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN_T
O_ORDER','1235 pr_order_line.ordered_quantity '||pr_order_line.ordered_quantity)
;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN_T
O_ORDER','1236 pr_order_line.UNIT_SELLING_PRICE '||pr_order_line.UNIT_SELLING_PR
ICE);
/*
IF the source_order categoy code is Return and line category code is ORDER
then
1. Check whether a corresponding record exists in the rma_entry_lines tab
le.
IF Yes then get the details of this record into the record group varia
ble rec_cur_get_rma_entry_lines and check whether a
record with the same line_id exists in the JAI_OM_OE_SO_LINES table.
IF such a record is not found then then insert a record into the JAI_O
M_OE_SO_LINES table.
*/
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN_T
O_ORDER','1244 pr_order_line.SOURCE_DOCUMENT_ID '||pr_order_line.SOURCE_DOCUMENT
_ID);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN_T
O_ORDER','1245 pr_order_line.SOURCE_DOCUMENT_LINE_ID '||pr_order_line.SOURCE_DOC
UMENT_LINE_ID);
OPEN cur_get_rma_entry_lines(pr_order_line.SOURCE_DOCUMENT_ID,
pr_order_line.SOURCE_DOCUMENT_LINE_ID);
FETCH cur_get_rma_entry_lines
INTO rec_cur_get_rma_entry_lines;
IF cur_get_rma_entry_lines%FOUND THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN_T
O_ORDER','1253 in IF cur_get_rma_entry_lines%FOUND THEN ');
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN_T
O_ORDER','1254 pr_order_line.SOURCE_DOCUMENT_ID '||pr_order_line.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN_T
O_ORDER','1255 pr_order_line.SOURCE_DOCUMENT_LINE_ID '||pr_order_line.header_id)
;
OPEN cur_source_line_id_exists(p_line_id => pr_order_line.line_id,
p_header_id => pr_order_line.header_id);
FETCH cur_source_line_id_exists
INTO l_exists;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETU
RN_TO_ORDER','1262 l_exists '||l_exists);
IF cur_source_line_id_exists%NOTFOUND THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1264 INSERT INTO JAI_OM_OE_SO_LINES pr_order_line.line_number '||pr_
order_line.line_number);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1265 INSERT INTO JAI_OM_OE_SO_LINES pr_order_line.line_id '||pr_orde
r_line.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1266 INSERT INTO JAI_OM_OE_SO_LINES pr_order_line.header_id '||pr_or
der_line.header_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN

_TO_ORDER','1267 INSERT INTO JAI_OM_OE_SO_LINES rec_cur_get_rma_entry_lines.quan


tity '||rec_cur_get_rma_entry_lines.quantity);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1268 INSERT INTO JAI_OM_OE_SO_LINES rec_cur_get_rma_entry_lines.uom
'||rec_cur_get_rma_entry_lines.uom);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1269 INSERT INTO JAI_OM_OE_SO_LINES rec_cur_get_rma_entry_lines.tax_
amount '||rec_cur_get_rma_entry_lines.tax_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1270 INSERT INTO JAI_OM_OE_SO_LINES rec_cur_get_rma_entry_lines.asse
ssable_value '||rec_cur_get_rma_entry_lines.assessable_value);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1271 INSERT INTO JAI_OM_OE_SO_LINES v_line_amount '||v_line_amount);

INSERT INTO JAI_OM_OE_SO_LINES


(line_number,
line_id,
header_id,
inventory_item_id,
unit_code,
quantity,
tax_category_id,
ato_flag,
selling_price,
line_amount,
assessable_value,
tax_amount,
line_tot_amount,
shipment_line_number,
creation_date,
created_by,
last_update_date,
last_updated_by,
last_update_login,
service_type_code,
ship_to_org_id)
VALUES
(pr_order_line.line_number,
pr_order_line.line_id,
pr_order_line.header_id,
rec_cur_get_rma_entry_lines.inventory_item_id,
rec_cur_get_rma_entry_lines.uom,
rec_cur_get_rma_entry_lines.quantity,
rec_cur_get_rma_entry_lines.tax_category_id,
'Y',
rec_cur_get_rma_entry_lines.selling_price,
v_line_amount,
rec_cur_get_rma_entry_lines.assessable_value,
rec_cur_get_rma_entry_lines.tax_amount,
(v_line_amount + rec_cur_get_rma_entry_lines.tax_amount),
pr_order_line.shipment_number,
pr_order_line.creation_date,
pr_order_line.created_by,
pr_order_line.last_update_date,
pr_order_line.last_updated_by,
pr_order_line.last_update_login,
rec_cur_get_rma_entry_lines.service_type_code,

pr_order_line.ship_to_org_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_R
ETURN_TO_ORDER','1319 no.of rows INSERT INTO JAI_OM_OE_SO_LINES are '||sql%rowc
ount);
END IF;
CLOSE cur_source_line_id_exists;
END IF;
CLOSE cur_get_rma_entry_lines;
/********************* Return TO Order tax lines computation **************
************/
l_tax_lines_exist
:= 'FALSE';
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN_T
O_ORDER','1328 before loop FOR rec_get_rma_tax_lines in cur_get_JAI_OM_OE_RMA_TA
XES pr_order_line.SOURCE_DOCUMENT_LINE_ID '||pr_order_line.SOURCE_DOCUMENT_LINE_
ID);
FOR rec_get_rma_tax_lines in cur_get_JAI_OM_OE_RMA_TAXES(p_line_id => pr_ord
er_line.SOURCE_DOCUMENT_LINE_ID) loop
l_tax_lines_exist := 'TRUE';
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN_
TO_ORDER','1333 in loop FOR rec_get_rma_tax_lines in cur_get_JAI_OM_OE_RMA_TAXES
');
OPEN cur_chk_tax_lines_exists(p_line_id1 => pr_order_line.line_id,
p_tax_id => rec_get_rma_tax_lines.tax_id);
FETCH cur_chk_tax_lines_exists
INTO l_tax_exists;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETU
RN_TO_ORDER','1338 l_tax_exists '||l_tax_exists);
IF cur_chk_tax_lines_exists%NOTFOUND THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1340 INSERT INTO JAI_OM_OE_SO_TAXES l_tax_exists '||l_tax_exists);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1341 INSERT INTO JAI_OM_OE_SO_TAXES pr_order_line.header_id '||pr_or
der_line.header_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1342 INSERT INTO JAI_OM_OE_SO_TAXES pr_order_line.line_id '||pr_orde
r_line.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1343 INSERT INTO JAI_OM_OE_SO_TAXES rec_get_rma_tax_lines.tax_rate '
||rec_get_rma_tax_lines.tax_rate);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1344 INSERT INTO JAI_OM_OE_SO_TAXES rec_get_rma_tax_lines.qty_rate '
||rec_get_rma_tax_lines.qty_rate);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1345 INSERT INTO JAI_OM_OE_SO_TAXES rec_get_rma_tax_lines.tax_amount
'||rec_get_rma_tax_lines.tax_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1346 INSERT INTO JAI_OM_OE_SO_TAXES rec_get_rma_tax_lines.base_tax_a
mount '||rec_get_rma_tax_lines.base_tax_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1347 INSERT INTO JAI_OM_OE_SO_TAXES rec_get_rma_tax_lines.func_tax_a
mount '||rec_get_rma_tax_lines.func_tax_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1348 INSERT INTO JAI_OM_OE_SO_TAXES l_tax_exists '||l_tax_exists);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1349 INSERT INTO JAI_OM_OE_SO_TAXES l_tax_exists '||l_tax_exists);

INSERT INTO JAI_OM_OE_SO_TAXES


(header_id,
line_id,
tax_line_no,
tax_id,
tax_rate,
qty_rate,
uom,
precedence_1,
precedence_2,
precedence_3,
precedence_4,
precedence_5,
precedence_6,
precedence_7,
precedence_8,
precedence_9,
precedence_10,
tax_amount,
base_tax_amount,
func_tax_amount,
creation_date,
created_by,
last_update_date,
last_updated_by,
last_update_login)
VALUES
(pr_order_line.header_id,
pr_order_line.line_id,
rec_get_rma_tax_lines.tax_line_no,
rec_get_rma_tax_lines.tax_id,
rec_get_rma_tax_lines.tax_rate,
rec_get_rma_tax_lines.qty_rate,
rec_get_rma_tax_lines.uom,
rec_get_rma_tax_lines.precedence_1,
rec_get_rma_tax_lines.precedence_2,
rec_get_rma_tax_lines.precedence_3,
rec_get_rma_tax_lines.precedence_4,
rec_get_rma_tax_lines.precedence_5,
rec_get_rma_tax_lines.precedence_6,
rec_get_rma_tax_lines.precedence_7,
rec_get_rma_tax_lines.precedence_8,
rec_get_rma_tax_lines.precedence_9,
rec_get_rma_tax_lines.precedence_10,
rec_get_rma_tax_lines.tax_amount,
rec_get_rma_tax_lines.base_tax_amount,
rec_get_rma_tax_lines.func_tax_amount,
pr_order_line.creation_date,
pr_order_line.created_by,
pr_order_line.last_update_date,
pr_order_line.last_updated_by,
pr_order_line.last_update_login);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_R
ETURN_TO_ORDER','1404 no.of rows after INSERT INTO JAI_OM_OE_SO_TAXES are '||sql
%rowcount);
END IF;
CLOSE cur_chk_tax_lines_exists;
END LOOP;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN_T

O_ORDER','1408 end loop FOR rec_get_rma_tax_lines in cur_get_JAI_OM_OE_RMA_TAXES


');
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETU
RN_TO_ORDER','1411 l_tax_lines_exist '||l_tax_lines_exist);
IF l_tax_lines_exist = 'TRUE' THEN
l_func_curr_det := jai_plsql_cache_pkg.return_sob_curr(p_org_id => pr_orde
r_line.ORG_ID);
v_set_of_books_id := l_func_curr_det.ledger_id;
v_converted_rate := jai_cmn_utils_pkg.currency_conversion(v_set_of_books_i
d,
pr_header_info.c
urrency_code,
pr_header_info.c
onv_date,
pr_header_info.c
onv_type_code,
pr_header_info.c
onv_rate);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1423 pr_header_info.customer_id '||pr_header_info.customer_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1424 pr_order_line.ship_to_ORG_id '||pr_order_line.ship_to_ORG_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1425 pr_order_line.inventory_item_id '||pr_order_line.inventory_item
_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1426 pr_order_line.ORDER_QUANTITY_UOM '||pr_order_line.ORDER_QUANTIT
Y_UOM);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1427 pr_order_line.unit_selling_price '||pr_order_line.unit_selling_
price);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1428 v_set_of_books_id '||v_set_of_books_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1429 pr_header_info.conv_type_code '||pr_header_info.conv_type_code)
;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1430 pr_header_info.conv_rate '||pr_header_info.conv_rate);
v_assessable_value := jai_om_utils_pkg.get_oe_assessable_value(p_customer_
=> pr_header_info.customer_id,
p_ship_to_s
ite_use_id => NVL(pr_order_line.ship_to_ORG_id, 0),
p_inventory
_item_id => pr_order_line.inventory_item_id,
p_uom_code
=> pr_order_line.ORDER_QUANTITY_UOM,
p_default_p
rice
=> pr_order_line.unit_selling_price,
p_ass_value
_date
=> pr_header_info.date_ordered,
p_sob_id
=> v_set_of_books_id,
p_curr_conv
id

_code

=> pr_header_info.conv_type_code,
p_conv_rate
=> pr_header_info.conv_rate

);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1443 v_assessable_amount '||v_assessable_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1444 pr_header_info.conv_rate '||pr_header_info.conv_rate);
v_assessable_amount := NVL(v_assessable_value, 0) * NVL(pr_order_line.orde
red_quantity, 0);
v_line_tax_amount := v_line_amount;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1448 v_line_tax_amount '||v_line_tax_amount);
ln_vat_assessable_value := jai_general_pkg.ja_in_vat_assessable_value(p_pa
=> pr_header_info.customer_id,
p_pa
rty_site_id
=> NVL(pr_order_line.ship_to_ORG_id, 0),
p_in
ventory_item_id => pr_order_line.inventory_item_id,
p_uo
m_code
=> pr_order_line.ORDER_QUANTITY_UOM,
p_de
fault_price
=> pr_order_line.unit_selling_price,
p_as
s_value_date
=> pr_header_info.date_ordered,
p_pa
rty_type
=> 'C');
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1458 ln_vat_assessable_value '||ln_vat_assessable_value);
ln_vat_assessable_value := nvl(ln_vat_assessable_value, 0) * NVL(pr_order_
line.ordered_quantity, 0);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1460 ln_vat_assessable_value '||ln_vat_assessable_value);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1461 pr_order_line.ordered_quantity '||pr_order_line.ordered_quantit
y);
rty_id

IF v_assessable_value <> rec_cur_get_rma_entry_lines.assessable_value THEN


jai_om_tax_pkg.recalculate_oe_taxes(pr_order_line.header_id,
pr_order_line.line_id,
v_assessable_amount,
ln_vat_assessable_value,
v_line_tax_amount,
rec_cur_get_rma_entry_lines.inventor
y_item_id,
rec_cur_get_rma_entry_lines.quantity
,
rec_cur_get_rma_entry_lines.uom,
v_converted_rate,
pr_order_line.last_update_date,
pr_order_line.last_updated_by,
pr_order_line.last_update_login);
UPDATE JAI_OM_OE_SO_LINES
SET assessable_value = v_assessable_value,
tax_amount
= NVL(v_line_tax_amount, 0),

line_tot_amount

= v_line_amount +
NVL(v_line_tax_amount, 0),
last_update_date = pr_order_line.last_update_date,
last_updated_by = pr_order_line.last_updated_by,
last_update_login = pr_order_line.last_update_login
WHERE header_id = pr_order_line.header_id
AND line_id = pr_order_line.line_id;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_R
ETURN_TO_ORDER','1487 no.of rows update in JAI_OM_SO_LINES are '||sql%rowcount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_R
ETURN_TO_ORDER','1488 UPDATE JAI_OM_OE_SO_LINES v_assessable_value '||v_assessab
le_value);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_R
ETURN_TO_ORDER','1489 UPDATE JAI_OM_OE_SO_LINES v_line_tax_amount '||v_line_tax_
amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_R
ETURN_TO_ORDER','1490 UPDATE JAI_OM_OE_SO_LINES pr_order_line.header_id '||pr_or
der_line.header_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_R
ETURN_TO_ORDER','1491 UPDATE JAI_OM_OE_SO_LINES pr_order_line.line_id '||pr_orde
r_line.line_id);
END IF;
END IF;
EXCEPTION
WHEN OTHERS THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1500 Exception occured in COPY_RETURN_TO_ORDER procedure');
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1501 sqlcode '||sqlcode);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_RETURN
_TO_ORDER','1502 sqlerrm '||sqlerrm);
RAISE;
END COPY_RETURN_TO_ORDER;
/*
REM +======================================================================+
REM NAME
COPY_ORDER_TO_RETURN
REM
REM DESCRIPTION COPY RETURN TAXES and LINES FROM ORIGINAL ORDER
REM
REM NOTES
Call from procdure COPY_SOURCE_ORDER
REM
REM +======================================================================+
*/
PROCEDURE COPY_ORDER_TO_RETURN(pr_order_line
t_rec%type,
p_order_number
NUMBER,
px_return_code
out nocopy varchar2,
px_return_message out nocopy varchar2) IS
-- get the details from JAI_OM_WSH_LINES_ALL table
CURSOR cur_get_picking_lines(p_source_document_id
OE_ORDER_LINES_ALL.SOUR
CE_DOCUMENT_ID%TYPE,
p_source_document_line_id OE_ORDER_LINES_ALL.SOUR
CE_DOCUMENT_LINE_ID%TYPE) IS
SELECT pl.inventory_item_id inventory_item_id,

pl.unit_code unit_code,
sum(pl.quantity) quantity,
pl.tax_category_id tax_category_id,
pl.selling_price selling_price,
sum(pl.tax_amount) tax_amount,
min(pl.delivery_detail_id) delivery_detail_id
, pl.organization_id, pl.location_id /*Added by mmurtuza for bu
g 17015322*/
FROM JAI_OM_WSH_LINES_ALL pl
WHERE pl.order_header_id = p_source_document_id
AND pl.order_line_id = p_source_document_line_id
GROUP BY pl.inventory_item_id,
pl.unit_code,
pl.selling_price,
pl.tax_category_id
,pl.organization_id, pl.location_id; /*Added by mmurtuza
for bug 17015322*/
cursor
select
from
where

c_sales_order_cur is
quantity, service_type_code
JAI_OM_OE_SO_LINES
line_id = pr_order_line.reference_line_id;

CURSOR cur_rma_entry_line_exists(p_line_id OE_ORDER_LINES_ALL.LINE_ID%TYPE,


p_header_id OE_ORDER_LINES_ALL.HEADER_ID%TYPE
) IS
SELECT 'X'
FROM JAI_OM_OE_RMA_LINES
WHERE rma_line_id = p_line_id
AND rma_header_id = p_header_id;
l_exists VARCHAR2(1);
rec_cur_get_picking_lines cur_get_picking_lines%ROWTYPE;
CURSOR cur_get_picking_tax_lines(p_source_document_id
JAI_OM_WSH_LINES_AL
L.ORDER_HEADER_ID%TYPE,
p_source_document_line_id JAI_OM_WSH_LINES_AL
L.ORDER_LINE_ID%TYPE) IS
SELECT ptl.tax_line_no tax_line_no,
ptl.tax_id tax_id,
ptl.tax_rate tax_rate,
ptl.qty_rate qty_rate,
ptl.uom uom,
ptl.precedence_1 precedence_1,
ptl.precedence_2 precedence_2,
ptl.precedence_3 precedence_3,
ptl.precedence_4 precedence_4,
ptl.precedence_5 precedence_5,
ptl.precedence_6 precedence_6,
ptl.precedence_7 precedence_7,
ptl.precedence_8 precedence_8,
ptl.precedence_9 precedence_9,
ptl.precedence_10 precedence_10,
jtc.tax_type tax_type,
nvl(jtc.rounding_factor, 0) rounding_factor,
SUM(ptl.tax_amount) tax_amount,
SUM(ptl.base_tax_amount) base_tax_amount,
SUM(ptl.func_tax_amount) func_tax_amount,
MIN(ptl.delivery_detail_id) delivery_detail_id
FROM JAI_OM_WSH_LINES_ALL pl,

WHERE
AND
AND
AND
GROUP

JAI_OM_WSH_LINE_TAXES ptl,
JAI_CMN_TAXES_ALL
jtc
ptl.delivery_detail_id = pl.delivery_detail_id
pl.order_header_id = p_source_document_id
pl.order_line_id = p_source_document_line_id
jtc.tax_id = ptl.tax_id
by ptl.tax_line_no,
ptl.tax_id,
ptl.tax_rate,
ptl.qty_rate,
ptl.uom,
precedence_1,
precedence_2,
precedence_3,
precedence_4,
precedence_5,
precedence_6,
precedence_7,
precedence_8,
precedence_9,
precedence_10,
jtc.tax_type,
nvl(jtc.rounding_factor, 0);

CURSOR c_get_quantity(p_source_document_id
JAI_OM_WSH_LINES_ALL.order_hea
der_id%type,
p_source_document_line_id JAI_OM_WSH_LINES_ALL.order_lin
e_id%type) IS
--commented out by zhiwei.xin for bug#14669425 on 16-Oct-2012 begin
/*SELECT sum(quantity)
FROM JAI_OM_WSH_LINES_ALL pl, JAI_OM_WSH_LINE_TAXES ptl
WHERE ptl.delivery_detail_id = pl.delivery_detail_id
AND pl.order_header_id = p_source_document_id
AND pl.order_line_id = p_source_document_line_id;*/
--commented out by zhiwei.xin for bug#14669425 on 16-Oct-2012 end.
-- added by zhiwei.xin for bug#14669425 on 16-Oct-2012 begin
-- added SUM clause for the 16806599
SELECT SUM(quantity)
FROM JAI_OM_WSH_LINES_ALL
WHERE order_header_id = p_source_document_id
AND order_line_id = p_source_document_line_id;
-- added by zhiwei.xin for bug#14669425 on 16-Oct-2012 end.
CURSOR
SELECT
FROM
WHERE

requested_qty_uom_cur(p_delivery_detail_id NUMBER) IS
requested_quantity_uom
wsh_delivery_details
delivery_detail_id = p_delivery_detail_id;

CURSOR
SELECT
FROM
WHERE
AND

c_check_vat_type_tax_exists(cp_tax_type VARCHAR2) IS
1
jai_regime_tax_types_v
regime_code = jai_constants.vat_regime
tax_type = cp_tax_type;

cursor cur_get_ddetail_id(p_source_document_id
OE_ORDER_LINES_ALL.SOURCE_
DOCUMENT_ID%TYPE,
p_source_document_line_id OE_ORDER_LINES_ALL.SOURCE_
DOCUMENT_LINE_ID%TYPE) is
select delivery_detail_id
from JAI_OM_OE_RMA_LINES

where rma_header_id = p_source_document_id


AND rma_line_id = p_source_document_line_id;
v_ddetail_id JAI_OM_OE_RMA_LINES.delivery_detail_id%type;
CURSOR c_get_detail_id(p_ddetail_id JAI_OM_OE_RMA_LINES.delivery_detail_id%typ
e) IS
SELECT wdd.delivery_detail_id, wnd.confirm_date
FROM wsh_delivery_details
wdd,
wsh_delivery_assignments wda,
wsh_new_deliveries
wnd
WHERE wdd.delivery_detail_id = p_ddetail_id
AND wda.delivery_detail_id = wdd.delivery_detail_id
AND wnd.delivery_id = wda.delivery_id;
CURSOR c_get_days_flags IS
SELECT excise_return_days,
sales_return_days,
vat_return_days,
nvl(manufacturing, 'N') manufacturing,
nvl(trading, 'N') trading
FROM JAI_CMN_INVENTORY_ORGS
WHERE organization_id = pr_order_line.ship_from_org_id
AND location_id = 0;
CURSOR
SELECT
FROM
WHERE

c_ordered_date IS
ordered_date
oe_order_headers_all
header_id = pr_order_line.header_id;

CURSOR
SELECT
FROM
WHERE
AND

c_fulfilled_date IS
CREATION_DATE
JAI_OM_WSH_LINES_ALL
ORDER_LINE_ID = pr_order_line.reference_line_id
SHIPPABLE_FLAG = 'N';

CURSOR c_get_ship_qty(p_source_document_id
NUMBER,
p_source_document_line_id NUMBER) IS
SELECT SUM(wdd.shipped_quantity) qty
FROM wsh_delivery_details wdd
WHERE wdd.delivery_detail_id in
(SELECT delivery_detail_id
FROM JAI_OM_WSH_LINES_ALL
WHERE order_header_id = p_source_document_id
and order_line_id = p_source_document_line_id)
AND wdd.inventory_item_id = pr_order_line.inventory_item_id;
CURSOR cur_get_picking_tax_lines_new(p_source_document_id
JAI_OM_WSH_LINE
S_ALL.ORDER_HEADER_ID%TYPE,
p_source_document_line_id JAI_OM_WSH_LINE
S_ALL.ORDER_LINE_ID%TYPE) IS
SELECT ptl.tax_line_no tax_line_no,
ptl.tax_id tax_id,
ptl.tax_rate tax_rate,
ptl.qty_rate qty_rate,
ptl.uom uom,
ptl.precedence_1 precedence_1,
ptl.precedence_2 precedence_2,
ptl.precedence_3 precedence_3,

FROM
WHERE
AND
AND
GROUP

ptl.precedence_4 precedence_4,
ptl.precedence_5 precedence_5,
ptl.precedence_6 precedence_6,
ptl.precedence_7 precedence_7,
ptl.precedence_8 precedence_8,
ptl.precedence_9 precedence_9,
ptl.precedence_10 precedence_10,
SUM(ptl.tax_amount) tax_amount,
SUM(ptl.base_tax_amount) base_tax_amount,
SUM(ptl.func_tax_amount) func_tax_amount,
MIN(ptl.delivery_detail_id) delivery_detail_id
JAI_OM_WSH_LINES_ALL pl, JAI_OM_WSH_LINE_TAXES ptl
ptl.delivery_detail_id = pl.delivery_detail_id
pl.order_header_id = p_source_document_id
pl.order_line_id = p_source_document_line_id
by tax_line_no,
tax_id,
tax_rate,
qty_rate,
uom,
precedence_1,
precedence_2,
precedence_3,
precedence_4,
precedence_5,
precedence_6,
precedence_7,
precedence_8,
precedence_9,
precedence_10;

-- Check whether a rma_tax_lines exist for the new line_id and tax_id
CURSOR cur_chk_rma_tax_lines_exists(p_line_id JAI_OM_OE_RMA_TAXES.RMA_LINE_ID%
TYPE,
p_tax_id JAI_OM_OE_RMA_TAXES.TAX_ID%TYPE)
IS
SELECT 'X'
FROM JAI_OM_OE_RMA_TAXES
WHERE rma_line_id = p_line_id
AND tax_id = p_tax_id;
/*Added cursor by mmurtuza for bug 17015322*/
cursor cur_get_order_type(p_src_header_id NUMBER) IS
SELECT order_type_id from oe_order_headers_all
where header_id = p_src_header_id;
l_tax_exists VARCHAR2(1);
lv_check_vat_type_exists
v_date_ordered
v_date_confirmed
v_delivery_detail_id
v_excise_return_days
v_sales_return_days
v_vat_return_days
v_excise_flag
v_sales_flag
v_vat_flag
v_round_tax
v_round_base

VARCHAR2(1);
DATE;
DATE;
JAI_OM_WSH_LINES_ALL.delivery_detail_id % TYPE;
JAI_CMN_INVENTORY_ORGS.excise_return_days % TYPE;
JAI_CMN_INVENTORY_ORGS.sales_return_days % TYPE;
JAI_CMN_INVENTORY_ORGS.vat_return_days % TYPE;
VARCHAR2(1);
VARCHAR2(1);
VARCHAR2(1);
NUMBER;
NUMBER;

v_round_func
v_tax_total
v_manufacturing
v_trading
v_shipped_quantity
v_quantity
v_requested_quantity_uom
v_conversion_rate
v_cor_amount
v_orig_ord_qty
v_rma_quantity_uom
v_service_type_code

NUMBER;
NUMBER;
JAI_CMN_INVENTORY_ORGS.manufacturing%type;
JAI_CMN_INVENTORY_ORGS.trading%type;
wsh_delivery_details.shipped_quantity % TYPE;
JAI_OM_WSH_LINES_ALL.quantity % TYPE;
VARCHAR2(3);
NUMBER := 0;
JAI_OM_WSH_LINES_ALL.tax_amount % TYPE;
Number;
VARCHAR2(3);
varchar2(30);

v_order_type_id NUMBER; /*mmurtuza for bug 17015322*/


v_asst_register_id NUMBER; /*mmurtuza for bug 17015322*/
v_register_code VARCHAR2(30); /*mmurtuza for bug 17015322*/
BEGIN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_TO_R
ETURN','begin of COPY_RETURN_TO_ORDER procedure');
/* *****************************************************************************
*************************
Change History
1. 27/May/2013 nkodakan for bug 16806599
Issue : RMA ORDER GETTING CREATED WITH DOUBLED TAX AMOUNT THAN ORIGINAL ORDER
Fix : Added a SUM clause in a cursor c_get_quantity
2. 29-Jan-2013 mmurtuza for bug 17015322
Issue:
BOND REGISTER SHOULD NOT BE UPDATED ON RMA OF EXPORT INVOICE.
Fix: Added code to make the excise taxes zero in RMA incase the reference ord
er is attached to bond register
********************************************************************************
***********************/
px_return_code
:= jai_constants.successful;
v_rma_quantity_uom := pr_order_line.order_quantity_uom;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_TO
_RETURN','1772 pr_order_line.order_quantity_uom '||pr_order_line.order_quantity_
uom);
OPEN c_sales_order_cur;
FETCH c_sales_order_cur
INTO v_orig_ord_qty, v_service_type_code;
CLOSE c_sales_order_cur;
/*mmurtuza for bug 17015322*/
OPEN cur_get_order_type(pr_order_line.SOURCE_DOCUMENT_ID);
fetch cur_get_order_type into v_order_type_id;
close cur_get_order_type;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_TO
_RETURN','1778 v_orig_ord_qty '||v_orig_ord_qty);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_TO
_RETURN','1779 v_service_type_code '||v_service_type_code);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_TO
_RETURN','1781 pr_order_line.SOURCE_DOCUMENT_ID '||pr_order_line.SOURCE_DOCUMENT

_ID);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_TO
_RETURN','1782 pr_order_line.SOURCE_DOCUMENT_LINE_ID '||pr_order_line.SOURCE_DOC
UMENT_LINE_ID);
OPEN cur_get_picking_lines(p_source_document_id
=> pr_order_line.SOURC
E_DOCUMENT_ID,
p_source_document_line_id => pr_order_line.SOURCE
_DOCUMENT_LINE_ID);
FETCH cur_get_picking_lines
INTO rec_cur_get_picking_lines;
IF cur_get_picking_lines%FOUND THEN
OPEN cur_rma_entry_line_exists(p_line_id => pr_order_line.line_id,
p_header_id => pr_order_line.header_id);
FETCH cur_rma_entry_line_exists
INTO l_exists;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDE
R_TO_RETURN','1793 l_exists '||l_exists);
/*
IF a record does not exists with the newline_id and header_id
only then go ahead with the insert
*/
IF cur_rma_entry_line_exists%NOTFOUND THEN
-- Insert a record into JAI_OM_OE_RMA_LINES
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDE
R_TO_RETURN','1800 INSERT INTO JAI_OM_OE_RMA_LINES pr_order_line.line_number '||
pr_order_line.line_number);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDE
R_TO_RETURN','1801 INSERT INTO JAI_OM_OE_RMA_LINES pr_order_line.line_id '||pr_o
rder_line.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDE
R_TO_RETURN','1802 INSERT INTO JAI_OM_OE_RMA_LINES pr_order_line.header_id '||pr
_order_line.header_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDE
R_TO_RETURN','1803 INSERT INTO JAI_OM_OE_RMA_LINES pr_order_line.ordered_quantit
y '||pr_order_line.ordered_quantity);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDE
R_TO_RETURN','1804 INSERT INTO JAI_OM_OE_RMA_LINES rec_cur_get_picking_lines.tax
_amount '||rec_cur_get_picking_lines.tax_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDE
R_TO_RETURN','1805 INSERT INTO JAI_OM_OE_RMA_LINES rec_cur_get_picking_lines.del
ivery_detail_id '||rec_cur_get_picking_lines.delivery_detail_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDE
R_TO_RETURN','1806 INSERT INTO JAI_OM_OE_RMA_LINES p_order_number '||p_order_num
ber);
INSERT INTO JAI_OM_OE_RMA_LINES
(rma_line_number,
rma_line_id,
rma_header_id,
rma_number,
inventory_item_id,
uom,
quantity,
tax_category_id,
selling_price,
tax_amount,
delivery_detail_id,
creation_date,
created_by,

last_update_date,
last_updated_by,
last_update_login,
service_type_code,
ship_to_org_id)
VALUES
(pr_order_line.line_number,
pr_order_line.line_id,
pr_order_line.header_id,
p_order_number,
rec_cur_get_picking_lines.inventory_item_id,
v_rma_quantity_uom,
pr_order_line.ordered_quantity,
rec_cur_get_picking_lines.tax_category_id,
pr_order_line.unit_selling_price,
rec_cur_get_picking_lines.tax_amount,
rec_cur_get_picking_lines.delivery_detail_id,
pr_order_line.creation_date,
pr_order_line.created_by,
pr_order_line.last_update_date,
pr_order_line.last_updated_by,
pr_order_line.last_update_login,
v_service_type_code,
pr_order_line.ship_to_org_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_O
RDER_TO_RETURN','1846 no.of rows INSERT INTO JAI_OM_OE_RMA_LINES are '||sql%row
count);
END IF;
CLOSE cur_rma_entry_line_exists;
/*mmurtuza for bug 17015322*/
jai_cmn_bond_register_pkg.get_register_id (rec_cur_get_picking_lines.o
rganization_id
,
rec_cur_get_picking_lines.location_
id
,
v_order_type_id
,
'Y'
,
v_asst_register_id
,
v_register_code
);
open cur_get_ddetail_id(p_source_document_id

=> pr_order_line.header_

id,
p_source_document_line_id => pr_order_line.line_id
);
fetch cur_get_ddetail_id
into v_ddetail_id;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDE
R_TO_RETURN','1854 v_ddetail_id '||v_ddetail_id);
close cur_get_ddetail_id;
/*
|| Following code copied from internal procedure rma_insert of Procedure J
A_IN_RMA_MAINTAIN (version 115.5)
*/
OPEN c_get_detail_id(v_ddetail_id);
FETCH c_get_detail_id
INTO v_delivery_detail_id, v_date_confirmed;
CLOSE c_get_detail_id;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_

TO_RETURN','1864 v_delivery_detail_id '||v_delivery_detail_id);


jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_RETURN','1865 v_date_confirmed '||v_date_confirmed);
/* moved code from below IF condition to here to check VAT return days for
both
shippable and non-shippalbe lines.*/
OPEN c_get_days_flags;
FETCH c_get_days_flags
INTO v_excise_return_days,
v_sales_return_days,
v_vat_return_days,
v_manufacturing,
v_trading;
CLOSE c_get_days_flags;
OPEN c_ordered_date;
FETCH c_ordered_date
INTO v_date_ordered;
CLOSE c_ordered_date;
IF v_delivery_detail_id IS NOT NULL THEN
IF (v_excise_return_days IS NULL OR
(v_date_ordered - v_date_confirmed) <=
v_excise_return_days) THEN
v_excise_flag := 'Y';
ELSE
v_excise_flag := 'N';
END IF;
IF (v_sales_return_days IS NULL OR
(v_date_ordered - v_date_confirmed) <=
v_sales_return_days) THEN
v_sales_flag := 'Y';
ELSE
v_sales_flag := 'N';
END IF;
IF (v_vat_return_days IS NULL OR
(v_date_ordered - v_date_confirmed) <= v_vat_return_days) THEN
v_vat_flag := 'Y';
ELSE
v_vat_flag := 'N';
END IF;
/*Fetch Shipped Quantity based on Source Order Details instead of Delive
ry Details
as a single Order Line can have multiple Delivery Details resulting in i
ncorrect Shipped Quantity*/
OPEN c_get_ship_qty(pr_order_line.SOURCE_DOCUMENT_ID,
pr_order_line.SOURCE_DOCUMENT_LINE_ID);
FETCH c_get_ship_qty
INTO v_shipped_quantity;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_OR
DER_TO_RETURN','1914 v_shipped_quantity '||v_shipped_quantity);
CLOSE c_get_ship_qty;
OPEN c_get_quantity(p_source_document_id
=> pr_order_line.SOURCE_DO
CUMENT_ID,
p_source_document_line_id => pr_order_line.SOURCE_DO

CUMENT_LINE_ID);
FETCH c_get_quantity
INTO v_quantity;
CLOSE c_get_quantity;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDE
R_TO_RETURN','1921 v_quantity '||v_quantity);
IF v_quantity <> 0 THEN
OPEN requested_qty_uom_cur(v_delivery_detail_id);
FETCH requested_qty_uom_cur
INTO v_requested_quantity_uom;
CLOSE requested_qty_uom_cur;
INV_CONVERT.inv_um_conversion(v_requested_quantity_uom,
v_rma_quantity_uom,
pr_order_line.inventory_item_id,
v_conversion_rate);
IF NVL(v_conversion_rate, 0) <= 0 THEN
INV_CONVERT.inv_um_conversion(v_requested_quantity_uom,
v_rma_quantity_uom,
0,
v_conversion_rate);
IF NVL(v_conversion_rate, 0) <= 0 THEN
v_conversion_rate := 1; --Changed v_conversion_rate from 0 to 1, s
o that divide by zero error does not occur.
END IF;
END IF;
v_cor_amount := (pr_order_line.ordered_quantity / v_quantity) *
(1 / v_conversion_rate);
END IF;
IF ROUND(v_shipped_quantity, 2) <
ROUND(pr_order_line.ordered_quantity * (1 / v_conversion_rate), 2) TH
EN
RAISE_APPLICATION_ERROR(-20401,
'RMA quantity can NOT be more than shipped qua
ntity');
END IF;
FOR rec_cur_get_picking_tax_lines IN cur_get_picking_tax_lines(p_source_
document_id
=> pr_order_line.SOURCE_DOCUMENT_ID,
p_source_
document_line_id => pr_order_line.SOURCE_DOCUMENT_LINE_ID) LOOP
OPEN cur_chk_rma_tax_lines_exists(p_line_id => pr_order_line.line_id,
p_tax_id => rec_cur_get_picking_tax
_lines.tax_id);
FETCH cur_chk_rma_tax_lines_exists
INTO l_exists;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
ORDER_TO_RETURN','1957 l_exists '||l_exists);
IF cur_chk_rma_tax_lines_exists%NOTFOUND THEN
IF rec_cur_get_picking_tax_lines.tax_type IN
('Excise',
'Addl. Excise',
'Other Excise',
'TDS',
'CVD') THEN
v_round_tax := ROUND((v_cor_amount *
rec_cur_get_picking_tax_lines.tax_amount),
rec_cur_get_picking_tax_lines.rounding_facto

r);
v_round_base := ROUND((v_cor_amount *
rec_cur_get_picking_tax_lines.base_tax_amoun
t),
rec_cur_get_picking_tax_lines.rounding_facto
r);
v_round_func := ROUND((v_cor_amount *
rec_cur_get_picking_tax_lines.func_tax_amoun
t),
rec_cur_get_picking_tax_lines.rounding_facto
r);
ELSE
v_round_tax := ROUND((v_cor_amount *
rec_cur_get_picking_tax_lines.tax_amount),
2);
v_round_base := ROUND((v_cor_amount *
rec_cur_get_picking_tax_lines.base_tax_amoun
t),
2);
v_round_func := ROUND((v_cor_amount *
rec_cur_get_picking_tax_lines.func_tax_amoun
t),
2);
END IF;
lv_check_vat_type_exists := NULL;
OPEN c_check_Vat_type_Tax_exists(rec_cur_get_picking_tax_lines.tax_t
ype);
FETCH c_check_Vat_type_Tax_exists
INTO lv_check_vat_type_exists;
CLOSE c_check_Vat_type_Tax_exists;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
ORDER_TO_RETURN','1993 lv_check_vat_type_exists '||lv_check_vat_type_exists);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
ORDER_TO_RETURN','1994 rec_cur_get_picking_tax_lines.tax_type '||rec_cur_get_pic
king_tax_lines.tax_type);
IF (rec_cur_get_picking_tax_lines.tax_type IN
('Excise',
'Addl. Excise',
'Other Excise',
JAI_CONSTANTS.TAX_TYPE_SH_EXC_EDU_CESS,
JAI_CONSTANTS.TAX_TYPE_EXC_EDU_CESS) AND
(v_excise_flag = 'N' OR v_register_code = 'BOND_REG')) OR /*added
condition of bond reg by mmurtuza for bug 17015322*/
(rec_cur_get_picking_tax_lines.tax_type IN
('Sales Tax', 'CST') AND v_sales_flag = 'N') OR
(lv_check_vat_type_exists = 1 AND v_vat_flag = 'N') THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COP
Y_ORDER_TO_RETURN','2005 in if IF (rec_cur_get_picking_tax_lines.tax_type IN');
v_round_tax := 0;
v_round_base := 0;
v_round_func := 0;
END IF;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
ORDER_TO_RETURN','2011 INSERT INTO JAI_OM_OE_RMA_TAXES pr_order_line.line_id '||
pr_order_line.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
ORDER_TO_RETURN','2012 INSERT INTO JAI_OM_OE_RMA_TAXES rec_cur_get_picking_tax_l

ines.tax_rate '||rec_cur_get_picking_tax_lines.tax_rate);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
ORDER_TO_RETURN','2013 INSERT INTO JAI_OM_OE_RMA_TAXES rec_cur_get_picking_tax_l
ines.qty_rate '||rec_cur_get_picking_tax_lines.qty_rate);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
ORDER_TO_RETURN','2014 INSERT INTO JAI_OM_OE_RMA_TAXES tax_amount '||v_round_tax
);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
ORDER_TO_RETURN','2015 INSERT INTO JAI_OM_OE_RMA_TAXES base_tax_amount '||v_roun
d_base);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
ORDER_TO_RETURN','2016 INSERT INTO JAI_OM_OE_RMA_TAXES func_tax_amount '||v_roun
d_func);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
ORDER_TO_RETURN','2017 INSERT INTO JAI_OM_OE_RMA_TAXES delivery_detail_id '||rec
_cur_get_picking_tax_lines.delivery_detail_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
ORDER_TO_RETURN','2018 INSERT INTO JAI_OM_OE_RMA_TAXES rec_cur_get_picking_tax_l
ines.tax_id '||rec_cur_get_picking_tax_lines.tax_id);
INSERT INTO JAI_OM_OE_RMA_TAXES
(rma_line_id,
tax_line_no,
tax_id,
tax_rate,
qty_rate,
uom,
tax_amount,
base_tax_amount,
func_tax_amount,
precedence_1,
precedence_2,
precedence_3,
precedence_4,
precedence_5,
precedence_6,
precedence_7,
precedence_8,
precedence_9,
precedence_10,
delivery_detail_id,
creation_date,
created_by,
last_update_date,
last_updated_by,
last_update_login)
VALUES
(pr_order_line.line_id,
rec_cur_get_picking_tax_lines.tax_line_no,
rec_cur_get_picking_tax_lines.tax_id,
rec_cur_get_picking_tax_lines.tax_rate,
rec_cur_get_picking_tax_lines.qty_rate,
rec_cur_get_picking_tax_lines.uom,
v_round_tax,
v_round_base,
v_round_func,
rec_cur_get_picking_tax_lines.precedence_1,
rec_cur_get_picking_tax_lines.precedence_2,
rec_cur_get_picking_tax_lines.precedence_3,

rec_cur_get_picking_tax_lines.precedence_4,
rec_cur_get_picking_tax_lines.precedence_5,
rec_cur_get_picking_tax_lines.precedence_6,
rec_cur_get_picking_tax_lines.precedence_7,
rec_cur_get_picking_tax_lines.precedence_8,
rec_cur_get_picking_tax_lines.precedence_9,
rec_cur_get_picking_tax_lines.precedence_10,
rec_cur_get_picking_tax_lines.delivery_detail_id,
pr_order_line.creation_date,
pr_order_line.created_by,
pr_order_line.last_update_date,
pr_order_line.last_updated_by,
pr_order_line.last_update_login);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CO
PY_ORDER_TO_RETURN','2074 no of rows INSERT INTO JAI_OM_OE_RMA_TAXES are '||sql%
rowcount);
IF rec_cur_get_picking_tax_lines.tax_type <> 'TDS' THEN
v_tax_total := NVL(v_tax_total, 0) + v_round_tax;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COP
Y_ORDER_TO_RETURN','2076 v_tax_total '||v_tax_total);
END IF;
END IF; --IF cur_chk_rma_tax_lines_exists%NOTFOUND
CLOSE cur_chk_rma_tax_lines_exists;
END LOOP;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.C
OPY_ORDER_TO_RETURN','2081 UPDATE JAI_OM_OE_RMA_LINES tax_amount '||v_tax_total)
;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.C
OPY_ORDER_TO_RETURN','2082 UPDATE JAI_OM_OE_RMA_LINES rma_line_id '||pr_order_li
ne.line_id);
UPDATE JAI_OM_OE_RMA_LINES
SET tax_amount = v_tax_total
WHERE rma_line_id = pr_order_line.line_id;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORD
ER_TO_RETURN','2086 no.of rows updated in JAI_OM_OE_RMA_LINES are '||sql%rowcoun
t);
-- need to process copying taxes from referenced SO line for non-shippab
le RMA line whose delivery_detail_id is NULL
ELSIF NVL(pr_order_line.SHIPPABLE_FLAG, 'Y') = 'N' THEN
-- need to check VAT flag for non-shippable, if the validation fails, th
en vat taxes amounts should be copied as zero.
OPEN c_fulfilled_date;
FETCH c_fulfilled_date
INTO v_date_confirmed;
CLOSE c_fulfilled_date;
IF (v_vat_return_days IS NULL OR
(v_date_ordered - v_date_confirmed) <= v_vat_return_days) THEN
v_vat_flag := 'Y';
ELSE
v_vat_flag := 'N';
END IF;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDE
R_TO_RETURN','2103 pr_order_line.ORDERED_QUANTITY '||pr_order_line.ORDERED_QUANT
ITY);
IF pr_order_line.ORDERED_QUANTITY <> 0 THEN
FOR tax_line_rec IN (SELECT tax_line_no,
precedence_1,

precedence_2,
precedence_3,
precedence_4,
precedence_5,
sptl.tax_id,
sptl.tax_rate,
sptl.qty_rate,
uom,
sptl.tax_amount,
nvl(jtc.rounding_factor, 0) rounding_facto
r,
base_tax_amount,
func_tax_amount,
jtc.tax_type,
precedence_6,
precedence_7,
precedence_8,
precedence_9,
precedence_10
FROM JAI_OM_WSH_LINE_TAXES sptl,
JAI_CMN_TAXES_ALL
jtc
WHERE order_line_id =
pr_order_line.reference_line_id
AND jtc.tax_id = sptl.tax_id) LOOP
lv_check_vat_type_exists := NULL;
OPEN c_check_Vat_type_Tax_exists(tax_line_rec.tax_type);
FETCH c_check_Vat_type_Tax_exists
INTO lv_check_vat_type_exists;
CLOSE c_check_Vat_type_Tax_exists;
IF (lv_check_vat_type_exists = 1 AND v_vat_flag = 'N') THEN
v_round_tax := 0;
v_round_base := 0;
v_round_func := 0;
ELSE
v_round_tax := tax_line_rec.tax_amount;
v_round_base := tax_line_rec.base_tax_amount;
v_round_func := tax_line_rec.func_tax_amount;
END IF; -- lv_check_vat_type_exists = 1 AND v_vat_flag = 'N'
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
ORDER_TO_RETURN','2146 INSERT INTO JAI_OM_OE_RMA_TAXES rma_line_id '||pr_order_l
ine.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
ORDER_TO_RETURN','2147 INSERT INTO JAI_OM_OE_RMA_TAXES tax_amount '||v_round_tax
);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
ORDER_TO_RETURN','2148 INSERT INTO JAI_OM_OE_RMA_TAXES base_tax_amount '||v_roun
d_base);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
ORDER_TO_RETURN','2149 INSERT INTO JAI_OM_OE_RMA_TAXES func_tax_amount '||v_roun
d_func);
INSERT INTO JAI_OM_OE_RMA_TAXES
(rma_line_id,
delivery_detail_id,
tax_line_no,
precedence_1,
precedence_2,

precedence_3,
precedence_4,
precedence_5,
tax_id,
tax_rate,
qty_rate,
uom,
tax_amount,
base_tax_amount,
func_tax_amount,
creation_date,
created_by,
last_update_date,
last_updated_by,
last_update_login,
precedence_6,
precedence_7,
precedence_8,
precedence_9,
precedence_10)
VALUES
(pr_order_line.line_id,
NULL,
tax_line_rec.tax_line_no,
tax_line_rec.precedence_1,
tax_line_rec.precedence_2,
tax_line_rec.precedence_3,
tax_line_rec.precedence_4,
tax_line_rec.precedence_5,
tax_line_rec.tax_id,
tax_line_rec.tax_rate,
tax_line_rec.qty_rate,
tax_line_rec.uom,
v_round_tax,
v_round_base,
v_round_func,
pr_order_line.creation_date,
pr_order_line.created_by,
pr_order_line.last_update_date,
pr_order_line.last_updated_by,
pr_order_line.last_update_login,
tax_line_rec.precedence_6,
tax_line_rec.precedence_7,
tax_line_rec.precedence_8,
tax_line_rec.precedence_9,
tax_line_rec.precedence_10);
END LOOP; -- tax_line_rec IN (SELECT tax_line_no ......
END IF; --IF pr_order_line.ORDERED_QUANTITY <> 0
END IF; --IF v_delivery_detail_id IS NOT NULL
ELSE
-- Details in picking lines not found . Raise an error message
CLOSE cur_get_picking_lines;
/*
RAISE_APPLICATION_ERROR (-20001,'No data found in localisatio
n shipping tables, hence copy cannot be done');
*/
px_return_code
:= jai_constants.expected_error;
px_return_message := 'No data found in localisation shipping tables,hence

copy cannot be done';


jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_
TO_RETURN','2217 before Return ');
return;
END IF;
CLOSE cur_get_picking_lines;
/************************************ Order TO Return tax lines computation
s ********************************************/
FOR rec_cur_get_picking_tax_lines IN cur_get_picking_tax_lines_new(p_source_
document_id
=> pr_order_line.SOURCE_DOCUMENT_ID,
p_source_
document_line_id => pr_order_line.SOURCE_DOCUMENT_LINE_ID) LOOP
OPEN cur_chk_rma_tax_lines_exists(p_line_id => pr_order_line.line_id,
p_tax_id => rec_cur_get_picking_tax_lin
es.tax_id);
FETCH cur_chk_rma_tax_lines_exists
INTO l_tax_exists;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_OR
DER_TO_RETURN','2229 l_tax_exists '||l_tax_exists);
IF cur_chk_rma_tax_lines_exists%NOTFOUND THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_OR
DER_TO_RETURN','2231 INSERT INTO JAI_OM_OE_RMA_TAXES rma_line_id '||pr_order_lin
e.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_OR
DER_TO_RETURN','2232 INSERT INTO JAI_OM_OE_RMA_TAXES tax_amount '||rec_cur_get_p
icking_tax_lines.tax_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_OR
DER_TO_RETURN','2233 INSERT INTO JAI_OM_OE_RMA_TAXES base_tax_amount '||rec_cur_
get_picking_tax_lines.base_tax_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_OR
DER_TO_RETURN','2234 INSERT INTO JAI_OM_OE_RMA_TAXES func_tax_amount '||rec_cur_
get_picking_tax_lines.func_tax_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_OR
DER_TO_RETURN','2235 INSERT INTO JAI_OM_OE_RMA_TAXES delivery_detail_id '||rec_c
ur_get_picking_tax_lines.delivery_detail_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_OR
DER_TO_RETURN','2236 INSERT INTO JAI_OM_OE_RMA_TAXES tax_line_no '||rec_cur_get_
picking_tax_lines.tax_line_no);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_OR
DER_TO_RETURN','2237 INSERT INTO JAI_OM_OE_RMA_TAXES tax_rate '||rec_cur_get_pic
king_tax_lines.tax_rate);
INSERT INTO JAI_OM_OE_RMA_TAXES
(rma_line_id,
tax_line_no,
tax_id,
tax_rate,
qty_rate,
uom,
tax_amount,
base_tax_amount,
func_tax_amount,
precedence_1,
precedence_2,
precedence_3,
precedence_4,
precedence_5,
precedence_6,
precedence_7,

precedence_8,
precedence_9,
precedence_10,
delivery_detail_id,
creation_date,
created_by,
last_update_date,
last_updated_by,
last_update_login)
VALUES
(pr_order_line.line_id,
rec_cur_get_picking_tax_lines.tax_line_no,
rec_cur_get_picking_tax_lines.tax_id,
rec_cur_get_picking_tax_lines.tax_rate,
rec_cur_get_picking_tax_lines.qty_rate,
rec_cur_get_picking_tax_lines.uom,
rec_cur_get_picking_tax_lines.tax_amount,
rec_cur_get_picking_tax_lines.base_tax_amount,
rec_cur_get_picking_tax_lines.func_tax_amount,
rec_cur_get_picking_tax_lines.precedence_1,
rec_cur_get_picking_tax_lines.precedence_2,
rec_cur_get_picking_tax_lines.precedence_3,
rec_cur_get_picking_tax_lines.precedence_4,
rec_cur_get_picking_tax_lines.precedence_5,
rec_cur_get_picking_tax_lines.precedence_6,
rec_cur_get_picking_tax_lines.precedence_7,
rec_cur_get_picking_tax_lines.precedence_8,
rec_cur_get_picking_tax_lines.precedence_9,
rec_cur_get_picking_tax_lines.precedence_10,
rec_cur_get_picking_tax_lines.delivery_detail_id,
pr_order_line.creation_date,
pr_order_line.created_by,
pr_order_line.last_update_date,
pr_order_line.last_updated_by,
pr_order_line.last_update_login);
END IF;
CLOSE cur_chk_rma_tax_lines_exists;
END LOOP;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDER_TO_R
ETURN','2295 after the loop ');
EXCEPTION
WHEN OTHERS THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDE
R_TO_RETURN','2298 excepton occured in COPY_ORDER_TO_RETURN procedure sqlcode '|
|sqlcode);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_ORDE
R_TO_RETURN','2299 sqlerrm '||sqlerrm);
RAISE;
END COPY_ORDER_TO_RETURN;
/*
REM
REM
REM
REM
REM
REM
REM
REM

+======================================================================+
NAME
COPY_MIXED_TO_RETURN
DESCRIPTION

COPY RETURN TAXES and LINES FROM ORIGINAL MIXED ORDER

NOTES

Call from procdure COPY_SOURCE_ORDER

+======================================================================+

*/
PROCEDURE COPY_MIXED_TO_RETURN(pr_order_line
p_order_number
px_return_code
px_return_message

t_rec%type,
NUMBER,
out nocopy varchar2,
out nocopy varchar2) IS

/* fetch the details of the original RMA order


*/
CURSOR c_rma_details(cp_rma_header_id number,
cp_rma_line_id number) is
SELECT *
FROM JAI_OM_OE_RMA_LINES
WHERE rma_header_id = cp_rma_header_id
AND rma_line_id = cp_rma_line_id;
/* get the new order number from oe_order_headers_all*/
CURSOR c_rma_number(cp_rma_header_id number) is
SELECT order_number
FROM oe_order_headers_all
WHERE header_id = cp_rma_header_id;
cv_rma_details C_RMA_DETAILS%ROWTYPE;
lv_rma_number OE_ORDER_HEADERS_ALL.ORDER_NUMBER%TYPE;
-- get the details from JAI_OM_WSH_LINES_ALL table
CURSOR cur_get_picking_lines(p_source_document_id
OE_ORDER_LINES_ALL.SOUR
CE_DOCUMENT_ID%TYPE,
p_source_document_line_id OE_ORDER_LINES_ALL.SOUR
CE_DOCUMENT_LINE_ID%TYPE) IS
SELECT pl.inventory_item_id inventory_item_id,
pl.unit_code unit_code,
sum(pl.quantity) quantity,
pl.tax_category_id tax_category_id,
pl.selling_price selling_price,
sum(pl.tax_amount) tax_amount,
min(pl.delivery_detail_id) delivery_detail_id
FROM JAI_OM_WSH_LINES_ALL pl
WHERE pl.order_header_id = p_source_document_id
AND pl.order_line_id = p_source_document_line_id
GROUP BY pl.inventory_item_id,
pl.unit_code,
pl.selling_price,
pl.tax_category_id;
cursor c_sales_order_cur is
select quantity, service_type_code
from JAI_OM_OE_SO_LINES
where line_id = pr_order_line.reference_line_id;
CURSOR cur_rma_entry_line_exists(p_line_id OE_ORDER_LINES_ALL.LINE_ID%TYPE,
p_header_id OE_ORDER_LINES_ALL.HEADER_ID%TYPE
) IS
SELECT 'X'
FROM JAI_OM_OE_RMA_LINES
WHERE rma_line_id = p_line_id
AND rma_header_id = p_header_id;
l_exists VARCHAR2(1);
rec_cur_get_picking_lines cur_get_picking_lines%ROWTYPE;

CURSOR cur_get_picking_tax_lines(p_source_document_id
JAI_OM_WSH_LINES_AL
L.ORDER_HEADER_ID%TYPE,
p_source_document_line_id JAI_OM_WSH_LINES_AL
L.ORDER_LINE_ID%TYPE) IS
SELECT ptl.tax_line_no tax_line_no,
ptl.tax_id tax_id,
ptl.tax_rate tax_rate,
ptl.qty_rate qty_rate,
ptl.uom uom,
ptl.precedence_1 precedence_1,
ptl.precedence_2 precedence_2,
ptl.precedence_3 precedence_3,
ptl.precedence_4 precedence_4,
ptl.precedence_5 precedence_5,
ptl.precedence_6 precedence_6,
ptl.precedence_7 precedence_7,
ptl.precedence_8 precedence_8,
ptl.precedence_9 precedence_9,
ptl.precedence_10 precedence_10,
jtc.tax_type tax_type,
nvl(jtc.rounding_factor, 0) rounding_factor,
SUM(ptl.tax_amount) tax_amount,
SUM(ptl.base_tax_amount) base_tax_amount,
SUM(ptl.func_tax_amount) func_tax_amount,
MIN(ptl.delivery_detail_id) delivery_detail_id
FROM JAI_OM_WSH_LINES_ALL pl,
JAI_OM_WSH_LINE_TAXES ptl,
JAI_CMN_TAXES_ALL
jtc
WHERE ptl.delivery_detail_id = pl.delivery_detail_id
AND pl.order_header_id = p_source_document_id
AND pl.order_line_id = p_source_document_line_id
AND jtc.tax_id = ptl.tax_id
GROUP by ptl.tax_line_no,
ptl.tax_id,
ptl.tax_rate,
ptl.qty_rate,
ptl.uom,
precedence_1,
precedence_2,
precedence_3,
precedence_4,
precedence_5,
precedence_6,
precedence_7,
precedence_8,
precedence_9,
precedence_10,
jtc.tax_type,
nvl(jtc.rounding_factor, 0);
CURSOR cur_chk_rma_tax_lines_exists(p_line_id JAI_OM_OE_RMA_TAXES.RMA_LINE_ID%
TYPE,
p_tax_id JAI_OM_OE_RMA_TAXES.TAX_ID%TYPE)
IS
SELECT 'X'
FROM JAI_OM_OE_RMA_TAXES
WHERE rma_line_id = p_line_id
AND tax_id = p_tax_id;
CURSOR c_get_quantity(p_source_document_id
JAI_OM_WSH_LINES_ALL.order_hea

der_id%type,
p_source_document_line_id JAI_OM_WSH_LINES_ALL.order_lin
e_id%type) IS
-- cmmented out by zhiwei.xin for bug#14669425 on 16-Oct-2012 begin
/*SELECT sum(quantity)
FROM JAI_OM_WSH_LINES_ALL pl, JAI_OM_WSH_LINE_TAXES ptl
WHERE ptl.delivery_detail_id = pl.delivery_detail_id
AND pl.order_header_id = p_source_document_id
AND pl.order_line_id = p_source_document_line_id;*/
-- commented out by zhiwei.xin for bug#14669425 on 16-Oct-2012 end.
-- added by zhiwei.xin for bug#14669425 on 16-Oct-2012 begin
-- added SUM clause for the 16806599
SELECT SUM(quantity)
FROM JAI_OM_WSH_LINES_ALL
WHERE order_header_id = p_source_document_id
AND order_line_id = p_source_document_line_id;
-- added by zhiwei.xin for bug#14669425 on 16-Oct-2012 end.
CURSOR
SELECT
FROM
WHERE

requested_qty_uom_cur(p_delivery_detail_id NUMBER) IS
requested_quantity_uom
wsh_delivery_details
delivery_detail_id = p_delivery_detail_id;

CURSOR
SELECT
FROM
WHERE
AND

c_check_vat_type_tax_exists(cp_tax_type VARCHAR2) IS
1
jai_regime_tax_types_v
regime_code = jai_constants.vat_regime
tax_type = cp_tax_type;

cursor cur_get_ddetail_id(p_source_document_id
OE_ORDER_LINES_ALL.SOURCE_
DOCUMENT_ID%TYPE,
p_source_document_line_id OE_ORDER_LINES_ALL.SOURCE_
DOCUMENT_LINE_ID%TYPE) is
select delivery_detail_id
from JAI_OM_OE_RMA_LINES
where rma_header_id = p_source_document_id
AND rma_line_id = p_source_document_line_id;
v_ddetail_id JAI_OM_OE_RMA_LINES.delivery_detail_id%type;
CURSOR c_get_detail_id(p_ddetail_id JAI_OM_OE_RMA_LINES.delivery_detail_id%typ
e) IS
SELECT wdd.delivery_detail_id, wnd.confirm_date
FROM wsh_delivery_details
wdd,
wsh_delivery_assignments wda,
wsh_new_deliveries
wnd
WHERE wdd.delivery_detail_id = p_ddetail_id
AND wda.delivery_detail_id = wdd.delivery_detail_id
AND wnd.delivery_id = wda.delivery_id;
CURSOR c_get_days_flags IS
SELECT excise_return_days,
sales_return_days,
vat_return_days,
nvl(manufacturing, 'N') manufacturing,
nvl(trading, 'N') trading
FROM JAI_CMN_INVENTORY_ORGS
WHERE organization_id = pr_order_line.ship_from_org_id
AND location_id = 0;

CURSOR
SELECT
FROM
WHERE

c_ordered_date IS
ordered_date
oe_order_headers_all
header_id = pr_order_line.header_id;

CURSOR
SELECT
FROM
WHERE
AND

c_fulfilled_date IS
CREATION_DATE
JAI_OM_WSH_LINES_ALL
ORDER_LINE_ID = pr_order_line.reference_line_id
SHIPPABLE_FLAG = 'N';

CURSOR c_get_ship_qty(p_source_document_id
NUMBER,
p_source_document_line_id NUMBER) IS
SELECT SUM(wdd.shipped_quantity) qty
FROM wsh_delivery_details wdd
WHERE wdd.delivery_detail_id in
(SELECT delivery_detail_id
FROM JAI_OM_WSH_LINES_ALL
WHERE order_header_id = p_source_document_id
and order_line_id = p_source_document_line_id)
AND wdd.inventory_item_id = pr_order_line.inventory_item_id;
lv_check_vat_type_exists
v_date_ordered
v_date_confirmed
v_delivery_detail_id
v_excise_return_days
v_sales_return_days
v_vat_return_days
v_excise_flag
v_sales_flag
v_vat_flag
v_round_tax
v_round_base
v_round_func
v_tax_total
v_manufacturing
v_trading
v_shipped_quantity
v_quantity
v_requested_quantity_uom
v_conversion_rate
v_cor_amount
v_orig_ord_qty
v_rma_quantity_uom
v_service_type_code

VARCHAR2(1);
DATE;
DATE;
JAI_OM_WSH_LINES_ALL.delivery_detail_id % TYPE;
JAI_CMN_INVENTORY_ORGS.excise_return_days % TYPE;
JAI_CMN_INVENTORY_ORGS.sales_return_days % TYPE;
JAI_CMN_INVENTORY_ORGS.vat_return_days % TYPE;
VARCHAR2(1);
VARCHAR2(1);
VARCHAR2(1);
NUMBER;
NUMBER;
NUMBER;
NUMBER;
JAI_CMN_INVENTORY_ORGS.manufacturing%type;
JAI_CMN_INVENTORY_ORGS.trading%type;
wsh_delivery_details.shipped_quantity % TYPE;
JAI_OM_WSH_LINES_ALL.quantity % TYPE;
VARCHAR2(3);
NUMBER := 0;
JAI_OM_WSH_LINES_ALL.tax_amount % TYPE;
Number;
VARCHAR2(3);
varchar2(30);

BEGIN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_TO_R
ETURN','begin of COPY_MIXED_TO_RETURN procedure');
/* *****************************************************************************
*************************
Change History
1. 27/May/2013 nkodakan for bug 16806599
Issue : RMA ORDER GETTING CREATED WITH DOUBLED TAX AMOUNT THAN ORIGINAL ORDER
Fix : Added a SUM clause in a cursor c_get_quantity

********************************************************************************
***********************/
-- here need to code the cases where order category code is MIXED and line_c
ategory_code is RETURN
-- this is typically the case where a legacy RMA is copied another legacy RM
A
-- need to insert into JAI_OM_OE_RMA_LINES from the source.
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_TO
_RETURN','2545 pr_order_line.return_context '||pr_order_line.return_context);
IF pr_order_line.return_context IS NULL THEN
px_return_code := jai_constants.successful;
open c_rma_details(pr_order_line.source_document_id,
pr_order_line.source_document_line_id);
fetch c_rma_details
into cv_rma_details;
close c_rma_details;
open c_rma_number(pr_order_line.header_id);
fetch c_rma_number
into lv_rma_number;
close c_rma_number;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_RETURN','2561 insert into JAI_OM_OE_RMA_LINES rma_line_id '||pr_order_line.li
ne_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_RETURN','2562 insert into JAI_OM_OE_RMA_LINES rma_line_number '||pr_order_lin
e.line_number);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_RETURN','2563 insert into JAI_OM_OE_RMA_LINES rma_header_id '||pr_order_line.
header_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_RETURN','2564 insert into JAI_OM_OE_RMA_LINES rma_number '||lv_rma_number);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_RETURN','2565 insert into JAI_OM_OE_RMA_LINES quantity '||pr_order_line.order
ed_quantity);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_RETURN','2566 insert into JAI_OM_OE_RMA_LINES selling_price '||pr_order_line.
unit_selling_price);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_RETURN','2567 insert into JAI_OM_OE_RMA_LINES tax_amount '||cv_rma_details.ta
x_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_RETURN','2568 insert into JAI_OM_OE_RMA_LINES assessable_value '||cv_rma_deta
ils.assessable_value);
insert into JAI_OM_OE_RMA_LINES
(rma_line_id,
rma_line_number,
rma_header_id,
rma_number,
picking_line_id,
uom,
selling_price,

quantity,
tax_category_id,
tax_amount,
inventory_item_id,
received_flag,
assessable_value,
creation_date,
created_by,
last_update_date,
last_updated_by,
last_update_login,
excise_duty_rate,
rate_per_unit,
delivery_detail_id,
ship_to_org_id)
values
(pr_order_line.line_id,
pr_order_line.line_number,
pr_order_line.header_id,
lv_rma_number,
null,
pr_order_line.order_quantity_uom,
pr_order_line.unit_selling_price,
pr_order_line.ordered_quantity,
cv_rma_details.tax_category_id,
(cv_rma_details.tax_amount),
pr_order_line.inventory_item_id,
cv_rma_details.received_flag,
cv_rma_details.assessable_value,
sysdate,
pr_order_line.created_by,
sysdate,
pr_order_line.last_updated_by,
pr_order_line.last_update_login,
cv_rma_details.excise_duty_rate,
cv_rma_details.rate_per_unit,
null,
pr_order_line.ship_to_org_id);
FOR cv_rma_taxes in (select *
from JAI_OM_OE_RMA_TAXES
where rma_line_id =
pr_order_line.source_document_line_id) Loop
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED
_TO_RETURN','2621 insert into JAI_OM_OE_RMA_TAXES rma_line_id '||pr_order_line.l
ine_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED
_TO_RETURN','2622 insert into JAI_OM_OE_RMA_TAXES tax_line_no '||cv_rma_taxes.ta
x_line_no);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED
_TO_RETURN','2623 insert into JAI_OM_OE_RMA_TAXES tax_amount '||cv_rma_taxes.tax
_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED
_TO_RETURN','2624 insert into JAI_OM_OE_RMA_TAXES base_tax_amount '||cv_rma_taxe
s.base_tax_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED
_TO_RETURN','2625 insert into JAI_OM_OE_RMA_TAXES func_tax_amount '||cv_rma_taxe
s.func_Tax_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED
_TO_RETURN','2626 insert into JAI_OM_OE_RMA_TAXES delivery_detail_id '||cv_rma_t

axes.delivery_detail_id);
insert into JAI_OM_OE_RMA_TAXES
(rma_line_id,
tax_line_no,
precedence_1,
precedence_2,
precedence_3,
precedence_4,
precedence_5,
tax_id,
tax_rate,
qty_rate,
uom,
tax_amount,
base_tax_amount,
func_tax_amount,
creation_date,
created_by,
last_update_date,
last_updated_by,
last_update_login,
delivery_detail_id,
precedence_6,
precedence_7,
precedence_8,
precedence_9,
precedence_10)
values
(pr_order_line.line_id,
cv_rma_taxes.tax_line_no,
cv_rma_taxes.precedence_1,
cv_rma_taxes.precedence_2,
cv_rma_taxes.precedence_3,
cv_rma_taxes.precedence_4,
cv_rma_taxes.precedence_5,
cv_rma_taxes.tax_id,
cv_rma_taxes.tax_rate,
cv_rma_taxes.qty_rate,
cv_rma_taxes.uom,
(cv_rma_taxes.tax_amount),
cv_rma_taxes.base_tax_amount,
cv_rma_taxes.func_Tax_amount,
pr_order_line.creation_date,
pr_order_line.created_by,
pr_order_line.last_update_Date,
pr_order_line.last_updated_by,
pr_order_line.last_update_login,
cv_rma_taxes.delivery_detail_id,
cv_rma_taxes.precedence_6,
cv_rma_taxes.precedence_7,
cv_rma_taxes.precedence_8,
cv_rma_taxes.precedence_9,
cv_rma_taxes.precedence_10);
end Loop;
elsif pr_order_line.return_context = 'ORDER' THEN
-- here need to code the cases where order catego
--this script will execute only for the return order context.

px_return_code
:= jai_constants.successful;
v_rma_quantity_uom := pr_order_line.order_quantity_uom;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_RETURN','2689 v_rma_quantity_uom '||v_rma_quantity_uom);
OPEN c_sales_order_cur;
FETCH c_sales_order_cur
into v_orig_ord_qty, v_service_type_code;
CLOSE c_sales_order_cur;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MI
XED_TO_RETURN','2695 pr_order_line.SOURCE_DOCUMENT_ID '||pr_order_line.SOURCE_DO
CUMENT_ID);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MI
XED_TO_RETURN','2696 pr_order_line.SOURCE_DOCUMENT_LINE_ID '||pr_order_line.SOUR
CE_DOCUMENT_LINE_ID);
OPEN cur_get_picking_lines(p_source_document_id
=> pr_order_line.
SOURCE_DOCUMENT_ID,
p_source_document_line_id => pr_order_line.SOUR
CE_DOCUMENT_LINE_ID);
FETCH cur_get_picking_lines
INTO rec_cur_get_picking_lines;
IF cur_get_picking_lines%FOUND THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXE
D_TO_RETURN','2703 pr_order_line.line_id '||pr_order_line.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXE
D_TO_RETURN','2704 pr_order_line.header_id '||pr_order_line.header_id);
OPEN cur_rma_entry_line_exists(p_line_id => pr_order_line.line_id,
p_header_id => pr_order_line.header_id);
FETCH cur_rma_entry_line_exists
INTO l_exists;
/*
IF a record does not exists with the newline_id and header_id
only then go ahead with the insert
*/
IF cur_rma_entry_line_exists%NOTFOUND THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIX
ED_TO_RETURN','2705 INSERT INTO JAI_OM_OE_RMA_LINES rma_line_number '||pr_order_
line.line_number);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIX
ED_TO_RETURN','2706 INSERT INTO JAI_OM_OE_RMA_LINES rma_line_id '||pr_order_line
.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIX
ED_TO_RETURN','2707 INSERT INTO JAI_OM_OE_RMA_LINES rma_header_id '||pr_order_li
ne.header_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIX
ED_TO_RETURN','2708 INSERT INTO JAI_OM_OE_RMA_LINES rma_number '||p_order_number
);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIX
ED_TO_RETURN','2709 INSERT INTO JAI_OM_OE_RMA_LINES quantity '||v_rma_quantity_u
om);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIX
ED_TO_RETURN','2710 INSERT INTO JAI_OM_OE_RMA_LINES tax_amount '||rec_cur_get_pi
cking_lines.tax_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIX
ED_TO_RETURN','2711 INSERT INTO JAI_OM_OE_RMA_LINES delivery_detail_id '||rec_cu
r_get_picking_lines.delivery_detail_id);

INSERT INTO JAI_OM_OE_RMA_LINES


(rma_line_number,
rma_line_id,
rma_header_id,
rma_number,
inventory_item_id,
uom,
quantity,
tax_category_id,
selling_price,
tax_amount,
delivery_detail_id,
creation_date,
created_by,
last_update_date,
last_updated_by,
last_update_login,
service_type_code,
ship_to_org_id)
VALUES
(pr_order_line.line_number,
pr_order_line.line_id,
pr_order_line.header_id,
p_order_number,
rec_cur_get_picking_lines.inventory_item_id,
v_rma_quantity_uom,
pr_order_line.ordered_quantity,
rec_cur_get_picking_lines.tax_category_id,
pr_order_line.unit_selling_price,
rec_cur_get_picking_lines.tax_amount,
rec_cur_get_picking_lines.delivery_detail_id,
pr_order_line.creation_date,
pr_order_line.created_by,
pr_order_line.last_update_date,
pr_order_line.last_updated_by,
pr_order_line.last_update_login,
v_service_type_code,
pr_order_line.ship_to_org_id);
END IF;
CLOSE cur_rma_entry_line_exists;
open cur_get_ddetail_id(p_source_document_id

=> pr_order_line.heade

r_id,
p_source_document_line_id => pr_order_line.line_
id);
fetch cur_get_ddetail_id
into v_ddetail_id;
close cur_get_ddetail_id;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXE
D_TO_RETURN','2769 v_ddetail_id '||v_ddetail_id);
OPEN c_get_detail_id(v_ddetail_id);
FETCH c_get_detail_id
INTO v_delivery_detail_id, v_date_confirmed;
CLOSE c_get_detail_id;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXE
D_TO_RETURN','2774 v_delivery_detail_id '||v_delivery_detail_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXE
D_TO_RETURN','2775 v_date_confirmed '||v_date_confirmed);
/* moved code from below IF condition to here to check VAT return days b

oth for
shippable and non-shippalbe lines. */
OPEN c_get_days_flags;
FETCH c_get_days_flags
INTO v_excise_return_days,
v_sales_return_days,
v_vat_return_days,
v_manufacturing,
v_trading;
CLOSE c_get_days_flags;
OPEN c_ordered_date;
FETCH c_ordered_date
INTO v_date_ordered;
CLOSE c_ordered_date;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXE
D_TO_RETURN','2793 v_excise_return_days '||v_excise_return_days);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXE
D_TO_RETURN','2794 v_date_ordered '||v_date_ordered);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXE
D_TO_RETURN','2795 v_date_confirmed '||v_date_confirmed);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXE
D_TO_RETURN','2796 v_vat_return_days '||v_vat_return_days);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXE
D_TO_RETURN','2797 v_sales_return_days '||v_sales_return_days);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXE
D_TO_RETURN','2798 v_manufacturing '||v_manufacturing);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXE
D_TO_RETURN','2799 v_trading '||v_trading);
IF v_delivery_detail_id IS NOT NULL THEN
IF (v_excise_return_days IS NULL OR
(v_date_ordered - v_date_confirmed) <=
v_excise_return_days) THEN
v_excise_flag := 'Y';
ELSE
v_excise_flag := 'N';
END IF;
IF (v_sales_return_days IS NULL OR
(v_date_ordered - v_date_confirmed) <=
v_sales_return_days) THEN
v_sales_flag := 'Y';
ELSE
v_sales_flag := 'N';
END IF;
IF (v_vat_return_days IS NULL OR
(v_date_ordered - v_date_confirmed) <=
v_vat_return_days) THEN
v_vat_flag := 'Y';
ELSE
v_vat_flag := 'N';
END IF;
/*Fetch Shipped Quantity based on Source Order Details instead of Deli
very Details

as a single Order Line can have multiple Delivery Details resulting in


incorrect Shipped Quantity*/
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MI
XED_TO_RETURN','2831 pr_order_line.SOURCE_DOCUMENT_ID '||pr_order_line.SOURCE_DO
CUMENT_ID);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MI
XED_TO_RETURN','2832 pr_order_line.SOURCE_DOCUMENT_LINE_ID '||pr_order_line.SOUR
CE_DOCUMENT_LINE_ID);
OPEN c_get_ship_qty(pr_order_line.SOURCE_DOCUMENT_ID,
pr_order_line.SOURCE_DOCUMENT_LINE_ID);
FETCH c_get_ship_qty
INTO v_shipped_quantity;
CLOSE c_get_ship_qty;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MI
XED_TO_RETURN','2839 v_shipped_quantity '||v_shipped_quantity);
OPEN c_get_quantity(p_source_document_id
=> pr_order_line.SOURCE_
DOCUMENT_ID,
p_source_document_line_id => pr_order_line.SOURCE_
DOCUMENT_LINE_ID);
FETCH c_get_quantity
INTO v_quantity;
CLOSE c_get_quantity;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MI
XED_TO_RETURN','2845 v_quantity '||v_quantity);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MI
XED_TO_RETURN','2846 v_delivery_detail_id '||v_delivery_detail_id);
IF v_quantity <> 0 THEN
OPEN requested_qty_uom_cur(v_delivery_detail_id);
FETCH requested_qty_uom_cur
INTO v_requested_quantity_uom;
CLOSE requested_qty_uom_cur;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
MIXED_TO_RETURN','2853 v_requested_quantity_uom '||v_requested_quantity_uom);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
MIXED_TO_RETURN','2855 v_requested_quantity_uom '||v_requested_quantity_uom);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
MIXED_TO_RETURN','2856 v_rma_quantity_uom '||v_rma_quantity_uom);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
MIXED_TO_RETURN','2857 pr_order_line.inventory_item_id '||pr_order_line.inventor
y_item_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
MIXED_TO_RETURN','2858 v_conversion_rate '||v_conversion_rate);
INV_CONVERT.inv_um_conversion(v_requested_quantity_uom,
v_rma_quantity_uom,
pr_order_line.inventory_item_id,
v_conversion_rate);
IF NVL(v_conversion_rate, 0) <= 0 THEN
INV_CONVERT.inv_um_conversion(v_requested_quantity_uom,
v_rma_quantity_uom,
0,
v_conversion_rate);
IF NVL(v_conversion_rate, 0) <= 0 THEN
v_conversion_rate := 1; --Changed v_conversion_rate from 0 to 1,
so that divide by zero error does not occur.

END IF;
END IF;
v_cor_amount := (pr_order_line.ordered_quantity / v_quantity) *
(1 / v_conversion_rate);
END IF;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MI
XED_TO_RETURN','2878 v_shipped_quantity '||v_shipped_quantity);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MI
XED_TO_RETURN','2879 pr_order_line.ordered_quantity '||pr_order_line.ordered_qua
ntity);
IF round(v_shipped_quantity, 2) <
round(pr_order_line.ordered_quantity * (1 / v_conversion_rate),
2) THEN
RAISE_APPLICATION_ERROR(-20401,
'RMA quantity can NOT be more than shipped q
uantity');
END IF;
FOR rec_cur_get_picking_tax_lines IN cur_get_picking_tax_lines(p_sourc
e_document_id
=> pr_order_line.SOURCE_DOCUMENT_ID,
p_sourc
e_document_line_id => pr_order_line.SOURCE_DOCUMENT_LINE_ID) LOOP
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
MIXED_TO_RETURN','2892 pr_order_line.line_id '||pr_order_line.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
MIXED_TO_RETURN','2893 rec_cur_get_picking_tax_lines.tax_id '||rec_cur_get_picki
ng_tax_lines.tax_id);
OPEN cur_chk_rma_tax_lines_exists(p_line_id => pr_order_line.line_id
,
p_tax_id => rec_cur_get_picking_t
ax_lines.tax_id);
FETCH cur_chk_rma_tax_lines_exists
INTO l_exists;
IF cur_chk_rma_tax_lines_exists%NOTFOUND THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COP
Y_MIXED_TO_RETURN','2900 rec_cur_get_picking_tax_lines.tax_type '||rec_cur_get_p
icking_tax_lines.tax_type);
IF rec_cur_get_picking_tax_lines.tax_type IN
('Excise',
'Addl. Excise',
'Other Excise',
'TDS',
'CVD') THEN
v_round_tax := ROUND((v_cor_amount *
rec_cur_get_picking_tax_lines.tax_amount),
rec_cur_get_picking_tax_lines.rounding_fac
tor);
v_round_base := ROUND((v_cor_amount *
rec_cur_get_picking_tax_lines.base_tax_amo
unt),
rec_cur_get_picking_tax_lines.rounding_fac
tor);
v_round_func := ROUND((v_cor_amount *
rec_cur_get_picking_tax_lines.func_tax_amo

unt),
rec_cur_get_picking_tax_lines.rounding_fac
tor);
ELSE
v_round_tax := ROUND((v_cor_amount *
rec_cur_get_picking_tax_lines.tax_amount),
2);
v_round_base := ROUND((v_cor_amount *
rec_cur_get_picking_tax_lines.base_tax_amo
unt),
2);
v_round_func := ROUND((v_cor_amount *
rec_cur_get_picking_tax_lines.func_tax_amo
unt),
2);
END IF;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COP
Y_MIXED_TO_RETURN','2928 v_round_tax '||v_round_tax);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COP
Y_MIXED_TO_RETURN','2929 v_round_base '||v_round_base);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COP
Y_MIXED_TO_RETURN','2930 v_round_func '||v_round_func);
lv_check_vat_type_exists := NULL;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COP
Y_MIXED_TO_RETURN','2934 rec_cur_get_picking_tax_lines.tax_type '||rec_cur_get_p
icking_tax_lines.tax_type);
OPEN c_check_Vat_type_Tax_exists(rec_cur_get_picking_tax_lines.tax
_type);
FETCH c_check_Vat_type_Tax_exists
INTO lv_check_vat_type_exists;
CLOSE c_check_Vat_type_Tax_exists;
IF (rec_cur_get_picking_tax_lines.tax_type IN
('Excise',
'Addl. Excise',
'Other Excise',
JAI_CONSTANTS.TAX_TYPE_SH_EXC_EDU_CESS,
JAI_CONSTANTS.TAX_TYPE_EXC_EDU_CESS) AND
v_excise_flag = 'N') OR
(rec_cur_get_picking_tax_lines.tax_type IN
('Sales Tax', 'CST') AND v_sales_flag = 'N') OR
(lv_check_vat_type_exists = 1 AND v_vat_flag = 'N') THEN
v_round_tax := 0;
v_round_base := 0;
v_round_func := 0;
END IF;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY
_MIXED_TO_RETURN','2956 INSERT INTO JAI_OM_OE_RMA_TAXES rma_line_id'||pr_order_l
ine.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY
_MIXED_TO_RETURN','2957 INSERT INTO JAI_OM_OE_RMA_TAXES tax_line_no'||rec_cur_ge
t_picking_tax_lines.tax_line_no);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY
_MIXED_TO_RETURN','2958 INSERT INTO JAI_OM_OE_RMA_TAXES tax_id'||rec_cur_get_pic
king_tax_lines.tax_id);

jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY
_MIXED_TO_RETURN','2959 INSERT INTO JAI_OM_OE_RMA_TAXES tax_amount'||v_round_tax
);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY
_MIXED_TO_RETURN','2960 INSERT INTO JAI_OM_OE_RMA_TAXES base_tax_amount'||v_roun
d_base);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY
_MIXED_TO_RETURN','2961 INSERT INTO JAI_OM_OE_RMA_TAXES func_tax_amount'||v_roun
d_func);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY
_MIXED_TO_RETURN','2962 INSERT INTO JAI_OM_OE_RMA_TAXES delivery_detail_id'||rec
_cur_get_picking_tax_lines.delivery_detail_id);
INSERT INTO JAI_OM_OE_RMA_TAXES
(rma_line_id,
tax_line_no,
tax_id,
tax_rate,
qty_rate,
uom,
tax_amount,
base_tax_amount,
func_tax_amount,
precedence_1,
precedence_2,
precedence_3,
precedence_4,
precedence_5,
precedence_6,
precedence_7,
precedence_8,
precedence_9,
precedence_10,
delivery_detail_id,
creation_date,
created_by,
last_update_date,
last_updated_by,
last_update_login)
VALUES
(pr_order_line.line_id,
rec_cur_get_picking_tax_lines.tax_line_no,
rec_cur_get_picking_tax_lines.tax_id,
rec_cur_get_picking_tax_lines.tax_rate,
rec_cur_get_picking_tax_lines.qty_rate,
rec_cur_get_picking_tax_lines.uom,
v_round_tax,
v_round_base,
v_round_func,
rec_cur_get_picking_tax_lines.precedence_1,
rec_cur_get_picking_tax_lines.precedence_2,
rec_cur_get_picking_tax_lines.precedence_3,
rec_cur_get_picking_tax_lines.precedence_4,
rec_cur_get_picking_tax_lines.precedence_5,
rec_cur_get_picking_tax_lines.precedence_6,
rec_cur_get_picking_tax_lines.precedence_7,
rec_cur_get_picking_tax_lines.precedence_8,
rec_cur_get_picking_tax_lines.precedence_9,
rec_cur_get_picking_tax_lines.precedence_10,

rec_cur_get_picking_tax_lines.delivery_detail_id,
pr_order_line.creation_date,
pr_order_line.created_by,
pr_order_line.last_update_date,
pr_order_line.last_updated_by,
pr_order_line.last_update_login);
IF rec_cur_get_picking_tax_lines.tax_type <> 'TDS' THEN
v_tax_total := NVL(v_tax_total, 0) + v_round_tax;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.C
OPY_MIXED_TO_RETURN','3020 v_round_tax '||v_round_tax);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.C
OPY_MIXED_TO_RETURN','3021 v_tax_total '||v_tax_total);
END IF;
END IF; --IF cur_chk_rma_tax_lines_exists%NOTFOUND
CLOSE cur_chk_rma_tax_lines_exists;
END LOOP;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MI
XED_TO_RETURN','3028 UPDATE JAI_OM_OE_RMA_LINES v_tax_total '||v_tax_total);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MI
XED_TO_RETURN','3029 UPDATE JAI_OM_OE_RMA_LINES pr_order_line.line_idpr_order_li
ne.line_id '||pr_order_line.line_id);
UPDATE JAI_OM_OE_RMA_LINES
SET tax_amount = v_tax_total
WHERE rma_line_id = pr_order_line.line_id;
-- need to process copying taxes from referenced SO line for non-shipp
able RMA line whose delivery_detail_id is NULL
ELSIF NVL(pr_order_line.SHIPPABLE_FLAG, 'Y') = 'N' THEN
-- should check VAT return date, if the validation fails, then vat amo
unts should be copied as zero.
OPEN c_fulfilled_date;
FETCH c_fulfilled_date
INTO v_date_confirmed;
CLOSE c_fulfilled_date;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MI
XED_TO_RETURN','3042 v_vat_return_days '||v_vat_return_days);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MI
XED_TO_RETURN','3043 v_date_ordered '||v_date_ordered);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MI
XED_TO_RETURN','3044 v_date_confirmed '||v_date_confirmed);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MI
XED_TO_RETURN','3045 v_vat_return_days '||v_vat_return_days);
IF (v_vat_return_days IS NULL OR
(v_date_ordered - v_date_confirmed) <=
v_vat_return_days) THEN
v_vat_flag := 'Y';
ELSE
v_vat_flag := 'N';
END IF; -- v_vat_return_days IS NULL OR .....
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIX
ED_TO_RETURN','3054 pr_order_line.ORDERED_QUANTITY '||pr_order_line.ORDERED_QUAN
TITY);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIX
ED_TO_RETURN','3055 pr_order_line.reference_line_id '||pr_order_line.reference_l
ine_id);

IF pr_order_line.ORDERED_QUANTITY <> 0 THEN


FOR tax_line_rec IN (SELECT tax_line_no,
precedence_1,
precedence_2,
precedence_3,
precedence_4,
precedence_5,
sptl.tax_id,
sptl.tax_rate,
sptl.qty_rate,
uom,
sptl.tax_amount,
nvl(jtc.rounding_factor, 0) rounding_fac
tor,
base_tax_amount,
func_tax_amount,
jtc.tax_type,
precedence_6,
precedence_7,
precedence_8,
precedence_9,
precedence_10
FROM JAI_OM_WSH_LINE_TAXES sptl,
JAI_CMN_TAXES_ALL
jtc
WHERE order_line_id =
pr_order_line.reference_line_id
AND jtc.tax_id = sptl.tax_id) LOOP
lv_check_vat_type_exists := NULL;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COP
Y_MIXED_TO_RETURN','3085 tax_line_rec.tax_type '||tax_line_rec.tax_type);
OPEN c_check_Vat_type_Tax_exists(tax_line_rec.tax_type);
FETCH c_check_Vat_type_Tax_exists
INTO lv_check_vat_type_exists;
CLOSE c_check_Vat_type_Tax_exists;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CO
PY_MIXED_TO_RETURN','3090 lv_check_vat_type_exists '||lv_check_vat_type_exists);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CO
PY_MIXED_TO_RETURN','3091 tax_line_rec.tax_amount '||tax_line_rec.tax_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CO
PY_MIXED_TO_RETURN','3092 tax_line_rec.base_tax_amount '||tax_line_rec.base_tax_
amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CO
PY_MIXED_TO_RETURN','3093 tax_line_rec.func_tax_amount '||tax_line_rec.func_tax_
amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CO
PY_MIXED_TO_RETURN','3094 v_vat_flag '||v_vat_flag);
IF (lv_check_vat_type_exists = 1 AND v_vat_flag = 'N') THEN
v_round_tax := 0;
v_round_base := 0;
v_round_func := 0;
ELSE
v_round_tax := tax_line_rec.tax_amount;
v_round_base := tax_line_rec.base_tax_amount;
v_round_func := tax_line_rec.func_tax_amount;
END IF; -- lv_check_vat_type_exists = 1 AND v_vat_flag = 'N'
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COP

Y_MIXED_TO_RETURN','3106 INSERT INTO JAI_OM_OE_RMA_TAXES rma_line_id '||pr_order


_line.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COP
Y_MIXED_TO_RETURN','3107 INSERT INTO JAI_OM_OE_RMA_TAXES tax_line_no '||tax_line
_rec.tax_line_no);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COP
Y_MIXED_TO_RETURN','3108 INSERT INTO JAI_OM_OE_RMA_TAXES tax_id '||tax_line_rec.
tax_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COP
Y_MIXED_TO_RETURN','3109 INSERT INTO JAI_OM_OE_RMA_TAXES tax_amount '||v_round_t
ax);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COP
Y_MIXED_TO_RETURN','3110 INSERT INTO JAI_OM_OE_RMA_TAXES base_tax_amount '||v_ro
und_base);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COP
Y_MIXED_TO_RETURN','3111 INSERT INTO JAI_OM_OE_RMA_TAXES func_tax_amount '||v_ro
und_func);
INSERT INTO JAI_OM_OE_RMA_TAXES
(rma_line_id,
delivery_detail_id,
tax_line_no,
precedence_1,
precedence_2,
precedence_3,
precedence_4,
precedence_5,
tax_id,
tax_rate,
qty_rate,
uom,
tax_amount,
base_tax_amount,
func_tax_amount,
creation_date,
created_by,
last_update_date,
last_updated_by,
last_update_login,
precedence_6,
precedence_7,
precedence_8,
precedence_9,
precedence_10)
VALUES
(pr_order_line.line_id,
NULL,
tax_line_rec.tax_line_no,
tax_line_rec.precedence_1,
tax_line_rec.precedence_2,
tax_line_rec.precedence_3,
tax_line_rec.precedence_4,
tax_line_rec.precedence_5,
tax_line_rec.tax_id,
tax_line_rec.tax_rate,
tax_line_rec.qty_rate,
tax_line_rec.uom,
v_round_tax,
v_round_base,
v_round_func,

pr_order_line.creation_date,
pr_order_line.created_by,
pr_order_line.last_update_date,
pr_order_line.last_updated_by,
pr_order_line.last_update_login,
tax_line_rec.precedence_6,
tax_line_rec.precedence_7,
tax_line_rec.precedence_8,
tax_line_rec.precedence_9,
tax_line_rec.precedence_10);
END LOOP; -- tax_line_rec IN (SELECT tax_line_no ......
END IF; --IF pr_order_line.ORDERED_QUANTITY <> 0
END IF; --IF v_delivery_detail_id IS NOT NULL
ELSE
-- Details in picking lines not found . Raise an error message
CLOSE cur_get_picking_lines;
px_return_code
:= jai_constants.expected_error;
px_return_message := 'No data found in localisation shipping tables,henc
e copy cannot be done';
return;
END IF;
CLOSE cur_get_picking_lines;
end if; --endif return_context<>'LEGACY'
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_TO
_RETURN','3181 after end if return_context<>LEGACY ');
EXCEPTION
WHEN OTHERS THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_RETURN','3184 exception occured in COPY_MIXED_TO_RETURN');
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_RETURN','3185 sqlcode '||sqlcode);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_RETURN','3186 sqlerrm '||sqlerrm);
RAISE;
END COPY_MIXED_TO_RETURN;
-- additions for the bug 16767223 starts
/*
REM +======================================================================+
REM NAME
COPY_MIXED_TO_ORDER
REM
REM DESCRIPTION COPY STANDARD SALES ORDER TAXES and LINES FROM ORIGINAL MIXE
D ORDER
REM
REM NOTES
Call from procdure COPY_SOURCE_ORDER
REM
REM +======================================================================+
*/
PROCEDURE COPY_MIXED_TO_ORDER(pr_order_line
t_rec%type,
p_order_number
NUMBER,
px_return_code
out nocopy varchar2,
px_return_message out nocopy varchar2) IS
/* fetch the details of the original SO order c_so_details */
CURSOR c_so_details(cp_header_id number,
cp_line_id number) is

SELECT
FROM
WHERE
AND

*
JAI_OM_OE_SO_LINES
header_id = cp_header_id
line_id = cp_line_id;

/* fetch the tax details from original SO order */


CURSOR c_so_tax_details(cp_header_id number,
cp_line_id number) is
SELECT *
FROM JAI_OM_OE_SO_TAXES
WHERE header_id = cp_header_id
AND line_id = cp_line_id;
cv_so_details c_so_details%rowtype;
c_source_line_id number; /*Added by mmurtuza for bug 17078336*/
v_tax_line_count number; /*Added by mmurtuza for bug 17078336*/
BEGIN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_TO_O
RDER','3299 begin of COPY_MIXED_TO_ORDER procedure');
/* ***************************************************************************
***************************
Change History
1. 17/July/2013 mmurtuza for bug 17078336
Issue : CHANGE OF CUSTOMER AT ORDER HEADER IS NOT REFLECTING AT THE LINES FOR AT
O ORDERS
Fix : Checked for existance of line in JAI_OM_OE_SO_LINES
2. 19/Sep/2013 mmurtuza for bug 17275984
Issue: WHILE COPYING SALES ORDER, TAX AMOUNT NOT GETTING UPDATED FOR ATO STAR IT
EM IN
Fix: Added shipment_schedule_line_id in insert statement
********************************************************************************
***********************/
px_return_code := jai_constants.successful;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_ORDER','3247 pr_order_line.source_document_id '||pr_order_line.source_documen
t_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_ORDER','3248 pr_order_line.source_document_line_id '||pr_order_line.source_do
cument_line_id);
open c_so_details(pr_order_line.source_document_id,
pr_order_line.source_document_line_id);
fetch c_so_details
into cv_so_details;
close c_so_details;
/*Start additions by mmurtuza for bug 17078336*/
SELECT COUNT(*)
INTO c_source_line_id
FROM JAI_OM_OE_SO_LINES
WHERE LINE_ID = pr_order_line.line_id;

jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXE
D_TO_ORDER','3261 c_source_line_id '||c_source_line_id);
IF c_source_line_id = 0 THEN
/*End additions by mmurtuza for bug 17078336*/
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_ORDER','insert into JAI_OM_OE_SO_LINES line_id '||pr_order_line.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_ORDER','insert into JAI_OM_OE_SO_LINES line_number '||pr_order_line.line_numb
er);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_ORDER','insert into JAI_OM_OE_SO_LINES header_id '||pr_order_line.header_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_ORDER','insert into JAI_OM_OE_SO_LINES tax_amount '||cv_so_details.tax_amount
);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_ORDER','insert into JAI_OM_OE_SO_LINES line_amount '||cv_so_details.line_amou
nt);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_ORDER','insert into JAI_OM_OE_SO_LINES line_tot_amount '||cv_so_details.line_
tot_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_ORDER','insert into JAI_OM_OE_SO_LINES ship_to_org_id '||pr_order_line.ship_t
o_org_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXED_
TO_ORDER','insert into JAI_OM_OE_SO_LINES ship_to_org_id '||pr_order_line.ato_li
ne_id);
insert into JAI_OM_OE_SO_LINES
(line_id,
line_number,
header_id,
tax_amount,
line_amount,
line_tot_amount,
shipment_line_number,
ato_flag,
selling_price,
quantity,
tax_category_id,
unit_code,
inventory_item_id,
assessable_value,
creation_date,
created_by,
last_update_date,
last_updated_by,
last_update_login,
ship_to_org_id,
shipment_schedule_line_id) /*Added shipment_schedule_line_id by
mmurtuza for bug 17275984*/
values
(pr_order_line.line_id,
pr_order_line.line_number,
pr_order_line.header_id,
cv_so_details.tax_amount,
cv_so_details.line_amount,
cv_so_details.line_tot_amount,

cv_so_details.shipment_line_number,
cv_so_details.ato_flag,
pr_order_line.unit_selling_price,
pr_order_line.ordered_quantity,
cv_so_details.tax_category_id,
cv_so_details.unit_code,
pr_order_line.inventory_item_id,
cv_so_details.assessable_value,
sysdate,
pr_order_line.created_by,
sysdate,
pr_order_line.last_updated_by,
pr_order_line.last_update_login,
pr_order_line.ship_to_org_id,
pr_order_line.ato_line_id); /*Added pr_order_line.ato_line_id
by mmurtuza for bug 17275984*/
/*Start additions by mmurtuza for bug 17078336*/
else
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MI
XED_TO_ORDER','3322 update JAI_OM_OE_SO_LINES ship_to_org_id '||pr_order_line.sh
ip_to_org_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MI
XED_TO_ORDER','3323 update line_number '||pr_order_line.line_number);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MI
XED_TO_ORDER','3324 update JAI_OM_OE_SO_LINES header_id '||pr_order_line.header_
id);
update JAI_OM_OE_SO_LINES
set ship_to_org_id = pr_order_line.ship_to_org_id,
line_number = pr_order_line.line_number,
last_update_date = sysdate,
last_updated_by = pr_order_line.last_updated_by,
last_update_login = pr_order_line.last_update_login
where LINE_ID = pr_order_line.line_id
and header_id = pr_order_line.header_id;
/*End additions by mmurtuza for bug 17078336*/
END IF;
for cv_so_tax_details in c_so_tax_details(pr_order_line.source_document_id,pr_
order_line.source_document_line_id)
loop
/*Start additions by mmurtuza for bug 17078336*/
SELECT COUNT(1)
INTO v_tax_line_count
FROM JAI_OM_OE_SO_TAXES
WHERE line_id = pr_order_line.line_id
AND tax_id = cv_so_tax_details.tax_id;
IF v_tax_line_count = 0 THEN
/*End additions by mmurtuza for bug 17078336*/
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.C
OPY_MIXED_TO_ORDER','3350 insert into JAI_OM_OE_SO_TAXES line_id'||pr_order_line
.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.C
OPY_MIXED_TO_ORDER','3351 insert into JAI_OM_OE_SO_TAXES header_id'||pr_order_li
ne.header_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.C

OPY_MIXED_TO_ORDER','3352 insert into JAI_OM_OE_SO_TAXES tax_amount'||cv_so_tax_


details.tax_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.C
OPY_MIXED_TO_ORDER','3353 insert into JAI_OM_OE_SO_TAXES base_tax_amount'||cv_so
_tax_details.base_tax_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.C
OPY_MIXED_TO_ORDER','3354 insert into JAI_OM_OE_SO_TAXES func_tax_amount'||cv_so
_tax_details.func_Tax_amount);
insert into JAI_OM_OE_SO_TAXES
(line_id,
header_id,
tax_line_no,
precedence_1,
precedence_2,
precedence_3,
precedence_4,
precedence_5,
tax_id,
tax_rate,
qty_rate,
uom,
tax_amount,
base_tax_amount,
func_tax_amount,
creation_date,
created_by,
last_update_date,
last_updated_by,
last_update_login,
TAX_CATEGORY_ID,
-- delivery_detail_id,
precedence_6,
precedence_7,
precedence_8,
precedence_9,
precedence_10)
values
(pr_order_line.line_id,
pr_order_line.header_id,
cv_so_tax_details.tax_line_no,
cv_so_tax_details.precedence_1,
cv_so_tax_details.precedence_2,
cv_so_tax_details.precedence_3,
cv_so_tax_details.precedence_4,
cv_so_tax_details.precedence_5,
cv_so_tax_details.tax_id,
cv_so_tax_details.tax_rate,
cv_so_tax_details.qty_rate,
cv_so_tax_details.uom,
(cv_so_tax_details.tax_amount),
cv_so_tax_details.base_tax_amount,
cv_so_tax_details.func_Tax_amount,
cv_so_tax_details.creation_date,
cv_so_tax_details.created_by,
cv_so_tax_details.last_update_Date,
cv_so_tax_details.last_updated_by,
cv_so_tax_details.last_update_login,
cv_so_tax_details.tax_category_id,
cv_so_tax_details.precedence_6,

cv_so_tax_details.precedence_7,
cv_so_tax_details.precedence_8,
cv_so_tax_details.precedence_9,
cv_so_tax_details.precedence_10);
end if; /*Added by mmurtuza for bug 17078336*/
end loop;
EXCEPTION
WHEN OTHERS THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXE
D_TO_ORDER','3218 Exception occured in COPY_MIXED_TO_ORDER procedure sqlcode '||
sqlcode);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_MIXE
D_TO_ORDER','3419 sqlerrrm '||sqlerrm);
RAISE;
END COPY_MIXED_TO_ORDER;
-- additions for the bug 16767223 ends
/*
REM +======================================================================+
REM NAME
COPY_SOURCE_ORDER
REM
REM DESCRIPTION COPY ORDER LINES FROM THE SOURCE ORDER
REM
REM NOTES
Call from procedure POPULATE_TAX
REM
REM +======================================================================+
*/
PROCEDURE COPY_SOURCE_ORDER (p_header_info
get_header_info%r
owtype,
pr_new_line
t_rec%type,
p_return_code
out nocopy varcha
r2,
p_return_message
out nocopy varcha
r2) IS
v_api_name CONSTANT VARCHAR2(30) := 'COPY_SOURCE_ORDER';
CURSOR source_order_doc_cur(P_Source_Document_Id NUMBER) IS
SELECT order_category_code
FROM oe_order_headers_all
WHERE header_id = p_source_document_id;
copy_rec
get_copy_order_line%ROWTYPE;
v_source_order_category_code VARCHAR2(30);
v_line_category_code
VARCHAR2(30);
BEGIN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOURCE_O
RDER','3454 begin of COPY_SOURCE_ORDER procedure');
v_line_category_code
:= pr_new_line.Line_Category_Code;
-- Copy Order
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOURCE_O
RDER','3457 pr_new_line.SOURCE_DOCUMENT_ID '||pr_new_line.SOURCE_DOCUMENT_ID);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOURCE_O

RDER','3458 pr_new_line.SOURCE_DOCUMENT_LINE_ID '||pr_new_line.SOURCE_DOCUMENT_L


INE_ID);
OPEN Get_Copy_Order_Line(pr_new_line.SOURCE_DOCUMENT_ID,
pr_new_line.SOURCE_DOCUMENT_LINE_ID);
FETCH Get_Copy_Order_Line
INTO copy_rec;
IF Get_Copy_Order_Line%NOTFOUND THEN
-- source order line does not exist in JAI_OM_OE_SO_LINES , should not pro
cess
-- this could be because of quantity being 0 / cancelled line.
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOURCE
_ORDER','3467 v_line_category_code '||v_line_category_code);
IF v_line_category_code = 'ORDER' THEN
CLOSE get_copy_order_line;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOUR
CE_ORDER','3470 before retrun ');
RETURN;
END IF;
END IF;
CLOSE get_copy_order_line;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOURCE_O
RDER','3476 pr_new_line.SOURCE_DOCUMENT_ID '||pr_new_line.SOURCE_DOCUMENT_ID);
OPEN source_order_doc_cur(pr_new_line.SOURCE_DOCUMENT_ID);
FETCH source_order_doc_cur
INTO v_source_order_category_code;
CLOSE source_order_doc_cur;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOURCE_O
RDER','3481 v_source_order_category_code '||v_source_order_category_code);
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' Order header category code ~ Line category code :' ||
v_source_order_category_code || ' ~ ' ||
v_line_category_code);
END IF;
/*
Made the check more explicit as functionality in case of order to order an
d return to order is different.
*/
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOURCE_O
RDER','3495 v_source_order_category_code '||v_source_order_category_code);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOURCE_O
RDER','3496 v_line_category_code '||v_line_category_code);
IF v_source_order_category_code = 'ORDER' AND
v_line_category_code = 'ORDER' THEN
-- copy order lines from original order
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOURCE
_ORDER','3501 before Call to copy_order_to_order procedure ');
copy_order_to_order(pr_copy
=> copy_rec,
pr_order_line
=> pr_new_line,
pr_header_info
=> p_header_info);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOURCE_O
RDER','3506 after the call to copy_order_to_order procedure ');

ELSIF v_source_order_category_code = 'RETURN' AND


v_line_category_code = 'ORDER' THEN
-- copy order lines from return order
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOURCE
_ORDER','3511 before call to copy_return_to_order procedure ');
copy_return_to_order(pr_order_line
=> pr_new_line,
pr_header_info
=> p_header_info);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOURCE
_ORDER','3514 after the call to copy_return_to_order procedure ');
ELSIF v_source_order_category_code = 'ORDER' AND
v_line_category_code = 'RETURN' THEN
-- copy return taxes and lines from original order
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOURCE
_ORDER','3520 before call to copy_order_to_return procedure ');
copy_order_to_return(pr_order_line => pr_new_line,
p_order_number => p_header_info.order_number,
px_return_code => p_return_code,
px_return_message => p_return_message);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOURCE
_ORDER','3525 After the call to copy_order_to_return procedure ');
if (p_return_code <> jai_constants.successful) then
return;
end if;
ELSIF rtrim(ltrim(v_source_order_category_code)) = 'MIXED' AND
ltrim(rtrim(v_line_category_code)) = 'RETURN' THEN
-- copy return taxes and lines from original mixed order
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOURCE
_ORDER','3534 Before call to copy_mixed_to_return procedure ');
copy_mixed_to_return(pr_order_line => pr_new_line,
p_order_number => p_header_info.order_number,
px_return_code => p_return_code,
px_return_message => p_return_message);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOURCE
_ORDER','3539 End of call to copy_mixed_to_return procedure ');
-- additions for the bug 16767223 starts
ELSIF rtrim(ltrim(v_source_order_category_code)) = 'MIXED' AND
ltrim(rtrim(v_line_category_code)) = 'ORDER' THEN
-- copy standard sales order taxes and lines from original mixed order
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOURC
E_ORDER','3545 Before call to copy_mixed_to_order procedure ');
copy_mixed_to_order(pr_order_line => pr_new_line,
p_order_number => p_header_info.order_number,
px_return_code => p_return_code,
px_return_message => p_return_message);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOURC
E_ORDER','3550 After the call to copy_mixed_to_order procedure ');
-- additions for the bug 16767223 ends
if (p_return_code <> jai_constants.successful) then
return;
end if;

ELSIF v_source_order_category_code = 'RETURN' AND


v_line_category_code = 'RETURN' THEN
-- Raise an Error
p_return_code
:= jai_constants.expected_error;
p_return_message := 'Copying of Return Order to Return Order is not curren
tly supported with India Localization Taxes';
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOURCE
_ORDER','3562 Before return ');
return;
END IF;
EXCEPTION
WHEN OTHERS THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOURCE
_ORDER','3567 Exception occured in COPY_SOURCE_ORDER procedure sqlcode '||sqlcod
e);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SOURCE
_ORDER','3568 sqlerrm '||sqlerrm);
RAISE;
END COPY_SOURCE_ORDER;
/*
REM +======================================================================+
REM NAME
CREATE_NORMAL_ORDER
REM
REM DESCRIPTION CREATE NORMAL ORDER LINES
REM
REM NOTES
Call from procdure POPULATE_TAX
REM
REM +======================================================================+
*/
PROCEDURE CREATE_NORMAL_ORDER (pr_order_line
t_rec%type,
pr_old_line
t_rec%type,
pr_header_info
get_header_info%ro
wtype,
p_return_code
out nocopy varchar
2 ,
p_return_message
out nocopy varchar
2 ) IS
v_api_name CONSTANT VARCHAR2(30) := 'CREATE_NORMAL_ORDER';
CURSOR
SELECT
FROM
WHERE

get_source_id IS
order_source_id
oe_order_headers_all
header_id = pr_order_line.header_id;

CURSOR
SELECT
FROM
WHERE

get_rma_tax_lines_count_cur IS
COUNT(1)
JAI_OM_OE_RMA_TAXES
rma_line_id = pr_order_line.line_id;

CURSOR
SELECT
FROM
WHERE
AND

get_so_tax_lines_count_cur(p_header_id NUMBER, p_line_id NUMBER) IS


COUNT(1)
JAI_OM_OE_SO_TAXES
header_id = p_header_id
line_id = p_line_id;

CURSOR get_rma_lines_count_cur(p_line_id NUMBER) IS


SELECT COUNT(1)

FROM JAI_OM_OE_RMA_LINES
WHERE rma_line_id = pr_order_line.line_id;
CURSOR
SELECT
FROM
WHERE
CURSOR
SELECT
FROM
WHERE
AND
AND
l of SQL
AND
CURSOR
SELECT
FROM
WHERE
AND
AND
AND
AND

get_so_lines_count_cur(p_line_id NUMBER) IS
COUNT(1)
JAI_OM_OE_SO_LINES
line_id = p_line_id;
return_tax_amount_Cur(p_header_id NUMBER, p_line_id NUMBER) IS
SUM(A.tax_amount)
JAI_OM_OE_RMA_TAXES a, JAI_CMN_TAXES_ALL b
a.rma_line_id = p_line_id
b.tax_id = A.tax_id
b.tax_type <> jai_constants.tax_type_tds /* 'TDS'; Ramananda for remova
LITERALs */
NVL(b.inclusive_tax_flag, 'N') = 'N';
order_tax_amount_Cur(p_header_id NUMBER, p_line_id NUMBER) IS
SUM(A.tax_amount)
JAI_OM_OE_SO_TAXES A, JAI_CMN_TAXES_ALL b
A.Header_ID = p_header_id
A.line_id = p_line_id
b.tax_id = A.tax_id
b.tax_type <> jai_constants.tax_type_tds
NVL(b.inclusive_tax_flag, 'N') = 'N';

v_transaction_name
l_func_curr_det
v_set_of_books_id
v_converted_rate
v_assessable_value
v_source_id
v_Line_Category_Code
v_tax_category_id
v_line_tax_amount
v_line_amount
v_assessable_amount
ln_vat_assessable_value
v_so_tax_lines_count
v_shipment_schedule_line_id
v_so_lines_count
c_source_line_id
v_service_type_code

VARCHAR2(30);
jai_plsql_cache_pkg.func_curr_details;
NUMBER;
NUMBER;
NUMBER;
NUMBER;
VARCHAR2(30);
NUMBER;
NUMBER;
NUMBER;
NUMBER;
JAI_OM_OE_SO_LINES.VAT_ASSESSABLE_VALUE%TYPE;
NUMBER;
NUMBER;
NUMBER;
NUMBER;
varchar2(30);

BEGIN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NORMAL
_ORDER','3651 begin of CREATE_NORMAL_ORDER procedure');
/* *****************************************************************************
*************************
Change History
1. 1 JAN 2014 nkodakan for bug 18093689
Issue : ERROR ON CLICKING AVAILABILITY WITHOUT ENTERING QUANTITY IN SALES OR
DER
Fix : Added a condition IF NVL(pr_order_line.ordered_quantity, 0) = 0 th
en
and also added out parameters p_return_code , p_return_message for proce
dure CREATE_NORMAL_ORDER

********************************************************************************
***********************/
v_transaction_name
:= 'SALES_ORDER';
v_Line_Category_Code
:= pr_order_line.Line_Category_Code;
v_service_type_code
:= JAI_AR_RCTLA_TRIGGER_PKG.get_service_type(pr_h
eader_info.customer_id,
NVL(
pr_order_line.ship_to_ORG_id, 0),
'C')
;
v_line_amount
:= (NVL(pr_order_line.ordered_quantity, 0) * NVL(
pr_order_line.UNIT_SELLING_PRICE, 0));
v_line_tax_amount
:= 0;
/*
Issue:If an RMA order is created having a return_context as null then the reco
rd gets
inserted into the JAI_OM_OE_SO_LINES table.
Even though a rma line is not having the return_context field still the
line should be treated as
RMA and not as a sales order line.
Solution:Added an NVL clause to the below IF statement .
Now even if the Return_context is null it would be treated as = LEGACY
and the v_transaction_name flag would be set to LEGACY.
Due to this the record would be inserted into the JAI_OM_OE_RMA_LINES ta
ble instead of the
JAI_OM_OE_SO_LINES table.
*/
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NORMAL
_ORDER','3674 pr_order_line.LINE_CATEGORY_CODE '||pr_order_line.LINE_CATEGORY_CO
DE);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NORMAL
_ORDER','3675 pr_order_line.return_context '||pr_order_line.return_context);
IF pr_order_line.LINE_CATEGORY_CODE = 'RETURN' THEN
IF pr_order_line.return_context IS NULL THEN
v_transaction_name := 'RMA_LEGACY_INSERT';
ELSE
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NO
RMAL_ORDER','3680 Before Return');
RETURN;
END IF;
END IF;
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' v_transaction_name ' || v_transaction_name);
END IF;
-- Else if the line is a fresh line , Unsplitted
/*
Removed the cursor set_of_books_cur and added the following check
using plsql caching for performance issues reported.
*/
l_func_curr_det := jai_plsql_cache_pkg.return_sob_curr(p_org_id => pr_order_
line.ORG_ID);

v_set_of_books_id := l_func_curr_det.ledger_id;
v_converted_rate

:= jai_cmn_utils_pkg.currency_conversion(v_set_of_books_i

d,
pr_header_info.c
urrency_code,
pr_header_info.c
onv_date,
pr_header_info.c
onv_type_code,
pr_header_info.c
onv_rate);
v_assessable_value := jai_om_utils_pkg.get_oe_assessable_value(p_customer_id
=> pr_header_info.customer_id,
p_ship_to_sit
e_use_id => NVL(pr_order_line.ship_to_ORG_id, 0),
p_inventory_i
tem_id => pr_order_line.inventory_item_id,
p_uom_code
=> pr_order_line.ORDER_QUANTITY_UOM,
p_default_pri
ce
=> pr_order_line.unit_selling_price,
p_ass_value_d
ate
=> pr_header_info.date_ordered,
p_sob_id
=> v_set_of_books_id,
p_curr_conv_c
ode
=> pr_header_info.conv_type_code,
p_conv_rate
=> v_converted_rate);
v_assessable_amount := NVL(v_assessable_value, 0) * NVL(pr_order_line.ordere
d_quantity, 0);
ln_vat_assessable_value := jai_general_pkg.JA_IN_VAT_ASSESSABLE_VALUE(P_PART
=> pr_header_info.customer_id,
P_PART
Y_SITE_ID
=> NVL(pr_order_line.ship_to_ORG_id, 0),
P_INVE
NTORY_ITEM_ID => pr_order_line.inventory_item_id,
P_UOM_
CODE
=> pr_order_line.ORDER_QUANTITY_UOM,
P_DEFA
ULT_PRICE
=> pr_order_line.unit_selling_price,
P_ASS_
VALUE_DATE
=> pr_header_info.date_ordered,
P_PART
Y_TYPE
=> 'C');
Y_ID

ln_vat_assessable_value := nvl(ln_vat_assessable_value, 0) * NVL(pr_order_li


ne.ordered_quantity, 0);
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' v_assessable_value' || v_assessable_value);
END IF;
OPEN get_source_id;
FETCH get_source_id

INTO v_source_id;
CLOSE get_source_id;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NORMAL
_ORDER','3738 v_line_category_code '||v_line_category_code);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NORMAL
_ORDER','3739 v_transaction_name '||v_transaction_name);
IF ((v_line_category_code = 'ORDER') OR
(v_transaction_name = 'RMA_LEGACY_INSERT')) THEN
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' inside IF OF v_line_category_code IN (ORDER) OR v_tran
saction_name = RMA_LEGACY_INSERT');
END IF;
IF NVL(pr_order_line.ship_to_ORG_id, 0) <> NVL(pr_old_line.ship_to_ORG_id,
0) THEN
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' BEFORE DELETING WHEN ship TO org has changed');
END IF;
IF (v_transaction_name = 'RMA_LEGACY_INSERT') THEN
DELETE
DELETE
ELSE
DELETE
DELETE
END IF;
END IF;

JAI_OM_OE_RMA_LINES WHERE RMA_LINE_ID = pr_order_line.line_id;


JAI_OM_OE_RMA_TAXES WHERE RMA_LINE_ID = pr_order_line.line_id;
JAI_OM_OE_SO_LINES WHERE LINE_ID = pr_order_line.line_id;
JAI_OM_OE_SO_TAXES WHERE Line_ID = pr_order_line.line_id;

IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN


FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' BEFORE calling jai_cmn_tax_defaultation_pkg.ja_in_cust_
default_taxes ');
END IF;
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' Before calling jai_cmn_tax_defaultation_pkg.ja_in_cust_
default_taxes:' ||
' pr_order_line.SHIP_FROM_ORG_ID:' || pr_order_line.SHIP_
FROM_ORG_ID ||
' customer_id: ' || pr_header_info.customer_id ||
' ship_to_site_use_id:' || pr_order_line.ship_to_ORG_id |
|
' pr_order_line.inventory_item_id:' || pr_order_line.inve
ntory_item_id ||
' pr_order_line.header_id:' || pr_order_line.header_id ||
' pr_order_line.line_id:' || pr_order_line.line_id);
END IF;
jai_cmn_tax_defaultation_pkg.ja_in_cust_default_taxes(pr_order_line.SHIP_F
ROM_ORG_ID,

pr_header_info.custo
mer_id,
NVL(pr_order_line.sh
ip_to_ORG_id, 0),
pr_order_line.invent
ory_item_id,
pr_order_line.header
_id,
pr_order_line.line_i
d,
v_tax_category_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NORM
AL_ORDER','3791 v_tax_category_id '||v_tax_category_id);
IF v_tax_category_id IS NULL THEN
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' BEFORE calling jai_cmn_tax_defaultation_pkg.ja_in_org
_default_taxes ');
END IF;
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' Tax category id is null, then call jai_cmn_tax_defaul
tation_pkg.ja_in_org_default_taxes:' ||
' pr_order_line.SHIP_FROM_ORG_ID:' || pr_order_line.SHI
P_FROM_ORG_ID ||
' pr_order_line.inventory_item_id: ' ||
pr_order_line.inventory_item_id);
END IF;
jai_cmn_tax_defaultation_pkg.ja_in_org_default_taxes(pr_order_line.SHIP_
FROM_ORG_ID,
pr_order_line.inven
tory_item_id,
v_tax_category_id);
ELSE
/* elsif of v_tax_category_id IS NULL */
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' BEFORE setting v_line_tax_amount := p_line_amount ');
END IF;
v_line_tax_amount := v_line_amount;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NORM
AL_ORDER','3820 v_line_tax_amount '||v_line_tax_amount);
END IF;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NORM
AL_ORDER','3821 v_transaction_name '||v_transaction_name);
IF v_transaction_name = 'RMA_LEGACY_INSERT' THEN
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' inside IF OF RMA_LEGACY_INSERT ');
END IF;

OPEN get_rma_tax_lines_count_cur;
FETCH get_rma_tax_lines_count_cur
INTO v_so_tax_lines_count;
CLOSE get_rma_tax_lines_count_cur;
ELSE
--14
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' inside ELSE OF RMA_LEGACY_INSERT ');
END IF;
OPEN get_so_tax_lines_count_cur(pr_order_line.header_id, pr_order_line.l
ine_id);
FETCH get_so_tax_lines_count_cur
INTO v_so_tax_lines_count;
CLOSE get_so_tax_lines_count_cur;
END IF;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NORM
AL_ORDER','3851 v_so_tax_lines_count '||v_so_tax_lines_count);
IF v_so_tax_lines_count = 0 THEN
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' inside IF OF v_so_tax_lines_count = 0 ');
END IF;
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' If v_so_tax_lines_count = 0, then call jai_cmn_tax_de
faultation_pkg.ja_in_calc_prec_taxes:' ||
' p_transaction_name:' || v_transaction_name ||
' p_tax_category_id:' || v_tax_category_id ||
' p_header_id:' || pr_order_line.header_id ||
' p_line_id:' || pr_order_line.line_id ||
' p_assessable_value:' || v_assessable_value ||
' p_line_tax_amount:' || v_line_tax_amount ||
' p_inventory_item_id:' || pr_order_line.inventory_item
_id ||
' p_line_quantity:' || pr_order_line.ordered_quantity |
|
' p_uom_code:' || pr_order_line.ORDER_QUANTITY_UOM);
END IF;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NO
RMAL_ORDER','3874 v_transaction_name '||v_transaction_name);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NO
RMAL_ORDER','3875 v_tax_category_id '||v_tax_category_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NO
RMAL_ORDER','3876 pr_order_line.header_id '||pr_order_line.header_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NO
RMAL_ORDER','3877 pr_order_line.line_id '||pr_order_line.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NO
RMAL_ORDER','3878 v_assessable_amount '||v_assessable_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NO
RMAL_ORDER','3879 v_line_tax_amount '||v_line_tax_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NO

RMAL_ORDER','3880 pr_order_line.ordered_quantity '||pr_order_line.ordered_quanti


ty);
jai_cmn_tax_defaultation_pkg.ja_in_calc_prec_taxes(transaction_name
=> v_transaction_name,
p_tax_category_id
=> v_tax_category_id,
p_header_id
=> pr_order_line.header_id,
p_line_id
=> pr_order_line.line_id,
p_assessable_value
=> v_assessable_amount,
p_tax_amount
=> v_line_tax_amount,
p_inventory_item_id
=> pr_order_line.inventory_item_id,
p_line_quantity
=> NVL(pr_order_line.ordered_quantity, 0),
p_uom_code
=> pr_order_line.ORDER_QUANTITY_UOM,
p_vendor_id
=> '',
p_currency
=> '',
p_currency_conv_facto
r => v_converted_rate,
p_creation_date
=> pr_order_line.creation_date,
p_created_by
=> pr_order_line.created_by,
p_last_update_date
=> pr_order_line.last_update_date,
p_last_updated_by
=> pr_order_line.last_updated_by,
p_last_update_login
=> pr_order_line.last_update_login,
p_operation_flag
=> NULL,
p_vat_assessable_valu
e => ln_vat_assessable_value
);
END IF; -- v_so_tax_lines_count = 0 THEN
END IF; -- v_line_category_code IN ('ORDER') THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NORMAL
_ORDER','3906 V_SHIPMENT_SCHEDULE_LINE_ID '||V_SHIPMENT_SCHEDULE_LINE_ID);
IF V_SHIPMENT_SCHEDULE_LINE_ID IS NULL THEN
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' inside IF OF V_SHIPMENT_SCHEDULE_LINE_ID IS NULL ');
END IF;
IF v_transaction_name = 'RMA_LEGACY_INSERT' THEN
OPEN get_rma_lines_count_cur(pr_order_line.line_id);
FETCH get_rma_lines_count_cur
INTO v_so_lines_count;

CLOSE get_rma_lines_count_cur;
ELSE
OPEN get_so_lines_count_cur(pr_order_line.line_id);
FETCH get_so_lines_count_cur
INTO v_so_lines_count;
CLOSE get_so_lines_count_cur;
END IF;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NORM
AL_ORDER','3927 v_so_lines_count '||v_so_lines_count);
IF v_so_lines_count = 0 THEN
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' inside IF OF v_so_lines_count = 0 ');
END IF;
IF v_transaction_name = 'RMA_LEGACY_INSERT' THEN
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
'BEFORE opening return_tax_amount_Cur ');
END IF;
OPEN return_tax_amount_Cur(pr_order_line.header_id, pr_order_line.LINE
_ID);
FETCH return_tax_amount_Cur
INTO v_line_tax_amount;
CLOSE return_tax_amount_Cur;
ELSE
OPEN order_tax_amount_Cur(pr_order_line.header_id, pr_order_line.LINE_
ID);
FETCH order_tax_amount_Cur
INTO v_line_tax_amount;
CLOSE order_tax_amount_Cur;
END IF;
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' Total tax : ' || v_line_tax_amount);
END IF;
-- Added by nkodakan for bug 18093689
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NO
RMAL_ORDER','3940 NARESH pr_order_line.ordered_quantity '||pr_order_line.ordered
_quantity);
IF NVL(pr_order_line.ordered_quantity, 0) = 0 then
p_return_code := jai_constants.expected_error ;
p_return_message := 'Please enter the quantity for the item correctly.
' ;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_
NORMAL_ORDER','3941 before return');
return ;
end if;
-- Added by nkodakan for bug 18093689
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NO
RMAL_ORDER','3959 v_transaction_name '||v_transaction_name);
IF v_transaction_name = 'RMA_LEGACY_INSERT' THEN

IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN


FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' BEFORE INSERTING RECORD INTO JAI_OM_OE_RMA_LINES ')
;
END IF;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_
NORMAL_ORDER','3967 INSERT INTO JAI_OM_OE_RMA_LINES rma_line_number '||pr_order_
line.line_number);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_
NORMAL_ORDER','3968 INSERT INTO JAI_OM_OE_RMA_LINES rma_line_id '||pr_order_line
.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_
NORMAL_ORDER','3969 INSERT INTO JAI_OM_OE_RMA_LINES rma_header_id '||pr_order_li
ne.header_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_
NORMAL_ORDER','3970 INSERT INTO JAI_OM_OE_RMA_LINES rma_number '||pr_header_info
.order_number);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_
NORMAL_ORDER','3971 INSERT INTO JAI_OM_OE_RMA_LINES quantity '||pr_order_line.or
dered_quantity);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_
NORMAL_ORDER','3972 INSERT INTO JAI_OM_OE_RMA_LINES tax_amount '||v_line_tax_amo
unt);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_
NORMAL_ORDER','3973 INSERT INTO JAI_OM_OE_RMA_LINES tax_category_id '||v_tax_cat
egory_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_
NORMAL_ORDER','3974 INSERT INTO JAI_OM_OE_RMA_LINES assessable_value '||v_assess
able_value);
INSERT INTO JAI_OM_OE_RMA_LINES
(rma_line_number,
rma_line_id,
rma_header_id,
rma_number,
inventory_item_id,
uom,
quantity,
tax_category_id,
selling_price,
tax_amount,
creation_date,
created_by,
last_update_date,
last_updated_by,
last_update_login,
assessable_value,
ship_to_org_id)
VALUES
(pr_order_line.line_number,
pr_order_line.line_id,
pr_order_line.header_id,
pr_header_info.order_number,
pr_order_line.inventory_item_id,
pr_order_line.ORDER_QUANTITY_UOM,
pr_order_line.ordered_quantity,
v_tax_category_id,
pr_order_line.UNIT_SELLING_PRICE,

v_line_tax_amount,
pr_order_line.creation_date,
pr_order_line.created_by,
pr_order_line.last_update_date,
pr_order_line.last_updated_by,
pr_order_line.last_update_login,
v_assessable_value,
pr_order_line.ship_to_org_id);
ELSE
/* else if of v_transaction_name = 'RMA_LEGACY_INSERT' */
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' BEFORE INSERTING RECORD INTO JAI_OM_OE_SO_LINES ');
END IF;
c_source_line_id := 0;
SELECT COUNT(*)
INTO c_source_line_id
FROM JAI_OM_OE_SO_LINES
WHERE LINE_ID = pr_order_line.line_id;
IF c_source_line_id = 0 THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_
NORMAL_ORDER','4027 INSERT INTO JAI_OM_OE_SO_LINES line_number '||pr_order_line.
line_number);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_
NORMAL_ORDER','4028 INSERT INTO JAI_OM_OE_SO_LINES line_id '||pr_order_line.line
_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_
NORMAL_ORDER','4029 INSERT INTO JAI_OM_OE_SO_LINES header_id '||pr_order_line.he
ader_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_
NORMAL_ORDER','4030 INSERT INTO JAI_OM_OE_SO_LINES quantity '||pr_order_line.ord
ered_quantity);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_
NORMAL_ORDER','4031 INSERT INTO JAI_OM_OE_SO_LINES line_amount '||v_line_amount)
;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_
NORMAL_ORDER','4032 INSERT INTO JAI_OM_OE_SO_LINES tax_amount '||v_line_tax_amou
nt);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_
NORMAL_ORDER','4033 INSERT INTO JAI_OM_OE_SO_LINES vat_assessable_value '||ln_va
t_assessable_value);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_
NORMAL_ORDER','4034 INSERT INTO JAI_OM_OE_SO_LINES assessable_value '||v_assessa
ble_value);
INSERT INTO JAI_OM_OE_SO_LINES
(line_number,
line_id,
header_id,
SHIPMENT_LINE_NUMBER,
shipment_schedule_line_id, -- uncommented by sriram - for lmw ato
issue
inventory_item_id,
unit_code,
ato_flag,
quantity,
tax_category_id,
selling_price,

assessable_value,
line_amount,
tax_amount,
line_tot_amount,
creation_date,
created_by,
last_update_date,
last_updated_by,
last_update_login,
vat_assessable_value,
service_type_code,
ship_to_org_id)
VALUES
(pr_order_line.line_number,
pr_order_line.line_id,
pr_order_line.header_id,
pr_order_line.SHIPMENT_NUMBER,
pr_order_line.ato_line_id, -- uncommented by sriram - for lmw ato
issue
pr_order_line.inventory_item_id,
pr_order_line.ORDER_QUANTITY_UOM,
'Y',
pr_order_line.ordered_quantity,
v_tax_category_id,
pr_order_line.UNIT_SELLING_PRICE,
v_assessable_value,
v_line_amount,
v_line_tax_amount,
(v_line_amount + v_line_tax_amount),
pr_order_line.creation_date,
pr_order_line.created_by,
pr_order_line.last_update_date,
pr_order_line.last_updated_by,
pr_order_line.last_update_login,
ln_vat_assessable_value,
v_service_type_code,
pr_order_line.ship_to_org_id);
END IF;
END IF; -END IF; -- IF v_so_lines_count = 0
END IF; -- V_SHIPMENT_SCHEDULE_LINE_ID
EXCEPTION
WHEN OTHERS THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NORM
AL_ORDER','4092 Exception occured in CREATE_NORMAL_ORDER procedure sqlcode '||sq
lcode);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.CREATE_NORM
AL_ORDER','4093 sqlerrm '||sqlerrm);
RAISE;
END CREATE_NORMAL_ORDER;
/*
REM
REM
REM
REM
REM
REM

+======================================================================+
NAME
PROCESS_CONFIG
DESCRIPTION

PROCESS ATO CONFIG

NOTES

Call from procdure POPULATE_TAX

REM
REM +======================================================================+
*/
PROCEDURE PROCESS_CONFIG (pr_order_line
t_rec%type) IS
v_api_name CONSTANT VARCHAR2(30) := 'PROCESS_CONFIG';
cursor
select
from
where
and

c_model_taxes is
*
JAI_OM_OE_SO_TAXES
header_id = pr_order_line.header_id
line_id = pr_order_line.ato_line_id;

cursor
select
from
where
and

c_model_tax_Categ is
tax_category_id, inventory_item_id, line_amount
JAI_OM_OE_SO_LINES
header_id = pr_order_line.header_id
line_id = pr_order_line.ato_line_id;

v_output_tax_amount
v_tax_category
v_ato_inventory_item_id
v_ato_line_amount
v_ato_tax_amount
v_ato_selling_price
v_ato_vat_assessable_value
v_ato_assessable_value
v_converted_rate

Number;
Number;
Number;
Number;
Number;
Number;
NUMBER;
Number;
NUMBER;

-- code segment added by sriram - LMW ATO


procedure calc_price_tax_for_config_item is
cursor c_get_line_tax_amt is
select line_amount,
tax_amount,
selling_price,
assessable_value,
quantity,
vat_assessable_value
from JAI_OM_OE_SO_LINES
where header_id = pr_order_line.header_id
and shipment_schedule_line_id = pr_order_line.ato_line_id
and line_id <> pr_order_line.line_id ;-- added for bug 17505816;
-- the last where clause handles the case where there are multiple config it
ems in the single order
begin
/* *****************************************************************************
*************************
Change History
1. 16-JAN-2014 nkodakan for bug 17505816
Issue : PRICE OF START ITEM DISAPEAR AFTER STAR ITEM OF ATO ORDER LINE BACK ORD
ER
Fix : added a condition and line_id <> pr_order_line.line_id in cursor c_get_
line_tax_amt
********************************************************************************
***********************/

jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.calc_price_ta
x_for_config_item','4150 begin of calc_price_tax_for_config_item procedure pr_or
der_line.header_id '||pr_order_line.header_id||
', pr_order_line.ato_line_id '||pr_order_line.ato_line_id||
', pr_order_line.line_id '||pr_order_line.line_id);
For so_lines_rec in c_get_line_tax_amt Loop
v_ato_line_amount
:= NVL(v_ato_line_amount, 0) +
NVL(so_lines_rec.line_amount, 0);
v_ato_tax_amount
:= NVL(v_ato_tax_amount, 0) +
NVL(so_lines_rec.tax_amount, 0);
v_ato_selling_price
:= NVL(v_ato_selling_price, 0) +
((NVL(so_lines_rec.selling_price, 0) *
so_lines_rec.quantity) /
pr_order_line.ordered_quantity);
v_ato_assessable_value := NVL(v_ato_assessable_value, 0) +
((NVL(so_lines_rec.assessable_value,
so_lines_rec.selling_price) *
so_lines_rec.quantity) /
pr_order_line.ordered_quantity);
v_ato_vat_assessable_value := NVL(v_ato_vat_assessable_value, 0) +
((NVL(so_lines_rec.vat_assessable_value,
so_lines_rec.selling_price) *
so_lines_rec.quantity) /
pr_order_line.ordered_quantity);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.calc_price_
tax_for_config_item','4160 v_ato_line_amount '||v_ato_line_amount||
', v_ato_tax_amount '||v_ato_tax_amount||
', v_ato_selling_price '||v_ato_selling_pri
ce||
', v_ato_assessable_value '||v_ato_assessab
le_value||
', v_ato_vat_assessable_value '||v_ato_vat_
assessable_value);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.calc_price_ta
x_for_config_item','4165 so_lines_rec.line_amount '||so_lines_rec.line_amount||
', so_lines_rec.selling_price '||so_lines_r
ec.selling_price||
', so_lines_rec.tax_amount '||so_lines_rec.
tax_amount||
', so_lines_rec.quantity '||so_lines_rec.qu
antity||
', so_lines_rec.assessable_value '||so_line
s_rec.assessable_value||
', so_lines_rec.vat_assessable_value '||so_
lines_rec.vat_assessable_value);
end loop;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.calc_price_ta
x_for_config_item','1470 end of calc_price_tax_for_config_item procedure ');
end;
BEGIN

jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CONFI
G','4177 begin of PROCESS_CONFIG procedure');
calc_price_tax_for_config_item;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CONFI
G','4178 update JAI_OM_OE_SO_LINES line_amount '||v_ato_line_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CONFI
G','4179 update JAI_OM_OE_SO_LINES assessable_value '||v_ato_assessable_value);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CONFI
G','4180 update JAI_OM_OE_SO_LINES vat_assessable_value '||v_ato_vat_assessable_
value);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CONFI
G','4181 update JAI_OM_OE_SO_LINES selling_price '||v_ato_selling_price);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CONFI
G','4182 update JAI_OM_OE_SO_LINES header_id '||pr_order_line.header_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CONFI
G','4183 update JAI_OM_OE_SO_LINES line_id '||pr_order_line.line_id);
update JAI_OM_OE_SO_LINES
set line_amount
= v_ato_line_amount,
assessable_value
= v_ato_assessable_value,
vat_assessable_value = v_ato_vat_assessable_value,
selling_price
= v_ato_selling_price
where header_id = pr_order_line.header_id
and line_id = pr_order_line.line_id;
-- copy the taxes of model item into config item
open c_model_tax_Categ;
Fetch c_model_tax_Categ
into v_tax_category,
v_ato_inventory_item_id,
v_output_tax_amount;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CONFI
G','4201 v_tax_category '||v_tax_category);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CONFI
G','4202 v_ato_inventory_item_id '||v_ato_inventory_item_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CONFI
G','4203 v_output_tax_amount '||v_output_tax_amount);
close c_model_tax_Categ;
For model_rec in c_model_taxes Loop
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
'In the Loop Header ID ~ Line ID :' ||
TO_CHAR(pr_order_line.header_id) || ' ~ ' ||
TO_CHAR(pr_order_line.line_id));
END IF;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CON
FIG','4216 tax_line_no '||model_rec.tax_line_no);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CON
FIG','4217 v_output_tax_amount '||pr_order_line.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CON
FIG','4218 header_id '||pr_order_line.header_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CON
FIG','4219 tax_amount '||model_rec.tax_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CON

FIG','4220 base_tax_amount '||model_rec.base_tax_amount);


jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CON
FIG','4221 func_tax_amount '||model_rec.func_tax_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CON
FIG','4222 model_rec.tax_id '||model_rec.tax_id);
Insert into JAI_OM_OE_SO_TAXES
(tax_line_no,
line_id,
header_id,
precedence_1,
precedence_2,
precedence_3,
precedence_4,
precedence_5,
tax_id,
tax_rate,
qty_rate,
uom,
tax_amount,
base_tax_amount,
func_tax_amount,
creation_date,
created_by,
last_update_date,
last_updated_by,
last_update_login,
tax_category_id,
precedence_6,
precedence_7,
precedence_8,
precedence_9,
precedence_10)
Values
(model_rec.tax_line_no,
pr_order_line.line_id,
pr_order_line.header_id,
model_rec.precedence_1,
model_rec.precedence_2,
model_rec.precedence_3,
model_rec.precedence_4,
model_rec.precedence_5,
model_rec.tax_id,
model_rec.tax_rate,
model_rec.qty_rate,
model_rec.uom,
model_rec.tax_amount,
model_rec.base_tax_amount,
model_rec.func_tax_amount,
model_rec.creation_date,
model_rec.created_by,
model_rec.last_update_date,
model_rec.last_updated_by,
model_rec.last_update_login,
model_rec.tax_category_id,
model_rec.precedence_6,
model_rec.precedence_7,
model_rec.precedence_8,
model_rec.precedence_9,
model_rec.precedence_10);

End Loop;
-- to recalculate taxes
v_ato_assessable_value := NVL(v_ato_assessable_value, 0) *
NVL(pr_order_line.ordered_quantity, 0);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CONFI
G', '4285 before call to jai_om_tax_pkg.calculate_ato_taxes ');
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CONFI
G', '4386 before call to jai_om_tax_pkg.calculate_ato_taxes pr_order_line.ordere
d_quantity'||pr_order_line.ordered_quantity);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CONFI
G', '4387 before call to jai_om_tax_pkg.calculate_ato_taxes pr_order_line.pricin
g_quantity_uom'||pr_order_line.pricing_quantity_uom);
jai_om_tax_pkg.calculate_ato_taxes('OE_LINES_UPDATE',
NULL,
pr_order_line.header_id,
pr_order_line.line_id,
v_ato_assessable_value,
v_ato_line_amount,
v_converted_rate,
pr_order_line.inventory_item_id,
pr_order_line.ordered_quantity,
pr_order_line.ordered_quantity,
pr_order_line.pricing_quantity_uom,
NULL,
NULL,
NULL,
NULL,
pr_order_line.last_update_date,
pr_order_line.last_updated_by,
pr_order_line.last_update_login,
v_ato_vat_assessable_value);
-- update the tax amounts after doing tax recalculation .
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CONFI
G', '4309 v_ato_line_amount '||v_ato_line_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CONFI
G', '4310 before call to jai_om_tax_pkg.calculate_ato_taxes pr_order_line.pricin
g_quantity_uom'||pr_order_line.pricing_quantity_uom);
update JAI_OM_OE_SO_LINES
set tax_amount
= NVL(v_ato_line_amount, 0),
line_tot_amount = line_amount + NVL(v_ato_line_amount, 0)
where header_id = pr_order_line.header_id
and line_id = pr_order_line.line_id;
EXCEPTION
WHEN OTHERS THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CON
FIG', '4320 exception occured in PROCESS_CONFIG procedure SQLCODE '||SQLCODE);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.PROCESS_CON
FIG', '4321 SQLERRM '||SQLERRM);
RAISE;
END PROCESS_CONFIG;
/*
REM +======================================================================+
REM NAME
COPY_SPLIT_LINE

REM
REM DESCRIPTION COPY FROM ORIGINAL LINES
REM
REM NOTES
Call from procdure POPULATE_TAX
REM
REM +======================================================================+
*/
PROCEDURE COPY_SPLIT_LINE(pr_order_line
t_rec%type) IS
v_api_name CONSTANT VARCHAR2(30) := 'COPY_SPLIT_LINE';
CURSOR
SELECT
FROM
WHERE

rec_get_lc_flag IS
lc_flag
JAI_OM_OE_SO_LINES
line_id = pr_order_line.split_from_line_id;

CURSOR
SELECT
FROM
WHERE
AND

get_so_tax_lines_count_cur(p_header_id NUMBER, p_line_id NUMBER) IS


COUNT(1)
JAI_OM_OE_SO_TAXES
header_id = p_header_id
line_id = p_line_id;

CURSOR so_tax_lines_cur(p_header_id NUMBER, p_line_id NUMBER) IS


SELECT tax_line_no,
tax_id,
tax_rate,
qty_rate,
uom,
precedence_1,
precedence_2,
precedence_3,
precedence_4,
precedence_5,
precedence_6,
precedence_7,
precedence_8,
precedence_9,
precedence_10,
tax_amount,
base_tax_amount,
func_tax_amount,
tax_category_id
FROM JAI_OM_OE_SO_TAXES
WHERE header_id = p_header_id
AND line_id = p_line_id;
cursor
select
from
where

c_fetch_rounding_factor(p_tax_id number) is
nvl(rounding_factor, 0), nvl(adhoc_flag, 'N')
JAI_CMN_TAXES_ALL
tax_id = p_tax_id;

CURSOR
SELECT
FROM
WHERE
AND
AND
AND
AND

order_tax_amount_Cur(p_header_id NUMBER, p_line_id NUMBER) IS


SUM(A.tax_amount)
JAI_OM_OE_SO_TAXES A, JAI_CMN_TAXES_ALL b
A.Header_ID = p_header_id
A.line_id = p_line_id
b.tax_id = A.tax_id
b.tax_type <> jai_constants.tax_type_tds
NVL(b.inclusive_tax_flag, 'N') = 'N';

copy_rec
c_source_line_id
v_line_new_amount
v_new_vat_assessable_value
l_lc_flag
v_old_quantity
v_so_tax_lines_count
v_tax_line_count
v_rounding_factor
v_adhoc_flag
v_new_tax_amount
v_new_base_tax_amount
v_header_tax_amount
v_new_func_tax_amount
v_line_quantity

get_copy_order_line%ROWTYPE;
NUMBER;
NUMBER;
NUMBER;
JAI_OM_OE_SO_LINES.LC_FLAG%TYPE;
NUMBER;
NUMBER;
NUMBER;
JAI_CMN_TAXES_ALL.rounding_factor%type;
JAI_CMN_TAXES_ALL.adhoc_flag%type;
NUMBER;
NUMBER;
number;
NUMBER;
NUMBER;

BEGIN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_LI
NE', '4406 begin of COPY_SPLIT_LINE procedure ');
c_source_line_id := 0;
v_header_tax_amount := 0;
v_line_quantity
:= NVL(pr_order_line.ordered_quantity, 0);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_LI
NE', '4410 v_line_quantity '||v_line_quantity);
SELECT
INTO
FROM
WHERE

COUNT(*)
c_source_line_id
JAI_OM_OE_SO_LINES
LINE_ID = pr_order_line.line_id;

jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPL
IT_LINE', '4417 pr_order_line.line_id '||pr_order_line.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPL
IT_LINE', '4418 c_source_line_id '||c_source_line_id);
IF c_source_line_id = 0 THEN
/*
If the original line from which the new line has been split is lc enable
d i.e lc _flag has been checked
the new line should also have the same value for lc_flag.
copy the original value of lc_flag value from the orginal line from wher
e the new line has been split.
*/
-- When this is a split line
OPEN Get_Copy_Order_Line(pr_order_line.header_id, pr_order_line.SPLIT_FROM
_LINE_ID);
FETCH Get_Copy_Order_Line
INTO copy_rec;
CLOSE Get_Copy_Order_Line;
-- Proportionate the corresponding amount according to the new quantity
v_line_new_amount
:= (copy_rec.line_amount /
copy_rec.QUANTITY) *
(v_line_quantity);
v_new_vat_assessable_value := (copy_rec.vat_assessable_value /
copy_rec.quantity) *
(v_line_quantity);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_
LINE', '4438 v_line_new_amount '||v_line_new_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_

LINE', '4439 v_new_vat_assessable_value '||v_new_vat_assessable_value);


OPEN rec_get_lc_flag;
FETCH rec_get_lc_flag
INTO l_lc_flag;
CLOSE rec_get_lc_flag;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_
LINE', '4446 line_number '||pr_order_line.line_number);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_
LINE', '4447 line_id '||pr_order_line.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_
LINE', '4448 header_id '||pr_order_line.header_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_
LINE', '4449 SPLIT_FROM_LINE_ID '||pr_order_line.SPLIT_FROM_LINE_ID);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_
LINE', '4450 quantity '|| pr_order_line.ordered_quantity);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_
LINE', '4451 line_amount '||v_line_new_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_
LINE', '4452 tax_amount '||v_new_vat_assessable_value);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_
LINE', '4453 assessable_value '||copy_rec.assessable_value);
INSERT INTO JAI_OM_OE_SO_LINES
(line_number,
line_id,
header_id,
SPLIT_FROM_LINE_ID,
SHIPMENT_LINE_NUMBER,
shipment_schedule_line_id,
inventory_item_id,
unit_code,
ato_flag,
quantity,
tax_category_id,
selling_price,
assessable_value,
line_amount,
tax_amount,
line_tot_amount,
creation_date,
created_by,
last_update_date,
last_updated_by,
last_update_login,
EXCISE_EXEMPT_TYPE,
EXCISE_EXEMPT_REFNO,
EXCISE_EXEMPT_DATE,
lc_flag,
VAT_EXEMPTION_FLAG,
VAT_EXEMPTION_TYPE,
VAT_EXEMPTION_DATE,
VAT_EXEMPTION_REFNO,
VAT_ASSESSABLE_VALUE,
VAT_REVERSAL_PRICE,
service_type_code,
ship_to_org_id)
VALUES

(pr_order_line.line_number,
pr_order_line.line_id,
pr_order_line.header_id,
pr_order_line.SPLIT_FROM_LINE_ID,
pr_order_line.SHIPMENT_NUMBER,
pr_order_line.ato_line_id,
pr_order_line.inventory_item_id,
pr_order_line.ORDER_QUANTITY_UOM,
'Y',
pr_order_line.ordered_quantity,
copy_rec.tax_category_id,
pr_order_line.UNIT_SELLING_PRICE,
copy_rec.assessable_value,
v_line_new_amount,
0,
0,
pr_order_line.creation_date,
pr_order_line.created_by,
pr_order_line.last_update_date,
pr_order_line.last_updated_by,
pr_order_line.last_update_login,
Copy_rec.EXCISE_EXEMPT_TYPE,
copy_rec.EXCISE_EXEMPT_REFNO,
copy_rec.EXCISE_EXEMPT_DATE,
l_lc_flag,
Copy_rec.VAT_EXEMPTION_FLAG,
Copy_rec.VAT_EXEMPTION_TYPE,
Copy_rec.VAT_EXEMPTION_DATE,
Copy_rec.VAT_EXEMPTION_REFNO,
v_new_vat_assessable_value,
(copy_rec.vat_reversal_price / copy_rec.quantity) *
(v_line_quantity),
copy_rec.service_type_code,
pr_order_line.ship_to_org_id);
END IF;
-- carry over the old ordered quantity into the below tax line loop for tax
amount proportionating
v_old_quantity := copy_rec.QUANTITY;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_LI
NE', '4530 v_old_quantity '||v_old_quantity);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_LI
NE', '4532 pr_order_line.header_id '||pr_order_line.header_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_LI
NE', '4533 pr_order_line.SPLIT_FROM_LINE_ID '||pr_order_line.SPLIT_FROM_LINE_ID)
;
OPEN Get_So_Tax_Lines_Count_Cur(pr_order_line.header_id,
pr_order_line.SPLIT_FROM_LINE_ID);
FETCH Get_So_Tax_Lines_Count_Cur
INTO v_so_tax_lines_count;
CLOSE Get_So_Tax_Lines_Count_Cur;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_LI
NE', '4540 v_so_tax_lines_count '||v_so_tax_lines_count);
IF NVL(v_so_tax_lines_count, 0) > 0 THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_
LINE', '4543 pr_order_line.SPLIT_FROM_LINE_ID '||pr_order_line.header_id);

jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_
LINE', '4544 pr_order_line.SPLIT_FROM_LINE_ID '||pr_order_line.SPLIT_FROM_LINE_I
D);
FOR Rec IN So_Tax_Lines_Cur(pr_order_line.header_id,
pr_order_line.SPLIT_FROM_LINE_ID) LOOP
SELECT
INTO
FROM
WHERE
AND

COUNT(1)
v_tax_line_count
JAI_OM_OE_SO_TAXES
line_id = pr_order_line.line_id
tax_id = rec.tax_id;

jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLI
T_LINE', '4554 v_tax_line_count '||v_tax_line_count);
IF v_tax_line_count = 0 THEN
open c_fetch_rounding_factor(rec.tax_id);
fetch c_fetch_rounding_factor
into v_rounding_factor, v_adhoc_flag;
close c_fetch_rounding_factor;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG
.COPY_SPLIT_LINE', '4562 v_adhoc_flag '||v_adhoc_flag);
IF v_adhoc_flag = 'N' THEN
--If the tax is a qty rate based tax then pick up the qty rate inste
ad of the tax_rate so added an nvl condition
--to also add qty_rate.
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSI
NG_PKG.COPY_SPLIT_LINE', '4568 rec.tax_rate '||rec.tax_rate);
IF rec.tax_rate is not null THEN
v_new_tax_amount := round((rec.base_tax_amount /
v_old_quantity) *
(v_line_quantity) *
(rec.tax_rate) / 100,
v_rounding_factor);
ELSIF rec.qty_rate is not null THEN
v_new_tax_amount := round((rec.base_tax_amount /
v_old_quantity) *
(v_line_quantity),
v_rounding_factor);
END IF;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
SPLIT_LINE', '4581 v_new_tax_amount '||v_new_tax_amount);
ELSIF v_adhoc_flag = 'Y' THEN
v_new_tax_amount := round((rec.tax_amount / v_old_quantity) *
v_line_quantity,
v_rounding_factor);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_
SPLIT_LINE', '4587 v_new_tax_amount '||v_new_tax_amount);
END IF;
v_new_base_tax_amount := round((rec.base_tax_amount /
v_old_quantity) *
(v_line_quantity),
v_rounding_factor);
v_new_func_tax_amount := round((rec.func_tax_amount /

v_header_tax_amount

v_old_quantity) *
(v_line_quantity),
v_rounding_factor);
:= v_header_tax_amount +
v_new_tax_amount;

jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG
.COPY_SPLIT_LINE', '4602 INSERT INTO JAI_OM_OE_SO_TAXES header_id '||pr_order_li
ne.header_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG
.COPY_SPLIT_LINE', '4603 INSERT INTO JAI_OM_OE_SO_TAXES line_id '||pr_order_line
.line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG
.COPY_SPLIT_LINE', '4604 INSERT INTO JAI_OM_OE_SO_TAXES tax_line_no '||rec.tax_l
ine_no);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG
.COPY_SPLIT_LINE', '4605 INSERT INTO JAI_OM_OE_SO_TAXES tax_id '||rec.tax_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG
.COPY_SPLIT_LINE', '4606 INSERT INTO JAI_OM_OE_SO_TAXES tax_amount '||v_new_tax_
amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG
.COPY_SPLIT_LINE', '4607 INSERT INTO JAI_OM_OE_SO_TAXES base_tax_amount '||v_new
_base_tax_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG
.COPY_SPLIT_LINE', '4608 INSERT INTO JAI_OM_OE_SO_TAXES func_tax_amount '||v_new
_func_tax_amount);
INSERT INTO JAI_OM_OE_SO_TAXES
(header_id,
line_id,
tax_line_no,
tax_id,
tax_rate,
qty_rate,
uom,
precedence_1,
precedence_2,
precedence_3,
precedence_4,
precedence_5,
precedence_6,
precedence_7,
precedence_8,
precedence_9,
precedence_10,
tax_amount,
base_tax_amount,
func_tax_amount,
creation_date,
created_by,
last_update_date,
last_updated_by,
last_update_login,
tax_category_id)
VALUES
(pr_order_line.header_id,
pr_order_line.line_id,
rec.tax_line_no,
rec.tax_id,
rec.tax_rate,

rec.qty_rate,
rec.uom,
rec.precedence_1,
rec.precedence_2,
rec.precedence_3,
rec.precedence_4,
rec.precedence_5,
rec.precedence_6,
rec.precedence_7,
rec.precedence_8,
rec.precedence_9,
rec.precedence_10,
v_new_tax_amount,
v_new_base_tax_amount,
v_new_func_tax_amount,
pr_order_line.creation_date,
pr_order_line.created_by,
pr_order_line.last_update_date,
pr_order_line.last_updated_by,
pr_order_line.last_update_login,
rec.tax_category_id);
END IF;
END LOOP; --FOR Rec IN So_Tax_Lines_Cur( pr_order_line.header_id, pr_order
_line.SPLIT_FROM_LINE_ID)
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
'** START OForder_tax_amount_Cur ' ||
pr_order_line.header_id || ' line id ' || pr_order_line.l
ine_id);
END IF;
OPEN order_tax_amount_Cur(pr_order_line.header_id, pr_order_line.line_id);
FETCH order_tax_amount_Cur
INTO v_header_tax_amount;
CLOSE order_tax_amount_Cur;
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
'** v_header_tax_amount ' || v_header_tax_amount);
END IF;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_
LINE', '4683 update JAI_OM_OE_SO_LINES tax_amount '||v_header_tax_amount);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_
LINE', '4684 update JAI_OM_OE_SO_LINES header_id '||pr_order_line.header_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_
LINE', '4685 update JAI_OM_OE_SO_LINES line_id '||pr_order_line.line_id);
update JAI_OM_OE_SO_LINES
set tax_amount
= nvl(v_header_tax_amount, 0),
line_tot_amount = nvl(v_header_tax_amount, 0) +
nvl(line_amount, 0)
where header_id = pr_order_line.header_id
and line_id = pr_order_line.line_id;
END IF; -- NVL(v_so_tax_lines_count,0)>0 THEN
EXCEPTION
WHEN OTHERS THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_LI
NE', '4696 exception occured in COPY_SPLIT_LINE procedure sqlcode '||sqlcode);

jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.COPY_SPLIT_LI
NE', '4697 sqlerrm '||sqlerrm);
RAISE;
END COPY_SPLIT_LINE;
--==========================================================================
-FUNCTION NAME:
--Get_Model_line_Detail
Private
--- DESCRIPTION:
-Return the ATO model line detail
--- PARAMETERS:
-In: pn_header_id IN NUMBER
-pn_line_id IN NUMBER
--OUT: xn_organization_id OUT NUMBER
-xn_inventory_item_id OUT NUMBER
--- DESIGN REFERENCES:
--- CHANGE HISTORY:
--04-June-2010 Eric Ma created
--==========================================================================
PROCEDURE Get_Model_line_Detail(pn_header_id
IN NUMBER,
pn_line_id
IN NUMBER,
xn_organization_id OUT NOCOPY NUMBER,
xn_inventory_item_id OUT NOCOPY NUMBER) IS
CURSOR Get_model_line_dtls_cur IS
SELECT ship_from_org_id, inventory_item_id
FROM OE_ORDER_LINES_ALL
WHERE header_id = pn_header_id
AND line_id = pn_line_id;
BEGIN
OPEN Get_model_line_dtls_cur;
FETCH Get_model_line_dtls_cur
INTO xn_organization_id, xn_inventory_item_id;
CLOSE Get_model_line_dtls_cur;
EXCEPTION
WHEN OTHERS THEN
RAISE;
END Get_Model_line_Detail;
/*
+======================================================================+
REM NAME
POPULATE_TAX
REM
REM DESCRIPTION Called from procdure JAI_TAX_PROCESSING_PKG
REM
REM NOTES
Come from procdure JAI_OE_OLA_TRIGGER_PKG.ARIU_T1
REM
REM HISTORY
REM 19-Jun-2012 Created from JAI trigger package
REM +======================================================================+
*/
PROCEDURE POPULATE_TAX(pr_old
t_rec%type,
pr_new
t_rec%type,

pv_action
varchar2,
pv_return_code
out nocopy varchar2,
pv_return_message out nocopy varchar2) IS
v_api_name CONSTANT VARCHAR2(30) := 'POPULATE_TAX';
CURSOR
SELECT
FROM
WHERE

get_order_source_type(p_source_document_type_id NUMBER) IS
name
oe_order_sources
order_source_id = p_source_document_type_id;

--------------------------------/* Declarations for Copy Order */


--------------------------------v_order_source_type
VARCHAR2(240);
r_get_header_info
v_hook

get_header_info%ROWTYPE;
VARCHAR2(6);

BEGIN
/* *****************************************************************************
*************************
Change History
1. 16-JAN-2014 nkodakan for bug 17505816
Issue : PRICE OF START ITEM DISAPEAR AFTER STAR ITEM OF ATO ORDER LINE BACK ORD
ER
Fix : Commented IF pr_new.SPLIT_FROM_LINE_ID IS NULL AND
2. 19-JAN-2014 nkodakan for bug 18093689
Issue : ERROR ON CLICKING AVAILABILITY WITHOUT ENTERING QUANTITY IN SALES OR
DER
Fix : Added parameters p_return_code , p_return_message for procedure CR
EATE_NORMAL_ORDER
********************************************************************************
***********************/
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.POPULATE_TAX'
,'4777 begin of POPULATE_TAX procedure');
IF (G_LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_PROCEDURE,
G_MODULE_NAME || v_api_name || '.BEGIN',
G_PKG_NAME || ': ' || v_api_name || '()+');
END IF;
pv_return_code := jai_constants.successful;
if (pv_action = jai_constants.updating and
((nvl(pr_old.line_number, -9999) <> nvl(pr_new.line_number, -9998)) and
pr_new.line_number is not null)) OR
(pv_action = jai_constants.updating and
((nvl(pr_old.shipment_number, -9999) <>
nvl(pr_new.shipment_number, -9998)) and
pr_new.shipment_number is not null)) then
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.POPULATE_TA

X','4794 update JAI_OM_OE_SO_LINES line_number'||pr_new.line_number);


jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.POPULATE_TA
X','4795 update JAI_OM_OE_SO_LINES shipment_line_number'||pr_new.shipment_number
);
update JAI_OM_OE_SO_LINES
set line_number
= pr_new.line_number,
shipment_line_number = pr_new.shipment_number
where line_id = pr_new.line_id;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.POPULATE_T
AX','4800 before return');
return;
end if;
v_hook := jai_cmn_hook_pkg.oe_lines_insert(pr_new.line_id,
pr_new.org_id,
pr_new.line_type_id,
pr_new.ship_from_org_id,
pr_new.ship_to_org_id,
pr_new.invoice_to_org_id,
pr_new.sold_to_org_id,
pr_new.sold_from_org_id,
pr_new.inventory_item_id,
pr_new.tax_code,
pr_new.price_list_id,
pr_new.source_document_type_id,
pr_new.source_document_line_id,
pr_new.reference_line_id,
pr_new.reference_header_id,
pr_new.salesrep_id,
pr_new.order_source_id,
pr_new.orig_sys_document_ref,
pr_new.orig_sys_line_ref);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.POPULATE_TAX'
,'4824 v_hook '||v_hook);
IF v_hook = 'FALSE' THEN
RETURN;
END IF;
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
'** START OF POPULATE_TAX ~ ' ||
TO_CHAR(SYSDATE, 'dd/mm/rrrr hh24:mi:ss'));
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' Header ID ~ Line ID :' || TO_CHAR(pr_new.header_id) ||
' ~ ' || TO_CHAR(pr_new.line_id));
END IF;
IF pv_action = jai_constants.updating AND
pr_new.inventory_item_id <> pr_old.inventory_item_id THEN
DELETE JAI_OM_OE_SO_LINES WHERE line_id = pr_new.line_id;
DELETE JAI_OM_OE_SO_TAXES WHERE line_id = pr_new.line_id;
END IF;

OPEN get_header_info(pr_new.header_id);
FETCH get_header_info
INTO r_get_header_info;
CLOSE get_header_info;
-- check for conversion date
IF r_get_header_info.conv_date IS NULL THEN
r_get_header_info.conv_date := r_get_header_info.date_ordered;
END IF;
IF pr_new.item_type_code = 'STANDARD' AND
((pr_new.reference_line_id IS NOT NULL OR
pr_new.line_category_code = 'RETURN') AND
pr_new.return_context IS NOT NULL) AND
NVL(pr_new.SOURCE_DOCUMENT_TYPE_ID, 0) <> 2 THEN
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
' Returning at STANDARD , RETURN, pr_new.SOURCE_DOCUMENT
_TYPE_ID');
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
'** END OF POPULATE_TAX ~ ' ||
TO_CHAR(SYSDATE, 'dd/mm/rrrr hh24:mi:ss'));
END IF;
RETURN;
END IF;
OPEN Get_Order_Source_Type(pr_new.SOURCE_DOCUMENT_TYPE_ID);
FETCH Get_Order_Source_Type
INTO V_Order_Source_Type;
CLOSE Get_Order_Source_Type;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.POPULATE_TAX'
,'4882 pr_new.SPLIT_FROM_LINE_ID '||pr_new.SPLIT_FROM_LINE_ID);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.POPULATE_TAX'
,'4883 pr_new.SOURCE_DOCUMENT_TYPE_ID '||pr_new.SOURCE_DOCUMENT_TYPE_ID);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.POPULATE_TAX'
,'4884 pr_new.SOURCE_DOCUMENT_LINE_ID '||pr_new.SOURCE_DOCUMENT_LINE_ID);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.POPULATE_TAX'
,'4885 V_Order_Source_Type '||V_Order_Source_Type);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.POPULATE_TAX'
,'4886 pr_new.LINE_CATEGORY_CODE '||pr_new.LINE_CATEGORY_CODE);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.POPULATE_TAX'
,'4887 pr_new.item_type_code '||pr_new.item_type_code);
IF (pr_new.SPLIT_FROM_LINE_ID IS NULL AND
pr_new.SOURCE_DOCUMENT_TYPE_ID IS NOT NULL AND
pr_new.SOURCE_DOCUMENT_LINE_ID IS NOT NULL AND
V_Order_Source_Type = 'Copy') THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.POPULATE_TA
X','4895 before call to procedure copy_source_order');
/************ Scenario 1. Copy Source Order ********************/
copy_source_order(pr_new_line
=> pr_new,
p_header_info
=> r_get_header_info,
p_return_code
=> pv_return_code,

p_return_message
=> pv_return_message);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.POPULATE_TA
X','4901 after call to procedure copy_source_order');
if (pv_return_code <> jai_constants.successful) then
return;
end if;
ELSE
IF pr_new.SPLIT_FROM_LINE_ID IS NOT NULL AND
pr_new.LINE_CATEGORY_CODE <> 'RETURN' THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.POPULATE_
TAX','4911 before call to procedure copy_split_line');
/************ Scenario 2. Copy Split Lines ********************/
copy_split_line(pr_order_line
=> pr_new);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.POPULATE_
TAX','4914 after the call to procedure copy_split_line');
ELSE
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.POPULATE_
TAX','4917 before call to procedure create_normal_order');
/************ Scenario 3. Normal Creation ********************/
create_normal_order(pr_order_line
=> pr_new,
pr_old_line
=> pr_old,
pr_header_info
=> r_get_header_info,
p_return_code
=> pv_return_code,
p_return_message
=> pv_return_message);
-- Added parameters p_return_code ,p_return_message
for bug 1809368
9
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.POPULATE_T
AX','4922 after the call to procedure create_normal_order');
END IF;
END IF;
if upper(pr_new.item_type_code) = 'CONFIG' then
-- commented IF pr_new.SPLIT_FROM_LINE_ID IS NULL AND for bug 17505816
-- IF pr_new.SPLIT_FROM_LINE_ID IS NULL AND
IF pr_new.LINE_CATEGORY_CODE <> 'RETURN' THEN
/************ Scenario 4. Item Config ********************/
process_config(pr_order_line => pr_new);
END IF;
end if;
-- commented out by zhiwei.xin for Trigger Replacement bug #15968958 on 20-D
ec-2012 begin
/***** order level validation *****/
/*order_line_validation(p_rec_old
=> pr_old,
p_rec_new
=> pr_new,
p_action
=> pv_action,
px_return_code
=> pv_return_code,
px_return_message => pv_return_message);*/
-- commented out by zhiwei.xin for Trigger Replacement bug #15968958 on 20-D
ec-2012 end.
IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,

'** SUCCESSFUL END OF POPULATE_TAX ~ ' ||


TO_CHAR(SYSDATE, 'DD/mm/rrrr hh24:mi:ss'));
FND_LOG.STRING(G_LEVEL_STATEMENT,
G_MODULE_NAME || v_api_name,
'Header ID ~ Line ID :' ||
TO_CHAR(pr_new.header_id) || ' ~ ' ||
TO_CHAR(pr_new.line_id));
END IF;
IF (G_LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_PROCEDURE,
G_MODULE_NAME || v_api_name || '.END',
G_PKG_NAME || ': ' || v_api_name || '()-' ||
' RETURN_CODE = ' || pv_return_code);
END IF;
EXCEPTION
WHEN OTHERS THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.POPULATE_TA
X','4966 Exception occured in POPULATE_TAX procedure sqlcode '||sqlcode||', sqle
rrm '||sqlerrm);
IF (G_LEVEL_ERROR >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_ERROR,
G_MODULE_NAME || v_api_name,
'Header ID ~ Line ID :' ||
TO_CHAR(pr_new.header_id) || ' ~ ' ||
TO_CHAR(pr_new.line_id));
FND_LOG.STRING(G_LEVEL_ERROR,
G_MODULE_NAME || v_api_name,
'Error :' || SQLERRM);
FND_LOG.STRING(G_LEVEL_ERROR,
G_MODULE_NAME || v_api_name,
'** Error END OF POPULATE_TAX ~ ' ||
TO_CHAR(SYSDATE, 'DD/mm/rrrr hh24:mi:ss'));
END IF;
Pv_return_code
:= jai_constants.unexpected_error;
Pv_return_message := 'Encountered an error in JAI_OM_TAX_PROCESSING_PKG.PO
PULATE_TAX ' ||
substr(sqlerrm, 1, 1900);
IF (G_LEVEL_UNEXPECTED >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_UNEXPECTED,
G_MODULE_NAME || v_api_name,
SQLERRM);
END IF;
END POPULATE_TAX;
/*
REM +======================================================================+
REM NAME
UPDATE_TAX
REM
REM DESCRIPTION Called from procdure JAI_TAX_PROCESSING_PKG
REM
REM NOTES
Come from procdure JAI_OE_OLA_TRIGGER_PKG.ARU_T1
REM
REM +======================================================================+
*/
PROCEDURE UPDATE_TAX(pr_old
t_rec%type,
pr_new
t_rec%type,

pv_action
varchar2,
pv_return_code
out nocopy varchar2,
pv_return_message out nocopy varchar2) IS
v_api_name CONSTANT VARCHAR2(30) := 'UPDATE_TAX';
v_row_id
ROWID;
v_line_id
NUMBER;
v_header_id
NUMBER;
v_warehouse_id
NUMBER;
v_quantity
NUMBER;
v_last_update_date
DATE;
v_last_updated_by
NUMBER;
v_last_update_login
NUMBER;
v_line_amount
NUMBER;
v_inventory_item_id
NUMBER;
v_uom_code
VARCHAR2(3);
v_ship_to_site_use_id
NUMBER;
v_selling_price
NUMBER;
v_old_assessable_value
NUMBER;
v_line_tax_amount
NUMBER;
v_assessable_amount
NUMBER;
v_ato_line_amount
NUMBER;
v_date_ordered
DATE;
v_assessable_value
NUMBER;
v_org_id
NUMBER;
v_set_of_books_id
NUMBER;
v_conv_type_code
VARCHAR2(30);
v_conv_rate
NUMBER;
v_conv_date
DATE;
v_conv_factor
NUMBER;
v_old_quantity
NUMBER;
v_price_list_id
NUMBER;
v_customer_id
NUMBER;
v_address_id
NUMBER;
ln_inventory_item_id
NUMBER;
ln_line_id
NUMBER;
l_func_curr_det jai_plsql_cache_pkg.func_curr_details;
CURSOR JAI_OM_OE_SO_LINES_cur(p_line_id NUMBER) IS
SELECT quantity,
assessable_value,
excise_exempt_type,
excise_exempt_refno,
vat_reversal_price
FROM JAI_OM_OE_SO_LINES
WHERE line_id = p_line_id;
CURSOR c_ja_in_rma_lines(p_line_id NUMBER) IS
SELECT quantity, assessable_value
FROM JAI_OM_OE_RMA_LINES
WHERE rma_line_id = p_line_id;
CURSOR bind_cur(p_header_id NUMBER) IS
SELECT org_id,
ROWID,
TRANSACTIONAL_CURR_CODE,
conversion_type_code,
conversion_rate,
CONVERSION_RATE_DATE,
SOLD_TO_ORG_ID,

price_list_id,
NVL(ORDERED_DATE, creation_date)
FROM OE_ORDER_HEADERS_ALL
WHERE header_id = p_header_id;
CURSOR address_cur(p_ship_to_org_id IN NUMBER) IS
SELECT NVL(cust_acct_site_id, 0) address_id
FROM HZ_CUST_SITE_USES_ALL A
WHERE A.site_use_id = p_ship_to_org_id;
v_currency_code

gl_sets_of_books.currency_code%TYPE;

v_excise_exempt_type varchar2(60);
v_excise_exempt_refno varchar2(30);
Cursor c_get_loc_record is
select selling_price, assessable_value
from JAI_OM_OE_SO_LINES
where header_id = pr_new.header_id
and line_id = pr_new.line_id;
v_loc_selling_price
Number;
v_loc_assessable_value Number;
ln_vat_assessable_value JAI_OM_OE_SO_LINES.VAT_ASSESSABLE_VALUE%TYPE;
ln_vat_reversal_price JAI_OM_OE_SO_LINES.vat_reversal_price%TYPE;
ln_ordered_qty
NUMBER;
PROCEDURE calc_price_tax_for_config_item(p_header_id number,
p_line_id number) is
CURSOR c_get_line_tax_amt is
SELECT line_amount,
tax_amount,
selling_price,
assessable_value,
decode(quantity, 0, 1, quantity) quantity,
vat_assessable_value
FROM JAI_OM_OE_SO_LINES
WHERE header_id = p_header_id
AND shipment_schedule_line_id = pr_new.ato_line_id
AND line_id <> p_line_id;
BEGIN
v_selling_price
v_assessable_value
ln_vat_assessable_value
v_ato_line_amount

:=
:=
:=
:=

0;
0;
0;
0;

IF nvl(pr_new.ordered_quantity, 0) = 0 THEN
ln_ordered_qty := 1;
ELSE
ln_ordered_qty := pr_new.ordered_quantity;
END IF;
FOR so_lines_rec in c_get_line_tax_amt LOOP
v_ato_line_amount := NVL(v_ato_line_amount, 0) +
NVL(so_lines_rec.line_amount, 0);
v_selling_price := NVL(v_selling_price, 0) +

((NVL(so_lines_rec.selling_price, 0) *
so_lines_rec.quantity) / ln_ordered_qty);
v_assessable_value := NVL(v_assessable_value, 0) +
((NVL(so_lines_rec.assessable_value,
so_lines_rec.selling_price) *
so_lines_rec.quantity) / ln_ordered_qty);
ln_vat_assessable_value := NVL(ln_vat_assessable_value, 0) +
((NVL(so_lines_rec.vat_assessable_value,
so_lines_rec.selling_price) *
so_lines_rec.quantity) / ln_ordered_qty);
END LOOP;
END;
PROCEDURE get_config_item(p_line_id
OUT NOCOPY NUMBER,
p_inventory_item_id OUT NOCOPY NUMBER) IS
PRAGMA AUTONOMOUS_TRANSACTION; --added for bug#16341712
CURSOR
SELECT
FROM
WHERE
and
and

cur_get_line_id IS
line_id, inventory_item_id
oe_order_lines_all
header_id = pr_new.Header_id
top_model_line_id = pr_new.top_model_line_id
item_type_code = 'CONFIG';

BEGIN
OPEN cur_get_line_id;
FETCH cur_get_line_id
INTO p_line_id, p_inventory_item_id;
CLOSE cur_get_line_id;
END get_config_item;
BEGIN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.UPDATE_TAX','51
62 begin of UPDATE_TAX procedure');
/* ***************************************************************************
***************************
Change History
1. 24/May/2013 mmurtuza for bug 16804271
issue: TAX GETTING CALCULATED AFTER 180 DAYS ALSO IN RMA ORDERS
Fix: Added parameter v_warehouse_id while calling jai_om_tax_pkg.calcul
ate_ato_taxes
********************************************************************************
***********************/
IF (G_LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_PROCEDURE,
G_MODULE_NAME || v_api_name || '.BEGIN',
G_PKG_NAME || ': ' || v_api_name || '()+');
END IF;
pv_return_code := jai_constants.successful;
v_line_id
v_header_id
v_warehouse_id

:= pr_new.line_id;
:= pr_new.header_id;
:= pr_new.SHIP_FROM_ORG_ID;

v_quantity
v_last_update_date
v_last_updated_by
v_last_update_login
v_line_amount

:=
:=
:=
:=
:=

v_inventory_item_id
v_uom_code
v_ship_to_site_use_id
v_selling_price
v_old_assessable_value
v_ato_line_amount

:=
:=
:=
:=
:=
:=

NVL(pr_new.ordered_quantity, 0);
pr_new.last_update_date;
pr_new.last_updated_by;
pr_new.last_update_login;
NVL(v_quantity, 0) *
NVL(pr_new.UNIT_selling_price, 0);
pr_new.inventory_item_id;
pr_new.ORDER_QUANTITY_UOM;
NVL(pr_new.SHIP_TO_ORG_ID, 0);
pr_new.UNIT_SELLING_PRICE;
0;
0;

-- the following if condition " if pr_new.LINE_CATEGORY_CODE = 'RETURN' t


hen " added by sriram
-- When a Legacy return order is created and line saved and if quantity is c
hanged , this trigger was throwing up
-- an exception - DIVIDE BY ZERO .The reason for this is that the cursor whi
ch fetches the old quantity and old
-- assessable value fetched the values from the JAI_OM_OE_SO_LINES table. Fo
r a return order , this is not relevant
-- as the JAI_OM_OE_SO_LINES has no records for a return order and instead r
ecords are present in the JAI_OM_OE_RMA_LINES
-- table.
-- code added by sriram includes adding the if statement below , adding the
elsif condition and opening the cursor
-- c_ja_in_rma_lines . This cursor definition also has been added by sriram
.
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.UPDATE_TAX','
5203 pr_new.LINE_CATEGORY_CODE '||pr_new.LINE_CATEGORY_CODE);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.UPDATE_TAX','
5204 v_line_id '||v_line_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.UPDATE_TAX','
5205 v_header_id '||v_header_id);
if pr_new.LINE_CATEGORY_CODE = 'RETURN' then
OPEN c_ja_in_rma_lines(v_line_id);
FETCH c_ja_in_rma_lines
INTO v_old_quantity, v_old_assessable_value;
CLOSE c_ja_in_rma_lines;
else
OPEN JAI_OM_OE_SO_LINES_cur(v_line_id);
FETCH JAI_OM_OE_SO_LINES_cur
INTO v_old_quantity,
v_old_assessable_value,
v_excise_exempt_type,
v_excise_exempt_refno,
ln_vat_reversal_price;
CLOSE JAI_OM_OE_SO_LINES_cur;
end if;
OPEN Bind_Cur(v_header_id);
FETCH Bind_Cur
INTO v_org_id,
v_row_id,
v_currency_code,
v_conv_type_code,
v_conv_rate,
v_conv_date,
v_customer_id,

v_price_list_id,
v_date_ordered;
CLOSE Bind_Cur;
IF v_conv_date IS NULL THEN
v_conv_date := v_date_ordered;
END IF;
/*
Removed the cursor set_of_books_cur and added the following check
using plsql caching for performance issues reported.
*/
l_func_curr_det := jai_plsql_cache_pkg.return_sob_curr(p_org_id => v_wareh
ouse_id);
v_set_of_books_id := l_func_curr_det.ledger_id;
v_conv_factor := jai_cmn_utils_pkg.currency_conversion(v_set_of_books_id,
v_currency_code,
v_conv_date,
v_conv_type_code,
v_conv_rate);
OPEN address_cur(v_ship_to_site_use_id);
FETCH address_cur
INTO v_address_id;
CLOSE address_cur;
--The Logic of Fetching the Assessable Value is written in the Function jai_
om_utils_pkg.get_oe_assessable_value.
v_assessable_value := jai_om_utils_pkg.get_oe_assessable_value(p_customer_id
=> v_customer_id,
p_ship_to_sit
e_use_id => v_ship_to_site_use_id,
p_inventory_i
tem_id => v_inventory_item_id,
p_uom_code
=> v_uom_code,
p_default_pri
ce
=> pr_new.unit_selling_price,
p_ass_value_d
ate
=> v_date_ordered,
p_sob_id
=> v_set_of_books_id,
p_curr_conv_c
ode
=> v_conv_type_code,
p_conv_rate
=> v_conv_factor);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.UPDATE_TAX','5
267 v_assessable_value '||v_assessable_value);
ln_vat_assessable_value := jai_general_pkg.ja_in_vat_assessable_value(p_part
=> v_customer_id,
p_part
y_site_id
=> v_ship_to_site_use_id,
p_inve
ntory_item_id => v_inventory_item_id,
p_uom_
code
=> v_uom_code,
p_defa
y_id

ult_price

=> pr_new.unit_selling_price,

value_date

=> v_date_ordered,

y_type

=> 'C');

p_ass_
p_part
ln_vat_assessable_value := nvl(ln_vat_assessable_value, 0) *
NVL(v_quantity, 0);
ln_vat_reversal_price := nvl(ln_vat_reversal_price, 0) *
NVL(v_quantity, 0);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.UPDATE_TAX','5
281 ln_vat_assessable_value '||ln_vat_assessable_value);
if NVL(pr_new.item_type_code, '$$$') = 'CONFIG' then
open c_get_loc_record;
fetch c_get_loc_record
into v_loc_selling_price, v_loc_assessable_value;
close c_get_loc_record;
v_assessable_value := v_loc_assessable_value;
else
/*
Functional Description:During partial shipment, if the assessable price list setup has been remov
ed after booking an order then
during the excise duty recalculation, the assessable value (which would be
found as null in the setup ) should be taken from the
JAI_OM_OE_SO_LINES table and if this too happens to be null then only shou
ld it be assigned as nvl(pr_new.unit_selling_price).
Technical Description:Check whether the assessable value is null in the table JAI_OM_OE_SO_LINES
IF
no then assign this value to the v_assessable_value variable
ELSE
Assign the assign the nvl(pr_new.unit_selling_price) to the v_assessable_v
alue variable.
*/
IF NVL(pr_new.Ordered_Quantity, 0) <> NVL(pr_old.Ordered_quantity, 0) AND
pr_new.flow_status_code = 'AWAITING_SHIPPING' THEN
/*
only when there is a partial shipment , do the calculation of assessable
value based on
price of the actual price list.
*/
DECLARE
CURSOR rec_get_assessable_value IS
SELECT assessable_value
FROM JAI_OM_OE_SO_LINES
WHERE line_id = v_line_id;
cur_rec_get_assessable_value rec_get_assessable_value%ROWTYPE;
BEGIN
pv_return_code := jai_constants.successful;

if v_assessable_value IS NOT NULL THEN


OPEN rec_get_assessable_value;
FETCH rec_get_assessable_value
INTO cur_rec_get_assessable_value;
IF cur_rec_get_assessable_value.assessable_value IS NOT NULL THEN
v_assessable_value := cur_rec_get_assessable_value.assessable_valu
e;
ELSE
v_assessable_value := NVL(pr_new.UNIT_SELLING_PRICE, 0);
END IF;
CLOSE rec_get_assessable_value;
end if;
END;
end if;
end if;
v_assessable_amount := NVL(v_assessable_value, 0) * NVL(v_quantity, 0);
IF v_assessable_amount = 0 THEN
v_assessable_amount := NVL(v_line_Amount, 0);
END IF;
if NVL(v_line_Amount, 0) = 0 then
v_line_amount := v_quantity * v_loc_selling_price;
end if;
v_line_tax_amount := NVL(v_line_amount, 0);
if v_excise_exempt_refno is not null and
v_excise_exempt_type is not null then
v_assessable_amount := 0;
end if;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.UPDATE_TAX','
5362 pr_new.item_type_code '||pr_new.item_type_code);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.UPDATE_TAX','
5363 ln_vat_assessable_value '||ln_vat_assessable_value);
IF upper(pr_new.item_type_code) = 'CONFIG' AND
pr_new.line_category_code <> 'RETURN' THEN
calc_price_tax_for_config_item(pr_new.header_id, pr_new.line_id);
END IF;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.UPDATE_TAX','
5369 before call to jai_om_tax_pkg.calculate_ato_taxes v_header_id '||v_header_i
d
||'v_line_id '||v_line_id
||'v_assessable_amount '||v_assessable_a
mount
||'v_line_tax_amount '||v_line_tax_amoun
t
||'v_warehouse_id '||v_warehouse_id);
jai_om_tax_pkg.calculate_ato_taxes('OE_LINES_UPDATE',
NULL,

v_header_id,
v_line_id,
v_assessable_amount,
v_line_tax_amount,
v_conv_factor,
v_inventory_item_id,
NVL(v_old_quantity, 0),
v_quantity,
v_uom_code,
NULL,
NULL,
NULL,
NULL,
v_last_update_date,
v_last_updated_by,
v_last_update_login,
ln_vat_assessable_value,
ln_vat_reversal_price,
v_war
ehouse_id); /*Added warehouse id by mmurtuza for bug 16804271*/
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.UPDATE_TAX','
5397 pr_new.line_category_code '||pr_new.line_category_code);
IF pr_new.line_category_code = 'ORDER' THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.UPDATE_TAX',
'5400 UPDATE jai_om_oe_so_lines quantity '||v_quantity
||'v_assessable_value '||v_assessable_v
alue
||'v_selling_price '||v_selling_price
||'ln_vat_assessable_value '||ln_vat_as
sessable_value
||'v_line_tax_amount '||v_line_tax_amou
nt
||'v_line_id '||v_line_id);
UPDATE jai_om_oe_so_lines
SET quantity
= v_quantity,
unit_code
= v_uom_code,
selling_price
= v_selling_price,
assessable_value
= nvl(v_assessable_value, v_selling_price),
vat_assessable_value = nvl(ln_vat_assessable_value, 0),
tax_amount
= NVL(v_line_tax_amount, 0),
line_amount
= v_line_amount,
line_tot_amount
= v_line_amount +
NVL(v_line_tax_amount, 0),
last_update_date
= v_last_update_date,
last_updated_by
= v_last_updated_by,
last_update_login
= v_last_update_login
WHERE line_id = v_line_id;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.UPDATE_TAX'
,'5421 pr_new.item_type_code '||pr_new.item_type_code);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.UPDATE_TAX'
,'5422 pr_new.unit_selling_price '||pr_new.unit_selling_price);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.UPDATE_TAX'
,'5423 pr_old.unit_selling_price '||pr_old.unit_selling_price);
IF (upper(pr_new.item_type_code) <> 'CONFIG' AND
pr_new.unit_selling_price <> pr_old.unit_selling_price) THEN

get_config_item(ln_line_id, ln_inventory_item_id);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.UPDATE_TA
X','5430 ln_line_id '||ln_line_id);
IF ln_line_id is not null THEN
calc_price_tax_for_config_item(pr_new.header_id, ln_line_id);
v_line_tax_amount := NVL(v_ato_line_amount, 0);
v_assessable_amount := NVL(v_assessable_value, 0) *
NVL(v_quantity, 0);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.UPDATE_
TAX','5437 before call to jai_om_tax_pkg.calculate_ato_taxes v_header_id '||v_he
ader_id
||'ln_line_id '||ln_line_id
||'v_assessable_amount '||v_assessable_amount
||'v_line_tax_amount '||v_line_tax_amount
||'v_quantity '||v_quantity
||'ln_vat_assessable_value '||ln_vat_assessable_value
||'ln_vat_reversal_price '||ln_vat_reversal_price
||'v_warehouse_id '||v_warehouse_id);
jai_om_tax_pkg.calculate_ato_taxes('OE_LINES_UPDATE',
NULL,
v_header_id,
ln_line_id,
v_assessable_amount,
v_line_tax_amount,
v_conv_factor,
ln_inventory_item_id,
NVL(v_quantity, 0),
v_quantity,
v_uom_code,
NULL,
NULL,
NULL,
NULL,
v_last_update_date,
v_last_updated_by,
v_last_update_login,
ln_vat_assessable_value,
ln_vat_reversal_price,
v_warehouse_id); /*Added warehouse id by mmurtuza for bug 16804271*/
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.UPDATE_
TAX','5468 UPDATE JAI_OM_OE_SO_LINES v_quantity'||v_quantity
||', v_selling_price '||v_selling_
price
||', v_assessable_value '||v_asses
sable_value
||', ln_vat_assessable_value '||ln
_vat_assessable_value

||', v_ato_line_amount '||v_ato_li


ne_amount
||', v_line_tax_amount '||v_line_t
ax_amount
||', ln_line_id '||ln_line_id);
UPDATE JAI_OM_OE_SO_LINES
SET quantity
unit_code
selling_price
assessable_value
vat_assessable_value
tax_amount
line_amount
line_tot_amount

=
=
=
=
=
=
=
=

last_update_date
=
last_updated_by
=
last_update_login
=
WHERE line_id = ln_line_id;

v_quantity,
v_uom_code,
v_selling_price,
nvl(v_assessable_value,
v_selling_price),
nvl(ln_vat_assessable_value, 0),
NVL(v_line_tax_amount, 0),
v_ato_line_amount,
v_ato_line_amount +
NVL(v_line_tax_amount, 0),
v_last_update_date,
v_last_updated_by,
v_last_update_login

END IF;
END IF;
ELSIF pr_new.line_category_code = 'RETURN' THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.UPDATE_TAX'
,'5496 UPDATE JAI_OM_OE_SO_LINES v_quantity'||v_quantity
||', v_selling_price '||v_selling_pric
e
||', v_assessable_value '||v_assessabl
e_value
||', v_line_tax_amount '||v_line_tax_a
mount
||', v_inventory_item_id '||v_inventor
y_item_id
||', v_line_id '||v_line_id);
UPDATE jai_om_oe_rma_lines
SET quantity
= v_quantity,
uom
= v_uom_code,
selling_price
= v_selling_price,
assessable_value = v_assessable_value,
tax_amount
= NVL(v_line_tax_amount, 0),
inventory_item_id = v_inventory_item_id,
last_update_date = v_last_update_date,
last_updated_by = v_last_updated_by,
last_update_login = v_last_update_login
WHERE rma_line_id = v_line_id;
END IF;
IF (G_LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_PROCEDURE,
G_MODULE_NAME || v_api_name || '.END',
G_PKG_NAME || ': ' || v_api_name || '()-' ||
' RETURN_CODE = ' || pv_return_code);
END IF;
EXCEPTION
WHEN OTHERS THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.UPDATE_TAX'

,'5524 Exception occured in UPDATE_TAX procedure sqlcode '||sqlcode||', sqlerrm


'||sqlerrm);
Pv_return_code
:= jai_constants.unexpected_error;
Pv_return_message := 'Encountered an error in JAI_OM_TAX_PROCESSING_PKG.UP
DATE_TAX ' ||
substr(sqlerrm, 1, 1900);
IF (G_LEVEL_UNEXPECTED >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_UNEXPECTED,
G_MODULE_NAME || v_api_name,
SQLERRM);
END IF;
END UPDATE_TAX;
/*
REM +======================================================================+
REM NAME
DEFAULT_TAX
REM
REM DESCRIPTION Called from procdure JAI_TAX_PROCESSING_PKG
REM
REM NOTES
Come from procdure JAI_OE_OLA_TRIGGER_PKG.BRIU_T1
REM
REM +======================================================================+
*/
PROCEDURE DEFAULT_TAX(pr_old
t_rec%type,
pr_new
t_rec%type,
pv_action
varchar2,
pv_return_code
out nocopy varchar2,
pv_return_message out nocopy varchar2) IS
v_exist_ship NUMBER;
v_api_name CONSTANT VARCHAR2(30) := 'DEFAULT_TAX';
CURSOR get_count IS
SELECT COUNT(*)
FROM JAI_OM_WSH_LINES_ALL
WHERE order_line_id = pr_new.reference_line_id;
/*
get the delivery_detail_id from wsh_delivery_details table
*/
CURSOR cur_get_delivery_detail_id IS
SELECT delivery_detail_id
FROM wsh_delivery_details
WHERE source_header_id = pr_new.reference_header_id
AND source_line_id = pr_new.reference_line_id
AND inventory_item_id = pr_new.inventory_item_id
AND shipped_quantity IS NOT NULL;
l_new_delivery_detail_id WSH_DELIVERY_DETAILS.DELIVERY_DETAIL_ID%TYPE;
Cursor c_ordered_date_cur is
select ordered_date
from oe_order_headers_all
where header_id = pr_new.header_id;
-- following cursor is used to get the ship confirm date based on the delive
ry detail id
cursor c_confirmed_date(p_delivery_Detail_id Number) is

select confirm_date
FROM wsh_delivery_details
wdd,
wsh_delivery_assignments wda,
wsh_new_deliveries
wnd
WHERE wdd.delivery_detail_id = (p_delivery_Detail_id)
AND wda.delivery_detail_id = wdd.delivery_detail_id
AND wnd.delivery_id = wda.delivery_id;
Cursor c_hr_organizations_cur is
SELECT excise_return_days, sales_return_days
FROM JAI_CMN_INVENTORY_ORGS
WHERE organization_id = pr_new.ship_from_org_id
AND location_id = 0;
Cursor cur_chk_item_dtls(cp_organization_id IN NUMBER,
cp_inventory_item_id IN NUMBER) IS
SELECT 1
FROM JAI_RGM_ITM_REGNS
WHERE ORGANIZATION_ID = cp_organization_id
AND inventory_item_id = cp_inventory_item_id;
ln_organization_id NUMBER;
ln_inventory_item_id NUMBER;
ln_item_exists
NUMBER;
v_ordered_Date
v_confirm_date
v_excise_return_days
v_sales_return_days

oe_order_headers_all.ordered_date%type;
wsh_new_deliveries.confirm_date%type;
Number;
Number;

CURSOR get_order_source_type(cp_source_document_type_id NUMBER) IS


SELECT name
FROM oe_order_sources
WHERE order_source_id = cp_source_document_type_id;
V_Order_Source_Type OE_ORDER_SOURCES.NAME%TYPE;
cursor c_rma_line_dtls(cp_rma_line_id in number) is
select delivery_detail_id,
nvl(allow_excise_credit_flag, 'N') allow_excise_credit_flag,
nvl(allow_sales_credit_flag, 'N') allow_sales_credit_flag,
rate_per_unit,
excise_duty_rate
from JAI_OM_OE_RMA_LINES
where rma_line_id = cp_rma_line_id;
ln_delivery_detail_id
lv_allow_excise_flag
lv_allow_sales_flag
ln_excise_duty_per_unit
ln_excise_duty_rate

number;
varchar2(1);
varchar2(1);
number;
number;

/*Start additions by mmurtuza for bug 18373353*/


CURSOR cur_ato_delivery_detail_id
IS
SELECT
delivery_detail_id
FROM
wsh_delivery_details
WHERE

source_header_id = pr_new.reference_header_id AND


shipped_quantity IS NOT NULL
AND
top_model_line_id IS NOT NULL and top_model_line_id=pr_new.reference_l
ine_id ;
ln_ato_flag NUMBER := 0 ;
PROCEDURE get_ato_order_flag(pn_ato_flag OUT NOCOPY NUMBER) IS
/*
|| Not able to use column ja_in_so_lines.ato_flag to identify whether the l
ine is ato or not
|| as ato_flag is 'Y' irrespective of sales order type
*/
PRAGMA AUTONOMOUS_TRANSACTION;
CURSOR c_is_ato_order IS
SELECT
1
FROM
oe_order_lines_all
WHERE
line_id = pr_new.reference_line_id
AND
top_model_line_id is not NULL;
BEGIN
OPEN c_is_ato_order ;
FETCH c_is_ato_order INTO pn_ato_flag ;
CLOSE c_is_ato_order ;
END get_ato_order_flag ;
/*End additions by mmurtuza for bug 18373353*/
BEGIN
/* ***************************************************************************
***************************
Change History
1. 19-Mar-2014 mmurtuza for bug 18373353
Issue: WHEN DOINIG RMA, KIT ITEM IS NOT POPULATING IN INDIA LOCALIZATION SCRE
EEN
Fix: Ported the fix of bug 9118233. Added PROCEDURE get_ato_order_flag ans us
ed it in procedure
2. 25-Mar-2014 mmurtuza for bug 18439425
Issue:
IN CASE OF RMA ITEM LINE NOT DISPLAYED ON SALES ORDER INDIA LOCA
LIZATION FORM
Fix: Added parameter p_action while calling procedure jai_om_rma_pkg.default_
taxes_onto_line
********************************************************************************
***********************/
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT_TAX',
'5634 begin of DEFAULT_TAX procedure');
IF (G_LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_PROCEDURE,
G_MODULE_NAME || v_api_name || '.BEGIN',
G_PKG_NAME || ': ' || v_api_name || '()+');

END IF;
pv_return_code := jai_constants.successful;
OPEN Get_Count;
FETCH Get_Count
INTO v_exist_ship;
CLOSE Get_Count;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT_TAX',
'5647 v_exist_ship '||v_exist_ship);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT_TAX',
'5649 pr_new.item_type_code '||pr_new.item_type_code
||', pr_new.ato_line_id '||pr_new.ato
_line_id
||', pv_action '||pv_action
||', pr_new.SHIP_from_ORG_ID '||pr_ne
w.SHIP_from_ORG_ID
||', pr_new.inventory_item_id '||pr_n
ew.inventory_item_id);
If pr_new.item_type_code = 'CONFIG' and pr_new.ato_line_id is not null AND
pv_action = jai_constants.inserting THEN
OPEN cur_chk_item_dtls(pr_new.SHIP_from_ORG_ID,
pr_new.inventory_item_id);
FETCH cur_chk_item_dtls
INTO ln_item_exists;
CLOSE cur_chk_item_dtls;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT_TAX
','5662 ln_item_exists '||ln_item_exists);
IF nvl(ln_item_exists, 0) <> 1 THEN
/*
* The firing table is on OE_ORDER_LINES_ALL. The firing table accessing
in the
* trigger in the enven of UPDATING will cause table mutating error. So
use an
* AUTONOMOUS transaction to resolve the issue.
*/
Get_Model_line_Detail(pn_header_id
pn_line_id
xn_organization_id
xn_inventory_item_id

=>
=>
=>
=>

pr_new.header_id,
pr_new.ato_line_id,
ln_organization_id,
ln_inventory_item_id);

--this is for excise attributes


jai_inv_items_pkg.copy_items(pn_organization_id
from_ORG_ID,
pn_inventory_item_id
tory_item_id,
pn_source_organization_id
ion_id,
pn_source_inventory_item_id
_item_id);
jai_inv_items_pkg.copy_items(pn_organization_id
from_ORG_ID,
pn_inventory_item_id
tory_item_id,
pn_source_organization_id

=> pr_new.SHIP_
=> pr_new.inven
=> ln_organizat
=> ln_inventory
=> pr_new.SHIP_
=> pr_new.inven
=> ln_organizat

ion_id,
pn_source_inventory_item_id => ln_inventory
_item_id,
pn_regime_code

=> jai_constant

s.vat_regime);
END IF;
END IF;
get_ato_order_flag( pn_ato_flag => ln_ato_flag ) ; /*Added by mmurtuza f
or bug 18373353*/
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT_TAX',
'5691 ln_ato_flag '||ln_ato_flag);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT_TAX',
'5691 v_exist_ship '||v_exist_ship);
IF nvl(ln_ato_flag, 0) = 0 THEN /*Added if by mmurtuza for bug 18373353
*/
IF NVL(v_exist_ship, 0) = 0 THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT_TA
X','5693 Before Return statement');
RETURN;
END IF;
END IF;
/*
Before inserting a record in the oe_order_lines_all table for a return ord
er, check if the delivery detail_id i.e pr_new.attribute2 is null.
IF yes then
1. pick up the delivery_detail_id from the wsh_delivery_details table for
records corresponding to the reference_header_id and
reference_line_id in this table and populate the pr_new.attibute2 dff
field
2.Set the pr_new.attribute3 = 'Y' and pr_new.attribute4 = 'Y'
3. Populate the context with the following information
if pr_new.return_context
pr_new.Context
---------------------------------------'ORDER'
'Sales Order India'
'INVOICE'
'Invoice India'
'PO'
'Customer PO India'
*/
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT_TAX',
'5712 pv_action '||pv_action
||', pr_new.reference_header_id '||pr_ne
w.reference_header_id);
IF pv_action IN (jai_constants.INSERTING, jai_constants.UPDATING) AND
pr_new.reference_header_id IS NOT NULL THEN
OPEN cur_get_delivery_detail_id;
FETCH cur_get_delivery_detail_id
INTO l_new_delivery_detail_id;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT_T
AX','5720 l_new_delivery_detail_id '||l_new_delivery_detail_id);
/*Added if block by mmurtuza for bug 18373353*/
IF nvl(ln_ato_flag,0) = 1 THEN

IF l_new_delivery_detail_id IS NULL THEN


OPEN cur_ato_delivery_detail_id;
FETCH cur_ato_delivery_detail_id INTO l_new_delivery_detail_id;
CLOSE cur_ato_delivery_detail_id ;
END IF ;
END IF ;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT
_TAX','5881 l_new_delivery_detail_id '||l_new_delivery_detail_id);
/*if cur_get_delivery_detail_id%FOUND then*/
IF l_new_delivery_detail_id IS NOT NULL THEN /*Changed if condition by
mmurtuza for bug 18373353*/
open c_ordered_date_cur;
fetch c_ordered_date_cur
into v_ordered_date;
close c_ordered_date_cur;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT_T
AX','5728 v_ordered_date '||v_ordered_date);
open c_confirmed_date(l_new_delivery_detail_id);
fetch c_confirmed_date
into v_confirm_date;
close c_confirmed_date;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT_T
AX','5734 v_confirm_date '||v_confirm_date);
open c_hr_organizations_cur;
fetch c_hr_organizations_cur
into v_excise_return_days, v_sales_return_days;
close c_hr_organizations_cur;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT_T
AX','5740 v_excise_return_days '||v_excise_return_days
||', v_sales_return_days '||
v_sales_return_days);
ln_delivery_detail_id := l_new_delivery_detail_id;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT_T
AX','ln_delivery_detail_id '||ln_delivery_detail_id
||', v_excise_return_days '||v_excis
e_return_days
||', v_ordered_date '||v_ordered_dat
e
||', v_confirm_date '||v_confirm_dat
e
||', v_sales_return_days '||v_sales_
return_days);
if (v_excise_return_days IS NULL OR
(v_ordered_date - v_confirm_date) <= v_excise_return_days) then
lv_allow_excise_flag := 'Y';
else
lv_allow_excise_flag := 'N';
end if;
if (v_sales_return_days IS NULL OR
(v_ordered_date - v_confirm_date) <= v_sales_return_days) then
lv_allow_sales_flag := 'Y';
else

lv_allow_sales_flag := 'N';
end if;
end if;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT_TAX
','5765 before CLOSE cur_get_delivery_detail_id ');
CLOSE cur_get_delivery_detail_id;
else
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT
_TAX','5770 pr_new.line_id '||pr_new.line_id);
open c_rma_line_dtls(pr_new.line_id);
fetch c_rma_line_dtls
into ln_delivery_detail_id,
lv_allow_excise_flag,
lv_allow_sales_flag,
ln_excise_duty_per_unit,
ln_excise_duty_rate;
close c_rma_line_dtls;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT_TAX
','5779 ln_delivery_detail_id '||ln_delivery_detail_id
||', lv_allow_excise_flag '||lv_a
llow_excise_flag
||', lv_allow_sales_flag '||lv_allow_sales_flag
||', ln_excise_duty_per_unit '||ln_excise_duty_per_unit
||', ln_excise_duty_rate '||ln_excise_duty_rate);
end if;
/* If the v_order_source_type is Copy then this trigger should not insert th
e taxes */
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT_TAX',
'5789 pr_new.SOURCE_DOCUMENT_TYPE_ID '||pr_new.SOURCE_DOCUMENT_TYPE_ID);
OPEN Get_Order_Source_Type(pr_new.SOURCE_DOCUMENT_TYPE_ID);
FETCH Get_Order_Source_Type
INTO V_Order_Source_Type;
CLOSE Get_Order_Source_Type;
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT_TAX',
'5795 pr_new.SPLIT_FROM_LINE_ID '||pr_new.SPLIT_FROM_LINE_ID
||', pr_new.SOURCE_DOCUMENT_TYPE_ID '||
pr_new.SOURCE_DOCUMENT_TYPE_ID
||', pr_new.SOURCE_DOCUMENT_LINE_ID '||
pr_new.SOURCE_DOCUMENT_LINE_ID
||', V_Order_Source_Type '||V_Order_Sou
rce_Type);
IF (pr_new.SPLIT_FROM_LINE_ID IS NULL AND
pr_new.SOURCE_DOCUMENT_TYPE_ID IS NOT NULL AND
pr_new.SOURCE_DOCUMENT_LINE_ID IS NOT NULL AND
V_Order_Source_Type = 'Copy') THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT
_TAX','5803 Before Return statement ');
RETURN;
END IF;

jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT_TAX',
'5807 Before call to jai_om_rma_pkg.default_taxes_onto_line pr_new.header_id '||
pr_new.header_id
||', pr_new.header_id '||pr_new.header_
id
||', pr_new.line_id '||pr_new.line_id
||', pr_new.reference_line_id '||pr_new
.reference_line_id
||', pr_new.line_number '||pr_new.line_
number
||', ln_delivery_detail_id '||ln_delive
ry_detail_id
||', pr_old.ordered_quantity '||pr_old.
ordered_quantity );
jai_om_rma_pkg.default_taxes_onto_line(pr_new.header_id,
pr_new.line_id,
pr_new.inventory_item_id,
pr_new.ship_from_org_id,
pr_new.reference_line_id,
pr_new.reference_customer_trx_line_id
,
pr_new.line_number,
pr_old.return_context,
ln_delivery_detail_id,
lv_allow_excise_flag,
lv_allow_sales_flag,
ln_excise_duty_per_unit,
ln_excise_duty_rate,
pr_old.reference_line_id,
pr_old.reference_customer_trx_line_id
,
pr_old.ordered_quantity,
pr_old.cancelled_quantity,
pr_new.return_context,
pr_new.ordered_quantity,
pr_new.cancelled_quantity,
pr_new.order_quantity_uom,
pr_old.unit_selling_price,
pr_new.unit_selling_price,
pr_new.item_type_code,
NULL,
pr_new.creation_date,
pr_new.created_by,
pr_new.last_update_date,
pr_new.last_updated_by,
pr_new.last_update_login,
pr_new.source_document_type_id,
pr_new.line_category_code,
pv_action /*Added parameter by mmurtuza for bug 18439425*/
);
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT_TAX',
'5849 after call to jai_om_rma_pkg.default_taxes_onto_line ');
IF (G_LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_PROCEDURE,
G_MODULE_NAME || v_api_name || '.END',
G_PKG_NAME || ': ' || v_api_name || '()-' ||
' RETURN_CODE = ' || pv_return_code);

END IF;
EXCEPTION
WHEN OTHERS THEN
jai_cmn_utils_pkg.write_fnd_log_msg('JAI_OM_TAX_PROCESSING_PKG.DEFAULT_TAX
','5858 Exception occured in DEFAULT_TAX procedure sqlcode '||sqlcode||' sqlerrm
'||sqlerrm);
Pv_return_code
:= jai_constants.unexpected_error;
Pv_return_message := 'Encountered an error in JAI_OM_TAX_PROCESSING_PKG.DE
FAULT_TAX ' ||
substr(sqlerrm, 1, 1900);
IF (G_LEVEL_UNEXPECTED >= G_CURRENT_RUNTIME_LEVEL) THEN
FND_LOG.STRING(G_LEVEL_UNEXPECTED,
G_MODULE_NAME || v_api_name,
SQLERRM);
END IF;
END DEFAULT_TAX;
END JAI_OM_TAX_PROCESSING_PKG;
/
COMMIT ;
EXIT ;