--UNION DE UNIONES
--DATO SIN ICOM Y FEMs
select cuenta, desc_cuenta, cca, ccb, desc_ccb, sum(valor) SIN_IVA, sum(iva) IMPUESTO,
0 EXENTO,0 TASA_CERO from
(
--ciclicas
select --'FAC_CICLICA' TIPO_FAC, a.tctire DOC, a.tcabil*100+a.tcmbil EMISION,
--c.tcccon COD_SERV, c.tcdcnp DESC_SERV, a.facpro||a.faclip||a.factse||a.fatico PROD,
--sum(b.TCVDET) VALOR_CONCEPTO, sum(round( b.tcvdet * 0.13, 2)) IVA_CONCEPTO
d.cta_ctble cuenta,e.descripcion desc_cuenta, d.cca, d.ccb, f.descripcion desc_ccb,
sum(b.TCVDET) VALOR,
round(sum( b.tcvdet * 0.13) ,2) IVA
from v4stcdat.v4bilhed a, v4stcdat.v4bildet b, v4stcdat.v4concep c, conceptos_facturacion d,
cuentas_contables e, centros_costob f
where a.tcnure = b.tcnure and
a.tcnfol = b.tcnfol and
a.tcaseb = b.tcaseb and
a.tcmseb = b.tcmseb and
b.tcccon = c.tcccon and
a.tcabil = 2007 and a.tcmbil = 3
and a.tcccli not in (534,12291) --excluyendo a icom y delsur
and d.cod_servicio = c.tcccon
and d.producto = a.facpro||a.faclip||a.factse||a.fatico
and d.cta_ctble = e.nombre
and d.ccb = f.codigo
group by a.tcabil*100+a.tcmbil, --c.tcccon, c.tcdcnp,
--a.facpro||a.faclip||a.factse||a.fatico, a.tctire
d.cta_ctble, d.cca, d.ccb, e.descripcion, f.descripcion
--order by 1 asc
union
--manuales
select --'FAC_MANUAL' TIPO_FAC, a.fctdoc DOC, a.fcazfa*100+a.fcmefa PERIODO,
--b.fccser COD_SER, c.tcnser DESC_SERV, a.tccpro||a.tcclip||a.tcctse||a.tctico PROD,
--sum( b.fcpreb) VALOR_CONCEPTO, sum( b.fcvid1 ) IVA_CONCEPTO
d.cta_ctble cuenta, e.DESCRIPCION desc_cuenta, d.cca, d.ccb, f.descripcion desc_ccb,
sum( b.fcpreb) VALOR,
sum( b.fcvid1 ) IVA
from v4stcdat.f4prfhed a, v4stcdat.f4prfdet b, v4stcdat.v4servi c, conceptos_facturacion d,
cuentas_contables e, centros_costob f
--fctdoc = FEM
where a.fctfac = b.fctfac and
a.fcnfac = b.fcnfac and
b.fccser = c.tccser (+)and
a.tccpro||a.tcclip||a.tcctse||a.tctico not in ('PVAS','PVWS') and
a.fcazfa = 2007 and a.fcmefa = 3
and d.cod_servicio = b.fccser
and d.producto = a.tccpro||a.tcclip||a.tcctse||a.tctico
and a.fctdoc not in ('FEM') --excluyendo exportacion, porque son exentos
and d.cta_ctble = e.nombre
and d.ccb = f.codigo
group by --a.fcazfa*100+a.fcmefa, b.fccser , c.tcnser,
--a.tccpro||a.tcclip||a.tcctse||a.tctico, a.fctdoc
d.cta_ctble, d.cca, d.ccb, e.DESCRIPCION, f.descripcion
order by 1 asc
)
group by cuenta, desc_cuenta, cca, ccb, desc_ccb
UNION
--DATO DE ICOM ,sacando icom y del sur
select --'FAC_CICLICA' TIPO_FAC, a.tctire DOC, a.tcabil*100+a.tcmbil EMISION,
--c.tcccon COD_SERV, c.tcdcnp DESC_SERV, a.facpro||a.faclip||a.factse||a.fatico PROD,
--sum(b.TCVDET) VALOR_CONCEPTO, sum(round( b.tcvdet * 0.13, 2)) IVA_CONCEPTO
--d.cta_ctble,e.descripcion, d.cca, d.ccb, f.descripcion,
'NUMERO CTA' CUENTA, 'DESC CTA' DESC_CUENTA, 0 CCA, 'IPE01' CCB, 'CLIENTES ESPECIALES' DESC_CCB,
sum(b.TCVDET) SIN_IVA, round(sum( b.tcvdet * 0.13) ,2) IMPUESTO,0 EXENTO,0 TASA_CERO
from v4stcdat.v4bilhed a, v4stcdat.v4bildet b, v4stcdat.v4concep c, conceptos_facturacion d,
cuentas_contables e, centros_costob f
where a.tcnure = b.tcnure and
a.tcnfol = b.tcnfol and
a.tcaseb = b.tcaseb and
a.tcmseb = b.tcmseb and
b.tcccon = c.tcccon and
a.tcabil = 2007 and a.tcmbil = 3
and a.tcccli in (534,12291) --excluyendo a icom y delsur
and d.cod_servicio = c.tcccon
and d.producto = a.facpro||a.faclip||a.factse||a.fatico
and d.cta_ctble = e.nombre
and d.ccb = f.codigo
group by a.tcabil*100+a.tcmbil, --c.tcccon, c.tcdcnp,
--a.facpro||a.faclip||a.factse||a.fatico, a.tctire
d.cta_ctble, d.cca, d.ccb, e.descripcion, f.descripcion
UNION
--FEMS
select --'FAC_MANUAL' TIPO_FAC, a.fctdoc DOC, a.fcazfa*100+a.fcmefa PERIODO,
--b.fccser COD_SER, c.tcnser DESC_SERV, a.tccpro||a.tcclip||a.tcctse||a.tctico PROD,
--sum( b.fcpreb) VALOR_CONCEPTO, sum( b.fcvid1 ) IVA_CONCEPTO
d.cta_ctble cuenta, e.DESCRIPCION desc_cuenta, d.cca, d.ccb, f.descripcion desc_ccb,
0 SIN_IVA, 0 IMPUESTO , sum( b.fcpreb) EXENTO,0 TASA_CERO
from v4stcdat.f4prfhed a, v4stcdat.f4prfdet b, v4stcdat.v4servi c, conceptos_facturacion d,
cuentas_contables e, centros_costob f
--fctdoc = FEM
where a.fctfac = b.fctfac and
a.fcnfac = b.fcnfac and
b.fccser = c.tccser (+)and
a.tccpro||a.tcclip||a.tcctse||a.tctico not in ('PVAS','PVWS') and
a.fcazfa = 2007 and a.fcmefa = 3
and d.cod_servicio = b.fccser
and d.producto = a.tccpro||a.tcclip||a.tcctse||a.tctico
and a.fctdoc in ('FEM') --excluyendo exportacion, porque son exentos
and d.cta_ctble = e.nombre
and d.ccb = f.codigo
group by --a.fcazfa*100+a.fcmefa, b.fccser , c.tcnser,
--a.tccpro||a.tcclip||a.tcctse||a.tctico, a.fctdoc
d.cta_ctble, d.cca, d.ccb, e.DESCRIPCION, f.descripcion
order by 1 asc;