开发步骤:
一,创建一个PROCEDURE 类似如下:
CREATE OR REPLACE PROCEDURE xxafx_TEST(p_sob_id NUMBER,
p_period_year NUMBER,
p_period_name VARCHAR2,
p_start_date varchar2,
p_end_date varchar2,
p_period_num NUMBER,
p_period_id number,
p_company_id varchar2,
p_currency_code VARCHAR2,
p_zbr VARCHAR2,
p_fhr VARCHAR2) IS
----------------------------------------------------------------------
-- Purpose :资产负债表
-----------------------------------------------------------------------
v_standard_code VARCHAR2(30);
v_converted_code VARCHAR2(30);
v_description VARCHAR2(240);
v_currency_code VARCHAR2(10);
v_column_1_name VARCHAR2(10);
v_column_2_name VARCHAR2(10);
p_date_title_str VARCHAR2(50);
n NUMBER(20);
v_balance_value number;
v_begin_balance NUMBER(20, 2);
v_period_balance NUMBER(20, 2);
v_period_min_num NUMBER(13);
v_company VARCHAR2(1000);
v_month NUMBER(10);
v_title_month number(10);
v_day NUMBER(10);
v_user VARCHAR2(20);
v_appro VARCHAR2(20);
v_r1_c1 NUMBER(30, 2); --行次为1,第一个变量
v_r1_c2 NUMBER(30, 2); --行次为1,第二个变量
v_r2_c1 NUMBER(30, 2);
v_r2_c2 NUMBER(30, 2);
v_r3_c1 NUMBER(30, 2);
v_r3_c2 NUMBER(30, 2);
v_r4_c1 NUMBER(30, 2);
v_r4_c2 NUMBER(30, 2);
v_r5_c1 NUMBER(30, 2);
v_r5_c2 NUMBER(30, 2);
v_r6_c1 NUMBER(30, 2); --应收帐款(1131-1141)
v_r6_c2 NUMBER(30, 2);
v_r7_c1 NUMBER(30, 2);
v_r7_c2 NUMBER(30, 2);
v_r8_c1 NUMBER(30, 2);
v_r8_c2 NUMBER(30, 2);
v_r9_c1 NUMBER(30, 2);
v_r9_c2 NUMBER(30, 2);
v_r10_c1 NUMBER(20, 2);
v_r10_c2 NUMBER(20, 2);
v_r11_c1 NUMBER(30, 2);
v_r11_c2 NUMBER(30, 2);
v_r24_c1 NUMBER(30, 2);
v_r24_c2 NUMBER(30, 2);
v_r31_c1 NUMBER(30, 2); --流动资产合计
v_r31_c2 NUMBER(30, 2);
v_r32_c1 NUMBER(30, 2);
v_r32_c2 NUMBER(30, 2);
v_r34_c1 NUMBER(30, 2);
v_r34_c2 NUMBER(30, 2);
v_r38_c1 NUMBER(30, 2); --长期投资合计
v_r38_c2 NUMBER(30, 2);
v_r39_c1 NUMBER(30, 2);
v_r39_c2 NUMBER(30, 2);
v_r40_c1 NUMBER(30, 2);
v_r40_c2 NUMBER(30, 2);
v_r41_c1 NUMBER(30, 2);
v_r41_c2 NUMBER(30, 2);
v_r42_c1 NUMBER(30, 2);
v_r42_c2 NUMBER(30, 2);
v_r43_c1 NUMBER(30, 2);
v_r43_c2 NUMBER(30, 2);
v_r44_c1 NUMBER(30, 2);
v_r44_c2 NUMBER(30, 2);
v_r45_c1 NUMBER(30, 2);
v_r45_c2 NUMBER(30, 2);
v_r46_c1 NUMBER(30, 2);
v_r46_c2 NUMBER(30, 2);
v_r50_c1 NUMBER(30, 2); --固定资产合计
v_r50_c2 NUMBER(30, 2);
v_r51_c1 NUMBER(30, 2);
v_r51_c2 NUMBER(30, 2);
v_r52_c1 NUMBER(30, 2);
v_r52_c2 NUMBER(30, 2);
v_r60_c1 NUMBER(30, 2); --无形资产及其他资产合计
v_r60_c2 NUMBER(30, 2);
v_r67_c2 NUMBER(30, 2); --资产总计
v_r67_c1 NUMBER(30, 2);
v_r68_c1 NUMBER(30, 2);
v_r68_c2 NUMBER(30, 2);
v_r69_c1 NUMBER(30, 2);
v_r69_c2 NUMBER(30, 2);
v_r70_c1 NUMBER(30, 2);
v_r70_c2 NUMBER(30, 2);
v_r71_c1 NUMBER(30, 2);
v_r71_c2 NUMBER(30, 2);
v_r72_c1 NUMBER(30, 2);
v_r72_c2 NUMBER(30, 2);
v_r73_c1 NUMBER(30, 2);
v_r73_c2 NUMBER(30, 2);
v_r74_c1 NUMBER(30, 2);
v_r74_c2 NUMBER(30, 2);
v_r75_c1 NUMBER(30, 2);
v_r75_c2 NUMBER(30, 2);
v_r76_c1 NUMBER(30, 2);
v_r76_c2 NUMBER(30, 2);
v_r81_c1 NUMBER(30, 2);
v_r81_c2 NUMBER(30, 2);
v_r82_c1 NUMBER(30, 2);
v_r82_c2 NUMBER(30, 2);
v_r83_c1 NUMBER(30, 2);
v_r83_c2 NUMBER(30, 2);
v_r90_c1 NUMBER(30, 2);
v_r90_c2 NUMBER(30, 2);
v_r100_c1 NUMBER(30, 2); --流动负债合计
v_r100_c2 NUMBER(30, 2);
v_r101_c1 NUMBER(30, 2);
v_r101_c2 NUMBER(30, 2);
v_r102_c1 NUMBER(30, 2);
v_r102_c2 NUMBER(30, 2);
v_r103_c1 NUMBER(30, 2);
v_r103_c2 NUMBER(30, 2);
v_r106_c1 NUMBER(30, 2);
v_r106_c2 NUMBER(30, 2);
v_r110_c1 NUMBER(30, 2); --长期负债合计
v_r110_c2 NUMBER(30, 2);
v_r111_c1 NUMBER(30, 2);
v_r111_c2 NUMBER(30, 2);
v_r114_c1 NUMBER(30, 2); --负债总计
v_r114_c2 NUMBER(30, 2);
v_r115_c1 NUMBER(30, 2);
v_r115_c2 NUMBER(30, 2);
v_r116_c1 NUMBER(30, 2);
v_r116_c2 NUMBER(30, 2);
v_r117_c1 NUMBER(30, 2);
v_r117_c2 NUMBER(30, 2);
v_r118_c1 NUMBER(30, 2);
v_r118_c2 NUMBER(30, 2);
v_r119_c1 NUMBER(30, 2);
v_r119_c2 NUMBER(30, 2);
v_r120_c1 NUMBER(30, 2);
v_r120_c2 NUMBER(30, 2);
v_r120_c3 NUMBER(30, 2);
v_r120_c4 NUMBER(30, 2);
v_r121_c2 NUMBER(30, 2);
v_r121_c1 NUMBER(30, 2);
v_r122_c1 NUMBER(30, 2);
v_r122_c2 NUMBER(30, 2);
v_r135_c1 NUMBER(30, 2);
v_r135_c2 NUMBER(30, 2);
v_internal_1 NUMBER(30, 2);
v_internal_2 NUMBER(30, 2);
v_reivable_1 NUMBER(30, 2);
v_reivable_2 NUMBER(30, 2);
v_r2176_c1 NUMBER(30, 2);
v_r2176_c2 NUMBER(30, 2);
v_period_name varchar2(60);
--====================取所有明细科目,余额用于计算======================
CURSOR c_acc IS
SELECT standard_code, converted_code, description
FROM xxafx_stx_converted_account
WHERE converted_code IS NOT NULL AND set_of_books_id = p_sob_id;
BEGIN
DELETE FROM xxafx_afx_bs;
COMMIT;
HTP.htmlOpen;
HTP.PRINT('<HEAD><META http-equiv=Content-Type content="text/html; charset=GB2312"></HEAD>');
HTP.bodyOpen;
----min period num
SELECT MIN(offset.period_num)
INTO v_period_min_num
FROM gl_period_statuses offset,
gl_period_statuses poi,
gl_period_types ptype
WHERE poi.period_year = p_period_year AND
offset.period_type = poi.period_type AND
ptype.period_type = poi.period_type AND
poi.period_year * ptype.number_per_fiscal_year + poi.period_num + 0 >=
offset.period_year * ptype.number_per_fiscal_year + 1 AND
poi.period_year * ptype.number_per_fiscal_year + poi.period_num + 0 <=
offset.period_year * ptype.number_per_fiscal_year +
ptype.number_per_fiscal_year AND
offset.application_id = poi.application_id AND
offset.set_of_books_id = poi.set_of_books_id AND
poi.set_of_books_id = p_sob_id AND poi.application_id = 101;
--年初数用期初数代替
--v_period_min_num:=p_period_num;
begin
select user_name
into v_user
from xxafx_user_profile_line
where user_id = p_zbr
and rownum < 2;
select user_name
into v_appro
from xxafx_user_profile_line
where user_id = p_fhr
and rownum < 2;
--COMPANY为空时显示帐套名称2008-1-24 by yxh
if p_company_id is not null then
select company_name
into v_company
from xxafx_user_profile_line
where company_id = p_company_id
and rownum < 2;
else
select t.description
into v_company
from gl_sets_of_books t
where t.set_of_books_id = p_sob_id
and rownum < 2;
end if;
EXCEPTION
WHEN OTHERS THEN
htp.P('公司ID或USER ID参数有误!');
end;
v_month := p_period_num;
INSERT INTO xxafx_afx_bs(
PERIOD_NUM,
STANDARD_CODE,
CONVERTED_CODE,
DESCRIPTION,
RESULT_1,
RESULT_2,
SET_OF_BOOKS_ID,
CURRENCY_CODE)
SELECT gb.period_num,
ca.standard_code,
ca.converted_code,
ca.description,
SUM(nvl(gb.begin_balance_dr, 0) - nvl(gb.begin_balance_cr, 0)),
SUM(nvl(gb.begin_balance_dr, 0) - nvl(gb.begin_balance_cr, 0) +
nvl(gb.period_net_dr, 0) - nvl(gb.period_net_cr, 0)),
p_sob_id,
p_currency_code
FROM gl_balances gb,
xxafx_stx_converted_account ca,
gl_code_combinations gcc
WHERE gcc.code_combination_id = gb.code_combination_id AND
gcc.segment3 = ca.converted_code AND
gcc.segment1 = nvl(p_company_id,gcc.segment1) and
gb.currency_code = p_currency_code AND
gb.period_year = p_period_year and
nvl(gcc.summary_flag,'N') <> 'Y' and
(gb.period_num = v_period_min_num or gb.period_num = v_month) and
gb.set_of_books_id = p_sob_id and
ca.set_of_books_id = p_sob_id
group by ca.standard_code,
ca.converted_code,
ca.description,
gb.period_num;
--取该区间的最后一天日期
select substr(p_start_date,6,2),
substr(p_end_date,9,2)
into v_title_month,
v_day
from dual;
--TITLE显示会计期间
select gps.period_name
into v_period_name
from gl_period_statuses gps
where gps.effective_period_num = p_period_id
and gps.application_id = 101
and gps.set_of_books_id = p_sob_id;
p_date_title_str := v_period_name;
--IF substr(p_start_date,6,2) = '12' THEN
--p_date_title_str := p_period_year || '年度';
--ELSE
--p_date_title_str := p_period_year || '年' || v_title_month || '月' || v_day || '日';
--END IF;
--Fetch date accord to standard account for bs
--------------------------------------------------ASSET-------------------------------------------------
SELECT SUM(result_1) --货币资金r1
INTO v_r1_c1
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 3) = '100' AND period_num = v_period_min_num;
SELECT SUM(result_2) --货币资金r1
INTO v_r1_c2
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 3) = '100' AND period_num = v_month;
SELECT SUM(result_1) --短期投资-短期投资跌价准备r2
INTO v_r2_c1
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
(SUBSTR(standard_code, 1, 4) = '1101' OR
SUBSTR(standard_code, 1, 4) = '1102') AND period_num = v_period_min_num;
SELECT SUM(result_2) --短期投资-短期投资跌价准备r2
INTO v_r2_c2
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
(SUBSTR(standard_code, 1, 4) = '1101' OR
SUBSTR(standard_code, 1, 4) = '1102') AND period_num = v_month;
SELECT SUM(result_1) --应收票据r3
INTO v_r3_c1
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1111' AND period_num = v_period_min_num;
SELECT SUM(result_2) --应收票据r3
INTO v_r3_c2
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1111' AND period_num = v_month;
SELECT SUM(result_1) --应收股利r4
INTO v_r4_c1
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1121' AND period_num = v_period_min_num;
SELECT SUM(result_2) --应收股利r4
INTO v_r4_c2
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1121' AND period_num = v_month;
SELECT SUM(result_1) --应收利息r5
INTO v_r5_c1
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1122' AND period_num = v_period_min_num;
SELECT SUM(result_2) --应收利息r5
INTO v_r5_c2
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1122' AND period_num = v_month;
SELECT SUM(result_1) --应收账款+减:坏帐准备r6
INTO v_r6_c1
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
(SUBSTR(standard_code, 1, 4) = '1131' OR
SUBSTR(standard_code, 1, 4) = '1141') AND period_num = v_period_min_num;
SELECT SUM(result_2) --应收账款+减:坏帐准备r6
INTO v_r6_c2
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
(SUBSTR(standard_code, 1, 4) = '1131' OR
SUBSTR(standard_code, 1, 4) = '1141') AND period_num = v_month;
SELECT SUM(result_1) --其他应收款r7
INTO v_r7_c1
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1133' AND period_num = v_period_min_num;
SELECT SUM(result_2) --其他应收款r7
INTO v_r7_c2
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1133' AND period_num = v_month;
SELECT SUM(result_1) --预付账款r8
INTO v_r8_c1
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1151' AND period_num = v_period_min_num;
SELECT SUM(result_2) --预付账款r8
INTO v_r8_c2
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1151' AND period_num = v_month;
SELECT SUM(result_1)--应收补贴款r9
INTO v_r9_c1
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1161' AND period_num = v_period_min_num;
SELECT SUM(result_2) --应收补贴款r9
INTO v_r9_c2
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1161' AND period_num = v_month;
SELECT SUM(result_1) --Internal transaction
INTO v_internal_1 --"1"开头,且未在以上科目中计算的,此处只含"待处理财产损溢"
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1181' AND period_num = v_period_min_num;
SELECT SUM(result_2) --Internal transaction
INTO v_internal_2 --"1"开头,且未在以上科目中计算的,此处只含"待处理财产损溢"
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1181' AND period_num = v_month;
SELECT SUM(result_1) --存货r10
INTO v_r10_c1
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
period_num = v_period_min_num AND
SUBSTR(standard_code, 1, 2) = '12' OR LPAD(standard_code, 1) = 4;
SELECT SUM(result_2) --存货r10
INTO v_r10_c2
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
period_num = v_month AND
SUBSTR(standard_code, 1, 2) = '12' OR LPAD(standard_code, 1) = 4;
SELECT SUM(result_1) --待摊费用r11
INTO v_r11_c1
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1301' AND period_num = v_period_min_num;
SELECT SUM(result_2) --待摊费用r11
INTO v_r11_c2
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1301' AND period_num = v_month;
SELECT SUM(result_1) --其他流动资产r24
INTO v_r24_c1 --"1"开头,且未在以上科目中计算的,此处只含"待处理财产损溢"
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) in ('1181','1191') AND period_num = v_period_min_num;
SELECT SUM(result_2) --其他流动资产r24
INTO v_r24_c2 --"1"开头,且未在以上科目中计算的,此处只含"待处理财产损溢"
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) in ('1181','1191') AND period_num = v_month;
v_reivable_1 := NVL(v_internal_1, 0) + NVL(v_r24_c1, 0);
v_reivable_2 := NVL(v_internal_2, 0) + NVL(v_r24_c2, 0);
v_r31_c1 := NVL(v_r1_c1, 0) + NVL(v_r2_c1, 0) + --流动资产合计r31
NVL(v_r3_c1, 0) + NVL(v_r4_c1, 0) + NVL(v_r5_c1, 0) +
NVL(v_r7_c1, 0) + NVL(v_r8_c1, 0) + NVL(v_r9_c1, 0) +
NVL(v_r10_c1, 0) + NVL(v_r11_c1, 0) + NVL(v_r6_c1, 0) +
NVL(v_reivable_1, 0);
v_r31_c2 := NVL(v_r1_c2, 0) + NVL(v_r2_c2, 0) + NVL(v_r3_c2, 0) +
NVL(v_r4_c2, 0) + NVL(v_r5_c2, 0) + NVL(v_r7_c2, 0) +
NVL(v_r8_c2, 0) + NVL(v_r9_c2, 0) + NVL(v_r10_c2, 0) +
NVL(v_r11_c2, 0) + NVL(v_r6_c2, 0) + NVL(v_reivable_2, 0);
SELECT SUM(result_1) --长期股权投资r32
INTO v_r32_c1
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1401' AND period_num = v_period_min_num;
SELECT SUM(result_2) --长期股权投资r32
INTO v_r32_c2
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1401' AND period_num = v_month;
SELECT SUM(result_1) --长期债权投资+委托贷款r34
INTO v_r34_c1
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) in ('1402', '1421', '1431') AND period_num = v_period_min_num;
SELECT SUM(result_2) --长期债权投资+委托贷款r34
INTO v_r34_c2
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) in ('1402', '1421', '1431') AND period_num = v_month;
v_r38_c1 := NVL(v_r32_c1, 0) + NVL(v_r34_c1, 0); --长期投资合计r38
v_r38_c2 := NVL(v_r32_c2, 0) + NVL(v_r34_c2, 0);
SELECT SUM(result_1) --固定资产原价r39
INTO v_r39_c1
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1501' AND period_num = v_period_min_num;
SELECT SUM(result_2) --固定资产原价r39
INTO v_r39_c2
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1501' AND period_num = v_month;
SELECT SUM(result_1) --减:累计折旧r40
INTO v_r40_c1
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1502' AND period_num = v_period_min_num;
SELECT SUM(result_2) --减:累计折旧r40
INTO v_r40_c2
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1502' AND period_num = v_month;
v_r41_c1 := NVL(v_r39_c1, 0) + NVL(v_r40_c1, 0); --固定资产净值r41
v_r41_c2 := NVL(v_r39_c2, 0) + NVL(v_r40_c2, 0);
SELECT SUM(result_1) --减:固定资产减值准备r42
INTO v_r42_c1
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1505' AND period_num = v_period_min_num;
SELECT SUM(result_2) --减:固定资产减值准备r42
INTO v_r42_c2
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1505' AND period_num = v_month;
v_r43_c1 := NVL(v_r41_c1, 0) + NVL(v_r42_c1, 0); --固定资产净额=固定资产净值+减:固定资产减值准备r43
v_r43_c2 := NVL(v_r41_c2, 0) + NVL(v_r42_c2, 0);
SELECT SUM(result_1) --工程物资r44
INTO v_r44_c1
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1601' AND period_num = v_period_min_num;
SELECT SUM(result_2) --工程物资r44
INTO v_r44_c2
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1601' AND period_num = v_month;
SELECT SUM(result_1) --在建工程-在建工程减值准备r45
INTO v_r45_c1
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
(SUBSTR(standard_code, 1, 4) = '1603' OR
SUBSTR(standard_code, 1, 4) = '1605') AND period_num = v_period_min_num;
SELECT SUM(result_2) --在建工程-在建工程减值准备r45
INTO v_r45_c2
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
(SUBSTR(standard_code, 1, 4) = '1603' OR
SUBSTR(standard_code, 1, 4) = '1605') AND period_num = v_month;
SELECT SUM(result_1) --固定资产清理r46
INTO v_r46_c1
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1701' AND period_num = v_period_min_num;
SELECT SUM(result_2) --固定资产清理r46
INTO v_r46_c2
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
SUBSTR(standard_code, 1, 4) = '1701' AND period_num = v_month;
v_r50_c1 := NVL(v_r39_c1, 0) + NVL(v_r40_c1, 0) --固定资产合计r50
+ NVL(v_r42_c1, 0) + NVL(v_r44_c1, 0) + NVL(v_r45_c1, 0) +
NVL(v_r46_c1, 0);
v_r50_c2 := NVL(v_r39_c2, 0) + NVL(v_r40_c2, 0) + NVL(v_r42_c2, 0) +
NVL(v_r44_c2, 0) + NVL(v_r45_c2, 0) + NVL(v_r46_c2, 0);
SELECT SUM(result_1) --无形资产-无形资产减值准备r51
INTO v_r51_c1
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books_id = p_sob_id AND
(SUBSTR(standard_code, 1, 4) = '1801' OR
SUBSTR(standard_code, 1, 4) = '1805') AND period_num = v_period_min_num;
SELECT SUM(result_2) --无形资产-无形资产减值准备r51
INTO v_r51_c2
FROM xxafx_afx_bs
WHERE currency_code = p_currency_code AND set_of_books