CREATE VIEW `outbound_report_lead`  AS SELECT `leads`.`id` AS `id_cliente_potencial`, `leads_cstm`.`tipo_documento_c` AS `tipo_documento`, `leads_cstm`.`numero_documento_c` AS `numero_de_documento`, `leads`.`first_name` AS `nombre_cliente_potencial`, `leads`.`last_name` AS `apellido_cliente_potencial`, `leads_cstm`.`telefono_movil_c` AS `telefono_movil`, `leads_cstm`.`telefono_fijo_c` AS `telefono_fijo`, `leads`.`title` AS `puesto`, `leads`.`primary_address_street` AS `direccion`, `leads`.`primary_address_city` AS `ciudad`, `leads`.`primary_address_state` AS `departamento`, `leads`.`primary_address_postalcode` AS `codigo_postal`, `leads`.`primary_address_country` AS `pais`, `leads`.`status` AS `estado_cliente_potencial`, `leads`.`lead_source` AS `origen_cliente_potencial`, `leads`.`campaign_id` AS `id_campaña`, `leads`.`description` AS `observaciones`, `log_outbound`.`id_outbound` AS `id_outbound`, `ip_outbound_plantillas_callbell`.`name` AS `nombre_outbound`, `ip_outbound_plantillas_callbell`.`fecha_inicio` AS `fecha_inicio`, `ip_outbound_plantillas_callbell`.`fecha_fin` AS `fecha_fin`, `ip_outbound_plantillas_callbell`.`estado` AS `estado`, `ip_outbound_plantillas_callbell`.`url_adjunto` AS `url_adjunto`, `ip_outbound_plantillas_callbell_cstm`.`ip_plantillas_callbell_id_c` AS `id_plantilla`, `ip_plantillas_callbell`.`name` AS `nombre_plantilla`, `ip_plantillas_callbell`.`type_template` AS `tipo_plantilla`, `ip_plantillas_callbell`.`uuid_template` AS `uuid_plantilla`, `log_outbound`.`id` AS `id_log`, `log_outbound`.`fecha` AS `fecha_log`, `log_outbound`.`proceso` AS `proceso_log`, `log_outbound`.`observaciones` AS `observaciones_log`, `log_outbound`.`type_client` AS `tipo_log`, `log_outbound`.`uuid_message` AS `uuid_mensaje`, `log_outbound`.`status_message` AS `estado_mensaje` FROM ((((`log_outbound` left join (`leads` left join `leads_cstm` on(`leads`.`id` = `leads_cstm`.`id_c`)) on(`log_outbound`.`id_client` = `leads`.`id`)) left join `ip_outbound_plantillas_callbell` on(`log_outbound`.`id_outbound` = `ip_outbound_plantillas_callbell`.`id`)) left join `ip_outbound_plantillas_callbell_cstm` on(`ip_outbound_plantillas_callbell`.`id` = `ip_outbound_plantillas_callbell_cstm`.`id_c`)) left join `ip_plantillas_callbell` on(`ip_outbound_plantillas_callbell_cstm`.`ip_plantillas_callbell_id_c` = `ip_plantillas_callbell`.`id`)) WHERE `log_outbound`.`type_client` = 'Lead' AND `ip_plantillas_callbell`.`deleted` = 0 ;
