重新生成IE02

  1  procedure ReBuild_IE02(
  2               pi_aac001 in  number,
  3               po_fhz    out varchar2,
  4               po_msg    out varchar2)
  5   is
  6     type typ_tab_ie02 is table of ie02%rowtype index by binary_integer;
  7     type typ_rec_InterestRate is record(
  8              YearRate  number(8, 6),
  9              MonthRate number(7, 6)
 10          );
 11     type typ_tab_InterestRate is table of typ_rec_InterestRate index by binary_integer;
 12 
 13     cursor cur_list is
 14       select ic50.bae001,   --系统机构代码
 15              ic50.aab001,   --组织ID-即虚拟单位编号
 16              ic50.aac001,   --个人编号
 17              case when nvl(ic52.aab383, 0) - nvl(ic52.aic021, 0) > 0 then nvl(ic52.aab383, 0) - nvl(ic52.aic021, 0) else 0 end aic441,   --划入统筹金额 = 应缴金额 - 划入账户金额
 18              case when nvl(ic52.aic452, 0) > 0 then nvl(ic52.aic452, 0) else 0 end aic452,   --政府补贴金额
 19              aae002
 20       from ic50,
 21            ic52
 22       where ic50.aac001 = ic52.aac001
 23         and ic50.aac001 = pi_aac001
 24         and ic52.bce094 = '1'  --缴费标志
 25         and ic52.aae016 = '1'; --复核标志
 26       
 27     i_count integer;
 28     s_bae001 ac01.bae001%type;
 29     n_aab001 ac01.aab001%type;
 30     n_MinYear_ie02 number(4);
 31     n_SysCurYear   number(4);
 32     n_LoopYear     number(4);
 33     n_LoopMonth    number(2);
 34     tab_ie02 typ_tab_ie02;
 35     tab_InterestRate typ_tab_InterestRate;
 36     
 37     procedure GetMinYear_ie02
 38     is
 39     begin
 40       select min(aae001)
 41       into n_MinYear_ie02
 42       from ic52
 43       where aac001 = pi_aac001
 44         and bce094 = '1'
 45         and aae016 = '1';
 46     end GetMinYear_ie02;
 47     
 48     procedure Init_tab_ie02
 49     is
 50     begin
 51       for i in n_MinYear_ie02..n_SysCurYear loop
 52         tab_ie02(i).bae001 := s_bae001;   --系统机构代码
 53         tab_ie02(i).aab001 := n_aab001;   --组织ID
 54         tab_ie02(i).aac001 := pi_aac001;   --人员ID
 55         tab_ie02(i).aae001 := i;   --账户年度
 56         tab_ie02(i).cic103 := 0;   --截止上年末个人缴费划拨统筹部分累计本息
 57         tab_ie02(i).cic105 := 0;   --1月增加个人缴费划拨统筹部分金额
 58         tab_ie02(i).cic106 := 0;   --2月增加个人缴费划拨统筹部分金额
 59         tab_ie02(i).cic107 := 0;   --3月增加个人缴费划拨统筹部分金额
 60         tab_ie02(i).cic108 := 0;   --4月增加个人缴费划拨统筹部分金额
 61         tab_ie02(i).cic109 := 0;   --5月增加个人缴费划拨统筹部分金额
 62         tab_ie02(i).cic110 := 0;   --6月增加个人缴费划拨统筹部分金额
 63         tab_ie02(i).cic111 := 0;   --7月增加个人缴费划拨统筹部分金额
 64         tab_ie02(i).cic112 := 0;   --8月增加个人缴费划拨统筹部分金额
 65         tab_ie02(i).cic113 := 0;   --9月增加个人缴费划拨统筹部分金额
 66         tab_ie02(i).cic114 := 0;   --10月增加个人缴费划拨统筹部分金额
 67         tab_ie02(i).cic115 := 0;   --11月增加个人缴费划拨统筹部分金额
 68         tab_ie02(i).cic116 := 0;   --12月增加个人缴费划拨统筹部分金额
 69         tab_ie02(i).cic117 := 0;   --本年个人缴费划拨统筹部分本金总额
 70         tab_ie02(i).cic131 := 0;   --本年缴纳个人缴费划拨统筹部分本年计入利息
 71         tab_ie02(i).cic133 := 0;   --截止上年末个人缴费划拨统筹部分累计本息在本年产生的利息
 72         tab_ie02(i).cic135 := 0;   --截止本年末个人缴费划拨统筹部分累计储存额(本息)
 73         tab_ie02(i).aae013 := null;   --备注
 74       end loop;
 75     end Init_tab_ie02;
 76     
 77     procedure Init_tab_InterestRate
 78     is
 79     begin
 80       for i in n_MinYear_ie02..n_SysCurYear loop
 81         GetAcctYearlyRate(
 82             i, 
 83             '110',
 84             tab_InterestRate(i).YearRate,
 85             po_fhz,
 86             po_msg);
 87         if po_fhz <> pkg_pub.def_OK then
 88           return;
 89         end if;
 90         
 91         tab_InterestRate(i).MonthRate := round(tab_InterestRate(i).YearRate / 12, 6);
 92       end loop;
 93     end Init_tab_InterestRate;
 94     
 95     procedure FillinAllotCorpusAmt(ai_aic441 in number)   --划入统筹金额
 96     is
 97     begin
 98       if ai_aic441 <> 0 then
 99         case n_LoopMonth
