880:
881: --sechawla 13-FEB-08 6765119
882: l_current_fa_cost := p_cost;
883:
884: -- SECHAWLA 21-NOV-03 3262519 : update the tax book with residual value as asset cost
885: --------------------------------------- Adjustments begin-------------------------------------------
886:
887: -- p_tax_owner will have a value only if the contract is on direct finance or sales type of lease
888: IF p_tax_owner = 'LESSEE' THEN
886:
887: -- p_tax_owner will have a value only if the contract is on direct finance or sales type of lease
888: IF p_tax_owner = 'LESSEE' THEN
889: IF p_delta_cost <> 0 THEN --SECHAWLA 15-DEC-04 Bug # 4028371 : added this condition
890: --update the tax asset book with residual value as asset cost
891:
892: l_adj_trans_rec.transaction_subtype := 'AMORTIZED';
893: l_adj_asset_hdr_rec.asset_id := p_asset_id;
894: l_adj_asset_hdr_rec.book_type_code := p_tax_book;
1168: -- columns of okx_asset_liens_v
1169:
1170: x_return_status := okl_api.G_RET_STS_SUCCESS;
1171:
1172: -- SECHAWLA 21-NOV-03 3262519 : update the corporate book with residual value as asset cost
1173: --------------------------------------- Adjustments begin-------------------------------------------
1174:
1175: -- p_tax_owner will have a value only if the contract is on direct finance or sales type of lease
1176: IF p_tax_owner IN ('LESSOR','LESSEE') THEN
1174:
1175: -- p_tax_owner will have a value only if the contract is on direct finance or sales type of lease
1176: IF p_tax_owner IN ('LESSOR','LESSEE') THEN
1177: IF p_delta_cost <> 0 THEN --SECHAWLA 15-DEC-04 Bug # 4028371 : added this condition
1178: --update the tax asset book with residual value as asset cost
1179:
1180: l_adj_trans_rec.transaction_subtype := 'AMORTIZED';
1181: l_adj_asset_hdr_rec.asset_id := p_asset_id;
1182: l_adj_asset_hdr_rec.book_type_code := p_book_type_code;
1450: -- columns of okx_asset_liens_v
1451:
1452: x_return_status := okl_api.G_RET_STS_SUCCESS;
1453:
1454: -- SECHAWLA 21-NOV-03 3262519 : update the corporate book with residual value as asset cost
1455: --------------------------------------- Adjustments begin-------------------------------------------
1456:
1457: -- p_tax_owner will have a value only if the contract is on direct finance or sales type of lease
1458: IF p_tax_owner IN ('LESSOR','LESSEE') THEN
1456:
1457: -- p_tax_owner will have a value only if the contract is on direct finance or sales type of lease
1458: IF p_tax_owner IN ('LESSOR','LESSEE') THEN
1459: IF p_delta_cost <> 0 THEN --SECHAWLA 15-DEC-04 Bug # 4028371 : added this condition
1460: --update the tax asset book with residual value as asset cost
1461:
1462: l_adj_trans_rec.transaction_subtype := 'AMORTIZED';
1463: l_adj_asset_hdr_rec.asset_id := p_asset_id;
1464: l_adj_asset_hdr_rec.book_type_code := p_book_type_code;
1685: -- take care of the scenario where tax book cost is more than the corporate book cost
1686: -- 2) full tax book retirement when the corp book is not fully retired but tax book does not
1687: -- have enough cost. This takes care of the scenario where tax book cost is less than the corp book cost
1688: -- SECHAWLA 05-FEB-03 Bug # 2781557
1689: -- Moved the logic to check if the asset was added in the current open period, from individual cost and unit
1690: -- retirement procedures to this procedure.
1691: -- SECHAWLA 11-MAR-03
1692: -- assumed 0 amount for proceeds of sale, if null. Allowed negative values for proceeds of sale
1693: -- SECHAWLA 03-JUN-03 2999419: Use the retirement prorate convention set in Oracle
1692: -- assumed 0 amount for proceeds of sale, if null. Allowed negative values for proceeds of sale
1693: -- SECHAWLA 03-JUN-03 2999419: Use the retirement prorate convention set in Oracle
1694: -- Assets for a particular asset and book, instead of using the constant value "MID-MONTH"
1695: -- RMUNJULU 11-SEP-03 3061751 Added code for SERVICE_K_INTEGRATION
1696: -- SECHAWLA 21-NOV-03 3262519 Update the asset cost with residual value, for DF and Sales lease,
1697: -- before retiring the asset
1698: -- rmunjulu EDAT
1699: -- Added 2 new parameters and Changed code to
1700: -- 1. set date trn occured as quote eff date
1705: -- 6. set trn date as quote eff date to partial untis retirement
1706: -- 7. set trn date as quote eff date to cost retirement
1707: -- rmunjulu EDAT 23-Nov-04 Set back IB End date as sysdate
1708: -- rmunjulu EDAT 10-Jan-05 Pass quote eff date and quote accpt date to adjust/retire proc
1709: -- girao 18-Jan-2005 4106216 NVL the residual value in l_linesfullv_csr
1710: -- SECHAWLA 10-FEB-06 5016156 In case of termination w/o purchase, asset cost should
1711: -- be updated with NIV (not RV), through Off-lease transactions
1712: -- rbruno 04-sep-07 bug 5436987 Adjustment transaction should have amount in functional currency
1713: --
1851: WHERE khr.id = cle.chr_id
1852: AND lkhr.id = khr.id
1853: AND cle.id = p_financial_asset_id;
1854:
1855: -- get the residual value for the fin asset
1856: CURSOR l_linesfullv_csr(p_fin_asset_id IN NUMBER) IS
1857: SELECT name, NVL(residual_value,0) -- girao Bug 4106216 NVL the residual value
1858: FROM okl_k_lines_full_v
1859: WHERE id = p_fin_asset_id;
1853: AND cle.id = p_financial_asset_id;
1854:
1855: -- get the residual value for the fin asset
1856: CURSOR l_linesfullv_csr(p_fin_asset_id IN NUMBER) IS
1857: SELECT name, NVL(residual_value,0) -- girao Bug 4106216 NVL the residual value
1858: FROM okl_k_lines_full_v
1859: WHERE id = p_fin_asset_id;
1860:
1861: --SECHAWLA 10-FEB-06 5016156 : begin
1879: l_contract_number VARCHAR2(120);
1880: l_rulv_rec okl_rule_pub.rulv_rec_type;
1881: l_tax_owner VARCHAR2(10);
1882: l_delta_cost NUMBER;
1883: l_residual_value NUMBER;
1884: l_name VARCHAR2(150);
1885: l_cost NUMBER;
1886: --SECHAWLA 21-NOV-2003 3262519 : end new declarations
1887:
1982: RAISE OKC_API.G_EXCEPTION_ERROR;
1983: END IF;
1984:
1985: -- Get the sysdate
1986: SELECT SYSDATE INTO l_sys_date FROM DUAL;
1987:
1988: -- rmunjulu EDAT Added condition to default
1989: IF p_quote_eff_date IS NOT NULL
1990: AND p_quote_eff_date <> OKL_API.G_MISS_DATE THEN
2152: -- l_rulv_rec.RULE_INFORMATION1 will contain the value 'LESSEE' or 'LESSOR'
2153: l_tax_owner := l_rulv_rec.RULE_INFORMATION1;
2154: END IF;
2155:
2156: -- get the residual value of the fin asset
2157: OPEN l_linesfullv_csr(p_financial_asset_id);
2158: FETCH l_linesfullv_csr INTO l_name, l_residual_value;
2159: CLOSE l_linesfullv_csr;
2160:
2154: END IF;
2155:
2156: -- get the residual value of the fin asset
2157: OPEN l_linesfullv_csr(p_financial_asset_id);
2158: FETCH l_linesfullv_csr INTO l_name, l_residual_value;
2159: CLOSE l_linesfullv_csr;
2160:
2161: IF l_residual_value IS NULL THEN
2162: x_return_status := OKL_API.G_RET_STS_ERROR;
2157: OPEN l_linesfullv_csr(p_financial_asset_id);
2158: FETCH l_linesfullv_csr INTO l_name, l_residual_value;
2159: CLOSE l_linesfullv_csr;
2160:
2161: IF l_residual_value IS NULL THEN
2162: x_return_status := OKL_API.G_RET_STS_ERROR;
2163: -- Residual value is not defined for the asset
2164: OKC_API.set_message( p_app_name => 'OKL',
2165: p_msg_name => 'OKL_AM_NO_RESIDUAL_VALUE',
2159: CLOSE l_linesfullv_csr;
2160:
2161: IF l_residual_value IS NULL THEN
2162: x_return_status := OKL_API.G_RET_STS_ERROR;
2163: -- Residual value is not defined for the asset
2164: OKC_API.set_message( p_app_name => 'OKL',
2165: p_msg_name => 'OKL_AM_NO_RESIDUAL_VALUE',
2166: p_token1 => 'ASSET_NUMBER',
2167: p_token1_value => l_name);
2161: IF l_residual_value IS NULL THEN
2162: x_return_status := OKL_API.G_RET_STS_ERROR;
2163: -- Residual value is not defined for the asset
2164: OKC_API.set_message( p_app_name => 'OKL',
2165: p_msg_name => 'OKL_AM_NO_RESIDUAL_VALUE',
2166: p_token1 => 'ASSET_NUMBER',
2167: p_token1_value => l_name);
2168:
2169:
2176:
2177: -- currency codes different so need for conversion
2178: IF l_contract_currency_code <> l_functional_currency_code THEN
2179:
2180: -- convert the residual value obtained to functional currency
2181: OKL_ACCOUNTING_UTIL.convert_to_functional_currency(
2182: p_khr_id => l_chr_id,
2183: p_to_currency => l_functional_currency_code,
2184: p_transaction_date => l_quote_eff_date,
2181: OKL_ACCOUNTING_UTIL.convert_to_functional_currency(
2182: p_khr_id => l_chr_id,
2183: p_to_currency => l_functional_currency_code,
2184: p_transaction_date => l_quote_eff_date,
2185: p_amount => l_residual_value, -- convert residual value from Contract to Functional currency
2186: x_return_status => l_return_status,
2187: x_contract_currency => l_contract_currency_code,
2188: x_currency_conversion_type => l_currency_conversion_type,
2189: x_currency_conversion_rate => l_currency_conversion_rate,
2189: x_currency_conversion_rate => l_currency_conversion_rate,
2190: x_currency_conversion_date => l_currency_conversion_date,
2191: x_converted_amount => l_converted_amount);
2192:
2193: l_residual_value := l_converted_amount; -- residual value is now converted to functional currency
2194:
2195: END IF;
2196: --rbruno 5436987 -- End
2197:
2195: END IF;
2196: --rbruno 5436987 -- End
2197:
2198:
2199: IF l_residual_value < 0 THEN
2200: x_return_status := OKL_API.G_RET_STS_ERROR;
2201: -- Residual value is negative for the asset
2202: OKC_API.set_message( p_app_name => 'OKL',
2203: p_msg_name => 'OKL_AM_INVALID_RESIDUAL',
2197:
2198:
2199: IF l_residual_value < 0 THEN
2200: x_return_status := OKL_API.G_RET_STS_ERROR;
2201: -- Residual value is negative for the asset
2202: OKC_API.set_message( p_app_name => 'OKL',
2203: p_msg_name => 'OKL_AM_INVALID_RESIDUAL',
2204: p_token1 => 'ASSET_NUMBER',
2205: p_token1_value => l_name);
2199: IF l_residual_value < 0 THEN
2200: x_return_status := OKL_API.G_RET_STS_ERROR;
2201: -- Residual value is negative for the asset
2202: OKC_API.set_message( p_app_name => 'OKL',
2203: p_msg_name => 'OKL_AM_INVALID_RESIDUAL',
2204: p_token1 => 'ASSET_NUMBER',
2205: p_token1_value => l_name);
2206:
2207:
2234: END LOOP;
2235:
2236: IF l_trx_status IS NULL THEN -- This means off-lease trx don't exist. It is termination with purchase
2237: --SECHAWLA 10-FEB-06 5016156: end
2238: l_delta_cost := l_residual_value - l_okxassetlines_rec.cost;
2239: --SECHAWLA 10-FEB-06 5016156 : begin
2240: ELSIF l_trx_status IN ('ENTERED','ERROR') THEN -- if any trx has this status
2241: x_return_status := OKL_API.G_RET_STS_ERROR;
2242: OKL_API.set_message( p_app_name => 'OKL',
2680:
2681: -- SECHAWLA 21-NOV-2003 3262519 : get the cost that is to be retired
2682: IF l_tax_owner = 'LESSEE' THEN -- tax owner will have a value for Direct Finance/Sales Lease only.
2683: -- Cost Adjustment will happen in tax book through do_cost_retirement
2684: -- Cost will become Residual Value
2685: l_cost := l_okxassetlines_rec.cost; -- Retire Asset Cost -- for bug 5760603 - Earlier RV
2686: ELSE -- tax owner = 'LESSOR' (cost adj does not happen in tax book)
2687: -- OR tax owner is null (not DF/Sales lease, no cost adjustment)
2688: l_cost := l_okxassetlines_rec.cost; -- Retire the current cost in FA -- this is FA Cost
2840:
2841: -- SECHAWLA 21-NOV-2003 3262519 : get the cost that is to be retired
2842: IF l_tax_owner = 'LESSEE' THEN -- tax owner will have a value for Direct Finance/Sales Lease only.
2843: -- Cost Adjustment will happen in tax book through do_cost_retirement
2844: -- Cost will become Residual Value
2845: l_cost := l_okxassetlines_rec.cost; -- for bug 5760603 -- Retire cost Not Rv
2846: ELSE -- tax owner = 'LESSOR' (cost adj does not happen in tax book)
2847: -- OR tax owner is null (not DF/Sales lease, no cost adjustment)
2848: l_cost := l_okxassetlines_rec.cost; -- cost to be considered is the curent cost
3491: -- take care of the scenario where tax book cost is more than the corporate book cost
3492: -- 2) full tax book retirement when the corp book is not fully retired but tax book does not
3493: -- have enough cost. This takes care of the scenario where tax book cost is less than the corp book cost
3494: -- SECHAWLA 05-FEB-03 Bug # 2781557
3495: -- Moved the logic to check if the asset was added in the current open period, from individual cost and unit
3496: -- retirement procedures to this procedure.
3497: -- SECHAWLA 11-MAR-03
3498: -- Removed the validation for NULL order quantity, as it is being NVLed to 1. Added a validation
3499: -- for unit_selling_price. If null, assigned 0 to sale_amount
3499: -- for unit_selling_price. If null, assigned 0 to sale_amount
3500: -- SECHAWLA 03-JUN-03 2999419: Use the retirement prorate convention set in Oracle
3501: -- Assets for a particular asset and book, instead of using the constant value "MID-MONTH"
3502: -- RMUNJULU 11-SEP-03 3061751 Added code for SERVICE_K_INTEGRATION
3503: -- SECHAWLA 21-NOV-03 3262519 Update the asset cost with residual value, for DF and Sales lease,
3504: -- before retiring the asset
3505: -- SECHAWLA 21-OCT-04 3924244 Modified procedure to work on order line instead of header
3506: -- girao 18-Jan-2005 4106216 NVL the residual value in l_linesfullv_csr
3507: -- SECHAWLA 10-FEB-06 5016156 in case of termination w/o purchase, asset cost should
3502: -- RMUNJULU 11-SEP-03 3061751 Added code for SERVICE_K_INTEGRATION
3503: -- SECHAWLA 21-NOV-03 3262519 Update the asset cost with residual value, for DF and Sales lease,
3504: -- before retiring the asset
3505: -- SECHAWLA 21-OCT-04 3924244 Modified procedure to work on order line instead of header
3506: -- girao 18-Jan-2005 4106216 NVL the residual value in l_linesfullv_csr
3507: -- SECHAWLA 10-FEB-06 5016156 in case of termination w/o purchase, asset cost should
3508: -- be updated with NIV (not RV), through Off-lease transactions
3509:
3510: -- End of comments
3672: WHERE khr.id = cle.chr_id
3673: AND lkhr.id = khr.id
3674: AND cle.id = p_financial_asset_id;
3675:
3676: -- get the residual value for the fin asset
3677: CURSOR l_linesfullv_csr(p_fin_asset_id IN NUMBER) IS
3678: SELECT name, NVL(residual_value,0) --girao bug 4106216 NVL the residual value
3679: FROM okl_k_lines_full_v
3680: WHERE id = p_fin_asset_id;
3674: AND cle.id = p_financial_asset_id;
3675:
3676: -- get the residual value for the fin asset
3677: CURSOR l_linesfullv_csr(p_fin_asset_id IN NUMBER) IS
3678: SELECT name, NVL(residual_value,0) --girao bug 4106216 NVL the residual value
3679: FROM okl_k_lines_full_v
3680: WHERE id = p_fin_asset_id;
3681:
3682: --SECHAWLA 10-FEB-06 5016156
3700: l_contract_number VARCHAR2(120);
3701: l_rulv_rec okl_rule_pub.rulv_rec_type;
3702: l_tax_owner VARCHAR2(10);
3703: l_delta_cost NUMBER;
3704: l_residual_value NUMBER;
3705: l_name VARCHAR2(150);
3706: l_cost NUMBER;
3707: --SECHAWLA 21-NOV-2003 3262519 : end new declarations
3708:
3787: RAISE OKC_API.G_EXCEPTION_ERROR;
3788: END IF;
3789:
3790: -- Get the sysdate
3791: SELECT SYSDATE INTO l_sys_date FROM DUAL;
3792:
3793: -- SECHAWLA 21-OCT-04 3924244
3794: IF p_order_line_Id IS NULL OR p_order_line_Id = OKL_API.G_MISS_NUM THEN
3795: x_return_status := OKL_API.G_RET_STS_ERROR;
3964: -- l_rulv_rec.RULE_INFORMATION1 will contain the value 'LESSEE' or 'LESSOR'
3965: l_tax_owner := l_rulv_rec.RULE_INFORMATION1;
3966: END IF;
3967:
3968: -- get the residual value of the fin asset
3969: OPEN l_linesfullv_csr(l_kle_id);
3970: FETCH l_linesfullv_csr INTO l_name, l_residual_value;
3971: CLOSE l_linesfullv_csr;
3972:
3966: END IF;
3967:
3968: -- get the residual value of the fin asset
3969: OPEN l_linesfullv_csr(l_kle_id);
3970: FETCH l_linesfullv_csr INTO l_name, l_residual_value;
3971: CLOSE l_linesfullv_csr;
3972:
3973: IF l_residual_value IS NULL THEN
3974: x_return_status := OKL_API.G_RET_STS_ERROR;
3969: OPEN l_linesfullv_csr(l_kle_id);
3970: FETCH l_linesfullv_csr INTO l_name, l_residual_value;
3971: CLOSE l_linesfullv_csr;
3972:
3973: IF l_residual_value IS NULL THEN
3974: x_return_status := OKL_API.G_RET_STS_ERROR;
3975: -- Residual value is not defined for the asset
3976: OKC_API.set_message( p_app_name => 'OKL',
3977: p_msg_name => 'OKL_AM_NO_RESIDUAL_VALUE',
3971: CLOSE l_linesfullv_csr;
3972:
3973: IF l_residual_value IS NULL THEN
3974: x_return_status := OKL_API.G_RET_STS_ERROR;
3975: -- Residual value is not defined for the asset
3976: OKC_API.set_message( p_app_name => 'OKL',
3977: p_msg_name => 'OKL_AM_NO_RESIDUAL_VALUE',
3978: p_token1 => 'ASSET_NUMBER',
3979: p_token1_value => l_name);
3973: IF l_residual_value IS NULL THEN
3974: x_return_status := OKL_API.G_RET_STS_ERROR;
3975: -- Residual value is not defined for the asset
3976: OKC_API.set_message( p_app_name => 'OKL',
3977: p_msg_name => 'OKL_AM_NO_RESIDUAL_VALUE',
3978: p_token1 => 'ASSET_NUMBER',
3979: p_token1_value => l_name);
3980:
3981:
3981:
3982: RAISE OKC_API.G_EXCEPTION_ERROR;
3983: END IF;
3984:
3985: IF l_residual_value < 0 THEN
3986: x_return_status := OKL_API.G_RET_STS_ERROR;
3987: -- Residual value is negative for the asset
3988: OKC_API.set_message( p_app_name => 'OKL',
3989: p_msg_name => 'OKL_AM_INVALID_RESIDUAL',
3983: END IF;
3984:
3985: IF l_residual_value < 0 THEN
3986: x_return_status := OKL_API.G_RET_STS_ERROR;
3987: -- Residual value is negative for the asset
3988: OKC_API.set_message( p_app_name => 'OKL',
3989: p_msg_name => 'OKL_AM_INVALID_RESIDUAL',
3990: p_token1 => 'ASSET_NUMBER',
3991: p_token1_value => l_name);
3985: IF l_residual_value < 0 THEN
3986: x_return_status := OKL_API.G_RET_STS_ERROR;
3987: -- Residual value is negative for the asset
3988: OKC_API.set_message( p_app_name => 'OKL',
3989: p_msg_name => 'OKL_AM_INVALID_RESIDUAL',
3990: p_token1 => 'ASSET_NUMBER',
3991: p_token1_value => l_name);
3992:
3993:
4022:
4023:
4024: IF l_trx_status IS NULL THEN -- This means off-lease trx don't exist. It is termination with purchase
4025: --SECHAWLA 10-FEB-06 5016156 : end
4026: l_delta_cost := l_residual_value - l_okxassetlines_rec.cost;
4027:
4028: --SECHAWLA 10-FEB-06 5016156 begin
4029: ELSIF l_trx_status IN ('ENTERED','ERROR') THEN -- if any trx has this status
4030: x_return_status := OKL_API.G_RET_STS_ERROR;
4453:
4454: -- SECHAWLA 21-NOV-2003 3262519 : get the cost that is to be retired
4455: IF l_tax_owner = 'LESSEE' THEN -- tax owner will have a value for Direct Finance/Sales Lease only.
4456: -- Cost Adjustment will happen in tax book through do_cost_retirement
4457: -- Cost will become Residual Value
4458: l_cost := l_okxassetlines_rec.cost; -- for bug 5760603 -- Retire cost Not Rv
4459: ELSE -- tax owner = 'LESSOR' (cost adj does not happen in tax book)
4460: -- OR tax owner is null (not DF/Sales lease, no cost adjustment)
4461: l_cost := l_okxassetlines_rec.cost; -- Retire the current cost in FA
4606: IF l_already_retired = 'N' THEN -- SECHAWLA 13-JAN-03 Bug # 2701440 : Added this condition to stop cost retirement of tax book if asset is already fully retierd in corp book
4607: -- SECHAWLA 21-NOV-2003 3262519 : get the cost that is to be retired
4608: IF l_tax_owner = 'LESSEE' THEN -- tax owner will have a value for Direct Finance/Sales Lease only.
4609: -- Cost Adjustment will happen in tax book through do_cost_retirement
4610: -- Cost will become Residual Value
4611: l_cost := l_okxassetlines_rec.cost; -- for bug 5760603 -- Retire cost Not Rv
4612: ELSE -- tax owner = 'LESSOR' (cost adj does not happen in tax book)
4613: -- OR tax owner is null (not DF/Sales lease, no cost adjustment)
4614: l_cost := l_okxassetlines_rec.cost; -- cost to be considered is the curent cost