PROCEDURE P_IA40LTXDYBFCL(PRM_AAZ166 IN VARCHAR2, --人员待遇补扣发事件ID
PRM_AAC001 IN VARCHAR2, --个人编号
PRM_AAB001 IN VARCHAR2, --单位编号
PRM_AAE140 IN VARCHAR2, --险种类型
PRM_AAA077 IN VARCHAR2, --补扣发业务类型
PRM_AAE161 IN VARCHAR2, --补发扣发原因
PRM_AAE041 IN VARCHAR2, --开始年月
PRM_AAE042 IN VARCHAR2, --终止年月
PRM_AAE058 IN VARCHAR2, --总金额
PRM_AAE011 IN VARCHAR2, --经办人
PRM_YAB003 IN VARCHAR2, --经办人经办机构
PRM_AAA078 IN VARCHAR2, --补扣发标志
PRM_AAA036 IN VARCHAR2, --待遇项目代码
PRM_AAE129 IN VARCHAR2, --核发金额
PRM_AAA027 IN VARCHAR2, --统筹区编码
PRM_AAE013 IN VARCHAR2, --备注
PRM_AAZ002 IN VARCHAR2, --业务日志ID
PRM_APPCODE OUT VARCHAR2,
PRM_ERRORMSG OUT VARCHAR2) IS
/===========变量声明 BEGIN============/
V_LSH VARCHAR2(20); --流水号
V_DATE DATE;
V_FLAG PLS_INTEGER := 0; --检查特殊工种是否重复标志
V_AAE002 NUMBER(6);
V_YAC001 NUMBER(6);
V_LASTAAA036 VARCHAR2(6);
V_BTJE NUMBER(14, 2);
V_OLDJE NUMBER(14, 2);
V_MAXAAE002 NUMBER(6);
V_JSJS NUMBER(14, 2);
V_AIC160 NUMBER(6);
v_count number;
/===========变量声明 END==============/
/*===========游标声明 BEGIN============*/
CURSOR CUR_AC61 IS
SELECT AAA036, SUM(AAE019) AAE019, nvl(A.YAC081,0) AS YAC081
FROM AC61 A, IC10 B
WHERE A.AAZ257 = B.AAZ257
AND B.AAC001 = PRM_AAC001
and a.aae100 = pkg_constants.GN_DEF_YES
AND ((B.AAE140='110' AND A.AAA036 IN ('101','103','104','111','112','210'))
OR ( B.AAE140='120' AND A.AAA036 IN ('116','117','118','119','120','121','122','123')))
AND B.AAE140=PRM_AAE140
AND V_AAE002 BETWEEN B.AIC160 AND NVL(A.AAE042, 999999)
GROUP BY AAA036, nvl(A.YAC081,0)
ORDER BY AAA036 DESC;
CURSOR CUR_AC61_1 IS
SELECT AAA036, SUM(AAE019) AAE019, nvl(A.YAC081,0) AS YAC081
FROM AC61 A, IC10 B
WHERE A.AAZ257 = B.AAZ257
AND B.AAC001 = PRM_AAC001
and a.aae100 = pkg_constants.GN_DEF_YES
AND ((B.AAE140='110' AND A.AAA036 IN ('101','102','103','104','111','112','114','210'))
OR ( B.AAE140='120' AND A.AAA036 IN ('102','116','117','118','119','120','121','122','123')))
AND B.AAE140=PRM_AAE140
AND V_AAE002 BETWEEN B.AIC160 AND NVL(A.AAE042, 999999)
GROUP BY AAA036, nvl(A.YAC081,0)
ORDER BY AAA036 DESC;
/*===========游标声明 END==============*/
BEGIN
/初始化变量/
PRM_APPCODE := PRE_ERRCODE || '.P_IA40LTXDYBFCL' ||
PKG_CONSTANTS.GN_DEF_ERR;
PRM_ERRORMSG := '';
/*==============自定义变量的初始化 BEGIN============*/
--SELECT PKG_COMMON.f_getSequence('AAZ170') INTO v_lsh FROM DUAL;
SELECT SYSDATE INTO V_DATE FROM DUAL;
/*==============自定义变量的初始化 END==============*/
/*==============代码正文============================*/
SELECT PKG_IA_COMMON.F_GETMAXAAE002(PRM_AAC001, PRM_AAE140)
INTO V_MAXAAE002
FROM DUAL;
--查询人员待遇享受开始年月V_AIC160
BEGIN
SELECT AIC160 INTO V_AIC160 FROM IC10 WHERE AAC001 = PRM_AAC001 AND AAE140=PRM_AAE140;
EXCEPTION
WHEN NO_DATA_FOUND THEN
PRM_APPCODE := PKG_CONSTANTS.GN_DEF_ERR;
PRM_ERRORMSG := '该人员在退休库中不存在';
RETURN;
END;
--补发开始年月不能早于待遇享受开始年月
IF PRM_AAE041 < V_AIC160 THEN
PRM_ERRORMSG := '补发开始年月不能早于该人员待遇享受开始年月: ' || V_AIC160 || '期!' ||
PKG_COMMON.F_GET_ERROR_LINE(DBMS_UTILITY.FORMAT_CALL_STACK);
GOTO LABEL_ERROR;
END IF;
--判断人员是否有该待遇项,如果没有,则不能补发没有的待遇项,220 代发 该项目不做限制
if nvl(prm_aaa036,'000') <> '997' and nvl(prm_aaa036,'000') <> '998' and prm_aaa036 <> '220' then
select count(1)
into v_count
from ac61
where aac001 = prm_aac001
and aae140 = PRM_AAE140
and aae100 = '1'
and prm_aae041 between aae041 and nvl(aae042, 999999)
and prm_aae042 between aae041 and nvl(aae042, 999999)
and aaa036 = prm_aaa036;--待遇项目代码
if v_count = 0 then
PRM_ERRORMSG := '该人员没有待遇项' || prm_aaa036 || ',不能补发没有的待遇项!' ||
PKG_COMMON.F_GET_ERROR_LINE(DBMS_UTILITY.FORMAT_CALL_STACK);
GOTO LABEL_ERROR;
end if;
end if;
--如果为998判断人员是否有998待遇项,如果没有,则不能补发
IF nvl(prm_aaa036,'000') = '998' then
select count(1)
into v_count
from ac61
where aac001 = prm_aac001
and aae140 = PRM_AAE140
and aae100 = '1'
and prm_aae041 between aae041 and nvl(aae042, 999999)
and prm_aae042 between aae041 and nvl(aae042, 999999)
AND ((PRM_AAE140='110' AND aaa036 IN ('101','102','103','104','111','112','114','210')) OR
(PRM_AAE140='120' AND aaa036 IN ('116', '102', '117', '118', '119', '120', '121', '122', '123')));
if v_count = 0 then
PRM_ERRORMSG := '该人员没有包含'|| prm_aaa036 ||'内容的待遇项,不能补发'|| prm_aaa036 ||'待遇项!' ||
PKG_COMMON.F_GET_ERROR_LINE(DBMS_UTILITY.FORMAT_CALL_STACK);
GOTO LABEL_ERROR;
end if;
end if;
--如果为997判断人员是否有997待遇项,如果没有,则不能补发
IF nvl(prm_aaa036,'000') = '997' then
select count(1)
into v_count
from ac61
where aac001 = prm_aac001
and aae140 = PRM_AAE140
and aae100 = '1'
and prm_aae041 between aae041 and nvl(aae042, 999999)
and prm_aae042 between aae041 and nvl(aae042, 999999)
AND ((PRM_AAE140='110' AND aaa036 IN ('101', '103', '104', '111', '112','210')) OR
(PRM_AAE140='120' AND aaa036 IN ('116', '117', '118', '119', '120', '121', '122', '123')));
if v_count = 0 then
PRM_ERRORMSG := '该人员没有包含'|| prm_aaa036 ||'内容的待遇项,不能补发'|| prm_aaa036 ||'待遇项!' ||
PKG_COMMON.F_GET_ERROR_LINE(DBMS_UTILITY.FORMAT_CALL_STACK);
GOTO LABEL_ERROR;
end if;
end if;
--写补、扣发事件
PKG_EVENTS.P_EVENTS_AC75(PRM_AAZ166, --人员待遇补扣发事件ID
NULL, --人员待遇停续发事件id
NULL, --业务日志ID
PRM_AAC001, --个人编号
NULL, --人员待遇终止事件ID
NULL, --人员待遇核定事件id
PRM_AAB001, --单位编号
PRM_AAE140, --险种类型
PRM_AAA077, --补扣发业务类型
PRM_AAE161, --补发扣发原因
PRM_AAE041, --开始年月
PRM_AAE042, --终止年月
PRM_AAE058, --总金额
PKG_CONSTANTS.AAE016_WFH, --复核标志
'0', --核定标志
NULL, --拨付事件ID
NULL, --人员应付计划事件ID
PRM_YAB003, --参保所属经办机构
PRM_AAE011, --经办人
PRM_YAB003, --经办人经办机构
V_DATE, --经办时间
PRM_AAE013, --备注
PRM_AAA027, --统筹区编码
NULL,
PRM_APPCODE, --
PRM_ERRORMSG);
IF PRM_APPCODE != PKG_CONSTANTS.GN_DEF_OK THEN
RETURN;
END IF;
--写补扣明细
V_AAE002 := PRM_AAE041;
WHILE V_AAE002 <= PRM_AAE042 LOOP
--如果待遇类别为998
IF PRM_AAA036 = '998' THEN
BEGIN
SELECT NVL(SUM(AAE019), 0)
INTO V_OLDJE
FROM AC61 A, IC10 B
WHERE A.AAZ257 = B.AAZ257
AND B.AAC001 = PRM_AAC001
and a.aae100 = pkg_constants.GN_DEF_YES
AND A.AAA036 =
DECODE(NVL(PRM_AAA036, '998'), '998', A.AAA036, PRM_AAA036)
AND V_AAE002 BETWEEN B.AIC160 AND NVL(A.AAE042, 999999)
AND ((B.AAE140 = '110' AND A.AAA036 IN ('101','102','103','104','111','112'))
OR ( B.AAE140 = '120' AND A.AAA036 IN ('102','116','117','118','119','120','121','122','123')))
AND B.AAE140 = PRM_AAE140;
IF SQL%NOTFOUND THEN
V_OLDJE := 0;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
V_OLDJE := 0;
END;
END IF;
IF PRM_AAA036 = '997' THEN
BEGIN
SELECT NVL(SUM(AAE019), 0)
INTO V_OLDJE
FROM AC61 A, IC10 B
WHERE A.AAZ257 = B.AAZ257
AND B.AAC001 = PRM_AAC001
and a.aae100 = pkg_constants.GN_DEF_YES
AND A.AAA036 =
DECODE(NVL(PRM_AAA036, '997'), '997', A.AAA036, PRM_AAA036)
AND V_AAE002 BETWEEN B.AIC160 AND NVL(A.AAE042, 999999)
AND ((B.AAE140='110' AND A.AAA036 IN ('101','103','104','111','112'))
OR ( B.AAE140='120' AND A.AAA036 IN ('116','117','118','119','120','121','122','123')))
AND B.AAE140=PRM_AAE140;
IF SQL%NOTFOUND THEN
V_OLDJE := 0;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
V_OLDJE := 0;
END;
END IF;
IF PRM_AAE129 > 0 AND PRM_AAA036 = '997' THEN
V_JSJS := PRM_AAE129;
V_BTJE := 0;
FOR C_AC61 IN CUR_AC61 LOOP
PKG_IA_COMMON.P_INSERTAC76(PRM_AAZ166, --人员待遇补扣发事件ID NUMBER (16) 2 Y Yes
PRM_AAE140, --险种类型 VARCHAR2 (6 Byte) 3 Y Yes
PRM_AAA078, --补扣发标志 VARCHAR2 (6 Byte) 4 Y Yes
V_MAXAAE002, --费款所属期 NUMBER (6) 5 Y Yes
V_AAE002, --对应费款所属期 NUMBER (6) 6 Y Yes
C_AC61.AAA036, --待遇项目代码 VARCHAR2 (6 Byte) 7 Y Yes
(V_JSJS *
ROUND(C_AC61.AAE019 / V_OLDJE, 2)), --计算金额 NUMBER (14,2) 8 Y Yes
(V_JSJS *
ROUND(C_AC61.AAE019 / V_OLDJE, 2)), --核发金额 NUMBER (14,2) 9 Y Yes
CASE WHEN PRM_AAE140 = pkg_constants.AAE140_JGYL THEN
pkg_ia_approve.f_jgylGetDyzfqd(prm_aac001, C_AC61.AAA036, pkg_constants.AAE140_JGYL) ELSE
(CASE WHEN(TO_NUMBER(C_AC61.AAA036)) > 200 OR TO_NUMBER(C_AC61.AAA036) = 999 THEN '0' ELSE '1' END)
END, --是否统筹支付 VARCHAR2 (6 Byte) 10 Y Yes
C_AC61.YAC081, --是否预支待遇 VARCHAR2 (6 Byte) 11 Y Yes
'0', --是否增发项目 VARCHAR2 (6 Byte) 12 Y Yes
PRM_APPCODE, --
PRM_ERRORMSG);
IF PRM_APPCODE != PKG_CONSTANTS.GN_DEF_OK THEN
RETURN;
END IF;
V_LASTAAA036 := C_AC61.AAA036;--待遇项目代码
END LOOP;
BEGIN
SELECT SUM(NVL(AAE129, 0))--核发金额
INTO V_BTJE
FROM AC76
WHERE AAZ166 = PRM_AAZ166--人员待遇补扣发事件id
AND AAA036 <> V_LASTAAA036--待遇项目代码
AND AAE003 = V_AAE002--费款所属期
AND AAE140 = PRM_AAE140;--险种类型
EXCEPTION
WHEN NO_DATA_FOUND THEN
V_BTJE := 0;
END;
UPDATE AC76
SET AAE128 =--计算金额
(PRM_AAE129 - NVL(V_BTJE, 0)),
AAE129 =--核发金额
(PRM_AAE129 - NVL(V_BTJE, 0))
WHERE AAZ166 = PRM_AAZ166
AND AAA036 = V_LASTAAA036
AND AAE003 = V_AAE002;
ELSIF PRM_AAE129 > 0 AND PRM_AAA036 = '998' THEN
V_JSJS := PRM_AAE129;
V_BTJE := 0;
FOR C_AC61_1 IN CUR_AC61_1 LOOP
PKG_IA_COMMON.P_INSERTAC76(PRM_AAZ166, --人员待遇补扣发事件ID NUMBER (16) 2 Y Yes
PRM_AAE140, --险种类型 VARCHAR2 (6 Byte) 3 Y Yes
PRM_AAA078, --补扣发标志 VARCHAR2 (6 Byte) 4 Y Yes
V_MAXAAE002, --费款所属期 NUMBER (6) 5 Y Yes
V_AAE002, --对应费款所属期 NUMBER (6) 6 Y Yes
C_AC61_1.AAA036, --待遇项目代码 VARCHAR2 (6 Byte) 7 Y Yes
(V_JSJS *
ROUND(C_AC61_1.AAE019 / V_OLDJE, 2)), --计算金额 NUMBER (14,2) 8 Y Yes
(V_JSJS *
ROUND(C_AC61_1.AAE019 / V_OLDJE, 2)), --核发金额 NUMBER (14,2) 9 Y Yes
CASE WHEN PRM_AAE140 = pkg_constants.AAE140_JGYL THEN
pkg_ia_approve.f_jgylGetDyzfqd(prm_aac001, C_AC61_1.AAA036, pkg_constants.AAE140_JGYL) ELSE
(CASE WHEN(TO_NUMBER(C_AC61_1.AAA036)) > 200 OR TO_NUMBER(C_AC61_1.AAA036) = 999 THEN '0' ELSE '1' END)
END, --是否统筹支付 VARCHAR2 (6 Byte) 10 Y Yes
C_AC61_1.YAC081, --是否预支待遇 VARCHAR2 (6 Byte) 11 Y Yes
'0', --是否增发项目 VARCHAR2 (6 Byte) 12 Y Yes
PRM_APPCODE, --
PRM_ERRORMSG);
IF PRM_APPCODE != PKG_CONSTANTS.GN_DEF_OK THEN
RETURN;
END IF;
V_LASTAAA036 := C_AC61_1.AAA036;
END LOOP;
BEGIN
SELECT SUM(NVL(AAE129, 0))
INTO V_BTJE
FROM AC76
WHERE AAZ166 = PRM_AAZ166
AND AAA036 <> V_LASTAAA036
AND AAE003 = V_AAE002;
EXCEPTION
WHEN NO_DATA_FOUND THEN
V_BTJE := 0;
END;
UPDATE AC76
SET AAE128 =
(PRM_AAE129 - NVL(V_BTJE, 0)),
AAE129 =
(PRM_AAE129 - NVL(V_BTJE, 0))
WHERE AAZ166 = PRM_AAZ166
AND AAA036 = V_LASTAAA036
AND AAE003 = V_AAE002;
ELSIF PRM_AAE129 > 0 AND PRM_AAA036 <> '998' AND PRM_AAA036 <> '997' THEN
PKG_IA_COMMON.P_INSERTAC76(PRM_AAZ166, --人员待遇补扣发事件ID NUMBER (16) 2 Y Yes
PRM_AAE140, --险种类型 VARCHAR2 (6 Byte) 3 Y Yes
PRM_AAA078, --补扣发标志 VARCHAR2 (6 Byte) 4 Y Yes
V_MAXAAE002, --费款所属期 NUMBER (6) 5 Y Yes
V_AAE002, --对应费款所属期 NUMBER (6) 6 Y Yes
PRM_AAA036, --待遇项目代码 VARCHAR2 (6 Byte) 7 Y Yes
PRM_AAE129, --计算金额 NUMBER (14,2) 8 Y Yes
PRM_AAE129, --核发金额 NUMBER (14,2) 9 Y Yes
CASE WHEN PRM_AAE140 = pkg_constants.AAE140_JGYL THEN
pkg_ia_approve.f_jgylGetDyzfqd(prm_aac001, PRM_AAA036, pkg_constants.AAE140_JGYL) ELSE
(CASE WHEN(TO_NUMBER(PRM_AAA036)) > 200 OR TO_NUMBER(PRM_AAA036) = 999 THEN '0' ELSE '1' END)
END, --是否统筹支付 VARCHAR2 (6 Byte) 10 Y Yes
CASE
WHEN PRM_AAA036 = '115' THEN
'1'
ELSE
'0'
END, --是否预支待遇 VARCHAR2 (6 Byte) 11 Y Yes
NULL, --是否增发项目 VARCHAR2 (6 Byte) 12 Y Yes
PRM_APPCODE, --
PRM_ERRORMSG);
IF PRM_APPCODE != PKG_CONSTANTS.GN_DEF_OK THEN
RETURN;
END IF;
END IF;
V_AAE002 := PKG_IA_COMMON.F_GETNEXTMONTH(V_AAE002, 1);
END LOOP;
UPDATE AC75 A
SET A.AAE058 =
(SELECT SUM(DECODE(B.AAA078,
PKG_CONSTANTS.AAA078_ZH,
-NVL(B.AAE129, 0),
NVL(B.AAE129, 0)))
FROM AC76 B
WHERE A.AAZ166 = B.AAZ166),
A.YID023 =
(SELECT PKG_IA_COMMON.F_GETNEXTMONTH(MAX(AAE002), 1)
FROM IB01I3
WHERE YAB003 = PRM_YAB003
AND AAE140 = PRM_AAE140)
WHERE A.AAZ166 = PRM_AAZ166
AND A.AAC001 = PRM_AAC001;
/*成功处理*/
<<LABEL_OK>>
/*给返回参数赋值*/
PRM_APPCODE := PKG_CONSTANTS.GN_DEF_OK;
PRM_ERRORMSG := '';
RETURN;
/*处理失败*/
<<LABEL_ERROR>>
/*给返回参数赋值*/
IF PRM_APPCODE = PKG_CONSTANTS.GN_DEF_OK THEN
PRM_APPCODE := PRE_ERRCODE || '.P_IA40LTXDYBFCL' ||
PKG_CONSTANTS.GN_DEF_ERR;
END IF;
RETURN;
EXCEPTION
WHEN OTHERS THEN
PRM_APPCODE := PKG_CONSTANTS.GN_DEF_ERR;
PRM_ERRORMSG := '数据库错误:' || SQLERRM ||
PKG_COMMON.F_GET_ERROR_LINE(DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
RETURN;
END P_IA40LTXDYBFCL;