hotfix cho huy
SQL Sprint
06/05/2025
CREATE OR REPLACE procedure PBH_PHH_LKE(
b_ma_dvi varchar2,b_nsd varchar2,b_pas varchar2,b_oraIn clob,b_oraOut out clob)
AS
b_loi varchar2(100); b_lenh varchar2(1000); b_phong varchar2(10);
b_ngay_ht number; b_nv varchar2(1); b_klk varchar2(1); b_tu number; b_den number;
b_dong number; cs_lke clob;
begin
-- Dan - Liet ke theo ngay
b_loi:=FHT_MA_NSD_KTRA(b_ma_dvi,b_nsd,b_pas,'BH','PHH','X');
if b_loi is not null then raise PROGRAM_ERROR; end if;
b_lenh:=FKH_JS_LENH('ngay_ht,nv,klk,tu,den');
EXECUTE IMMEDIATE b_lenh into b_ngay_ht,b_nv,b_klk,b_tu,b_den using b_oraIn;
if b_klk='N' then
select count(*) into b_dong from bh_phh where ma_dvi=b_ma_dvi and
ngay_ht=b_ngay_ht and nv=b_nv and nsd=b_nsd;
PKH_LKE_TRANG(b_dong,b_tu,b_den);
select JSON_ARRAYAGG(json_object(ma_dvi,so_id,so_hd,nsd) order by so_hd desc returning clob) into cs_lke from
(select ma_dvi,so_id,so_hd,nsd,rownum sott from bh_phh where
ma_dvi=b_ma_dvi and ngay_ht=b_ngay_ht and nv=b_nv and nsd=b_nsd order by so_hd)
where sott between b_tu and b_den;
elsif b_klk='P' or FHT_MA_NSD_QU(b_ma_dvi,b_nsd,'BH','PHH','X')<>'C' then
b_phong:=FHT_MA_NSD_PHONG(b_ma_dvi,b_nsd);
select count(*) into b_dong from bh_phh where ma_dvi=b_ma_dvi and
ngay_ht=b_ngay_ht and nv=b_nv and phong=b_phong;
PKH_LKE_TRANG(b_dong,b_tu,b_den);
select JSON_ARRAYAGG(json_object(ma_dvi,so_id,so_hd,nsd) order by so_hd desc returning clob) into cs_lke from
(select ma_dvi,so_id,so_hd,nsd,rownum sott from bh_phh where
ma_dvi=b_ma_dvi and ngay_ht=b_ngay_ht and nv=b_nv and phong=b_phong order by so_hd)
where sott between b_tu and b_den;
else
select count(*) into b_dong from bh_phh where ma_dvi=b_ma_dvi and ngay_ht=b_ngay_ht and nv=b_nv;
PKH_LKE_TRANG(b_dong,b_tu,b_den);
select JSON_ARRAYAGG(json_object(ma_dvi,so_id,so_hd,nsd) order by so_hd desc returning clob) into cs_lke from
(select ma_dvi,so_id,so_hd,nsd,rownum sott from bh_phh where
ma_dvi=b_ma_dvi and ngay_ht=b_ngay_ht and nv=b_nv order by so_hd)
where sott between b_tu and b_den;
end if;
select json_object('dong' value b_dong,'cs_lke' value cs_lke) into b_oraOut from dual;
exception when others then if b_loi is null then raise PROGRAM_ERROR; else raise_application_error(-20105,b_loi); end if;
end;
/