CREATE OR REPLACE PACKAGE BODY PG_FIN_REPORT IS
--ACCYEARMONTH 核算年
--CURRENTMONTH 核算月
--USERID 用户id
PROCEDURE SP_INNER_REPORT_REV(CURRENTYEAR CHAR,
CURRENTMONTH CHAR,
USERID NUMBER,
SP_V_RESULT_COUNT OUT NUMBER) AS
BATCH_ID NUMBER; --批次ID
ACC_YEARMONTH CHAR(8);
P_BATCH_ID NUMBER;
V_ERRORCODE NUMBER;
V_ERRORTEXT VARCHAR2(4000);
--生成财务核算报表
BEGIN
SP_V_RESULT_COUNT := 0;
BATCH_ID := 0;
--核算年月
ACC_YEARMONTH := CONCAT(CURRENTYEAR, CURRENTMONTH);
--获取收入报表批次ID
SELECT COUNT(1)
INTO BATCH_ID
FROM TFIN_INNER_REVBATCH T
WHERE T.ACC_YEAR_MONTH = ACC_YEARMONTH
AND T.IS_DELETE = 0;
--生成核算报表
IF BATCH_ID > 0 THEN
--如果存在数据,作废
SELECT T.BATCH_ID
INTO P_BATCH_ID
FROM TFIN_INNER_REVBATCH T
WHERE T.ACC_YEAR_MONTH = ACC_YEARMONTH
AND T.IS_DELETE = 0;
--删除明细
UPDATE TFIN_INNER_REVREPORT T
SET T.IS_DELETE = 1,
T.LAST_OPERATE_ID = USERID,
T.LAST_OPERATE_TIME = SYSDATE
WHERE T.BATCH_ID = P_BATCH_ID;
SP_V_RESULT_COUNT := SP_V_RESULT_COUNT + SQL%ROWCOUNT;
--删除批次
UPDATE TFIN_INNER_REVBATCH T
SET T.IS_DELETE = 1,
T.LAST_OPERATE_ID = USERID,
T.LAST_OPERATE_TIME = SYSDATE
WHERE T.ACC_YEAR_MONTH = ACC_YEARMONTH;
SP_V_RESULT_COUNT := SP_V_RESULT_COUNT + SQL%ROWCOUNT;
----添加基础数据start 20190131
--删除基础数据明细
UPDATE TFIN_INNER_REVBASE T
SET T.IS_DELETE = 1,
T.LAST_OPERATE_ID = USERID,
T.LAST_OPERATE_TIME = SYSDATE
WHERE T.POSTING_DATE = TO_NUMBER(ACC_YEARMONTH);
SP_V_RESULT_COUNT := SP_V_RESULT_COUNT + SQL%ROWCOUNT;
END IF;
--新增批次数据
SELECT SEQ_TFIN_INNER_REVBATCH.NEXTVAL INTO BATCH_ID FROM DUAL;
---添加基础数据start
INSERT INTO TFIN_INNER_REVBASE
(REVBASE_ID,
BATCH_ID,
DEP_ID,
GROUP_ID,
DEP_NAME,
GROUP_NAME,
POSTING_DATE,
REPORT_TOTAL_FEE,
MAN_FEE,
OTHER_FEE,
INST_FEE,
CREATE_ID,
CREATE_TIME)
SELECT SEQ_TFIN_INNER_REVBASE.NEXTVAL,
BATCH_ID,
VTT.DEP_ID,
VTT.GROUP_ID,
VTT.DEP_NAME,
VTT.GROUP_NAME,
VTT.POSTING_DATE,
VTT.REPORT_TOTAL_FEE, --本期收入
VTT.MAN_FEE,
VTT.OTHER_MAN_FEE,
VTT.INST_FEE,
USERID,
SYSDATE
FROM OMS_V3.VW_FIN_REV_REPORT VTT
WHERE VTT.POSTING_DATE = TO_NUMBER(ACC_YEARMONTH);
SP_V_RESULT_COUNT := SP_V_RESULT_COUNT + SQL%ROWCOUNT;
---添加基础数据end
--产品新的批次ID
INSERT INTO TFIN_INNER_REVBATCH
(BATCH_ID,
BATCH_NAME,
ACC_YEAR_MONTH,
IS_LOCK,
IS_DELETE,
CREATE_ID,
CREATE_TIME,
LAST_OPERATE_ID,
LAST_OPERATE_TIME)
VALUES
(BATCH_ID,
CONCAT('revreport-', ACC_YEARMONTH),
ACC_YEARMONTH,
0,
0,
USERID,
SYSDATE,
NULL,
NULL);
SP_V_RESULT_COUNT := SP_V_RESULT_COUNT + SQL%ROWCOUNT;
--写入明细表
IF CURRENTMONTH = '01' THEN
--每年的一月 除分公司与BPO公司
INSERT INTO TFIN_INNER_REVREPORT
(REVREPORT_ID,
BATCH_ID,
DEP_ID,
GROUP_ID,
ACC_UNIT_ID,
ACC_UNIT_NAME,
PROFITNORM_VALUE,
THIS_REVENUE,
INVESTMENT_REVENUE,
TAX,
THISREVENUE_TOTAL,
YEARSREVENUE_TOTAL,
IS_DELETE,
CREATE_ID,
CREATE_TIME,
LAST_OPERATE_ID,
LAST_OPERATE_TIME)
SELECT SEQ_TFIN_INNER_REVREPORT.NEXTVAL,
BATCH_ID,
T3.DEP_ID,
T3.GROUP_ID,
T1.UNIT_ID,
T1.ACC_UNIT_NAME,
T2.PROFITNORM_VALUE,
NVL(T3.TOTAL_FEE, 0),
0,
0,
NVL(T3.TOTAL_FEE, 0),
NVL(T3.TOTAL_FEE, 0),
0,
USERID,
SYSDATE,
NULL,
NULL
FROM TFIN_INNER_ACCOUNT_UNIT T1
LEFT JOIN TFIN_PROFIT_PLAN T2
ON T1.UNIT_ID = T2.UNIT_ID
AND T2.INDEX_YEAR = CURRENTYEAR
LEFT JOIN (SELECT TT.DEP_ID,
TT.GROUP_ID,
TT.DEP_NAME,
TT.GROUP_NAME,
TT.POSTING_DATE,
TT.REPORT_TOTAL_FEE TOTAL_FEE --本期收入
FROM TFIN_INNER_REVBASE TT
WHERE TT.POSTING_DATE = TO_NUMBER(ACC_YEARMONTH)
AND TT.IS_DELETE = 0) T3
ON T1.ORG_ID = T3.GROUP_ID
WHERE T1.IS_DELETE = 0
AND T1.ORG_ID NOT IN (1, 2058, 2059)
/* AND T1.ORG_TYPE = 2*/
; ---小组统计
SP_V_RESULT_COUNT := SP_V_RESULT_COUNT + SQL%ROWCOUNT;
---增加分公司逻辑start
--每年的一月
INSERT INTO TFIN_INNER_REVREPORT
(REVREPORT_ID,
BATCH_ID,
DEP_ID,
GROUP_ID,
ACC_UNIT_ID,
ACC_UNIT_NAME,
PROFITNORM_VALUE,
THIS_REVENUE,
INVESTMENT_REVENUE,
TAX,
THISREVENUE_TOTAL,
YEARSREVENUE_TOTAL,
IS_DELETE,
CREATE_ID,
CREATE_TIME,
LAST_OPERATE_ID,
LAST_OPERATE_TIME)
SELECT SEQ_TFIN_INNER_REVREPORT.NEXTVAL,
BATCH_ID,
T3.DEP_ID,
T3.GROUP_ID,
T1.UNIT_ID,
T1.ACC_UNIT_NAME,
T2.PROFITNORM_VALUE,
NVL(T3.TOTAL_FEE, 0) + NVL(COM.TOTAL_FEE, 0),
0,
0,
NVL(T3.TOTAL_FEE, 0) + NVL(COM.TOTAL_FEE, 0),
NVL(T3.TOTAL_FEE, 0) + NVL(COM.TOTAL_FEE, 0),
0,
USERID,
SYSDATE,
NULL,
NULL
FROM TFIN_INNER_ACCOUNT_UNIT T1
LEFT JOIN TFIN_PROFIT_PLAN T2
ON T1.UNIT_ID = T2.UNIT_ID
AND T2.INDEX_YEAR = CURRENTYEAR
--分公司以及需要体现在分公司的核算单位:分公司,人事,对外委托组,
LEFT JOIN (SELECT SUM(B.REPORT_TOTAL_FEE) TOTAL_FEE,
1 DEP_ID,
1 GROUP_ID
FROM TFIN_INNER_REVBASE B
WHERE B.GROUP_ID IN (1, 42, 307, 21) --分公司,人事,对外委托组,
AND B.IS_DELETE = 0
AND B.POSTING_DATE = TO_NUMBER(ACC_YEARMONTH)) COM
ON COM.GROUP_ID = T1.ORG_ID
--BPO部分的其他收入
LEFT JOIN (SELECT SUM(TT.OTHER_FEE) TOTAL_FEE,
1 DEP_ID,
1 GROUP_ID
FROM TFIN_INNER_REVBASE TT
WHERE TT.DEP_ID = 2058 --BPO公司
AND TT.IS_DELETE = 0
AND TT.POSTING_DATE = TO_NUMBER(ACC_YEARMONTH)) T3
ON T3.GROUP_ID = T1.ORG_ID
WHERE T1.ORG_ID = 1
AND T1.IS_DELETE = 0;
SP_V_RESULT_COUNT := SP_V_RESULT_COUNT + SQL%ROWCOUNT;
---增加分公司逻辑end
---增加BPO公司逻辑start
--每年的一月
INSERT INTO TFIN_INNER_REVREPORT
(REVREPORT_ID,
BATCH_ID,
DEP_ID,
GROUP_ID,
ACC_UNIT_ID,
ACC_UNIT_NAME,
PROFITNORM_VALUE,
THIS_REVENUE,
INVESTMENT_REVENUE,
TAX,
THISREVENUE_TOTAL,
YEARSREVENUE_TOTAL,
IS_DELETE,
CREATE_ID,
CREATE_TIME,
LAST_OPERATE_ID,
LAST_OPERATE_TIME)
SELECT SEQ_TFIN_INNER_REVREPORT.NEXTVAL,
BATCH_ID,
T3.DEP_ID,
T3.GROUP_ID,
T1.UNIT_ID,
T1.ACC_UNIT_NAME,
T2.PROFITNORM_VALUE,
NVL(T3.TOTAL_FEE, 0),
0,
0,
NVL(T3.TOTAL_FEE, 0),
NVL(T3.TOTAL_FEE, 0),
0,
USERID,
SYSDATE,
NULL,
NULL
FROM TFIN_INNER_ACCOUNT_UNIT T1
LEFT JOIN TFIN_PROFIT_PLAN T2
ON T1.UNIT_ID = T2.UNIT_ID
AND T2.INDEX_YEAR = CURRENTYEAR
--BPO部分的管理费+利息收入
LEFT JOIN (SELECT SUM(TT.MAN_FEE) + SUM(TT.INST_FEE) TOTAL_FEE,
2058 DEP_ID,
2058 GROUP_ID
FROM TFIN_INNER_REVBASE TT
WHERE TT.BATCH_ID = BATCH_ID
AND TT.DEP_ID = 2058 --BPO公司
AND TT.IS_DELETE = 0
AND TT.POSTING_DATE = TO_NUMBER(ACC_YEARMONTH)) T3
ON T3.GROUP_ID = T1.ORG_ID
WHERE T1.ORG_ID = 2058
AND T1.IS_DELETE = 0;
SP_V_RESULT_COUNT := SP_V_RESULT_COUNT + SQL%ROWCOUNT;
---增加BPO公司逻辑end
ELSE
--其他月份除分公司与BPO公司
INSERT INTO TFIN_INNER_REVREPORT
(REVREPORT_ID,
BATCH_ID,
DEP_ID,
GROUP_ID,
ACC_UNIT_ID,
ACC_UNIT_NAME,
PROFITNORM_VALUE,
THIS_REVENUE,
INVESTMENT_REVENUE,
TAX,
THISREVENUE_TOTAL,
YEARSREVENUE_TOTAL,
IS_DELETE,
CREATE_ID,
CREATE_TIME,
LAST_OPERATE_ID,
LAST_OPERATE_TIME)
SELECT SEQ_TFIN_INNER_REVREPORT.NEXTVAL,
BATCH_ID,
T3.DEP_ID,
T3.GROUP_ID,
T1.UNIT_ID,
T1.ACC_UNIT_NAME,
T2.PROFITNORM_VALUE,
NVL(T3.TOTAL_FEE, 0),
0,
0,
NVL(T3.TOTAL_FEE, 0),
NVL(T3.TOTAL_FEE, 0) +
(SELECT NVL(SUM(NVL(T4.YEARSREVENUE_TOTAL, 0)), 0)
FROM TFIN_INNER_REVREPORT T4
JOIN TFIN_INNER_REVBATCH T5
ON T4.BATCH_ID = T5.BATCH_ID
WHERE T4.IS_DELETE = 0
AND T4.STATUS = 0
AND T5.ACC_YEAR_MONTH = TO_NUMBER(ACC_YEARMONTH) - 1
AND T4.ACC_UNIT_ID = T1.UNIT_ID),
0,
USERID,
SYSDATE,
NULL,
NULL
FROM TFIN_INNER_ACCOUNT_UNIT T1
LEFT JOIN TFIN_PROFIT_PLAN T2
ON T1.UNIT_ID = T2.UNIT_ID
AND T2.INDEX_YEAR = CURRENTYEAR
LEFT JOIN (SELECT TT.DEP_ID,
TT.GROUP_ID,
TT.DEP_NAME,
TT.GROUP_NAME,
TT.POSTING_DATE,
TT.REPORT_TOTAL_FEE TOTAL_FEE --本期收入
FROM TFIN_INNER_REVBASE TT
WHERE TT.POSTING_DATE = TO_NUMBER(ACC_YEARMONTH)
AND TT.IS_DELETE = 0) T3
ON T3.GROUP_ID = T1.ORG_ID
WHERE T1.IS_DELETE = 0
AND T1.ORG_ID NOT IN (1, 2058, 2059)
/* AND T1.ORG_TYPE = 2*/
; ---按小组统计
SP_V_RESULT_COUNT := SP_V_RESULT_COUNT + SQL%ROWCOUNT;
---增加分公司逻辑start
--其他月份
INSERT INTO TFIN_INNER_REVREPORT
(REVREPORT_ID,
BATCH_ID,
DEP_ID,
GROUP_ID,
ACC_UNIT_ID,
ACC_UNIT_NAME,
PROFITNORM_VALUE,
THIS_REVENUE,
INVESTMENT_REVENUE,
TAX,
THISREVENUE_TOTAL,
YEARSREVENUE_TOTAL,
IS_DELETE,
CREATE_ID,
CREATE_TIME,
LAST_OPERATE_ID,
LAST_OPERATE_TIME)
SELECT SEQ_TFIN_INNER_REVREPORT.NEXTVAL,
BATCH_ID,
T3.DEP_ID,
T3.GROUP_ID,
T1.UNIT_ID,
T1.ACC_UNIT_NAME,
T2.PROFITNORM_VALUE,
NVL(T3.TOTAL_FEE, 0) + NVL(COM.TOTAL_FEE, 0),
0,
0,
NVL(T3.TOTAL_FEE, 0) + NVL(COM.TOTAL_FEE, 0),
NVL(T3.TOTAL_FEE, 0) + NVL(COM.TOTAL_FEE, 0) +
(SELECT NVL(SUM(NVL(T4.YEARSREVENUE_TOTAL, 0)), 0)
FROM TFIN_INNER_REVREPORT T4
JOIN TFIN_INNER_REVBATCH T5
ON T4.BATCH_ID = T5.BATCH_ID
WHERE T4.IS_DELETE = 0
AND T5.ACC_YEAR_MONTH = TO_NUMBER(ACC_YEARMONTH) - 1
AND T4.ACC_UNIT_ID = T1.UNIT_ID),
0,
USERID,
SYSDATE,
NULL,
NULL
FROM TFIN_INNER_ACCOUNT_UNIT T1
JOIN TFIN_PROFIT_PLAN T2
ON T1.UNIT_ID = T2.UNIT_ID
AND T2.IS_DELETE = 0
AND T2.INDEX_YEAR = CURRENTYEAR
--分公司以及需要体现在分公司的核算单位:分公司,人事,对外委托组,互联网
LEFT JOIN (SELECT SUM(B.REPORT_TOTAL_FEE) TOTAL_FEE,
1 DEP_ID,
1 GROUP_ID
FROM TFIN_INNER_REVBASE B
WHERE B.GROUP_ID IN (1, 42, 307, 21) --分公司,人事,对外委托组,互联网
AND B.IS_DELETE = 0
AND B.POSTING_DATE = TO_NUMBER(ACC_YEARMONTH)) COM
ON COM.GROUP_ID = T1.ORG_ID
--BPO部分的其他收入
LEFT JOIN (SELECT SUM(TT.OTHER_FEE) TOTAL_FEE,
1 DEP_ID,
1 GROUP_ID
FROM TFIN_INNER_REVBASE TT
WHERE TT.DEP_ID = 2058 --BPO公司
AND TT.IS_DELETE = 0
AND TT.POSTING_DATE = TO_NUMBER(ACC_YEARMONTH)) T3
ON T3.GROUP_ID = T1.ORG_ID
WHERE T1.ORG_ID = 1
AND T1.IS_DELETE = 0;
SP_V_RESULT_COUNT := SP_V_RESULT_COUNT + SQL%ROWCOUNT;
---增加分公司逻辑end
---增加BPO公司逻辑start
--其他月份
INSERT INTO TFIN_INNER_REVREPORT
(REVREPORT_ID,
BATCH_ID,
DEP_ID,
GROUP_ID,
ACC_UNIT_ID,
ACC_UNIT_NAME,
PROFITNORM_VALUE,
THIS_REVENUE,
INVESTMENT_REVENUE,
TAX,
THISREVENUE_TOTAL,
YEARSREVENUE_TOTAL,
IS_DELETE,
CREATE_ID,
CREATE_TIME,
LAST_OPERATE_ID,
LAST_OPERATE_TIME)
SELECT SEQ_TFIN_INNER_REVREPORT.NEXTVAL,
BATCH_ID,
T3.DEP_ID,
T3.GROUP_ID,
T1.UNIT_ID,
T1.ACC_UNIT_NAME,
T2.PROFITNORM_VALUE,
NVL(T3.TOTAL_FEE, 0),
0,
0,
NVL(T3.TOTAL_FEE, 0),
NVL(T3.TOTAL_FEE, 0) +
(SELECT NVL(SUM(NVL(T4.YEARSREVENUE_TOTAL, 0)), 0)
FROM TFIN_INNER_REVREPORT T4
JOIN TFIN_INNER_REVBATCH T5
ON T4.BATCH_ID = T5.BATCH_ID
WHERE T4.IS_DELETE = 0
AND T5.ACC_YEAR_MONTH = TO_NUMBER(ACC_YEARMONTH) - 1
AND T4.ACC_UNIT_ID = T1.UNIT_ID),
0,
USERID,
SYSDATE,
NULL,
NULL
FROM TFIN_INNER_ACCOUNT_UNIT T1
LEFT JOIN TFIN_PROFIT_PLAN T2
ON T1.UNIT_ID = T2.UNIT_ID
AND T2.INDEX_YEAR = CURRENTYEAR
--BPO部分的管理费+利息收入
LEFT JOIN (SELECT SUM(TT.MAN_FEE) + SUM(TT.INST_FEE) TOTAL_FEE,
2058 DEP_ID,
2058 GROUP_ID
FROM TFIN_INNER_REVBASE TT
WHERE TT.BATCH_ID = BATCH_ID
AND TT.DEP_ID = 2058 --BPO公司
AND TT.IS_DELETE = 0
AND TT.POSTING_DATE = TO_NUMBER(ACC_YEARMONTH)) T3
ON T3.GROUP_ID = T1.ORG_ID
WHERE T1.ORG_ID = 2058
AND T1.IS_DELETE = 0;
SP_V_RESULT_COUNT := SP_V_RESULT_COUNT + SQL%ROWCOUNT;
---增加BPO公司逻辑end
END IF;
--结束
COMMIT;
DBMS_OUTPUT.PUT_LINE(SP_V_RESULT_COUNT);
EXCEPTION
WHEN OTHERS THEN
BEGIN
ROLLBACK;
V_ERRORCODE := SQLCODE;
V_ERRORTEXT := SUBSTR(SQLERRM, 1, 200);
OMS_V3.SP_FIN_WRITEOFFS_LOG(V_ERRORCODE, 110, V_ERRORTEXT);
DBMS_OUTPUT.PUT_LINE(0);
END;
END SP_INNER_REPORT_REV;
-----成本核算--------------------------20180214------
PROCEDURE SP_INNER_REPORT_COST(CURRENTYEAR CHAR,
CURRENTMONTH CHAR,
USERID NUMBER,
SP_V_RESULT_COUNT OUT NUMBER) AS
BATCH_ID NUMBER; --批次ID
ACC_YEARMONTH CHAR(8);
P_BATCH_ID NUMBER;
V_ERRORCODE NUMBER;
V_ERRORTEXT VARCHAR2(4000);
--生成财务核算报表
BEGIN
SP_V_RESULT_COUNT := 0;
BATCH_ID := 0;
--核算年月
ACC_YEARMONTH := CONCAT(CURRENTYEAR, CURRENTMONTH);
--获取收入报表批次ID
SELECT COUNT(1)
INTO BATCH_ID
FROM TFIN_INNER_COSTBATCH T
WHERE T.ACC_YEAR_MONTH = ACC_YEARMONTH
AND T.IS_DELETE = 0;
--生成核算报表
IF BATCH_ID > 0 THEN
--如果存在数据,作废
SELECT T.BATCH_ID
INTO P_BATCH_ID
FROM TFIN_INNER_COSTBATCH T
WHERE T.ACC_YEAR_MONTH = ACC_YEARMONTH
AND T.IS_DELETE = 0;
--删除明细
UPDATE TFIN_INNER_COSTREPORT T
SET T.IS_DELETE = 1,
T.LAST_OPERATE_ID = USERID,
T.LAST_OPERATE_TIME = SYSDATE
WHERE T.BATCH_ID = P_BATCH_ID;
SP_V_RESULT_COUNT := SP_V_RESULT_COUNT + SQL%ROWCOUNT;
--删除批次
UPDATE TFIN_INNER_COSTBATCH T
SET T.IS_DELETE = 1,
T.LAST_OPERATE_ID = USERID,
T.LAST_OPERATE_TIME = SYSDATE
WHERE T.ACC_YEAR_MONTH = ACC_YEARMONTH;
SP_V_RESULT_COUNT := SP_V_RESULT_COUNT + SQL%ROWCOUNT;
----添加基础数据start 20190214
--删除基础数据明细
UPDATE TFIN_INNER_COSTBASE T
SET T.IS_DELETE = 1,
T.LAST_OPERATE_ID = USERID,
T.LAST_OPERATE_TIME = SYSDATE
WHERE T.POSTING_DATE = TO_NUMBER(ACC_YEARMONTH);
SP_V_RESULT_COUNT := SP_V_RESULT_COUNT + SQL%ROWCOUNT;
END IF;
--新增批次数据
SELECT SEQ_INNER_COSTBATCH.NEXTVAL INTO BATCH_ID FROM DUAL;
---添加基础数据start
INSERT INTO TFIN_INNER_COSTBASE
(COSTBASE_ID,
DEP_ID,
GROUP_ID,
DEP_NAME,
GROUP_NAME,
POSTING_DATE,
SALARY_FEE,
TC_FEE,
SHEBAO_FEE,
JBYL_FEE,
GJJ_FEE,
QUNUAN_FEE,
SAVE_FEE,
TANQIN_FEE,
ADDEDRATE_FEE,
BCYL_FEE,
EMS_FEE,
CONSIGN_FEE,
HUODONG_FEE,
ZJZY_FEE,
BAN_ZHENG_FEE,
TJ_FEE,
SALARY_COST_FEE,
MOVIE_FEE,
BT_FEE,
JITI_FEE,
IS_DELETE,
CREATE_ID,
CREATE_TIME,
REMARK,
BATCH_ID)
SELECT SEQ_INNER_COSTBASE.NEXTVAL,
DEP_ID,
GROUP_ID,
DEP_NAME,
GROUP_NAME,
ACC_YEARMONTH,
SALARY_FEE,
TC_FEE,
SHEBAO_FEE,
YILIAO_FEE,
GJJ_FEE,
QUNUAN_FEE,
SAVE_FEE,
TANQIN_FEE,
ADDEDRATE_FEE,
BCYL_FEE,
EMS_FEE,
CONSIGN_FEE,
HUODONG_FEE,
ZJZY_FEE,
BAN_ZHENG_FEE,
TJ_FEE,
SALARY_COST_FEE,
MOVIE_FEE,
BT_FEE,
JITI_FEE,
0,
USERID,
SYSDATE,
'基础数据',
1
FROM (SELECT DEP_ID,
GROUP_ID,
DEP_NAME,
GROUP_NAME,
SUM(SALARY_FEE) SALARY_FEE,
SUM(TC_FEE) TC_FEE,
SUM(SHEBAO_FEE) SHEBAO_FEE,
SUM(YILIAO_FEE) YILIAO_FEE,
SUM(GJJ_FEE) GJJ_FEE,
SUM(QUNUAN_FEE) QUNUAN_FEE,
SUM(SAVE_FEE) SAVE_FEE,
SUM(TANQIN_FEE) TANQIN_FEE,
SUM(ADDEDRATE_FEE) ADDEDRATE_FEE,
SUM(BCYL_FEE) BCYL_FEE,
SUM(EMS_FEE) EMS_FEE,
SUM(CONSIGN_FEE) CONSIGN_FEE,
SUM(HUODONG_FEE) HUODONG_FEE,
0 ZJZY_FEE, --资金占用费
SUM(BAN_ZHENG_FEE) BAN_ZHENG_FEE,
SUM(TJ_FEE) TJ_FEE,
SUM(SALARY_COST_FEE) SALARY_COST_FEE,
SUM(MOVIE_FEE) MOVIE_FEE,
SUM(BT_FEE) BT_FEE,
SUM(JITI_FEE) JITI_FEE
FROM OMS_V3.VW_FIN_COST_ACCOUNT
WHERE TO_CHAR(TO_DATE(POSTING_DATE, 'yyyy-mm-dd'), 'yyyymm') =
TO_NUMBER(ACC_YEARMONTH)
GROUP BY DEP_ID, DEP_NAME, GROUP_ID, GROUP_NAME);
SP_V_RESULT_COUNT := SP_V_RESULT_COUNT + SQL%ROWCOUNT;
---添加基础数据end
--产品新的批次ID
INSERT INTO TFIN_INNER_COSTBATCH
(BATCH_ID,
BATCH_NAME,
ACC_YEAR_MONTH,
IS_LOCK,
IS_DELETE,
CREATE_ID,
CREATE_TIME,
LAST_OPERATE_ID,
LAST_OPERATE_TIME)
VALUES
(BATCH_ID,
CONCAT('revreport-', ACC_YEARMONTH),
ACC_YEARMONTH,
0,
0,
USERID,
SYSDATE,
NULL,
NULL);
SP_V_RESULT_COUNT := SP_V_RESULT_COUNT + SQL%ROWCOUNT;
----批次结束
IF CURRENTMONTH = '01' THEN
INSERT INTO TFIN_INNER_COSTREPORT
(COSTREPORT_ID,
BATCH_ID,
DEP_ID,
GROUP_ID,
ACC_UNIT_ID,
ACC_UNIT_NAME,
SALARY_FEE,
SHEBAO_FEE,
JBYL_FEE,
GJJ_FEE,
QUNUAN_FEE,
SAVE_FEE,
TANQIN_FEE,
BCYL_FEE,
EMS_FEE,
CONSIGN_FEE,
HUODONG_FEE,
FUND_OCCUPY_FEE, ---资金占用费
THISCOSTING_TOTAL,
YEARSCOSTING_TOTAL,
IS_DELETE,
CREATE_ID,
CREATE_TIME,
STATUS)
SELECT SEQ_INNER_COSTREPORT.NEXTVAL,
BATCH_ID, ---批次ID
BASE.DEP_ID,
BASE.GROUP_ID,
UNIT.UNIT_ID,
UNIT.ACC_UNIT_NAME,
SALARY_FEE, --雇员工资
BASE.SHEBAO_FEE, ---社保
BASE.JBYL_FEE, ---基本医疗
BASE.GJJ_FEE, ---公积金
BASE.QUNUAN_FEE, ---取暖
BASE.SAVE_FEE, ---存档费
BASE.TANQIN_FEE, ---探亲费
BASE.BCYL_FEE, --- 补充医疗
BASE.EMS_FEE, ---快递费
BASE.CONSIGN_FEE, ---委托服务费
BASE.HUODONG_FEE, ---雇员活动费
BASE.ZJZY_FEE, ---资金占用费
BASE.TOTAL_FEE,
BASE.TOTAL_FEE,
0, --是否删除
USERID, --创建人
SYSDATE,
0 ---修改状态
FROM TFIN_INNER_ACCOUNT_UNIT UNIT
LEFT JOIN VM_TFIN_INNER_COSTBASE BASE
ON BASE.GROUP_ID = UNIT.ORG_ID
AND BASE.TOTAL_FEE <> 0
AND UNIT.IS_DELETE = 0
WHERE BASE.POSTING_DATE = TO_NUMBER(ACC_YEARMONTH);
SP_V_RESULT_COUNT := SP_V_RESULT_COUNT + SQL%ROWCOUNT;
ELSE
INSERT INTO TFIN_INNER_COSTREPORT
(COSTREPORT_ID,
BATCH_ID,
DEP_ID,
GROUP_ID,
ACC_UNIT_ID,
ACC_UNIT_NAME,
SALARY_FEE,
SHEBAO_FEE,
JBYL_FEE,
GJJ_FEE,
QUNUAN_FEE,
SAVE_FEE,
TANQIN_FEE,
BCYL_FEE,
EMS_FEE,
CONSIGN_FEE,
HUODONG_FEE,
FUND_OCCUPY_FEE, ---资金占用费
THISCOSTING_TOTAL,
YEARSCOSTING_TOTAL,
IS_DELETE,
CREATE_ID,
CREATE_TIME,
STATUS)
SELECT SEQ_INNER_COSTREPORT.NEXTVAL,
BATCH_ID, ---批次ID
BASE.DEP_ID,
BASE.GROUP_ID,
UNIT.UNIT_ID,
UNIT.ACC_UNIT_NAME,
SALARY_FEE, --雇员工资
BASE.SHEBAO_FEE, ---社保
BASE.JBYL_FEE, ---基本医疗
BASE.GJJ_FEE, ---公积金
BASE.QUNUAN_FEE, ---取暖
BASE.SAVE_FEE, ---存档费
BASE.TANQIN_FEE, ---探亲费
BASE.BCYL_FEE, --- 补充医疗
BASE.EMS_FEE, ---快递费
BASE.CONSIGN_FEE, ---委托服务费
BASE.HUODONG_FEE, ---雇员活动费
BASE.ZJZY_FEE, ---资金占用费
BASE.TOTAL_FEE,
BASE.TOTAL_FEE +
(SELECT NVL(SUM(NVL(T4.THISCOSTING_TOTAL, 0)), 0)
FROM TFIN_INNER_COSTREPORT T4
JOIN TFIN_INNER_COSTBATCH T5
ON T4.BATCH_ID = T5.BATCH_ID
WHERE T4.IS_DELETE = 0
AND T5.ACC_YEAR_MONTH = TO_NUMBER(ACC_YEARMONTH) - 1
AND T4.ACC_UNIT_ID = UNIT.UNIT_ID),
0, --是否删除
USERID, --创建人
SYSDATE,
0 ---修改状态
FROM TFIN_INNER_ACCOUNT_UNIT UNIT
LEFT JOIN VM_TFIN_INNER_COSTBASE BASE
ON BASE.GROUP_ID = UNIT.ORG_ID
AND BASE.TOTAL_FEE <> 0
AND UNIT.IS_DELETE = 0
WHERE BASE.POSTING_DATE = TO_NUMBER(ACC_YEARMONTH);
SP_V_RESULT_COUNT := SP_V_RESULT_COUNT + SQL%ROWCOUNT;
END IF;
--结束
COMMIT;
DBMS_OUTPUT.PUT_LINE(SP_V_RESULT_COUNT);
EXCEPTION
WHEN OTHERS THEN
BEGIN
ROLLBACK;
V_ERRORCODE := SQLCODE;
V_ERRORTEXT := SUBSTR(SQLERRM, 1, 200);
OMS_V3.SP_FIN_WRITEOFFS_LOG(V_ERRORCODE, 110, V_ERRORTEXT);
DBMS_OUTPUT.PUT_LINE(0);
END;
END SP_INNER_REPORT_COST;
END PG_FIN_REPORT;