Project

General

Profile

mo ra chan cap nhat hd

SQL Sprint
05/05/2025

CREATE OR REPLACE procedure PBH_HD_UP_XOA(
    b_ma_dvi varchar2,b_so_id number,b_dvi_ksoatN varchar2,b_ksoatN varchar2,b_loi out varchar2,b_du varchar2:='K')
AS
    b_lenh varchar2(1000); b_i1 number; b_i2 number; b_so_hd varchar2(20);
    b_nv varchar2(10); b_kieu_hd varchar2(1); b_so_idD number; b_ngay_ht number;
    b_ttrang varchar2(1); b_dvi_ksoat varchar2(10); b_ksoat varchar2(10);
    a_bang pht_type.a_var;
begin
-- Dan - Xoa hop dong goc
b_loi:='loi:Loi Up xoa:loi';
select count(*) into b_i1 from bh_hd_goc where ma_dvi=b_ma_dvi and so_id=b_so_id;
if b_i1=0 then b_loi:=''; return; end if;
select nv,kieu_hd,so_id_d,ttrang,dvi_ksoat,ksoat,so_hd,ngay_ht into
    b_nv,b_kieu_hd,b_so_idD,b_ttrang,b_dvi_ksoat,b_ksoat,b_so_hd,b_ngay_ht
    from bh_hd_goc where ma_dvi=b_ma_dvi and so_id=b_so_id;
if b_ttrang='H' then b_loi:='loi:Hop dong/GCN da huy:loi'; return; end if;
if b_ttrang='D' then b_loi:='loi:Khong sua, xoa hop dong/GCN da duyet:loi'; return; end if;
if b_ttrang not in('T','D') then b_loi:=''; return; end if;
if trim(b_ksoat) is not null and (b_dvi_ksoatN<>b_dvi_ksoat or b_ksoatN<>b_ksoat) then
    b_loi:='loi:Nguoi khac duyet:loi'; return;
end if;
if b_ttrang='D' then
    select nvl(max(ngay_ht),0) into b_i1 from bh_hd_goc_tthd where ma_dvi=b_ma_dvi and so_id=b_so_idD;
    if b_i1>b_ngay_ht then b_loi:='loi:Hop dong/GCN da thanh toan phi:loi'; return; end if;
    select count(*) into b_i1 from tbh_ghep_hd where ma_dvi_hd=b_ma_dvi and so_id_hd=b_so_id;
    if b_i1=0 then
        select count(*) into b_i1 from tbh_tm_hd where ma_dvi_hd=b_ma_dvi and so_id_hd=b_so_id;
    end if;
    if b_i1<>0 then b_loi:='loi:Hop dong/GCN da xu ly tai:loi'; return; end if;
end if;
PBH_GCNE_XOA(b_ma_dvi,b_so_id,b_loi);
if b_loi is not null then return; end if;
PTBH_TMB_CBI_XOA(b_ma_dvi,b_so_id,b_loi);
PTBH_CBI_XOA(b_ma_dvi,b_so_id,b_loi);
if b_loi is not null then return; end if;
PBH_HD_GOC_XOA_NV(b_ma_dvi,b_so_id,b_loi);
if b_loi is not null then return; end if;
if b_du='C' then
    PBH_HD_DU_NV(b_nv,b_ma_dvi,b_so_id,'','','T',b_so_hd,b_loi);
    if b_loi is not null then return; end if;
end if;
update bh_hd_goc set so_hd=b_so_hd,ksoat='',dvi_ksoat='',ttrang='T',so_id_kt=-1 where ma_dvi=b_ma_dvi and so_id=b_so_id;
if b_kieu_hd='U' then return; end if;
if b_kieu_hd='K' then
    PBH_HD_GOC_THL_KEM(b_ma_dvi,b_so_idD,b_loi);
else
    PBH_HD_GOC_THL_CT(b_ma_dvi,b_so_idD,b_loi,b_so_id);
end if;
if b_loi is not null then return; end if;
b_loi:='';
exception when others then if b_loi is null then raise PROGRAM_ERROR; else null; end if;
end;
/

Files