oracle子增值,讨论:如何对FA现有的某个资产进行增值处理?[结案!]

我的理解,是要按这个PROCEDURE去处理.

PROCEDURE do_adjustment

(p_api_version              IN     NUMBER,

p_init_msg_list            IN     VARCHAR2 := FND_API.G_FALSE,

p_commit                   IN     VARCHAR2 := FND_API.G_FALSE,

p_validation_level         IN     NUMBER   := FND_API.G_VALID_LEVEL_FULL,

p_calling_fn               IN     VARCHAR2,

x_return_status               OUT NOCOPY VARCHAR2,

x_msg_count                   OUT NOCOPY NUMBER,

x_msg_data                    OUT NOCOPY VARCHAR2,

px_trans_rec               IN OUT NOCOPY FA_API_TYPES.trans_rec_type,

px_asset_hdr_rec           IN OUT NOCOPY FA_API_TYPES.asset_hdr_rec_type,

p_asset_fin_rec_adj        IN     FA_API_TYPES.asset_fin_rec_type,

x_asset_fin_rec_new           OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,

x_asset_fin_mrc_tbl_new       OUT NOCOPY FA_API_TYPES.asset_fin_tbl_type,

px_inv_trans_rec           IN OUT NOCOPY FA_API_TYPES.inv_trans_rec_type,

px_inv_tbl                 IN OUT NOCOPY FA_API_TYPES.inv_tbl_type,

px_inv_rate_tbl            IN OUT NOCOPY FA_API_TYPES.inv_rate_tbl_type,

p_asset_deprn_rec_adj      IN     FA_API_TYPES.asset_deprn_rec_type,

x_asset_deprn_rec_new         OUT NOCOPY FA_API_TYPES.asset_deprn_rec_type,

x_asset_deprn_mrc_tbl_new     OUT NOCOPY FA_API_TYPES.asset_deprn_tbl_type,

p_group_reclass_options_rec IN    FA_API_TYPES.group_reclass_options_rec_type

) IS

l_reporting_flag          varchar2(1);

l_inv_count               number := 0;

l_rate_count              number := 0;

l_deprn_count             number := 0;

l_count                   number := 0;

l_asset_fin_rec_adj       FA_API_TYPES.asset_fin_rec_type   := p_asset_fin_rec_adj;

l_asset_fin_mrc_tbl_adj   FA_API_TYPES.asset_fin_tbl_type;

l_asset_deprn_rec_adj     FA_API_TYPES.asset_deprn_rec_type;

l_asset_deprn_mrc_tbl_adj FA_API_TYPES.asset_deprn_tbl_type;

l_asset_fin_rec_new       FA_API_TYPES.asset_fin_rec_type   := p_asset_fin_rec_adj;

l_asset_fin_mrc_tbl_new   FA_API_TYPES.asset_fin_tbl_type;

l_asset_deprn_rec_new     FA_API_TYPES.asset_deprn_rec_type;

l_asset_deprn_mrc_tbl_new FA_API_TYPES.asset_deprn_tbl_type;

l_asset_desc_rec          FA_API_TYPES.asset_desc_rec_type;

l_asset_type_rec          FA_API_TYPES.asset_type_rec_type;

l_asset_cat_rec           FA_API_TYPES.asset_cat_rec_type;

-- used to store original sob info upon entry into api

l_orig_set_of_books_id    number;

l_orig_currency_context   varchar2(64);

-- used for tax books when doing cip-in-tax or autocopy

l_trans_rec               FA_API_TYPES.trans_rec_type;

l_asset_hdr_rec           FA_API_TYPES.asset_hdr_rec_type;

l_tax_book_tbl            FA_CACHE_PKG.fazctbk_tbl_type;

l_tax_index               NUMBER;  -- index for tax loop

l_calling_fn              VARCHAR2(35) := 'fa_adjustment_pub.do_adjustment';

adj_err                   EXCEPTION;

BEGIN

SAVEPOINT do_adjustment;

g_cip_cost := 0;

-- Initialize message list if p_init_msg_list is set to TRUE.

if (fnd_api.to_boolean(p_init_msg_list)) then

-- initialize error message stack.