100           when 1  then tab_ie02(n_LoopYear).cic105 := tab_ie02(n_LoopYear).cic105 + ai_aic441;  --1月增加个人缴费划拨统筹部分金额
101           when 2  then tab_ie02(n_LoopYear).cic106 := tab_ie02(n_LoopYear).cic106 + ai_aic441;  --2月增加个人缴费划拨统筹部分金额
102           when 3  then tab_ie02(n_LoopYear).cic107 := tab_ie02(n_LoopYear).cic107 + ai_aic441;  --3月增加个人缴费划拨统筹部分金额
103           when 4  then tab_ie02(n_LoopYear).cic108 := tab_ie02(n_LoopYear).cic108 + ai_aic441;  --4月增加个人缴费划拨统筹部分金额
104           when 5  then tab_ie02(n_LoopYear).cic109 := tab_ie02(n_LoopYear).cic109 + ai_aic441;  --5月增加个人缴费划拨统筹部分金额
105           when 6  then tab_ie02(n_LoopYear).cic110 := tab_ie02(n_LoopYear).cic110 + ai_aic441;  --6月增加个人缴费划拨统筹部分金额
106           when 7  then tab_ie02(n_LoopYear).cic111 := tab_ie02(n_LoopYear).cic111 + ai_aic441;  --7月增加个人缴费划拨统筹部分金额
107           when 8  then tab_ie02(n_LoopYear).cic112 := tab_ie02(n_LoopYear).cic112 + ai_aic441;  --8月增加个人缴费划拨统筹部分金额
108           when 9  then tab_ie02(n_LoopYear).cic113 := tab_ie02(n_LoopYear).cic113 + ai_aic441;  --9月增加个人缴费划拨统筹部分金额
109           when 10 then tab_ie02(n_LoopYear).cic114 := tab_ie02(n_LoopYear).cic114 + ai_aic441;  --10月增加个人缴费划拨统筹部分金额
110           when 11 then tab_ie02(n_LoopYear).cic115 := tab_ie02(n_LoopYear).cic115 + ai_aic441;  --11月增加个人缴费划拨统筹部分金额
111           when 12 then tab_ie02(n_LoopYear).cic116 := tab_ie02(n_LoopYear).cic116 + ai_aic441;  --12月增加个人缴费划拨统筹部分金额
112         end case;    
113         
114         tab_ie02(n_LoopYear).cic117 := tab_ie02(n_LoopYear).cic117 + ai_aic441;  --本年个人缴费划拨统筹部分本金总额
115       end if;
116     end FillinAllotCorpusAmt;
117     
118     procedure CalculateAccountAccrual
119     is
120       n_cic103 number(8, 2);   --截止上年末个人缴费划拨统筹部分累计本息
121       n_AccrualEndMonth number(2);
122     begin
123       n_cic103 := 0;
124       for n_year in tab_ie02.First..tab_ie02.Last loop
125         tab_ie02(n_year).cic103 := n_cic103;
126 
127         if n_year < n_SysCurYear then
128           n_AccrualEndMonth := 12;
129         else
130           n_AccrualEndMonth := to_number(to_char(sysdate, 'mm'));
131         end if;
132         
133         --按正常按时缴费模式处理,从缴费当月起计息
134         for n_month in 1..n_AccrualEndMonth loop
135           --1月份
136           if n_month = 1 then
137             if tab_ie02(n_year).cic105 <> 0 and n_AccrualEndMonth >= n_month then
138               tab_ie02(n_year).cic131 := tab_ie02(n_year).cic131 + tab_InterestRate(n_year).MonthRate * tab_ie02(n_year).cic105 * (n_AccrualEndMonth - n_month + 1);
139             end if;
140           --2月份
141           elsif n_month = 2 then
142             if tab_ie02(n_year).cic106 <> 0 and n_AccrualEndMonth >= n_month then
143               tab_ie02(n_year).cic131 := tab_ie02(n_year).cic131 + tab_InterestRate(n_year).MonthRate * tab_ie02(n_year).cic106 * (n_AccrualEndMonth - n_month + 1);
144             end if;
145           --3月份
146           elsif n_month = 3 then
147             if tab_ie02(n_year).cic107 <> 0 and n_AccrualEndMonth >= n_month then
148               tab_ie02(n_year).cic131 := tab_ie02(n_year).cic131 + tab_InterestRate(n_year).MonthRate * tab_ie02(n_year).cic107 * (n_AccrualEndMonth - n_month + 1);
149             end if;
150           --4月份
151           elsif n_month = 4 then
152             if tab_ie02(n_year).cic108 <> 0 and n_AccrualEndMonth >= n_month then
153               tab_ie02(n_year).cic131 := tab_ie02(n_year).cic131 + tab_InterestRate(n_year).MonthRate * tab_ie02(n_year).cic108 * (n_AccrualEndMonth - n_month + 1);
154             end if;
155           --5月份
156           elsif n_month = 5 then
157             if tab_ie02(n_year).cic109 <> 0 and n_AccrualEndMonth >= n_month then
158               tab_ie02(n_year).cic131 := tab_ie02(n_year).cic131 + tab_InterestRate(n_year).MonthRate * tab_ie02(n_year).cic109 * (n_AccrualEndMonth - n_month + 1);
159             end if;
160           --6月份
161           elsif n_month = 6 then
162             if tab_ie02(n_year).cic110 <> 0 and n_AccrualEndMonth >= n_month then
163               tab_ie02(n_year).cic131 := tab_ie02(n_year).cic131 + tab_InterestRate(n_year).MonthRate * tab_ie02(n_year).cic110 * (n_AccrualEndMonth - n_month + 1);
164             end if;
165           --7月份
166           elsif n_month = 7 then
167             if tab_ie02(n_year).cic111 <> 0 and n_AccrualEndMonth >= n_month then
168               tab_ie02(n_year).cic131 := tab_ie02(n_year).cic131 + tab_InterestRate(n_year).MonthRate * tab_ie02(n_year).cic111 * (n_AccrualEndMonth - n_month + 1);
169             end if;
170           --8月份
171           elsif n_month = 8 then
172             if tab_ie02(n_year).cic112 <> 0 and n_AccrualEndMonth >= n_month then
173               tab_ie02(n_year).cic131 := tab_ie02(n_year).cic131 + tab_InterestRate(n_year).MonthRate * tab_ie02(n_year).cic112 * (n_AccrualEndMonth - n_month + 1);
174             end if;
175           --9月份
176           elsif n_month = 9 then
177             if tab_ie02(n_year).cic113 <> 0 and n_AccrualEndMonth >= n_month then
178               tab_ie02(n_year).cic131 := tab_ie02(n_year).cic131 + tab_InterestRate(n_year).MonthRate * tab_ie02(n_year).cic113 * (n_AccrualEndMonth - n_month + 1);
179             end if;
180           --10月份
181           elsif n_month = 10 then
182             if tab_ie02(n_year).cic114 <> 0 and n_AccrualEndMonth >= n_month then
183               tab_ie02(n_year).cic131 := tab_ie02(n_year).cic131 + tab_InterestRate(n_year).MonthRate * tab_ie02(n_year).cic114 * (n_AccrualEndMonth - n_month + 1);
184             end if;
185           --11月份
186           elsif n_month = 11 then
187             if tab_ie02(n_year).cic115 <> 0 and n_AccrualEndMonth >= n_month then
188               tab_ie02(n_year).cic131 := tab_ie02(n_year).cic131 + tab_InterestRate(n_year).MonthRate * tab_ie02(n_year).cic115 * (n_AccrualEndMonth - n_month + 1);
189             end if;
190           --12月份
191           elsif n_month = 12 then
192             if tab_ie02(n_year).cic116 <> 0 and n_AccrualEndMonth >= n_month then
193               tab_ie02(n_year).cic131 := tab_ie02(n_year).cic131 + tab_InterestRate(n_year).MonthRate * tab_ie02(n_year).cic116 * (n_AccrualEndMonth - n_month + 1);
194             end if;
195           end if;
196         end loop;
197         
198         if n_AccrualEndMonth = 12 then
199           tab_ie02(n_year).cic133 := tab_ie02(n_year).cic103 * tab_InterestRate(n_year).YearRate;
200         else
201           tab_ie02(n_year).cic133 := tab_ie02(n_year).cic103 * tab_InterestRate(n_year).MonthRate * n_AccrualEndMonth;
202         end if;
203       
204         tab_ie02(n_year).cic135 := tab_ie02(n_year).cic103 + tab_ie02(n_year).cic117 + tab_ie02(n_year).cic131 + tab_ie02(n_year).cic133; 
205         
206         n_cic103 := tab_ie02(n_year).cic135;
207       end loop;
208     end CalculateAccountAccrual;
209     
210     procedure Insert_ie02
211     is
212     begin
213       for i in n_MinYear_ie02..n_SysCurYear loop
214         insert into ie02(
215             bae001,   --系统机构代码
216             aab001,   --组织ID
217             aac001,   --人员ID
218             aae001,   --账户年度
219             cic103,   --截止上年末个人缴费划拨统筹部分累计本息
220             cic105,   --1月增加个人缴费划拨统筹部分金额
221             cic106,   --2月增加个人缴费划拨统筹部分金额
222             cic107,   --3月增加个人缴费划拨统筹部分金额
223             cic108,   --4月增加个人缴费划拨统筹部分金额
224             cic109,   --5月增加个人缴费划拨统筹部分金额
225             cic110,   --6月增加个人缴费划拨统筹部分金额
226             cic111,   --7月增加个人缴费划拨统筹部分金额
227             cic112,   --8月增加个人缴费划拨统筹部分金额
228             cic113,   --9月增加个人缴费划拨统筹部分金额
229             cic114,   --10月增加个人缴费划拨统筹部分金额
230             cic115,   --11月增加个人缴费划拨统筹部分金额
231             cic116,   --12月增加个人缴费划拨统筹部分金额
232             cic117,   --本年个人缴费划拨统筹部分本金总额
233             cic131,   --本年缴纳个人缴费划拨统筹部分本年计入利息
234             cic133,   --截止上年末个人缴费划拨统筹部分累计本息在本年产生的利息
235             cic135,   --截止本年末个人缴费划拨统筹部分累计储存额(本息)
236             aae013)   --备注
237         values(
238             tab_ie02(i).bae001,   --系统机构代码
239             tab_ie02(i).aab001,   --组织ID
240             tab_ie02(i).aac001,   --人员ID
241             tab_ie02(i).aae001,   --账户年度
242             tab_ie02(i).cic103,   --截止上年末个人缴费划拨统筹部分累计本息
243             tab_ie02(i).cic105,   --1月增加个人缴费划拨统筹部分金额
244             tab_ie02(i).cic106,   --2月增加个人缴费划拨统筹部分金额
245             tab_ie02(i).cic107,   --3月增加个人缴费划拨统筹部分金额
246             tab_ie02(i).cic108,   --4月增加个人缴费划拨统筹部分金额
247             tab_ie02(i).cic109,   --5月增加个人缴费划拨统筹部分金额
248             tab_ie02(i).cic110,   --6月增加个人缴费划拨统筹部分金额
249             tab_ie02(i).cic111,   --7月增加个人缴费划拨统筹部分金额
250             tab_ie02(i).cic112,   --8月增加个人缴费划拨统筹部分金额
251             tab_ie02(i).cic113,   --9月增加个人缴费划拨统筹部分金额
252             tab_ie02(i).cic114,   --10月增加个人缴费划拨统筹部分金额
253             tab_ie02(i).cic115,   --11月增加个人缴费划拨统筹部分金额
254             tab_ie02(i).cic116,   --12月增加个人缴费划拨统筹部分金额
255             tab_ie02(i).cic117,   --本年个人缴费划拨统筹部分本金总额
256             tab_ie02(i).cic131,   --本年缴纳个人缴费划拨统筹部分本年计入利息
257             tab_ie02(i).cic133,   --截止上年末个人缴费划拨统筹部分累计本息在本年产生的利息
258             tab_ie02(i).cic135,   --截止本年末个人缴费划拨统筹部分累计储存额(本息)
259             tab_ie02(i).aae013);  --备注
260       end loop;
261     end Insert_ie02;
262     
263   begin
264     po_fhz := pkg_pub.def_OK;
265     
266     select count(1)
267     into i_count 
268     from ic52
269     where aac001 = pi_aac001
270       and bce094 = '1'  --缴费标志
271       and aae016 = '1'  --复核标志
272       and (aae002 is null or length(to_char(aae002)) <> 6);
273     if i_count > 0 then
274       po_fhz := pkg_pub.def_ERR;
275       po_msg := to_char(pi_aac001)||'系统检查发现该参保人存在有失地居民人员养老按年零星缴费记录的【费款所属期】不正确,无法重建划统筹部分的账户记录,请先检查核实!';
276       return;
277     end if;
278 
279     select count(1) into i_count from ie02 where aac001 = pi_aac001;
280     if i_count > 0 then
281       delete ie02 where aac001 = pi_aac001;
282     end if;
283     
284     select bae001, aab001 into s_bae001, n_aab001 from ac01 where aac001 = pi_aac001;
285     n_SysCurYear := to_char(sysdate, 'yyyy');
286     
287     GetMinYear_ie02;
288     if n_MinYear_ie02 is null then
289       return;
290     elsif n_MinYear_ie02 > n_SysCurYear then
291       po_fhz := pkg_pub.def_ERR;
292       po_msg := to_char(pi_aac001)||'系统检查发现该参保人存在有失地居民人员养老按年零星缴费记录的所属账户年度大于系统当前年度值,认为数据有问题,请先检查核实!';
293       return;
294     end if;
295     
296     Init_tab_ie02;
297     for rec in cur_list loop
298       n_LoopYear  := to_number(substr(rec.aae002, 1, 4));
299       n_LoopMonth := to_number(substr(rec.aae002, 5, 2));
300 
301       if n_LoopMonth < 1 or n_LoopMonth > 12 then
302         po_fhz := pkg_pub.def_ERR;
303         po_msg := to_char(pi_aac001)||'系统检查发现该参保人存在有失地居民人员养老按年零星缴费记录无法确定其记账所属年月,认为数据有问题,请通知系统管理员协助检查核实!';
304         return;
305       end if;
306 
307       FillinAllotCorpusAmt(rec.aic441);
308 
309       if tab_ie02(n_LoopYear).bae001 <> rec.bae001 then
310         tab_ie02(n_LoopYear).bae001 := rec.bae001;
311       end if;
312       if tab_ie02(n_LoopYear).aab001 <> rec.aab001 then
313         tab_ie02(n_LoopYear).aab001 := rec.aab001;
314       end if;
315     end loop;
316 
317     Init_tab_InterestRate;
318     if po_fhz <> pkg_pub.def_OK then
319       return;
320     end if;
321     
322     CalculateAccountAccrual;
323     Insert_ie02;
324   exception
325     when others then
326       po_fhz := pkg_pub.def_ERR;
327       po_msg := to_char(pi_aac001)||'对该参保人的失地居民人员养老按年零星缴费记录重建划统筹部分的账户记录时发生失败:'||sqlerrm;
328   end ReBuild_IE02;
原文地址:https://www.cnblogs.com/Sunnor/p/4971678.html