drop table t204_ap_summary 
/
create table t204_ap_summary 
( f_fypd                   char(06)       not null
, f_vndr_c                 char(20)       not null
, f_ap_a                   decimal(15,2)  not null
, f_txn_a                  decimal(15,2)  not null
, f_adm_a                  decimal(15,2)  not null
)
/
grant select on t204_ap_summary to commbill_user;
/

insert into t204_ap_summary
select a.f_fypd
     , a.f_vndr_c
     , 0
     , sum(a.f_txn_a)
     , sum(a.f_adm_a)
  from commbill_dbo.t204_cb_ldap_charges a
 group by a.f_fypd
        , a.f_vndr_c
/

insert into t204_ap_summary
select a.f_fypd
     , a.f_vndr_c
     , 0
     , sum(a.f_txn_a)
     , sum(a.f_adm_a)
  from commbill_dbo.t204_cb_ool_charges a
 group by a.f_fypd
        , a.f_vndr_c
/

insert into t204_ap_summary 
select f_fypd        
     , f_vndr_x   
     , sum(f_txn_a)
     , 0
     , 0
  from t204_ap_detail
 group by f_vndr_x
     , f_fypd
/

exit;
