DROP VIEW xxcdb.xx_assets_depreciation_v;
CREATE OR REPLACE VIEW xxcdb.xx_assets_depreciation_v
(
asset_id, asset_number, serial_number, tag_number, po_number, model_number,
description, attribute_category_code, segment2, manufacturer_name,
date_placed_in_service, original_cost, current_cost,
adjusted_cost, deprn_amount, acmulated_deprn, net_book_value, deprn_run_date,
CALENDAR_PERIOD_OPEN_DATE, CALENDAR_PERIOD_CLOSE_DATE,
DATE_RETIRED,
full_name, EMPLOYEE_NUMBER,
units_assigned, state, location, retirement_pending_flag,
book_type_code
)
As
(
SELECT distinct
fav.asset_id,
fav.asset_number, fav.serial_number, fav.tag_number,
fiv.po_number, fav.model_number,
fav.description, fav.attribute_category_code, fc.segment2, fav.manufacturer_name,
fb.date_placed_in_service, fb.original_cost, fb.cost current_cost,
fb.adjusted_cost, x.deprn_amount, x.acmulated_deprn,
fb.original_cost-x.acmulated_deprn net_book_value, x.deprn_run_date,
x.CALENDAR_PERIOD_OPEN_DATE, x.CALENDAR_PERIOD_CLOSE_DATE,
ret.DATE_RETIRED,
ppx.full_name, ppx.EMPLOYEE_NUMBER,
fdh.units_assigned, fl.segment2 state,
fl.segment1|| '.' ||fl.segment2|| '.' ||fl.segment3 || '.' ||fl.segment4 location,
fb.retirement_pending_flag,
x.book_type_code
FROM apps.fa_categories fc,
apps.fa_invoice_details_v fiv,
apps.per_people_x ppx,
apps.fa_distribution_history fdh,
apps.fa_books_v fb,
apps.fa_additions_v fav,
apps.fa_retirements ret,
apps.fa_locations fl,
(
select fd.JE_HEADER_ID,
fd.COST, fd.deprn_amount,
deprn_reserve acmulated_deprn,
fd.deprn_run_date,
fdp.CALENDAR_PERIOD_OPEN_DATE, fdp.CALENDAR_PERIOD_CLOSE_DATE,
fd.asset_id, fd.book_type_code
from apps.fa_deprn_detail fd
,fa.fa_deprn_periods fdp
where fd.deprn_amount<>0
and fdp.period_counter = fd.PERIOD_COUNTER
and fdp.BOOK_TYPE_CODE=fd.BOOK_TYPE_CODE
order by fd.deprn_run_date desc
) x
WHERE fav.asset_category_id = fc.category_id
AND fb.asset_id(+) = fav.asset_id
AND fdh.asset_id(+) = fav.asset_id
AND TRUNC (SYSDATE) >= TRUNC (fdh.date_effective(+))
AND fdh.date_ineffective IS NULL
AND fdh.assigned_to = ppx.person_id(+)
AND fiv.asset_id(+) = fav.asset_id
and fb.book_type_code = 'WRI CORPORATE'
and fav.asset_id = x.asset_id
and fl.location_id = fdh.location_id
--and fb.retirement_pending_flag='NO'
and ret.asset_id (+) =fav.asset_id
and x.CALENDAR_PERIOD_CLOSE_DATE between :begin_date and :end_date
--and fb.asset_id ='1025'
-- and fav.ASSET_NUMBER ='1025'
--and fb.asset_id between '2600' and '8500'
--and fb.date_placed_in_service between to_date('1/1/2007', 'mm/dd/yyyy') and to_date('12/31/2007', 'mm/dd/yyyy')
--and x.deprn_run_date between to_date('1/1/2007', 'mm/dd/yyyy') and to_date('5/31/2007', 'mm/dd/yyyy')
union
SELECT distinct
fav.asset_id,
fav.asset_number, fav.serial_number, fav.tag_number,
fiv.po_number, fav.model_number,
fav.description, fav.attribute_category_code, fc.segment2, fav.manufacturer_name,
fb.date_placed_in_service, fb.original_cost, fb.cost current_cost,
fb.adjusted_cost, x.deprn_amount, x.acmulated_deprn,
fb.original_cost-x.acmulated_deprn net_book_value, x.deprn_run_date,
x.CALENDAR_PERIOD_OPEN_DATE, x.CALENDAR_PERIOD_CLOSE_DATE,
ret.DATE_RETIRED,
ppx.full_name, ppx.EMPLOYEE_NUMBER,
fdh.units_assigned, fl.segment2 state,
fl.segment1|| '.' ||fl.segment2|| '.' ||fl.segment3 || '.' ||fl.segment4 location,
fb.retirement_pending_flag,
x.book_type_code
FROM apps.fa_categories fc,
apps.fa_invoice_details_v fiv,
apps.per_people_x ppx,
apps.fa_distribution_history fdh,
apps.fa_books_v fb,
apps.fa_additions_v fav,
apps.fa_retirements ret,
apps.fa_locations fl,
(
select fd.JE_HEADER_ID,
fd.COST, fd.deprn_amount,
deprn_reserve acmulated_deprn,
fd.deprn_run_date,
fdp.CALENDAR_PERIOD_OPEN_DATE, fdp.CALENDAR_PERIOD_CLOSE_DATE,
fd.asset_id, fd.book_type_code
from apps.fa_deprn_detail fd
,fa.fa_deprn_periods fdp
where fd.deprn_amount<>0
and fdp.period_counter = fd.PERIOD_COUNTER
and fdp.BOOK_TYPE_CODE=fd.BOOK_TYPE_CODE
order by fd.deprn_run_date desc
) x
WHERE fav.asset_category_id = fc.category_id
AND fb.asset_id(+) = fav.asset_id
AND fdh.asset_id(+) = fav.asset_id
AND TRUNC (SYSDATE) >= TRUNC (fdh.date_effective(+))
AND fdh.date_ineffective IS NULL
AND fdh.assigned_to = ppx.person_id(+)
AND fiv.asset_id(+) = fav.asset_id
and fb.book_type_code = 'WRI CORPORATE'
and fav.asset_id = x.asset_id
and fl.location_id = fdh.location_id
--and fb.retirement_pending_flag='NO'
and ret.asset_id (+) =fav.asset_id
and ret.DATE_RETIRED is null
and fb.original_cost-x.acmulated_deprn=0
and x.CALENDAR_PERIOD_CLOSE_DATE <= :begin_date
)
CREATE OR REPLACE PACKAGE your_package
IS
PROCEDURE set_begin_date(p_date IN DATE);
PROCEDURE set_end_date(p_date IN DATE);
FUNCTION get_begin_date
RETURN DATE;
FUNCTION get_end_date
RETURN DATE;
END;
CREATE OR REPLACE PACKAGE BODY your_package
IS
g_begin_date DATE := NULL;
g_end_date DATE := NULL;
PROCEDURE set_begin_date(p_date IN DATE)
IS
BEGIN
g_begin_date := p_date;
END set_begin_date;
PROCEDURE set_end_date(p_date IN DATE)
IS
BEGIN
g_end_date := p_date;
END set_end_date;
FUNCTION get_begin_date
RETURN DATE
IS
BEGIN
RETURN g_begin_date;
END get_begin_date;
FUNCTION get_end_date
RETURN DATE
IS
BEGIN
RETURN g_end_date;
END get_end_date;
END;
CREATE OR REPLACE VIEW xxcdb.xx_assets_depreciation_v(asset_id,
asset_number,
serial_number,
tag_number,
po_number,
model_number,
description,
attribute_category_code,
segment2,
manufacturer_name,
date_placed_in_service,
original_cost,
current_cost,
adjusted_cost,
deprn_amount,
acmulated_deprn,
net_book_value,
deprn_run_date,
calendar_period_open_date,
calendar_period_close_date,
date_retired,
full_name,
employee_number,
units_assigned,
state,
LOCATION,
retirement_pending_flag,
book_type_code
)
AS
(SELECT DISTINCT fav.asset_id, fav.asset_number, fav.serial_number,
fav.tag_number, fiv.po_number, fav.model_number,
fav.description, fav.attribute_category_code,
fc.segment2, fav.manufacturer_name,
fb.date_placed_in_service, fb.original_cost,
fb.COST current_cost, fb.adjusted_cost, x.deprn_amount,
x.acmulated_deprn,
fb.original_cost - x.acmulated_deprn net_book_value,
x.deprn_run_date, x.calendar_period_open_date,
x.calendar_period_close_date, ret.date_retired,
ppx.full_name, ppx.employee_number, fdh.units_assigned,
fl.segment2 state,
fl.segment1
|| '.'
|| fl.segment2
|| '.'
|| fl.segment3
|| '.'
|| fl.segment4 LOCATION,
fb.retirement_pending_flag, x.book_type_code
FROM apps.fa_categories fc,
apps.fa_invoice_details_v fiv,
apps.per_people_x ppx,
apps.fa_distribution_history fdh,
apps.fa_books_v fb,
apps.fa_additions_v fav,
apps.fa_retirements ret,
apps.fa_locations fl,
(SELECT fd.je_header_id, fd.COST, fd.deprn_amount,
deprn_reserve acmulated_deprn,
fd.deprn_run_date,
fdp.calendar_period_open_date,
fdp.calendar_period_close_date, fd.asset_id,
fd.book_type_code
FROM apps.fa_deprn_detail fd,
fa.fa_deprn_periods fdp
WHERE fd.deprn_amount <> 0
AND fdp.period_counter = fd.period_counter
AND fdp.book_type_code = fd.book_type_code
ORDER BY fd.deprn_run_date DESC) x
WHERE fav.asset_category_id = fc.category_id
AND fb.asset_id(+) = fav.asset_id
AND fdh.asset_id(+) = fav.asset_id
AND TRUNC(SYSDATE) >= TRUNC(fdh.date_effective(+))
AND fdh.date_ineffective IS NULL
AND fdh.assigned_to = ppx.person_id(+)
AND fiv.asset_id(+) = fav.asset_id
AND fb.book_type_code = 'WRI CORPORATE'
AND fav.asset_id = x.asset_id
AND fl.location_id = fdh.location_id
--and fb.retirement_pending_flag='NO'
AND ret.asset_id(+) = fav.asset_id
AND x.calendar_period_close_date BETWEEN your_package.get_begin_date
AND your_package.get_end_date
--and fb.asset_id ='1025'
-- and fav.ASSET_NUMBER ='1025'
--and fb.asset_id between '2600' and '8500'
--and fb.date_placed_in_service between to_date('1/1/2007', 'mm/dd/yyyy') and to_date('12/31/2007', 'mm/dd/yyyy')
--and x.deprn_run_date between to_date('1/1/2007', 'mm/dd/yyyy') and to_date('5/31/2007', 'mm/dd/yyyy')
UNION
SELECT DISTINCT fav.asset_id, fav.asset_number, fav.serial_number,
fav.tag_number, fiv.po_number, fav.model_number,
fav.description, fav.attribute_category_code,
fc.segment2, fav.manufacturer_name,
fb.date_placed_in_service, fb.original_cost,
fb.COST current_cost, fb.adjusted_cost, x.deprn_amount,
x.acmulated_deprn,
fb.original_cost - x.acmulated_deprn net_book_value,
x.deprn_run_date, x.calendar_period_open_date,
x.calendar_period_close_date, ret.date_retired,
ppx.full_name, ppx.employee_number, fdh.units_assigned,
fl.segment2 state,
fl.segment1
|| '.'
|| fl.segment2
|| '.'
|| fl.segment3
|| '.'
|| fl.segment4 LOCATION,
fb.retirement_pending_flag, x.book_type_code
FROM apps.fa_categories fc,
apps.fa_invoice_details_v fiv,
apps.per_people_x ppx,
apps.fa_distribution_history fdh,
apps.fa_books_v fb,
apps.fa_additions_v fav,
apps.fa_retirements ret,
apps.fa_locations fl,
(SELECT fd.je_header_id, fd.COST, fd.deprn_amount,
deprn_reserve acmulated_deprn,
fd.deprn_run_date,
fdp.calendar_period_open_date,
fdp.calendar_period_close_date, fd.asset_id,
fd.book_type_code
FROM apps.fa_deprn_detail fd,
fa.fa_deprn_periods fdp
WHERE fd.deprn_amount <> 0
AND fdp.period_counter = fd.period_counter
AND fdp.book_type_code = fd.book_type_code
ORDER BY fd.deprn_run_date DESC) x
WHERE fav.asset_category_id = fc.category_id
AND fb.asset_id(+) = fav.asset_id
AND fdh.asset_id(+) = fav.asset_id
AND TRUNC(SYSDATE) >= TRUNC(fdh.date_effective(+))
AND fdh.date_ineffective IS NULL
AND fdh.assigned_to = ppx.person_id(+)
AND fiv.asset_id(+) = fav.asset_id
AND fb.book_type_code = 'WRI CORPORATE'
AND fav.asset_id = x.asset_id
AND fl.location_id = fdh.location_id
--and fb.retirement_pending_flag='NO'
AND ret.asset_id(+) = fav.asset_id
AND ret.date_retired IS NULL
AND fb.original_cost - x.acmulated_deprn = 0
AND x.calendar_period_close_date <= your_package.get_begin_date)
How? can you tell more specific?