select
`vtiger_listastrabajo`.`listastrabajoid` AS `listastrabajoid`,
`vtiger_listastrabajo`.`asunto` AS `asunto`,
`vtiger_listastrabajo`.`consecutivo` AS `consecutivo`,
`vtiger_listastrabajo`.`tipoitemlista` AS `tipoitemlista`,
`vtiger_listastrabajo`.`paciente` AS `paciente`,
`vtiger_listastrabajo`.`relacionadocon` AS `relacionadocon`,
`vtiger_listastrabajo`.`formaitemlista` AS `formaitemlista`,
`vtiger_listastrabajo`.`fechadeteccion` AS `fechadeteccion`,
`vtiger_listastrabajo`.`fechaproceso` AS `fechaproceso`,
`vtiger_listastrabajo`.`fechafin` AS `fechafin`,
`vtiger_listastrabajo`.`prioritario` AS `prioritario`,
`vtiger_listastrabajo`.`semaforo` AS `semaforo`,
`vtiger_listastrabajo`.`osprogramada` AS `osprogramada`,
`vtiger_listastrabajo`.`diastotales` AS `diastotales`,
`vtiger_listastrabajo`.`subtipolista` AS `subtipolista`,
`vtiger_listastrabajo`.`prioridadlista` AS `prioridadlista`,
`vtiger_listastrabajo`.`responsableasignado` AS `responsableasignado`,
`vtiger_listastrabajo`.`visto` AS `visto`,
`vtiger_listastrabajo`.`estadoitemlista` AS `estadoitemlista`,
`vtiger_listastrabajo`.`fechaactivacion` AS `fechaactivacion`,
`vtiger_listastrabajo`.`historial` AS `historial`,
`vtiger_listastrabajo`.`tipoencuesta` AS `tipoencuesta`,
`vtiger_listastrabajo`.`fechanovedad` AS `fechanovedad`,
`vtiger_listastrabajo`.`textonovedad` AS `textonovedad`,
`vtiger_listastrabajo`.`conteogestion` AS `conteogestion`,
`vtiger_listastrabajo`.`pais` AS `pais`,
`vtiger_listastrabajo`.`departamento` AS `departamento`,
`vtiger_listastrabajo`.`ciudad` AS `ciudad`,
`vtiger_listastrabajo`.`barrio` AS `barrio`,
`vtiger_listastrabajo`.`zona_barrio` AS `zona_barrio`,
`vtiger_listastrabajo`.`direccion` AS `direccion`,
`vtiger_listastrabajo`.`phone` AS `phone`,
`vtiger_listastrabajocf`.`cf_3465` AS `InconsistenciaCierre`,
`vtiger_listastrabajocf`.`cf_3467` AS `ObsCierre`,
`vtiger_crmentity`.`description` AS `description`,
`vtiger_barrios`.`localidad` AS `localidad`,
`vtiger_pacientesii`.`identificador_paciente` AS `identificador_paciente`,
`vtiger_pacientesii`.`entidadpadrename` AS `entidadpadrename`,
`vtiger_account`.`epsconsolidada` AS `epsconsolidada`,
`vtiger_pacientesii`.`empresa` AS `idempresa`,
`vtiger_empresa`.`empresa` AS `nombreempresa`,
`vtiger_pacientesiicf`.`cf_1619` AS `EstadoPaciente`,
`vtiger_pacientesiicf`.`cf_1679` AS `perdidorecuperacion`,
date_format(`vtiger_crmentity`.`createdtime`, '%Y%m') AS `agno_mes`,
date_format(`vtiger_crmentity`.`createdtime`, '%Y%m%d') AS `agno_mes_dia`,
yearweek(`vtiger_crmentity`.`createdtime`, 0) AS `agno_semana`,
`vtiger_users`.`user_name` AS `usuario_creacion`,
concat(`vtiger_users`.`first_name`, ' ', `vtiger_users`.`last_name`) AS `nombre_usuario_creacion`,
#01 (
select
`vtiger_crmentity`.`setype`
from
`vtiger_crmentity`
where
(
`vtiger_crmentity`.`crmid` = `vtiger_listastrabajo`.`relacionadocon`
)
)
AS `ModuloRelacionado`,
#02 if((isnull(`vtiger_listastrabajogrouprel`.`groupname`)
or
(
`vtiger_listastrabajogrouprel`.`groupname` = ''
)
),
(
case
when
(
(
select
`vtiger_crmentity`.`setype`
from
`vtiger_crmentity`
where
(
`vtiger_crmentity`.`crmid` = `vtiger_listastrabajo`.`relacionadocon`
)
) = 'OrdenesServicio'
)
then
(
select
`vtiger_ordenesserviciogrouprel`.`groupname`
from
`vtiger_ordenesserviciogrouprel`
where
(
`vtiger_ordenesserviciogrouprel`.`ordenesservicioid` = `vtiger_listastrabajo`.`relacionadocon`
)
)
when
(
(
select
`vtiger_crmentity`.`setype`
from
`vtiger_crmentity`
where
(
`vtiger_crmentity`.`crmid` = `vtiger_listastrabajo`.`relacionadocon`
)
) = 'Cilindros'
)
then
(
select
`vtiger_cilindrosgrouprel`.`groupname`
from
`vtiger_cilindrosgrouprel`
where
(
`vtiger_cilindrosgrouprel`.`cilindrosid` = `vtiger_listastrabajo`.`relacionadocon`
)
)
when
(
(
select
`vtiger_crmentity`.`setype`
from
`vtiger_crmentity`
where
(
`vtiger_crmentity`.`crmid` = `vtiger_listastrabajo`.`relacionadocon`
)
) = 'PacientesII'
)
then
(
select
`vtiger_pacientesiigrouprel`.`groupname`
from
`vtiger_pacientesiigrouprel`
where
(
`vtiger_pacientesiigrouprel`.`pacientesiiid` = `vtiger_listastrabajo`.`relacionadocon`
)
)
when
(
(
select
`vtiger_crmentity`.`setype`
from
`vtiger_crmentity`
where
(
`vtiger_crmentity`.`crmid` = `vtiger_listastrabajo`.`relacionadocon`
)
) = 'ItemsDagnos'
)
then
(
select
`vtiger_itemsdagnosgrouprel`.`groupname`
from
`vtiger_itemsdagnosgrouprel`
where
(
`vtiger_itemsdagnosgrouprel`.`itemsdagnosid` = `vtiger_listastrabajo`.`relacionadocon`
)
)
when
(
(
select
`vtiger_crmentity`.`setype`
from
`vtiger_crmentity`
where
(
`vtiger_crmentity`.`crmid` = `vtiger_listastrabajo`.`relacionadocon`
)
) = 'Visitas'
)
then
(
select
`vtiger_visitasgrouprel`.`groupname`
from
`vtiger_visitasgrouprel`
where
(
`vtiger_visitasgrouprel`.`visitasid` = `vtiger_listastrabajo`.`relacionadocon`
)
)
when
(
(
select
`vtiger_crmentity`.`setype`
from
`vtiger_crmentity`
where
(
`vtiger_crmentity`.`crmid` = `vtiger_listastrabajo`.`relacionadocon`
)
) = 'PlanillasTrabajo'
)
then
(
select
`vtiger_planillastrabajogrouprel`.`groupname`
from
`vtiger_planillastrabajogrouprel`
where
(
`vtiger_planillastrabajogrouprel`.`planillastrabajoid` = `vtiger_listastrabajo`.`relacionadocon`
)
)
when
(
(
select
`vtiger_crmentity`.`setype`
from
`vtiger_crmentity`
where
(
`vtiger_crmentity`.`crmid` = `vtiger_listastrabajo`.`relacionadocon`
)
) = 'Recogidas'
)
then
(
select
`vtiger_recogidasgrouprel`.`groupname`
from
`vtiger_recogidasgrouprel`
where
(
`vtiger_recogidasgrouprel`.`recogidasid` = `vtiger_listastrabajo`.`relacionadocon`
)
)
when
(
(
select
`vtiger_crmentity`.`setype`
from
`vtiger_crmentity`
where
(
`vtiger_crmentity`.`crmid` = `vtiger_listastrabajo`.`relacionadocon`
)
) = 'ActivosRetornables'
)
then
(
select
`vtiger_activosretornablesgrouprel`.`groupname`
from
`vtiger_activosretornablesgrouprel`
where
(
`vtiger_activosretornablesgrouprel`.`activosretornablesid` = `vtiger_listastrabajo`.`relacionadocon`
)
)
when
(
(
select
`vtiger_crmentity`.`setype`
from
`vtiger_crmentity`
where
(
`vtiger_crmentity`.`crmid` = `vtiger_listastrabajo`.`relacionadocon`
)
) = 'RecibosCaja'
)
then
(
select
`vtiger_reciboscajagrouprel`.`groupname`
from
`vtiger_reciboscajagrouprel`
where
(
`vtiger_reciboscajagrouprel`.`reciboscajaid` = `vtiger_listastrabajo`.`relacionadocon`
)
)
when
(
(
select
`vtiger_crmentity`.`setype`
from
`vtiger_crmentity`
where
(
`vtiger_crmentity`.`crmid` = `vtiger_listastrabajo`.`relacionadocon`
)
) = 'MantenimientoGases'
)
then
(
select
`vtiger_mantenimientogasesgrouprel`.`groupname`
from
`vtiger_mantenimientogasesgrouprel`
where
(
`vtiger_mantenimientogasesgrouprel`.`mantenimientogasesid` = `vtiger_listastrabajo`.`relacionadocon`
)
)
when
(
(
select
`vtiger_crmentity`.`setype`
from
`vtiger_crmentity`
where
(
`vtiger_crmentity`.`crmid` = `vtiger_listastrabajo`.`relacionadocon`
)
) = 'Empleados'
)
then
(
select
`vtiger_empleadosgrouprel`.`groupname`
from
`vtiger_empleadosgrouprel`
where
(
`vtiger_empleadosgrouprel`.`empleadosid` = `vtiger_listastrabajo`.`relacionadocon`
)
)
else
'Sin Regional'
end
)
, `vtiger_listastrabajogrouprel`.`groupname`) AS `REGIONAL`
from
(
join
on((`vtiger_listastrabajo`.`listastrabajoid` = `vtiger_listastrabajocf`.`listastrabajoid`)))
join
on((`vtiger_listastrabajo`.`listastrabajoid` = `vtiger_crmentity`.`crmid`)))
left join
on((`vtiger_listastrabajo`.`paciente` = `vtiger_pacientesii`.`pacientesiiid`)))
left join
on((`vtiger_pacientesiicf`.`pacientesiiid` = `vtiger_pacientesii`.`pacientesiiid`)))
left join
on((`vtiger_empresa`.`empresaid` = `vtiger_pacientesii`.`empresa`)))
left join
on((`vtiger_listastrabajogrouprel`.`listastrabajoid` = `vtiger_listastrabajo`.`listastrabajoid`)))
left join
`vtiger_barrios`
on((`vtiger_barrios`.`barriosid` = `vtiger_listastrabajo`.`barrio`)))
left join
on((`vtiger_account`.`accountid` = `vtiger_pacientesii`.`accountid`)))
left join
`vtiger_users`
on((`vtiger_users`.`id` = `vtiger_crmentity`.`smcreatorid`)))
left join
on((`vtiger_listastrabajo`.`tipoitemlista` = `vtiger_tipoitemlista`.`tipoitemlista`))
)
where
(
(`vtiger_listastrabajo`.`estadoitemlista` <> 'Terminado')
and
(
`vtiger_listastrabajo`.`estadoitemlista` <> 'Anulado'
)
and
(
not((`vtiger_listastrabajo`.`tipoitemlista` like 'Referencias%'))
)
and
(
not((`vtiger_listastrabajo`.`tipoitemlista` like '%Hidros%'))
)
and
(
not((`vtiger_listastrabajo`.`tipoitemlista` like 'Encuestas Pendientes'))
)
)
|