Project

General

Profile

báo giá xe

SQL Sprint
13/05/2025

create or replace PROCEDURE PTBH_BAO_NV_XE(
    b_so_idT number,b_ma_dvi varchar2,b_so_id number,b_so_id_dtB number,
    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_nt_tien varchar2(5); b_nt_phi varchar2(5);
    a_ma_taT pht_type.a_var; a_ptT pht_type.a_num;
begin
-- Dan - Ghep nghiep vu xe
b_loi:='loi:Loi xu ly PTBH_BAO_NV_XE:loi';
delete tbh_ghep_nv_temp; delete tbh_ghep_nv_temp2;
if FBH_BAO_BGHD_XE(b_ma_dvi,b_so_id)=' ' then
    select ngay_ht,ngay_hl,ngay_kt,nt_tien,nt_phi into b_ngay_ht,b_ngay_hl,b_ngay_kt,b_nt_tien,b_nt_phi
        from bh_xeB where ma_dvi=b_ma_dvi and so_id=b_so_id;
else
    select ngay_ht,ngay_hl,ngay_kt,nt_tien,nt_phi into b_ngay_ht,b_ngay_hl,b_ngay_kt,b_nt_tien,b_nt_phi
        from bh_xe where ma_dvi=b_ma_dvi and so_id=b_so_id;
end if;
if b_nt_tien<>'VND' then b_tp:=2; end if;
PTBH_BAO_NV_XEd(b_ma_dvi,b_so_id,b_so_id_dtB,b_loi);
if b_loi is not null then return; end if;
b_ma_dt:=FBH_XEB_MA_DT(b_ma_dvi,b_so_id,b_so_id_dtB);
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