Bug #9127
openChấm dứt hợp đồng
100%
Description
create or replace procedure PBH_TH_HH(
b_ma_dvi varchar2,b_so_id number,b_so_id_tt number,b_loi out varchar2)
AS
b_i1 number:=0; b_so_idD number;
b_kieu_kt varchar2(1); b_ma_dl varchar2(20); b_phong varchar2(10); b_ma_nt varchar2(5);
begin
-- Dan - Tong hop so cai hoa hong
delete bh_hd_goc_sc_hh where ma_dvi=b_ma_dvi and so_id_tt=b_so_id_tt and so_id=b_so_id;
select min(ma_nt),nvl(sum(hhong+htro+dvu),0) into b_ma_nt,b_i1 from bh_hd_goc_ttpt where
ma_dvi=b_ma_dvi and so_id=b_so_id and so_id_tt=b_so_id_tt and pt<>'C';
if b_i1=0 then b_loi:=''; return; end if;
select so_id_d,kieu_kt,ma_kt into b_so_idD,b_kieu_kt,b_ma_dl
from bh_hd_goc where ma_dvi=b_ma_dvi and so_id=b_so_id;
if b_kieu_kt not in('M','D') or b_ma_dl=' ' then b_loi:=''; return; end if;
select count(*) into b_i1 from bh_hd_goc_hh_ct where
ma_dvi=b_ma_dvi and so_id_tt=b_so_id_tt and so_id=b_so_id;
if b_i1=0 then
select nvl(min(ngay_ht),0),min(phong) into b_i1,b_phong from bh_hd_goc_hu where ma_dvi=b_ma_dvi and so_id=b_so_id;
if b_i1=0 then
select ngay_ht,phong into b_i1,b_phong from bh_hd_goc_ttps where ma_dvi=b_ma_dvi and so_id_tt=b_so_id_tt;
end if;
insert into bh_hd_goc_sc_hh values(b_ma_dvi,b_so_id,b_so_id_tt,b_phong,b_ma_dl,b_ma_nt,b_i1);
end if;
b_loi:='';
exception when others then if b_loi is null then b_loi:='loi:Loi xu ly PBH_TH_HH:loi'; end if;
end;
Files