Xoa_XOL
User documentation
19/05/2025
create or replace procedure PTBH_XOL_XOA_XOA(
b_ma_dvi varchar2,b_nsd varchar2,b_so_id number,b_loi out varchar2,b_nh varchar2:='K')
AS
b_i1 number:=0; b_nsdC varchar2(20); b_so_idD number; b_ngay_ht number;
dc_lh_nv pht_type.a_var; dc_tu pht_type.a_num; dc_den pht_type.a_num;
dc_lan pht_type.a_num; dc_vu pht_type.a_num; dc_tien pht_type.a_num;
b_ma_dvi varchar2,b_nsd varchar2,b_so_id number,b_loi out varchar2,b_nh varchar2:='K')
AS
b_i1 number:=0; b_nsdC varchar2(20); b_so_idD number; b_ngay_ht number;
dc_lh_nv pht_type.a_var; dc_tu pht_type.a_num; dc_den pht_type.a_num;
dc_lan pht_type.a_num; dc_vu pht_type.a_num; dc_tien pht_type.a_num;
begin
-- Dan - Xoa
b_loi:='loi:Loi xu ly PTBH_XOL_XOA_XOA:loi';
select count(*) into b_i1 from tbh_xol where so_id=b_so_id;
if b_i1=0 then b_loi:=''; return; end if;
select nsd,ngay_ht,so_id_d into b_nsdC,b_ngay_ht,b_so_idD from tbh_xol where so_id=b_so_id;
if b_nsdC not in(' ',b_nsd) then
b_loi:='loi:Khong sua, xoa so lieu nguoi khac:loi'; return;
end if;
select lh_nv,tu,den,-lan,-vu,-tien bulk collect into dc_lh_nv,dc_tu,dc_den,dc_lan,dc_vu,dc_tien from tbh_xol_dc where so_id=b_so_id;
PTBH_XOL_TH(b_so_idD,b_ngay_ht,dc_lh_nv,dc_tu,dc_den,dc_lan,dc_vu,dc_tien,b_loi);
if b_loi is not null then return; end if;
PTBH_TH_TA_XOA(b_ma_dvi,b_so_id,b_loi);
if b_loi is not null then return; end if;
if b_nh='K' and b_so_idD=b_so_id then
select count(*) into b_i1 from tbh_xol_sc where so_id=b_so_idD and ngay<>0;
if b_i1<>0 then b_loi:='loi:Da co phuc hoi, boi thuong:loi'; return; end if;
select count(*) into b_i1 from tbh_ps where so_id=b_so_id and so_id_xl<>0;
if b_i1<>0 then b_loi:='loi:Da co xu ly thanh toan phi tai XOL:loi'; return; end if;
end if;
delete tbh_xol_txt where so_id=b_so_id;
delete tbh_xol_dc where so_id=b_so_id;
delete tbh_xol_kytt where so_id=b_so_id;
delete tbh_xol_nv where so_id=b_so_id;
delete tbh_xol_nbh where so_id=b_so_id;
delete tbh_xol where so_id=b_so_id;
b_loi:='';
end;
-- Dan - Xoa
b_loi:='loi:Loi xu ly PTBH_XOL_XOA_XOA:loi';
select count(*) into b_i1 from tbh_xol where so_id=b_so_id;
if b_i1=0 then b_loi:=''; return; end if;
select nsd,ngay_ht,so_id_d into b_nsdC,b_ngay_ht,b_so_idD from tbh_xol where so_id=b_so_id;
if b_nsdC not in(' ',b_nsd) then
b_loi:='loi:Khong sua, xoa so lieu nguoi khac:loi'; return;
end if;
select lh_nv,tu,den,-lan,-vu,-tien bulk collect into dc_lh_nv,dc_tu,dc_den,dc_lan,dc_vu,dc_tien from tbh_xol_dc where so_id=b_so_id;
PTBH_XOL_TH(b_so_idD,b_ngay_ht,dc_lh_nv,dc_tu,dc_den,dc_lan,dc_vu,dc_tien,b_loi);
if b_loi is not null then return; end if;
PTBH_TH_TA_XOA(b_ma_dvi,b_so_id,b_loi);
if b_loi is not null then return; end if;
if b_nh='K' and b_so_idD=b_so_id then
select count(*) into b_i1 from tbh_xol_sc where so_id=b_so_idD and ngay<>0;
if b_i1<>0 then b_loi:='loi:Da co phuc hoi, boi thuong:loi'; return; end if;
select count(*) into b_i1 from tbh_ps where so_id=b_so_id and so_id_xl<>0;
if b_i1<>0 then b_loi:='loi:Da co xu ly thanh toan phi tai XOL:loi'; return; end if;
end if;
delete tbh_xol_txt where so_id=b_so_id;
delete tbh_xol_dc where so_id=b_so_id;
delete tbh_xol_kytt where so_id=b_so_id;
delete tbh_xol_nv where so_id=b_so_id;
delete tbh_xol_nbh where so_id=b_so_id;
delete tbh_xol where so_id=b_so_id;
b_loi:='';
end;