2959
User documentation
08/04/2025
create or replace procedure PBH_XEH_TESTr(
b_ma_dvi varchar2,b_nsd varchar2,b_so_idG number,
dt_ct in out clob,dt_ds in out clob,
b_so_hdL out varchar2,
ds_so_id out pht_type.a_num,ds_kieu_gcn out pht_type.a_var,ds_gcn out pht_type.a_var,ds_gcnG out pht_type.a_var,
ds_ma_sp out pht_type.a_var,ds_cdich out pht_type.a_var,ds_goi out pht_type.a_var,
ds_tenC out pht_type.a_nvar,ds_cmtC out pht_type.a_var,ds_mobiC out pht_type.a_var,
ds_emailC out pht_type.a_var,ds_dchiC out pht_type.a_nvar,ds_ng_huong out pht_type.a_nvar,
ds_bien_xe out pht_type.a_var,ds_so_khung out pht_type.a_var,ds_so_may out pht_type.a_var,
ds_hang out pht_type.a_var,ds_hieu out pht_type.a_var,ds_pban out pht_type.a_var,
ds_loai_xe out pht_type.a_var,ds_nhom_xe out pht_type.a_var,ds_dong out pht_type.a_var,
ds_dco out pht_type.a_var,ds_ttai out pht_type.a_num,ds_so_cn out pht_type.a_num,
ds_nam_sx out pht_type.a_num,ds_gia out pht_type.a_num,
ds_md_sd out pht_type.a_var,ds_nv_bh out pht_type.a_var,ds_bh_tbo out pht_type.a_var,
ds_ngay_hl out pht_type.a_num,ds_ngay_kt out pht_type.a_num,
ds_so_idP out pht_type.a_var,ds_xe_id out pht_type.a_num,
ds_giam out pht_type.a_num,ds_phi out pht_type.a_num,
ds_thue out pht_type.a_num,ds_ttoan out pht_type.a_num,
dk_so_id out pht_type.a_num,dk_bt out pht_type.a_num,dk_ma out pht_type.a_var,dk_ten out pht_type.a_nvar,dk_tc out pht_type.a_var,
dk_ma_ct out pht_type.a_var,dk_kieu out pht_type.a_var,dk_tien out pht_type.a_num,dk_pt out pht_type.a_num,
dk_phi out pht_type.a_num,dk_thue out pht_type.a_num,dk_ttoan out pht_type.a_num,
dk_cap out pht_type.a_num,dk_ma_dk out pht_type.a_var,
dk_lh_nv out pht_type.a_var,dk_t_suat out pht_type.a_num,
dk_ptB out pht_type.a_num,dk_phiB out pht_type.a_num,
dk_ptG out pht_type.a_num,dk_phiG out pht_type.a_num,
dk_lkeP out pht_type.a_var,dk_lkeB out pht_type.a_var,dk_lh_bh out pht_type.a_var,
lt_so_id out pht_type.a_num,lt_dk out pht_type.a_clob,lt_lt out pht_type.a_clob,
lt_kbt out pht_type.a_clob,b_loi out varchar2)
AS
b_lenh varchar2(2000); b_i1 number; b_i2 number; b_kt number; b_ktG number; b_ps varchar2(1); dt_khd clob; b_txt clob;
b_c_thue varchar2(1); b_nt_tien varchar2(5); b_nt_phi varchar2(5); b_tp number:=0; b_ktruC varchar2(30);
b_phi number; b_thue number; b_ttoan number; b_giam number; b_thueH number; b_ttoanH number;
b_ten nvarchar2(500); b_dchi nvarchar2(500); b_cmt varchar2(20); b_mobi varchar2(20); b_email varchar2(50);
b_kieu_hd varchar2(1); b_ttrang varchar2(1); b_tygia number; b_so_idP number; b_ma_dk varchar2(10);
b_gio_hl varchar2(50); b_ngay_hl number; b_gio_kt varchar2(50); b_ngay_kt number; b_ngay_cap number;
b_loai_khH varchar2(1); b_cmtH varchar2(20); b_mobiH varchar2(20); b_emailH varchar2(50);
b_tenH nvarchar2(500); b_dchiH nvarchar2(500); b_ma_khH varchar2(20); b_tuoi number; b_nv_bhC varchar2(10);
a_ds_ct pht_type.a_clob; a_ds_dk pht_type.a_clob; a_ds_lt pht_type.a_clob; a_ds_ttt pht_type.a_clob;
a_ds_kbt pht_type.a_clob; a_ds_dkbs pht_type.a_clob; a_dsM pht_type.a_clob;
a_nv pht_type.a_var; a_bien pht_type.a_var; ds_so_idS pht_type.a_var; ds_ktru pht_type.a_num;
dk_maX pht_type.a_var; dk_tenX pht_type.a_nvar; dk_tcX pht_type.a_var; dk_ma_ctX pht_type.a_var;
dk_ma_dkX pht_type.a_var; dk_kieuX pht_type.a_var; dk_tienX pht_type.a_num; dk_ptX pht_type.a_num;
dk_phiX pht_type.a_num; dk_thueX pht_type.a_num; dk_lkePX pht_type.a_var; dk_lkeBX pht_type.a_var;
dk_lh_nvX pht_type.a_var; dk_t_suatX pht_type.a_num; dk_nvX pht_type.a_var; dk_capX pht_type.a_num;
dk_ptGX pht_type.a_num; dk_phiGX pht_type.a_num; dk_ptBX pht_type.a_num; dk_phiBX pht_type.a_num;
a_loaiL pht_type.a_var; a_maL pht_type.a_var; a_loi pht_type.a_var;
begin
-- Dan - Nhap
b_lenh:=FKH_JS_LENH('ttrang,kieu_hd,gio_hl,ngay_hl,gio_kt,ngay_kt,ngay_cap,
thue,ttoan,nt_tien,nt_phi,tygia,c_thue,ten,cmt,mobi,email,dchi,so_hdl');
EXECUTE IMMEDIATE b_lenh into b_ttrang,b_kieu_hd,b_gio_hl,b_ngay_hl,b_gio_kt,b_ngay_kt,b_ngay_cap,
b_thueH,b_ttoanH,b_nt_tien,b_nt_phi,b_tygia,b_c_thue,b_ten,b_cmt,b_mobi,b_email,b_dchi,b_so_hdL using dt_ct;
b_c_thue:=nvl(trim(b_c_thue),'C');
if nvl(trim(b_nt_phi),'VND')<>'VND' then b_tp:=2; end if;
b_ten:=nvl(trim(b_ten),' '); b_dchi:=nvl(trim(b_dchi),' ');
b_cmt:=nvl(trim(b_cmt),' '); b_mobi:=nvl(trim(b_mobi),' '); b_email:=nvl(trim(b_email),' ');
if b_so_hdL not in('E','P','T') then b_so_hdL:='T'; end if;
b_lenh:=FKH_JS_LENH('ds_ct,ds_dk,ds_lt,ds_kbt,ds_ttt,ds_dkbs');
EXECUTE IMMEDIATE b_lenh bulk collect into a_ds_ct,a_ds_dk,a_ds_lt,a_ds_kbt,a_ds_ttt,a_ds_dkbs using dt_ds;
if a_ds_ct.count=0 then b_loi:='loi:Nhap danh sach xe:loi'; return; end if;
a_loaiL(1):='MDSD'; a_loi(1):='muc dich su dung';
a_loaiL(2):='LOAI'; a_loi(2):='loai xe';
b_kt:=0;
for ds_lp in 1..a_ds_ct.count loop
b_lenh:='so_id_dt,so_ids,gcn,gcn_g,ngay_hl,ngay_kt,ma_sp,cdich,goi,';
b_lenh:=b_lenh||'tenc,cmtc,mobic,emailc,dchic,';
b_lenh:=b_lenh||'bien_xe,so_khung,so_may,hang,hieu,pban,';
b_lenh:=b_lenh||'loai_xe,nhom_xe,dong,dco,ttai,so_cn,nam_sx,gia,';
b_lenh:=b_lenh||'md_sd,bh_tbo,ktru,nvb,nvt,nvv,nvm';
b_lenh:=FKH_JS_LENH(b_lenh);
EXECUTE IMMEDIATE b_lenh into
ds_so_id(ds_lp),ds_so_idS(ds_lp),ds_gcn(ds_lp),ds_gcnG(ds_lp),
ds_ngay_hl(ds_lp),ds_ngay_kt(ds_lp),ds_ma_sp(ds_lp),ds_cdich(ds_lp),ds_goi(ds_lp),
ds_tenC(ds_lp),ds_cmtC(ds_lp),ds_mobiC(ds_lp),ds_emailC(ds_lp),ds_dchiC(ds_lp),
ds_bien_xe(ds_lp),ds_so_khung(ds_lp),ds_so_may(ds_lp),ds_hang(ds_lp),ds_hieu(ds_lp),ds_pban(ds_lp),
ds_loai_xe(ds_lp),ds_nhom_xe(ds_lp),ds_dong(ds_lp),ds_dco(ds_lp),ds_ttai(ds_lp),ds_so_cn(ds_lp),ds_nam_sx(ds_lp),ds_gia(ds_lp),
ds_md_sd(ds_lp),ds_bh_tbo(ds_lp),b_ktruC,a_nv(1),a_nv(2),a_nv(3),a_nv(4) using a_ds_ct(ds_lp);
-- chuclh - fix kieu gcn
ds_ktru(ds_lp):=PKH_LOC_CHU_SO(PKH_TEN_TENl(b_ktruC),'F','T');
ds_kieu_gcn(ds_lp):='G'; ds_bien_xe(ds_lp):=nvl(trim(ds_bien_xe(ds_lp)),' ');
ds_so_khung(ds_lp):=nvl(trim(ds_so_khung(ds_lp)),' '); ds_so_may(ds_lp):=nvl(trim(ds_so_may(ds_lp)),' ');
if ds_bien_xe(ds_lp)<>' ' then
a_bien(ds_lp):=ds_bien_xe(ds_lp);
elsif ds_so_khung(ds_lp)<>' ' then
a_bien(ds_lp):=ds_so_khung(ds_lp);
else
b_loi:='loi:Nhap bien xe, so khung '||to_char(ds_lp)||':loi'; return;
end if;
ds_ma_sp(ds_lp):=nvl(trim(ds_ma_sp(ds_lp)),' '); ds_cdich(ds_lp):=nvl(trim(ds_cdich(ds_lp)),' '); ds_goi(ds_lp):=nvl(trim(ds_goi(ds_lp)),' ');
if ds_ma_sp(ds_lp)<>' ' and FBH_XE_SP_HAN(ds_ma_sp(ds_lp))<>'C' then b_loi:='loi:Sai ma san pham xe '||a_bien(ds_lp)||':loi'; return; end if;
if ds_cdich(ds_lp)<>' ' and FBH_MA_CDICH_HAN(ds_cdich(ds_lp))<>'C' then b_loi:='loi:Het chien dich xe '||a_bien(ds_lp)||':loi'; return; end if;
if ds_goi(ds_lp)<>' ' and FBH_XE_GOI_HAN(ds_goi(ds_lp))<>'C' then b_loi:='loi:Ma goi het han xe '||a_bien(ds_lp)||':loi'; return; end if;
if trim(ds_tenC(ds_lp)) is null then
ds_tenC(ds_lp):=b_ten; ds_dchiC(ds_lp):=b_dchi; ds_cmtC(ds_lp):=b_cmt; ds_mobiC(ds_lp):=b_mobi; ds_emailC(ds_lp):=b_email;
end if;
ds_hang(ds_lp):=PKH_MA_TENl(ds_hang(ds_lp)); ds_hieu(ds_lp):=PKH_MA_TENl(ds_hieu(ds_lp)); ds_pban(ds_lp):=PKH_MA_TENl(ds_pban(ds_lp));
ds_loai_xe(ds_lp):=PKH_MA_TENl(ds_loai_xe(ds_lp)); ds_nhom_xe(ds_lp):=PKH_MA_TENl(ds_nhom_xe(ds_lp));
ds_dong(ds_lp):=PKH_MA_TENl(ds_dong(ds_lp)); ds_dco(ds_lp):=PKH_MA_TENl(ds_dco(ds_lp));
ds_ttai(ds_lp):=nvl(ds_ttai(ds_lp),0); ds_so_cn(ds_lp):=nvl(ds_so_cn(ds_lp),0);
ds_nam_sx(ds_lp):=nvl(ds_nam_sx(ds_lp),0); ds_gia(ds_lp):=nvl(ds_gia(ds_lp),0);
ds_md_sd(ds_lp):=PKH_MA_TENl(ds_md_sd(ds_lp)); ds_bh_tbo(ds_lp):=nvl(trim(ds_bh_tbo(ds_lp)),'C');
if ds_hang(ds_lp)<>' ' and FBH_XE_HANG_HAN(ds_hang(ds_lp))<>'C' then b_loi:='loi:Sai hang xe xe '||a_bien(ds_lp)||':loi'; return; end if;
if ds_hang(ds_lp)<>' ' and ds_hieu(ds_lp)<>' ' and FBH_XE_HIEU_HAN(ds_hang(ds_lp),ds_hieu(ds_lp))<>'C' then
b_loi:='loi:Sai hieu xe '||a_bien(ds_lp)||':loi'; return;
end if;
if ds_hang(ds_lp)<>' ' and ds_hieu(ds_lp)<>' ' and ds_pban(ds_lp)<>' ' and FBH_XE_PB_HAN(ds_hang(ds_lp),ds_hieu(ds_lp),ds_pban(ds_lp))<>'C' then
b_loi:='loi:Sai phien ban xe '||a_bien(ds_lp)||':loi'; return;
end if;
if ds_dong(ds_lp)<>' ' and FBH_XE_DONG_HAN(ds_dong(ds_lp))<>'C' then b_loi:='loi:Sai dong xe '||a_bien(ds_lp)||':loi'; return; end if;
if ds_dco(ds_lp) not in(' ','X','D','E','H') then b_loi:='loi:Sai loai dong co:loi'; return; end if;
if ds_loai_xe(ds_lp)<>' ' and FBH_XE_LOAI_HAN(ds_loai_xe(ds_lp))<>'C' then b_loi:='loi:Sai loai xe '||a_bien(ds_lp)||':loi'; return; end if;
if ds_nhom_xe(ds_lp)<>' ' and FBH_XE_NHOM_HAN(ds_nhom_xe(ds_lp))<>'C' then b_loi:='loi:Sai nhom xe '||a_bien(ds_lp)||':loi'; return; end if;
if ds_md_sd(ds_lp)<>' ' and FBH_XE_MDSD_HAN(ds_md_sd(ds_lp))<>'C' then b_loi:='loi:Sai muc dich su dung xe '||a_bien(ds_lp)||':loi'; return; end if;
ds_nv_bh(ds_lp):=''; ds_so_idP(ds_lp):=''; ds_ng_huong(ds_lp):=''; ds_xe_id(ds_lp):=0;
for b_lp in 1..3 loop
a_nv(b_lp):=nvl(trim(a_nv(b_lp)),' ');
if a_nv(b_lp)='C' then
a_nv(b_lp):=substr('BTV',b_lp,1);
PKH_GHEP(ds_nv_bh(ds_lp),a_nv(b_lp));
else
a_nv(b_lp):=' ';
end if;
end loop;
b_tuoi:=FBH_XE_TUOI(ds_nam_sx(ds_lp));
if ds_nv_bh(ds_lp) is null then b_loi:='loi:Chua chon loai phi mua xe '||a_bien(ds_lp)||':loi'; return; end if;
--
if ds_so_id(ds_lp)<100000 then
PHT_ID_MOI(ds_so_id(ds_lp),b_loi);
if b_loi is not null then return; end if;
b_lenh:=FKH_JS_LENH('ma,ten,tc,ma_ct,kieu,tien,pt,phi,thue,cap,ma_dk,lh_nv,t_suat,ptb,phib,lkep,lkeb');
EXECUTE IMMEDIATE b_lenh bulk collect into
dk_maX,dk_tenX,dk_tcX,dk_ma_ctX,dk_kieuX,dk_tienX,dk_ptX,dk_phiX,dk_thueX,dk_capX,
dk_ma_dkX,dk_lh_nvX,dk_t_suatX,dk_ptBX,dk_phiBX,dk_lkePX,dk_lkeBX using a_ds_dk(ds_lp);
for b_lp in 1..dk_maX.count loop
b_kt:=b_kt+1; dk_so_id(b_kt):=ds_so_id(ds_lp);
dk_bt(b_kt):=b_lp;
-- chuclh - dieu khoan bo sung dk_kieu, dk_lh_bh
dk_kieu(b_kt):=dk_kieuX(b_lp); dk_ma(b_kt):=dk_maX(b_lp); dk_ten(b_kt):=dk_tenX(b_lp);
dk_tc(b_kt):=dk_tcX(b_lp); dk_ma_ct(b_kt):=dk_ma_ctX(b_lp); dk_tien(b_kt):=dk_tienX(b_lp);
dk_pt(b_kt):=dk_ptX(b_lp); dk_phi(b_kt):=dk_phiX(b_lp); dk_thue(b_kt):=dk_thueX(b_lp);
dk_cap(b_kt):=dk_capX(b_lp); dk_ma_dk(b_kt):=dk_ma_dkX(b_lp); dk_lh_nv(b_kt):=dk_lh_nvX(b_lp);
dk_t_suat(b_kt):=dk_t_suatX(b_lp); dk_ptB(b_kt):=dk_ptBX(b_lp); dk_phiB(b_kt):=dk_phiBX(b_lp);
dk_lkeP(b_kt):=dk_lkePX(b_lp); dk_lkeB(b_kt):=dk_lkeBX(b_lp); dk_lh_bh(b_kt):='C';
end loop;
b_ktG:=b_kt;
if b_kt=0 then b_loi:='loi:Nhap dieu khoan xe '||a_bien(ds_lp)||':loi'; return; end if;
for b_lp1 in 1..3 loop
if a_nv(b_lp1)<>' ' then
FBH_XE_BPHI_SO_ID('H',a_nv(b_lp1),ds_bh_tbo(ds_lp),ds_md_sd(ds_lp),
ds_ma_sp(ds_lp),ds_cdich(ds_lp),ds_goi(ds_lp),ds_loai_xe(ds_lp),ds_nhom_xe(ds_lp),
ds_dong(ds_lp),ds_dco(ds_lp),ds_ttai(ds_lp),ds_so_cn(ds_lp),
b_tuoi,ds_gia(ds_lp),ds_ngay_hl(ds_lp),b_so_idP,b_loi);
if b_loi is not null then return; end if;
if b_so_idP=0 then b_loi:='loi:Khong co bieu phi ' || a_nv(b_lp1) ||' xe '|| a_bien(ds_lp) ||':loi'; return; end if;
PKH_GHEP(ds_so_idP(ds_lp),to_char(b_so_idP));
end if;
end loop;
if ds_so_idS(ds_lp)<>ds_so_idP(ds_lp) then
b_loi:='loi:Khac bieu phi xe '||a_bien(ds_lp)||':loi'; return;
end if;
ds_gcn(ds_lp):=nvl(trim(ds_gcn(ds_lp)),' '); ds_gcnG(ds_lp):=nvl(trim(ds_gcnG(ds_lp)),' ');
ds_kieu_gcn(ds_lp):='G'; ds_gcnG(ds_lp):=' ';
if b_so_hdL<>'P' then ds_gcn(ds_lp):=' '; end if;
elsif b_kieu_hd in('S','B') and ds_gcnG(ds_lp)<>' ' then
select count(*) into b_i1 from bh_xe_ds where ma_dvi=b_ma_dvi and so_id_dt=ds_so_id(ds_lp) and gcn=ds_gcnG(ds_lp);
if b_i1=0 then b_loi:='loi:GCN '||ds_gcnG(ds_lp)||' da xoa:loi'; return; end if;
ds_kieu_gcn(ds_lp):=b_kieu_hd;
if ds_gcn(ds_lp)=ds_gcnG(ds_lp) then ds_gcn(ds_lp):=' '; end if;
end if;
if ds_gcn(ds_lp)=' ' or instr(ds_gcn(ds_lp),'.')=2 then
if instr(ds_gcn(ds_lp),'.')=2 then ds_gcn(ds_lp):=substr(ds_gcn(ds_lp),3); end if;
if b_so_hdL='P' then
b_loi:='loi:Nhap so GCN xe '||a_bien(ds_lp)||':loi'; return;
elsif b_so_hdL='T' or ds_kieu_gcn(ds_lp)<>'S' then
if b_so_hdL='T' then ds_gcn(ds_lp):=substr(to_char(ds_so_id(ds_lp)),3); end if;
if ds_kieu_gcn(ds_lp) in('B','S') then
select count(*) into b_i1 from bh_xe_ds where ma_dvi=b_ma_dvi and so_id_dt=ds_so_id(ds_lp) and kieu_gcn=b_kieu_hd;
ds_gcn(ds_lp):=ds_gcn(ds_lp)||'/'||b_kieu_hd||to_char(b_i1+1);
end if;
else
PBH_XE_VACH('XE',ds_gcn(ds_lp),b_loi);
if b_loi is not null then return; end if;
end if;
end if;
EXECUTE IMMEDIATE b_lenh bulk collect into
dk_maX,dk_tenX,dk_tcX,dk_ma_ctX,dk_kieuX,dk_tienX,dk_ptX,dk_phiX,dk_thueX,dk_capX,
dk_ma_dkX,dk_lh_nvX,dk_t_suatX,dk_ptBX,dk_phiBX,dk_lkePX,dk_lkeBX using a_ds_dkbs(ds_lp);
for b_lp in 1..dk_maX.count loop
b_kt:=b_kt+1; dk_so_id(b_kt):=ds_so_id(ds_lp);
dk_bt(b_kt):=b_lp+10000;
-- chuclh - dieu khoan bo sung dk_kieu, dk_lh_bh
dk_kieu(b_kt):=dk_kieuX(b_lp); dk_ma(b_kt):=dk_maX(b_lp); dk_ten(b_kt):=dk_tenX(b_lp);
dk_tc(b_kt):=dk_tcX(b_lp); dk_ma_ct(b_kt):=dk_ma_ctX(b_lp); dk_tien(b_kt):=dk_tienX(b_lp);
dk_pt(b_kt):=dk_ptX(b_lp); dk_phi(b_kt):=dk_phiX(b_lp); dk_thue(b_kt):=dk_thueX(b_lp);
dk_cap(b_kt):=dk_capX(b_lp); dk_ma_dk(b_kt):=dk_ma_dkX(b_lp); dk_lh_nv(b_kt):=dk_lh_nvX(b_lp);
dk_t_suat(b_kt):=dk_t_suatX(b_lp); dk_ptB(b_kt):=dk_ptBX(b_lp); dk_phiB(b_kt):=dk_phiBX(b_lp);
dk_lkeP(b_kt):=dk_lkePX(b_lp); dk_lkeB(b_kt):=dk_lkeBX(b_lp); dk_lh_bh(b_kt):='M';
end loop;
for b_lp in 1..dk_maX.count loop
b_ma_dk:=FBH_MA_DKBS_MA_DK(dk_ma_dkX(b_lp));
if b_ma_dk<>' ' then
b_i1:=FKH_ARR_VTRI(dk_ma_dk,b_ma_dk);
if b_i1 not between 1 and b_ktG then
b_loi:='loi:Dieu khoan bo sung '||dk_ma_dkX(b_lp)||' phai gan kem dieu khoan chinh '||b_ma_dk||':loi'; return;
end if;
end if;
end loop;
if b_loi is not null then return; end if;
for b_lp in 1..dk_ma.count loop
dk_ma(b_lp):=trim(dk_ma(b_lp));
if dk_ma(b_lp) is null then b_loi:='loi:Loi nhap chi tiet nghiep vu xe '||a_bien(ds_lp)||':loi'; return; end if;
dk_lh_nv(b_lp):=nvl(trim(dk_lh_nv(b_lp)),' '); dk_tien(b_lp):=nvl(dk_tien(b_lp),0);
dk_phi(b_lp):=nvl(dk_phi(b_lp),0); dk_phiB(b_lp):=nvl(dk_phiB(b_lp),0);
if b_c_thue='K' then dk_thue(b_lp):=0; else dk_thue(b_lp):=nvl(dk_thue(b_lp),0); end if;
dk_ttoan(b_lp):=dk_phi(b_lp)+dk_thue(b_lp);
end loop;
--
lt_so_id(ds_lp):=ds_so_id(ds_lp);
lt_dk(ds_lp):=a_ds_dk(ds_lp);lt_lt(ds_lp):=a_ds_lt(ds_lp); lt_kbt(ds_lp):=a_ds_kbt(ds_lp);
PKH_JS_THAYn(a_ds_ct(ds_lp),'so_id_dt',ds_so_id(ds_lp));
PKH_JS_THAYa(a_ds_ct(ds_lp),'gcn,gcn_g',ds_gcn(ds_lp)||','||ds_gcnG(ds_lp));
end loop;
if b_kieu_hd in('B','S') and b_so_idG<>0 then
for r_lp in (select so_id_dt,gcn from bh_xe_ds where ma_dvi=b_ma_dvi and so_id=b_so_idG) loop
if FKH_ARR_VTRI_N(ds_so_id,r_lp.so_id_dt)=0 then b_loi:='loi:Khong xoa GCN cu '||r_lp.gcn||':loi'; return; end if;
end loop;
end if;
if b_c_thue<>'C' then
for b_lp in 1..dk_so_id.count loop dk_thue(b_lp):=0; end loop;
else
for b_lp in 1..dk_so_id.count loop
dk_thue(b_lp):=round(dk_phi(b_lp)*dk_t_suat(b_lp)/100, b_tp);
end loop;
end if;
for b_lp in 1..dk_so_id.count loop
dk_ttoan(b_lp):=dk_phi(b_lp)+dk_thue(b_lp);
end loop;
PBH_HD_THAY_PHIg(b_nt_tien,b_nt_tien,b_tygia,b_thueH,b_ttoanH,dk_lh_nv,dk_tien,dk_phi,dk_thue,dk_ttoan,b_loi);
if b_loi is not null then return; end if;
for b_lp in 1..dk_ma.count loop
-- viet anh them dkien dk_tien=0
if dk_phiB(b_lp)>dk_phi(b_lp) then
if dk_tien(b_lp)<>0 and dk_ptB(b_lp) <= 100 then
dk_phiG(b_lp):=dk_phiB(b_lp)-dk_phi(b_lp);
dk_ptG(b_lp):=round(dk_phiG(b_lp)*dk_ptB(b_lp)/dk_phiB(b_lp),2);
else
dk_phiG(b_lp):=dk_phiB(b_lp)-dk_phi(b_lp);
dk_ptG(b_lp):=round(dk_phiG(b_lp)*100/dk_phiB(b_lp),2);
end if;
else
dk_ptG(b_lp):=0; dk_phiG(b_lp):=0;
end if;
end loop;
for b_lp in 1..ds_so_id.count loop
b_phi:=0; b_thue:=0; b_giam:=0;
for b_lp1 in 1..dk_so_id.count loop
if dk_lh_nv(b_lp1)<>' ' and dk_so_id(b_lp1)=ds_so_id(b_lp) then
b_phi:=b_phi+dk_phi(b_lp1); b_thue:=b_thue+dk_thue(b_lp1); b_giam:=b_giam+dk_phiG(b_lp1);
end if;
end loop;
ds_giam(b_lp):=b_giam; ds_phi(b_lp):=b_phi; ds_thue(b_lp):=b_thue; ds_ttoan(b_lp):=b_phi+b_thue;
end loop;
for b_lp in 1..ds_so_id.count loop
ds_xe_id(b_lp):=FBH_XEtso_SO_ID(ds_bien_xe(b_lp),ds_so_khung(b_lp));
if ds_xe_id(b_lp)<>0 then
for r_lp in(select distinct nv_bh from bh_xe_ds where xe_id=ds_xe_id(b_lp) and so_id_dt<>ds_so_id(b_lp) and
FKH_GIAO(ds_ngay_hl(b_lp),ds_ngay_kt(b_lp),ngay_hl,ngay_kt)='C' and FBH_XE_TTRANG(ma_dvi,so_id,'C')='D') loop
b_nv_bhC:=r_lp.nv_bh; b_i1:=length(b_nv_bhC);
for b_lp in 1..b_i1 loop
if instr(ds_nv_bh(b_lp),substr(b_nv_bhC,b_lp,1))<>0 then
b_loi:='loi:Trung thoi gian bao hiem xe '||a_bien(b_lp)||':loi'; return;
end if;
end loop;
end loop;
else
PHT_ID_MOI(ds_xe_id(b_lp),b_loi);
if b_loi is not null then return; end if;
end if;
end loop;
if b_ttrang in('T','D') then
for b_lp in 1..ds_so_id.count loop
b_lenh:=FKH_JS_LENH('loai_khh,tenh,dchih,cmth,mobih,emailh');
EXECUTE IMMEDIATE b_lenh into b_loai_khH,b_tenH,b_dchiH,b_cmtH,b_mobiH,b_emailH using a_ds_ct(b_lp);
if trim(b_tenH) is not null then
ds_ng_huong(b_lp):=b_tenH;
if trim(b_cmtH) is not null then
if b_loai_khH='C' then
ds_ng_huong(b_lp):=b_tenH||', so CMT/CCCD: '||b_cmtH;
else
ds_ng_huong(b_lp):=b_tenH||', ma thue : '||b_cmtH;
end if;
end if;
if trim(b_dchiH) is not null then
ds_ng_huong(b_lp):=b_tenH||', dia chi: '||b_dchiH;
end if;
select json_object('loai' value b_loai_khH,'ten' value b_tenH,'cmt' value b_cmtH,
'dchi' value b_dchiH,'mobi' value b_mobiH,'email' value b_emailH) into b_txt from dual;
PBH_DTAC_MA_NH(b_txt,b_ma_khH,b_loi,b_ma_dvi,b_nsd);
if b_ma_khH not in(' ','VANGLAI') then PKH_JS_THAY(a_ds_ct(b_lp),'ma_khH',b_ma_khH); end if;
end if;
if ds_tenC(b_lp)<>' ' and ds_tenC(b_lp)<>b_ten and trim(ds_cmtC(b_lp)||ds_mobiC(b_lp)||ds_emailC(b_lp)) is not null then
select json_object('loai' value 'C','ten' value ds_tenC(b_lp),'cmt' value ds_cmtC(b_lp),
'dchi' value ds_dchiC(b_lp),'mobi' value ds_mobiC(b_lp),'email' value ds_emailC(b_lp)) into b_txt from dual;
PBH_DTAC_MA_NH(b_txt,b_ma_khH,b_loi,b_ma_dvi,b_nsd);
if b_ma_khH not in(' ','VANGLAI') then PKH_JS_THAY(a_ds_ct(b_lp),'ma_khC',b_ma_khH); end if;
end if;
end loop;
end if;
for b_lp in 1..ds_so_id.count loop
if ds_ktru(b_lp)<>0 then
PBH_XEG_KBT(ds_nv_bh(b_lp),ds_so_idP(b_lp),ds_ktru(b_lp),a_ds_kbt(b_lp),b_loi);
if b_loi is not null then return; end if;
end if;
select json_object('ds_ct' value a_ds_ct(b_lp),'ds_dk' value a_ds_dk(b_lp),
'ds_lt' value a_ds_lt(b_lp),'ds_kbt' value a_ds_kbt(b_lp),'ds_ttt' value a_ds_ttt(b_lp),
'ds_dkbs' value a_ds_dkbs(b_lp) returning clob) into a_dsM(b_lp) from dual;
end loop;
dt_ds:=FKH_ARRc_JS(a_dsM);
b_loi:='';
exception when others then if b_loi is null then raise PROGRAM_ERROR; else null; end if;
end;