fa_srvr_msg.init_server_message;

-- initialize debug message stack.

fa_debug_pkg.initialize;

end if;

-- Check version of the API

-- Standard call to check for API call compatibility.

if NOT fnd_api.compatible_api_call (

G_API_VERSION,

p_api_version,

G_API_NAME,

G_PKG_NAME

) then

x_return_status := FND_API.G_RET_STS_ERROR;

raise adj_err;

end if;

-- call the cache for the primary transaction book

if NOT fa_cache_pkg.fazcbc(X_book => px_asset_hdr_rec.book_type_code) then

raise adj_err;

end if;

px_asset_hdr_rec.set_of_books_id := fa_cache_pkg.fazcbc_record.set_of_books_id;

-- verify the asset exist in the book already

if not FA_ASSET_VAL_PVT.validate_asset_book

(p_transaction_type_code      => 'ADJUSTMENT',

p_book_type_code             => px_asset_hdr_rec.book_type_code,

p_asset_id                   => px_asset_hdr_rec.asset_id,

p_calling_fn                 => l_calling_fn

) then

raise adj_err;

end if;

-- get the current info for the primary book

fnd_profile.get ('GL_SET_OF_BKS_ID',l_orig_set_of_books_id);

l_orig_currency_context :=  SUBSTRB(USERENV('CLIENT_INFO'),45,10);

fnd_profile.put('GL_SET_OF_BKS_ID', px_asset_hdr_rec.set_of_books_id);

fnd_client_info.set_currency_context (px_asset_hdr_rec.set_of_books_id);

-- Account for transaction submitted from a responsibility

-- that is not tied to a SOB_ID by getting the value from

-- the book struct

-- Get the book type code P,R or N

if not fa_cache_pkg.fazcsob

(X_set_of_books_id   => px_asset_hdr_rec.set_of_books_id,

X_mrc_sob_type_code => l_reporting_flag

) then

raise adj_err;

end if;

--  Error out if the program is submitted from the Reporting Responsibility

--  No transaction permitted directly on reporting books.

IF l_reporting_flag = 'R' THEN

fa_srvr_msg.add_message

(calling_fn => l_calling_fn,

name => 'MRC_OSP_INVALID_BOOK_TYPE');

raise adj_err;

END IF;

-- end initial MRC validation

-- pop the structs for the non-fin information needed for trx

if not FA_UTIL_PVT.get_asset_desc_rec

(p_asset_hdr_rec         => px_asset_hdr_rec,

px_asset_desc_rec       => l_asset_desc_rec

) then

raise adj_err;

end if;

if not FA_UTIL_PVT.get_asset_cat_rec

(p_asset_hdr_rec         => px_asset_hdr_rec,

px_asset_cat_rec        => l_asset_cat_rec,

p_date_effective        => null

) then

raise adj_err;

end if;

if not FA_UTIL_PVT.get_asset_type_rec

(p_asset_hdr_rec         => px_asset_hdr_rec,

px_asset_type_rec       => l_asset_type_rec,

p_date_effective        => null

) then

raise adj_err;

end if;

-- don't see a reason to pop the dist info here since it's static

-- and should be needed by the calc engine

l_inv_count   := px_inv_tbl.count;

l_rate_count  := px_inv_rate_tbl.count;

-- do not allow manual cost changes on cip assets in corp

-- cost adjustments must be doen via invoices

if (fa_cache_pkg.fazcbc_record.book_class = 'CORPORATE' and

l_asset_type_rec.asset_type = 'CIP' and

nvl(p_asset_fin_rec_adj.cost, 0) <> 0) then

fa_srvr_msg.add_message

(calling_fn => l_calling_fn,

name       => 'FA_BOOK_NO_CIP_COST_CHANGE');

raise adj_err;

end if;

-- do not allow manual cost changes on cip assets in tax

-- except when api is called from the cip-in-tax gateway

if (fa_cache_pkg.fazcbc_record.book_class = 'TAX' and

l_asset_type_rec.asset_type = 'CIP' and

p_calling_fn NOT IN ('fa_ciptax_api_pkg.cip_adj','FA_RECLASS_PVT.do_redefault'))

