Saturday, March 23, 2013
Tran Seq No wise Tax,Discount details, gross amount and net amount in RESA
with
resa_tran as
(
select /*+ MATERIALIZE */ sth.store store,s.store_name Store_Name,trunc(tran_datetime) tran_date ,tran_seq_no, ssd.business_date,
sth.day,
value , tran_type,tran_no,REGISTER,CASHIER
from sa_tran_head sth,sa_store_day ssd,store s
where s.store = sth.store and s.store between 999 and 9999 and s.store in (1495,1569,3023)--and tran_seq_no in (1216648196)
and ssd.store_day_seq_no = sth.store_day_seq_no and
sth.status = 'P' and tran_type in ('SALE','RETURN')
and trunc(sth.tran_datetime) between '26-Mar-12' and '05-Apr-12'
)
select a.Store "Store", a.store_name "Store Name",a.tran_date "Transaction Date",a.tran_seq_no "Tran Seq No",
a.value "Reliazed Sale" , a.tran_type "Transcation Type" ,a.tran_no "Bill No" ,a.REGISTER "Pos Terminal No",a.CASHIER "Staff Id",
--a.item,a.item_seq_no,
sum(total_retail) "Total Retail/Gross Amt",sum(nvl(disc,0)) "Discount", sum(nvl(tax,0)) "Tax Amount"
,(sum(total_retail)- sum(nvl(disc,0)) - sum(nvl(tax,0))) "Net Amount"
from
(
select rt.store, rt.store_name, rt.business_date,rt.day, rt.tran_date, rt.tran_seq_no,sti.item,sti.item_seq_no,
value , tran_type,tran_no,REGISTER,CASHIER,
sum(sti.qty*sti.unit_retail) total_retail
from resa_tran rt, sa_tran_item sti, item_master im, deps d, groups gp
where
rt.tran_seq_no = sti.TRAN_SEQ_NO and rt.store = sti.store and rt.day = sti.day
and im.dept = d.dept and sti.item = im.item and d.GROUP_NO = gp.group_no
group by rt.store,rt.store_name,rt.tran_date, rt.business_date,rt.day, rt.tran_seq_no, sti.item_seq_no,sti.item,
value , tran_type,tran_no,REGISTER,CASHIER
) a,
(
select rt.store, business_date,rt.day, rt.tran_seq_no, std.ITEM_SEQ_NO,
sum(nvl(std.QTY,0)*nvl(std.UNIT_DISCOUNT_AMT,0)) disc
from resa_tran rt, sa_tran_disc std
where rt.tran_seq_no = std.TRAN_SEQ_NO and rt.store = std.store and rt.day = std.day
group by rt.store, business_date ,rt.day, std.item_seq_no, rt.tran_seq_no
) b,
(
select rt.store, business_date,rt.day, rt.tran_seq_no, stg.ITEM_SEQ_NO,
sum(nvl(stg.QTY,0)*nvl(stg.UNIT_IGTAX_AMT,0)) Tax
from resa_tran rt, sa_tran_igtax stg
where rt.tran_seq_no = stg.TRAN_SEQ_NO and rt.store = stg.store and rt.day = stg.day
group by rt.store, business_date ,rt.day, stg.item_seq_no, rt.tran_seq_no
) c
where a.tran_seq_no = b.tran_seq_no(+) and a.item_seq_no = b.item_seq_no(+) and a.store = b.store(+) and a.day = b.day(+) and
a.tran_seq_no = c.tran_seq_no(+) and a.item_seq_no = c.item_seq_no(+) and a.store = c.store(+) and a.day = c.day(+)
group by a.Store, a.store_name,a.tran_date,a.tran_seq_no,--,a.item,a.item_seq_no
value , tran_type,tran_no,REGISTER,CASHIER
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment