insert into fee(fee_id, FRAN_ID, fee_sdate, fee_fruse, fee_royal, fee_cost, fee_tplus, fee_tminus, fee_overdue, fee_cpn)
values(
'CB2022901' ||'-'||TO_CHAR(sysdate,'yyyyMMDD'),
'CB2022901',
TO_CHAR(sysdate,'yyyy/MM/DD'),
500000,
(select total*0.05 as royal
from(
select sum(a.pay_cost) as total
from pay a
inner join morder b
on (a.morder_id = b.morder_id)
where (a.pay_date >= '2022/08/01' and a.pay_date < '2022/09/01')
and a.morder_id in (
select b.morder_id
from resv a
right outer join morder b
on (a.resv_id = b.resv_id)
where a.fran_id='CB2022901'
and (a.resv_date >= '2022/08/01' and a.resv_date < '2022/09/01')
or b.resv_id is null
)
)),
(select sum(frorder_price) as total_frorder_price
from frorder
where fran_id='CB2022901'
and FRORDER_STATE = 'ST15'
and (frorder_date >= '2022/08/01' and frorder_date < '2022/09/01')),
(select sum(sum_per) as trade_plus_sum
from (
select distinct b.buyerprod_id, b.sum_qty, a.headin_release, sum_qty * headin_release as sum_per
from headin a
inner join (
select buyerprod_id, sum(resp_qty) as sum_qty
from trade
where req_fran = 'CB2022901'
and (req_date>= '2022/08/01' and req_date < '2022/09/01')
and resp_qty is not null
group by buyerprod_id
) b
on a.buyerprod_id = b.buyerprod_id ) ),
(select sum(sum_per) as trade_minus_sum
from (
select distinct b.buyerprod_id, b.sum_qty, a.headin_release, sum_qty * headin_release as sum_per
from headin a
inner join (
select buyerprod_id, sum(resp_qty) as sum_qty
from trade
where resp_fran = 'CB2022901'
and (req_date>= '2022/08/01' and req_date < '2022/09/01')
and resp_qty is not null
group by buyerprod_id
) b
on a.buyerprod_id = b.buyerprod_id)),
0,
(select sum(lgu_name)
from (
select distinct a.mycpn_id, b.lgu_name
from(
select distinct a.MYCPN_ID, b.cpn_lgu
from (
select distinct a.mycpn_id, b.cpn_id
from(
select distinct a.mycpn_id
from pay a
inner join morder b
on (a.morder_id = b.morder_id)
where (a.pay_date >= '2022/08/01' and a.pay_date < '2022/09/01')
and a.morder_id in (
select b.morder_id
from resv a
right outer join morder b
on (a.resv_id = b.resv_id)
where a.fran_id='CB2022901'
and (a.resv_date >= '2022/08/01' and a.resv_date < '2022/09/01')
or b.resv_id is null
)
) a
inner join mycpn b
on(a.mycpn_id = b.mycpn_id)
) a
inner join cpn b
on (a.cpn_id = b.cpn_id)
) a
inner join lgu b
on(a.cpn_lgu = b.lgu_id)
))
)
select total*0.05 as royal
from(
select sum(a.pay_cost) as total
from pay a
inner join morder b
on (a.morder_id = b.morder_id)
where (a.pay_date >= '2022/08/01' and a.pay_date < '2022/09/01')
and a.morder_id in (
select b.morder_id
from resv a
right outer join morder b
on (a.resv_id = b.resv_id)
where a.fran_id='CB2022901'
and (a.resv_date >= '2022/08/01' and a.resv_date < '2022/09/01')
or b.resv_id is null
)
);
select sum(frorder_price) as total_frorder_price
from frorder
where fran_id='CB2022901'
and FRORDER_STATE = 'ST15'
and (frorder_date >= '2022/08/01' and frorder_date < '2022/09/01')
select sum(sum_per) as trade_plus_sum
from (
select distinct b.buyerprod_id, b.sum_qty, a.headin_release, sum_qty * headin_release as sum_per
from headin a
inner join (
select buyerprod_id, sum(resp_qty) as sum_qty
from trade
where req_fran = 'CB2022901'
and (req_date>= '2022/08/01' and req_date < '2022/09/01')
and resp_qty is not null
group by buyerprod_id
) b
on a.buyerprod_id = b.buyerprod_id
);
select sum(sum_per) as trade_minus_sum
from (
select distinct b.buyerprod_id, b.sum_qty, a.headin_release, sum_qty * headin_release as sum_per
from headin a
inner join (
select buyerprod_id, sum(resp_qty) as sum_qty
from trade
where resp_fran = 'CB2022901'
and (req_date>= '2022/08/01' and req_date < '2022/09/01')
and resp_qty is not null
group by buyerprod_id
) b
on a.buyerprod_id = b.buyerprod_id
);
select sum(lgu_name)
from (
select distinct a.mycpn_id, b.lgu_name
from(
select distinct a.MYCPN_ID, b.cpn_lgu
from (
select distinct a.mycpn_id, b.cpn_id
from(
select distinct a.mycpn_id
from pay a
inner join morder b
on (a.morder_id = b.morder_id)
where (a.pay_date >= '2022/08/01' and a.pay_date < '2022/09/01')
and a.morder_id in (
select b.morder_id
from resv a
right outer join morder b
on (a.resv_id = b.resv_id)
where a.fran_id='CB2022901'
and (a.resv_date >= '2022/08/01' and a.resv_date < '2022/09/01')
or b.resv_id is null
)
) a
inner join mycpn b
on(a.mycpn_id = b.mycpn_id)
) a
inner join cpn b
on (a.cpn_id = b.cpn_id)
) a
inner join lgu b
on(a.cpn_lgu = b.lgu_id)
);