then

fa_srvr_msg.add_message

(calling_fn => l_calling_fn,

name       => 'FA_BOOK_NO_CIP_COST_CHANGE');

raise adj_err;

end if;

-- do not allow cost adjustment on group assets

if (l_asset_type_rec.asset_type = 'GROUP' and

nvl(p_asset_fin_rec_adj.cost, 0) <> 0) then

fa_srvr_msg.add_message

(calling_fn => l_calling_fn,

name       => 'FA_BOOK_NO_GROUP_COST_CHANGE');

raise adj_err;

end if;

-- nor invoice related adjustments

if (l_asset_type_rec.asset_type = 'GROUP' and

px_inv_tbl.count <> 0) then

fa_srvr_msg.add_message

(calling_fn => l_calling_fn,

name       => 'FA_BOOK_NO_GROUP_COST_CHANGE');

raise adj_err;

end if;

-- set the trx type to ADJUSTMENT or CIP ADJUSTMENT

-- is reset in the private api for period of addition

if (l_asset_type_rec.asset_type = 'CIP') then

px_trans_rec.transaction_type_code := 'CIP ADJUSTMENT';

elsif (l_asset_type_rec.asset_type = 'GROUP') then

px_trans_rec.transaction_type_code := 'GROUP ADJUSTMENT';

if (nvl(px_trans_rec.transaction_key, 'XX') <> 'SG') then

px_trans_rec.transaction_key       := 'GJ';

end if;

else

px_trans_rec.transaction_type_code := 'ADJUSTMENT';

end if;

-- default the trx_subtype to EXPENSED if null (AMORTIZED for group)

if (l_asset_type_rec.asset_type = 'GROUP' and

px_trans_rec.transaction_subtype is null) then

px_trans_rec.transaction_subtype := 'AMORTIZED';

elsif (px_trans_rec.transaction_subtype is null) then

px_trans_rec.transaction_subtype := 'EXPENSED';

end if;

-- also check if this is the period of addition - use absolute mode for adjustments

-- we will only clear cost outside period of addition

if not FA_ASSET_VAL_PVT.validate_period_of_addition

(p_asset_id            => px_asset_hdr_rec.asset_id,

p_book                => px_asset_hdr_rec.book_type_code,

p_mode                => 'ABSOLUTE',

px_period_of_addition => px_asset_hdr_rec.period_of_addition) then

raise adj_err;

end if;

-- call the mrc wrapper for the transaction book

if not do_all_books

(px_trans_rec               => px_trans_rec,

px_asset_hdr_rec           => px_asset_hdr_rec ,

p_asset_desc_rec           => l_asset_desc_rec ,

p_asset_type_rec           => l_asset_type_rec ,

p_asset_cat_rec            => l_asset_cat_rec ,

p_asset_fin_rec_adj        => p_asset_fin_rec_adj,

px_inv_trans_rec           => px_inv_trans_rec,

px_inv_tbl                 => px_inv_tbl,

px_inv_rate_tbl            => px_inv_rate_tbl,

p_asset_deprn_rec_adj      => p_asset_deprn_rec_adj,

p_group_reclass_options_rec=> p_group_reclass_options_rec

)then

raise adj_err;

end if;

-- If book is a corporate book, process cip assets and autocopy

if (fa_cache_pkg.fazcbc_record.book_class = 'CORPORATE') then

-- BUG# 2792134

-- null out the fin_rec table as well as deprn

-- cost and mrc cost will be rederived using corp values

l_asset_fin_rec_adj := null;

l_asset_fin_mrc_tbl_adj.delete;

l_asset_fin_rec_adj.cost := G_cost;

-- excluding salvage changes for now

-- nothing else should apply to tax (method, etc, and remain the same)

-- do not continue if there are no changes to process

if (nvl(l_asset_fin_rec_adj.cost, 0) = 0) then

null;

else

-- null out the deprn_adj table as we do not want to autocopy

-- any deprn info to tax books

l_asset_deprn_rec_adj := null;

l_trans_rec                       := px_trans_rec;

l_asset_hdr_rec                   := px_asset_hdr_rec;

if not fa_cache_pkg.fazctbk

