hot fix 09
SQL Sprint
05/05/2025
create or replace procedure PBH_THL_PHI_NBH(
b_ma_dvi varchar2,b_so_id number,b_loi out varchar2)
As
b_ma_nt varchar2(5); b_ngay_ht number; b_tp number; b_tien number;
begin
-- Dan - Tong hop lai phi nha lead, nhan tai tam thoi
b_loi:='loi:Loi xu ly PBH_THL_PHI_NBH:loi';
select min(nt_phi),min(ngay_ht) into b_ma_nt,b_ngay_ht from bh_hd_goc where ma_dvi=b_ma_dvi and so_id=b_so_id;
if b_ma_nt is null then b_loi:=''; return; end if;
if b_ma_nt<>'VND' then b_tp:=2; else b_tp:=0; end if;
for r_lp in(select a.nha_bh,sum(a.pt*b.ttoan) tien from
(select * from bh_hd_do_tl where ma_dvi=b_ma_dvi and so_id=b_so_id and kieu='V' and pthuc in('C','T')) a,
(select * from bh_hd_goc_dkdt where ma_dvi=b_ma_dvi and so_id=b_so_id) b where
a.so_id_dt in(0,b.so_id_dt) and a.lh_nv in(' ',b.lh_nv) group by a.nha_bh) loop
b_tien:=round(r_lp.tien/100,b_tp);
PBH_TH_PHI_NBH(b_ma_dvi,'N',b_so_id,r_lp.nha_bh,b_ma_nt,b_tien,b_ngay_ht,b_loi);
if b_loi is not null then return; end if;
end loop;
b_loi:='';
exception when others then if b_loi is null then raise PROGRAM_ERROR; else null; end if;
end;
/
create or replace procedure PBH_PKT_PQU_BG(
b_ma_dviN varchar2,b_nsdN varchar2,b_ma_dvi varchar2,b_so_id number,b_loi out varchar2)
AS
b_ma_sp varchar2(10); b_nt_tien varchar2(5); b_tien number;
dk_ma pht_type.a_var; dk_ten pht_type.a_nvar; dk_tien pht_type.a_num; dk_ptG pht_type.a_num;
begin
-- dan - Kiem tra phan quyen
b_loi:='loi:Bao gia da xoa:loi';
select ma_sp,nt_tien,tien into b_ma_sp,b_nt_tien,b_tien from bh_pktB where ma_dvi=b_ma_dvi and so_id=b_so_id;
for r_lp in (select * from bh_pktB_dvi where ma_dvi=b_ma_dvi and so_id=b_so_id) loop
select ma,ten,tien,ptG bulk collect into dk_ma,dk_ten,dk_tien,dk_ptG
from bh_pktB_dk where ma_dvi=b_ma_dvi and so_id=b_so_id and so_id_dt=r_lp.so_id_dt;
-- viet anh
FBH_PKT_PQU_HD(b_ma_dviN,b_nsdN,r_lp.ten,r_lp.rru,b_ma_sp,b_nt_tien,b_tien,' ',dk_ma,dk_ten,dk_tien,dk_ptG,b_loi);
if b_loi is not null then return; end if;
end loop;
b_loi:='';
exception when others then if b_loi is null then raise PROGRAM_ERROR; else null; end if;
end;
/