select
`vtiger_crmentity`.`createdtime` AS `created_time`,
`vtiger_comentarios`.`comentariosid` AS `Comentario_ID`,
`vtiger_comentarios`.`consecutivo` AS `consecutivo`,
`vtiger_familianovedad`.`familianovedad` AS `familia_novedad`,
`vtiger_subfamilianovedad`.`subfamilianovedad` AS `subfamilia_novedad`,
`vtiger_caso`.`caso` AS `caso`,
`vtiger_novedad`.`novedad` AS `novedad`,
`vtiger_comentarios`.`subtipificacion` AS `subtipificacion`,
`vtiger_comentarios`.`asuntocomentario` AS `asunto_comentario`,
`vtiger_crmentity`.`description` AS `descripcion`,
(
select
`vtiger_users`.`user_name`
from
`vtiger_users`
where
(
`vtiger_crmentity`.`smcreatorid` = `vtiger_users`.`id`
)
)
AS `Creador_Novedad`,
(
select
`vtiger_users`.`user_name`
from
`vtiger_users`
where
(
`vtiger_errores`.`responsable` = `vtiger_users`.`id`
)
)
AS `Responsable_Error`,
(
select
`vtiger_crmentity`.`setype`
from
`vtiger_crmentity`
where
(
`vtiger_crmentity`.`crmid` = `vtiger_comentarios`.`relacionadocon`
)
)
AS `ModuloRelacionado`,
(
case
when
(
`vtiger_comentarios`.`modulorelacionado` = 'PacientesII'
)
then
(
select
`vtiger_pacientesii`.`identificador_paciente`
from
`vtiger_pacientesii`
where
(
`vtiger_pacientesii`.`pacientesiiid` = `vtiger_comentarios`.`relacionadocon`
)
)
when
(
`vtiger_comentarios`.`modulorelacionado` = 'Visitas'
)
then
(
select
`vtiger_visitas`.`visita`
from
`vtiger_visitas`
where
(
`vtiger_visitas`.`visitasid` = `vtiger_comentarios`.`relacionadocon`
)
)
when
(
`vtiger_comentarios`.`modulorelacionado` = 'OrdenesServicio'
)
then
(
select
`vtiger_ordenesservicio`.`asunto_orden`
from
`vtiger_ordenesservicio`
where
(
`vtiger_ordenesservicio`.`ordenesservicioid` = `vtiger_comentarios`.`relacionadocon`
)
)
when
(
`vtiger_comentarios`.`modulorelacionado` = 'PlanillasTrabajo'
)
then
(
select
`vtiger_planillastrabajo`.`identificador`
from
`vtiger_planillastrabajo`
where
(
`vtiger_planillastrabajo`.`planillastrabajoid` = `vtiger_comentarios`.`relacionadocon`
)
)
when
(
`vtiger_comentarios`.`modulorelacionado` = 'PlanillasTrabajo'
)
then
(
select
`vtiger_planillastrabajo`.`identificador`
from
`vtiger_planillastrabajo`
where
(
`vtiger_planillastrabajo`.`planillastrabajoid` = `vtiger_comentarios`.`relacionadocon`
)
)
when
(
`vtiger_comentarios`.`modulorelacionado` = 'Comentarios'
)
then
(
select
`vtiger_comentarios`.`asuntocomentario`
from
`vtiger_comentarios` `B`
where
(
`B`.`comentariosid` = `vtiger_comentarios`.`relacionadocon`
)
)
when
(
`vtiger_comentarios`.`modulorelacionado` = 'Contratos'
)
then
(
select
`vtiger_contratosdecomodato`.`asunto`
from
`vtiger_contratosdecomodato`
where
(
`vtiger_contratosdecomodato`.`contratosdecomodatoid` = `vtiger_comentarios`.`relacionadocon`
)
)
else
`vtiger_comentarios`.`modulorelacionado`
end
)
AS `Relacionado_con`,
`vtiger_comentarios`.`relacionadocon` AS `Relacionado_ID`,
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`
from
(
left join
on((`vtiger_comentarios`.`comentariosid` = `vtiger_crmentity`.`crmid`)))
left join
on((`vtiger_comentarios`.`familianovedad` = `vtiger_familianovedad`.`picklist_valueid`)))
left join
on((`vtiger_comentarios`.`subfamilianovedad` = `vtiger_subfamilianovedad`.`picklist_valueid`)))
left join
on((`vtiger_comentarios`.`novedad` = `vtiger_confignovedades`.`confignovedadesid`)))
left join
on((`vtiger_confignovedades`.`caso` = `vtiger_caso`.`picklist_valueid`)))
left join
on((`vtiger_confignovedades`.`novedad` = `vtiger_novedad`.`picklist_valueid`)))
left join
on((`vtiger_comentarios`.`comentariosid` = `vtiger_errores`.`novedadrel`))
)
where
(
((`vtiger_comentarios`.`familianovedad` = 66847)
or
(
`vtiger_comentarios`.`familianovedad` = 67556
)
)
and
(
`vtiger_novedad`.`picklist_valueid` <> 68335
)
)
|