3109
SQL Sprint
27/04/2025
create or replace procedure PBH_HD_TT_NH_VAT_DO(
b_ma_dvi varchar2,b_nsd varchar2,b_so_id_tt number,b_ngay_ht number,b_phong varchar2,b_nha_bh varchar2,
b_ma_nt varchar2,b_so_don varchar2,b_ngay_bc number,b_loi out varchar2)
AS
b_i1 number; b_ma_thue varchar2(30); b_ten nvarchar2(50); b_dchi nvarchar2(50); b_don varchar2(50);
begin
-- Dan - Nhap hoa don VAT dong BH
select nvl(sum(ttoan_qd),-1) into b_i1 from bh_hd_goc_ttpt where ma_dvi=b_ma_dvi and so_id_tt=b_so_id_tt and pt not in('C','N','H');
if b_i1<0 then b_loi:=''; return; end if;
select ten,dchi,cmt into b_ten,b_dchi,b_ma_thue from bh_ma_nbh where ma=b_nha_bh;
b_loi:='loi:Trung so hoa don VAT:loi';
insert into bh_hd_do_vat values(b_ma_dvi,b_so_id_tt,b_ngay_ht,'R',b_nha_bh,
b_ten,b_dchi,b_ma_thue,b_so_don,b_ngay_bc,b_phong,b_nsd,sysdate);
delete temp_1;
insert into temp_1(c1,n1,n2,n3,n4) select ma_nt,sum(phi),sum(phi_qd),sum(thue),sum(thue_qd) from bh_hd_goc_ttpt
where ma_dvi=b_ma_dvi and so_id_tt=b_so_id_tt and pt not in('C','N','H') group by ma_nt;
insert into bh_hd_do_vat_ct select b_ma_dvi,b_so_id_tt,rownum,b_so_id_tt,c1,n1,n2,n3,n4 from temp_1;
PBH_HD_DO_TH_VAT(b_ma_dvi,b_so_id_tt,b_loi);
if b_loi is not null then return; end if;
exception when others then if b_loi is null then raise PROGRAM_ERROR; else null; end if;
end;