Project

General

Profile

lỗi duyệt báo giá

SQL Sprint
13/05/2025

create or replace procedure PTBH_BAO_NV_PKT(
    b_so_idT number,b_ma_dvi varchar2,b_so_id number,b_so_id_dtB number,
    a_ma_dvi pht_type.a_var,a_so_id pht_type.a_num,a_so_id_dt pht_type.a_num,
    b_ma_dt out varchar2,b_loi out varchar2)
AS
    b_ngay_ht number; b_ngay_hl number; b_ngay_kt number; b_tp number:=0; b_i1 number;
    b_kieu_ps varchar2(1); b_nv varchar2(10); b_so_hd varchar2(20);
    b_nt_tien varchar2(5); b_nt_phi varchar2(5); b_ma_dtT varchar2(10);
    a_ma_taT pht_type.a_var; a_ptT pht_type.a_num;
begin
-- Dan - Ghep tich tu voi 1 dtuong bao gia
b_loi:='loi:Loi xu ly PTBH_BAO_NV_PKT:loi';
delete tbh_ghep_nv_temp; delete tbh_ghep_nv_temp2;
-- chuclh:SUA THEO TAI SAN
PTBH_TM_TTINf(a_ma_dvi(1),a_so_id(1),b_kieu_ps,b_nv,b_so_hd,b_ngay_ht,b_ngay_hl,b_ngay_kt,b_nt_tien,b_nt_phi,b_loi);
if b_loi is not null then return; end if;
if b_nt_tien<>'VND' then b_tp:=2; end if;
b_ma_dt:=' ';
for b_lp in 1..a_ma_dvi.count loop
    if FBH_BAO_BGHD_PKT(a_ma_dvi(b_lp),a_so_id(b_lp))=' ' then
        select nvl(max(ma_dt),' ') into b_ma_dtT from bh_phhB_dvi where
            ma_dvi=a_ma_dvi(b_lp) and so_id=a_so_id(b_lp) and so_id_dt=a_so_id_dt(b_lp);
        PTBH_BAO_NV_PHHd(a_ma_dvi(b_lp),a_so_id(b_lp),a_so_id_dt(b_lp),b_ngay_ht,b_ngay_hl,b_ngay_kt,b_nt_tien,b_nt_phi,b_loi);
    else
        select nvl(max(ma_dt),' ') into b_ma_dtT from bh_phh_dvi where
            ma_dvi=a_ma_dvi(b_lp) and so_id=a_so_id(b_lp) and so_id_dt=a_so_id_dt(b_lp);
        PTBH_GHEP_NV_1(b_ma_dvi,b_ngay_ht,b_ngay_hl,0,'',b_nt_tien,b_nt_phi,
            a_ma_dvi(b_lp),a_so_id(b_lp),a_so_id_dt(b_lp),b_loi,'C');
    end if;
    if b_loi is not null then return; end if;
    b_ma_dtT:=FBH_PHH_DTUONG_CAT(b_ma_dtT);
    if b_ma_dtT>b_ma_dt then b_ma_dt:=b_ma_dtT; end if;
end loop;
insert into tbh_ghep_nv_temp
    select ma_ta,b_nt_tien,sum(tien),b_nt_phi,sum(phi),0,sum(do_tien),0,sum(ta_tien),0,sum(ve_tien)
    from tbh_ghep_nv_temp2 group by ma_ta having sum(tien)<>0 or sum(phi)<>0;
select b.ma_ta,sum(b.pt) bulk collect into a_ma_taT,a_ptT from tbh_tmB a,tbh_tmB_phi b where
    a.ma_dviP=b_ma_dvi and a.so_idP=b_so_id and a.so_id_dtP in(0,b_so_id_dtB) and a.so_id<>b_so_idT and b.so_id=a.so_id
    group by b.ma_ta;
for b_lp in 1..a_ma_taT.count loop
    update tbh_ghep_nv_temp set ta_tien=ta_tien+round(tien*a_ptT(b_lp)/100,b_tp) where ma_ta=a_ma_taT(b_lp);
end loop;
update tbh_ghep_nv_temp set do_tl=round(do_tien*100/tien,2),ta_tl=round(ta_tien*100/tien,2),ve_tl=round(ve_tien*100/tien,2) where tien<>0;
delete tbh_ghep_nv_temp2;
b_loi:='';
end;

Files