select 0, typprx, typtie, sigtie, codpro, prxvdu, qtemin, coddev, etbcod, codbar, sigrep, codeop, pricestatus
from (
-- Corporate and Standard Prices:
-- Select * from tas
-- if codreg = ' ' then 'Corporate' else 'Standard'
select decode(tas.codreg, ' ', '10.Corporate', '09.Standard') typprx, 'CLI' typtie, ' ' sigtie, tas.codpro, tas.prxstd1 prxvdu, 1 qtemin, tas.coddev, tas.codreg etbcod, ' ' codbar, ' ' sigrep, ' ' codeop, '1' pricestatus
from tas, pro
where pro.codsoc = 0
and pro.codblocage in ('11','11B', 'INV', '15')
and not (pro.fampro = '5BSERV' and pro.sfapro = 'CHARGE')
and upper(substr(pro.codpro, 3, 1)) != 'X'
--and zod.codsoc = 0
--and zod.typzod = 'PRO'
--and zod.numzod = '109'
--and zod.valzod != ' '
--and zod.clezod = pro.codpro
and tas.codsoc = 0
and tas.achvte = 'V'
and tas.codpro = pro.codpro
and to_char(sysdate, 'YYYYMMDD') between tas.datapp1 and decode(tas.datval1, ' ', to_char(sysdate, 'YYYYMMDD'), tas.datval1)
and not (to_char(sysdate, 'YYYYMMDD') between tas.datapp2 and decode(tas.datval2, ' ', to_char(sysdate, 'YYYYMMDD'), tas.datval2) and tas.datapp2 > tas.datapp1)
and not (to_char(sysdate, 'YYYYMMDD') between tas.datapp3 and decode(tas.datval3, ' ', to_char(sysdate, 'YYYYMMDD'), tas.datval3) and tas.datapp3 > tas.datapp1)
union all
-- Quantity Level Prices
-- Select * from tac where codbar <> ' '
select decode(tac.codreg, ' ', '08.Quantity GIE', '07.Quantity REG') typprx, 'CLI' typtie, ' ' sigtie, tac.codpro, tac.prxcol1 prxvdu, tac.qtemin, tac.coddev, tac.codreg etbcod, tac.codbar, ' ' sigrep, ' ' codeop, '1' pricestatus
from tac, tas, pro
where pro.codsoc = 0
and pro.codblocage in ('11','11B', 'INV', '15')
and not (pro.fampro = '5BSERV' and pro.sfapro = 'CHARGE')
and upper(substr(pro.codpro, 3, 1)) != 'X'
--and zod.codsoc = 0
--and zod.typzod = 'PRO'
--and zod.numzod = '109'
--and zod.valzod != ' '
--and zod.clezod = pro.codpro
and tas.codsoc = 0
and tas.achvte = 'V'
and tas.codpro = pro.codpro
and to_char(sysdate, 'YYYYMMDD') between tas.datapp1 and decode(tas.datval1, ' ', to_char(sysdate, 'YYYYMMDD'), tas.datval1)
and not (to_char(sysdate, 'YYYYMMDD') between tas.datapp2 and decode(tas.datval2, ' ', to_char(sysdate, 'YYYYMMDD'), tas.datval2) and tas.datapp2 > tas.datapp1)
and not (to_char(sysdate, 'YYYYMMDD') between tas.datapp3 and decode(tas.datval3, ' ', to_char(sysdate, 'YYYYMMDD'), tas.datval3) and tas.datapp3 > tas.datapp1)
and tac.codsoc = 0
and tac.achvte = 'V'
and tac.codpro = tas.codpro
and tac.codreg = tas.codreg
and tac.codbar = ' '
union all
-- Scale Prices
-- Select * from tac where codbar = ' '
select decode(tac.codreg, ' ', '06.Scale GIE', '05.Scale REG') typprx, 'CLI' typtie, ' ' sigtie, tac.codpro, tac.prxcol1 prxvdu, tac.qtemin, tac.coddev, tac.codreg etbcod, tac.codbar, tbl.lib2 sigrep, ' ' codeop, tbl.lir pricestatus
from tbl, tac, tas, pro
where pro.codsoc = 0
and pro.codblocage in ('11','11B', 'INV', '15')
and not (pro.fampro = '5BSERV' and pro.sfapro = 'CHARGE')
and upper(substr(pro.codpro, 3, 1)) != 'X'
--and zod.codsoc = 0
--and zod.typzod = 'PRO'
--and zod.numzod = '109'
--and zod.valzod != ' '
--and zod.clezod = pro.codpro
and tas.codsoc = 0
and tas.achvte = 'V'
and tas.codpro = pro.codpro
and to_char(sysdate, 'YYYYMMDD') between tas.datapp1 and decode(tas.datval1, ' ', to_char(sysdate, 'YYYYMMDD'), tas.datval1)
and not (to_char(sysdate, 'YYYYMMDD') between tas.datapp2 and decode(tas.datval2, ' ', to_char(sysdate, 'YYYYMMDD'), tas.datval2) and tas.datapp2 > tas.datapp1)
and not (to_char(sysdate, 'YYYYMMDD') between tas.datapp3 and decode(tas.datval3, ' ', to_char(sysdate, 'YYYYMMDD'), tas.datval3) and tas.datapp3 > tas.datapp1)
and tac.codsoc = 0
and tac.achvte = 'V'
and tac.codpro = tas.codpro
and tac.codreg = tas.codreg
and tac.codbar <> ' '
and tbl.codsoc = 0 and tbl.codtbl = '310' and tbl.lir = tac.codbar and tbl.lib3 = decode(tac.codreg, ' ', 'GIE', tac.codreg) and tbl.num1 in (1, 2)
union all
-- Specific Price CLI : tqui = 1 / tqoi = 501 select '04.Specific Price CLI' typprx, tie.typtie, tie.sigtie, pro.codpro, cts.prxnet prxvdu, cts.qtemin, cts.coddev, cts.etbcod, tie.codbar, tie.sigrep, ' ' codeop, '1' pricestatus
from cts, pro, tie
where tie.codsoc = 0
and tie.typtie = 'CLI'
and tie.codett = 'CUS' and pro.codsoc = 0
and pro.codblocage in ('11','11B', 'INV', '15')
and not (pro.fampro = '5BSERV' and pro.sfapro = 'CHARGE')
and upper(substr(pro.codpro, 3, 1)) != 'X'
--and zod.codsoc = 0
--and zod.typzod = 'PRO'
--and zod.numzod = '109'
--and zod.valzod != ' '
--and zod.clezod = pro.codpro
and cts.codsoc = 0
and cts.achvte = 'V'
and cts.typcot = 'LIG'
and cts.tqui = '1' and cts.tqoi = '501'
and cts.codcre = 'PRN'
and to_char(sysdate, 'YYYYMMDD') between cts.datapp and cts.datval
and cts.clequi = tie.sigtie
and cts.cleqoi = pro.codpro
and cts.datapp = (select max(cts2.datapp) from cts cts2
where cts2.codsoc = cts.codsoc
and cts2.achvte = cts.achvte
and cts2.typcot = cts.typcot
and cts2.tqui = cts.tqui and cts2.tqoi = cts.tqoi
and cts2.codcre = cts.codcre
and to_char(sysdate, 'YYYYMMDD') between cts2.datapp and cts2.datval
and cts2.clequi = cts.clequi
and cts2.cleqoi = cts.cleqoi)
union all -- Specific Price GRC : tqui = 3 / tqoi = 501 select '03.Specific Price GRC' typprx, tie.typtie, tie.sigtie, pro.codpro, cts.prxnet prxvdu, cts.qtemin, cts.coddev, cts.etbcod, tie.codbar, tie.sigrep, ' ' codeop, '1' pricestatus
from cts, pro, tie
where tie.codsoc = 0
and tie.typtie = 'GRC'
and tie.codett = 'CUS' and pro.codsoc = 0
and pro.codblocage in ('11','11B', 'INV', '15')
and not (pro.fampro = '5BSERV' and pro.sfapro = 'CHARGE')
and upper(substr(pro.codpro, 3, 1)) != 'X'
--and zod.codsoc = 0
--and zod.typzod = 'PRO'
--and zod.numzod = '109'
--and zod.valzod != ' '
--and zod.clezod = pro.codpro
and cts.codsoc = 0
and cts.achvte = 'V'
and cts.typcot = 'LIG'
and cts.tqui = '3' and cts.tqoi = '501'
and cts.codcre = 'PRN'
and to_char(sysdate, 'YYYYMMDD') between cts.datapp and cts.datval
and cts.clequi = tie.sigtie
and cts.cleqoi = pro.codpro
and cts.datapp = (select max(cts2.datapp) from cts cts2
where cts2.codsoc = cts.codsoc
and cts2.achvte = cts.achvte
and cts2.typcot = cts.typcot
and cts2.tqui = cts.tqui and cts2.tqoi = cts.tqoi
and cts2.codcre = cts.codcre
and to_char(sysdate, 'YYYYMMDD') between cts2.datapp and cts2.datval
and cts2.clequi = cts.clequi
and cts2.cleqoi = cts.cleqoi)
union all
-- Specific Price GRC : tqui = 4 / tqoi = 501
-- And cts.clequi = cnx.numcnt
select '02.Agreement' typprx, tie.typtie, tie.sigtie, pro.codpro, cts.prxnet prxvdu, cts.qtemin qte, cts.coddev, cts.etbcod, tie.codbar, tie.sigrep, ' ' codeop, '1' pricestatus
from cts, pro, cnt, tie
where tie.codsoc = 0
and tie.typtie in ('CLI', 'GRC')
and tie.codett = 'CUS' and cnt.codsoc = 0
and cnt.achvte = 'V'
and cnt.typeve = 'CNT'
and to_char(sysdate, 'YYYYMMDD') between cnt.datapp and cnt.datval
and cnt.typtie = tie.typtie
and cnt.sigtie = tie.sigtie
and pro.codsoc = 0
and pro.codblocage in ('11','11B', 'INV', '15')
and not (pro.fampro = '5BSERV' and pro.sfapro = 'CHARGE')
and upper(substr(pro.codpro, 3, 1)) != 'X'
--and zod.codsoc = 0
--and zod.typzod = 'PRO'
--and zod.numzod = '109'
--and zod.valzod != ' '
--and zod.clezod = pro.codpro
and cts.codsoc = 0
and cts.achvte = 'V'
and cts.typcot = 'LIG'
and cts.tqui = '4' and cts.tqoi = '501'
and cts.codcre = 'PRN'
and to_char(sysdate, 'YYYYMMDD') between cts.datapp and cts.datval
and cts.clequi = cnt.numcnt
and cts.cleqoi = pro.codpro
union all
-- Promotion : tqui = 85 / tqoi = 501
-- Need to match codeop each time the user look for prices (need to be entered mannualy) select '01.Promotion' typprx, tie.typtie, tie.sigtie, pro.codpro, cts.prxnet prxvdu, cts.qtemin, cts.coddev, tie.etbcod, tie.codbar, tie.sigrep, ope.codeop, '1' pricestatus
from cts, pro, tie, opc, ope
where ope.codsoc = 0
and to_char(sysdate, 'YYYYMMDD') between ope.datdeb and ope.datfin
and opc.codsoc = 0
and opc.codeop = ope.codeop
and opc.typtie in ('CLI', 'GRC')
and tie.codsoc = 0
and tie.typtie = opc.typtie
and tie.sigtie = opc.sigtie
and tie.codett = 'CUS'
and pro.codsoc = 0
and pro.codblocage in ('11','11B', 'INV', '15')
and not (pro.fampro = '5BSERV' and pro.sfapro = 'CHARGE')
and upper(substr(pro.codpro, 3, 1)) != 'X'
--and zod.codsoc = 0
--and zod.typzod = 'PRO'
--and zod.numzod = '109'
--and zod.valzod != ' '
--and zod.clezod = pro.codpro
and cts.codsoc = 0
and cts.achvte = 'V'
and cts.typcot = 'LIG'
and cts.tqui = '85' and cts.tqoi = '501'
and cts.codcre = 'PRN'
and cts.clequi = ope.codeop
and cts.cleqoi = pro.codpro
) tmp
|