(x_corp_book    => px_asset_hdr_rec.book_type_code,

x_asset_type   => l_asset_type_rec.asset_type,

x_tax_book_tbl => l_tax_book_tbl) then

raise adj_err;

end if;

for l_tax_index in 1..l_tax_book_tbl.count loop

-- verify that the asset exists in the tax book

-- if not just bypass it

if not (FA_ASSET_VAL_PVT.validate_asset_book

(p_transaction_type_code      => 'ADJUSTMENT',

p_book_type_code             => l_tax_book_tbl(l_tax_index),

p_asset_id                   => px_asset_hdr_rec.asset_id,

p_calling_fn                 => l_calling_fn)) then

null;

else

-- cache the book information for the tax book

if (NOT fa_cache_pkg.fazcbc(X_book => l_tax_book_tbl(l_tax_index))) then

raise adj_err;

end if;

-- NOTE!!!!

-- May need to set the transaction date, trx_type, subtype here as well

-- based on the open period and settings for each tax book in the loop

l_asset_hdr_rec.book_type_code           := l_tax_book_tbl(l_tax_index);

l_asset_hdr_rec.set_of_books_id          := fa_cache_pkg.fazcbc_record.set_of_books_id;

l_trans_rec.source_transaction_header_id := px_trans_rec.transaction_header_id;

l_trans_rec.transaction_header_id        := null;

-- set the gl sob info for the primary tax book

fnd_profile.put('GL_SET_OF_BKS_ID', l_asset_hdr_rec.set_of_books_id);

fnd_client_info.set_currency_context (l_asset_hdr_rec.set_of_books_id);

if not do_all_books

(px_trans_rec               => l_trans_rec,              -- tax

px_asset_hdr_rec           => l_asset_hdr_rec ,         -- tax

p_asset_desc_rec           => l_asset_desc_rec ,

p_asset_type_rec           => l_asset_type_rec ,

p_asset_cat_rec            => l_asset_cat_rec ,

p_asset_fin_rec_adj        => l_asset_fin_rec_adj,

px_inv_trans_rec           => px_inv_trans_rec,

px_inv_tbl                 => px_inv_tbl,

px_inv_rate_tbl            => px_inv_rate_tbl,

p_asset_deprn_rec_adj      => l_asset_deprn_rec_adj,

p_group_reclass_options_rec=> p_group_reclass_options_rec

) then

raise adj_err;

end if;

end if; -- exists in tax book

end loop; -- tax books

end if; -- cost change

end if; -- corporate book

x_return_status :=  FND_API.G_RET_STS_SUCCESS;

EXCEPTION

when adj_err then

ROLLBACK TO do_adjustment;

fnd_profile.put('GL_SET_OF_BKS_ID', l_orig_set_of_books_id);

fnd_client_info.set_currency_context (l_orig_currency_context);

fa_srvr_msg.add_message(calling_fn => l_calling_fn);

-- do not retrieve / clear messaging when this is being called

-- from reclass api - allow calling util to dump them

if (p_calling_fn <> 'FA_RECLASS_PVT.do_redefault'  and

p_calling_fn <> 'fa_inv_xfr_pub.do_transfer') then

FND_MSG_PUB.count_and_get (

p_count => x_msg_count,

p_data  => x_msg_data

);

end if;

x_return_status :=  FND_API.G_RET_STS_ERROR;

when others then

ROLLBACK TO do_adjustment;

fnd_profile.put('GL_SET_OF_BKS_ID', l_orig_set_of_books_id);

fnd_client_info.set_currency_context (l_orig_currency_context);

fa_srvr_msg.add_sql_error(

calling_fn => l_calling_fn);

-- do not retrieve / clear messaging when this is being called

-- from reclass api - allow calling util to dump them

if (p_calling_fn <> 'FA_RECLASS_PVT.do_redefault'  and

p_calling_fn <> 'fa_inv_xfr_pub.do_transfer') then

FND_MSG_PUB.count_and_get (

p_count => x_msg_count,

p_data  => x_msg_data

);

end if;

x_return_status :=  FND_API.G_RET_STS_ERROR;

END do_adjustment;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值