CREATE TABLE `vtiger_tiposiniestro` (
  `tiposiniestroid` int(11) NOT NULL AUTO_INCREMENT,
  `tiposiniestro` varchar(255) DEFAULT NULL,
  `presence` tinyint(1) DEFAULT '1',
  `sortorderid` smallint(6) DEFAULT '0',
  PRIMARY KEY (`tiposiniestroid`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tlfcontacto` (
  `tlfcontactoid` int(11) NOT NULL AUTO_INCREMENT,
  `tlfcontacto` varchar(255) DEFAULT NULL,
  `presence` tinyint(1) DEFAULT '1',
  `sortorderid` smallint(6) DEFAULT '0',
  PRIMARY KEY (`tlfcontactoid`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tmp_read_group_rel_sharing_per` (
  `userid` int(10) NOT NULL,
  `tabid` smallint(5) NOT NULL,
  `relatedtabid` int(10) NOT NULL,
  `sharedgroupid` int(10) NOT NULL,
  PRIMARY KEY (`userid`,`tabid`,`relatedtabid`,`sharedgroupid`),
  KEY `tmp_read_group_rel_sharing_per_userid_sharedgroupid_tabid` (`userid`,`sharedgroupid`,`tabid`),
  CONSTRAINT `fk_4_vtiger_tmp_read_group_rel_sharing_per` FOREIGN KEY (`userid`) REFERENCES `vtiger_users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tmp_read_group_sharing_per` (
  `userid` int(10) NOT NULL,
  `tabid` smallint(5) NOT NULL,
  `sharedgroupid` int(10) NOT NULL,
  PRIMARY KEY (`userid`,`tabid`,`sharedgroupid`),
  KEY `tmp_read_group_sharing_per_userid_sharedgroupid_idx` (`userid`,`sharedgroupid`),
  CONSTRAINT `fk_3_vtiger_tmp_read_group_sharing_per` FOREIGN KEY (`userid`) REFERENCES `vtiger_users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tmp_read_user_rel_sharing_per` (
  `userid` int(10) NOT NULL,
  `tabid` smallint(5) NOT NULL,
  `relatedtabid` int(10) NOT NULL,
  `shareduserid` int(10) NOT NULL,
  PRIMARY KEY (`userid`,`tabid`,`relatedtabid`,`shareduserid`),
  KEY `tmp_read_user_rel_sharing_per_userid_shared_reltabid_idx` (`userid`,`shareduserid`,`relatedtabid`),
  CONSTRAINT `fk_4_vtiger_tmp_read_user_rel_sharing_per` FOREIGN KEY (`userid`) REFERENCES `vtiger_users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tmp_read_user_sharing_per` (
  `userid` int(10) NOT NULL,
  `tabid` smallint(5) NOT NULL,
  `shareduserid` int(10) NOT NULL,
  PRIMARY KEY (`userid`,`tabid`,`shareduserid`),
  KEY `tmp_read_user_sharing_per_userid_shareduserid_idx` (`userid`,`shareduserid`),
  CONSTRAINT `fk_3_vtiger_tmp_read_user_sharing_per` FOREIGN KEY (`userid`) REFERENCES `vtiger_users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tmp_write_group_rel_sharing_per` (
  `userid` int(10) NOT NULL,
  `tabid` smallint(5) NOT NULL,
  `relatedtabid` int(10) NOT NULL,
  `sharedgroupid` int(10) NOT NULL,
  PRIMARY KEY (`userid`,`tabid`,`relatedtabid`,`sharedgroupid`),
  KEY `tmp_write_group_rel_sharing_per_userid_sharedgroupid_tabid_idx` (`userid`,`sharedgroupid`,`tabid`),
  CONSTRAINT `fk_4_vtiger_tmp_write_group_rel_sharing_per` FOREIGN KEY (`userid`) REFERENCES `vtiger_users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tmp_write_group_sharing_per` (
  `userid` int(10) NOT NULL,
  `tabid` smallint(5) NOT NULL,
  `sharedgroupid` int(10) NOT NULL,
  PRIMARY KEY (`userid`,`tabid`,`sharedgroupid`),
  KEY `tmp_write_group_sharing_per_UK1` (`userid`,`sharedgroupid`),
  CONSTRAINT `fk_3_vtiger_tmp_write_group_sharing_per` FOREIGN KEY (`userid`) REFERENCES `vtiger_users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tmp_write_user_rel_sharing_per` (
  `userid` int(10) NOT NULL,
  `tabid` smallint(5) NOT NULL,
  `relatedtabid` int(10) NOT NULL,
  `shareduserid` int(10) NOT NULL,
  PRIMARY KEY (`userid`,`tabid`,`relatedtabid`,`shareduserid`),
  KEY `tmp_write_user_rel_sharing_per_userid_sharduserid_tabid_idx` (`userid`,`shareduserid`,`tabid`),
  CONSTRAINT `fk_4_vtiger_tmp_write_user_rel_sharing_per` FOREIGN KEY (`userid`) REFERENCES `vtiger_users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tmp_write_user_sharing_per` (
  `userid` int(10) NOT NULL,
  `tabid` smallint(5) NOT NULL,
  `shareduserid` int(10) NOT NULL,
  PRIMARY KEY (`userid`,`tabid`,`shareduserid`),
  KEY `tmp_write_user_sharing_per_userid_shareduserid_idx` (`userid`,`shareduserid`),
  CONSTRAINT `fk_3_vtiger_tmp_write_user_sharing_per` FOREIGN KEY (`userid`) REFERENCES `vtiger_users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tpago1cuota` (
  `tpago1cuotaid` int(11) NOT NULL AUTO_INCREMENT,
  `tpago1cuota` varchar(255) DEFAULT NULL,
  `presence` tinyint(1) DEFAULT '1',
  `sortorderid` smallint(6) DEFAULT '0',
  PRIMARY KEY (`tpago1cuotaid`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tpago2cuota` (
  `tpago2cuotaid` int(11) NOT NULL AUTO_INCREMENT,
  `tpago2cuota` varchar(255) DEFAULT NULL,
  `presence` tinyint(1) DEFAULT '1',
  `sortorderid` smallint(6) DEFAULT '0',
  PRIMARY KEY (`tpago2cuotaid`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tpago3cuota` (
  `tpago3cuotaid` int(11) NOT NULL AUTO_INCREMENT,
  `tpago3cuota` varchar(255) DEFAULT NULL,
  `presence` tinyint(1) DEFAULT '1',
  `sortorderid` smallint(6) DEFAULT '0',
  PRIMARY KEY (`tpago3cuotaid`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tpago4cuota` (
  `tpago4cuotaid` int(11) NOT NULL AUTO_INCREMENT,
  `tpago4cuota` varchar(255) DEFAULT NULL,
  `presence` tinyint(1) DEFAULT '1',
  `sortorderid` smallint(6) DEFAULT '0',
  PRIMARY KEY (`tpago4cuotaid`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tpago5cuota` (
  `tpago5cuotaid` int(11) NOT NULL AUTO_INCREMENT,
  `tpago5cuota` varchar(255) DEFAULT NULL,
  `presence` tinyint(1) DEFAULT '1',
  `sortorderid` smallint(6) DEFAULT '0',
  PRIMARY KEY (`tpago5cuotaid`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tpago6cuota` (
  `tpago6cuotaid` int(11) NOT NULL AUTO_INCREMENT,
  `tpago6cuota` varchar(255) DEFAULT NULL,
  `presence` tinyint(1) DEFAULT '1',
  `sortorderid` smallint(6) DEFAULT '0',
  PRIMARY KEY (`tpago6cuotaid`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tpagoabono` (
  `tpagoabonoid` int(11) NOT NULL AUTO_INCREMENT,
  `tpagoabono` varchar(255) DEFAULT NULL,
  `presence` tinyint(1) DEFAULT '1',
  `sortorderid` smallint(6) DEFAULT '0',
  PRIMARY KEY (`tpagoabonoid`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tracking_unit` (
  `tracking_unitid` int(10) NOT NULL AUTO_INCREMENT,
  `tracking_unit` varchar(200) NOT NULL,
  `presence` int(1) NOT NULL DEFAULT '1',
  `picklist_valueid` int(10) NOT NULL DEFAULT '0',
  `sortorderid` int(10) DEFAULT '0',
  PRIMARY KEY (`tracking_unitid`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tracking_unit_seq` (
  `id` int(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_trees_templates` (
  `templateid` int(10) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `module` int(10) DEFAULT NULL,
  `access` int(1) DEFAULT '1',
  `share` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`templateid`),
  KEY `module` (`module`)
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_trees_templates_data` (
  `templateid` smallint(5) unsigned NOT NULL,
  `name` varchar(255) NOT NULL,
  `tree` varchar(255) NOT NULL,
  `parenttrre` varchar(255) NOT NULL,
  `depth` tinyint(3) unsigned NOT NULL,
  `label` varchar(255) NOT NULL,
  `state` varchar(100) NOT NULL DEFAULT '',
  `icon` varchar(255) NOT NULL DEFAULT '',
  KEY `id` (`templateid`),
  KEY `parenttrre` (`parenttrre`,`templateid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tribunal` (
  `tribunalid` int(11) NOT NULL AUTO_INCREMENT,
  `tribunal` varchar(255) DEFAULT NULL,
  `presence` tinyint(1) DEFAULT '1',
  `sortorderid` smallint(6) DEFAULT '0',
  PRIMARY KEY (`tribunalid`)
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tribunalcompetente` (
  `tribunalcompetenteid` int(11) NOT NULL AUTO_INCREMENT,
  `tribunalcompetente` varchar(255) DEFAULT NULL,
  `presence` tinyint(1) DEFAULT '1',
  `sortorderid` smallint(6) DEFAULT '0',
  PRIMARY KEY (`tribunalcompetenteid`)
) ENGINE=InnoDB AUTO_INCREMENT=139 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tribunalcompetentedc` (
  `tribunalcompetentedcid` int(11) NOT NULL AUTO_INCREMENT,
  `tribunalcompetentedc` varchar(255) DEFAULT NULL,
  `presence` tinyint(1) DEFAULT '1',
  `sortorderid` smallint(6) DEFAULT '0',
  PRIMARY KEY (`tribunalcompetentedcid`)
) ENGINE=InnoDB AUTO_INCREMENT=139 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tribunalradicado` (
  `tribunalradicadoid` int(11) NOT NULL AUTO_INCREMENT,
  `tribunalradicado` varchar(255) DEFAULT NULL,
  `presence` tinyint(1) DEFAULT '1',
  `sortorderid` smallint(6) DEFAULT '0',
  PRIMARY KEY (`tribunalradicadoid`)
) ENGINE=InnoDB AUTO_INCREMENT=221 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_tribunalradicadodc` (
  `tribunalradicadodcid` int(11) NOT NULL AUTO_INCREMENT,
  `tribunalradicadodc` varchar(255) DEFAULT NULL,
  `presence` tinyint(1) DEFAULT '1',
  `sortorderid` smallint(6) DEFAULT '0',
  PRIMARY KEY (`tribunalradicadodcid`)
) ENGINE=InnoDB AUTO_INCREMENT=221 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_troubletickets` (
  `ticketid` int(10) NOT NULL,
  `ticket_no` varchar(100) NOT NULL,
  `groupname` varchar(100) DEFAULT NULL,
  `parent_id` int(10) DEFAULT NULL,
  `product_id` int(10) DEFAULT NULL,
  `priority` varchar(200) DEFAULT NULL,
  `severity` varchar(200) DEFAULT NULL,
  `status` varchar(200) DEFAULT NULL,
  `category` varchar(200) DEFAULT NULL,
  `title` varchar(255) NOT NULL,
  `solution` text,
  `update_log` text,
  `version_id` int(10) DEFAULT NULL,
  `sum_time` decimal(10,2) DEFAULT '0.00',
  `servicecontractsid` int(10) DEFAULT NULL,
  `attention` text,
  `pssold_id` int(10) DEFAULT NULL,
  `ordertime` decimal(10,2) DEFAULT NULL,
  `from_portal` smallint(1) DEFAULT NULL,
  `contract_type` varchar(255) DEFAULT NULL,
  `contracts_end_date` date DEFAULT NULL,
  `report_time` int(10) DEFAULT NULL,
  `response_time` datetime DEFAULT NULL,
  PRIMARY KEY (`ticketid`),
  KEY `troubletickets_ticketid_idx` (`ticketid`),
  KEY `troubletickets_status_idx` (`status`),
  KEY `parent_id` (`parent_id`),
  KEY `product_id` (`product_id`),
  KEY `servicecontractsid` (`servicecontractsid`),
  KEY `pssold_id` (`pssold_id`),
  KEY `ticket_no` (`ticket_no`),
  CONSTRAINT `fk_1_vtiger_troubletickets` FOREIGN KEY (`ticketid`) REFERENCES `vtiger_crmentity` (`crmid`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_usageunit` (
  `usageunitid` int(10) NOT NULL AUTO_INCREMENT,
  `usageunit` varchar(200) NOT NULL,
  `presence` int(1) NOT NULL DEFAULT '1',
  `picklist_valueid` int(10) NOT NULL DEFAULT '0',
  `sortorderid` int(10) DEFAULT NULL,
  PRIMARY KEY (`usageunitid`),
  UNIQUE KEY `usageunit_usageunit_idx` (`usageunit`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_usageunit_seq` (
  `id` int(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_user2mergefields` (
  `userid` int(10) DEFAULT NULL,
  `tabid` smallint(5) DEFAULT NULL,
  `fieldid` int(10) DEFAULT NULL,
  `visible` int(2) DEFAULT NULL,
  KEY `userid_tabid_idx` (`userid`,`tabid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_user2role` (
  `userid` int(10) NOT NULL,
  `roleid` varchar(255) NOT NULL,
  PRIMARY KEY (`userid`),
  KEY `user2role_roleid_idx` (`roleid`),
  CONSTRAINT `fk_2_vtiger_user2role` FOREIGN KEY (`userid`) REFERENCES `vtiger_users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_user_module_preferences` (
  `userid` varchar(30) NOT NULL,
  `tabid` smallint(5) NOT NULL,
  `default_cvid` int(10) NOT NULL,
  PRIMARY KEY (`userid`,`tabid`),
  KEY `fk_2_vtiger_user_module_preferences` (`tabid`),
  CONSTRAINT `fk_2_vtiger_user_module_preferences` FOREIGN KEY (`tabid`) REFERENCES `vtiger_tab` (`tabid`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_users` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `user_name` varchar(32) DEFAULT NULL,
  `first_name` varchar(30) DEFAULT NULL,
  `last_name` varchar(30) DEFAULT NULL,
  `email1` varchar(100) DEFAULT NULL,
  `is_admin` varchar(3) DEFAULT '0',
  `status` varchar(25) DEFAULT NULL,
  `deleted` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `language` varchar(36) DEFAULT NULL,
  `user_password` varchar(200) DEFAULT NULL,
  `internal_mailer` tinyint(1) unsigned NOT NULL DEFAULT '1',
  `reports_to_id` mediumint(10) unsigned DEFAULT NULL,
  `modified_user_id` varchar(36) DEFAULT NULL,
  `currency_id` mediumint(10) NOT NULL DEFAULT '1',
  `description` text,
  `date_entered` timestamp NULL DEFAULT NULL,
  `date_modified` timestamp NULL DEFAULT NULL,
  `date_password_change` datetime DEFAULT NULL,
  `force_password_change` tinyint(1) DEFAULT '0',
  `holidays` varchar(60) DEFAULT NULL,
  `namedays` varchar(60) DEFAULT NULL,
  `workdays` varchar(30) DEFAULT NULL,
  `weekstart` int(10) DEFAULT NULL,
  `date_format` varchar(200) DEFAULT NULL,
  `hour_format` varchar(30) DEFAULT 'am/pm',
  `start_hour` varchar(30) DEFAULT '10:00',
  `end_hour` varchar(30) DEFAULT '23:00',
  `view_date_format` varchar(50) DEFAULT 'PLL_ELAPSED',
  `activity_view` varchar(200) DEFAULT 'Today',
  `lead_view` varchar(200) DEFAULT 'Today',
  `imagename` varchar(250) DEFAULT NULL,
  `reminder_interval` varchar(100) DEFAULT NULL,
  `reminder_next_time` varchar(100) DEFAULT NULL,
  `theme` varchar(100) DEFAULT NULL,
  `tz` varchar(30) DEFAULT NULL,
  `time_zone` varchar(200) DEFAULT NULL,
  `currency_grouping_pattern` varchar(100) DEFAULT NULL,
  `currency_decimal_separator` varchar(2) DEFAULT NULL,
  `currency_grouping_separator` varchar(2) DEFAULT NULL,
  `currency_symbol_placement` varchar(20) DEFAULT NULL,
  `no_of_currency_decimals` tinyint(1) unsigned DEFAULT NULL,
  `truncate_trailing_zeros` tinyint(1) unsigned DEFAULT NULL,
  `dayoftheweek` varchar(100) DEFAULT NULL,
  `callduration` smallint(3) unsigned DEFAULT NULL,
  `othereventduration` smallint(3) unsigned DEFAULT NULL,
  `default_record_view` varchar(10) DEFAULT NULL,
  `leftpanelhide` tinyint(3) unsigned DEFAULT NULL,
  `rowheight` varchar(10) DEFAULT NULL,
  `defaulteventstatus` varchar(50) DEFAULT NULL,
  `defaultactivitytype` varchar(50) DEFAULT NULL,
  `is_owner` varchar(5) DEFAULT NULL,
  `emailoptout` tinyint(3) unsigned NOT NULL DEFAULT '1',
  `available` tinyint(1) DEFAULT '0',
  `auto_assign` tinyint(1) DEFAULT '0',
  `records_limit` int(10) DEFAULT NULL,
  `phone_crm_extension` varchar(100) DEFAULT NULL,
  `phone_crm_extension_extra` varchar(100) DEFAULT NULL,
  `accesskey` varchar(36) DEFAULT NULL,
  `confirm_password` varchar(200) DEFAULT NULL,
  `cal_color` varchar(25) DEFAULT NULL,
  `user_preferences` text,
  `phone` varchar(45) DEFAULT '',
  `sisfirma` tinyint(1) DEFAULT '0',
  PRIMARY KEY (`id`),
  UNIQUE KEY `email1` (`email1`),
  KEY `user_user_name_idx` (`user_name`),
  KEY `user_user_password_idx` (`user_password`),
  KEY `status` (`status`)
) ENGINE=InnoDB AUTO_INCREMENT=403 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_users2group` (
  `groupid` int(10) NOT NULL,
  `userid` int(10) NOT NULL,
  PRIMARY KEY (`groupid`,`userid`),
  KEY `users2group_groupname_uerid_idx` (`groupid`,`userid`),
  KEY `fk_2_vtiger_users2group` (`userid`),
  CONSTRAINT `fk_2_vtiger_users2group` FOREIGN KEY (`userid`) REFERENCES `vtiger_users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_users_last_import` (
  `id` int(36) NOT NULL AUTO_INCREMENT,
  `assigned_user_id` varchar(36) DEFAULT NULL,
  `bean_type` varchar(36) DEFAULT NULL,
  `bean_id` int(10) DEFAULT NULL,
  `deleted` int(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `idx_user_id` (`assigned_user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_users_seq` (
  `id` int(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_userscf` (
  `usersid` int(10) NOT NULL,
  PRIMARY KEY (`usersid`),
  CONSTRAINT `vtiger_userscf_ibfk_1` FOREIGN KEY (`usersid`) REFERENCES `vtiger_users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_valorpie` (
  `valorpieid` int(11) NOT NULL AUTO_INCREMENT,
  `valorpie` varchar(255) DEFAULT NULL,
  `presence` tinyint(1) DEFAULT '1',
  `sortorderid` smallint(6) DEFAULT '0',
  PRIMARY KEY (`valorpieid`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_valorplan` (
  `valorplanid` int(11) NOT NULL AUTO_INCREMENT,
  `valorplan` varchar(255) DEFAULT NULL,
  `presence` tinyint(1) DEFAULT '1',
  `sortorderid` smallint(6) DEFAULT '0',
  PRIMARY KEY (`valorplanid`)
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_vendor` (
  `vendorid` int(10) NOT NULL DEFAULT '0',
  `vendor_no` varchar(100) NOT NULL,
  `vendorname` varchar(100) DEFAULT NULL,
  `phone` varchar(100) DEFAULT NULL,
  `email` varchar(100) DEFAULT NULL,
  `website` varchar(100) DEFAULT NULL,
  `glacct` varchar(200) DEFAULT NULL,
  `category` varchar(50) DEFAULT NULL,
  `description` text,
  `vat_id` varchar(30) DEFAULT NULL,
  `registration_number_1` varchar(30) DEFAULT NULL,
  `registration_number_2` varchar(30) DEFAULT NULL,
  `verification` text,
  `sum_time` decimal(10,2) DEFAULT '0.00',
  `active` tinyint(1) DEFAULT '0',
  `phone_extra` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`vendorid`),
  KEY `vendorname` (`vendorname`),
  CONSTRAINT `fk_1_vtiger_vendor` FOREIGN KEY (`vendorid`) REFERENCES `vtiger_crmentity` (`crmid`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_vendoraddress` (
  `vendorid` int(10) NOT NULL,
  `addresslevel1a` varchar(255) DEFAULT NULL,
  `addresslevel1b` varchar(255) DEFAULT NULL,
  `addresslevel1c` varchar(255) DEFAULT NULL,
  `addresslevel2a` varchar(255) DEFAULT NULL,
  `addresslevel2b` varchar(255) DEFAULT NULL,
  `addresslevel2c` varchar(255) DEFAULT NULL,
  `addresslevel3a` varchar(255) DEFAULT NULL,
  `addresslevel3b` varchar(255) DEFAULT NULL,
  `addresslevel3c` varchar(255) DEFAULT NULL,
  `addresslevel4a` varchar(255) DEFAULT NULL,
  `addresslevel4b` varchar(255) DEFAULT NULL,
  `addresslevel4c` varchar(255) DEFAULT NULL,
  `addresslevel5a` varchar(255) DEFAULT NULL,
  `addresslevel5b` varchar(255) DEFAULT NULL,
  `addresslevel5c` varchar(255) DEFAULT NULL,
  `addresslevel6a` varchar(255) DEFAULT NULL,
  `addresslevel6b` varchar(255) DEFAULT NULL,
  `addresslevel6c` varchar(255) DEFAULT NULL,
  `addresslevel7a` varchar(255) DEFAULT NULL,
  `addresslevel7b` varchar(255) DEFAULT NULL,
  `addresslevel7c` varchar(255) DEFAULT NULL,
  `addresslevel8a` varchar(255) DEFAULT NULL,
  `addresslevel8b` varchar(255) DEFAULT NULL,
  `addresslevel8c` varchar(255) DEFAULT NULL,
  `poboxa` varchar(50) DEFAULT NULL,
  `poboxb` varchar(50) DEFAULT NULL,
  `poboxc` varchar(50) DEFAULT NULL,
  `buildingnumbera` varchar(100) DEFAULT NULL,
  `buildingnumberb` varchar(100) DEFAULT NULL,
  `buildingnumberc` varchar(100) DEFAULT NULL,
  `localnumbera` varchar(100) DEFAULT NULL,
  `localnumberb` varchar(100) DEFAULT NULL,
  `localnumberc` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`vendorid`),
  CONSTRAINT `vtiger_vendoraddress_ibfk_1` FOREIGN KEY (`vendorid`) REFERENCES `vtiger_vendor` (`vendorid`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_vendorcf` (
  `vendorid` int(10) NOT NULL DEFAULT '0',
  PRIMARY KEY (`vendorid`),
  CONSTRAINT `fk_1_vtiger_vendorcf` FOREIGN KEY (`vendorid`) REFERENCES `vtiger_vendor` (`vendorid`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_vendorcontactrel` (
  `vendorid` int(10) NOT NULL DEFAULT '0',
  `contactid` int(10) NOT NULL DEFAULT '0',
  PRIMARY KEY (`vendorid`,`contactid`),
  KEY `vendorcontactrel_vendorid_idx` (`vendorid`),
  KEY `vendorcontactrel_contact_idx` (`contactid`),
  CONSTRAINT `fk_2_vtiger_vendorcontactrel` FOREIGN KEY (`vendorid`) REFERENCES `vtiger_vendor` (`vendorid`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_ventadedemandas` (
  `ventadedemandasid` int(11) NOT NULL,
  `id` varchar(255) DEFAULT NULL,
  `number` varchar(32) DEFAULT NULL,
  `tiposiniestro` varchar(30) DEFAULT '',
  `direccionsiniestro` varchar(100) DEFAULT '',
  `comunasiniestro` varchar(100) DEFAULT '',
  `banco` varchar(100) DEFAULT '',
  `compseguros` varchar(100) DEFAULT '',
  `liquidador` varchar(100) DEFAULT '',
  `fechacreacioncaso` date DEFAULT NULL,
  `fechadenuncia` date DEFAULT NULL,
  `fechavisita` date DEFAULT NULL,
  `fechapresupuesto` date DEFAULT NULL,
  `fechainforme` date DEFAULT NULL,
  `fechaimpug` date DEFAULT NULL,
  `fecharesp` date DEFAULT NULL,
  `fechapreinspeccion` date DEFAULT NULL,
  `porcentajeapagar` decimal(5,2) DEFAULT NULL,
  `contratofirmado` varchar(1) DEFAULT '0',
  `estadocobranza` varchar(100) DEFAULT '',
  `estadocomercialdda` varchar(255) DEFAULT '',
  `estadollamada` varchar(255) DEFAULT '',
  `captador` varchar(100) DEFAULT '',
  `obsllamada` text,
  `fechavolver` date DEFAULT NULL,
  `horavolver` time DEFAULT NULL,
  `rutcliente` varchar(100) DEFAULT '',
  `fono` varchar(100) DEFAULT '',
  `correo` varchar(100) DEFAULT '',
  `ddavendida` tinyint(1) DEFAULT '0',
  `ddarechazada` tinyint(1) DEFAULT '0',
  `correotentativo` tinyint(1) DEFAULT '0',
  `correonromalo` tinyint(1) DEFAULT '0',
  `idsiniestro` int(11) unsigned DEFAULT '0',
  `perdidareclamadauf` decimal(23,2) DEFAULT NULL,
  `perddetuf` decimal(23,2) DEFAULT NULL,
  `deducibleuf` decimal(23,2) DEFAULT NULL,
  `perdinduf` decimal(23,2) DEFAULT NULL,
  `indemnizacionclpclp` bigint(20) DEFAULT '0',
  `montorecuperarclp` bigint(20) DEFAULT '0',
  `actualizar` tinyint(1) DEFAULT '0',
  `estadocasosiniestro` varchar(100) DEFAULT '',
  `clienteid` int(11) unsigned DEFAULT '0',
  `fcontratofirmado` date DEFAULT NULL,
  `estado_pf` varchar(10) DEFAULT '',
  `descargadoc` varchar(255) DEFAULT '',
  `motivorechazovtadda` varchar(255) DEFAULT '',
  `cuotaunoddapagada` tinyint(1) DEFAULT '0',
  `crearsusdda` tinyint(1) DEFAULT '0',
  `susddafacturada` tinyint(1) DEFAULT '0',
  `paymentsinid` int(11) unsigned DEFAULT '0',
  `suscripcionid` int(11) unsigned DEFAULT '0',
  `pordemandar` tinyint(1) DEFAULT '0',
  `generardda` tinyint(1) DEFAULT '0',
  `fechaasignacion` date DEFAULT NULL,
  `comisionpagada` tinyint(1) DEFAULT '0',
  `categoriacomision` varchar(255) DEFAULT '',
  `agregadolistadda` tinyint(1) DEFAULT '0',
  `planaslegal` varchar(255) DEFAULT '',
  `pac_toku_monflow` tinyint(1) DEFAULT '0',
  PRIMARY KEY (`ventadedemandasid`),
  KEY `vtiger_ventadedemandas_idsiniestro_idx` (`idsiniestro`),
  KEY `vtiger_ventadedemandas_clienteid_idx` (`clienteid`),
  KEY `vtiger_ventadedemandas_paymentsinid_idx` (`paymentsinid`),
  KEY `vtiger_ventadedemandas_suscripcionid_idx` (`suscripcionid`),
  CONSTRAINT `fk_1_vtiger_ventadedemandasventadedemandasid` FOREIGN KEY (`ventadedemandasid`) REFERENCES `vtiger_crmentity` (`crmid`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_ventadedemandascf` (
  `ventadedemandasid` int(11) NOT NULL,
  PRIMARY KEY (`ventadedemandasid`),
  CONSTRAINT `fk_1_vtiger_ventadedemandascfventadedemandasid` FOREIGN KEY (`ventadedemandasid`) REFERENCES `vtiger_ventadedemandas` (`ventadedemandasid`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_ventademandas` (
  `ventademandasid` int(11) NOT NULL,
  `id` varchar(255) DEFAULT NULL,
  `number` varchar(32) DEFAULT NULL,
  `relacionsiniestro` int(11) unsigned DEFAULT '0',
  `montopresupuesto` bigint(15) DEFAULT '0',
  `tiposiniestro` varchar(30) DEFAULT '',
  `perdidadeterminadap` bigint(20) DEFAULT '0',
  `direccionsiniestro` varchar(40) DEFAULT '',
  `deducibleafectop` bigint(15) DEFAULT '0',
  `comunacaso` varchar(30) DEFAULT '',
  `perdidaindemnizablep` varchar(15) DEFAULT '',
  `ciudadcaso` varchar(40) DEFAULT '',
  `pagoporcentaje` decimal(5,2) DEFAULT NULL,
  `categorizacion` varchar(30) DEFAULT '',
  `montoporreclamarp` bigint(15) DEFAULT '0',
  `ciaseguros` varchar(40) DEFAULT '',
  `llamada` varchar(255) DEFAULT '',
  `volverllamar` tinyint(1) DEFAULT '0',
  `edogestion` varchar(255) DEFAULT '',
  `fvolverllamar` date DEFAULT NULL,
  `hvolverllamar` time DEFAULT NULL,
  `obsllamada` text,
  `casorevisado` tinyint(1) DEFAULT '0',
  `presupuestomanual` tinyint(1) DEFAULT '0',
  `descmand` tinyint(1) DEFAULT '0',
  `nombre` varchar(40) DEFAULT '',
  `apellido` varchar(40) DEFAULT '',
  `cliente` varchar(25) DEFAULT '',
  `serienrodocto` varchar(20) DEFAULT '',
  `movil` varchar(20) DEFAULT '',
  `email` varchar(40) DEFAULT '',
  `tlfparticular` varchar(30) DEFAULT '',
  `mailotro` varchar(30) DEFAULT '',
  `tlfotro` varchar(30) DEFAULT '',
  `observaciones` text,
  `edocivil` varchar(30) DEFAULT '',
  `profesion` varchar(40) DEFAULT '',
  `modificardatos` tinyint(1) DEFAULT '0',
  `comentariomodificacion` text,
  `banco` varchar(30) DEFAULT '',
  `entliquidadora` varchar(30) DEFAULT '',
  `fdenuncio` date DEFAULT NULL,
  `estado` varchar(30) DEFAULT '',
  `fvisita` date DEFAULT NULL,
  `fpresupuesto` date DEFAULT NULL,
  `frecinfliq` date DEFAULT NULL,
  `deducibleafecto` decimal(8,2) DEFAULT NULL,
  `perdidareclamada` decimal(8,2) DEFAULT NULL,
  `perdidadeterminada` decimal(8,2) DEFAULT NULL,
  `fimpugnacion` date DEFAULT NULL,
  `perdidaindemnizable` decimal(8,2) DEFAULT NULL,
  `frespimpugnacion` date DEFAULT NULL,
  `notificacionaceptacion` tinyint(1) DEFAULT '0',
  `notificacionrechazo` tinyint(1) DEFAULT '0',
  `notificacionemail` tinyint(1) DEFAULT '0',
  `mailinformativo` tinyint(1) DEFAULT '0',
  `mail_firmas` tinyint(1) DEFAULT '0',
  `dctosdec` tinyint(1) DEFAULT '0',
  `fdocdec` date DEFAULT NULL,
  `dctosfirmados` tinyint(1) DEFAULT '0',
  `fcontratofirmado` date DEFAULT NULL,
  `mandatofirmado` tinyint(1) DEFAULT '0',
  `fmandatofirmado` date DEFAULT NULL,
  `comentariocontrato` text,
  `costodemanda` bigint(20) DEFAULT '0',
  `fnegociacion` date DEFAULT NULL,
  `abono` bigint(20) DEFAULT '0',
  `fprimerpago` date DEFAULT NULL,
  `fabono0` date DEFAULT NULL,
  `nrofactura` varchar(20) DEFAULT '',
  `diapago` varchar(255) DEFAULT '',
  `ffactura` date DEFAULT NULL,
  `nrocuotasgd` varchar(255) DEFAULT '',
  `facturapagada` tinyint(1) DEFAULT '0',
  `valorcuota` bigint(20) DEFAULT '0',
  `ffacturapagada` date DEFAULT NULL,
  `deudarestante` bigint(20) DEFAULT '0',
  `fabono` date DEFAULT NULL,
  `nfacabono` varchar(30) DEFAULT '',
  `abonopagado` tinyint(1) DEFAULT '0',
  `tpagoabono` varchar(255) DEFAULT '',
  `fpagoabono` date DEFAULT NULL,
  `bdepago` varchar(255) DEFAULT '',
  `codwebpayabono` varchar(40) DEFAULT '',
  `tarjpagoabono` varchar(255) DEFAULT '',
  `valor1cuota` bigint(20) DEFAULT '0',
  `fcompromisocuota1` date DEFAULT NULL,
  `1cuotapagada` tinyint(1) DEFAULT '0',
  `f1cuota` date DEFAULT NULL,
  `tpago1cuota` varchar(255) DEFAULT '',
  `bdpago1cuota` varchar(255) DEFAULT '',
  `codwebpaycuota1` varchar(30) DEFAULT '',
  `tarjpagocuota1` varchar(255) DEFAULT '',
  `valor2cuota` bigint(20) DEFAULT '0',
  `fcompromisocuota2` date DEFAULT NULL,
  `2cuotapagada` tinyint(1) DEFAULT '0',
  `f2cuota` date DEFAULT NULL,
  `tpago2cuota` varchar(255) DEFAULT '',
  `bdpago2cuota` varchar(255) DEFAULT '',
  `codwebpaycuota2` varchar(30) DEFAULT '',
  `tarjpagocuota2` varchar(255) DEFAULT '',
  `valor3cuota` bigint(20) DEFAULT '0',
  `fcompromisocuota3` date DEFAULT NULL,
  `3cuotapagada` tinyint(1) DEFAULT '0',
  `f3cuota` date DEFAULT NULL,
  `tpago3cuota` varchar(255) DEFAULT '',
  `bdpago3cuota` varchar(255) DEFAULT '',
  `codwebpaycuota3` varchar(30) DEFAULT '',
  `tarjpagocuota3` varchar(255) DEFAULT '',
  `valoruff` decimal(10,2) DEFAULT NULL,
  `idclientevd1` int(11) DEFAULT NULL,
  `matchclayabono` tinyint(1) DEFAULT '0',
  `matchclaycuota1` tinyint(1) DEFAULT '0',
  `matchclaycuota2` tinyint(1) DEFAULT '0',
  `matchclaycuota3` tinyint(1) DEFAULT '0',
  `idcliente` int(11) unsigned DEFAULT '0',
  PRIMARY KEY (`ventademandasid`),
  KEY `vtiger_ventademandas_relacionsiniestro_idx` (`relacionsiniestro`),
  KEY `vtiger_ventademandas_idcliente_idx` (`idcliente`),
  CONSTRAINT `fk_1_vtiger_ventademandasventademandasid` FOREIGN KEY (`ventademandasid`) REFERENCES `vtiger_crmentity` (`crmid`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_ventademandascf` (
  `ventademandasid` int(11) NOT NULL,
  PRIMARY KEY (`ventademandasid`),
  CONSTRAINT `fk_1_vtiger_ventademandascfventademandasid` FOREIGN KEY (`ventademandasid`) REFERENCES `vtiger_ventademandas` (`ventademandasid`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_verification` (
  `verificationid` int(10) NOT NULL AUTO_INCREMENT,
  `verification` varchar(200) NOT NULL,
  `presence` int(1) NOT NULL DEFAULT '1',
  `picklist_valueid` int(10) NOT NULL DEFAULT '0',
  `sortorderid` int(10) DEFAULT '0',
  PRIMARY KEY (`verificationid`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_verification_seq` (
  `id` int(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_version` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `old_version` varchar(30) DEFAULT NULL,
  `current_version` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_version_seq` (
  `id` int(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_view_date_format` (
  `view_date_formatid` int(11) NOT NULL AUTO_INCREMENT,
  `view_date_format` varchar(50) DEFAULT NULL,
  `presence` tinyint(1) DEFAULT '1',
  `sortorderid` smallint(6) DEFAULT '0',
  PRIMARY KEY (`view_date_formatid`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_visibility` (
  `visibilityid` int(10) NOT NULL AUTO_INCREMENT,
  `visibility` varchar(200) NOT NULL,
  `sortorderid` int(10) NOT NULL DEFAULT '0',
  `presence` int(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`visibilityid`),
  UNIQUE KEY `visibility_visibility_idx` (`visibility`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_visibility_seq` (
  `id` int(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_viveencasa` (
  `viveencasaid` int(11) NOT NULL AUTO_INCREMENT,
  `viveencasa` varchar(255) DEFAULT NULL,
  `presence` tinyint(1) DEFAULT '1',
  `sortorderid` smallint(6) DEFAULT '0',
  PRIMARY KEY (`viveencasaid`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_widgets` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `tabid` smallint(5) DEFAULT NULL,
  `type` varchar(30) DEFAULT NULL,
  `label` varchar(100) DEFAULT NULL,
  `wcol` tinyint(1) DEFAULT '1',
  `sequence` tinyint(2) DEFAULT NULL,
  `nomargin` tinyint(1) DEFAULT '0',
  `data` text,
  PRIMARY KEY (`id`),
  KEY `tabid` (`tabid`),
  CONSTRAINT `vtiger_widgets_ibfk_1` FOREIGN KEY (`tabid`) REFERENCES `vtiger_tab` (`tabid`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=227 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_ws_entity` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `name` varchar(25) NOT NULL,
  `handler_path` varchar(255) NOT NULL,
  `handler_class` varchar(64) NOT NULL,
  `ismodule` int(3) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=99 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_ws_entity_seq` (
  `id` int(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_ws_fieldinfo` (
  `id` varchar(64) NOT NULL,
  `property_name` varchar(32) DEFAULT NULL,
  `property_value` varchar(64) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_ws_fieldtype` (
  `fieldtypeid` int(10) NOT NULL AUTO_INCREMENT,
  `uitype` smallint(3) NOT NULL,
  `fieldtype` varchar(200) NOT NULL,
  PRIMARY KEY (`fieldtypeid`),
  UNIQUE KEY `uitype_idx` (`uitype`)
) ENGINE=InnoDB AUTO_INCREMENT=57 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_ws_operation` (
  `operationid` int(10) NOT NULL AUTO_INCREMENT,
  `name` varchar(128) NOT NULL,
  `handler_path` varchar(255) NOT NULL,
  `handler_method` varchar(64) NOT NULL,
  `type` varchar(8) NOT NULL,
  `prelogin` int(3) NOT NULL,
  PRIMARY KEY (`operationid`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_ws_operation_parameters` (
  `operationid` int(10) NOT NULL,
  `name` varchar(128) NOT NULL,
  `type` varchar(64) NOT NULL,
  `sequence` int(10) NOT NULL,
  PRIMARY KEY (`operationid`,`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_ws_operation_seq` (
  `id` int(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_ws_referencetype` (
  `fieldtypeid` int(10) NOT NULL,
  `type` varchar(25) NOT NULL,
  PRIMARY KEY (`fieldtypeid`,`type`),
  KEY `fieldtypeid` (`fieldtypeid`),
  CONSTRAINT `fk_1_vtiger_referencetype` FOREIGN KEY (`fieldtypeid`) REFERENCES `vtiger_ws_fieldtype` (`fieldtypeid`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_ws_userauthtoken` (
  `userid` int(10) NOT NULL,
  `token` varchar(36) NOT NULL,
  `expiretime` int(10) NOT NULL,
  PRIMARY KEY (`userid`,`expiretime`),
  UNIQUE KEY `userid_idx` (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `w_yf_portal_session` (
  `id` varchar(32) NOT NULL,
  `user_id` int(10) DEFAULT NULL,
  `language` varchar(10) DEFAULT NULL,
  `created` datetime DEFAULT NULL,
  `changed` datetime DEFAULT NULL,
  `params` text,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `w_yf_portal_user` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `server_id` int(10) DEFAULT NULL,
  `status` tinyint(1) DEFAULT '0',
  `user_name` varchar(50) NOT NULL,
  `password_h` varchar(200) DEFAULT NULL,
  `password_t` varchar(200) DEFAULT NULL,
  `type` tinyint(1) unsigned DEFAULT '1',
  `login_time` datetime DEFAULT NULL,
  `logout_time` datetime DEFAULT NULL,
  `language` varchar(10) DEFAULT NULL,
  `crmid` int(10) DEFAULT NULL,
  `user_id` int(10) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `user_name` (`user_name`),
  KEY `user_name_2` (`user_name`,`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `w_yf_servers` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `pass` varchar(100) DEFAULT NULL,
  `acceptable_url` varchar(255) DEFAULT NULL,
  `status` tinyint(1) NOT NULL DEFAULT '0',
  `api_key` varchar(100) NOT NULL,
  `type` varchar(40) NOT NULL,
  `accounts_id` int(10) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `name` (`name`,`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `yetiforce_auth` (
  `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
  `type` varchar(20) DEFAULT NULL,
  `param` varchar(20) DEFAULT NULL,
  `value` text,
  PRIMARY KEY (`id`),
  UNIQUE KEY `type` (`type`,`param`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
CREATE TABLE `yetiforce_currencyupdate` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `currency_id` int(10) NOT NULL,
  `fetch_date` date NOT NULL,
  `exchange_date` date NOT NULL,
  `exchange` decimal(10,4) NOT NULL,
  `bank_id` int(10) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `fetchdate_currencyid_unique` (`currency_id`,`exchange_date`,`bank_id`),
  KEY `fk_1_vtiger_osscurrencies` (`currency_id`),
  CONSTRAINT `fk_1_vtiger_osscurrencies` FOREIGN KEY (`currency_id`) REFERENCES `vtiger_currency_info` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `yetiforce_currencyupdate_banks` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `bank_name` varchar(255) NOT NULL,
  `active` int(1) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_bankname` (`bank_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `yetiforce_mail_config` (
  `type` varchar(50) DEFAULT NULL,
  `name` varchar(50) DEFAULT NULL,
  `value` text,
  UNIQUE KEY `type` (`type`,`name`),
  KEY `type_2` (`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `yetiforce_mail_quantities` (
  `userid` int(10) unsigned NOT NULL,
  `num` int(10) unsigned DEFAULT '0',
  `status` tinyint(1) DEFAULT '0',
  PRIMARY KEY (`userid`),
  CONSTRAINT `yetiforce_mail_quantities_ibfk_1` FOREIGN KEY (`userid`) REFERENCES `roundcube_users` (`user_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `yetiforce_menu` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `role` int(10) DEFAULT NULL,
  `parentid` int(10) DEFAULT '0',
  `type` tinyint(1) DEFAULT NULL,
  `sequence` int(3) DEFAULT NULL,
  `module` smallint(5) DEFAULT NULL,
  `label` varchar(100) DEFAULT NULL,
  `newwindow` tinyint(1) DEFAULT '0',
  `dataurl` text,
  `showicon` tinyint(1) DEFAULT '0',
  `icon` varchar(255) DEFAULT NULL,
  `sizeicon` varchar(255) DEFAULT NULL,
  `hotkey` varchar(30) DEFAULT NULL,
  `filters` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `parent_id` (`parentid`),
  KEY `role` (`role`),
  KEY `module` (`module`),
  CONSTRAINT `yetiforce_menu_ibfk_1` FOREIGN KEY (`module`) REFERENCES `vtiger_tab` (`tabid`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1653 DEFAULT CHARSET=utf8;
CREATE TABLE `yetiforce_proc_marketing` (
  `type` varchar(30) DEFAULT NULL,
  `param` varchar(30) DEFAULT NULL,
  `value` varchar(200) DEFAULT NULL,
  KEY `type` (`type`,`param`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `yetiforce_proc_sales` (
  `type` varchar(30) DEFAULT NULL,
  `param` varchar(30) DEFAULT NULL,
  `value` varchar(200) DEFAULT NULL,
  KEY `type` (`type`,`param`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `yetiforce_proc_tc` (
  `type` varchar(30) DEFAULT NULL,
  `param` varchar(30) DEFAULT NULL,
  `value` varchar(200) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `yetiforce_updates` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `time` timestamp NULL DEFAULT NULL,
  `user` varchar(50) DEFAULT NULL,
  `name` varchar(100) DEFAULT NULL,
  `from_version` varchar(10) DEFAULT NULL,
  `to_version` varchar(10) DEFAULT NULL,
  `result` tinyint(1) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
/*!50001 DROP VIEW IF EXISTS `AbonoC1C2`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `AbonoC1C2` AS select `vtiger_suscripcion`.`suscripcionid` AS `id`,`vtiger_suscripcion`.`number` AS `number`,`vtiger_siniestro`.`siniestro` AS `Siniestro`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Cliente`,concat(`vtiger_users`.`first_name`,' ',`vtiger_users`.`last_name`) AS `Asignado`,`vtiger_suscripcion`.`estado` AS `estado`,`vtiger_suscripcion`.`nrofactura` AS `nrofactura`,`vtiger_crmentity`.`smownerid` AS `assigned_user_id`,`vtiger_crmentity`.`createdtime` AS `createdtime`,`vtiger_suscripcion`.`abono` AS `abono`,`vtiger_suscripcion`.`primeracuota` AS `Cuota1`,`vtiger_suscripcion`.`segundacuota` AS `Cuota2`,`vtiger_suscripcion`.`fechavenabo` AS `fechavenabo`,`vtiger_suscripcion`.`fven1` AS `fven1`,`vtiger_suscripcion`.`fven2` AS `fven2`,`vtiger_suscripcion`.`nrocuotas` AS `nrocuotas` from ((((`vtiger_suscripcion` join `vtiger_crmentity` on((`vtiger_suscripcion`.`suscripcionid` = `vtiger_crmentity`.`crmid`))) join `vtiger_siniestro` on((`vtiger_siniestro`.`siniestroid` = `vtiger_suscripcion`.`siniestro`))) join `vtiger_cliente` on((`vtiger_cliente`.`clienteid` = `vtiger_suscripcion`.`nombrecliente`))) join `vtiger_users` on((`vtiger_crmentity`.`smownerid` = `vtiger_users`.`id`))) where ((`vtiger_crmentity`.`createdtime` between '2019-05-01 00:00:00' and '2021-12-31 23:59:59') and (`vtiger_suscripcion`.`abonopagado` = 0) and (`vtiger_suscripcion`.`1cuotapagada` = 0) and (`vtiger_suscripcion`.`2cuotapagada` = 0) and (`vtiger_suscripcion`.`fechavenabo` < curdate()) and (`vtiger_suscripcion`.`fven1` < curdate()) and (`vtiger_suscripcion`.`fven2` < curdate()) and (`vtiger_suscripcion`.`notacredito` = 0) and (`vtiger_suscripcion`.`valorcuota` <> 0) and (`vtiger_suscripcion`.`nrocuotas` not in (0,1)) and (`vtiger_suscripcion`.`nrofactura` <> 0) and (`vtiger_suscripcion`.`nrofactura` is not null) and (`vtiger_suscripcion`.`estado` not in ('No aplica','Desistido','Por Procesar','Por Facturar','Retención')) and (`vtiger_crmentity`.`deleted` = 0)) */;
/*!50001 DROP VIEW IF EXISTS `Asesoria_Legal`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `Asesoria_Legal` AS select `vtiger_siniestro`.`siniestroid` AS `id`,`vtiger_siniestro`.`siniestro` AS `Nro_Siniestro`,`vtiger_siniestro`.`facturapagada` AS `Factura_pagada`,`vtiger_siniestro`.`estado_` AS `Estado`,`vtiger_siniestro`.`fsismo_nuevo` AS `Fecha_Sismo_Nuevo`,`vtiger_siniestro`.`fdenuncio` AS `Fecha_Denuncio`,`vtiger_siniestro`.`tiposiniestro` AS `Tipo_Siniestro`,`vtiger_siniestro`.`perdidareclamada` AS `Perdida_Reclamada`,`vtiger_siniestro`.`perdidadeterminada` AS `Perdida_Determinada`,`vtiger_siniestro`.`deducibleafecto` AS `Deducible_Afecto`,`vtiger_siniestro`.`perdidaindemnizable` AS `Perdida_Indemnizable`,`vtiger_siniestro`.`indemnizacion` AS `Indemnizacion`,`vtiger_siniestro`.`perdrecuperablepesos` AS `Perdida_Recuperable_Pesos`,`vtiger_siniestro`.`direccionsiniestro` AS `Direccion_Siniestro`,`vtiger_siniestro`.`fvisita` AS `Fecha_Visita`,`vtiger_siniestro`.`fpresupuesto` AS `Fecha_Presupuesto`,`vtiger_siniestro`.`frecinfliq` AS `Fecha_Informe_Liquidacion`,`vtiger_siniestro`.`fimpugnacion` AS `Fecha_Impugnacion`,`vtiger_siniestro`.`frespimpugnacion` AS `Fecha_Respuesta_Impugnacion`,`vtiger_siniestro`.`fechapreinsp` AS `Fecha_Preinspeccion`,`vtiger_siniestro`.`banco` AS `Banco`,`vtiger_siniestro`.`entliquidadora` AS `Entidad_Liquidadora`,`vtiger_siniestro`.`contratofirmado2` AS `Contrato_Firmado`,((`vtiger_siniestro`.`perdidadeterminada` / `vtiger_siniestro`.`perdidareclamada`) * 100) AS `Porcentaje_Pago`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Nombre`,`vtiger_cliente`.`movil` AS `Telefono`,`vtiger_cliente`.`email` AS `Email`,`vtiger_siniestro`.`comunacaso` AS `Comuna_Siniestro`,`vtiger_siniestro`.`ciudadcaso` AS `Ciudad_Caso`,`vtiger_crmentity`.`createdtime` AS `Fecha_creacion_caso`,`vtiger_siniestro`.`ciaseguros` AS `Comania_seguros`,`vtiger_siniestro`.`captador` AS `Captador`,`vtiger_cliente`.`cliente` AS `Rut`,`vtiger_cliente`.`clienteid` AS `Id_Cliente`,`vtiger_paymentsin`.`paymentsin_status` AS `paymentsin_status`,`vtiger_siniestro`.`valoruf` AS `valoruf`,`vtiger_siniestro`.`creadaaslegal` AS `creadaaslegal` from (((`vtiger_siniestro` join `vtiger_crmentity` on((`vtiger_siniestro`.`siniestroid` = `vtiger_crmentity`.`crmid`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) join `vtiger_paymentsin` on((`vtiger_siniestro`.`siniestroid` = `vtiger_paymentsin`.`nrosiniestro`))) where ((`vtiger_siniestro`.`tiposiniestro` = 'Sismo') and (`vtiger_crmentity`.`createdtime` > '2019-01-30 23:59:59') and (`vtiger_siniestro`.`estado_` in ('Informe liq para impugnar PR','Informe de liq Impugnado PR','Revision Resp. Imp. PR')) and (`vtiger_siniestro`.`creadaaslegal` = 0) and ((`vtiger_siniestro`.`facturapagada` = '1') or (`vtiger_siniestro`.`facturapagada` = '0')) and (`vtiger_crmentity`.`deleted` = 0)) */;
/*!50001 DROP VIEW IF EXISTS `C1`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `C1` AS select `vtiger_suscripcion`.`suscripcionid` AS `id`,`vtiger_suscripcion`.`number` AS `number`,`vtiger_siniestro`.`siniestro` AS `Siniestro`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Cliente`,concat(`vtiger_users`.`first_name`,' ',`vtiger_users`.`last_name`) AS `Asignado`,`vtiger_suscripcion`.`nrofactura` AS `nrofactura`,`vtiger_crmentity`.`createdtime` AS `createdtime`,`vtiger_suscripcion`.`abono` AS `abono`,`vtiger_suscripcion`.`primeracuota` AS `Cuota1`,`vtiger_suscripcion`.`fechavenabo` AS `fechavenabo`,`vtiger_suscripcion`.`fven1` AS `fven1`,`vtiger_suscripcion`.`fven2` AS `fven2`,`vtiger_suscripcion`.`valorcuota` AS `valorcuota`,`vtiger_suscripcion`.`nrocuotas` AS `nrocuotas`,`vtiger_crmentity`.`smownerid` AS `assigned_user_id` from ((((`vtiger_suscripcion` join `vtiger_crmentity` on((`vtiger_suscripcion`.`suscripcionid` = `vtiger_crmentity`.`crmid`))) join `vtiger_siniestro` on((`vtiger_siniestro`.`siniestroid` = `vtiger_suscripcion`.`siniestro`))) join `vtiger_cliente` on((`vtiger_suscripcion`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) join `vtiger_users` on((`vtiger_crmentity`.`smownerid` = `vtiger_users`.`id`))) where ((`vtiger_crmentity`.`createdtime` between '2019-05-01 00:00:00' and '2021-12-31 23:59:59') and (`vtiger_suscripcion`.`1cuotapagada` = 0) and (`vtiger_suscripcion`.`fven1` < curdate()) and (`vtiger_suscripcion`.`notacredito` = 0) and (`vtiger_suscripcion`.`abonopagado` = 1) and (`vtiger_suscripcion`.`fven2` > curdate()) and (`vtiger_suscripcion`.`valorcuota` <> 0) and (`vtiger_suscripcion`.`valorcuota` is not null) and (`vtiger_suscripcion`.`estado` not in ('Desistido','Por Procesar','Por Facturar','Retencion')) and (`vtiger_crmentity`.`deleted` = 0)) */;
/*!50001 DROP VIEW IF EXISTS `C1C2`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `C1C2` AS select `vtiger_suscripcion`.`suscripcionid` AS `id`,`vtiger_suscripcion`.`number` AS `number`,`vtiger_siniestro`.`siniestro` AS `Siniestro`,`vtiger_suscripcion`.`nrofactura` AS `nrofactura`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Cliente`,concat(`vtiger_users`.`first_name`,' ',`vtiger_users`.`last_name`) AS `Asignado`,`vtiger_crmentity`.`smownerid` AS `assigned_user_id`,`vtiger_crmentity`.`createdtime` AS `createdtime`,`vtiger_suscripcion`.`abono` AS `abono`,`vtiger_suscripcion`.`primeracuota` AS `Cuota1`,`vtiger_suscripcion`.`segundacuota` AS `Cuota2`,`vtiger_suscripcion`.`fechavenabo` AS `fechavenabo`,`vtiger_suscripcion`.`fven1` AS `fven1`,`vtiger_suscripcion`.`fven2` AS `fven2`,`vtiger_suscripcion`.`abonopagado` AS `abonopagado` from ((((`vtiger_suscripcion` join `vtiger_crmentity` on((`vtiger_suscripcion`.`suscripcionid` = `vtiger_crmentity`.`crmid`))) join `vtiger_siniestro` on((`vtiger_siniestro`.`siniestroid` = `vtiger_suscripcion`.`siniestro`))) join `vtiger_cliente` on((`vtiger_suscripcion`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) join `vtiger_users` on((`vtiger_crmentity`.`smownerid` = `vtiger_users`.`id`))) where ((`vtiger_crmentity`.`deleted` = 0) and (`vtiger_crmentity`.`createdtime` between '2019-05-01 00:00:00' and '2021-12-31 23:59:59') and (`vtiger_suscripcion`.`1cuotapagada` = 0) and (`vtiger_suscripcion`.`2cuotapagada` = 0) and (`vtiger_suscripcion`.`fven1` < curdate()) and (`vtiger_suscripcion`.`fven2` < curdate()) and (`vtiger_suscripcion`.`notacredito` = 0) and (`vtiger_suscripcion`.`abonopagado` = 1) and (`vtiger_suscripcion`.`nrofactura` <> 0) and (`vtiger_suscripcion`.`nrofactura` is not null) and (`vtiger_suscripcion`.`valorcuota` <> 0) and (`vtiger_suscripcion`.`estado` not in ('No Aplica','Desistido','Por Procesar','Por Facturar','Retención'))) */;
/*!50001 DROP VIEW IF EXISTS `C2`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `C2` AS select `vtiger_suscripcion`.`suscripcionid` AS `id`,`vtiger_suscripcion`.`number` AS `number`,`vtiger_siniestro`.`siniestro` AS `Siniestro`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Cliente`,concat(`vtiger_users`.`first_name`,' ',`vtiger_users`.`last_name`) AS `Asignado`,`vtiger_suscripcion`.`nrofactura` AS `nrofactura`,`vtiger_crmentity`.`createdtime` AS `createdtime`,`vtiger_suscripcion`.`abono` AS `abono`,`vtiger_suscripcion`.`segundacuota` AS `Cuota2`,`vtiger_suscripcion`.`fechavenabo` AS `fechavenabo`,`vtiger_suscripcion`.`fven1` AS `fven1`,`vtiger_suscripcion`.`fven2` AS `fven2`,`vtiger_suscripcion`.`valorcuota` AS `valorcuota`,`vtiger_suscripcion`.`nrocuotas` AS `nrocuotas`,`vtiger_crmentity`.`smownerid` AS `assigned_user_id` from ((((`vtiger_suscripcion` join `vtiger_crmentity` on((`vtiger_suscripcion`.`suscripcionid` = `vtiger_crmentity`.`crmid`))) join `vtiger_siniestro` on((`vtiger_siniestro`.`siniestroid` = `vtiger_suscripcion`.`siniestro`))) join `vtiger_cliente` on((`vtiger_suscripcion`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) join `vtiger_users` on((`vtiger_crmentity`.`smownerid` = `vtiger_users`.`id`))) where ((`vtiger_crmentity`.`deleted` = 0) and (`vtiger_crmentity`.`createdtime` between '2019-05-01 00:00:00' and '2021-12-31 23:59:59') and (`vtiger_suscripcion`.`2cuotapagada` = 0) and (`vtiger_suscripcion`.`fven2` < curdate()) and (`vtiger_suscripcion`.`notacredito` = 0) and (`vtiger_suscripcion`.`abonopagado` = 1) and (`vtiger_suscripcion`.`1cuotapagada` = 1) and (`vtiger_suscripcion`.`valorcuota` <> 0) and (`vtiger_suscripcion`.`valorcuota` is not null) and (`vtiger_suscripcion`.`estado` not in ('No aplica','Desistido','Por Procesar','Por Facturar','Retención'))) */;
/*!50001 DROP VIEW IF EXISTS `Claycons_sus_da_VISTA`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_crm_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `Claycons_sus_da_VISTA` AS select `Claycons_sus_da`.`id` AS `id`,`Claycons_sus_da`.`Modulo` AS `Modulo`,`Claycons_sus_da`.`Nro_Caso` AS `Nro_Caso`,`Claycons_sus_da`.`Estado_Siniestro` AS `Estado_Siniestro`,`Claycons_sus_da`.`Estado_Comercial_Demanda` AS `Estado_Comercial_Demanda`,`Claycons_sus_da`.`Num_Factura_clay` AS `Num_Factura_clay`,`Claycons_sus_da`.`Num_Factura_crm` AS `Num_Factura_crm`,`Claycons_sus_da`.`Rev_Nro_Factura_clay_crm` AS `Rev_Nro_Factura_clay_crm`,`Claycons_sus_da`.`Fecha_Emision_Factura_clay` AS `Fecha_Emision_Factura_clay`,`Claycons_sus_da`.`Fecha_de_Factura_crm` AS `Fecha_de_Factura_crm`,`Claycons_sus_da`.`Rev_Fecha_Factura_clay_crm` AS `Rev_Fecha_Factura_clay_crm`,`Claycons_sus_da`.`Rut_Cliente_clay` AS `Rut_Cliente_clay`,`Claycons_sus_da`.`Rut_Cliente_crm` AS `Rut_Cliente_crm`,`Claycons_sus_da`.`Rev_Rut_Cliente_clay_crm` AS `Rev_Rut_Cliente_clay_crm`,`Claycons_sus_da`.`Nombre` AS `Nombre`,`Claycons_sus_da`.`Email` AS `Email`,`Claycons_sus_da`.`Telefono_1` AS `Telefono_1`,`Claycons_sus_da`.`Telefono_2` AS `Telefono_2`,`Claycons_sus_da`.`Monto_clay` AS `Monto_clay`,`Claycons_sus_da`.`Valor_del_Plan` AS `Valor_del_Plan`,`Claycons_sus_da`.`Saldo_CLAY` AS `Saldo_CLAY`,`Claycons_sus_da`.`Saldo_CRM` AS `Saldo_CRM`,`vtiger_suscripciondemanda`.`suscripciondemandaid` AS `ID_SUSCRIPCION_DEMANDA`,cast(`vtiger_crmentity`.`createdtime` as date) AS `CREACION_CASO_CRM`,`vtiger_suscripciondemanda`.`fechavencimientocuotauno` AS `FECHA_VENCIMIENTO_CUOTA_1`,`vtiger_suscripciondemanda`.`fechavencimientocuotados` AS `FECHA_VENCIMIENTO_CUOTA_2`,`vtiger_suscripciondemanda`.`fechavencimientocuotatres` AS `FECHA_VENCIMIENTO_CUOTA_3`,`vtiger_suscripciondemanda`.`nrocuotas` AS `nrocuotas`,`vtiger_suscripciondemanda`.`idventadedemanda` AS `Id_demanda` from (((`Claycons_sus_da` join `vtiger_siniestro` on((`Claycons_sus_da`.`Nro_Caso` = `vtiger_siniestro`.`siniestro`))) join `vtiger_crmentity` on((`vtiger_siniestro`.`siniestroid` = `vtiger_crmentity`.`crmid`))) join `vtiger_suscripciondemanda` on((`vtiger_siniestro`.`siniestroid` = `vtiger_suscripciondemanda`.`siniestroid`))) */;
/*!50001 DROP VIEW IF EXISTS `ContratofirmadosSinMandato`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `ContratofirmadosSinMandato` AS select `vtiger_siniestro`.`siniestroid` AS `id`,`vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_cliente`.`cliente` AS `Rut`,concat(`vtiger_cliente`.`nombre`,`vtiger_cliente`.`apellido`) AS `Cliente`,`vtiger_siniestro`.`nombrecliente` AS `nombrecliente`,`vtiger_crmentity`.`createdtime` AS `createdtime`,`vtiger_siniestro`.`captador` AS `captador`,`vtiger_siniestro`.`estado_` AS `estado` from ((`vtiger_siniestro` join `vtiger_crmentity` on((`vtiger_siniestro`.`siniestroid` = `vtiger_crmentity`.`crmid`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) where ((`vtiger_crmentity`.`createdtime` > '2021 23:59:59') and (`vtiger_siniestro`.`estado_` not in ('No aplica','Desistido','Cerrado sin pago','Cerrado','Sin Poliza','Cerrado (Sin Dctos)','Repetido','CERRADO SIN DAÑOS','Por Procesar','Gestión Abogado','Retención')) and (`vtiger_siniestro`.`contratofirmado2` = 1) and (`vtiger_siniestro`.`mandtomconfir` = 0) and (`vtiger_siniestro`.`captador` not in ('Marco Diaz','Valeria Gomez','Rodrigo Valenzuela')) and (`vtiger_crmentity`.`deleted` = 0)) order by `vtiger_siniestro`.`estado_` */;
/*!50001 DROP VIEW IF EXISTS `Control_firmas_contratos`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `Control_firmas_contratos` AS select `vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_cliente`.`nombre` AS `nombre`,`vtiger_cliente`.`apellido` AS `apellido`,`vtiger_cliente`.`cliente` AS `cliente`,`vtiger_cliente`.`serienrodocto` AS `serienrodocto`,`vtiger_siniestro`.`banco` AS `banco`,`vtiger_siniestro`.`estado_` AS `estado`,`vtiger_crmentity`.`createdtime` AS `createdtime` from ((`vtiger_siniestro` join `vtiger_cliente` on((`vtiger_cliente`.`clienteid` = `vtiger_siniestro`.`nombrecliente`))) join `vtiger_crmentity` on((`vtiger_siniestro`.`siniestroid` = `vtiger_crmentity`.`crmid`))) where ((`vtiger_siniestro`.`estado_` = 'Abierto (CP)') or (`vtiger_siniestro`.`estado_` = 'Preinspección Programada') or (`vtiger_siniestro`.`estado_` = 'Preinspección Realizada') or (`vtiger_siniestro`.`estado_` = 'Preinspección Revizada') or (`vtiger_siniestro`.`estado_` = 'En progreso') or (`vtiger_siniestro`.`estado_` = 'Liquidador Asignado') or (`vtiger_siniestro`.`estado_` = 'Visita Programada') or (`vtiger_siniestro`.`estado_` = 'Visita Realizada') or (`vtiger_siniestro`.`estado_` = 'Esperando')) */;
/*!50001 DROP VIEW IF EXISTS `CuotasSus2`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `CuotasSus2` AS select `crmclay_rep20_sus`.`Modulo` AS `Modulo`,`crmclay_rep20_sus`.`ncaso` AS `ncaso`,`crmclay_rep20_sus`.`Fecha_Emision` AS `Fecha_Emision`,`crmclay_rep20_sus`.`Mes_Año` AS `Mes_Año`,`crmclay_rep20_sus`.`Emitida_Recibida` AS `Emitida_Recibida`,`crmclay_rep20_sus`.`Num_Factura` AS `Num_Factura`,`crmclay_rep20_sus`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,`crmclay_rep20_sus`.`RUT_Receptor` AS `RUT_Receptor`,`crmclay_rep20_sus`.`Exento` AS `Exento`,`crmclay_rep20_sus`.`Saldo` AS `Saldo`,(`crmclay_rep20_sus`.`Exento` - `crmclay_rep20_sus`.`Saldo`) AS `Pagado`,`vtiger_suscripcion`.`nrocuotas` AS `NrocuotasOriginal`,`vtiger_suscripcion`.`nrocuotas` AS `nrocuotas`,(case when (`vtiger_suscripcion`.`nrocuotas` = 0) then 1 when (`vtiger_suscripcion`.`nrocuotas` = 1) then 2 when (`vtiger_suscripcion`.`nrocuotas` = 2) then 3 else (`vtiger_suscripcion`.`nrocuotas` + 1) end) AS `cuotasreales`,`vtiger_suscripcion`.`abono` AS `abono` from ((`crmclay_rep20_sus` join `vtiger_siniestro` on((`crmclay_rep20_sus`.`ncaso` = `vtiger_siniestro`.`siniestro`))) join `vtiger_suscripcion` on((`vtiger_siniestro`.`siniestroid` = `vtiger_suscripcion`.`siniestro`))) order by `crmclay_rep20_sus`.`Mes_Año` */;
/*!50001 DROP VIEW IF EXISTS `DatosClinetes_SimpliRute`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `DatosClinetes_SimpliRute` AS select `datosclientes`.`Movil` AS `Movil`,`datosclientes`.`cliente` AS `cliente`,`datosclientes`.`Nombre_de_contacto` AS `Nombre_de_contacto`,`datosclientes`.`Correo_electronico` AS `Correo_electronico`,`datosclientes`.`createdtime` AS `createdtime`,concat(`vtiger_users`.`first_name`,' ',`vtiger_users`.`last_name`) AS `Agente_exclusivo` from ((((`datosclientes` join `Plantilla_simplirute` on((`datosclientes`.`Correo_electronico` = `Plantilla_simplirute`.`SMS`))) join `vtiger_siniestro` on((`Plantilla_simplirute`.`ID_De_Referencia` = `vtiger_siniestro`.`siniestro`))) join `vtiger_crmentity` on((`vtiger_siniestro`.`siniestroid` = `vtiger_crmentity`.`crmid`))) join `vtiger_users` on((`vtiger_users`.`id` = `vtiger_crmentity`.`smownerid`))) */;
/*!50001 DROP VIEW IF EXISTS `FacturasEstadoesperando`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `FacturasEstadoesperando` AS select `vtiger_suscripcion`.`suscripcionid` AS `id`,`vtiger_cliente`.`cliente` AS `Rut`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Nombre_cliente`,`vtiger_siniestro`.`siniestro` AS `Siniestro`,`vtiger_suscripcion`.`estado` AS `Estado`,`vtiger_suscripcion`.`valortotal` AS `Valor_total`,`vtiger_crmentity`.`createdtime` AS `Creacion_sus`,`vtiger_suscripcion`.`nrofactura` AS `N_factura`,`vtiger_suscripcion`.`ffactura` AS `Fecha_factura`,`vtiger_suscripcion`.`captador` AS `Captador`,`vtiger_suscripcion`.`contratofirmado` AS `Contrato_Firmado`,`vtiger_siniestro`.`id_fact_relBase_sus` AS `id_relbase`,`vtiger_siniestro`.`estado_factura_sii` AS `estado_factura_sii` from (((`vtiger_suscripcion` join `vtiger_crmentity` on((`vtiger_suscripcion`.`suscripcionid` = `vtiger_crmentity`.`crmid`))) join `vtiger_siniestro` on((`vtiger_suscripcion`.`siniestro` = `vtiger_siniestro`.`siniestroid`))) join `vtiger_cliente` on((`vtiger_suscripcion`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) where ((`vtiger_suscripcion`.`estado` not in ('Ingresado a CRM (CP)','Preinspección REprogramada','Abierto (CP)','Preinspección Programada','No Quiere Firmar','No aplica','Desistido','REPETIDO','Por Procesar','Retención','Denunciado (CRM - SOS)','Por Recuperar','Reencantar','Preinspección a Reprogramar')) and (`vtiger_crmentity`.`createdtime` > '2022-01-01 23:59:59') and (`vtiger_suscripcion`.`nrofactura` <> 0) and (`vtiger_siniestro`.`id_fact_relBase_sus` <> 0) and (`vtiger_siniestro`.`estado_factura_sii` = 'Esperando') and (`vtiger_suscripcion`.`estado` is not null) and (`vtiger_suscripcion`.`estado` <> '') and (`vtiger_crmentity`.`deleted` = 0)) */;
/*!50001 DROP VIEW IF EXISTS `FirmasProcesadas_TC`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `FirmasProcesadas_TC` AS select `vtiger_siniestro`.`siniestroid` AS `id`,`vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_cliente`.`cliente` AS `Rut`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Cliente`,`vtiger_siniestro`.`nombrecliente` AS `nombrecliente`,`vtiger_crmentity`.`createdtime` AS `createdtime`,`vtiger_siniestro`.`captador` AS `captador`,`vtiger_siniestro`.`estado_` AS `estado`,`vtiger_users`.`user_name` AS `user_name`,`vtiger_siniestro`.`contratofirmado2` AS `contratofirmado2`,`vtiger_siniestro`.`tomadeconocimiento` AS `tomadeconocimiento` from (((`vtiger_siniestro` join `vtiger_crmentity` on((`vtiger_siniestro`.`siniestroid` = `vtiger_crmentity`.`crmid`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) join `vtiger_users` on((`vtiger_crmentity`.`smownerid` = `vtiger_users`.`id`))) where ((`vtiger_cliente`.`cliente` <> '') and (`vtiger_siniestro`.`nombrecliente` <> '') and (`vtiger_crmentity`.`createdtime` > '2021 23:59:59') and (`vtiger_siniestro`.`captador` not in ('Marco Diaz','Valeria Gomez','Rodrigo Valenzuela')) and (`vtiger_siniestro`.`estado_` not in ('No aplica','Desistido','Cerrado sin pago','Cerrado','Sin Poliza','Cerrado (Sin Dctos)','Repetido','CERRADO SIN DAÑOS','Por Procesar','Gestión Abogado','Retención')) and (`vtiger_siniestro`.`contratofirmado2` = 1) and (`vtiger_siniestro`.`tomadeconocimiento` = 1) and (`vtiger_crmentity`.`deleted` = 0) and (`vtiger_siniestro`.`fdenuncio` <> '') and (`vtiger_siniestro`.`direccionsiniestro` <> '') and (`vtiger_siniestro`.`comunacaso` <> '')) order by `vtiger_siniestro`.`estado_` */;
/*!50001 DROP VIEW IF EXISTS `FirmasSinProcesar`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `FirmasSinProcesar` AS select `vtiger_siniestro`.`siniestroid` AS `id`,`vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_cliente`.`cliente` AS `Rut`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Cliente`,`vtiger_siniestro`.`nombrecliente` AS `nombrecliente`,`vtiger_crmentity`.`createdtime` AS `createdtime`,`vtiger_siniestro`.`captador` AS `captador`,`vtiger_siniestro`.`estado_` AS `estado`,`vtiger_users`.`user_name` AS `user_name` from (((`vtiger_siniestro` join `vtiger_crmentity` on((`vtiger_siniestro`.`siniestroid` = `vtiger_crmentity`.`crmid`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) join `vtiger_users` on((`vtiger_crmentity`.`smownerid` = `vtiger_users`.`id`))) where ((`vtiger_crmentity`.`createdtime` > '2021 23:59:59') and (`vtiger_siniestro`.`captador` not in ('Marco Diaz','Valeria Gomez','Rodrigo Valenzuela')) and (`vtiger_siniestro`.`estado_` not in ('No aplica','Desistido','Cerrado sin pago','Cerrado','Sin Poliza','Cerrado (Sin Dctos)','Repetido','CERRADO SIN DAÑOS','Por Procesar','Gestión Abogado','Retención')) and (`vtiger_siniestro`.`contratofirmado2` = 0) and (`vtiger_crmentity`.`deleted` = 0)) order by `vtiger_siniestro`.`estado_` */;
/*!50001 DROP VIEW IF EXISTS `FirmasSinProcesar_TC`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `FirmasSinProcesar_TC` AS select `vtiger_siniestro`.`siniestroid` AS `id`,`vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_cliente`.`cliente` AS `Rut`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Cliente`,`vtiger_siniestro`.`nombrecliente` AS `nombrecliente`,`vtiger_crmentity`.`createdtime` AS `createdtime`,`vtiger_siniestro`.`captador` AS `captador`,`vtiger_siniestro`.`estado_` AS `estado`,`vtiger_users`.`user_name` AS `user_name`,`vtiger_siniestro`.`contratofirmado2` AS `contratofirmado2`,`vtiger_siniestro`.`tomadeconocimiento` AS `tomadeconocimiento` from (((`vtiger_siniestro` join `vtiger_crmentity` on((`vtiger_siniestro`.`siniestroid` = `vtiger_crmentity`.`crmid`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) join `vtiger_users` on((`vtiger_crmentity`.`smownerid` = `vtiger_users`.`id`))) where ((`vtiger_cliente`.`cliente` <> '') and (`vtiger_siniestro`.`nombrecliente` <> '') and (`vtiger_crmentity`.`createdtime` > '2021 23:59:59') and (`vtiger_siniestro`.`captador` not in ('Marco Diaz','Valeria Gomez','Rodrigo Valenzuela')) and (`vtiger_siniestro`.`estado_` not in ('No aplica','Desistido','Cerrado sin pago','Cerrado','Sin Poliza','Cerrado (Sin Dctos)','Repetido','CERRADO SIN DAÑOS','Por Procesar','Gestión Abogado','Retención')) and (`vtiger_siniestro`.`contratofirmado2` = 1) and (`vtiger_crmentity`.`deleted` = 0) and (`vtiger_siniestro`.`fdenuncio` <> '') and (`vtiger_siniestro`.`direccionsiniestro` <> '') and (`vtiger_siniestro`.`comunacaso` <> '') and (`vtiger_siniestro`.`tomadeconocimiento` = 0)) order by `vtiger_siniestro`.`estado_` */;
/*!50001 DROP VIEW IF EXISTS `FirmasVenDemPorProc`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `FirmasVenDemPorProc` AS select `vtiger_ventadedemandas`.`ventadedemandasid` AS `id`,`vtiger_ventadedemandas`.`idsiniestro` AS `idsiniestro`,`vtiger_ventadedemandas`.`estadocobranza` AS `estadocobranza`,`vtiger_ventadedemandas`.`estadocomercialdda` AS `estadocomercialdda`,`vtiger_ventadedemandas`.`montorecuperarclp` AS `montorecuperarclp`,`vtiger_ventadedemandas`.`porcentajeapagar` AS `porcentajeapagar`,`vtiger_ventadedemandas`.`fono` AS `fono`,`vtiger_ventadedemandas`.`correo` AS `correo`,`vtiger_ventadedemandas`.`estadollamada` AS `estadollamada`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Nombre`,`vtiger_ventadedemandas`.`actualizar` AS `actualizar`,`vtiger_ventadedemandas`.`fechadenuncia` AS `fechadenuncia`,`vtiger_ventadedemandas`.`clienteid` AS `clienteid`,`vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_users`.`user_name` AS `user_name`,`vtiger_ventadedemandas`.`contratofirmado` AS `contratofirmado` from ((((`vtiger_ventadedemandas` join `vtiger_crmentity` on((`vtiger_ventadedemandas`.`ventadedemandasid` = `vtiger_crmentity`.`crmid`))) join `vtiger_cliente` on((`vtiger_ventadedemandas`.`clienteid` = `vtiger_cliente`.`clienteid`))) join `vtiger_siniestro` on((`vtiger_ventadedemandas`.`idsiniestro` = `vtiger_siniestro`.`siniestroid`))) join `vtiger_users` on((`vtiger_crmentity`.`smownerid` = `vtiger_users`.`id`))) where ((`vtiger_crmentity`.`deleted` = 0) and (`vtiger_ventadedemandas`.`contratofirmado` <> 1)) order by `vtiger_ventadedemandas`.`ventadedemandasid` desc */;
/*!50001 DROP VIEW IF EXISTS `FirmasVenDemPorProcv2`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `FirmasVenDemPorProcv2` AS select `vtiger_ventadedemandas`.`ventadedemandasid` AS `id`,`vtiger_ventadedemandas`.`idsiniestro` AS `idsiniestro`,`vtiger_ventadedemandas`.`estadocobranza` AS `estadocobranza`,`vtiger_ventadedemandas`.`estadocomercialdda` AS `estadocomercialdda`,`vtiger_ventadedemandas`.`montorecuperarclp` AS `montorecuperarclp`,`vtiger_ventadedemandas`.`porcentajeapagar` AS `porcentajeapagar`,`vtiger_cliente`.`movil` AS `fono`,`vtiger_cliente`.`email` AS `correo`,`vtiger_ventadedemandas`.`estadollamada` AS `estadollamada`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Nombre`,`vtiger_ventadedemandas`.`actualizar` AS `actualizar`,`vtiger_ventadedemandas`.`fechadenuncia` AS `fechadenuncia`,`vtiger_ventadedemandas`.`clienteid` AS `clienteid`,`vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_users`.`user_name` AS `user_name`,`vtiger_ventadedemandas`.`contratofirmado` AS `contratofirmado`,`vtiger_siniestro`.`creadaaslegal` AS `creadaaslegal`,`vtiger_ventadedemandas`.`planaslegal` AS `planaslegal`,`vtiger_suscripciondemanda`.`fechaemifact` AS `FechaEmifact` from (((((`vtiger_ventadedemandas` join `vtiger_crmentity` on((`vtiger_ventadedemandas`.`ventadedemandasid` = `vtiger_crmentity`.`crmid`))) join `vtiger_cliente` on((`vtiger_ventadedemandas`.`clienteid` = `vtiger_cliente`.`clienteid`))) join `vtiger_siniestro` on((`vtiger_ventadedemandas`.`idsiniestro` = `vtiger_siniestro`.`siniestroid`))) join `vtiger_users` on((`vtiger_crmentity`.`smownerid` = `vtiger_users`.`id`))) join `vtiger_suscripciondemanda` on((`vtiger_ventadedemandas`.`ventadedemandasid` = `vtiger_suscripciondemanda`.`idventadedemanda`))) where ((`vtiger_ventadedemandas`.`estadocomercialdda` = 'Vendida') and (`vtiger_ventadedemandas`.`contratofirmado` <> 1) and (`vtiger_siniestro`.`creadaaslegal` = 1) and (`vtiger_ventadedemandas`.`planaslegal` = 180000) and (`vtiger_crmentity`.`deleted` = 0)) order by `vtiger_ventadedemandas`.`ventadedemandasid` desc */;
/*!50001 DROP VIEW IF EXISTS `IngresoMesActual_x_vendedor`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `IngresoMesActual_x_vendedor` AS (select `vtiger_siniestro`.`captador` AS `captador`,sum((case when (`vtiger_siniestro`.`estado_` in ('Ingresado a CRM (CP)','Preinspección a Reprogramar','Preinspección Programada','Preinspección Realizada','Preinspección Revisada','En Progreso (SOS)','Retomar En Progreso','Liquidador Asignado (SOS)','Revisión Progreso','Gestionar En Progreso','En progreso','Liquidador Asignado','Visita a Reprogramar','Visita Programada','Visita Realizada','Esperando','Denunciado (CRM - SOS)','Ingresado CRM (SOS)','Preinspección Programada (SOS)','Preinspección Reprogramar (SOS)','Abierto (Prioridad Baja)','Preinforme PR','Preinforme Cobertura','Preinforme PR (Gestionado)','Preinforme Cobertura (Gestionado)','Informe liq para impugnar PR','Informe liq impugnado Cobertura','Informe de liq Impugnado PR','Inf. Liq. Impugnar Cobertura','Revisión respuesta impugnación PR','Revisión respuesta impugnación Cobertura','Addendum para Impugnar','Addendum Impugnado')) then 1 else 0 end)) AS `Activos`,sum((case when (`vtiger_siniestro`.`estado_` = 'Desistido') then 1 else 0 end)) AS `Desistidos`,sum((case when (`vtiger_siniestro`.`estado_` = 'Abierto (CP)') then 1 else 0 end)) AS `Abiertos` from (`vtiger_siniestro` join `vtiger_crmentity` on((`vtiger_siniestro`.`siniestroid` = `vtiger_crmentity`.`crmid`))) where ((`vtiger_crmentity`.`deleted` = 0) and (`vtiger_crmentity`.`createdtime` between date_format(now(),'%Y-%m-01 00:00:00') and ((last_day(now()) + interval 1 day) - interval 1 second))) group by `vtiger_siniestro`.`captador`) union all (select 'Total' AS `captador`,sum((case when (`vtiger_siniestro`.`estado_` in ('Ingresado a CRM (CP)','Preinspección a Reprogramar','Preinspección Programada','Preinspección Realizada','Preinspección Revisada','En Progreso (SOS)','Retomar En Progreso','Liquidador Asignado (SOS)','Revisión Progreso','Gestionar En Progreso','En progreso','Liquidador Asignado','Visita a Reprogramar','Visita Programada','Visita Realizada','Esperando','Denunciado (CRM - SOS)','Ingresado CRM (SOS)','Preinspección Programada (SOS)','Preinspección Reprogramar (SOS)','Abierto (Prioridad Baja)','Preinforme PR','Preinforme Cobertura','Preinforme PR (Gestionado)','Preinforme Cobertura (Gestionado)','Informe liq para impugnar PR','Informe liq impugnado Cobertura','Informe de liq Impugnado PR','Inf. Liq. Impugnar Cobertura','Revisión respuesta impugnación PR','Revisión respuesta impugnación Cobertura','Addendum para Impugnar','Addendum Impugnado')) then 1 else 0 end)) AS `Activos`,sum((case when (`vtiger_siniestro`.`estado_` = 'Desistido') then 1 else 0 end)) AS `Desistidos`,sum((case when (`vtiger_siniestro`.`estado_` = 'Abierto (CP)') then 1 else 0 end)) AS `Abiertos` from (`vtiger_siniestro` join `vtiger_crmentity` on((`vtiger_siniestro`.`siniestroid` = `vtiger_crmentity`.`crmid`))) where ((`vtiger_crmentity`.`deleted` = 0) and (`vtiger_crmentity`.`createdtime` between date_format(now(),'%Y-%m-01 00:00:00') and ((last_day(now()) + interval 1 day) - interval 1 second)))) */;
/*!50001 DROP VIEW IF EXISTS `IngresoMesActual_x_vendedor2`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `IngresoMesActual_x_vendedor2` AS (select `sub`.`captador` AS `captador`,sum((case when (`sub`.`estado_` in ('Ingresado a CRM (CP)','Preinspección a Reprogramar','Preinspección Programada','Preinspección Realizada','Preinspección Revisada','En Progreso (SOS)','Retomar En Progreso','Liquidador Asignado (SOS)','Revisión Progreso','Gestionar En Progreso','En progreso','Liquidador Asignado','Visita a Reprogramar','Visita Programada','Visita Realizada','Esperando','Denunciado (CRM - SOS)','Ingresado CRM (SOS)','Preinspección Programada (SOS)','Preinspección Reprogramar (SOS)','Abierto (Prioridad Baja)','Preinforme PR','Preinforme Cobertura','Preinforme PR (Gestionado)','Preinforme Cobertura (Gestionado)','Informe liq para impugnar PR','Informe liq impugnado Cobertura','Informe de liq Impugnado PR','Inf. Liq. Impugnar Cobertura','Revisión respuesta impugnación PR','Revisión respuesta impugnación Cobertura','Addendum para Impugnar','Addendum Impugnado','Desistido (Cobrar Suscripción)')) then 1 else 0 end)) AS `Ingresados`,sum((case when (`sub`.`estado_` = 'Desistido') then 1 else 0 end)) AS `Desistidos`,sum((case when (`sub`.`estado_` = 'Abierto (CP)') then 1 else 0 end)) AS `Abiertos`,sum((case when (`crmcubic_crm_asesor`.`vtiger_suscripcion`.`abonopagado` = 1) then 1 else 0 end)) AS `Abonados_1`,sum((case when (`crmcubic_crm_asesor`.`vtiger_suscripcion`.`abonopagado` = 0) then 1 else 0 end)) AS `Abonados_0`,sum((case when (`sub`.`estado_` <> 'Desistido') then `crmcubic_crm_asesor`.`vtiger_suscripcion`.`abono` else 0 end)) AS `Total_Abono`,sum((case when ((`sub`.`estado_` <> 'Desistido') and (`crmcubic_crm_asesor`.`vtiger_suscripcion`.`abonopagado` = 1)) then `crmcubic_crm_asesor`.`vtiger_suscripcion`.`abono` else 0 end)) AS `Abono_Pagado`,(sum((case when (`sub`.`estado_` <> 'Desistido') then `crmcubic_crm_asesor`.`vtiger_suscripcion`.`abono` else 0 end)) - sum((case when ((`sub`.`estado_` <> 'Desistido') and (`crmcubic_crm_asesor`.`vtiger_suscripcion`.`abonopagado` = 1)) then `crmcubic_crm_asesor`.`vtiger_suscripcion`.`abono` else 0 end))) AS `Deuda_Total` from (((select `crmcubic_crm_asesor`.`vtiger_siniestro`.`captador` AS `captador`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestroid` AS `siniestroid`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`estado_` AS `estado_` from (`crmcubic_crm_asesor`.`vtiger_siniestro` join `crmcubic_crm_asesor`.`vtiger_crmentity` on((`crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestroid` = `crmcubic_crm_asesor`.`vtiger_crmentity`.`crmid`))) where ((`crmcubic_crm_asesor`.`vtiger_crmentity`.`deleted` = 0) and (`crmcubic_crm_asesor`.`vtiger_crmentity`.`createdtime` between date_format((curdate() - interval (dayofmonth(curdate()) - 1) day),'%Y-%m-01 00:00:00') and last_day(curdate()))))) `sub` left join `crmcubic_crm_asesor`.`vtiger_suscripcion` on((`sub`.`siniestroid` = `crmcubic_crm_asesor`.`vtiger_suscripcion`.`siniestro`))) group by `sub`.`captador`) union all (select 'Total' AS `captador`,sum((case when (`sub`.`estado_` in ('Ingresado a CRM (CP)','Preinspección a Reprogramar','Preinspección Programada','Preinspección Realizada','Preinspección Revisada','En Progreso (SOS)','Retomar En Progreso','Liquidador Asignado (SOS)','Revisión Progreso','Gestionar En Progreso','En progreso','Liquidador Asignado','Visita a Reprogramar','Visita Programada','Visita Realizada','Esperando','Denunciado (CRM - SOS)','Ingresado CRM (SOS)','Preinspección Programada (SOS)','Preinspección Reprogramar (SOS)','Abierto (Prioridad Baja)','Preinforme PR','Preinforme Cobertura','Preinforme PR (Gestionado)','Preinforme Cobertura (Gestionado)','Informe liq para impugnar PR','Informe liq impugnado Cobertura','Informe de liq Impugnado PR','Inf. Liq. Impugnar Cobertura','Revisión respuesta impugnación PR','Revisión respuesta impugnación Cobertura','Addendum para Impugnar','Addendum Impugnado','Desistido (Cobrar Suscripción)')) then 1 else 0 end)) AS `Ingresados`,sum((case when (`sub`.`estado_` = 'Desistido') then 1 else 0 end)) AS `Desistidos`,sum((case when (`sub`.`estado_` = 'Abierto (CP)') then 1 else 0 end)) AS `Abiertos`,sum((case when (`crmcubic_crm_asesor`.`vtiger_suscripcion`.`abonopagado` = 1) then 1 else 0 end)) AS `Abonados_1`,sum((case when (`crmcubic_crm_asesor`.`vtiger_suscripcion`.`abonopagado` = 0) then 1 else 0 end)) AS `Abonados_0`,sum((case when (`sub`.`estado_` <> 'Desistido') then `crmcubic_crm_asesor`.`vtiger_suscripcion`.`abono` else 0 end)) AS `Total_Abono`,sum((case when ((`sub`.`estado_` <> 'Desistido') and (`crmcubic_crm_asesor`.`vtiger_suscripcion`.`abonopagado` = 1)) then `crmcubic_crm_asesor`.`vtiger_suscripcion`.`abono` else 0 end)) AS `Abono_Pagado`,(sum((case when (`sub`.`estado_` <> 'Desistido') then `crmcubic_crm_asesor`.`vtiger_suscripcion`.`abono` else 0 end)) - sum((case when ((`sub`.`estado_` <> 'Desistido') and (`crmcubic_crm_asesor`.`vtiger_suscripcion`.`abonopagado` = 1)) then `crmcubic_crm_asesor`.`vtiger_suscripcion`.`abono` else 0 end))) AS `Deuda_Total` from (((select `crmcubic_crm_asesor`.`vtiger_siniestro`.`captador` AS `captador`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestroid` AS `siniestroid`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`estado_` AS `estado_` from (`crmcubic_crm_asesor`.`vtiger_siniestro` join `crmcubic_crm_asesor`.`vtiger_crmentity` on((`crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestroid` = `crmcubic_crm_asesor`.`vtiger_crmentity`.`crmid`))) where ((`crmcubic_crm_asesor`.`vtiger_crmentity`.`deleted` = 0) and (`crmcubic_crm_asesor`.`vtiger_crmentity`.`createdtime` between date_format((curdate() - interval (dayofmonth(curdate()) - 1) day),'%Y-%m-01 00:00:00') and last_day(curdate()))))) `sub` left join `crmcubic_crm_asesor`.`vtiger_suscripcion` on((`sub`.`siniestroid` = `crmcubic_crm_asesor`.`vtiger_suscripcion`.`siniestro`)))) */;
/*!50001 DROP VIEW IF EXISTS `IngresoMesAnterior_x_vendedor`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `IngresoMesAnterior_x_vendedor` AS (select `vtiger_siniestro`.`captador` AS `captador`,sum((case when (`vtiger_siniestro`.`estado_` in ('Ingresado a CRM (CP)','Preinspección a Reprogramar','Preinspección Programada','Preinspección Realizada','Preinspección Revisada','En Progreso (SOS)','Retomar En Progreso','Liquidador Asignado (SOS)','Revisión Progreso','Gestionar En Progreso','En progreso','Liquidador Asignado','Visita a Reprogramar','Visita Programada','Visita Realizada','Esperando','Denunciado (CRM - SOS)','Ingresado CRM (SOS)','Preinspección Programada (SOS)','Preinspección Reprogramar (SOS)','Abierto (Prioridad Baja)','Preinforme PR','Preinforme Cobertura','Preinforme PR (Gestionado)','Preinforme Cobertura (Gestionado)','Informe liq para impugnar PR','Informe liq impugnado Cobertura','Informe de liq Impugnado PR','Inf. Liq. Impugnar Cobertura','Revisión respuesta impugnación PR','Revisión respuesta impugnación Cobertura','Addendum para Impugnar','Addendum Impugnado')) then 1 else 0 end)) AS `Activos`,sum((case when (`vtiger_siniestro`.`estado_` = 'Desistido') then 1 else 0 end)) AS `Desistidos`,sum((case when (`vtiger_siniestro`.`estado_` = 'Abierto (CP)') then 1 else 0 end)) AS `Abiertos` from (`vtiger_siniestro` join `vtiger_crmentity` on((`vtiger_siniestro`.`siniestroid` = `vtiger_crmentity`.`crmid`))) where ((`vtiger_crmentity`.`deleted` = 0) and (`vtiger_crmentity`.`createdtime` between date_format((now() - interval 1 month),'%Y-%m-01 00:00:00') and ((last_day((now() - interval 1 month)) + interval 1 day) - interval 1 second))) group by `vtiger_siniestro`.`captador`) union all (select 'Total' AS `captador`,sum((case when (`vtiger_siniestro`.`estado_` in ('Ingresado a CRM (CP)','Preinspección a Reprogramar','Preinspección Programada','Preinspección Realizada','Preinspección Revisada','En Progreso (SOS)','Retomar En Progreso','Liquidador Asignado (SOS)','Revisión Progreso','Gestionar En Progreso','En progreso','Liquidador Asignado','Visita a Reprogramar','Visita Programada','Visita Realizada','Esperando','Denunciado (CRM - SOS)','Ingresado CRM (SOS)','Preinspección Programada (SOS)','Preinspección Reprogramar (SOS)','Abierto (Prioridad Baja)','Preinforme PR','Preinforme Cobertura','Preinforme PR (Gestionado)','Preinforme Cobertura (Gestionado)','Informe liq para impugnar PR','Informe liq impugnado Cobertura','Informe de liq Impugnado PR','Inf. Liq. Impugnar Cobertura','Revisión respuesta impugnación PR','Revisión respuesta impugnación Cobertura','Addendum para Impugnar','Addendum Impugnado')) then 1 else 0 end)) AS `Activos`,sum((case when (`vtiger_siniestro`.`estado_` = 'Desistido') then 1 else 0 end)) AS `Desistidos`,sum((case when (`vtiger_siniestro`.`estado_` = 'Abierto (CP)') then 1 else 0 end)) AS `Abiertos` from (`vtiger_siniestro` join `vtiger_crmentity` on((`vtiger_siniestro`.`siniestroid` = `vtiger_crmentity`.`crmid`))) where ((`vtiger_crmentity`.`deleted` = 0) and (`vtiger_crmentity`.`createdtime` between date_format((now() - interval 1 month),'%Y-%m-01 00:00:00') and ((last_day((now() - interval 1 month)) + interval 1 day) - interval 1 second)))) */;
/*!50001 DROP VIEW IF EXISTS `IngresoMesAnterior_x_vendedor2`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `IngresoMesAnterior_x_vendedor2` AS (select `sub`.`captador` AS `captador`,sum((case when (`sub`.`estado_` in ('Ingresado a CRM (CP)','Preinspección a Reprogramar','Preinspección Programada','Preinspección Realizada','Preinspección Revisada','En Progreso (SOS)','Retomar En Progreso','Liquidador Asignado (SOS)','Revisión Progreso','Gestionar En Progreso','En progreso','Liquidador Asignado','Visita a Reprogramar','Visita Programada','Visita Realizada','Esperando','Denunciado (CRM - SOS)','Ingresado CRM (SOS)','Preinspección Programada (SOS)','Preinspección Reprogramar (SOS)','Abierto (Prioridad Baja)','Preinforme PR','Preinforme Cobertura','Preinforme PR (Gestionado)','Preinforme Cobertura (Gestionado)','Informe liq para impugnar PR','Informe liq impugnado Cobertura','Informe de liq Impugnado PR','Inf. Liq. Impugnar Cobertura','Revisión respuesta impugnación PR','Revisión respuesta impugnación Cobertura','Addendum para Impugnar','Addendum Impugnado','Desistido (Cobrar Suscripción)')) then 1 else 0 end)) AS `Ingresados`,sum((case when (`sub`.`estado_` = 'Desistido') then 1 else 0 end)) AS `Desistidos`,sum((case when (`sub`.`estado_` = 'Abierto (CP)') then 1 else 0 end)) AS `Abiertos`,sum((case when (`crmcubic_crm_asesor`.`vtiger_suscripcion`.`abonopagado` = 1) then 1 else 0 end)) AS `Abonados_1`,sum((case when (`crmcubic_crm_asesor`.`vtiger_suscripcion`.`abonopagado` = 0) then 1 else 0 end)) AS `Abonados_0`,sum((case when (`sub`.`estado_` <> 'Desistido') then `crmcubic_crm_asesor`.`vtiger_suscripcion`.`abono` else 0 end)) AS `Total_Abono`,sum((case when ((`sub`.`estado_` <> 'Desistido') and (`crmcubic_crm_asesor`.`vtiger_suscripcion`.`abonopagado` = 1)) then `crmcubic_crm_asesor`.`vtiger_suscripcion`.`abono` else 0 end)) AS `Abono_Pagado`,(sum((case when (`sub`.`estado_` <> 'Desistido') then `crmcubic_crm_asesor`.`vtiger_suscripcion`.`abono` else 0 end)) - sum((case when ((`sub`.`estado_` <> 'Desistido') and (`crmcubic_crm_asesor`.`vtiger_suscripcion`.`abonopagado` = 1)) then `crmcubic_crm_asesor`.`vtiger_suscripcion`.`abono` else 0 end))) AS `Deuda_Total` from (((select `crmcubic_crm_asesor`.`vtiger_siniestro`.`captador` AS `captador`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestroid` AS `siniestroid`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`estado_` AS `estado_` from (`crmcubic_crm_asesor`.`vtiger_siniestro` join `crmcubic_crm_asesor`.`vtiger_crmentity` on((`crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestroid` = `crmcubic_crm_asesor`.`vtiger_crmentity`.`crmid`))) where ((`crmcubic_crm_asesor`.`vtiger_crmentity`.`deleted` = 0) and (`crmcubic_crm_asesor`.`vtiger_crmentity`.`createdtime` between date_format((now() - interval 1 month),'%Y-%m-01 00:00:00') and ((last_day((now() - interval 1 month)) + interval 1 day) - interval 1 second))))) `sub` left join `crmcubic_crm_asesor`.`vtiger_suscripcion` on((`sub`.`siniestroid` = `crmcubic_crm_asesor`.`vtiger_suscripcion`.`siniestro`))) group by `sub`.`captador`) union all (select 'Total' AS `captador`,sum((case when (`sub`.`estado_` in ('Ingresado a CRM (CP)','Preinspección a Reprogramar','Preinspección Programada','Preinspección Realizada','Preinspección Revisada','En Progreso (SOS)','Retomar En Progreso','Liquidador Asignado (SOS)','Revisión Progreso','Gestionar En Progreso','En progreso','Liquidador Asignado','Visita a Reprogramar','Visita Programada','Visita Realizada','Esperando','Denunciado (CRM - SOS)','Ingresado CRM (SOS)','Preinspección Programada (SOS)','Preinspección Reprogramar (SOS)','Abierto (Prioridad Baja)','Preinforme PR','Preinforme Cobertura','Preinforme PR (Gestionado)','Preinforme Cobertura (Gestionado)','Informe liq para impugnar PR','Informe liq impugnado Cobertura','Informe de liq Impugnado PR','Inf. Liq. Impugnar Cobertura','Revisión respuesta impugnación PR','Revisión respuesta impugnación Cobertura','Addendum para Impugnar','Addendum Impugnado','Desistido (Cobrar Suscripción)')) then 1 else 0 end)) AS `Ingresados`,sum((case when (`sub`.`estado_` = 'Desistido') then 1 else 0 end)) AS `Desistidos`,sum((case when (`sub`.`estado_` = 'Abierto (CP)') then 1 else 0 end)) AS `Abiertos`,sum((case when (`crmcubic_crm_asesor`.`vtiger_suscripcion`.`abonopagado` = 1) then 1 else 0 end)) AS `Abonados_1`,sum((case when (`crmcubic_crm_asesor`.`vtiger_suscripcion`.`abonopagado` = 0) then 1 else 0 end)) AS `Abonados_0`,sum((case when (`sub`.`estado_` <> 'Desistido') then `crmcubic_crm_asesor`.`vtiger_suscripcion`.`abono` else 0 end)) AS `Total_Abono`,sum((case when ((`sub`.`estado_` <> 'Desistido') and (`crmcubic_crm_asesor`.`vtiger_suscripcion`.`abonopagado` = 1)) then `crmcubic_crm_asesor`.`vtiger_suscripcion`.`abono` else 0 end)) AS `Abono_Pagado`,(sum((case when (`sub`.`estado_` <> 'Desistido') then `crmcubic_crm_asesor`.`vtiger_suscripcion`.`abono` else 0 end)) - sum((case when ((`sub`.`estado_` <> 'Desistido') and (`crmcubic_crm_asesor`.`vtiger_suscripcion`.`abonopagado` = 1)) then `crmcubic_crm_asesor`.`vtiger_suscripcion`.`abono` else 0 end))) AS `Deuda_Total` from (((select `crmcubic_crm_asesor`.`vtiger_siniestro`.`captador` AS `captador`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestroid` AS `siniestroid`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`estado_` AS `estado_` from (`crmcubic_crm_asesor`.`vtiger_siniestro` join `crmcubic_crm_asesor`.`vtiger_crmentity` on((`crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestroid` = `crmcubic_crm_asesor`.`vtiger_crmentity`.`crmid`))) where ((`crmcubic_crm_asesor`.`vtiger_crmentity`.`deleted` = 0) and (`crmcubic_crm_asesor`.`vtiger_crmentity`.`createdtime` between date_format((now() - interval 1 month),'%Y-%m-01 00:00:00') and ((last_day((now() - interval 1 month)) + interval 1 day) - interval 1 second))))) `sub` left join `crmcubic_crm_asesor`.`vtiger_suscripcion` on((`sub`.`siniestroid` = `crmcubic_crm_asesor`.`vtiger_suscripcion`.`siniestro`)))) */;
/*!50001 DROP VIEW IF EXISTS `LEADS_NO_CLIENTES`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `LEADS_NO_CLIENTES` AS select `vtiger_campanasmktdigital`.`nombrecompleto` AS `nombrecompleto`,`vtiger_campanasmktdigital`.`correo` AS `correo`,`vtiger_campanasmktdigital`.`telefono` AS `telefono`,`vtiger_campanasmktdigital`.`comuna` AS `comuna`,`vtiger_crmentity`.`createdtime` AS `fecha_de_creacion_Leads`,`vtiger_campanasmktdigital`.`motivorechazo` AS `motivorechazo`,`vtiger_campanasmktdigital`.`estadolead` AS `estadolead`,`vtiger_campanasmktdigital`.`estadollamada` AS `estadollamada`,`vtiger_campanasmktdigital`.`gestionadopor` AS `gestionadopor`,`vtiger_campanasmktdigital`.`obsrechazo` AS `obsrechazo`,`vtiger_campanasmktdigital`.`obslead` AS `obslead` from ((`vtiger_campanasmktdigital` left join `vtiger_cliente` on((`vtiger_campanasmktdigital`.`correo` = `vtiger_cliente`.`email`))) join `vtiger_crmentity` on((`vtiger_campanasmktdigital`.`campanasmktdigitalid` = `vtiger_crmentity`.`crmid`))) where (isnull(`vtiger_cliente`.`email`) = TRUE) */;
/*!50001 DROP VIEW IF EXISTS `LEADS_PROCESADOS`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `LEADS_PROCESADOS` AS select `vtiger_cliente`.`cliente` AS `Rut`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Nombre`,`vtiger_cliente`.`movil` AS `movil`,`vtiger_cliente`.`email` AS `email`,`vtiger_cliente`.`comunacliente` AS `comunacliente` from (`vtiger_campanasmktdigital` join `vtiger_cliente` on((`vtiger_campanasmktdigital`.`correo` = `vtiger_cliente`.`email`))) */;
/*!50001 DROP VIEW IF EXISTS `Leads_asig_por_gest`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `Leads_asig_por_gest` AS select `vtiger_siniestro`.`siniestro` AS `Nro_Caso`,`vtiger_crmentity`.`createdtime` AS `Fecha_Creacion`,`vtiger_crmentity`.`smownerid` AS `Id_captador`,`vtiger_ventadedemandas`.`tiposiniestro` AS `Tipo_Siniestro`,`vtiger_ventadedemandas`.`comunasiniestro` AS `Comuna`,`vtiger_ventadedemandas`.`direccionsiniestro` AS `Direccion`,`vtiger_ventadedemandas`.`banco` AS `Banco`,`vtiger_ventadedemandas`.`liquidador` AS `Liquidador`,`vtiger_ventadedemandas`.`compseguros` AS `Cia_Seguros`,`vtiger_ventadedemandas`.`fechacreacioncaso` AS `Fecha_Crea_Caso`,`vtiger_ventadedemandas`.`fechadenuncia` AS `Fecha_Denuncio`,`vtiger_ventadedemandas`.`fechavisita` AS `Fecha_Visita`,`vtiger_ventadedemandas`.`fechapresupuesto` AS `Fecha_Presupuesto`,`vtiger_ventadedemandas`.`fechainforme` AS `Fecha_informe`,`vtiger_ventadedemandas`.`fechaimpug` AS `Fecha_impug`,`vtiger_ventadedemandas`.`fecharesp` AS `Fecha_Respuesta`,`vtiger_ventadedemandas`.`fechapreinspeccion` AS `Fecha_Preinspeccion`,`vtiger_ventadedemandas`.`rutcliente` AS `Rut_Cliente`,`vtiger_ventadedemandas`.`fono` AS `Fono_Cliente`,`vtiger_ventadedemandas`.`correo` AS `Email_Cliente`,`vtiger_ventadedemandas`.`planaslegal` AS `Plan`,`vtiger_ventadedemandas`.`contratofirmado` AS `Contrato_frimado`,`vtiger_ventadedemandas`.`perdidareclamadauf` AS `Pedida_rec_UF`,`vtiger_ventadedemandas`.`perddetuf` AS `Perdida_det_UF`,`vtiger_ventadedemandas`.`deducibleuf` AS `Desucible_UF`,`vtiger_ventadedemandas`.`perdinduf` AS `Perdida_indembizable_UF`,`vtiger_ventadedemandas`.`indemnizacionclpclp` AS `Indemnizacion`,`vtiger_ventadedemandas`.`montorecuperarclp` AS `Monto_Rec_PESOS`,`vtiger_ventadedemandas`.`estadollamada` AS `Estado_LLamda`,concat(`vtiger_users`.`first_name`,' ',`vtiger_users`.`last_name`) AS `Captador`,`vtiger_ventadedemandas`.`estadocomercialdda` AS `Estado_Comercial_ASL`,`vtiger_ventadedemandas`.`porcentajeapagar` AS `Porc_a_Pagar`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Cliente`,`vtiger_ventadedemandas`.`ventadedemandasid` AS `ventadedemandasid`,`vtiger_users`.`user_name` AS `Usuario` from ((((`vtiger_siniestro` join `vtiger_ventadedemandas` on((`vtiger_ventadedemandas`.`idsiniestro` = `vtiger_siniestro`.`siniestroid`))) join `vtiger_crmentity` on((`vtiger_ventadedemandas`.`ventadedemandasid` = `vtiger_crmentity`.`crmid`))) join `vtiger_users` on((`vtiger_users`.`id` = `vtiger_crmentity`.`smownerid`))) join `vtiger_cliente` on((`vtiger_ventadedemandas`.`clienteid` = `vtiger_cliente`.`clienteid`))) where ((`vtiger_ventadedemandas`.`planaslegal` = 180000) and (`vtiger_ventadedemandas`.`estadocomercialdda` <> 'Vendida')) */;
/*!50001 DROP VIEW IF EXISTS `Lost_Filtro1`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `Lost_Filtro1` AS select `ClayCrm`.`id` AS `id`,`ClayCrm`.`Nro_caso` AS `Nro_caso`,`ClayCrm`.`Num_Factura` AS `Num_Factura` from (`ClayCrm` left join `facturas_report_clay_all` on((`ClayCrm`.`Num_Factura` = `facturas_report_clay_all`.`Factura`))) where isnull(`facturas_report_clay_all`.`Factura`) */;
/*!50001 DROP VIEW IF EXISTS `Lost_Filtro2`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `Lost_Filtro2` AS select `Lost_solo_Cobranza_Rep`.`id` AS `id`,`Lost_solo_Cobranza_Rep`.`Num_Factura` AS `Num_factura`,`Lost_solo_Cobranza_Rep`.`Nro_caso` AS `Nro_caso` from `Lost_solo_Cobranza_Rep` union all select `Lost_solo_Cobranza_Sus_Rep`.`id` AS `id`,`Lost_solo_Cobranza_Sus_Rep`.`Num_Factura` AS `Num_factura`,`Lost_solo_Cobranza_Sus_Rep`.`Nro_caso` AS `Nro_caso` from `Lost_solo_Cobranza_Sus_Rep` union all select `Lost_solo_Sus_Dda_Rep`.`id` AS `id`,`Lost_solo_Sus_Dda_Rep`.`Num_Factura` AS `Num_factura`,`Lost_solo_Sus_Dda_Rep`.`Nro_caso` AS `Nro_caso` from `Lost_solo_Sus_Dda_Rep` union all select `Lost_solo_Sus_Rep`.`id` AS `id`,`Lost_solo_Sus_Rep`.`Num_Factura` AS `Num_factura`,`Lost_solo_Sus_Rep`.`Nro_caso` AS `Nro_caso` from `Lost_solo_Sus_Rep` */;
/*!50001 DROP VIEW IF EXISTS `Lost_Filtro3`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `Lost_Filtro3` AS select `Lost_Filtro1`.`id` AS `id`,`Lost_Filtro1`.`Nro_caso` AS `Nro_caso`,`Lost_Filtro1`.`Num_Factura` AS `Num_Factura` from (`Lost_Filtro1` left join `Lost_Filtro2` on(((`Lost_Filtro1`.`id` = `Lost_Filtro2`.`id`) and (`Lost_Filtro1`.`Nro_caso` = `Lost_Filtro2`.`Nro_caso`) and (`Lost_Filtro1`.`Num_Factura` = `Lost_Filtro2`.`Num_factura`)))) where isnull(`Lost_Filtro2`.`id`) order by `Lost_Filtro1`.`Nro_caso` */;
/*!50001 DROP VIEW IF EXISTS `Lost_Filtro4`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `Lost_Filtro4` AS select `Lost_Filtro2`.`id` AS `id`,`Lost_Filtro2`.`Num_factura` AS `Num_factura`,`Lost_Filtro2`.`Nro_caso` AS `Nro_caso` from `Lost_Filtro2` union select `Lost_Filtro3`.`id` AS `id`,`Lost_Filtro3`.`Num_Factura` AS `Num_factura`,`Lost_Filtro3`.`Nro_caso` AS `Nro_caso` from `Lost_Filtro3` order by `id` */;
/*!50001 DROP VIEW IF EXISTS `Lost_Filtro5`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `Lost_Filtro5` AS select `Lost_Filtro4`.`Num_factura` AS `Num_factura`,`Lost_Filtro4`.`Nro_caso` AS `Nro_caso`,(case when (`vtiger_siniestro`.`nrofactura` is not null) then 'Siniestro 30%' when (`vtiger_suscripcion`.`nrofactura` is not null) then 'Suscripción' when (`vtiger_suscripciondemanda`.`nrofactura` is not null) then 'Suscripción de Demanda' else 'No Encontrado' end) AS `TableName`,(case when (`vtiger_siniestro`.`nrofactura` is not null) then `vtiger_siniestro`.`estado_` when (`vtiger_suscripcion`.`nrofactura` is not null) then `vtiger_suscripcion`.`estado` when (`vtiger_suscripciondemanda`.`nrofactura` is not null) then `vtiger_suscripciondemanda`.`estadosuscripcion` else 'Sin estado' end) AS `estado del modulo`,(case when (`vtiger_suscripcion`.`nrofactura` is not null) then `vtiger_suscripcion`.`nrocuotas` when (`vtiger_suscripciondemanda`.`nrofactura` is not null) then `vtiger_suscripciondemanda`.`nrocuotas` else NULL end) AS `Nro_cuotas` from (((`Lost_Filtro4` left join `vtiger_siniestro` on((`Lost_Filtro4`.`Num_factura` = `vtiger_siniestro`.`nrofactura`))) left join `vtiger_suscripcion` on((`Lost_Filtro4`.`Num_factura` = `vtiger_suscripcion`.`nrofactura`))) left join `vtiger_suscripciondemanda` on((`Lost_Filtro4`.`Num_factura` = `vtiger_suscripciondemanda`.`nrofactura`))) */;
/*!50001 DROP VIEW IF EXISTS `Lost_Filtro6`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `Lost_Filtro6` AS select `Lost_Filtro5`.`Nro_caso` AS `Nro_caso`,`Lost_Filtro5`.`Num_factura` AS `Num_factura`,`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`ClayCrm`.`Mes_Año` AS `Mes_Año`,`Lost_Filtro5`.`TableName` AS `TableName`,`Lost_Filtro5`.`estado del modulo` AS `estado del modulo`,`Lost_Filtro5`.`Nro_cuotas` AS `Nro_cuotas`,`ClayCrm`.`Saldo` AS `Saldo`,`vtiger_cliente`.`dircliente` AS `dircliente`,`vtiger_cliente`.`nombre` AS `nombre`,`vtiger_cliente`.`apellido` AS `apellido`,`vtiger_cliente`.`movil` AS `movil`,`vtiger_cliente`.`movil_extra` AS `movil_extra`,`vtiger_cliente`.`email` AS `email` from ((`ClayCrm` join `Lost_Filtro5` on((`ClayCrm`.`Num_Factura` = `Lost_Filtro5`.`Num_factura`))) join `vtiger_cliente` on((replace(`ClayCrm`.`RUT_Receptor`,'.','') = `vtiger_cliente`.`cliente`))) */;
/*!50001 DROP VIEW IF EXISTS `Lost_solo_Cobranza`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `Lost_solo_Cobranza` AS select distinct `ClayCrm`.`id` AS `id`,`ClayCrm`.`Nro_caso` AS `Nro_caso`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Saldo` AS `Saldo`,`ClayCrm`.`COBRANZA_EX` AS `COBRANZA_EX`,`vtiger_paymentsin`.`paymentsin_status` AS `paymentsin_status` from ((`ClayCrm` left join `facturas_report_clay_all` on((`ClayCrm`.`Num_Factura` = `facturas_report_clay_all`.`Factura`))) join `vtiger_paymentsin` on((`ClayCrm`.`Num_Factura` = `vtiger_paymentsin`.`nrofactura`))) where (isnull(`facturas_report_clay_all`.`Factura`) and (`ClayCrm`.`SUSCRIPCION_EX` = 0) and (`ClayCrm`.`SUSCRIPCION_DDA_EX` = 0) and (`ClayCrm`.`COBRANZA_EX` = 1)) */;
/*!50001 DROP VIEW IF EXISTS `Lost_solo_Cobranza_Rep`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `Lost_solo_Cobranza_Rep` AS select distinct `ClayCrm`.`id` AS `id`,`ClayCrm`.`Nro_caso` AS `Nro_caso`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Saldo` AS `Saldo`,`ClayCrm`.`COBRANZA_EX` AS `COBRANZA_EX`,`vtiger_paymentsin`.`paymentsin_status` AS `Estado_Cobranza` from ((`ClayCrm` left join `facturas_report_clay_all` on((`ClayCrm`.`Num_Factura` = `facturas_report_clay_all`.`Factura`))) join `vtiger_paymentsin` on((`ClayCrm`.`Num_Factura` = `vtiger_paymentsin`.`nrofactura`))) where ((`ClayCrm`.`COBRANZA_EX` = 1) and (isnull(`facturas_report_clay_all`.`Factura`) = TRUE) and (`ClayCrm`.`SUSCRIPCION_EX` = 0) and (`ClayCrm`.`SUSCRIPCION_DDA_EX` = 0)) */;
/*!50001 DROP VIEW IF EXISTS `Lost_solo_Cobranza_Sus_Rep`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `Lost_solo_Cobranza_Sus_Rep` AS select distinct `ClayCrm`.`id` AS `id`,`ClayCrm`.`Nro_caso` AS `Nro_caso`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Saldo` AS `Saldo`,`ClayCrm`.`COBRANZA_EX` AS `COBRANZA_EX`,`vtiger_paymentsin`.`paymentsin_status` AS `Estado_Cobranza`,`vtiger_suscripcion`.`estado` AS `Estado_Suscripcion` from (((`ClayCrm` left join `facturas_report_clay_all` on((`ClayCrm`.`Num_Factura` = `facturas_report_clay_all`.`Factura`))) join `vtiger_paymentsin` on((`ClayCrm`.`Num_Factura` = `vtiger_paymentsin`.`nrofactura`))) join `vtiger_suscripcion` on((`vtiger_suscripcion`.`nrofactura` = `ClayCrm`.`Num_Factura`))) where ((`ClayCrm`.`COBRANZA_EX` = 1) and (isnull(`facturas_report_clay_all`.`Factura`) = TRUE) and (`ClayCrm`.`SUSCRIPCION_EX` = 1) and (`ClayCrm`.`SUSCRIPCION_DDA_EX` = 0)) */;
/*!50001 DROP VIEW IF EXISTS `Lost_solo_Sus_Dda_Rep`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `Lost_solo_Sus_Dda_Rep` AS select distinct `ClayCrm`.`id` AS `id`,`ClayCrm`.`Nro_caso` AS `Nro_caso`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Saldo` AS `Saldo`,`ClayCrm`.`SUSCRIPCION_DDA_EX` AS `SUSCRIPCION_DDA_EX`,`vtiger_suscripciondemanda`.`estadocomercialdda` AS `estadocomercialdda`,`vtiger_suscripciondemanda`.`estadocaso` AS `estadocaso` from ((`ClayCrm` left join `facturas_report_clay_all` on((`ClayCrm`.`Num_Factura` = `facturas_report_clay_all`.`Factura`))) join `vtiger_suscripciondemanda` on((`vtiger_suscripciondemanda`.`nrofactura` = `ClayCrm`.`Num_Factura`))) where ((`ClayCrm`.`SUSCRIPCION_DDA_EX` = 1) and (isnull(`facturas_report_clay_all`.`Factura`) = TRUE) and (`ClayCrm`.`SUSCRIPCION_EX` = 0) and (`ClayCrm`.`COBRANZA_EX` = 0)) */;
/*!50001 DROP VIEW IF EXISTS `Lost_solo_Sus_Rep`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `Lost_solo_Sus_Rep` AS select distinct `ClayCrm`.`id` AS `id`,`ClayCrm`.`Nro_caso` AS `Nro_caso`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Saldo` AS `Saldo`,`ClayCrm`.`SUSCRIPCION_EX` AS `SUSCRIPCION_EX`,`vtiger_suscripcion`.`estado` AS `estado` from ((`ClayCrm` left join `facturas_report_clay_all` on((`ClayCrm`.`Num_Factura` = `facturas_report_clay_all`.`Factura`))) join `vtiger_suscripcion` on((`ClayCrm`.`Num_Factura` = `vtiger_suscripcion`.`nrofactura`))) where (isnull(`facturas_report_clay_all`.`Factura`) and (`ClayCrm`.`SUSCRIPCION_EX` = 1) and (`ClayCrm`.`SUSCRIPCION_DDA_EX` = 0) and (`ClayCrm`.`COBRANZA_EX` = 0)) */;
/*!50001 DROP VIEW IF EXISTS `Pac_suscripcion`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `Pac_suscripcion` AS select `vtiger_siniestro`.`siniestroid` AS `Id_siniestro`,`vtiger_suscripcion`.`suscripcionid` AS `Id_suscripcion`,`vtiger_cliente`.`cliente` AS `Rut_Cliente`,`vtiger_siniestro`.`siniestro` AS `Nro_Caso`,`vtiger_siniestro`.`estado_` AS `Estado`,`vtiger_siniestro`.`montopresupuesto` AS `Monto_del_Presupuesto`,`vtiger_suscripcion`.`valorcuota` AS `Valor_Cuota`,`vtiger_suscripcion`.`diaspago` AS `Dias_de_Pago`,`vtiger_suscripcion`.`nrocuotas` AS `Nro_Cuotas`,`vtiger_suscripcion`.`abono` AS `Valor_Abono`,`vtiger_suscripcion`.`fechavenabo` AS `Fecha_Ven_Abono`,`vtiger_suscripcion`.`fechacargopacabono` AS `Fecha_Cargo_Pac_Abono`,`vtiger_suscripcion`.`fechaabonofintocabono` AS `Fecha_Transfer_abono_Fintoc`,`vtiger_suscripcion`.`abonopagado` AS `Abono_pagado`,`vtiger_suscripcion`.`primeracuota` AS `Valor_Cuota_1`,`vtiger_suscripcion`.`fven1` AS `Fecha_Ven_Cuota_1`,`vtiger_suscripcion`.`fechacargopaccuota1` AS `Fecha_Cargo_Pac_Cuota_1`,`vtiger_suscripcion`.`fechaabonofintoccuota1` AS `Fecha_Transfer_Cuota_1_Fintoc`,`vtiger_suscripcion`.`1cuotapagada` AS `Cuota_1_Pagada`,`vtiger_suscripcion`.`segundacuota` AS `Valor_Cuota_2`,`vtiger_suscripcion`.`fven2` AS `Fecha_Ven_Cuota_2`,`vtiger_suscripcion`.`fechacargopaccuota2` AS `Fecha_Cargo_Pac_Cuota_2`,`vtiger_suscripcion`.`fechaabonofintoccuota2` AS `Fecha_Transfer_Cuota_2_Fintoc`,`vtiger_suscripcion`.`2cuotapagada` AS `Cuota_2_Pagada`,`vtiger_suscripcion`.`nrofactura` AS `Nro_Factura_Suscripcion`,`vtiger_suscripcion`.`ffactura` AS `Fecha_Factura_Suscripcion`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Nombre_Cliente`,`vtiger_suscripcion`.`valortotal` AS `Valor_plan`,`vtiger_cliente`.`clienteid` AS `Id_cliente`,`vtiger_cliente`.`estadopac` AS `estadopac` from ((`vtiger_suscripcion` join `vtiger_siniestro` on((`vtiger_siniestro`.`siniestroid` = `vtiger_suscripcion`.`siniestro`))) join `vtiger_cliente` on((`vtiger_suscripcion`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) where ((`vtiger_suscripcion`.`tpagoabono` = 'PAC') and (`vtiger_suscripcion`.`tpago1cuota` = 'PAC') and (`vtiger_suscripcion`.`tpago2cuota` = 'PAC')) */;
/*!50001 DROP VIEW IF EXISTS `Plantilla_driving`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `Plantilla_driving` AS select `Plantilla_simplirute`.`ID_De_Referencia` AS `Codigo_de_despacho`,`Plantilla_simplirute`.`direccionsiniestro` AS `Direccion_1`,`Plantilla_simplirute`.`Persona_De_Contacto` AS `Nombre_cliente`,`vtiger_siniestro`.`comunacaso` AS `Comuna`,`Plantilla_simplirute`.`Latitud` AS `Latitud`,`Plantilla_simplirute`.`Longitud` AS `Longitud`,`Plantilla_simplirute`.`Telefono_De_Contacto` AS `Telefono_de_Contacto`,`Plantilla_simplirute`.`SMS` AS `Email_de_Contacto`,`vtiger_siniestro`.`siniestroid` AS `Codigo_de_direccion` from (`Plantilla_simplirute` join `vtiger_siniestro` on((`Plantilla_simplirute`.`ID_De_Referencia` = `vtiger_siniestro`.`siniestro`))) */;
/*!50001 DROP VIEW IF EXISTS `Plantilla_simplirute`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `Plantilla_simplirute` AS select concat(`vtiger_siniestro`.`siniestro`,' - ',`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Titulo`,`vtiger_siniestro`.`direccionsiniestro` AS `direccionsiniestro`,`vtiger_siniestro`.`latitud_sini` AS `Latitud`,`vtiger_siniestro`.`longitud_sini` AS `Longitud`,`vtiger_siniestro`.`siniestro` AS `ID_De_Referencia`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Persona_De_Contacto`,`vtiger_cliente`.`movil` AS `Telefono_De_Contacto`,`vtiger_cliente`.`email` AS `SMS`,`vtiger_siniestro`.`estado_` AS `Notas`,`vtiger_crmentity`.`createdtime` AS `createdtime` from ((`vtiger_siniestro` join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) join `vtiger_crmentity` on((`vtiger_cliente`.`clienteid` = `vtiger_crmentity`.`crmid`))) where ((`vtiger_siniestro`.`estado_` in ('Ingresado a CRM (CP)','Abierto (CP)','Preinspección a Reprogramar','Preinspección Programada','Liquidador Asignado','Visita a Reprogramar','Visita Programada','Pre-inspección / Inspección - Programada','Pre-inspección / Inspección - Reprogramar')) and (`vtiger_crmentity`.`createdtime` >= '2022-01-01')) */;
/*!50001 DROP VIEW IF EXISTS `PorFacturar_Honorarios`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `PorFacturar_Honorarios` AS select `vtiger_siniestro`.`siniestroid` AS `id`,`vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_siniestro`.`nombrecliente` AS `nombrecliente`,`vtiger_siniestro`.`estado_` AS `estado_`,`vtiger_siniestro`.`facturarinforme` AS `facturarinforme`,`vtiger_siniestro`.`informefacturado` AS `informefacturado`,`vtiger_siniestro`.`frecinfliq` AS `frecinfliq`,`vtiger_siniestro`.`nrofactura` AS `nrofactura`,`vtiger_siniestro`.`perdidaindemnizable` AS `perdidaindemnizable`,`vtiger_siniestro`.`valorfactura` AS `valorfactura`,`vtiger_crmentity`.`createdtime` AS `createdtime`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Nombre`,`vtiger_siniestro`.`id_fact_relBase_hono` AS `id_relbase`,`vtiger_cliente`.`cliente` AS `Rut` from ((`vtiger_siniestro` join `vtiger_crmentity` on((`vtiger_siniestro`.`siniestroid` = `vtiger_crmentity`.`crmid`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) where ((`vtiger_siniestro`.`estado_` in ('Informe liq para impugnar PR','Informe de liq Impugnado PR','Revision Resp. Imp. PR')) and (`vtiger_siniestro`.`informefacturado` = '0') and (`vtiger_siniestro`.`frecinfliq` > '2021-12-31') and (`vtiger_crmentity`.`deleted` = 0) and (`vtiger_siniestro`.`indemnizacion` > '270000') and ((isnull(`vtiger_siniestro`.`nrofactura`) = TRUE) or (`vtiger_siniestro`.`nrofactura` = ''))) */;
/*!50001 DROP VIEW IF EXISTS `PorFacturar_HonorariosALL`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `PorFacturar_HonorariosALL` AS select `vtiger_siniestro`.`siniestroid` AS `id`,`vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_siniestro`.`nombrecliente` AS `nombrecliente`,`vtiger_siniestro`.`estado_` AS `estado_`,`vtiger_siniestro`.`facturarinforme` AS `facturarinforme`,`vtiger_siniestro`.`informefacturado` AS `informefacturado`,`vtiger_siniestro`.`frecinfliq` AS `frecinfliq`,`vtiger_siniestro`.`nrofactura` AS `nrofactura`,`vtiger_siniestro`.`perdidaindemnizable` AS `perdidaindemnizable`,`vtiger_siniestro`.`valorfactura` AS `valorfactura`,`vtiger_crmentity`.`createdtime` AS `createdtime`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Nombre`,`vtiger_siniestro`.`id_fact_relBase_hono` AS `id_relbase`,`vtiger_cliente`.`cliente` AS `Rut` from ((`vtiger_siniestro` join `vtiger_crmentity` on((`vtiger_siniestro`.`siniestroid` = `vtiger_crmentity`.`crmid`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) where ((`vtiger_siniestro`.`estado_` in ('Informe liq para impugnar PR','Informe de liq Impugnado PR','Revision Resp. Imp. PR')) and (`vtiger_siniestro`.`informefacturado` = '0') and (`vtiger_siniestro`.`frecinfliq` > '2021-12-31') and (`vtiger_crmentity`.`deleted` = 0) and ((isnull(`vtiger_siniestro`.`nrofactura`) = TRUE) or (`vtiger_siniestro`.`nrofactura` = ''))) */;
/*!50001 DROP VIEW IF EXISTS `PorFacturar_Honorarios_Adendum`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `PorFacturar_Honorarios_Adendum` AS select `vtiger_siniestro`.`siniestroid` AS `id`,`vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_siniestro`.`nombrecliente` AS `nombrecliente`,`vtiger_siniestro`.`estado_` AS `estado_`,`vtiger_siniestro`.`facturarinforme` AS `facturarinforme`,`vtiger_siniestro`.`informefacturado` AS `informefacturado`,`vtiger_siniestro`.`frecinfliq` AS `frecinfliq`,`vtiger_siniestro`.`nrofacturaaddedum1` AS `nrofactura`,`vtiger_siniestro`.`perdidaindemnizable` AS `perdidaindemnizable`,`vtiger_siniestro`.`valorfactura` AS `valorfactura`,`vtiger_crmentity`.`createdtime` AS `createdtime`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Nombre`,`vtiger_siniestro`.`id_fact_relbase_hono_adendum` AS `id_relbase`,`vtiger_cliente`.`cliente` AS `Rut`,`vtiger_siniestro`.`montoaddendum1` AS `montoaddendum1`,`vtiger_siniestro`.`indemaddendum1` AS `indemaddendum1`,`vtiger_siniestro`.`montofacturaaddendum1` AS `montofacturaaddendum1`,`vtiger_siniestro`.`facturaraddendum1` AS `facturaraddendum1`,`vtiger_siniestro`.`facturaraddendum2` AS `facturaraddendum2` from ((`vtiger_siniestro` join `vtiger_crmentity` on((`vtiger_siniestro`.`siniestroid` = `vtiger_crmentity`.`crmid`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) where ((`vtiger_siniestro`.`nrofacturaaddedum1` = 0) and (`vtiger_siniestro`.`montoaddendum1` > '0') and (`vtiger_siniestro`.`montofacturaaddendum1` > '0') and (`vtiger_siniestro`.`facturaraddendum1` = '1') and (`vtiger_siniestro`.`addendum1facturado` = '0') and (`vtiger_crmentity`.`deleted` = 0)) */;
/*!50001 DROP VIEW IF EXISTS `PorFacturar_VentaDemanda`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `PorFacturar_VentaDemanda` AS select `vtiger_ventadedemandas`.`ventadedemandasid` AS `id_Demanda`,`vtiger_suscripciondemanda`.`suscripciondemandaid` AS `id_Suscripcion`,`vtiger_siniestro`.`siniestro` AS `N_Caso`,`vtiger_ventadedemandas`.`rutcliente` AS `Rut`,concat(`vtiger_cliente`.`nombre`,`vtiger_cliente`.`apellido`) AS `Nombre`,`vtiger_ventadedemandas`.`estadocomercialdda` AS `Estado_de_Demanda`,`vtiger_ventadedemandas`.`contratofirmado` AS `Contrato_Firmado`,`vtiger_suscripciondemanda`.`valorplan` AS `Valor_Total`,`vtiger_suscripciondemanda`.`id_relbase` AS `id_RelBase`,`vtiger_suscripciondemanda`.`nrocuotas` AS `Nro_cuotas` from ((((`vtiger_ventadedemandas` join `vtiger_crmentity` on((`vtiger_ventadedemandas`.`ventadedemandasid` = `vtiger_crmentity`.`crmid`))) join `vtiger_cliente` on((`vtiger_ventadedemandas`.`clienteid` = `vtiger_cliente`.`clienteid`))) join `vtiger_siniestro` on((`vtiger_ventadedemandas`.`idsiniestro` = `vtiger_siniestro`.`siniestroid`))) join `vtiger_suscripciondemanda` on((`vtiger_ventadedemandas`.`ventadedemandasid` = `vtiger_suscripciondemanda`.`idventadedemanda`))) where ((`vtiger_ventadedemandas`.`estadocomercialdda` = 'Vendida') and ((`vtiger_ventadedemandas`.`contratofirmado` = '1') or (`vtiger_ventadedemandas`.`contratofirmado` = '0')) and (`vtiger_ventadedemandas`.`susddafacturada` = '0') and (`vtiger_crmentity`.`deleted` = 0) and (`vtiger_ventadedemandas`.`planaslegal` = 180000)) */;
/*!50001 DROP VIEW IF EXISTS `PorFacturarv2`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `PorFacturarv2` AS select `vtiger_suscripcion`.`suscripcionid` AS `id`,`vtiger_cliente`.`cliente` AS `Rut`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Nombre_cliente`,`vtiger_siniestro`.`siniestro` AS `Siniestro`,`vtiger_siniestro`.`estado_` AS `Estado`,`vtiger_suscripcion`.`valortotal` AS `Valor_total`,`vtiger_crmentity`.`createdtime` AS `Creacion_sus`,`vtiger_suscripcion`.`nrofactura` AS `N_factura`,`vtiger_suscripcion`.`ffactura` AS `Fecha_factura`,`vtiger_suscripcion`.`captador` AS `Captador`,`vtiger_suscripcion`.`contratofirmado` AS `Contrato_Firmado`,`vtiger_siniestro`.`id_fact_relBase_sus` AS `id_relbase`,`vtiger_siniestro`.`estado_factura_sii` AS `estado_factura_sii`,`vtiger_siniestro`.`siniestroid` AS `siniestroid`,`vtiger_suscripcion`.`montopresupuesto` AS `montopresupuesto`,`vtiger_suscripcion`.`nrocuotas` AS `Nrocuotas` from (((`vtiger_suscripcion` join `vtiger_crmentity` on((`vtiger_suscripcion`.`suscripcionid` = `vtiger_crmentity`.`crmid`))) join `vtiger_siniestro` on((`vtiger_suscripcion`.`siniestro` = `vtiger_siniestro`.`siniestroid`))) join `vtiger_cliente` on((`vtiger_suscripcion`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) where ((`vtiger_suscripcion`.`estado` is not null) and (`vtiger_crmentity`.`createdtime` > '2022-01-01 23:59:59') and (`vtiger_suscripcion`.`nrofactura` = 0) and (`vtiger_siniestro`.`estado_factura_sii` <> 'Aceptado') and (`vtiger_siniestro`.`estado_` not in ('Preinspección REprogramada','Abierto (CP)','Preinspección Programada','No Quiere Firmar','No aplica','Desistido','REPETIDO','Por Procesar','Retención','Denunciado (CRM - SOS)','Por Recuperar','Reencantar','Preinspección a Reprogramar','No Recuperado','Abierto (Prioridad Baja)','por desistir','Pre-inspección / Inspeccioón Programada','No Procesados 06-2024')) and (`vtiger_suscripcion`.`estado` <> '') and (`vtiger_crmentity`.`deleted` = 0)) */;
/*!50001 DROP VIEW IF EXISTS `Reclamos_cliente`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `Reclamos_cliente` AS select `vtiger_cliente`.`cliente` AS `Rut`,concat(`vtiger_cliente`.`nombre`,'',`vtiger_cliente`.`apellido`) AS `Nombre`,`vtiger_cliente`.`movil` AS `Telefono`,`vtiger_cliente`.`email` AS `Email` from `vtiger_cliente` */;
/*!50001 DROP VIEW IF EXISTS `RepClientes_Deuda_mas_actual`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `RepClientes_Deuda_mas_actual` AS select `Reporte_Clientes_monflow`.`Tipo_doc` AS `Tipo_doc`,`Reporte_Clientes_monflow`.`Num_documento` AS `Num_documento`,`Reporte_Clientes_monflow`.`Nombres` AS `Nombres`,`Reporte_Clientes_monflow`.`Apellidos` AS `Apellidos`,`Reporte_Clientes_monflow`.`Genero` AS `Genero`,`Reporte_Clientes_monflow`.`Fecha_de_Nacimiento` AS `Fecha_de_Nacimiento`,`Reporte_Clientes_monflow`.`Celular_1` AS `Celular_1`,`Reporte_Clientes_monflow`.`Celular_2` AS `Celular_2`,`Reporte_Clientes_monflow`.`Correo_1` AS `Correo_1`,`Reporte_Clientes_monflow`.`Correo_2` AS `Correo_2`,`Reporte_Clientes_monflow`.`ID_ext_cliente` AS `ID_ext_cliente`,`Reporte_Clientes_monflow`.`Indicador_Dia` AS `Indicador_Dia`,`Reporte_Clientes_monflow`.`Prop_Pago` AS `Prop_Pago`,`Reporte_Clientes_monflow`.`Canal_comunicacion_preferido` AS `Canal_comunicacion_preferido`,`Reporte_Clientes_monflow`.`Canal_de_pago_Preferido` AS `Canal_de_pago_Preferido`,`Reporte_Clientes_monflow`.`Estado` AS `Estado`,`Reporte_Clientes_monflow`.`Variable_1` AS `Variable_1`,`Reporte_Clientes_monflow`.`Variable_2` AS `Variable_2`,`Reporte_Clientes_monflow`.`Variable_3` AS `Variable_3`,`Reporte_Clientes_monflow`.`Variable_4` AS `Variable_4`,`Reporte_Clientes_monflow`.`Variable_5` AS `Variable_5`,`Reporte_Clientes_monflow`.`Variable_6` AS `Variable_6`,`Reporte_Clientes_monflow`.`Variable_7` AS `Variable_7`,`Reporte_Clientes_monflow`.`Variable_8` AS `Variable_8`,`Reporte_Clientes_monflow`.`Variable_9` AS `Variable_9`,`Reporte_Clientes_monflow`.`Variable_10` AS `Variable_10`,`Reporte_Clientes_monflow`.`Asesor_Id` AS `Asesor_Id`,`Reporte_Clientes_monflow`.`Referencia_1_nombre` AS `Referencia_1_nombre`,`Reporte_Clientes_monflow`.`Referencia_1_apellido` AS `Referencia_1_apellido`,`Reporte_Clientes_monflow`.`Referencia_1_telefono` AS `Referencia_1_telefono`,`Reporte_Clientes_monflow`.`Referencia_1_correo_electronico` AS `Referencia_1_correo_electronico`,`Reporte_Clientes_monflow`.`Referencia_2_nombre` AS `Referencia_2_nombre`,`Reporte_Clientes_monflow`.`Referencia_2_apellido` AS `Referencia_2_apellido`,`Reporte_Clientes_monflow`.`Referencia_2_telefono` AS `Referencia_2_telefono`,`Reporte_Clientes_monflow`.`Referencia_2_correo_electronico` AS `Referencia_2_correo_electronico`,`Reporte_Clientes_monflow`.`Garante_1_nombre` AS `Garante_1_nombre`,`Reporte_Clientes_monflow`.`Garante_1_apellido` AS `Garante_1_apellido`,`Reporte_Clientes_monflow`.`Garante_1_telefono` AS `Garante_1_telefono`,`Reporte_Clientes_monflow`.`Garante_1_correo_electronico` AS `Garante_1_correo_electronico`,`Reporte_Clientes_monflow`.`Garante_2_nombre` AS `Garante_2_nombre`,`Reporte_Clientes_monflow`.`Garante_2_apellido` AS `Garante_2_apellido`,`Reporte_Clientes_monflow`.`Garante_2_telefono` AS `Garante_2_telefono`,`Reporte_Clientes_monflow`.`Garante_2_correo_electronico` AS `Garante_2_correo_electronico`,`Reporte_Clientes_monflow`.`Deleted` AS `Deleted`,`Reporte_Clientes_monflow`.`Celular_1_codigo_pais` AS `Celular_1_codigo_pais`,`Reporte_Clientes_monflow`.`Celular_2_codigo_pais` AS `Celular_2_codigo_pais`,`Reporte_Clientes_monflow`.`Referencia_1_telefono_codigo_pais` AS `Referencia_1_telefono_codigo_pais`,`Reporte_Clientes_monflow`.`Referencia_2_telefono_codigo_pais` AS `Referencia_2_telefono_codigo_pais`,`Reporte_Clientes_monflow`.`Garante_1_telefono_codigo_pais` AS `Garante_1_telefono_codigo_pais`,`Reporte_Clientes_monflow`.`Garante_2_telefono_codigo_pais` AS `Garante_2_telefono_codigo_pais`,`Vista_Max_Dias_Atraso_Min_Fecha`.`Monto_OP` AS `Monto_OP`,`Vista_Max_Dias_Atraso_Min_Fecha`.`Dias_de_atraso` AS `Dias_de_atraso`,`Vista_Max_Dias_Atraso_Min_Fecha`.`ID_ext_orden` AS `ID_ext_orden`,`vtiger_siniestro`.`estado_` AS `Estado para Variable 8` from ((`Reporte_Clientes_monflow` join `Vista_Max_Dias_Atraso_Min_Fecha` on((`Reporte_Clientes_monflow`.`Num_documento` = `Vista_Max_Dias_Atraso_Min_Fecha`.`Num_documento`))) join `vtiger_siniestro` on((`Vista_Max_Dias_Atraso_Min_Fecha`.`ID_ext_orden` = `vtiger_siniestro`.`siniestro`))) */;
/*!50001 DROP VIEW IF EXISTS `RepClientes_Suma_diasAtraso_sumaMonto`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `RepClientes_Suma_diasAtraso_sumaMonto` AS select `crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Tipo_doc` AS `Tipo_doc`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Num_documento` AS `Num_documento`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Nombres` AS `Nombres`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Apellidos` AS `Apellidos`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Genero` AS `Genero`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Fecha_de_Nacimiento` AS `Fecha_de_Nacimiento`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Celular_1` AS `Celular_1`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Celular_2` AS `Celular_2`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Correo_1` AS `Correo_1`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Correo_2` AS `Correo_2`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`ID_ext_cliente` AS `ID_ext_cliente`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Indicador_Dia` AS `Indicador_Dia`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Prop_Pago` AS `Prop_Pago`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Canal_comunicacion_preferido` AS `Canal_comunicacion_preferido`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Canal_de_pago_Preferido` AS `Canal_de_pago_Preferido`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Estado` AS `Estado`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Variable_1` AS `Variable_1`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Variable_2` AS `Variable_2`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Variable_3` AS `Variable_3`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Variable_4` AS `Variable_4`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Variable_5` AS `Variable_5`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Variable_6` AS `Variable_6`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Variable_7` AS `Variable_7`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Variable_8` AS `Variable_8`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Variable_9` AS `Variable_9`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Variable_10` AS `Variable_10`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Asesor_Id` AS `Asesor_Id`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Referencia_1_nombre` AS `Referencia_1_nombre`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Referencia_1_apellido` AS `Referencia_1_apellido`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Referencia_1_telefono` AS `Referencia_1_telefono`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Referencia_1_correo_electronico` AS `Referencia_1_correo_electronico`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Referencia_2_nombre` AS `Referencia_2_nombre`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Referencia_2_apellido` AS `Referencia_2_apellido`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Referencia_2_telefono` AS `Referencia_2_telefono`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Referencia_2_correo_electronico` AS `Referencia_2_correo_electronico`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Garante_1_nombre` AS `Garante_1_nombre`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Garante_1_apellido` AS `Garante_1_apellido`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Garante_1_telefono` AS `Garante_1_telefono`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Garante_1_correo_electronico` AS `Garante_1_correo_electronico`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Garante_2_nombre` AS `Garante_2_nombre`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Garante_2_apellido` AS `Garante_2_apellido`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Garante_2_telefono` AS `Garante_2_telefono`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Garante_2_correo_electronico` AS `Garante_2_correo_electronico`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Deleted` AS `Deleted`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Celular_1_codigo_pais` AS `Celular_1_codigo_pais`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Celular_2_codigo_pais` AS `Celular_2_codigo_pais`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Referencia_1_telefono_codigo_pais` AS `Referencia_1_telefono_codigo_pais`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Referencia_2_telefono_codigo_pais` AS `Referencia_2_telefono_codigo_pais`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Garante_1_telefono_codigo_pais` AS `Garante_1_telefono_codigo_pais`,`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Garante_2_telefono_codigo_pais` AS `Garante_2_telefono_codigo_pais`,`Vista_Max_Dias_Atraso_Pendiente`.`Total_Monto_OP` AS `Total_Monto_OP`,`Vista_Max_Dias_Atraso_Pendiente`.`Total_Dias_de_atraso` AS `Total_Dias_de_atraso`,`Vista_Max_Dias_Atraso_Pendiente`.`ID_ext_orden` AS `ID_ext_orden`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`estado_` AS `Estado para Variable 8` from ((`crmcubic_crm_asesor`.`Reporte_Clientes_monflow` join `crmcubic_crm_asesor`.`Vista_Max_Dias_Atraso_Pendiente` on((`crmcubic_crm_asesor`.`Reporte_Clientes_monflow`.`Num_documento` = `Vista_Max_Dias_Atraso_Pendiente`.`Num_documento`))) join `crmcubic_crm_asesor`.`vtiger_siniestro` on((`Vista_Max_Dias_Atraso_Pendiente`.`ID_ext_orden` = `crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestro`))) */;
/*!50001 DROP VIEW IF EXISTS `SINFACTURAR`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `SINFACTURAR` AS select `vtiger_siniestro`.`siniestroid` AS `id`,`vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_cliente`.`cliente` AS `Rut`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Cliente`,`vtiger_siniestro`.`nombrecliente` AS `nombrecliente`,`vtiger_crmentity`.`createdtime` AS `createdtime`,`vtiger_siniestro`.`captador` AS `captador`,`vtiger_siniestro`.`estado_` AS `estado`,`vtiger_users`.`user_name` AS `user_name` from (((`vtiger_siniestro` join `vtiger_crmentity` on((`vtiger_siniestro`.`siniestroid` = `vtiger_crmentity`.`crmid`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) join `vtiger_users` on((`vtiger_crmentity`.`smownerid` = `vtiger_users`.`id`))) where ((`vtiger_crmentity`.`createdtime` > '2021 23:59:59') and (`vtiger_siniestro`.`captador` not in ('Marco Diaz','Valeria Gomez','Rodrigo Valenzuela')) and (`vtiger_siniestro`.`estado_` not in ('No aplica','Desistido','Cerrado sin pago','Cerrado','Sin Poliza','Cerrado (Sin Dctos)','Repetido','CERRADO SIN DAÑOS','Por Procesar','Gestión Abogado','Retención')) and (`vtiger_siniestro`.`contratofirmado2` = 0) and (`vtiger_crmentity`.`deleted` = 0)) order by `vtiger_siniestro`.`estado_` */;
/*!50001 DROP VIEW IF EXISTS `Toku_sus_fil_0`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `Toku_sus_fil_0` AS select `vtiger_siniestro`.`siniestroid` AS `siniestroid`,`vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_siniestro`.`estado_` AS `estado_`,`vtiger_suscripcion`.`suscripcionid` AS `suscripcionid`,`vtiger_suscripcion`.`valortotal` AS `valortotal`,`vtiger_suscripcion`.`nrocuotas` AS `nrocuotas`,`vtiger_suscripcion`.`nrofactura` AS `nrofactura`,`vtiger_cliente`.`cliente` AS `cliente`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `NOMBRE_CLI`,`vtiger_cliente`.`movil` AS `movil`,`vtiger_cliente`.`email` AS `email`,`vtiger_crmentity`.`createdtime` AS `createdtime`,`vtiger_suscripcion`.`abonopagado` AS `abonopagado`,`vtiger_suscripcion`.`fechavenabo` AS `fechavenabo`,`vtiger_suscripcion`.`1cuotapagada` AS `1cuotapagada`,`vtiger_suscripcion`.`fven1` AS `fven1`,`vtiger_suscripcion`.`2cuotapagada` AS `2cuotapagada`,`vtiger_suscripcion`.`fven2` AS `fven2` from (((`vtiger_cliente` join `vtiger_suscripcion` on((`vtiger_suscripcion`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) join `vtiger_siniestro` on((`vtiger_siniestro`.`siniestroid` = `vtiger_suscripcion`.`siniestro`))) join `vtiger_crmentity` on((`vtiger_siniestro`.`siniestroid` = `vtiger_crmentity`.`crmid`))) where ((`vtiger_crmentity`.`createdtime` >= date_format(curdate(),'%Y-%m-01')) and (`vtiger_siniestro`.`estado_` in ('Ingresado a CRM (CP)','Preinspección a Reprogramar','Preinspección Programada','Preinspección Realizada','Preinspección Revisada','En Progreso (SOS)','Retomar En Progreso','Liquidador Asignado (SOS)','Revisión Progreso','Gestionar En Progreso','En progreso','Liquidador Asignado','Visita a Reprogramar','Visita Programada','Visita Realizada','Esperando','Denunciado (CRM - SOS)','Ingresado CRM (SOS)','Preinspección Programada (SOS)','Preinspección Reprogramar (SOS)','Abierto (Prioridad Baja)','Preinforme PR','Preinforme Cobertura','Preinforme PR (Gestionado)','Preinforme Cobertura (Gestionado)','Informe liq para impugnar PR','Informe liq impugnado Cobertura','Informe de liq Impugnado PR','Inf. Liq. Impugnar Cobertura','Revisión respuesta impugnación PR','Revisión respuesta impugnación Cobertura','Addendum para Impugnar','Addendum Impugnado','Desistido (Cobrar Suscripción)')) and (`vtiger_suscripcion`.`nrofactura` <> 0) and (`vtiger_suscripcion`.`tpagoabono` <> 'PAC') and (`vtiger_suscripcion`.`nrocuotas` = 0) and (`vtiger_suscripcion`.`abonopagado` = 0)) */;
/*!50001 DROP VIEW IF EXISTS `TotalHonorarios`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `TotalHonorarios` AS select `vtiger_paymentsin`.`paymentsinid` AS `id`,`vtiger_paymentsin`.`paymentsin_status` AS `paymentsin_status`,`vtiger_paymentsin`.`nrofactura` AS `nrofactura`,`vtiger_paymentsin`.`cliente` AS `cliente`,`vtiger_paymentsin`.`indemnizacion` AS `indemnizacion`,`vtiger_paymentsin`.`valorfactura` AS `valorfactura`,`vtiger_crmentity`.`createdtime` AS `createdtime`,`vtiger_paymentsin`.`banco` AS `banco`,`vtiger_paymentsin`.`ffactura` AS `ffactura`,`vtiger_paymentsin`.`fvencimientofactura` AS `fvencimientofactura`,`vtiger_paymentsin`.`nrosiniestro` AS `nrosiniestro`,`vtiger_paymentsin`.`captador` AS `captador`,`vtiger_crmentity`.`smownerid` AS `assigned_user_id` from (`vtiger_paymentsin` join `vtiger_crmentity` on((`vtiger_paymentsin`.`paymentsinid` = `vtiger_crmentity`.`crmid`))) where ((`vtiger_crmentity`.`deleted` = 0) and (`vtiger_crmentity`.`createdtime` > '2019 23:59:59') and (`vtiger_paymentsin`.`paymentsin_status` not in ('Paid','Nota de Crédito'))) */;
/*!50001 DROP VIEW IF EXISTS `VentasDeDemandaPorProcesar`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `VentasDeDemandaPorProcesar` AS select `vtiger_ventadedemandas`.`ventadedemandasid` AS `id`,`vtiger_ventadedemandas`.`number` AS `number`,`vtiger_crmentity`.`createdtime` AS `createdtime`,`vtiger_crmentity`.`smownerid` AS `assigned_user_id`,`vtiger_ventadedemandas`.`idsiniestro` AS `idsiniestro`,`vtiger_ventadedemandas`.`clienteid` AS `clienteid`,`vtiger_ventadedemandas`.`fono` AS `fono` from (`vtiger_ventadedemandas` join `vtiger_crmentity` on((`vtiger_ventadedemandas`.`ventadedemandasid` = `vtiger_crmentity`.`crmid`))) where (`vtiger_crmentity`.`deleted` = 0) order by `vtiger_ventadedemandas`.`ventadedemandasid` desc */;
/*!50001 DROP VIEW IF EXISTS `Vista_Max_Dias_Atraso_Min_Fecha`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `Vista_Max_Dias_Atraso_Min_Fecha` AS select `r1`.`Tipo_doc` AS `Tipo_doc`,`r1`.`Num_documento` AS `Num_documento`,`r1`.`Producto` AS `Producto`,`r1`.`Codigo_de_pago` AS `Codigo_de_pago`,`r1`.`Cuota` AS `Cuota`,`r1`.`ID_ext_cliente` AS `ID_ext_cliente`,`r1`.`Moneda` AS `Moneda`,`r1`.`Monto_OP` AS `Monto_OP`,`r1`.`Cargos_Intereses_OP` AS `Cargos_Intereses_OP`,`r1`.`Monto_total` AS `Monto_total`,`r1`.`Fecha_vencimiento` AS `Fecha_vencimiento`,`r1`.`Dias_de_atraso` AS `Dias_de_atraso`,`r1`.`Estado` AS `Estado`,`r1`.`Fecha_de_emision` AS `Fecha_de_emision`,`r1`.`ID_ext_orden` AS `ID_ext_orden`,`r1`.`Estado_Caso` AS `Estado_Caso`,`r1`.`Captador` AS `Captador`,`r1`.`Nombre` AS `Nombre`,`r1`.`Email` AS `Email`,`r1`.`Telefono` AS `Telefono`,`r1`.`Comuna` AS `Comuna`,`r1`.`Contrato_Firmado` AS `Contrato_Firmado` from `Reporte_Ordenes_Pago` `r1` where ((`r1`.`Dias_de_atraso` = (select max(`r2`.`Dias_de_atraso`) from `Reporte_Ordenes_Pago` `r2` where (`r2`.`ID_ext_cliente` = `r1`.`ID_ext_cliente`))) and (`r1`.`Fecha_vencimiento` = (select min(`r3`.`Fecha_vencimiento`) from `Reporte_Ordenes_Pago` `r3` where ((`r3`.`ID_ext_cliente` = `r1`.`ID_ext_cliente`) and (`r3`.`Dias_de_atraso` = `r1`.`Dias_de_atraso`))))) */;
/*!50001 DROP VIEW IF EXISTS `Vista_Max_Dias_Atraso_Pendiente`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `Vista_Max_Dias_Atraso_Pendiente` AS select `r1`.`ID_ext_cliente` AS `ID_ext_cliente`,`r1`.`Num_documento` AS `Num_documento`,`r1`.`Tipo_doc` AS `Tipo_doc`,`r1`.`Producto` AS `Producto`,`r1`.`Codigo_de_pago` AS `Codigo_de_pago`,`r1`.`Cuota` AS `Cuota`,`r1`.`Moneda` AS `Moneda`,`r1`.`Total_Monto_OP` AS `Total_Monto_OP`,`r1`.`Total_Dias_de_atraso` AS `Total_Dias_de_atraso`,`r1`.`Min_Fecha_vencimiento` AS `Min_Fecha_vencimiento`,`r1`.`Estado` AS `Estado`,`r1`.`Max_Fecha_de_emision` AS `Max_Fecha_de_emision`,`r1`.`ID_ext_orden` AS `ID_ext_orden`,`r1`.`Estado_Caso` AS `Estado_Caso`,`r1`.`Captador` AS `Captador`,`r1`.`Nombre` AS `Nombre`,`r1`.`Email` AS `Email`,`r1`.`Telefono` AS `Telefono`,`r1`.`Comuna` AS `Comuna`,`r1`.`Contrato_Firmado` AS `Contrato_Firmado` from (select `crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`ID_ext_cliente` AS `ID_ext_cliente`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Num_documento` AS `Num_documento`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Tipo_doc` AS `Tipo_doc`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Producto` AS `Producto`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Codigo_de_pago` AS `Codigo_de_pago`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Cuota` AS `Cuota`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Moneda` AS `Moneda`,sum(`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Monto_OP`) AS `Total_Monto_OP`,sum(`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Dias_de_atraso`) AS `Total_Dias_de_atraso`,min(`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Fecha_vencimiento`) AS `Min_Fecha_vencimiento`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Estado` AS `Estado`,max(`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Fecha_de_emision`) AS `Max_Fecha_de_emision`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`ID_ext_orden` AS `ID_ext_orden`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Estado_Caso` AS `Estado_Caso`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Captador` AS `Captador`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Nombre` AS `Nombre`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Email` AS `Email`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Telefono` AS `Telefono`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Comuna` AS `Comuna`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Contrato_Firmado` AS `Contrato_Firmado` from `crmcubic_crm_asesor`.`Reporte_Ordenes_Pago` where (`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Estado` = 'Pendiente') group by `crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`ID_ext_cliente`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Num_documento`) `r1` where (`r1`.`Total_Dias_de_atraso` = (select max(`r2`.`Total_Dias_de_atraso`) from (select `crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`ID_ext_cliente` AS `ID_ext_cliente`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Num_documento` AS `Num_documento`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Tipo_doc` AS `Tipo_doc`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Producto` AS `Producto`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Codigo_de_pago` AS `Codigo_de_pago`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Cuota` AS `Cuota`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Moneda` AS `Moneda`,sum(`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Monto_OP`) AS `Total_Monto_OP`,sum(`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Dias_de_atraso`) AS `Total_Dias_de_atraso`,min(`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Fecha_vencimiento`) AS `Min_Fecha_vencimiento`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Estado` AS `Estado`,max(`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Fecha_de_emision`) AS `Max_Fecha_de_emision`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`ID_ext_orden` AS `ID_ext_orden`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Estado_Caso` AS `Estado_Caso`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Captador` AS `Captador`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Nombre` AS `Nombre`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Email` AS `Email`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Telefono` AS `Telefono`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Comuna` AS `Comuna`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Contrato_Firmado` AS `Contrato_Firmado` from `crmcubic_crm_asesor`.`Reporte_Ordenes_Pago` where (`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Estado` = 'Pendiente') group by `crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`ID_ext_cliente`,`crmcubic_crm_asesor`.`Reporte_Ordenes_Pago`.`Num_documento`) `r2` where (`r2`.`ID_ext_cliente` = `r1`.`ID_ext_cliente`))) */;
/*!50001 DROP VIEW IF EXISTS `abono`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `abono` AS select `vtiger_suscripcion`.`suscripcionid` AS `id`,`vtiger_suscripcion`.`number` AS `number`,`vtiger_suscripcion`.`siniestro` AS `siniestro`,`vtiger_suscripcion`.`nombrecliente` AS `nombrecliente`,`vtiger_crmentity`.`smownerid` AS `assigned_user_id`,`vtiger_crmentity`.`createdtime` AS `createdtime`,`vtiger_suscripcion`.`abono` AS `abono`,`vtiger_suscripcion`.`notacredito` AS `notacredito`,`vtiger_suscripcion`.`fechavenabo` AS `fechavenabo`,`vtiger_suscripcion`.`fven1` AS `fven1`,`vtiger_suscripcion`.`fven2` AS `fven2` from (`vtiger_suscripcion` join `vtiger_crmentity` on((`vtiger_suscripcion`.`suscripcionid` = `vtiger_crmentity`.`crmid`))) where ((`vtiger_crmentity`.`deleted` = 0) and (`vtiger_crmentity`.`createdtime` between '2019-05-01 00:00:00' and '2021-12-31 23:59:59') and (`vtiger_suscripcion`.`abonopagado` = 0) and (`vtiger_suscripcion`.`fechavenabo` < curdate()) and (`vtiger_suscripcion`.`fven1` > curdate()) and (`vtiger_suscripcion`.`fven2` > curdate()) and (`vtiger_suscripcion`.`notacredito` = 0) and (`vtiger_suscripcion`.`estado` not in ('NO aplica','Desistido','Por Procesar','Retención'))) */;
/*!50001 DROP VIEW IF EXISTS `abono1cuota`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `abono1cuota` AS select `vtiger_suscripcion`.`suscripcionid` AS `id`,`vtiger_suscripcion`.`number` AS `number`,`vtiger_siniestro`.`siniestro` AS `Siniestro`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Nombre Cliente`,concat(`vtiger_users`.`first_name`,' ',`vtiger_users`.`last_name`) AS `Asignado`,`vtiger_crmentity`.`createdtime` AS `createdtime`,`vtiger_suscripcion`.`abono` AS `abono`,`vtiger_suscripcion`.`notacredito` AS `notacredito`,`vtiger_suscripcion`.`fechavenabo` AS `fechavenabo`,`vtiger_suscripcion`.`fven1` AS `fven1`,`vtiger_suscripcion`.`fven2` AS `fven2`,`vtiger_suscripcion`.`primeracuota` AS `primeracuota` from ((((`vtiger_suscripcion` join `vtiger_crmentity` on((`vtiger_suscripcion`.`suscripcionid` = `vtiger_crmentity`.`crmid`))) join `vtiger_cliente` on((`vtiger_suscripcion`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) join `vtiger_users` on((`vtiger_crmentity`.`smownerid` = `vtiger_users`.`id`))) join `vtiger_siniestro` on((`vtiger_siniestro`.`siniestroid` = `vtiger_suscripcion`.`siniestro`))) where ((`vtiger_crmentity`.`createdtime` between '2019-05-01 00:00:00' and '2021-12-31 23:59:59') and (`vtiger_suscripcion`.`notacredito` = 0) and (`vtiger_suscripcion`.`fechavenabo` < curdate()) and (`vtiger_suscripcion`.`fven1` < curdate()) and ((`vtiger_suscripcion`.`fven2` > curdate()) or isnull(`vtiger_suscripcion`.`fven2`) or (`vtiger_suscripcion`.`fven2` = '')) and (`vtiger_suscripcion`.`abonopagado` = 0) and (`vtiger_suscripcion`.`nrofactura` <> 0) and (`vtiger_suscripcion`.`nrofactura` is not null) and (`vtiger_suscripcion`.`1cuotapagada` = 0) and (`vtiger_suscripcion`.`valorcuota` <> 0) and (`vtiger_suscripcion`.`estado` not in ('No aplica','Desistido','Por procesar','Retención')) and (`vtiger_crmentity`.`deleted` = 0)) */;
/*!50001 DROP VIEW IF EXISTS `abono2`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `abono2` AS select `abono`.`id` AS `id`,`abono`.`number` AS `number`,`vtiger_siniestro`.`siniestro` AS `siniestro`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Cliente`,concat(`vtiger_users`.`first_name`,' ',`vtiger_users`.`last_name`) AS `Asignado`,`abono`.`createdtime` AS `createdtime`,`abono`.`abono` AS `abono`,`abono`.`notacredito` AS `notacredito`,`abono`.`fechavenabo` AS `fechavenabo`,`abono`.`fven1` AS `fven1`,`abono`.`fven2` AS `fven2` from (((`vtiger_siniestro` join `abono` on((`abono`.`siniestro` = `vtiger_siniestro`.`siniestroid`))) join `vtiger_cliente` on((`abono`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) join `vtiger_users` on((`abono`.`assigned_user_id` = `vtiger_users`.`id`))) */;
/*!50001 DROP VIEW IF EXISTS `audigen`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_crm_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `audigen` AS select `ClayCrm`.`id` AS `id`,`ClayCrm`.`Modulo` AS `Modulo`,`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`ClayCrm`.`Mes_Año` AS `Mes_Año`,`ClayCrm`.`Codigo_SII` AS `Codigo_SII`,`ClayCrm`.`Tipo` AS `Tipo`,`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Nro_caso` AS `Nro_caso`,`ClayCrm`.`1er_Item` AS `1er_Item`,`ClayCrm`.`Razon_Social_Emisor` AS `Razon_Social_Emisor`,`ClayCrm`.`RUT_Emisor` AS `RUT_Emisor`,`ClayCrm`.`Direccion_Emisor` AS `Direccion_Emisor`,`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,`ClayCrm`.`RUT_Receptor` AS `RUT_Receptor`,`ClayCrm`.`Direccion_Receptor` AS `Direccion_Receptor`,`ClayCrm`.`Exento` AS `Exento`,`ClayCrm`.`Neto` AS `Neto`,`ClayCrm`.`Total_Neto` AS `Total_Neto`,`ClayCrm`.`IVA` AS `IVA`,`ClayCrm`.`Otros_Impuestos` AS `Otros_Impuestos`,`ClayCrm`.`Total` AS `Total`,`ClayCrm`.`Saldo` AS `Saldo`,`ClayCrm`.`Pagado` AS `Pagado`,`ClayCrm`.`Contabilizado` AS `Contabilizado`,`ClayCrm`.`Rechazado` AS `Rechazado`,`ClayCrm`.`Monto_Incobrable` AS `Monto_Incobrable`,`ClayCrm`.`Vendedor` AS `Vendedor`,`ClayCrm`.`Email` AS `Email`,`ClayCrm`.`Telefono` AS `Telefono`,`ClayCrm`.`Telefono2` AS `Telefono2`,`ClayCrm`.`Suscripcion_SUS` AS `Suscripcion_SUS`,`ClayCrm`.`Caso_Siniestro_SUS` AS `Caso_Siniestro_SUS`,`ClayCrm`.`Estado_Caso_Siniestro_SUS` AS `Estado_Caso_Siniestro_SUS`,`ClayCrm`.`Fecha_suscripcion_SUS` AS `Fecha_suscripcion_SUS`,`ClayCrm`.`Captador_SUS` AS `Captador_SUS`,`ClayCrm`.`Monto_SUS` AS `Monto_SUS`,`ClayCrm`.`Saldo_CRM_SUS` AS `Saldo_CRM_SUS`,`ClayCrm`.`Estado_Factura_SUS` AS `Estado_Factura_SUS`,`ClayCrm`.`Nro_Factura_SUS` AS `Nro_Factura_SUS`,`ClayCrm`.`Fecha_Factura_SUS` AS `Fecha_Factura_SUS`,`ClayCrm`.`Nota_Credito_SUS` AS `Nota_Credito_SUS`,`ClayCrm`.`Pagada_NC_SUS` AS `Pagada_NC_SUS`,`ClayCrm`.`Nro_Nota_Credito_SUS` AS `Nro_Nota_Credito_SUS`,`ClayCrm`.`Rut_Cliente_SUS` AS `Rut_Cliente_SUS`,`ClayCrm`.`Suscripcion_DDA` AS `Suscripcion_DDA`,`ClayCrm`.`Caso_Siniestro_DDA` AS `Caso_Siniestro_DDA`,`ClayCrm`.`Estado_Caso_Siniestro_DDA` AS `Estado_Caso_Siniestro_DDA`,`ClayCrm`.`Estado_Demanda_DDA` AS `Estado_Demanda_DDA`,`ClayCrm`.`Fecha_suscripcion_DDA` AS `Fecha_suscripcion_DDA`,`ClayCrm`.`Captador_DDA` AS `Captador_DDA`,`ClayCrm`.`Monto_DDA` AS `Monto_DDA`,`ClayCrm`.`Saldo_CRM_DDA` AS `Saldo_CRM_DDA`,`ClayCrm`.`Nro_Factura_DDA` AS `Nro_Factura_DDA`,`ClayCrm`.`Estado_Factura_DDA` AS `Estado_Factura_DDA`,`ClayCrm`.`Rut_Cliente_DDA` AS `Rut_Cliente_DDA`,`ClayCrm`.`Cobranza_COB` AS `Cobranza_COB`,`ClayCrm`.`Caso_Siniestro_COB` AS `Caso_Siniestro_COB`,`ClayCrm`.`Estado_Caso_Siniestro_COB` AS `Estado_Caso_Siniestro_COB`,`ClayCrm`.`Nro_Factura_COB` AS `Nro_Factura_COB`,`ClayCrm`.`Monto_Factura_COB` AS `Monto_Factura_COB`,`ClayCrm`.`Fecha_Factura_COB` AS `Fecha_Factura_COB`,`ClayCrm`.`Estado_Cobranza_COB` AS `Estado_Cobranza_COB`,`ClayCrm`.`Rut_Cliente_COB` AS `Rut_Cliente_COB`,if(((`ClayCrm`.`RUT_Receptor` = `ClayCrm`.`Rut_Cliente_SUS`) or (`ClayCrm`.`RUT_Receptor` = `ClayCrm`.`Rut_Cliente_DDA`) or (`ClayCrm`.`RUT_Receptor` = `ClayCrm`.`Rut_Cliente_COB`)),'OK','REV') AS `Valida_RUT_OK`,`ClayCrm`.`Valida_Monto_OK` AS `Valida_Monto_OK`,`ClayCrm`.`Valida_Fecha_OK` AS `Valida_Fecha_OK`,if((`ClayCrm`.`Saldo` = `ClayCrm`.`Saldo_CRM_SUS`),'OK','NO') AS `OK_SALDO_SUS`,if((`ClayCrm`.`Saldo` = `ClayCrm`.`Saldo_CRM_DDA`),'OK','NO') AS `OK_SALDO_SUS_DDA`,`ClayCrm`.`OK_SALDO_COBRA` AS `OK_SALDO_COBRA`,`ClayCrm`.`Valida_Estado_OK` AS `Valida_Estado_OK`,`ClayCrm`.`Valida_Existe_OK` AS `Valida_Existe_OK`,`ClayCrm`.`SUSCRIPCION_EX` AS `SUSCRIPCION_EX`,`ClayCrm`.`SUSCRIPCION_DDA_EX` AS `SUSCRIPCION_DDA_EX`,`ClayCrm`.`COBRANZA_EX` AS `COBRANZA_EX` from `ClayCrm` */;
/*!50001 DROP VIEW IF EXISTS `caso_simplirut_estado_mod`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `caso_simplirut_estado_mod` AS select `vtiger_siniestro`.`estado_` AS `estado_`,`vtiger_siniestro`.`siniestro` AS `siniestro`,`det_maestro_Simplirute`.`id_sr` AS `id_sr` from (((`maestro_SimpliRute` left join `vista_casos_clientes` on((`vista_casos_clientes`.`siniestro` = `maestro_SimpliRute`.`ID_de_referencia`))) join `vtiger_siniestro` on((`maestro_SimpliRute`.`ID_de_referencia` = `vtiger_siniestro`.`siniestro`))) join `det_maestro_Simplirute` on((`maestro_SimpliRute`.`id_m_sr` = `det_maestro_Simplirute`.`id_msr`))) where isnull(`vista_casos_clientes`.`siniestro`) */;
/*!50001 DROP VIEW IF EXISTS `com_ciu_relbase`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `com_ciu_relbase` AS select `comu_relBase`.`id` AS `id`,`comu_relBase`.`id_city` AS `id_city`,`comu_relBase`.`com` AS `com`,`ciu_relBase`.`cui` AS `cui` from (`ciu_relBase` join `comu_relBase` on((`ciu_relBase`.`id` = `comu_relBase`.`id_city`))) */;
/*!50001 DROP VIEW IF EXISTS `contratos_firmados_DC`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `contratos_firmados_DC` AS select `vtiger_demandacolectiva`.`demandacolectivaid` AS `id`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Nombre`,`vtiger_cliente`.`movil` AS `Telefono`,`vtiger_cliente`.`email` AS `Email`,`vtiger_demandacolectiva`.`contratofirmado` AS `Contrato_firmado` from ((`vtiger_demandacolectiva` join `vtiger_cliente` on((`vtiger_demandacolectiva`.`idcliente` = `vtiger_cliente`.`clienteid`))) join `vtiger_crmentity` on((`vtiger_demandacolectiva`.`demandacolectivaid` = `vtiger_crmentity`.`crmid`))) where (`vtiger_crmentity`.`deleted` = 0) */;
/*!50001 DROP VIEW IF EXISTS `contratosfirmados`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `contratosfirmados` AS select `vtiger_siniestro`.`siniestroid` AS `id`,`vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_cliente`.`cliente` AS `Rut`,concat(`vtiger_cliente`.`nombre`,`vtiger_cliente`.`apellido`) AS `Cliente`,`vtiger_siniestro`.`nombrecliente` AS `nombrecliente`,`vtiger_crmentity`.`createdtime` AS `createdtime`,`vtiger_siniestro`.`captador` AS `captador`,`vtiger_siniestro`.`estado_` AS `estado`,`vtiger_users`.`user_name` AS `user_name` from (((`vtiger_siniestro` join `vtiger_crmentity` on((`vtiger_siniestro`.`siniestroid` = `vtiger_crmentity`.`crmid`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) join `vtiger_users` on((`vtiger_users`.`id` = `vtiger_crmentity`.`smownerid`))) where ((`vtiger_crmentity`.`createdtime` > '2021 23:59:59') and (`vtiger_siniestro`.`captador` not in ('Marco Diaz','Valeria Gomez','Rodrigo Valenzuela')) and (`vtiger_siniestro`.`estado_` not in ('No aplica','Desistido','Cerrado sin pago','Cerrado','Sin Poliza','Cerrado (Sin Dctos)','Repetido','CERRADO SIN DAÑOS','Por Procesar','Gestión Abogado','Retención')) and (`vtiger_siniestro`.`contratofirmado2` = 1) and (`vtiger_crmentity`.`deleted` = 0) and (`vtiger_siniestro`.`estado_pf` = 1)) order by `vtiger_siniestro`.`estado_` */;
/*!50001 DROP VIEW IF EXISTS `contratosfirmados_vd`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `contratosfirmados_vd` AS select `vtiger_ventadedemandas`.`ventadedemandasid` AS `id`,`vtiger_ventadedemandas`.`idsiniestro` AS `idsiniestro`,`vtiger_ventadedemandas`.`estadocobranza` AS `estadocobranza`,`vtiger_ventadedemandas`.`estadocomercialdda` AS `estadocomercialdda`,`vtiger_ventadedemandas`.`montorecuperarclp` AS `montorecuperarclp`,`vtiger_ventadedemandas`.`porcentajeapagar` AS `porcentajeapagar`,`vtiger_ventadedemandas`.`fono` AS `fono`,`vtiger_ventadedemandas`.`correo` AS `correo`,`vtiger_ventadedemandas`.`estadollamada` AS `estadollamada`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Nombre`,`vtiger_ventadedemandas`.`actualizar` AS `actualizar`,`vtiger_ventadedemandas`.`fechadenuncia` AS `fechadenuncia`,`vtiger_ventadedemandas`.`clienteid` AS `clienteid`,`vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_users`.`user_name` AS `user_name`,`vtiger_ventadedemandas`.`contratofirmado` AS `contratofirmado`,`vtiger_cliente`.`cliente` AS `Rut` from ((((`vtiger_ventadedemandas` join `vtiger_crmentity` on((`vtiger_ventadedemandas`.`ventadedemandasid` = `vtiger_crmentity`.`crmid`))) join `vtiger_cliente` on((`vtiger_ventadedemandas`.`clienteid` = `vtiger_cliente`.`clienteid`))) join `vtiger_siniestro` on((`vtiger_ventadedemandas`.`idsiniestro` = `vtiger_siniestro`.`siniestroid`))) join `vtiger_users` on((`vtiger_crmentity`.`smownerid` = `vtiger_users`.`id`))) where ((`vtiger_ventadedemandas`.`contratofirmado` = 1) and (`vtiger_crmentity`.`deleted` = 0) and (`vtiger_siniestro`.`creadaaslegal` = 1) and (`vtiger_ventadedemandas`.`planaslegal` = 180000)) order by `vtiger_ventadedemandas`.`ventadedemandasid` desc */;
/*!50001 DROP VIEW IF EXISTS `count_sus`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `count_sus` AS select `vtiger_cliente`.`clienteid` AS `clienteid`,(select count(`vtiger_suscripcion`.`nrofactura`) AS `sus` from (`vtiger_suscripcion` join `vtiger_siniestro` on((`vtiger_suscripcion`.`siniestro` = `vtiger_siniestro`.`siniestroid`))) where ((`vtiger_suscripcion`.`nombrecliente` = `vtiger_cliente`.`clienteid`) and (`vtiger_suscripcion`.`nrofactura` <> '') and (`vtiger_suscripcion`.`estado` not in ('Ingresado a CRM (CP)','Preinspección REprogramada','Abierto (CP)','Preinspección Programada','No Quiere Firmar','No aplica','Desistido','REPETIDO','Por Procesar','Retención','Denunciado (CRM - SOS)','Por Recuperar','Reencantar','Preinspección a Reprogramar','No Recuperado')) and (`vtiger_suscripcion`.`facturapagada` = 'No'))) AS `Count_sus`,`vtiger_cliente`.`cliente` AS `cliente` from `vtiger_cliente` */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_0-0-0`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_0-0-0` AS select `ClayCrm`.`id` AS `id`,`ClayCrm`.`Modulo` AS `Modulo`,`crmclay_router`.`ncaso` AS `ncaso`,`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`ClayCrm`.`Mes_Año` AS `Mes_Año`,`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,`ClayCrm`.`RUT_Receptor` AS `RUT_Receptor`,`ClayCrm`.`Exento` AS `Exento`,`ClayCrm`.`Saldo` AS `Saldo` from (`crmclay_router` join `ClayCrm` on((`crmclay_router`.`ncaso` = `ClayCrm`.`Nro_caso`))) where ((`crmclay_router`.`sus` = 0) and (`crmclay_router`.`co` = 0) and (`crmclay_router`.`dda` = 0)) */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_1_co`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_1_co` AS select `c`.`ncaso` AS `ncaso`,max((case when (`c`.`Modulo` = 'Cobranza') then `c`.`Razon_Social_Receptor` else NULL end)) AS `Razon_Social_Cobranza`,max((case when (`c`.`Modulo` = 'Cobranza') then replace(`c`.`RUT_Receptor`,'.','') else NULL end)) AS `RUT_Cobranza`,max((case when (`c`.`Modulo` = 'Cobranza') then `c`.`Num_Factura` else NULL end)) AS `Nro_factura_Cobranza`,max((case when (`c`.`Modulo` = 'Cobranza') then `c`.`Exento` else 0 end)) AS `Exento_Cobranza`,max((case when (`c`.`Modulo` = 'Cobranza') then `c`.`Saldo` else 0 end)) AS `Saldo_Cobranza`,max((case when (`c`.`Modulo` = 'Cobranza') then (`c`.`Exento` - `c`.`Saldo`) else 0 end)) AS `Abonado_Cobranza`,max(`c`.`Fecha_Emision`) AS `Fecha_Emision`,max(`c`.`Mes_Año`) AS `Mes_Año`,max(`c`.`Emitida_Recibida`) AS `Emitida_Recibida`,max(`c`.`movil`) AS `movil`,max(`c`.`movil_extra`) AS `movil_extra`,max(`c`.`email`) AS `email`,max(`c`.`dircliente`) AS `dircliente`,max(`c`.`comunacliente`) AS `comunacliente`,max(`c`.`ciudadcliente`) AS `ciudadcliente`,max(`c`.`estado_`) AS `estado_`,max(`c`.`banco`) AS `banco`,max(`c`.`ciaseguros`) AS `ciaseguros`,max(`c`.`montopresupuesto`) AS `montopresupuesto`,max(`c`.`fsismo`) AS `fsismo`,max(`c`.`tiposiniestro`) AS `tiposiniestro`,max(`c`.`tipopropiedad`) AS `tipopropiedad`,max(`c`.`ciudadcaso`) AS `ciudadcaso`,max(`c`.`comunacaso`) AS `comunacaso`,max(`c`.`direccionsiniestro`) AS `direccionsiniestro`,max(`c`.`mts2`) AS `mts2`,max(`c`.`ContratoFirmadoTexto`) AS `ContratoFirmadoTexto`,max(`c`.`MandatoFirmadoTexto`) AS `MandatoFirmadoTexto`,sum(`c`.`Saldo`) AS `Total_Saldo` from (select `crmcubic_crm_asesor`.`ClayCrm`.`id` AS `id`,`crmcubic_crm_asesor`.`crmclay_router`.`ncaso` AS `ncaso`,`crmcubic_crm_asesor`.`ClayCrm`.`Modulo` AS `Modulo`,`crmcubic_crm_asesor`.`ClayCrm`.`Num_Factura` AS `Num_Factura`,`crmcubic_crm_asesor`.`ClayCrm`.`Exento` AS `Exento`,`crmcubic_crm_asesor`.`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,`crmcubic_crm_asesor`.`ClayCrm`.`RUT_Receptor` AS `RUT_Receptor`,ifnull(`crmcubic_crm_asesor`.`ClayCrm`.`Saldo`,0) AS `Saldo`,`crmcubic_crm_asesor`.`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`crmcubic_crm_asesor`.`ClayCrm`.`Mes_Año` AS `Mes_Año`,`crmcubic_crm_asesor`.`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`crmcubic_crm_asesor`.`vtiger_cliente`.`movil` AS `movil`,`crmcubic_crm_asesor`.`vtiger_cliente`.`movil_extra` AS `movil_extra`,`crmcubic_crm_asesor`.`vtiger_cliente`.`email` AS `email`,`crmcubic_crm_asesor`.`vtiger_cliente`.`dircliente` AS `dircliente`,`crmcubic_crm_asesor`.`vtiger_cliente`.`comunacliente` AS `comunacliente`,`crmcubic_crm_asesor`.`vtiger_cliente`.`ciudadcliente` AS `ciudadcliente`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`estado_` AS `estado_`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`banco` AS `banco`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`ciaseguros` AS `ciaseguros`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`montopresupuesto` AS `montopresupuesto`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`fsismo` AS `fsismo`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`tiposiniestro` AS `tiposiniestro`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`tipopropiedad` AS `tipopropiedad`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`ciudadcaso` AS `ciudadcaso`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`comunacaso` AS `comunacaso`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`direccionsiniestro` AS `direccionsiniestro`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`mts2` AS `mts2`,(case `crmcubic_crm_asesor`.`vtiger_siniestro`.`contratofirmado` when 1 then 'Sí' else 'No' end) AS `ContratoFirmadoTexto`,(case `crmcubic_crm_asesor`.`vtiger_siniestro`.`mandatofirmado` when 1 then 'Sí' else 'No' end) AS `MandatoFirmadoTexto` from (((`crmcubic_crm_asesor`.`crmclay_router` join `crmcubic_crm_asesor`.`ClayCrm` on((`crmcubic_crm_asesor`.`crmclay_router`.`ncaso` = `crmcubic_crm_asesor`.`ClayCrm`.`Nro_caso`))) join `crmcubic_crm_asesor`.`vtiger_siniestro` on((`crmcubic_crm_asesor`.`ClayCrm`.`Nro_caso` = `crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestro`))) join `crmcubic_crm_asesor`.`vtiger_cliente` on((`crmcubic_crm_asesor`.`vtiger_siniestro`.`nombrecliente` = `crmcubic_crm_asesor`.`vtiger_cliente`.`clienteid`))) where ((`crmcubic_crm_asesor`.`crmclay_router`.`sus` = 0) and (`crmcubic_crm_asesor`.`crmclay_router`.`co` = 1) and (`crmcubic_crm_asesor`.`crmclay_router`.`dda` = 0))) `c` group by `c`.`ncaso` */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_1_dda`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_1_dda` AS select `c`.`ncaso` AS `ncaso`,max((case when (`c`.`Modulo` = 'Suscripción DDA') then `c`.`Razon_Social_Receptor` else NULL end)) AS `Razon_Social_Suscripcion_DDA`,max((case when (`c`.`Modulo` = 'Suscripción DDA') then replace(`c`.`RUT_Receptor`,'.','') else NULL end)) AS `RUT_Suscripcion_DDA`,max((case when (`c`.`Modulo` = 'Suscripción DDA') then `c`.`Num_Factura` else NULL end)) AS `Nro_factura_suscripcion_DDA`,max((case when (`c`.`Modulo` = 'Suscripción DDA') then `c`.`Exento` else 0 end)) AS `Exento_suscripcion_DDA`,max((case when (`c`.`Modulo` = 'Suscripción DDA') then `c`.`Saldo` else 0 end)) AS `Saldo_suscripcion_DDA`,max((case when (`c`.`Modulo` = 'Suscripción DDA') then (`c`.`Exento` - `c`.`Saldo`) else 0 end)) AS `Abonado_suscripcion_DDA`,max((case when ((`c`.`Modulo` = 'Suscripción DDA') and (`c`.`contrato_firmado_SDDA` is not null)) then `c`.`contrato_firmado_SDDA` else NULL end)) AS `contrato_firmado_SDDA`,max(`c`.`Fecha_Emision`) AS `Fecha_Emision`,max(`c`.`Mes_Año`) AS `Mes_Año`,max(`c`.`Emitida_Recibida`) AS `Emitida_Recibida`,max(`c`.`movil`) AS `movil`,max(`c`.`movil_extra`) AS `movil_extra`,max(`c`.`email`) AS `email`,max(`c`.`dircliente`) AS `dircliente`,max(`c`.`comunacliente`) AS `comunacliente`,max(`c`.`ciudadcliente`) AS `ciudadcliente`,max(`c`.`estado_`) AS `estado_`,max(`c`.`banco`) AS `banco`,max(`c`.`ciaseguros`) AS `ciaseguros`,max(`c`.`montopresupuesto`) AS `montopresupuesto`,max(`c`.`fsismo`) AS `fsismo`,max(`c`.`tiposiniestro`) AS `tiposiniestro`,max(`c`.`tipopropiedad`) AS `tipopropiedad`,max(`c`.`ciudadcaso`) AS `ciudadcaso`,max(`c`.`comunacaso`) AS `comunacaso`,max(`c`.`direccionsiniestro`) AS `direccionsiniestro`,max(`c`.`mts2`) AS `mts2`,max(`c`.`ContratoFirmadoTexto`) AS `ContratoFirmadoTexto`,max(`c`.`MandatoFirmadoTexto`) AS `MandatoFirmadoTexto`,sum(`c`.`SaldoUnico`) AS `Total_Saldo` from (select distinct `crmcubic_crm_asesor`.`ClayCrm`.`id` AS `id`,`crmcubic_crm_asesor`.`crmclay_router`.`ncaso` AS `ncaso`,`crmcubic_crm_asesor`.`ClayCrm`.`Modulo` AS `Modulo`,`crmcubic_crm_asesor`.`ClayCrm`.`Num_Factura` AS `Num_Factura`,`crmcubic_crm_asesor`.`ClayCrm`.`Exento` AS `Exento`,`crmcubic_crm_asesor`.`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,`crmcubic_crm_asesor`.`ClayCrm`.`RUT_Receptor` AS `RUT_Receptor`,ifnull(`crmcubic_crm_asesor`.`ClayCrm`.`Saldo`,0) AS `Saldo`,`crmcubic_crm_asesor`.`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`crmcubic_crm_asesor`.`ClayCrm`.`Mes_Año` AS `Mes_Año`,`crmcubic_crm_asesor`.`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`crmcubic_crm_asesor`.`vtiger_cliente`.`movil` AS `movil`,`crmcubic_crm_asesor`.`vtiger_cliente`.`movil_extra` AS `movil_extra`,`crmcubic_crm_asesor`.`vtiger_cliente`.`email` AS `email`,`crmcubic_crm_asesor`.`vtiger_cliente`.`dircliente` AS `dircliente`,`crmcubic_crm_asesor`.`vtiger_cliente`.`comunacliente` AS `comunacliente`,`crmcubic_crm_asesor`.`vtiger_cliente`.`ciudadcliente` AS `ciudadcliente`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`estado_` AS `estado_`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`banco` AS `banco`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`ciaseguros` AS `ciaseguros`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`montopresupuesto` AS `montopresupuesto`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`fsismo` AS `fsismo`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`tiposiniestro` AS `tiposiniestro`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`tipopropiedad` AS `tipopropiedad`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`ciudadcaso` AS `ciudadcaso`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`comunacaso` AS `comunacaso`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`direccionsiniestro` AS `direccionsiniestro`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`mts2` AS `mts2`,(case `crmcubic_crm_asesor`.`vtiger_siniestro`.`contratofirmado` when 1 then 'Sí' else 'No' end) AS `ContratoFirmadoTexto`,(case `crmcubic_crm_asesor`.`vtiger_siniestro`.`mandatofirmado` when 1 then 'Sí' else 'No' end) AS `MandatoFirmadoTexto`,(case `crmcubic_crm_asesor`.`vtiger_ventadedemandas`.`contratofirmado` when 1 then 'Sí' when 0 then 'No' end) AS `contrato_firmado_SDDA`,ifnull(`crmcubic_crm_asesor`.`ClayCrm`.`Saldo`,0) AS `SaldoUnico` from ((((`crmcubic_crm_asesor`.`crmclay_router` join `crmcubic_crm_asesor`.`ClayCrm` on((`crmcubic_crm_asesor`.`crmclay_router`.`ncaso` = `crmcubic_crm_asesor`.`ClayCrm`.`Nro_caso`))) join `crmcubic_crm_asesor`.`vtiger_siniestro` on((`crmcubic_crm_asesor`.`ClayCrm`.`Nro_caso` = `crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestro`))) join `crmcubic_crm_asesor`.`vtiger_cliente` on((`crmcubic_crm_asesor`.`vtiger_siniestro`.`nombrecliente` = `crmcubic_crm_asesor`.`vtiger_cliente`.`clienteid`))) left join `crmcubic_crm_asesor`.`vtiger_ventadedemandas` on((`crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestroid` = `crmcubic_crm_asesor`.`vtiger_ventadedemandas`.`idsiniestro`))) where ((`crmcubic_crm_asesor`.`crmclay_router`.`sus` = 0) and (`crmcubic_crm_asesor`.`crmclay_router`.`co` = 0) and (`crmcubic_crm_asesor`.`crmclay_router`.`dda` = 1))) `c` group by `c`.`ncaso` */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_1_sus`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_1_sus` AS select `c`.`ncaso` AS `ncaso`,max((case when (`c`.`Modulo` = 'Suscripción') then `c`.`Razon_Social_Receptor` else NULL end)) AS `Razon_Social_Suscripcion`,max((case when (`c`.`Modulo` = 'Suscripción') then replace(`c`.`RUT_Receptor`,'.','') else NULL end)) AS `RUT_Suscripcion`,max((case when (`c`.`Modulo` = 'Suscripción') then `c`.`Num_Factura` else NULL end)) AS `Nro_factura_suscripcion`,max((case when (`c`.`Modulo` = 'Suscripción') then `c`.`Exento` else 0 end)) AS `Exento_suscripcion`,max((case when (`c`.`Modulo` = 'Suscripción') then `c`.`Saldo` else 0 end)) AS `Saldo_suscripcion`,max((case when (`c`.`Modulo` = 'Suscripción') then (`c`.`Exento` - `c`.`Saldo`) else 0 end)) AS `Abonado_suscripcion`,max(`c`.`Fecha_Emision`) AS `Fecha_Emision`,max(`c`.`Mes_Año`) AS `Mes_Año`,max(`c`.`Emitida_Recibida`) AS `Emitida_Recibida`,max(`c`.`movil`) AS `movil`,max(`c`.`movil_extra`) AS `movil_extra`,max(`c`.`email`) AS `email`,max(`c`.`dircliente`) AS `dircliente`,max(`c`.`comunacliente`) AS `comunacliente`,max(`c`.`ciudadcliente`) AS `ciudadcliente`,max(`c`.`estado_`) AS `estado_`,max(`c`.`banco`) AS `banco`,max(`c`.`ciaseguros`) AS `ciaseguros`,max(`c`.`montopresupuesto`) AS `montopresupuesto`,max(`c`.`fsismo`) AS `fsismo`,max(`c`.`tiposiniestro`) AS `tiposiniestro`,max(`c`.`tipopropiedad`) AS `tipopropiedad`,max(`c`.`ciudadcaso`) AS `ciudadcaso`,max(`c`.`comunacaso`) AS `comunacaso`,max(`c`.`direccionsiniestro`) AS `direccionsiniestro`,max(`c`.`mts2`) AS `mts2`,max(`c`.`ContratoFirmadoTexto`) AS `ContratoFirmadoTexto`,max(`c`.`MandatoFirmadoTexto`) AS `MandatoFirmadoTexto`,sum(`c`.`Saldo`) AS `Total_Saldo` from (select `crmcubic_crm_asesor`.`ClayCrm`.`id` AS `id`,`crmcubic_crm_asesor`.`crmclay_router`.`ncaso` AS `ncaso`,`crmcubic_crm_asesor`.`ClayCrm`.`Modulo` AS `Modulo`,`crmcubic_crm_asesor`.`ClayCrm`.`Num_Factura` AS `Num_Factura`,`crmcubic_crm_asesor`.`ClayCrm`.`Exento` AS `Exento`,`crmcubic_crm_asesor`.`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,`crmcubic_crm_asesor`.`ClayCrm`.`RUT_Receptor` AS `RUT_Receptor`,ifnull(`crmcubic_crm_asesor`.`ClayCrm`.`Saldo`,0) AS `Saldo`,`crmcubic_crm_asesor`.`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`crmcubic_crm_asesor`.`ClayCrm`.`Mes_Año` AS `Mes_Año`,`crmcubic_crm_asesor`.`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`crmcubic_crm_asesor`.`vtiger_cliente`.`movil` AS `movil`,`crmcubic_crm_asesor`.`vtiger_cliente`.`movil_extra` AS `movil_extra`,`crmcubic_crm_asesor`.`vtiger_cliente`.`email` AS `email`,`crmcubic_crm_asesor`.`vtiger_cliente`.`dircliente` AS `dircliente`,`crmcubic_crm_asesor`.`vtiger_cliente`.`comunacliente` AS `comunacliente`,`crmcubic_crm_asesor`.`vtiger_cliente`.`ciudadcliente` AS `ciudadcliente`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`estado_` AS `estado_`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`banco` AS `banco`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`ciaseguros` AS `ciaseguros`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`montopresupuesto` AS `montopresupuesto`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`fsismo` AS `fsismo`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`tiposiniestro` AS `tiposiniestro`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`tipopropiedad` AS `tipopropiedad`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`ciudadcaso` AS `ciudadcaso`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`comunacaso` AS `comunacaso`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`direccionsiniestro` AS `direccionsiniestro`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`mts2` AS `mts2`,(case `crmcubic_crm_asesor`.`vtiger_siniestro`.`contratofirmado` when 1 then 'Sí' else 'No' end) AS `ContratoFirmadoTexto`,(case `crmcubic_crm_asesor`.`vtiger_siniestro`.`mandatofirmado` when 1 then 'Sí' else 'No' end) AS `MandatoFirmadoTexto` from (((`crmcubic_crm_asesor`.`crmclay_router` join `crmcubic_crm_asesor`.`ClayCrm` on((`crmcubic_crm_asesor`.`crmclay_router`.`ncaso` = `crmcubic_crm_asesor`.`ClayCrm`.`Nro_caso`))) join `crmcubic_crm_asesor`.`vtiger_siniestro` on((`crmcubic_crm_asesor`.`ClayCrm`.`Nro_caso` = `crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestro`))) join `crmcubic_crm_asesor`.`vtiger_cliente` on((`crmcubic_crm_asesor`.`vtiger_siniestro`.`nombrecliente` = `crmcubic_crm_asesor`.`vtiger_cliente`.`clienteid`))) where ((`crmcubic_crm_asesor`.`crmclay_router`.`sus` = 1) and (`crmcubic_crm_asesor`.`crmclay_router`.`co` = 0) and (`crmcubic_crm_asesor`.`crmclay_router`.`dda` = 0))) `c` group by `c`.`ncaso` */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_1_sus_co`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_1_sus_co` AS select `c`.`ncaso` AS `ncaso`,max((case when (`c`.`Modulo` = 'Suscripción') then `c`.`Razon_Social_Receptor` else NULL end)) AS `Razon_Social_Suscripcion`,max((case when (`c`.`Modulo` = 'Suscripción') then replace(`c`.`RUT_Receptor`,'.','') else NULL end)) AS `RUT_Suscripcion`,max((case when (`c`.`Modulo` = 'Suscripción') then `c`.`Num_Factura` else NULL end)) AS `Nro_factura_suscripcion`,max((case when (`c`.`Modulo` = 'Suscripción') then `c`.`Exento` else 0 end)) AS `Exento_suscripcion`,max((case when (`c`.`Modulo` = 'Suscripción') then `c`.`Saldo` else 0 end)) AS `Saldo_suscripcion`,max((case when (`c`.`Modulo` = 'Suscripción') then (`c`.`Exento` - `c`.`Saldo`) else 0 end)) AS `Abonado_suscripcion`,max((case when (`c`.`Modulo` = 'Cobranza') then `c`.`Razon_Social_Receptor` else NULL end)) AS `Razon_Social_Cobranza`,max((case when (`c`.`Modulo` = 'Cobranza') then replace(`c`.`RUT_Receptor`,'.','') else NULL end)) AS `RUT_Cobranza`,max((case when (`c`.`Modulo` = 'Cobranza') then `c`.`Num_Factura` else NULL end)) AS `Nro_factura_cobranza`,max((case when (`c`.`Modulo` = 'Cobranza') then `c`.`Exento` else 0 end)) AS `Exento_cobranza`,max((case when (`c`.`Modulo` = 'Cobranza') then `c`.`Saldo` else 0 end)) AS `Saldo_cobranza`,max((case when (`c`.`Modulo` = 'Cobranza') then (`c`.`Exento` - `c`.`Saldo`) else 0 end)) AS `Abonado_cobranza`,(case when (max((case when (`c`.`Modulo` = 'Suscripción') then replace(`c`.`RUT_Receptor`,'.','') else NULL end)) = max((case when (`c`.`Modulo` = 'Cobranza') then replace(`c`.`RUT_Receptor`,'.','') else NULL end))) then 'RI' else 'RD' end) AS `Comparación_de_RUTs`,max(`c`.`Fecha_Emision`) AS `Fecha_Emision`,max(`c`.`Mes_Año`) AS `Mes_Año`,max(`c`.`Emitida_Recibida`) AS `Emitida_Recibida`,max(`c`.`movil`) AS `movil`,max(`c`.`movil_extra`) AS `movil_extra`,max(`c`.`email`) AS `email`,max(`c`.`dircliente`) AS `dircliente`,max(`c`.`comunacliente`) AS `comunacliente`,max(`c`.`ciudadcliente`) AS `ciudadcliente`,max(`c`.`estado_`) AS `estado_`,max(`c`.`banco`) AS `banco`,max(`c`.`ciaseguros`) AS `ciaseguros`,max(`c`.`montopresupuesto`) AS `montopresupuesto`,max(`c`.`fsismo`) AS `fsismo`,max(`c`.`tiposiniestro`) AS `tiposiniestro`,max(`c`.`tipopropiedad`) AS `tipopropiedad`,max(`c`.`ciudadcaso`) AS `ciudadcaso`,max(`c`.`comunacaso`) AS `comunacaso`,max(`c`.`direccionsiniestro`) AS `direccionsiniestro`,max(`c`.`mts2`) AS `mts2`,max(`c`.`ContratoFirmadoTexto`) AS `ContratoFirmadoTexto`,max(`c`.`MandatoFirmadoTexto`) AS `MandatoFirmadoTexto`,sum(`c`.`Saldo`) AS `Total_Saldo` from (select `crmcubic_crm_asesor`.`ClayCrm`.`id` AS `id`,`crmcubic_crm_asesor`.`crmclay_router`.`ncaso` AS `ncaso`,`crmcubic_crm_asesor`.`ClayCrm`.`Modulo` AS `Modulo`,`crmcubic_crm_asesor`.`ClayCrm`.`Num_Factura` AS `Num_Factura`,`crmcubic_crm_asesor`.`ClayCrm`.`Exento` AS `Exento`,`crmcubic_crm_asesor`.`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,`crmcubic_crm_asesor`.`ClayCrm`.`RUT_Receptor` AS `RUT_Receptor`,ifnull(`crmcubic_crm_asesor`.`ClayCrm`.`Saldo`,0) AS `Saldo`,`crmcubic_crm_asesor`.`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`crmcubic_crm_asesor`.`ClayCrm`.`Mes_Año` AS `Mes_Año`,`crmcubic_crm_asesor`.`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`crmcubic_crm_asesor`.`vtiger_cliente`.`movil` AS `movil`,`crmcubic_crm_asesor`.`vtiger_cliente`.`movil_extra` AS `movil_extra`,`crmcubic_crm_asesor`.`vtiger_cliente`.`email` AS `email`,`crmcubic_crm_asesor`.`vtiger_cliente`.`dircliente` AS `dircliente`,`crmcubic_crm_asesor`.`vtiger_cliente`.`comunacliente` AS `comunacliente`,`crmcubic_crm_asesor`.`vtiger_cliente`.`ciudadcliente` AS `ciudadcliente`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`estado_` AS `estado_`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`banco` AS `banco`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`ciaseguros` AS `ciaseguros`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`montopresupuesto` AS `montopresupuesto`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`fsismo` AS `fsismo`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`tiposiniestro` AS `tiposiniestro`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`tipopropiedad` AS `tipopropiedad`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`ciudadcaso` AS `ciudadcaso`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`comunacaso` AS `comunacaso`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`direccionsiniestro` AS `direccionsiniestro`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`mts2` AS `mts2`,(case `crmcubic_crm_asesor`.`vtiger_siniestro`.`contratofirmado` when 1 then 'Sí' else 'No' end) AS `ContratoFirmadoTexto`,(case `crmcubic_crm_asesor`.`vtiger_siniestro`.`mandatofirmado` when 1 then 'Sí' else 'No' end) AS `MandatoFirmadoTexto` from (((`crmcubic_crm_asesor`.`crmclay_router` join `crmcubic_crm_asesor`.`ClayCrm` on((`crmcubic_crm_asesor`.`crmclay_router`.`ncaso` = `crmcubic_crm_asesor`.`ClayCrm`.`Nro_caso`))) join `crmcubic_crm_asesor`.`vtiger_siniestro` on((`crmcubic_crm_asesor`.`ClayCrm`.`Nro_caso` = `crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestro`))) join `crmcubic_crm_asesor`.`vtiger_cliente` on((`crmcubic_crm_asesor`.`vtiger_siniestro`.`nombrecliente` = `crmcubic_crm_asesor`.`vtiger_cliente`.`clienteid`))) where ((`crmcubic_crm_asesor`.`crmclay_router`.`sus` = 1) and (`crmcubic_crm_asesor`.`crmclay_router`.`co` = 1) and (`crmcubic_crm_asesor`.`crmclay_router`.`dda` = 0))) `c` group by `c`.`ncaso` order by `Comparación_de_RUTs` */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_1_sus_dda`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_1_sus_dda` AS select `c`.`ncaso` AS `ncaso`,max((case when (`c`.`Modulo` = 'Suscripción DDA') then `c`.`Razon_Social_Receptor` else NULL end)) AS `Razon_Social_Suscripcion_DDA`,max((case when (`c`.`Modulo` = 'Suscripción DDA') then replace(`c`.`RUT_Receptor`,'.','') else NULL end)) AS `RUT_Suscripcion_DDA`,max((case when (`c`.`Modulo` = 'Suscripción DDA') then `c`.`Num_Factura` else NULL end)) AS `Nro_factura_suscripcion_DDA`,max((case when (`c`.`Modulo` = 'Suscripción DDA') then `c`.`Exento` else 0 end)) AS `Exento_suscripcion_DDA`,max((case when (`c`.`Modulo` = 'Suscripción DDA') then `c`.`Saldo` else 0 end)) AS `Saldo_suscripcion_DDA`,max((case when (`c`.`Modulo` = 'Suscripción DDA') then (`c`.`Exento` - `c`.`Saldo`) else 0 end)) AS `Abonado_suscripcion_DDA`,max((case when (`c`.`Modulo` = 'Suscripción') then `c`.`Razon_Social_Receptor` else NULL end)) AS `Razon_Social_Suscripción`,max((case when (`c`.`Modulo` = 'Suscripción') then replace(`c`.`RUT_Receptor`,'.','') else NULL end)) AS `RUT_Suscripción`,max((case when (`c`.`Modulo` = 'Suscripción') then `c`.`Num_Factura` else NULL end)) AS `Nro_factura_Suscripción`,max((case when (`c`.`Modulo` = 'Suscripción') then `c`.`Exento` else 0 end)) AS `Exento_Suscripción`,max((case when (`c`.`Modulo` = 'Suscripción') then `c`.`Saldo` else 0 end)) AS `Saldo_Suscripción`,max((case when (`c`.`Modulo` = 'Suscripción') then (`c`.`Exento` - `c`.`Saldo`) else 0 end)) AS `Abonado_Suscripción`,(case when (max((case when (`c`.`Modulo` = 'Suscripción DDA') then replace(`c`.`RUT_Receptor`,'.','') else NULL end)) = max((case when (`c`.`Modulo` = 'Suscripción') then replace(`c`.`RUT_Receptor`,'.','') else NULL end))) then 'RI' else 'RD' end) AS `Comparación_de_RUTs`,max((case when ((`c`.`Modulo` = 'Suscripción DDA') and (`c`.`contrato_firmado_SDDA` is not null)) then `c`.`contrato_firmado_SDDA` else NULL end)) AS `contrato_firmado_SDDA`,max(`c`.`Fecha_Emision`) AS `Fecha_Emision`,max(`c`.`Mes_Año`) AS `Mes_Año`,max(`c`.`Emitida_Recibida`) AS `Emitida_Recibida`,max(`c`.`movil`) AS `movil`,max(`c`.`movil_extra`) AS `movil_extra`,max(`c`.`email`) AS `email`,max(`c`.`dircliente`) AS `dircliente`,max(`c`.`comunacliente`) AS `comunacliente`,max(`c`.`ciudadcliente`) AS `ciudadcliente`,max(`c`.`estado_`) AS `estado_`,max(`c`.`banco`) AS `banco`,max(`c`.`ciaseguros`) AS `ciaseguros`,max(`c`.`montopresupuesto`) AS `montopresupuesto`,max(`c`.`fsismo`) AS `fsismo`,max(`c`.`tiposiniestro`) AS `tiposiniestro`,max(`c`.`tipopropiedad`) AS `tipopropiedad`,max(`c`.`ciudadcaso`) AS `ciudadcaso`,max(`c`.`comunacaso`) AS `comunacaso`,max(`c`.`direccionsiniestro`) AS `direccionsiniestro`,max(`c`.`mts2`) AS `mts2`,max(`c`.`ContratoFirmadoTexto`) AS `ContratoFirmadoTexto`,max(`c`.`MandatoFirmadoTexto`) AS `MandatoFirmadoTexto`,sum(`c`.`SaldoUnico`) AS `Total_Saldo` from (select distinct `crmcubic_crm_asesor`.`ClayCrm`.`id` AS `id`,`crmcubic_crm_asesor`.`crmclay_router`.`ncaso` AS `ncaso`,`crmcubic_crm_asesor`.`ClayCrm`.`Modulo` AS `Modulo`,`crmcubic_crm_asesor`.`ClayCrm`.`Num_Factura` AS `Num_Factura`,`crmcubic_crm_asesor`.`ClayCrm`.`Exento` AS `Exento`,`crmcubic_crm_asesor`.`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,`crmcubic_crm_asesor`.`ClayCrm`.`RUT_Receptor` AS `RUT_Receptor`,ifnull(`crmcubic_crm_asesor`.`ClayCrm`.`Saldo`,0) AS `Saldo`,`crmcubic_crm_asesor`.`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`crmcubic_crm_asesor`.`ClayCrm`.`Mes_Año` AS `Mes_Año`,`crmcubic_crm_asesor`.`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`crmcubic_crm_asesor`.`vtiger_cliente`.`movil` AS `movil`,`crmcubic_crm_asesor`.`vtiger_cliente`.`movil_extra` AS `movil_extra`,`crmcubic_crm_asesor`.`vtiger_cliente`.`email` AS `email`,`crmcubic_crm_asesor`.`vtiger_cliente`.`dircliente` AS `dircliente`,`crmcubic_crm_asesor`.`vtiger_cliente`.`comunacliente` AS `comunacliente`,`crmcubic_crm_asesor`.`vtiger_cliente`.`ciudadcliente` AS `ciudadcliente`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`estado_` AS `estado_`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`banco` AS `banco`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`ciaseguros` AS `ciaseguros`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`montopresupuesto` AS `montopresupuesto`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`fsismo` AS `fsismo`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`tiposiniestro` AS `tiposiniestro`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`tipopropiedad` AS `tipopropiedad`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`ciudadcaso` AS `ciudadcaso`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`comunacaso` AS `comunacaso`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`direccionsiniestro` AS `direccionsiniestro`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`mts2` AS `mts2`,(case `crmcubic_crm_asesor`.`vtiger_siniestro`.`contratofirmado` when 1 then 'Sí' else 'No' end) AS `ContratoFirmadoTexto`,(case `crmcubic_crm_asesor`.`vtiger_siniestro`.`mandatofirmado` when 1 then 'Sí' else 'No' end) AS `MandatoFirmadoTexto`,(case `crmcubic_crm_asesor`.`vtiger_ventadedemandas`.`contratofirmado` when 1 then 'Sí' when 0 then 'No' end) AS `contrato_firmado_SDDA`,ifnull(`crmcubic_crm_asesor`.`ClayCrm`.`Saldo`,0) AS `SaldoUnico` from ((((`crmcubic_crm_asesor`.`crmclay_router` join `crmcubic_crm_asesor`.`ClayCrm` on((`crmcubic_crm_asesor`.`crmclay_router`.`ncaso` = `crmcubic_crm_asesor`.`ClayCrm`.`Nro_caso`))) join `crmcubic_crm_asesor`.`vtiger_siniestro` on((`crmcubic_crm_asesor`.`ClayCrm`.`Nro_caso` = `crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestro`))) join `crmcubic_crm_asesor`.`vtiger_cliente` on((`crmcubic_crm_asesor`.`vtiger_siniestro`.`nombrecliente` = `crmcubic_crm_asesor`.`vtiger_cliente`.`clienteid`))) left join `crmcubic_crm_asesor`.`vtiger_ventadedemandas` on((`crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestroid` = `crmcubic_crm_asesor`.`vtiger_ventadedemandas`.`idsiniestro`))) where ((`crmcubic_crm_asesor`.`crmclay_router`.`sus` = 1) and (`crmcubic_crm_asesor`.`crmclay_router`.`co` = 0) and (`crmcubic_crm_asesor`.`crmclay_router`.`dda` = 1))) `c` group by `c`.`ncaso` order by `Comparación_de_RUTs` */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_Clientes_perdidos_monflow`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_Clientes_perdidos_monflow` AS select distinct replace(`crmcubic_crm_asesor`.`ClayCrm`.`RUT_Receptor`,'.','') AS `RUT_Receptor`,`crmcubic_crm_asesor`.`ClayCrm`.`Num_Factura` AS `Num_Factura`,`crmcubic_crm_asesor`.`ClayCrm`.`Nro_caso` AS `Nro_caso` from (`crmcubic_crm_asesor`.`ClayCrm` left join `crmcubic_crm_asesor`.`crmclay_rep20_Todos_lo_clientes` on((replace(`crmcubic_crm_asesor`.`ClayCrm`.`RUT_Receptor`,'.','') = `crmclay_rep20_Todos_lo_clientes`.`Num_documento`))) where isnull(`crmclay_rep20_Todos_lo_clientes`.`Num_documento`) */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_Clientes_perdidos_monflow_2`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_Clientes_perdidos_monflow_2` AS select 501 AS `Tipo_doc`,`crmcubic_crm_asesor`.`vtiger_cliente`.`cliente` AS `Num_documento`,`crmcubic_crm_asesor`.`vtiger_cliente`.`nombre` AS `Nombres`,`crmcubic_crm_asesor`.`vtiger_cliente`.`apellido` AS `Apellidos`,'O' AS `Género`,'24/06/1987' AS `Fecha_de_Nacimiento`,(case when (left(replace(`crmcubic_crm_asesor`.`vtiger_cliente`.`movil`,'+56',''),1) = '0') then substr(replace(`crmcubic_crm_asesor`.`vtiger_cliente`.`movil`,'+56',''),2) else replace(`crmcubic_crm_asesor`.`vtiger_cliente`.`movil`,'+56','') end) AS `Celular_1`,replace(replace(`crmcubic_crm_asesor`.`vtiger_cliente`.`movil_extra`,'+56',''),'0','') AS `Celular_2`,`crmcubic_crm_asesor`.`vtiger_cliente`.`email` AS `Correo_1`,`crmcubic_crm_asesor`.`vtiger_cliente`.`email` AS `Correo_2`,`crmcubic_crm_asesor`.`vtiger_cliente`.`cliente` AS `ID_ext_cliente`,0 AS `Indicador_al_día`,99 AS `Propensión_al_pago`,1 AS `Canal_comunicación_preferido`,1 AS `Canal_de_pago_Preferido`,1 AS `Estado`,'' AS `Variable_1`,'' AS `Variable_2`,'' AS `Variable_3`,'' AS `Variable_4`,'' AS `Variable_5`,'' AS `Variable_6`,'' AS `Variable_7`,'' AS `Variable_8`,'' AS `Variable_9`,'' AS `Variable_10`,'' AS `Asesor_ID`,'' AS `Referencia_1_nombre`,'' AS `Referencia_1_teléfono`,'' AS `Referencia_1_correo_electrónico`,'' AS `Referencia_2_nombre`,'' AS `Referencia_2_apellido`,'' AS `Referencia_2_teléfono`,'' AS `Referencia_2_correo_electrónico`,'' AS `Garante_1_nombre`,'' AS `Garante_1_apellido`,'' AS `Garante_1_teléfono`,'' AS `Garante_1_correo_electrónico`,'' AS `Garante_2_nombre`,'' AS `Garante_2_apellido`,'' AS `Garante_2_teléfono`,'' AS `Garante_2_correo_electrónico`,'' AS `Eliminación` from (`crmcubic_crm_asesor`.`crmclay_rep20_Clientes_perdidos_monflow` join `crmcubic_crm_asesor`.`vtiger_cliente` on((`crmclay_rep20_Clientes_perdidos_monflow`.`RUT_Receptor` = `crmcubic_crm_asesor`.`vtiger_cliente`.`cliente`))) */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_Clientes_perdidos_monflow_3`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_Clientes_perdidos_monflow_3` AS select `crmcubic_crm_asesor`.`crmclay_router`.`sus` AS `sus`,`crmcubic_crm_asesor`.`crmclay_router`.`co` AS `co`,`crmcubic_crm_asesor`.`crmclay_router`.`dda` AS `dda`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Tipo_doc` AS `Tipo_doc`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Num_documento` AS `Num_documento`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Nombres` AS `Nombres`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Apellidos` AS `Apellidos`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Género` AS `Género`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Fecha_de_Nacimiento` AS `Fecha_de_Nacimiento`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Celular_1` AS `Celular_1`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Celular_2` AS `Celular_2`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Correo_1` AS `Correo_1`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Correo_2` AS `Correo_2`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`ID_ext_cliente` AS `ID_ext_cliente`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Indicador_al_día` AS `Indicador_al_día`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Propensión_al_pago` AS `Propensión_al_pago`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Canal_comunicación_preferido` AS `Canal_comunicación_preferido`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Canal_de_pago_Preferido` AS `Canal_de_pago_Preferido`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Estado` AS `Estado`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Variable_1` AS `Variable_1`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Variable_2` AS `Variable_2`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Variable_3` AS `Variable_3`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Variable_4` AS `Variable_4`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Variable_5` AS `Variable_5`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Variable_6` AS `Variable_6`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Variable_7` AS `Variable_7`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Variable_8` AS `Variable_8`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Variable_9` AS `Variable_9`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Variable_10` AS `Variable_10`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Asesor_ID` AS `Asesor_ID`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Referencia_1_nombre` AS `Referencia_1_nombre`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Referencia_1_teléfono` AS `Referencia_1_teléfono`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Referencia_1_correo_electrónico` AS `Referencia_1_correo_electrónico`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Referencia_2_nombre` AS `Referencia_2_nombre`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Referencia_2_apellido` AS `Referencia_2_apellido`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Referencia_2_teléfono` AS `Referencia_2_teléfono`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Referencia_2_correo_electrónico` AS `Referencia_2_correo_electrónico`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Garante_1_nombre` AS `Garante_1_nombre`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Garante_1_apellido` AS `Garante_1_apellido`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Garante_1_teléfono` AS `Garante_1_teléfono`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Garante_1_correo_electrónico` AS `Garante_1_correo_electrónico`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Garante_2_nombre` AS `Garante_2_nombre`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Garante_2_apellido` AS `Garante_2_apellido`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Garante_2_teléfono` AS `Garante_2_teléfono`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Garante_2_correo_electrónico` AS `Garante_2_correo_electrónico`,`crmclay_rep20_Clientes_perdidos_monflow_2`.`Eliminación` AS `Eliminación`,`crmcubic_crm_asesor`.`ClayCrm`.`Modulo` AS `Modulo`,`crmcubic_crm_asesor`.`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`crmcubic_crm_asesor`.`ClayCrm`.`Mes_Año` AS `Mes_Año`,`crmcubic_crm_asesor`.`ClayCrm`.`Num_Factura` AS `Num_Factura`,`crmcubic_crm_asesor`.`ClayCrm`.`Nro_caso` AS `Nro_caso`,`crmcubic_crm_asesor`.`ClayCrm`.`Total` AS `Total`,`crmcubic_crm_asesor`.`ClayCrm`.`Saldo` AS `Saldo`,`crmcubic_crm_asesor`.`ClayCrm`.`Pagado` AS `Pagado` from ((`crmcubic_crm_asesor`.`ClayCrm` join `crmcubic_crm_asesor`.`crmclay_rep20_Clientes_perdidos_monflow_2` on((`crmclay_rep20_Clientes_perdidos_monflow_2`.`Num_documento` = replace(`crmcubic_crm_asesor`.`ClayCrm`.`RUT_Receptor`,'.','')))) join `crmcubic_crm_asesor`.`crmclay_router` on((`crmcubic_crm_asesor`.`ClayCrm`.`Nro_caso` = `crmcubic_crm_asesor`.`crmclay_router`.`ncaso`))) */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_NewRonin`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_NewRonin` AS select `ClayCrm`.`id` AS `id`,`ClayCrm`.`Modulo` AS `Modulo`,`ClayCrm`.`Nro_caso` AS `Nro_caso`,`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`ClayCrm`.`Mes_Año` AS `Mes_Año`,`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,`ClayCrm`.`RUT_Receptor` AS `RUT_Receptor`,`ClayCrm`.`Exento` AS `Exento`,`ClayCrm`.`Saldo` AS `Saldo` from (`ClayCrm` left join `crmclay_router` on((`ClayCrm`.`Nro_caso` = `crmclay_router`.`ncaso`))) where isnull(`crmclay_router`.`ncaso`) */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_Todos_lo_clientes`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_Todos_lo_clientes` AS select `subquery`.`Tipo_doc` AS `Tipo_doc`,`subquery`.`Num_documento` AS `Num_documento`,`subquery`.`Nombres` AS `Nombres`,`subquery`.`Apellidos` AS `Apellidos`,`subquery`.`Género` AS `Género`,`subquery`.`Fecha_de_Nacimiento` AS `Fecha_de_Nacimiento`,`subquery`.`Celular_1` AS `Celular_1`,`subquery`.`Celular_2` AS `Celular_2`,`subquery`.`Correo_1` AS `Correo_1`,`subquery`.`Correo_2` AS `Correo_2`,`subquery`.`ID_ext_cliente` AS `ID_ext_cliente`,`subquery`.`Indicador_al_día` AS `Indicador_al_día`,`subquery`.`Propensión_al_pago` AS `Propensión_al_pago`,`subquery`.`Canal_comunicación_preferido` AS `Canal_comunicación_preferido`,`subquery`.`Canal_de_pago_Preferido` AS `Canal_de_pago_Preferido`,`subquery`.`Estado` AS `Estado`,`subquery`.`Variable_1` AS `Variable_1`,`subquery`.`Variable_2` AS `Variable_2`,`subquery`.`Variable_3` AS `Variable_3`,`subquery`.`Variable_4` AS `Variable_4`,`subquery`.`Variable_5` AS `Variable_5`,`subquery`.`Variable_6` AS `Variable_6`,`subquery`.`Variable_7` AS `Variable_7`,`subquery`.`Variable_8` AS `Variable_8`,`subquery`.`Variable_9` AS `Variable_9`,`subquery`.`Variable_10` AS `Variable_10`,`subquery`.`Asesor_ID` AS `Asesor_ID`,`subquery`.`Referencia_1_nombre` AS `Referencia_1_nombre`,`subquery`.`Referencia_1_teléfono` AS `Referencia_1_teléfono`,`subquery`.`Referencia_1_correo_electrónico` AS `Referencia_1_correo_electrónico`,`subquery`.`Referencia_2_nombre` AS `Referencia_2_nombre`,`subquery`.`Referencia_2_apellido` AS `Referencia_2_apellido`,`subquery`.`Referencia_2_teléfono` AS `Referencia_2_teléfono`,`subquery`.`Referencia_2_correo_electrónico` AS `Referencia_2_correo_electrónico`,`subquery`.`Garante_1_nombre` AS `Garante_1_nombre`,`subquery`.`Garante_1_apellido` AS `Garante_1_apellido`,`subquery`.`Garante_1_teléfono` AS `Garante_1_teléfono`,`subquery`.`Garante_1_correo_electrónico` AS `Garante_1_correo_electrónico`,`subquery`.`Garante_2_nombre` AS `Garante_2_nombre`,`subquery`.`Garante_2_apellido` AS `Garante_2_apellido`,`subquery`.`Garante_2_teléfono` AS `Garante_2_teléfono`,`subquery`.`Garante_2_correo_electrónico` AS `Garante_2_correo_electrónico`,`subquery`.`Eliminación` AS `Eliminación` from (select 501 AS `Tipo_doc`,`crmcubic_crm_asesor`.`vtiger_cliente`.`cliente` AS `Num_documento`,`crmcubic_crm_asesor`.`vtiger_cliente`.`nombre` AS `Nombres`,`crmcubic_crm_asesor`.`vtiger_cliente`.`apellido` AS `Apellidos`,'O' AS `Género`,'24/06/1987' AS `Fecha_de_Nacimiento`,(case when (left(replace(`crmcubic_crm_asesor`.`vtiger_cliente`.`movil`,'+56',''),1) = '0') then substr(replace(`crmcubic_crm_asesor`.`vtiger_cliente`.`movil`,'+56',''),2) else replace(`crmcubic_crm_asesor`.`vtiger_cliente`.`movil`,'+56','') end) AS `Celular_1`,replace(replace(`crmcubic_crm_asesor`.`vtiger_cliente`.`movil_extra`,'+56',''),'0','') AS `Celular_2`,`crmcubic_crm_asesor`.`vtiger_cliente`.`email` AS `Correo_1`,`crmcubic_crm_asesor`.`vtiger_cliente`.`email` AS `Correo_2`,`crmcubic_crm_asesor`.`vtiger_cliente`.`cliente` AS `ID_ext_cliente`,0 AS `Indicador_al_día`,99 AS `Propensión_al_pago`,1 AS `Canal_comunicación_preferido`,1 AS `Canal_de_pago_Preferido`,1 AS `Estado`,'' AS `Variable_1`,'' AS `Variable_2`,'' AS `Variable_3`,'' AS `Variable_4`,'' AS `Variable_5`,'' AS `Variable_6`,'' AS `Variable_7`,'' AS `Variable_8`,'' AS `Variable_9`,'' AS `Variable_10`,'' AS `Asesor_ID`,'' AS `Referencia_1_nombre`,'' AS `Referencia_1_teléfono`,'' AS `Referencia_1_correo_electrónico`,'' AS `Referencia_2_nombre`,'' AS `Referencia_2_apellido`,'' AS `Referencia_2_teléfono`,'' AS `Referencia_2_correo_electrónico`,'' AS `Garante_1_nombre`,'' AS `Garante_1_apellido`,'' AS `Garante_1_teléfono`,'' AS `Garante_1_correo_electrónico`,'' AS `Garante_2_nombre`,'' AS `Garante_2_apellido`,'' AS `Garante_2_teléfono`,'' AS `Garante_2_correo_electrónico`,'' AS `Eliminación` from (`crmcubic_crm_asesor`.`ClayCrm` join `crmcubic_crm_asesor`.`vtiger_cliente` on((replace(`crmcubic_crm_asesor`.`ClayCrm`.`RUT_Receptor`,'.','') = `crmcubic_crm_asesor`.`vtiger_cliente`.`cliente`)))) `subquery` where (`subquery`.`Celular_1` regexp '^[0-9]{9}$') group by `subquery`.`Num_documento` */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_co`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_co` AS select `ClayCrm`.`id` AS `id`,`ClayCrm`.`Modulo` AS `Modulo`,`crmclay_router`.`ncaso` AS `ncaso`,`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`ClayCrm`.`Mes_Año` AS `Mes_Año`,`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,`ClayCrm`.`RUT_Receptor` AS `RUT_Receptor`,`ClayCrm`.`Exento` AS `Exento`,`ClayCrm`.`Saldo` AS `Saldo`,`vtiger_cliente`.`movil` AS `movil`,`vtiger_cliente`.`movil_extra` AS `movil_extra`,`vtiger_cliente`.`email` AS `email`,`vtiger_cliente`.`dircliente` AS `dircliente`,`vtiger_cliente`.`comunacliente` AS `comunacliente`,`vtiger_cliente`.`ciudadcliente` AS `ciudadcliente`,`vtiger_siniestro`.`estado_` AS `estado_`,`vtiger_siniestro`.`banco` AS `banco`,`vtiger_siniestro`.`ciaseguros` AS `ciaseguros`,`vtiger_siniestro`.`montopresupuesto` AS `montopresupuesto`,`vtiger_siniestro`.`fsismo` AS `fsismo`,`vtiger_siniestro`.`tiposiniestro` AS `tiposiniestro`,`vtiger_siniestro`.`tipopropiedad` AS `tipopropiedad`,`vtiger_siniestro`.`ciudadcaso` AS `ciudadcaso`,`vtiger_siniestro`.`comunacaso` AS `comunacaso`,`vtiger_siniestro`.`direccionsiniestro` AS `direccionsiniestro`,`vtiger_siniestro`.`mts2` AS `mts2`,(case `vtiger_siniestro`.`contratofirmado` when 1 then 'Sí' when 0 then 'No' end) AS `ContratoFirmadoTexto`,(case `vtiger_siniestro`.`mandatofirmado` when 1 then 'Sí' when 0 then 'No' end) AS `MandatoFirmadoTexto` from (((`crmclay_router` join `ClayCrm` on((`crmclay_router`.`ncaso` = `ClayCrm`.`Nro_caso`))) join `vtiger_siniestro` on((`ClayCrm`.`Nro_caso` = `vtiger_siniestro`.`siniestro`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) where ((`crmclay_router`.`sus` = 0) and (`crmclay_router`.`co` = 1) and (`crmclay_router`.`dda` = 0)) */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_co-dda`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_co-dda` AS select `ClayCrm`.`id` AS `id`,`ClayCrm`.`Modulo` AS `Modulo`,`crmclay_router`.`ncaso` AS `ncaso`,`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`ClayCrm`.`Mes_Año` AS `Mes_Año`,`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,`ClayCrm`.`RUT_Receptor` AS `RUT_Receptor`,`ClayCrm`.`Exento` AS `Exento`,`ClayCrm`.`Saldo` AS `Saldo` from (`crmclay_router` join `ClayCrm` on((`crmclay_router`.`ncaso` = `ClayCrm`.`Nro_caso`))) where ((`crmclay_router`.`sus` = 0) and (`crmclay_router`.`co` = 1) and (`crmclay_router`.`dda` = 1)) */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_co-dda-sus`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_co-dda-sus` AS select `ClayCrm`.`id` AS `id`,`ClayCrm`.`Modulo` AS `Modulo`,`crmclay_router`.`ncaso` AS `ncaso`,`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`ClayCrm`.`Mes_Año` AS `Mes_Año`,`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,if((left(replace(`ClayCrm`.`RUT_Receptor`,'.',''),1) = '0'),substr(replace(`ClayCrm`.`RUT_Receptor`,'.',''),2),replace(`ClayCrm`.`RUT_Receptor`,'.','')) AS `RUT_Receptor`,`ClayCrm`.`Exento` AS `Exento`,`ClayCrm`.`Saldo` AS `Saldo`,'501' AS `Tipo_doc`,if((left(replace(`ClayCrm`.`RUT_Receptor`,'.',''),1) = '0'),substr(replace(`ClayCrm`.`RUT_Receptor`,'.',''),2),replace(`ClayCrm`.`RUT_Receptor`,'.','')) AS `Num_documento`,(case when (`ClayCrm`.`Modulo` = 'Suscripción') then 'Suscripción Siniestro' when (`ClayCrm`.`Modulo` = 'Cobranza') then 'Honorarios Siniestro' when (`ClayCrm`.`Modulo` = 'Suscripción DDA') then 'Suscripción Asesoria Legal' end) AS `Producto`,(case when (`ClayCrm`.`Modulo` = 'Suscripción') then concat('FS',`ClayCrm`.`Num_Factura`) when (`ClayCrm`.`Modulo` = 'Cobranza') then concat('FH',`ClayCrm`.`Num_Factura`) when (`ClayCrm`.`Modulo` = 'Suscripción DDA') then concat('FL',`ClayCrm`.`Num_Factura`) end) AS `Código_de_pago`,1 AS `Cuota`,if((left(replace(`ClayCrm`.`RUT_Receptor`,'.',''),1) = '0'),substr(replace(`ClayCrm`.`RUT_Receptor`,'.',''),2),replace(`ClayCrm`.`RUT_Receptor`,'.','')) AS `ID_ext_cliente`,'CLP' AS `Moneda`,`ClayCrm`.`Saldo` AS `Monto_OP`,'' AS `Cargos_e_Intereses_OP`,date_format((str_to_date(`ClayCrm`.`Fecha_Emision`,'%Y-%m-%d') + interval 60 day),'%d/%m/%Y') AS `Fecha_de_vencimiento_DD_MM_YYYY`,'' AS `Anulada`,'' AS `URL_Adjunto_1`,'' AS `URL_Adjunto_2`,date_format(str_to_date(`ClayCrm`.`Fecha_Emision`,'%Y-%m-%d'),'%d/%m/%Y') AS `Fecha_de_emisión_DD_MM_YYYY`,(case when (`ClayCrm`.`Modulo` = 'Suscripción') then 'Suscripción Siniestro' when (`ClayCrm`.`Modulo` = 'Cobranza') then 'Honorarios Siniestro' when (`ClayCrm`.`Modulo` = 'Suscripción DDA') then 'Suscripción Asesoria Legal' end) AS `Descripción`,0 AS `Descuento`,`crmclay_router`.`ncaso` AS `ID_ext_orden` from (((`crmclay_router` join `ClayCrm` on((`crmclay_router`.`ncaso` = `ClayCrm`.`Nro_caso`))) join `vtiger_siniestro` on((`crmclay_router`.`ncaso` = `vtiger_siniestro`.`siniestro`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) where ((`crmclay_router`.`sus` = 1) and (`crmclay_router`.`co` = 1) and (`crmclay_router`.`dda` = 1)) */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_co-dda_Monflow`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_co-dda_Monflow` AS select `ClayCrm`.`id` AS `id`,`ClayCrm`.`Modulo` AS `Modulo`,`crmclay_router`.`ncaso` AS `ncaso`,`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`ClayCrm`.`Mes_Año` AS `Mes_Año`,`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,if((left(replace(`ClayCrm`.`RUT_Receptor`,'.',''),1) = '0'),substr(replace(`ClayCrm`.`RUT_Receptor`,'.',''),2),replace(`ClayCrm`.`RUT_Receptor`,'.','')) AS `RUT_Receptor`,`ClayCrm`.`Exento` AS `Exento`,`ClayCrm`.`Saldo` AS `Saldo`,'501' AS `Tipo_doc`,if((left(replace(`ClayCrm`.`RUT_Receptor`,'.',''),1) = '0'),substr(replace(`ClayCrm`.`RUT_Receptor`,'.',''),2),replace(`ClayCrm`.`RUT_Receptor`,'.','')) AS `Num_documento`,(case when (`ClayCrm`.`Modulo` = 'Cobranza') then 'Honorarios Siniestro' when (`ClayCrm`.`Modulo` = 'Suscripción DDA') then 'Suscripción Asesoria Legal' end) AS `Producto`,(case when (`ClayCrm`.`Modulo` = 'Cobranza') then concat('FH',`ClayCrm`.`Num_Factura`) when (`ClayCrm`.`Modulo` = 'Suscripción DDA') then concat('FL',`ClayCrm`.`Num_Factura`) end) AS `Código_de_pago`,1 AS `Cuota`,if((left(replace(`ClayCrm`.`RUT_Receptor`,'.',''),1) = '0'),substr(replace(`ClayCrm`.`RUT_Receptor`,'.',''),2),replace(`ClayCrm`.`RUT_Receptor`,'.','')) AS `ID_ext_cliente`,'CLP' AS `Moneda`,`ClayCrm`.`Saldo` AS `Monto_OP`,'' AS `Cargos_e_Intereses_OP`,date_format((str_to_date(`ClayCrm`.`Fecha_Emision`,'%Y-%m-%d') + interval 60 day),'%d/%m/%Y') AS `Fecha_de_vencimiento_DD_MM_YYYY`,'' AS `Anulada`,'' AS `URL_Adjunto_1`,'' AS `URL_Adjunto_2`,date_format(str_to_date(`ClayCrm`.`Fecha_Emision`,'%Y-%m-%d'),'%d/%m/%Y') AS `Fecha_de_emisión_DD_MM_YYYY`,(case when (`ClayCrm`.`Modulo` = 'Cobranza') then 'Honorarios Siniestro' when (`ClayCrm`.`Modulo` = 'Suscripción DDA') then 'Suscripción Asesoria Legal' end) AS `Descripción`,0 AS `Descuento`,`crmclay_router`.`ncaso` AS `ID_ext_orden` from (((`crmclay_router` join `ClayCrm` on((`crmclay_router`.`ncaso` = `ClayCrm`.`Nro_caso`))) join `vtiger_siniestro` on((`crmclay_router`.`ncaso` = `vtiger_siniestro`.`siniestro`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) where ((`crmclay_router`.`sus` = 0) and (`crmclay_router`.`co` = 1) and (`crmclay_router`.`dda` = 1)) */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_co_Monflow`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_co_Monflow` AS select `ClayCrm`.`id` AS `id`,`ClayCrm`.`Modulo` AS `Modulo`,`crmclay_router`.`ncaso` AS `ncaso`,`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`ClayCrm`.`Mes_Año` AS `Mes_Año`,`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,if((left(replace(`ClayCrm`.`RUT_Receptor`,'.',''),1) = '0'),substr(replace(`ClayCrm`.`RUT_Receptor`,'.',''),2),replace(`ClayCrm`.`RUT_Receptor`,'.','')) AS `RUT_Receptor`,`ClayCrm`.`Exento` AS `Exento`,`ClayCrm`.`Saldo` AS `Saldo`,'501' AS `Tipo_doc`,if((left(replace(`ClayCrm`.`RUT_Receptor`,'.',''),1) = '0'),substr(replace(`ClayCrm`.`RUT_Receptor`,'.',''),2),replace(`ClayCrm`.`RUT_Receptor`,'.','')) AS `Num_documento`,'Honorarios siniestros' AS `Producto`,concat('FH',`ClayCrm`.`Num_Factura`) AS `Código_de_pago`,1 AS `Cuota`,if((left(replace(`ClayCrm`.`RUT_Receptor`,'.',''),1) = '0'),substr(replace(`ClayCrm`.`RUT_Receptor`,'.',''),2),replace(`ClayCrm`.`RUT_Receptor`,'.','')) AS `ID_ext_cliente`,'CLP' AS `Moneda`,`ClayCrm`.`Saldo` AS `Monto_OP`,'' AS `Cargos_e_Intereses_OP`,date_format((str_to_date(`ClayCrm`.`Fecha_Emision`,'%Y-%m-%d') + interval 60 day),'%d/%m/%Y') AS `Fecha_de_vencimiento_DD_MM_YYYY`,'' AS `Anulada`,'' AS `URL_Adjunto_1`,'' AS `URL_Adjunto_2`,`ClayCrm`.`Fecha_Emision` AS `Fecha_de_emisión_DD_MM_YYYY`,'Honorarios siniestros' AS `Descripción`,0 AS `Descuento`,`crmclay_router`.`ncaso` AS `ID_ext_orden` from (((`crmclay_router` join `ClayCrm` on((`crmclay_router`.`ncaso` = `ClayCrm`.`Nro_caso`))) join `vtiger_siniestro` on((`crmclay_router`.`ncaso` = `vtiger_siniestro`.`siniestro`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) where ((`crmclay_router`.`sus` = 0) and (`crmclay_router`.`co` = 1) and (`crmclay_router`.`dda` = 0)) */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_dda`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_dda` AS select `ClayCrm`.`id` AS `id`,`ClayCrm`.`Modulo` AS `Modulo`,`crmclay_router`.`ncaso` AS `ncaso`,`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`ClayCrm`.`Mes_Año` AS `Mes_Año`,`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,`ClayCrm`.`RUT_Receptor` AS `RUT_Receptor`,`ClayCrm`.`Exento` AS `Exento`,`ClayCrm`.`Saldo` AS `Saldo`,`vtiger_cliente`.`movil` AS `movil`,`vtiger_cliente`.`movil_extra` AS `movil_extra`,`vtiger_cliente`.`email` AS `email`,`vtiger_cliente`.`dircliente` AS `dircliente`,`vtiger_cliente`.`comunacliente` AS `comunacliente`,`vtiger_cliente`.`ciudadcliente` AS `ciudadcliente`,`vtiger_siniestro`.`estado_` AS `estado_`,`vtiger_siniestro`.`banco` AS `banco`,`vtiger_siniestro`.`ciaseguros` AS `ciaseguros`,`vtiger_siniestro`.`montopresupuesto` AS `montopresupuesto`,`vtiger_siniestro`.`fsismo` AS `fsismo`,`vtiger_siniestro`.`tiposiniestro` AS `tiposiniestro`,`vtiger_siniestro`.`tipopropiedad` AS `tipopropiedad`,`vtiger_siniestro`.`ciudadcaso` AS `ciudadcaso`,`vtiger_siniestro`.`comunacaso` AS `comunacaso`,`vtiger_siniestro`.`direccionsiniestro` AS `direccionsiniestro`,`vtiger_siniestro`.`mts2` AS `mts2`,(case `vtiger_siniestro`.`contratofirmado` when 1 then 'Sí' when 0 then 'No' end) AS `ContratoFirmadoTexto`,(case `vtiger_siniestro`.`mandatofirmado` when 1 then 'Sí' when 0 then 'No' end) AS `MandatoFirmadoTexto` from (((`crmclay_router` join `ClayCrm` on((`crmclay_router`.`ncaso` = `ClayCrm`.`Nro_caso`))) join `vtiger_siniestro` on((`ClayCrm`.`Nro_caso` = `vtiger_siniestro`.`siniestro`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) where ((`crmclay_router`.`sus` = 0) and (`crmclay_router`.`co` = 0) and (`crmclay_router`.`dda` = 1)) */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_dda_Monflow`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_dda_Monflow` AS select `ClayCrm`.`id` AS `id`,`ClayCrm`.`Modulo` AS `Modulo`,`crmclay_router`.`ncaso` AS `ncaso`,`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`ClayCrm`.`Mes_Año` AS `Mes_Año`,`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,if((left(replace(`ClayCrm`.`RUT_Receptor`,'.',''),1) = '0'),substr(replace(`ClayCrm`.`RUT_Receptor`,'.',''),2),replace(`ClayCrm`.`RUT_Receptor`,'.','')) AS `RUT_Receptor`,`ClayCrm`.`Exento` AS `Exento`,`ClayCrm`.`Saldo` AS `Saldo`,'501' AS `Tipo_doc`,if((left(replace(`ClayCrm`.`RUT_Receptor`,'.',''),1) = '0'),substr(replace(`ClayCrm`.`RUT_Receptor`,'.',''),2),replace(`ClayCrm`.`RUT_Receptor`,'.','')) AS `Num_documento`,'Suscripción Asesoria Legal' AS `Producto`,concat('FL',`ClayCrm`.`Num_Factura`) AS `Código_de_pago`,1 AS `Cuota`,if((left(replace(`ClayCrm`.`RUT_Receptor`,'.',''),1) = '0'),substr(replace(`ClayCrm`.`RUT_Receptor`,'.',''),2),replace(`ClayCrm`.`RUT_Receptor`,'.','')) AS `ID_ext_cliente`,'CLP' AS `Moneda`,`ClayCrm`.`Saldo` AS `Monto_OP`,'' AS `Cargos_e_Intereses_OP`,date_format((str_to_date(`ClayCrm`.`Fecha_Emision`,'%Y-%m-%d') + interval 60 day),'%d/%m/%Y') AS `Fecha_de_vencimiento_DD_MM_YYYY`,'' AS `Anulada`,'' AS `URL_Adjunto_1`,'' AS `URL_Adjunto_2`,`ClayCrm`.`Fecha_Emision` AS `Fecha_de_emisión_DD_MM_YYYY`,'Suscripción Asesoria Legal' AS `Descripción`,0 AS `Descuento`,`crmclay_router`.`ncaso` AS `ID_ext_orden` from (((`crmclay_router` join `ClayCrm` on((`crmclay_router`.`ncaso` = `ClayCrm`.`Nro_caso`))) join `vtiger_siniestro` on((`crmclay_router`.`ncaso` = `vtiger_siniestro`.`siniestro`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) where ((`crmclay_router`.`sus` = 0) and (`crmclay_router`.`co` = 0) and (`crmclay_router`.`dda` = 1)) */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_sus`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_sus` AS select `ClayCrm`.`id` AS `id`,`ClayCrm`.`Modulo` AS `Modulo`,`crmclay_router`.`ncaso` AS `ncaso`,`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`ClayCrm`.`Mes_Año` AS `Mes_Año`,`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,`ClayCrm`.`RUT_Receptor` AS `RUT_Receptor`,`ClayCrm`.`Exento` AS `Exento`,`ClayCrm`.`Saldo` AS `Saldo`,`vtiger_cliente`.`movil` AS `movil`,`vtiger_cliente`.`movil_extra` AS `movil_extra`,`vtiger_cliente`.`email` AS `email`,`vtiger_cliente`.`dircliente` AS `dircliente`,`vtiger_cliente`.`comunacliente` AS `comunacliente`,`vtiger_cliente`.`ciudadcliente` AS `ciudadcliente`,`vtiger_siniestro`.`estado_` AS `estado_`,`vtiger_siniestro`.`banco` AS `banco`,`vtiger_siniestro`.`ciaseguros` AS `ciaseguros`,`vtiger_siniestro`.`montopresupuesto` AS `montopresupuesto`,`vtiger_siniestro`.`fsismo` AS `fsismo`,`vtiger_siniestro`.`tiposiniestro` AS `tiposiniestro`,`vtiger_siniestro`.`tipopropiedad` AS `tipopropiedad`,`vtiger_siniestro`.`ciudadcaso` AS `ciudadcaso`,`vtiger_siniestro`.`comunacaso` AS `comunacaso`,`vtiger_siniestro`.`direccionsiniestro` AS `direccionsiniestro`,`vtiger_siniestro`.`mts2` AS `mts2`,(case `vtiger_siniestro`.`contratofirmado` when 1 then 'Sí' when 0 then 'No' end) AS `ContratoFirmadoTexto`,(case `vtiger_siniestro`.`mandatofirmado` when 1 then 'Sí' when 0 then 'No' end) AS `MandatoFirmadoTexto` from (((`crmclay_router` join `ClayCrm` on((`crmclay_router`.`ncaso` = `ClayCrm`.`Nro_caso`))) join `vtiger_siniestro` on((`ClayCrm`.`Nro_caso` = `vtiger_siniestro`.`siniestro`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) where ((`crmclay_router`.`sus` = 1) and (`crmclay_router`.`co` = 0) and (`crmclay_router`.`dda` = 0)) */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_sus-co`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_sus-co` AS select `ClayCrm`.`id` AS `id`,`ClayCrm`.`Modulo` AS `Modulo`,`crmclay_router`.`ncaso` AS `ncaso`,`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`ClayCrm`.`Mes_Año` AS `Mes_Año`,`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,`ClayCrm`.`RUT_Receptor` AS `RUT_Receptor`,`ClayCrm`.`Exento` AS `Exento`,`ClayCrm`.`Saldo` AS `Saldo`,`vtiger_cliente`.`movil` AS `movil`,`vtiger_cliente`.`movil_extra` AS `movil_extra`,`vtiger_cliente`.`email` AS `email`,`vtiger_cliente`.`dircliente` AS `dircliente`,`vtiger_cliente`.`comunacliente` AS `comunacliente`,`vtiger_cliente`.`ciudadcliente` AS `ciudadcliente`,`vtiger_siniestro`.`estado_` AS `estado_`,`vtiger_siniestro`.`banco` AS `banco`,`vtiger_siniestro`.`ciaseguros` AS `ciaseguros`,`vtiger_siniestro`.`montopresupuesto` AS `montopresupuesto`,`vtiger_siniestro`.`fsismo` AS `fsismo`,`vtiger_siniestro`.`tiposiniestro` AS `tiposiniestro`,`vtiger_siniestro`.`tipopropiedad` AS `tipopropiedad`,`vtiger_siniestro`.`ciudadcaso` AS `ciudadcaso`,`vtiger_siniestro`.`comunacaso` AS `comunacaso`,`vtiger_siniestro`.`direccionsiniestro` AS `direccionsiniestro`,`vtiger_siniestro`.`mts2` AS `mts2`,(case `vtiger_siniestro`.`contratofirmado` when 1 then 'Sí' when 0 then 'No' end) AS `ContratoFirmadoTexto`,(case `vtiger_siniestro`.`mandatofirmado` when 1 then 'Sí' when 0 then 'No' end) AS `MandatoFirmadoTexto` from (((`crmclay_router` join `ClayCrm` on((`crmclay_router`.`ncaso` = `ClayCrm`.`Nro_caso`))) join `vtiger_siniestro` on((`ClayCrm`.`Nro_caso` = `vtiger_siniestro`.`siniestro`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) where ((`crmclay_router`.`sus` = 1) and (`crmclay_router`.`co` = 1) and (`crmclay_router`.`dda` = 0)) */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_sus-co-dda`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_sus-co-dda` AS select `ClayCrm`.`id` AS `id`,`ClayCrm`.`Modulo` AS `Modulo`,`crmclay_router`.`ncaso` AS `ncaso`,`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`ClayCrm`.`Mes_Año` AS `Mes_Año`,`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,`ClayCrm`.`RUT_Receptor` AS `RUT_Receptor`,`ClayCrm`.`Exento` AS `Exento`,`ClayCrm`.`Saldo` AS `Saldo` from (`crmclay_router` join `ClayCrm` on((`crmclay_router`.`ncaso` = `ClayCrm`.`Nro_caso`))) where ((`crmclay_router`.`sus` = 1) and (`crmclay_router`.`co` = 1) and (`crmclay_router`.`dda` = 1)) */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_sus-co_Monflow`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_sus-co_Monflow` AS select `ClayCrm`.`id` AS `id`,`ClayCrm`.`Modulo` AS `Modulo`,`crmclay_router`.`ncaso` AS `ncaso`,`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`ClayCrm`.`Mes_Año` AS `Mes_Año`,`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,if((left(replace(`ClayCrm`.`RUT_Receptor`,'.',''),1) = '0'),substr(replace(`ClayCrm`.`RUT_Receptor`,'.',''),2),replace(`ClayCrm`.`RUT_Receptor`,'.','')) AS `RUT_Receptor`,`ClayCrm`.`Exento` AS `Exento`,`ClayCrm`.`Saldo` AS `Saldo`,'501' AS `Tipo_doc`,if((left(replace(`ClayCrm`.`RUT_Receptor`,'.',''),1) = '0'),substr(replace(`ClayCrm`.`RUT_Receptor`,'.',''),2),replace(`ClayCrm`.`RUT_Receptor`,'.','')) AS `Num_documento`,(case when (`ClayCrm`.`Modulo` = 'Cobranza') then 'Honorarios Siniestro' when (`ClayCrm`.`Modulo` = 'Suscripción') then 'Suscripción Siniestro' end) AS `Producto`,(case when (`ClayCrm`.`Modulo` = 'Cobranza') then concat('FH',`ClayCrm`.`Num_Factura`) when (`ClayCrm`.`Modulo` = 'Suscripción') then concat('FS',`ClayCrm`.`Num_Factura`) end) AS `Código_de_pago`,1 AS `Cuota`,if((left(replace(`ClayCrm`.`RUT_Receptor`,'.',''),1) = '0'),substr(replace(`ClayCrm`.`RUT_Receptor`,'.',''),2),replace(`ClayCrm`.`RUT_Receptor`,'.','')) AS `ID_ext_cliente`,'CLP' AS `Moneda`,`ClayCrm`.`Saldo` AS `Monto_OP`,'' AS `Cargos_e_Intereses_OP`,date_format((str_to_date(`ClayCrm`.`Fecha_Emision`,'%Y-%m-%d') + interval 60 day),'%d/%m/%Y') AS `Fecha_de_vencimiento_DD_MM_YYYY`,'' AS `Anulada`,'' AS `URL_Adjunto_1`,'' AS `URL_Adjunto_2`,date_format(str_to_date(`ClayCrm`.`Fecha_Emision`,'%Y-%m-%d'),'%d/%m/%Y') AS `Fecha_de_emisión_DD_MM_YYYY`,(case when (`ClayCrm`.`Modulo` = 'Cobranza') then 'Honorarios Siniestro' when (`ClayCrm`.`Modulo` = 'Suscripción') then 'Suscripción Siniestro' end) AS `Descripción`,0 AS `Descuento`,`crmclay_router`.`ncaso` AS `ID_ext_orden` from (((`crmclay_router` join `ClayCrm` on((`crmclay_router`.`ncaso` = `ClayCrm`.`Nro_caso`))) join `vtiger_siniestro` on((`crmclay_router`.`ncaso` = `vtiger_siniestro`.`siniestro`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) where ((`crmclay_router`.`sus` = 1) and (`crmclay_router`.`co` = 1) and (`crmclay_router`.`dda` = 0)) */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_sus-dda`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_sus-dda` AS select `ClayCrm`.`id` AS `id`,`ClayCrm`.`Modulo` AS `Modulo`,`crmclay_router`.`ncaso` AS `ncaso`,`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`ClayCrm`.`Mes_Año` AS `Mes_Año`,`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,`ClayCrm`.`RUT_Receptor` AS `RUT_Receptor`,`ClayCrm`.`Exento` AS `Exento`,`ClayCrm`.`Saldo` AS `Saldo` from (`crmclay_router` join `ClayCrm` on((`crmclay_router`.`ncaso` = `ClayCrm`.`Nro_caso`))) where ((`crmclay_router`.`sus` = 1) and (`crmclay_router`.`co` = 0) and (`crmclay_router`.`dda` = 1)) */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_sus-dda_Monflow`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_sus-dda_Monflow` AS select `ClayCrm`.`id` AS `id`,`ClayCrm`.`Modulo` AS `Modulo`,`crmclay_router`.`ncaso` AS `ncaso`,`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`ClayCrm`.`Mes_Año` AS `Mes_Año`,`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,if((left(replace(`ClayCrm`.`RUT_Receptor`,'.',''),1) = '0'),substr(replace(`ClayCrm`.`RUT_Receptor`,'.',''),2),replace(`ClayCrm`.`RUT_Receptor`,'.','')) AS `RUT_Receptor`,`ClayCrm`.`Exento` AS `Exento`,`ClayCrm`.`Saldo` AS `Saldo`,'501' AS `Tipo_doc`,if((left(replace(`ClayCrm`.`RUT_Receptor`,'.',''),1) = '0'),substr(replace(`ClayCrm`.`RUT_Receptor`,'.',''),2),replace(`ClayCrm`.`RUT_Receptor`,'.','')) AS `Num_documento`,(case when (`ClayCrm`.`Modulo` = 'Suscripción DDA') then 'Suscripción Asesoria Legal' when (`ClayCrm`.`Modulo` = 'Suscripción') then 'Suscripción Siniestro' end) AS `Producto`,(case when (`ClayCrm`.`Modulo` = 'Suscripción DDA') then concat('FL',`ClayCrm`.`Num_Factura`) when (`ClayCrm`.`Modulo` = 'Suscripción') then concat('FS',`ClayCrm`.`Num_Factura`) end) AS `Código_de_pago`,1 AS `Cuota`,if((left(replace(`ClayCrm`.`RUT_Receptor`,'.',''),1) = '0'),substr(replace(`ClayCrm`.`RUT_Receptor`,'.',''),2),replace(`ClayCrm`.`RUT_Receptor`,'.','')) AS `ID_ext_cliente`,'CLP' AS `Moneda`,`ClayCrm`.`Saldo` AS `Monto_OP`,'' AS `Cargos_e_Intereses_OP`,date_format((str_to_date(`ClayCrm`.`Fecha_Emision`,'%Y-%m-%d') + interval 60 day),'%d/%m/%Y') AS `Fecha_de_vencimiento_DD_MM_YYYY`,'' AS `Anulada`,'' AS `URL_Adjunto_1`,'' AS `URL_Adjunto_2`,date_format(str_to_date(`ClayCrm`.`Fecha_Emision`,'%Y-%m-%d'),'%d/%m/%Y') AS `Fecha_de_emisión_DD_MM_YYYY`,(case when (`ClayCrm`.`Modulo` = 'Suscripción DDA') then 'Suscripción Asesoria Legal' when (`ClayCrm`.`Modulo` = 'Suscripción') then 'Suscripción Siniestro' end) AS `Descripción`,0 AS `Descuento`,`crmclay_router`.`ncaso` AS `ID_ext_orden` from (((`crmclay_router` join `ClayCrm` on((`crmclay_router`.`ncaso` = `ClayCrm`.`Nro_caso`))) join `vtiger_siniestro` on((`crmclay_router`.`ncaso` = `vtiger_siniestro`.`siniestro`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) where ((`crmclay_router`.`sus` = 1) and (`crmclay_router`.`co` = 0) and (`crmclay_router`.`dda` = 1)) */;
/*!50001 DROP VIEW IF EXISTS `crmclay_rep20_sus_Mmonflow`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `crmclay_rep20_sus_Mmonflow` AS select `ClayCrm`.`id` AS `id`,`ClayCrm`.`Modulo` AS `Modulo`,`crmclay_router`.`ncaso` AS `ncaso`,`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`ClayCrm`.`Mes_Año` AS `Mes_Año`,`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`ClayCrm`.`Num_Factura` AS `Num_Factura`,`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,if((left(replace(`ClayCrm`.`RUT_Receptor`,'.',''),1) = '0'),substr(replace(`ClayCrm`.`RUT_Receptor`,'.',''),2),replace(`ClayCrm`.`RUT_Receptor`,'.','')) AS `RUT_Receptor`,`ClayCrm`.`Exento` AS `Exento`,`ClayCrm`.`Saldo` AS `Saldo`,'501' AS `Tipo_doc`,if((left(replace(`ClayCrm`.`RUT_Receptor`,'.',''),1) = '0'),substr(replace(`ClayCrm`.`RUT_Receptor`,'.',''),2),replace(`ClayCrm`.`RUT_Receptor`,'.','')) AS `Num_documento`,'Suscripción Siniestro' AS `Producto`,concat('FS',`ClayCrm`.`Num_Factura`) AS `Código_de_pago`,1 AS `Cuota`,if((left(replace(`ClayCrm`.`RUT_Receptor`,'.',''),1) = '0'),substr(replace(`ClayCrm`.`RUT_Receptor`,'.',''),2),replace(`ClayCrm`.`RUT_Receptor`,'.','')) AS `ID_ext_cliente`,'CLP' AS `Moneda`,`ClayCrm`.`Saldo` AS `Monto_OP`,'' AS `Cargos_e_Intereses_OP`,date_format((str_to_date(`ClayCrm`.`Fecha_Emision`,'%Y-%m-%d') + interval 60 day),'%d/%m/%Y') AS `Fecha_de_vencimiento_DD_MM_YYYY`,'' AS `Anulada`,'' AS `URL_Adjunto_1`,'' AS `URL_Adjunto_2`,`ClayCrm`.`Fecha_Emision` AS `Fecha_de_emisión_DD_MM_YYYY`,'Suscripción Siniestro' AS `Descripción`,0 AS `Descuento`,`crmclay_router`.`ncaso` AS `ID_ext_orden` from (((`crmclay_router` join `ClayCrm` on((`crmclay_router`.`ncaso` = `ClayCrm`.`Nro_caso`))) join `vtiger_siniestro` on((`crmclay_router`.`ncaso` = `vtiger_siniestro`.`siniestro`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) where ((`crmclay_router`.`sus` = 1) and (`crmclay_router`.`co` = 0) and (`crmclay_router`.`dda` = 0)) */;
/*!50001 DROP VIEW IF EXISTS `datosclientes`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `datosclientes` AS select `vtiger_cliente`.`movil` AS `Movil`,`vtiger_cliente`.`cliente` AS `cliente`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Nombre_de_contacto`,`vtiger_cliente`.`email` AS `Correo_electronico`,`vtiger_crmentity`.`createdtime` AS `createdtime` from (`vtiger_cliente` join `vtiger_crmentity` on((`vtiger_cliente`.`clienteid` = `vtiger_crmentity`.`crmid`))) where ((`vtiger_crmentity`.`createdtime` >= '2022-01-01') and (`vtiger_crmentity`.`createdtime` <= curdate())) */;
/*!50001 DROP VIEW IF EXISTS `eventos_calendario_agendados`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `eventos_calendario_agendados` AS select `vtiger_activity`.`activityid` AS `activityid`,`vtiger_activity`.`subject` AS `subject`,`vtiger_activity`.`activitytype` AS `activitytype`,`vtiger_activity`.`date_start` AS `date_start`,`vtiger_activity`.`due_date` AS `due_date`,`vtiger_activity`.`status` AS `status`,`vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_siniestro`.`comunacaso` AS `comunacaso`,`vtiger_siniestro`.`direccionsiniestro` AS `direccionsiniestro`,`vtiger_siniestro`.`latitud_sini` AS `latitud_sini`,`vtiger_siniestro`.`longitud_sini` AS `longitud_sini`,`vtiger_siniestro`.`nombrecliente` AS `nombrecliente`,`vtiger_activity`.`nrocaso` AS `nrocaso`,`vtiger_cliente`.`cliente` AS `cliente`,`vtiger_cliente`.`nombre` AS `nombre`,`vtiger_cliente`.`apellido` AS `apellido`,`vtiger_crmentity`.`smcreatorid` AS `smcreatorid`,`vtiger_crmentity`.`smownerid` AS `smownerid`,`vtiger_crmentity`.`modifiedby` AS `modifiedby`,`vtiger_crmentity`.`createdtime` AS `createdtime`,`vtiger_crmentity`.`modifiedtime` AS `modifiedtime`,concat(`vtiger_users`.`first_name`,' ',`vtiger_users`.`last_name`) AS `Creado_por`,concat(`vtiger_users1`.`first_name`,' ',`vtiger_users1`.`last_name`) AS `Asignado_a`,concat(`vtiger_users2`.`first_name`,' ',`vtiger_users2`.`last_name`) AS `Ultima_mod_por`,`vtiger_siniestro`.`estado_` AS `Estado_caso`,`vtiger_activity`.`time_start` AS `time_start`,`vtiger_activity`.`time_end` AS `time_end`,`vtiger_cliente`.`movil` AS `movil`,`vtiger_cliente`.`email` AS `email`,`vtiger_cliente`.`captador` AS `captador` from ((((((`vtiger_activity` join `vtiger_siniestro` on((`vtiger_activity`.`nrocaso` = `vtiger_siniestro`.`siniestroid`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) join `vtiger_crmentity` on((`vtiger_activity`.`activityid` = `vtiger_crmentity`.`crmid`))) join `vtiger_users` on((`vtiger_crmentity`.`smcreatorid` = `vtiger_users`.`id`))) join `vtiger_users` `vtiger_users1` on((`vtiger_crmentity`.`smownerid` = `vtiger_users1`.`id`))) join `vtiger_users` `vtiger_users2` on((`vtiger_crmentity`.`modifiedby` = `vtiger_users2`.`id`))) where ((`vtiger_siniestro`.`latitud_sini` <> '') and (`vtiger_siniestro`.`longitud_sini` <> '') and (`vtiger_activity`.`nrocaso` <> 0)) order by `vtiger_crmentity`.`createdtime` desc */;
/*!50001 DROP VIEW IF EXISTS `facturados_suscripcion`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `facturados_suscripcion` AS select `vtiger_suscripcion`.`suscripcionid` AS `id`,`vtiger_cliente`.`cliente` AS `Rut`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Nombre_cliente`,`vtiger_siniestro`.`siniestro` AS `Siniestro`,`vtiger_suscripcion`.`estado` AS `Estado`,`vtiger_suscripcion`.`valortotal` AS `Valor_total`,`vtiger_crmentity`.`createdtime` AS `Creacion_sus`,`vtiger_suscripcion`.`nrofactura` AS `N_factura`,`vtiger_suscripcion`.`ffactura` AS `Fecha_factura`,`vtiger_suscripcion`.`captador` AS `Captador`,`vtiger_suscripcion`.`contratofirmado` AS `Contrato_Firmado`,`vtiger_siniestro`.`id_fact_relBase_sus` AS `id_relbase`,`vtiger_siniestro`.`estado_factura_sii` AS `estado_factura_sii` from (((`vtiger_suscripcion` join `vtiger_crmentity` on((`vtiger_suscripcion`.`suscripcionid` = `vtiger_crmentity`.`crmid`))) join `vtiger_siniestro` on((`vtiger_suscripcion`.`siniestro` = `vtiger_siniestro`.`siniestroid`))) join `vtiger_cliente` on((`vtiger_suscripcion`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) where ((`vtiger_suscripcion`.`estado` not in ('Ingresado a CRM (CP)','Preinspección REprogramada','Abierto (CP)','Preinspección Programada','No Quiere Firmar','No aplica','Desistido','REPETIDO','Por Procesar','Retención','Denunciado (CRM - SOS)','Por Recuperar','Reencantar','Preinspección a Reprogramar')) and (`vtiger_crmentity`.`createdtime` > '2022-01-01 23:59:59') and (`vtiger_suscripcion`.`nrofactura` <> 0) and (`vtiger_siniestro`.`id_fact_relBase_sus` <> 0) and (`vtiger_siniestro`.`estado_factura_sii` = 'Aceptado') and (`vtiger_suscripcion`.`estado` is not null) and (`vtiger_suscripcion`.`estado` <> '') and (`vtiger_crmentity`.`deleted` = 0)) */;
/*!50001 DROP VIEW IF EXISTS `facturas_report_clay_all`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `facturas_report_clay_all` AS select `Claycons_cobra`.`Modulo` AS `Modulo`,`Claycons_cobra`.`Num_Factura_clay` AS `Factura` from `Claycons_cobra` union select `Claycons_sus`.`Modulo` AS `Modulo`,`Claycons_sus`.`Num_Factura_clay` AS `Factura` from `Claycons_sus` union select `Claycons_sus_cobra`.`Modulo_sus` AS `Modulo_sus`,`Claycons_sus_cobra`.`Num_Factura_clay_sus` AS `Factura` from `Claycons_sus_cobra` union select `Claycons_sus_da`.`Modulo` AS `Modulo`,NULL AS `Factura` from `Claycons_sus_da` union select `ClayDuplicados`.`Modulo` AS `Modulo`,NULL AS `Factura` from `ClayDuplicados` */;
/*!50001 DROP VIEW IF EXISTS `geo_all`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `geo_all` AS select `vtiger_siniestro`.`siniestroid` AS `id`,`vtiger_siniestro`.`latitud_sini` AS `latitude`,`vtiger_siniestro`.`longitud_sini` AS `longitude`,`vtiger_siniestro`.`direccionsiniestro` AS `Direccion`,`vtiger_siniestro`.`ciudadcaso` AS `Ciudad` from `vtiger_siniestro` where (`vtiger_siniestro`.`georeferenciado_estado` = 1) */;
/*!50001 DROP VIEW IF EXISTS `grid_crmclay_rep20_1_co_dda`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `grid_crmclay_rep20_1_co_dda` AS select `c`.`ncaso` AS `ncaso`,max((case when (`c`.`Modulo` = 'Suscripción DDA') then `c`.`Razon_Social_Receptor` else NULL end)) AS `Razon_Social_Suscripcion_DDA`,max((case when (`c`.`Modulo` = 'Suscripción DDA') then replace(`c`.`RUT_Receptor`,'.','') else NULL end)) AS `RUT_Suscripcion_DDA`,max((case when (`c`.`Modulo` = 'Suscripción DDA') then `c`.`Num_Factura` else NULL end)) AS `Nro_factura_suscripcion_DDA`,max((case when (`c`.`Modulo` = 'Suscripción DDA') then `c`.`Exento` else 0 end)) AS `Exento_suscripcion_DDA`,max((case when (`c`.`Modulo` = 'Suscripción DDA') then `c`.`Saldo` else 0 end)) AS `Saldo_suscripcion_DDA`,max((case when (`c`.`Modulo` = 'Suscripción DDA') then (`c`.`Exento` - `c`.`Saldo`) else 0 end)) AS `Abonado_suscripcion_DDA`,max((case when (`c`.`Modulo` = 'Cobranza') then `c`.`Razon_Social_Receptor` else NULL end)) AS `Razon_Social_Cobranza`,max((case when (`c`.`Modulo` = 'Cobranza') then replace(`c`.`RUT_Receptor`,'.','') else NULL end)) AS `RUT_Cobranza`,max((case when (`c`.`Modulo` = 'Cobranza') then `c`.`Num_Factura` else NULL end)) AS `Nro_factura_cobranza`,max((case when (`c`.`Modulo` = 'Cobranza') then `c`.`Exento` else 0 end)) AS `Exento_cobranza`,max((case when (`c`.`Modulo` = 'Cobranza') then `c`.`Saldo` else 0 end)) AS `Saldo_cobranza`,max((case when (`c`.`Modulo` = 'Cobranza') then (`c`.`Exento` - `c`.`Saldo`) else 0 end)) AS `Abonado_cobranza`,(case when (max((case when (`c`.`Modulo` = 'Suscripción DDA') then replace(`c`.`RUT_Receptor`,'.','') else NULL end)) = max((case when (`c`.`Modulo` = 'Cobranza') then replace(`c`.`RUT_Receptor`,'.','') else NULL end))) then 'RI' else 'RD' end) AS `Comparación_de_RUTs`,max((case when ((`c`.`Modulo` = 'Suscripción DDA') and (`c`.`contrato_firmado_SDDA` is not null)) then `c`.`contrato_firmado_SDDA` else NULL end)) AS `contrato_firmado_SDDA`,max(`c`.`Fecha_Emision`) AS `Fecha_Emision`,max(`c`.`Mes_Año`) AS `Mes_Año`,max(`c`.`Emitida_Recibida`) AS `Emitida_Recibida`,max(`c`.`movil`) AS `movil`,max(`c`.`movil_extra`) AS `movil_extra`,max(`c`.`email`) AS `email`,max(`c`.`dircliente`) AS `dircliente`,max(`c`.`comunacliente`) AS `comunacliente`,max(`c`.`ciudadcliente`) AS `ciudadcliente`,max(`c`.`estado_`) AS `estado_`,max(`c`.`banco`) AS `banco`,max(`c`.`ciaseguros`) AS `ciaseguros`,max(`c`.`montopresupuesto`) AS `montopresupuesto`,max(`c`.`fsismo`) AS `fsismo`,max(`c`.`tiposiniestro`) AS `tiposiniestro`,max(`c`.`tipopropiedad`) AS `tipopropiedad`,max(`c`.`ciudadcaso`) AS `ciudadcaso`,max(`c`.`comunacaso`) AS `comunacaso`,max(`c`.`direccionsiniestro`) AS `direccionsiniestro`,max(`c`.`mts2`) AS `mts2`,max(`c`.`ContratoFirmadoTexto`) AS `ContratoFirmadoTexto`,max(`c`.`MandatoFirmadoTexto`) AS `MandatoFirmadoTexto`,sum(`c`.`SaldoUnico`) AS `Total_Saldo` from (select distinct `crmcubic_crm_asesor`.`ClayCrm`.`id` AS `id`,`crmcubic_crm_asesor`.`crmclay_router`.`ncaso` AS `ncaso`,`crmcubic_crm_asesor`.`ClayCrm`.`Modulo` AS `Modulo`,`crmcubic_crm_asesor`.`ClayCrm`.`Num_Factura` AS `Num_Factura`,`crmcubic_crm_asesor`.`ClayCrm`.`Exento` AS `Exento`,`crmcubic_crm_asesor`.`ClayCrm`.`Razon_Social_Receptor` AS `Razon_Social_Receptor`,`crmcubic_crm_asesor`.`ClayCrm`.`RUT_Receptor` AS `RUT_Receptor`,ifnull(`crmcubic_crm_asesor`.`ClayCrm`.`Saldo`,0) AS `Saldo`,`crmcubic_crm_asesor`.`ClayCrm`.`Fecha_Emision` AS `Fecha_Emision`,`crmcubic_crm_asesor`.`ClayCrm`.`Mes_Año` AS `Mes_Año`,`crmcubic_crm_asesor`.`ClayCrm`.`Emitida_Recibida` AS `Emitida_Recibida`,`crmcubic_crm_asesor`.`vtiger_cliente`.`movil` AS `movil`,`crmcubic_crm_asesor`.`vtiger_cliente`.`movil_extra` AS `movil_extra`,`crmcubic_crm_asesor`.`vtiger_cliente`.`email` AS `email`,`crmcubic_crm_asesor`.`vtiger_cliente`.`dircliente` AS `dircliente`,`crmcubic_crm_asesor`.`vtiger_cliente`.`comunacliente` AS `comunacliente`,`crmcubic_crm_asesor`.`vtiger_cliente`.`ciudadcliente` AS `ciudadcliente`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`estado_` AS `estado_`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`banco` AS `banco`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`ciaseguros` AS `ciaseguros`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`montopresupuesto` AS `montopresupuesto`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`fsismo` AS `fsismo`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`tiposiniestro` AS `tiposiniestro`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`tipopropiedad` AS `tipopropiedad`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`ciudadcaso` AS `ciudadcaso`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`comunacaso` AS `comunacaso`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`direccionsiniestro` AS `direccionsiniestro`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`mts2` AS `mts2`,(case `crmcubic_crm_asesor`.`vtiger_siniestro`.`contratofirmado` when 1 then 'Sí' else 'No' end) AS `ContratoFirmadoTexto`,(case `crmcubic_crm_asesor`.`vtiger_siniestro`.`mandatofirmado` when 1 then 'Sí' else 'No' end) AS `MandatoFirmadoTexto`,(case `crmcubic_crm_asesor`.`vtiger_ventadedemandas`.`contratofirmado` when 1 then 'Sí' when 0 then 'No' end) AS `contrato_firmado_SDDA`,ifnull(`crmcubic_crm_asesor`.`ClayCrm`.`Saldo`,0) AS `SaldoUnico` from ((((`crmcubic_crm_asesor`.`crmclay_router` join `crmcubic_crm_asesor`.`ClayCrm` on((`crmcubic_crm_asesor`.`crmclay_router`.`ncaso` = `crmcubic_crm_asesor`.`ClayCrm`.`Nro_caso`))) join `crmcubic_crm_asesor`.`vtiger_siniestro` on((`crmcubic_crm_asesor`.`ClayCrm`.`Nro_caso` = `crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestro`))) join `crmcubic_crm_asesor`.`vtiger_cliente` on((`crmcubic_crm_asesor`.`vtiger_siniestro`.`nombrecliente` = `crmcubic_crm_asesor`.`vtiger_cliente`.`clienteid`))) left join `crmcubic_crm_asesor`.`vtiger_ventadedemandas` on((`crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestroid` = `crmcubic_crm_asesor`.`vtiger_ventadedemandas`.`idsiniestro`))) where ((`crmcubic_crm_asesor`.`crmclay_router`.`sus` = 0) and (`crmcubic_crm_asesor`.`crmclay_router`.`co` = 1) and (`crmcubic_crm_asesor`.`crmclay_router`.`dda` = 1))) `c` group by `c`.`ncaso` */;
/*!50001 DROP VIEW IF EXISTS `grillacontratos`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `grillacontratos` AS select `vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_cliente`.`nombre` AS `nombre`,`vtiger_cliente`.`apellido` AS `apellido`,`vtiger_cliente`.`cliente` AS `cliente`,`ingresos1_2019_grupo_santiago`.`calle_cliente` AS `calle_cliente`,`vtiger_cliente`.`comunacliente` AS `comunacliente`,`vtiger_cliente`.`ciudadcliente` AS `ciudadcliente`,`vtiger_cliente`.`tlfparticular` AS `tlfparticular`,`vtiger_cliente`.`movil` AS `movil`,`ingresos1_2019_grupo_santiago`.`dia` AS `dia`,`ingresos1_2019_grupo_santiago`.`mes` AS `mes`,`ingresos1_2019_grupo_santiago`.`ano` AS `ano`,`vtiger_cliente`.`email` AS `email`,`ingresos1_2019_grupo_santiago`.`tipo_propiedad` AS `tipo_propiedad`,`ingresos1_2019_grupo_santiago`.`calle_caso` AS `calle_caso`,`ingresos1_2019_grupo_santiago`.`comuna_caso` AS `comuna_caso`,`ingresos1_2019_grupo_santiago`.`provincia_caso` AS `provincia_caso`,`ingresos1_2019_grupo_santiago`.`banco` AS `banco`,`ingresos1_2019_grupo_santiago`.`tipo_siniestro` AS `tipo_siniestro`,`ingresos1_2019_grupo_santiago`.`valor_total_del_servicio` AS `valor_total_del_servicio`,`ingresos1_2019_grupo_santiago`.`abono` AS `abono`,`ingresos1_2019_grupo_santiago`.`nro_de_cuotas` AS `nro_de_cuotas`,`ingresos1_2019_grupo_santiago`.`valor_de_cuotas` AS `valor_de_cuotas`,`ingresos1_2019_grupo_santiago`.`dias_pago` AS `dias_pago`,`ingresos1_2019_grupo_santiago`.`Estado_sms_mati` AS `Estado_sms_mati`,`ingresos1_2019_grupo_santiago`.`Estado_mati` AS `Estado_mati`,`ingresos1_2019_grupo_santiago`.`Estado_sms_firma` AS `Estado_sms_firma`,`ingresos1_2019_grupo_santiago`.`Estado_Firma` AS `Estado_Firma`,`ingresos1_2019_grupo_santiago`.`fecha_contrato` AS `fecha_contrato`,`vtiger_siniestro`.`captador` AS `captador`,`vtiger_siniestro`.`fcontratofirmado` AS `fcontratofirmado` from ((`ingresos1_2019_grupo_santiago` join `vtiger_siniestro` on((`vtiger_siniestro`.`siniestro` = convert(`ingresos1_2019_grupo_santiago`.`id` using utf8)))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) */;
/*!50001 DROP VIEW IF EXISTS `inf_suscripcionDDA`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `inf_suscripcionDDA` AS select `vtiger_suscripciondemanda`.`suscripciondemandaid` AS `suscripciondemandaid`,`vtiger_cliente`.`cliente` AS `cliente`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Nombre`,`vtiger_suscripciondemanda`.`estadocomercialdda` AS `estadocomercialdda`,`vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_suscripciondemanda`.`valorplan` AS `valorplan`,`vtiger_suscripciondemanda`.`nrofactura` AS `nrofactura`,`vtiger_suscripciondemanda`.`fechaemifact` AS `fechaemifact`,`vtiger_suscripciondemanda`.`facturasusddapagada` AS `facturasusddapagada`,`vtiger_suscripciondemanda`.`nrocuotas` AS `nrocuotas`,`vtiger_suscripciondemanda`.`valorcuotas` AS `valorcuotas`,`vtiger_suscripciondemanda`.`valorcuota1dda` AS `valorcuota1dda`,`vtiger_suscripciondemanda`.`cuotaunoddapagada` AS `cuotaunoddapagada`,`vtiger_suscripciondemanda`.`valorcuotadosdda` AS `valorcuotadosdda`,`vtiger_suscripciondemanda`.`cuotadospagada` AS `cuotadospagada`,`vtiger_suscripciondemanda`.`valorcuotatresdda` AS `valorcuotatresdda`,`vtiger_suscripciondemanda`.`cuotatrespagada` AS `cuotatrespagada` from ((`vtiger_suscripciondemanda` join `vtiger_siniestro` on((`vtiger_suscripciondemanda`.`siniestroid` = `vtiger_siniestro`.`siniestroid`))) join `vtiger_cliente` on((`vtiger_suscripciondemanda`.`clienteid` = `vtiger_cliente`.`clienteid`))) */;
/*!50001 DROP VIEW IF EXISTS `info_demandacomercial`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `info_demandacomercial` AS select concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Demandante`,`vtiger_cliente`.`cliente` AS `Rut`,`vtiger_demandacomercial`.`ddo` AS `ddo`,`vtiger_demandacomercial`.`caratula` AS `caratula`,`vtiger_demandacomercial`.`rol` AS `rol`,`vtiger_demandacomercial`.`estadodda` AS `estadodda`,`vtiger_demandacomercial`.`tribunal` AS `tribunal`,`vtiger_demandacomercial`.`abogadoasignado` AS `abogadoasignado`,`vtiger_demandacomercial`.`mesasignacion` AS `mesasignacion`,`vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_demandacomercial`.`suscripcionddaid` AS `suscripcionddaid`,`vtiger_demandacomercial`.`ventadedemandasid` AS `ventadedemandasid` from ((`vtiger_demandacomercial` join `vtiger_siniestro` on((`vtiger_demandacomercial`.`siniestro` = `vtiger_siniestro`.`siniestroid`))) join `vtiger_cliente` on((`vtiger_demandacomercial`.`demandadoid` = `vtiger_cliente`.`clienteid`))) */;
/*!50001 DROP VIEW IF EXISTS `lista_validados_mati`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `lista_validados_mati` AS select `grillacontratos`.`siniestro` AS `siniestro`,`grillacontratos`.`nombre` AS `nombre`,`grillacontratos`.`apellido` AS `apellido`,`grillacontratos`.`cliente` AS `cliente`,`grillacontratos`.`calle_cliente` AS `calle_cliente`,`grillacontratos`.`comunacliente` AS `comunacliente`,`grillacontratos`.`ciudadcliente` AS `ciudadcliente`,`grillacontratos`.`tlfparticular` AS `tlfparticular`,`grillacontratos`.`movil` AS `movil`,`grillacontratos`.`dia` AS `dia`,`grillacontratos`.`mes` AS `mes`,`grillacontratos`.`ano` AS `ano`,`grillacontratos`.`email` AS `email`,`grillacontratos`.`tipo_propiedad` AS `tipo_propiedad`,`grillacontratos`.`calle_caso` AS `calle_caso`,`grillacontratos`.`comuna_caso` AS `comuna_caso`,`grillacontratos`.`provincia_caso` AS `provincia_caso`,`grillacontratos`.`banco` AS `banco`,`grillacontratos`.`tipo_siniestro` AS `tipo_siniestro`,`grillacontratos`.`valor_total_del_servicio` AS `valor_total_del_servicio`,`grillacontratos`.`abono` AS `abono`,`grillacontratos`.`nro_de_cuotas` AS `nro_de_cuotas`,`grillacontratos`.`valor_de_cuotas` AS `valor_de_cuotas`,`grillacontratos`.`dias_pago` AS `dias_pago`,`grillacontratos`.`Estado_sms_mati` AS `Estado_sms_mati`,`grillacontratos`.`Estado_mati` AS `Estado_mati`,`grillacontratos`.`Estado_sms_firma` AS `Estado_sms_firma`,`grillacontratos`.`Estado_Firma` AS `Estado_Firma`,`grillacontratos`.`fecha_contrato` AS `fecha_contrato`,`grillacontratos`.`captador` AS `captador`,`grillacontratos`.`fcontratofirmado` AS `fcontratofirmado`,`mai2`.`estatus` AS `estatus` from (`grillacontratos` join `mai2` on((`grillacontratos`.`cliente` = `mai2`.`rut`))) */;
/*!50001 DROP VIEW IF EXISTS `pagos_ASL`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `pagos_ASL` AS select `vtiger_ventadedemandas`.`ventadedemandasid` AS `id`,`vtiger_ventadedemandas`.`idsiniestro` AS `idsiniestro`,`vtiger_ventadedemandas`.`estadocobranza` AS `estadocobranza`,`vtiger_ventadedemandas`.`estadocomercialdda` AS `estadocomercialdda`,`vtiger_ventadedemandas`.`montorecuperarclp` AS `montorecuperarclp`,`vtiger_ventadedemandas`.`porcentajeapagar` AS `porcentajeapagar`,`vtiger_cliente`.`movil` AS `fono`,`vtiger_cliente`.`email` AS `correo`,`vtiger_ventadedemandas`.`estadollamada` AS `estadollamada`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Nombre`,`vtiger_ventadedemandas`.`actualizar` AS `actualizar`,`vtiger_ventadedemandas`.`fechadenuncia` AS `fechadenuncia`,`vtiger_ventadedemandas`.`clienteid` AS `clienteid`,`vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_users`.`user_name` AS `user_name`,`vtiger_ventadedemandas`.`contratofirmado` AS `contratofirmado`,`vtiger_siniestro`.`creadaaslegal` AS `creadaaslegal`,`vtiger_ventadedemandas`.`planaslegal` AS `planaslegal`,`vtiger_suscripciondemanda`.`nrofactura` AS `nrofactura`,`vtiger_suscripciondemanda`.`nrocuotas` AS `nrocuotas`,`vtiger_suscripciondemanda`.`cuotaunoddapagada` AS `cuotaunoddapagada`,`vtiger_suscripciondemanda`.`fechacuotaunopagada` AS `fechacuotaunopagada`,`vtiger_suscripciondemanda`.`fechavencimientocuotauno` AS `fechavencimientocuotauno`,`vtiger_suscripciondemanda`.`cuotadospagada` AS `cuotadospagada`,`vtiger_suscripciondemanda`.`fechacuotadospagada` AS `fechacuotadospagada`,`vtiger_suscripciondemanda`.`fechavencimientocuotados` AS `fechavencimientocuotados`,`vtiger_suscripciondemanda`.`cuotatrespagada` AS `cuotatrespagada`,`vtiger_suscripciondemanda`.`fechacuotatrespagada` AS `fechacuotatrespagada`,`vtiger_suscripciondemanda`.`fechavencimientocuotatres` AS `fechavencimientocuotatres`,`vtiger_suscripciondemanda`.`valorcuota1dda` AS `valorcuota1dda`,`vtiger_suscripciondemanda`.`valorcuotadosdda` AS `valorcuotadosdda`,`vtiger_suscripciondemanda`.`valorcuotatresdda` AS `valorcuotatresdda`,`vtiger_cliente`.`cliente` AS `cliente`,`vtiger_suscripciondemanda`.`fechaemifact` AS `fechaemifact` from (((((`vtiger_ventadedemandas` join `vtiger_crmentity` on((`vtiger_ventadedemandas`.`ventadedemandasid` = `vtiger_crmentity`.`crmid`))) join `vtiger_cliente` on((`vtiger_ventadedemandas`.`clienteid` = `vtiger_cliente`.`clienteid`))) join `vtiger_siniestro` on((`vtiger_ventadedemandas`.`idsiniestro` = `vtiger_siniestro`.`siniestroid`))) join `vtiger_users` on((`vtiger_crmentity`.`smownerid` = `vtiger_users`.`id`))) join `vtiger_suscripciondemanda` on((`vtiger_ventadedemandas`.`ventadedemandasid` = `vtiger_suscripciondemanda`.`idventadedemanda`))) where (((`vtiger_ventadedemandas`.`estadocomercialdda` = 'Vendida') and (`vtiger_ventadedemandas`.`contratofirmado` <> 1)) or ((`vtiger_ventadedemandas`.`contratofirmado` = 1) and (`vtiger_siniestro`.`creadaaslegal` = 1) and (`vtiger_ventadedemandas`.`planaslegal` = 180000) and (`vtiger_crmentity`.`deleted` = 0))) order by `vtiger_ventadedemandas`.`ventadedemandasid` desc */;
/*!50001 DROP VIEW IF EXISTS `por_prcesar_dc`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `por_prcesar_dc` AS select `vtiger_siniestro`.`siniestroid` AS `ID_CASO`,`vtiger_cliente`.`clienteid` AS `ID_CLIENTE`,`vtiger_siniestro`.`siniestro` AS `NRO_CASO`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `NOMBRE`,`vtiger_cliente`.`cliente` AS `RUT`,`vtiger_cliente`.`email` AS `EMAIL`,`vtiger_siniestro`.`entliquidadora` AS `ENT_LIQUIDADORA`,`vtiger_siniestro`.`ciaseguros` AS `CIA_DE_SEGUROS`,`vtiger_cliente`.`movil` AS `MOVIL`,`vtiger_demandacolectiva`.`demandacolectivaid` AS `ID_DC`,`vtiger_demandacolectiva`.`contratofirmado` AS `DC_FIRMADO`,`vtiger_crmentity`.`deleted` AS `deleted` from (((`vtiger_siniestro` join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) join `vtiger_demandacolectiva` on((`vtiger_siniestro`.`siniestroid` = `vtiger_demandacolectiva`.`idsiniestro`))) join `vtiger_crmentity` on((`vtiger_demandacolectiva`.`demandacolectivaid` = `vtiger_crmentity`.`crmid`))) where (`vtiger_crmentity`.`deleted` = 0) */;
/*!50001 DROP VIEW IF EXISTS `porsuscribir_all`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `porsuscribir_all` AS select concat(`crmcubic_crm_asesor`.`vtiger_cliente`.`nombre`,' ',`crmcubic_crm_asesor`.`vtiger_cliente`.`apellido`) AS `Clinete`,`count_sus`.`cliente` AS `Rut`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`captador` AS `Captador`,`count_sus`.`Count_sus` AS `Suscripcion_sini_VGTE`,`count_sus`.`clienteid` AS `Clinete_id`,`crmcubic_crm_asesor`.`vtiger_suscripcion`.`ffactura` AS `Fecha_Factura`,`crmcubic_crm_asesor`.`vtiger_cliente`.`movil` AS `telefono`,`crmcubic_crm_asesor`.`vtiger_cliente`.`email` AS `email`,`crmcubic_crm_asesor`.`vtiger_users`.`user_name` AS `usercrm`,(select `crmcubic_fintoc`.`fintoc_transact_det_sus`.`status_subscription_sus_ftds` from `crmcubic_fintoc`.`fintoc_transact_det_sus` where ((`crmcubic_fintoc`.`fintoc_transact_det_sus`.`status_subscription_sus_ftds` in ('active','pending','canceled')) and (`crmcubic_fintoc`.`fintoc_transact_det_sus`.`holder_id_account_sus_ftds` = replace(`crmcubic_crm_asesor`.`vtiger_cliente`.`cliente`,'-','')))) AS `status_sus` from (((((`crmcubic_crm_asesor`.`vtiger_siniestro` join `crmcubic_crm_asesor`.`vtiger_crmentity` on((`crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestroid` = `crmcubic_crm_asesor`.`vtiger_crmentity`.`crmid`))) join `crmcubic_crm_asesor`.`vtiger_users` on((`crmcubic_crm_asesor`.`vtiger_crmentity`.`smownerid` = `crmcubic_crm_asesor`.`vtiger_users`.`id`))) join `crmcubic_crm_asesor`.`vtiger_suscripcion` on((`crmcubic_crm_asesor`.`vtiger_suscripcion`.`siniestro` = `crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestroid`))) join `crmcubic_crm_asesor`.`count_sus` on((`count_sus`.`clienteid` = `crmcubic_crm_asesor`.`vtiger_suscripcion`.`nombrecliente`))) join `crmcubic_crm_asesor`.`vtiger_cliente` on((`count_sus`.`clienteid` = `crmcubic_crm_asesor`.`vtiger_cliente`.`clienteid`))) order by `status_sus` desc */;
/*!50001 DROP VIEW IF EXISTS `porsuscrinir_all_2`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `porsuscrinir_all_2` AS select concat(`crmcubic_crm_asesor`.`vtiger_cliente`.`nombre`,' ',`crmcubic_crm_asesor`.`vtiger_cliente`.`apellido`) AS `Clinete`,`count_sus`.`cliente` AS `Rut`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`captador` AS `Captador`,`count_sus`.`Count_sus` AS `Suscripcion_sini_VGTE`,`count_sus`.`clienteid` AS `Clinete_id`,`crmcubic_crm_asesor`.`vtiger_suscripcion`.`ffactura` AS `Fecha_Factura`,`crmcubic_crm_asesor`.`vtiger_cliente`.`movil` AS `telefono`,`crmcubic_crm_asesor`.`vtiger_cliente`.`email` AS `email`,`crmcubic_crm_asesor`.`vtiger_users`.`user_name` AS `usercrm`,(select `crmcubic_fintoc`.`fintoc_transact_det_sus`.`status_subscription_sus_ftds` from `crmcubic_fintoc`.`fintoc_transact_det_sus` where ((`crmcubic_fintoc`.`fintoc_transact_det_sus`.`status_subscription_sus_ftds` in ('active','pending','canceled')) and (`crmcubic_fintoc`.`fintoc_transact_det_sus`.`holder_id_account_sus_ftds` = replace(`crmcubic_crm_asesor`.`vtiger_cliente`.`cliente`,'-','')))) AS `status_sus`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestro` AS `Ncaso`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`estado_` AS `estado_caso` from (((((`crmcubic_crm_asesor`.`vtiger_siniestro` join `crmcubic_crm_asesor`.`vtiger_crmentity` on((`crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestroid` = `crmcubic_crm_asesor`.`vtiger_crmentity`.`crmid`))) join `crmcubic_crm_asesor`.`vtiger_users` on((`crmcubic_crm_asesor`.`vtiger_crmentity`.`smownerid` = `crmcubic_crm_asesor`.`vtiger_users`.`id`))) join `crmcubic_crm_asesor`.`vtiger_suscripcion` on((`crmcubic_crm_asesor`.`vtiger_suscripcion`.`siniestro` = `crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestroid`))) join `crmcubic_crm_asesor`.`count_sus` on((`count_sus`.`clienteid` = `crmcubic_crm_asesor`.`vtiger_suscripcion`.`nombrecliente`))) join `crmcubic_crm_asesor`.`vtiger_cliente` on((`count_sus`.`clienteid` = `crmcubic_crm_asesor`.`vtiger_cliente`.`clienteid`))) order by `status_sus` desc */;
/*!50001 DROP VIEW IF EXISTS `rep_audi`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`cubic`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `rep_audi` AS select `vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_suscripcion`.`nrofactura` AS `nrofactura`,`vtiger_siniestro`.`direccionsiniestro` AS `direccionsiniestro`,`vtiger_siniestro`.`comunacaso` AS `comunacaso`,`vtiger_suscripcion`.`valortotal` AS `valortotal`,`vtiger_cliente`.`clienteid` AS `clienteid`,`vtiger_suscripcion`.`fpagoabono` AS `fpagoabono`,`vtiger_suscripcion`.`valorcuota` AS `valorcuota`,`vtiger_suscripcion`.`abono` AS `abono`,`vtiger_suscripcion`.`primeracuota` AS `primeracuota`,`vtiger_suscripcion`.`segundacuota` AS `segundacuota`,`vtiger_suscripcion`.`1cuotapagada` AS `1cuotapagada`,`vtiger_suscripcion`.`2cuotapagada` AS `2cuotapagada`,`vtiger_suscripcion`.`nrocuotas` AS `nrocuotas`,`vtiger_suscripcion`.`suscripcionid` AS `suscripcionid`,`vtiger_suscripcion`.`number` AS `number`,`vtiger_suscripcion`.`captador` AS `captador`,`vtiger_cliente`.`nombre` AS `nombre`,`vtiger_cliente`.`apellido` AS `apellido`,`vtiger_suscripcion`.`diaspago` AS `diaspago`,`vtiger_suscripcion`.`facturapagada` AS `facturapagada`,`vtiger_suscripcion`.`ven1cuota` AS `ven1cuota`,`vtiger_suscripcion`.`ffactura` AS `ffactura`,`vtiger_suscripcion`.`ffacturapagada` AS `ffacturapagada`,`vtiger_suscripcion`.`abonopagado` AS `abonopagado`,`vtiger_suscripcion`.`matclayabo` AS `matclayabo`,`vtiger_suscripcion`.`codwebpayabono` AS `codwebpayabono`,`vtiger_suscripcion`.`fechadelabono` AS `fechadelabono`,`vtiger_suscripcion`.`tpagoabono` AS `tpagoabono`,`vtiger_suscripcion`.`banco` AS `banco`,`vtiger_suscripcion`.`nrocuenta` AS `nrocuenta`,`vtiger_suscripcion`.`tipocuenta` AS `tipocuenta`,`vtiger_suscripcion`.`sucursal` AS `sucursal`,`vtiger_suscripcion`.`tpago1cuota` AS `tpago1cuota`,`vtiger_suscripcion`.`fven1` AS `fven1`,`vtiger_suscripcion`.`f1cuotapagada` AS `f1cuotapagada`,`vtiger_suscripcion`.`bdpago1cuota` AS `bdpago1cuota`,`vtiger_suscripcion`.`tpago2cuota` AS `tpago2cuota`,`vtiger_suscripcion`.`fven2` AS `fven2`,`vtiger_suscripcion`.`f2cuotapagada` AS `f2cuotapagada`,`vtiger_suscripcion`.`bdpago2cuota` AS `bdpago2cuota`,`vtiger_suscripcion`.`bdpago` AS `bdpago`,`vtiger_suscripcion`.`codwebpaycuota1` AS `codwebpaycuota1`,`vtiger_suscripcion`.`codwebpaycuota2` AS `codwebpaycuota2`,`vtiger_suscripcion`.`tarjpagoabono` AS `tarjpagoabono`,`vtiger_suscripcion`.`tarjpagocuota1` AS `tarjpagocuota1`,`vtiger_suscripcion`.`tarjpagocuota2` AS `tarjpagocuota2`,`vtiger_suscripcion`.`matclayuno` AS `matclayuno`,`vtiger_suscripcion`.`matchclaydos` AS `matchclaydos` from ((`vtiger_cliente` join `vtiger_suscripcion` on((`vtiger_cliente`.`clienteid` = `vtiger_suscripcion`.`nombrecliente`))) join `vtiger_siniestro` on((`vtiger_suscripcion`.`siniestro` = `vtiger_siniestro`.`siniestroid`))) */;
/*!50001 DROP VIEW IF EXISTS `rep_vista_1_asl`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `rep_vista_1_asl` AS select `vtiger_siniestro`.`siniestro` AS `Nro_caso`,`vtiger_siniestro`.`fecha_siniestro` AS `Fecha_caso`,`vtiger_siniestro`.`fvisita` AS `Fecha_visita_caso`,`vtiger_siniestro`.`fdenuncio` AS `Fecha_denuncio_caso`,`vtiger_siniestro`.`indemnizacion` AS `Monto_Indemnizacion_caso`,`vtiger_siniestro`.`estado_` AS `Estado_caso`,`vtiger_crmentity`.`createdtime` AS `Fecha_creasion_caso`,`vtiger_paymentsin`.`nrofactura` AS `Nro_factura_cobranza`,`vtiger_paymentsin`.`valorfactura` AS `Valor_factura_cobranza`,`vtiger_paymentsin`.`ffactura` AS `Fecha_factura_cobranza`,`vtiger_paymentsin`.`facturapagada` AS `Factura_pagada_cobranza`,`vtiger_paymentsin`.`fpagofactura` AS `Fecha_pago_factura_cobranza`,`vtiger_paymentsin`.`bancopago` AS `Banco_pago_cobranza`,`vtiger_paymentsin`.`tipopago` AS `Tipo_pago_cobranza`,`vtiger_paymentsin`.`paymentsin_status` AS `Estado_cobranza`,`vtiger_suscripcion`.`estado` AS `Estado_suscripcion_siniestro`,`vtiger_suscripcion`.`valortotal` AS `Valor_total_suscripcion`,`vtiger_suscripcion`.`nrocuotas` AS `Nro_cuotas_suscripcion`,`vtiger_suscripcion`.`nrofactura` AS `Nro_factura_suscripcion`,`vtiger_suscripcion`.`ffactura` AS `Fecha_factura_suscripcion`,`vtiger_suscripcion`.`abonopagado` AS `Abono_pagado_suscripcion`,`vtiger_suscripcion`.`1cuotapagada` AS `Cuota1_pagada_suscripcion`,`vtiger_suscripcion`.`2cuotapagada` AS `Cuota2_pagada_suscripcion`,`vtiger_cliente`.`cliente` AS `Rut_cliente`,`vtiger_cliente`.`nombre` AS `Nombre_cliente`,`vtiger_cliente`.`apellido` AS `Apellido_cliente`,`vtiger_cliente`.`movil` AS `Movil_cliente`,`vtiger_cliente`.`movil_extra` AS `Movil_extra_cliente`,`vtiger_cliente`.`email` AS `Email_cliente`,`vtiger_cliente`.`comunacliente` AS `Comuna_cliente`,`vtiger_siniestro`.`siniestroid` AS `idsini` from ((((`vtiger_siniestro` join `vtiger_paymentsin` on((`vtiger_siniestro`.`siniestroid` = `vtiger_paymentsin`.`nrosiniestro`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) join `vtiger_suscripcion` on((`vtiger_siniestro`.`siniestroid` = `vtiger_suscripcion`.`siniestro`))) join `vtiger_crmentity` on((`vtiger_siniestro`.`siniestroid` = `vtiger_crmentity`.`crmid`))) where ((`vtiger_siniestro`.`estado_` = 'Informe liq para impugnar PR') or (`vtiger_siniestro`.`estado_` = 'Informe de liq Impugnado PR') or (`vtiger_siniestro`.`estado_` = 'Revision Resp. Imp. PR')) */;
/*!50001 DROP VIEW IF EXISTS `rep_vista_2_asl`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `rep_vista_2_asl` AS select `rep_vista_1_asl`.`Nro_caso` AS `Nro_caso`,`rep_vista_1_asl`.`Fecha_caso` AS `Fecha_caso`,`rep_vista_1_asl`.`Fecha_visita_caso` AS `Fecha_visita_caso`,`rep_vista_1_asl`.`Fecha_denuncio_caso` AS `Fecha_denuncio_caso`,`rep_vista_1_asl`.`Monto_Indemnizacion_caso` AS `Monto_Indemnizacion_caso`,`rep_vista_1_asl`.`Estado_caso` AS `Estado_caso`,`rep_vista_1_asl`.`Fecha_creasion_caso` AS `Fecha_creasion_caso`,`rep_vista_1_asl`.`Nro_factura_cobranza` AS `Nro_factura_cobranza`,`rep_vista_1_asl`.`Valor_factura_cobranza` AS `Valor_factura_cobranza`,`rep_vista_1_asl`.`Fecha_factura_cobranza` AS `Fecha_factura_cobranza`,`rep_vista_1_asl`.`Factura_pagada_cobranza` AS `Factura_pagada_cobranza`,`rep_vista_1_asl`.`Fecha_pago_factura_cobranza` AS `Fecha_pago_factura_cobranza`,`rep_vista_1_asl`.`Banco_pago_cobranza` AS `Banco_pago_cobranza`,`rep_vista_1_asl`.`Tipo_pago_cobranza` AS `Tipo_pago_cobranza`,`rep_vista_1_asl`.`Estado_cobranza` AS `Estado_cobranza`,`rep_vista_1_asl`.`Estado_suscripcion_siniestro` AS `Estado_suscripcion_siniestro`,`rep_vista_1_asl`.`Valor_total_suscripcion` AS `Valor_total_suscripcion`,`rep_vista_1_asl`.`Nro_cuotas_suscripcion` AS `Nro_cuotas_suscripcion`,`rep_vista_1_asl`.`Nro_factura_suscripcion` AS `Nro_factura_suscripcion`,`rep_vista_1_asl`.`Fecha_factura_suscripcion` AS `Fecha_factura_suscripcion`,`rep_vista_1_asl`.`Abono_pagado_suscripcion` AS `Abono_pagado_suscripcion`,`rep_vista_1_asl`.`Cuota1_pagada_suscripcion` AS `Cuota1_pagada_suscripcion`,`rep_vista_1_asl`.`Cuota2_pagada_suscripcion` AS `Cuota2_pagada_suscripcion`,`rep_vista_1_asl`.`Rut_cliente` AS `Rut_cliente`,`rep_vista_1_asl`.`Nombre_cliente` AS `Nombre_cliente`,`rep_vista_1_asl`.`Apellido_cliente` AS `Apellido_cliente`,`rep_vista_1_asl`.`Movil_cliente` AS `Movil_cliente`,`rep_vista_1_asl`.`Movil_extra_cliente` AS `Movil_extra_cliente`,`rep_vista_1_asl`.`Email_cliente` AS `Email_cliente`,`rep_vista_1_asl`.`Comuna_cliente` AS `Comuna_cliente`,`rep_vista_1_asl`.`idsini` AS `idsini` from (`rep_vista_1_asl` left join `vtiger_ventadedemandas` on((`rep_vista_1_asl`.`idsini` = `vtiger_ventadedemandas`.`idsiniestro`))) where isnull(`vtiger_ventadedemandas`.`idsiniestro`) */;
/*!50001 DROP VIEW IF EXISTS `rep_vista_3_asl`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `rep_vista_3_asl` AS select `rep_vista_1_asl`.`Nro_caso` AS `Nro_caso`,`rep_vista_1_asl`.`Fecha_caso` AS `Fecha_caso`,`rep_vista_1_asl`.`Fecha_visita_caso` AS `Fecha_visita_caso`,`rep_vista_1_asl`.`Fecha_denuncio_caso` AS `Fecha_denuncio_caso`,`rep_vista_1_asl`.`Monto_Indemnizacion_caso` AS `Monto_Indemnizacion_caso`,`rep_vista_1_asl`.`Estado_caso` AS `Estado_caso`,`rep_vista_1_asl`.`Fecha_creasion_caso` AS `Fecha_creasion_caso`,`rep_vista_1_asl`.`Nro_factura_cobranza` AS `Nro_factura_cobranza`,`rep_vista_1_asl`.`Valor_factura_cobranza` AS `Valor_factura_cobranza`,`rep_vista_1_asl`.`Fecha_factura_cobranza` AS `Fecha_factura_cobranza`,`rep_vista_1_asl`.`Factura_pagada_cobranza` AS `Factura_pagada_cobranza`,`rep_vista_1_asl`.`Fecha_pago_factura_cobranza` AS `Fecha_pago_factura_cobranza`,`rep_vista_1_asl`.`Banco_pago_cobranza` AS `Banco_pago_cobranza`,`rep_vista_1_asl`.`Tipo_pago_cobranza` AS `Tipo_pago_cobranza`,`rep_vista_1_asl`.`Estado_cobranza` AS `Estado_cobranza`,`rep_vista_1_asl`.`Estado_suscripcion_siniestro` AS `Estado_suscripcion_siniestro`,`rep_vista_1_asl`.`Valor_total_suscripcion` AS `Valor_total_suscripcion`,`rep_vista_1_asl`.`Nro_cuotas_suscripcion` AS `Nro_cuotas_suscripcion`,`rep_vista_1_asl`.`Nro_factura_suscripcion` AS `Nro_factura_suscripcion`,`rep_vista_1_asl`.`Fecha_factura_suscripcion` AS `Fecha_factura_suscripcion`,`rep_vista_1_asl`.`Abono_pagado_suscripcion` AS `Abono_pagado_suscripcion`,`rep_vista_1_asl`.`Cuota1_pagada_suscripcion` AS `Cuota1_pagada_suscripcion`,`rep_vista_1_asl`.`Cuota2_pagada_suscripcion` AS `Cuota2_pagada_suscripcion`,`rep_vista_1_asl`.`Rut_cliente` AS `Rut_cliente`,`rep_vista_1_asl`.`Nombre_cliente` AS `Nombre_cliente`,`rep_vista_1_asl`.`Apellido_cliente` AS `Apellido_cliente`,`rep_vista_1_asl`.`Movil_cliente` AS `Movil_cliente`,`rep_vista_1_asl`.`Movil_extra_cliente` AS `Movil_extra_cliente`,`rep_vista_1_asl`.`Email_cliente` AS `Email_cliente`,`rep_vista_1_asl`.`Comuna_cliente` AS `Comuna_cliente`,`rep_vista_1_asl`.`idsini` AS `idsini`,`vtiger_siniestro`.`perdidareclamada` AS `Pérdida_Reclamada_UF`,`vtiger_siniestro`.`perdidadeterminada` AS `Pérdida_Determinada_UF`,`vtiger_siniestro`.`deducibleafecto` AS `Deducible_Afecto`,`vtiger_siniestro`.`perdidaindemnizable` AS `Pérdida_Indemnizable`,`vtiger_siniestro`.`indemnizacion` AS `Indemnización_Pesos`,`vtiger_siniestro`.`valoruf` AS `Valor_UF`,`vtiger_siniestro`.`perdrecuperableuf` AS `Perdida_Recuperable_UF`,`vtiger_siniestro`.`perdrecuperablepesos` AS `Perdida_Recuperable_Pesos`,`vtiger_siniestro`.`informefacturado` AS `Informe_Facturado`,`vtiger_siniestro`.`observaciones` AS `Observaciones`,`vtiger_siniestro`.`fprobpagocia` AS `Fecha_Probable_de_pago`,'Sin Gestión' AS `Gestión`,'V' AS `Tipo` from ((`rep_vista_1_asl` left join `vtiger_ventadedemandas` on((`rep_vista_1_asl`.`idsini` = `vtiger_ventadedemandas`.`idsiniestro`))) join `vtiger_siniestro` on((`rep_vista_1_asl`.`idsini` = `vtiger_siniestro`.`siniestroid`))) where (isnull(`vtiger_ventadedemandas`.`idsiniestro`) = TRUE) */;
/*!50001 DROP VIEW IF EXISTS `rep_vista_4_150000_asl`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `rep_vista_4_150000_asl` AS select `vtiger_ventadedemandas`.`planaslegal` AS `planaslegal`,`vtiger_siniestro`.`siniestro` AS `Nro_Caso`,`vtiger_crmentity`.`createdtime` AS `Fecha_Creasion_Caso`,`vtiger_siniestro`.`estado_` AS `Estado_Caso`,`vtiger_siniestro`.`perdidareclamada` AS `Pérdida_Reclamada_UF`,`vtiger_siniestro`.`perdidadeterminada` AS `Pérdida_Determinada_UF`,`vtiger_siniestro`.`deducibleafecto` AS `Deducible_Afecto`,`vtiger_siniestro`.`perdidaindemnizable` AS `Pérdida_Indemnizable`,`vtiger_siniestro`.`indemnizacion` AS `Indemnización_Pesos`,`vtiger_siniestro`.`valoruf` AS `Valor_UF`,`vtiger_siniestro`.`perdrecuperableuf` AS `Perdida_Recuperable_UF`,`vtiger_siniestro`.`perdrecuperablepesos` AS `Perdida_Recuperable_Pesos`,`vtiger_siniestro`.`informefacturado` AS `Informe_Facturado`,`vtiger_siniestro`.`observaciones` AS `Observaciones`,`vtiger_siniestro`.`fprobpagocia` AS `Fecha_Probable_de_pago`,`vtiger_cliente`.`cliente` AS `Rut_Cliente`,`vtiger_cliente`.`nombre` AS `Nombre_Clinete`,`vtiger_cliente`.`apellido` AS `Apellido_cliente`,`vtiger_cliente`.`movil` AS `Movil_Cliente`,`vtiger_cliente`.`movil_extra` AS `Movil_Extra_Cliente`,`vtiger_cliente`.`email` AS `email`,`vtiger_siniestro`.`comunacaso` AS `Comuna_Cliente`,'G' AS `Tipo`,`vtiger_ventadedemandas`.`estadocomercialdda` AS `Gestion` from (((`vtiger_cliente` join `vtiger_siniestro` on((`vtiger_cliente`.`clienteid` = `vtiger_siniestro`.`nombrecliente`))) join `vtiger_crmentity` on((`vtiger_cliente`.`clienteid` = `vtiger_crmentity`.`crmid`))) join `vtiger_ventadedemandas` on((`vtiger_siniestro`.`siniestroid` = `vtiger_ventadedemandas`.`idsiniestro`))) where ((`vtiger_ventadedemandas`.`planaslegal` = '150000') and (`vtiger_siniestro`.`estado_` in ('Informe liq para impugnar PR','Informe de liq Impugnado PR','Revision Resp. Imp. PR'))) */;
/*!50001 DROP VIEW IF EXISTS `report`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`cubic`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `report` AS select `vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_suscripcion`.`nrofactura` AS `nrofactura`,`vtiger_siniestro`.`direccionsiniestro` AS `direccionsiniestro`,`vtiger_siniestro`.`comunacaso` AS `comunacaso`,`vtiger_suscripcion`.`valortotal` AS `valortotal`,`vtiger_cliente`.`clienteid` AS `clienteid`,`vtiger_suscripcion`.`fpagoabono` AS `fpagoabono`,`vtiger_suscripcion`.`valorcuota` AS `valorcuota`,`vtiger_suscripcion`.`abono` AS `abono`,`vtiger_suscripcion`.`primeracuota` AS `primeracuota`,`vtiger_suscripcion`.`segundacuota` AS `segundacuota`,`vtiger_suscripcion`.`1cuotapagada` AS `1cuotapagada`,`vtiger_suscripcion`.`2cuotapagada` AS `2cuotapagada`,`vtiger_suscripcion`.`nrocuotas` AS `nrocuotas`,`vtiger_suscripcion`.`suscripcionid` AS `suscripcionid` from ((`vtiger_cliente` join `vtiger_suscripcion` on((`vtiger_cliente`.`clienteid` = `vtiger_suscripcion`.`nombrecliente`))) join `vtiger_siniestro` on((`vtiger_suscripcion`.`siniestro` = `vtiger_siniestro`.`siniestroid`))) */;
/*!50001 DROP VIEW IF EXISTS `rev_clay_pagos_comision`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_crm_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `rev_clay_pagos_comision` AS select `Clay_comision_pagos`.`Nro_de_Caso_Caso_de_Siniestro` AS `Nro_de_Caso_Caso_de_Siniestro`,`Clay_comision_pagos`.`Nombre_del_Cliente_Caso_de_Siniestro` AS `Nombre_del_Cliente_Caso_de_Siniestro`,`Clay_comision_pagos`.`Valor_del_Plan_Suscripción` AS `Valor_del_Plan_Suscripción`,`Clay_comision_pagos`.`Captador_Caso_de_Siniestro` AS `Captador_Caso_de_Siniestro`,`Clay_comision_pagos`.`Fecha_de_creación_Caso_de_Siniestro` AS `Fecha_de_creación_Caso_de_Siniestro`,`Clay_comision_pagos`.`Tipo_de_Siniestro_Caso_de_Siniestro` AS `Tipo_de_Siniestro_Caso_de_Siniestro`,`Clay_comision_pagos`.`Contrato_Firmado_Caso_de_Siniestro` AS `Contrato_Firmado_Caso_de_Siniestro`,`Clay_comision_pagos`.`Abono_Pagado_Suscripción` AS `Abono_Pagado_Suscripción`,`Clay_comision_pagos`.`Fecha_de_Pago_Abono_Suscripción` AS `Fecha_de_Pago_Abono_Suscripción`,`Clay_comision_pagos`.`Nro_de_Factura_Suscripción` AS `Nro_de_Factura_Suscripción`,`Clay_comision_pagos`.`Valor_del_Plan_Caso_de_Siniestro` AS `Valor_del_Plan_Caso_de_Siniestro`,`Clay_comision_pagos`.`Comisión_Pagada_Caso_de_Siniestro` AS `Comisión_Pagada_Caso_de_Siniestro`,`Clay_comision_pagos`.`Fecha_Pago_Comisión_Caso_de_Siniestro` AS `Fecha_Pago_Comisión_Caso_de_Siniestro`,`Clay_comision_pagos`.`Ciudad_(Siniestro)_Caso_de_Siniestro` AS `Ciudad_(Siniestro)_Caso_de_Siniestro`,`ClayCrm_comision`.`Total` AS `Total`,`ClayCrm_comision`.`Saldo` AS `Saldo`,`vtiger_siniestro`.`fcontratofirmado` AS `fcontratofirmado`,`vtiger_siniestro`.`contratofirmado2` AS `contratofirmado2`,`vtiger_suscripcion`.`fpagoabono` AS `fpagoabono`,`vtiger_suscripcion`.`abonopagado` AS `abonopagado` from (((`ClayCrm_comision` join `Clay_comision_pagos` on((`ClayCrm_comision`.`Num_Factura` = `Clay_comision_pagos`.`Nro_de_Factura_Suscripción`))) join `vtiger_siniestro` on((`Clay_comision_pagos`.`Nro_de_Caso_Caso_de_Siniestro` = `vtiger_siniestro`.`siniestro`))) join `vtiger_suscripcion` on((`vtiger_siniestro`.`siniestroid` = `vtiger_suscripcion`.`siniestro`))) */;
/*!50001 DROP VIEW IF EXISTS `revision_visitas_simpirute`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `revision_visitas_simpirute` AS select `vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_siniestro`.`estado_` AS `estado_`,`vtiger_siniestro`.`confirmapreinspeccion` AS `confirmapreinspeccion`,`vtiger_siniestro`.`confirmainspeccion` AS `confirmainspeccion`,`det_maestro_Simplirute`.`id_sr` AS `id_sr`,`det_maestro_Simplirute`.`Nombre_plan_dms` AS `Nombre_plan_dms`,`det_maestro_Simplirute`.`start_date_dms` AS `start_date_dms` from ((`vtiger_siniestro` join `maestro_SimpliRute` on((`vtiger_siniestro`.`siniestro` = `maestro_SimpliRute`.`ID_de_referencia`))) join `det_maestro_Simplirute` on((`maestro_SimpliRute`.`id_m_sr` = `det_maestro_Simplirute`.`id_msr`))) */;
/*!50001 DROP VIEW IF EXISTS `sus_pac2`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `sus_pac2` AS select `Pac_suscripcion`.`Id_siniestro` AS `Id_siniestro`,`Pac_suscripcion`.`Id_suscripcion` AS `Id_suscripcion`,`Pac_suscripcion`.`Rut_Cliente` AS `Rut_Cliente`,`Pac_suscripcion`.`Nro_Caso` AS `Nro_Caso`,`Pac_suscripcion`.`Estado` AS `Estado`,`Pac_suscripcion`.`Monto_del_Presupuesto` AS `Monto_del_Presupuesto`,`Pac_suscripcion`.`Valor_Cuota` AS `Valor_Cuota`,`Pac_suscripcion`.`Dias_de_Pago` AS `Dias_de_Pago`,`Pac_suscripcion`.`Nro_Cuotas` AS `Nro_Cuotas`,`Pac_suscripcion`.`Valor_Abono` AS `Valor_Abono`,`Pac_suscripcion`.`Fecha_Ven_Abono` AS `Fecha_Ven_Abono`,`Pac_suscripcion`.`Fecha_Cargo_Pac_Abono` AS `Fecha_Cargo_Pac_Abono`,`Pac_suscripcion`.`Fecha_Transfer_abono_Fintoc` AS `Fecha_Transfer_abono_Fintoc`,`Pac_suscripcion`.`Abono_pagado` AS `Abono_pagado`,`Pac_suscripcion`.`Valor_Cuota_1` AS `Valor_Cuota_1`,`Pac_suscripcion`.`Fecha_Ven_Cuota_1` AS `Fecha_Ven_Cuota_1`,`Pac_suscripcion`.`Fecha_Cargo_Pac_Cuota_1` AS `Fecha_Cargo_Pac_Cuota_1`,`Pac_suscripcion`.`Fecha_Transfer_Cuota_1_Fintoc` AS `Fecha_Transfer_Cuota_1_Fintoc`,`Pac_suscripcion`.`Cuota_1_Pagada` AS `Cuota_1_Pagada`,`Pac_suscripcion`.`Valor_Cuota_2` AS `Valor_Cuota_2`,`Pac_suscripcion`.`Fecha_Ven_Cuota_2` AS `Fecha_Ven_Cuota_2`,`Pac_suscripcion`.`Fecha_Cargo_Pac_Cuota_2` AS `Fecha_Cargo_Pac_Cuota_2`,`Pac_suscripcion`.`Fecha_Transfer_Cuota_2_Fintoc` AS `Fecha_Transfer_Cuota_2_Fintoc`,`Pac_suscripcion`.`Cuota_2_Pagada` AS `Cuota_2_Pagada`,`Pac_suscripcion`.`Nro_Factura_Suscripcion` AS `Nro_Factura_Suscripcion`,`Pac_suscripcion`.`Fecha_Factura_Suscripcion` AS `Fecha_Factura_Suscripcion`,`Pac_suscripcion`.`Nombre_Cliente` AS `Nombre_Cliente`,`Pac_suscripcion`.`Valor_plan` AS `Valor_plan`,`Pac_suscripcion`.`Id_cliente` AS `Id_cliente`,(select `crmcubic_fintoc`.`fintoc_transact_det_sus`.`status_subscription_sus_ftds` from `crmcubic_fintoc`.`fintoc_transact_det_sus` where (`crmcubic_fintoc`.`fintoc_transact_det_sus`.`rut_cli` = `Pac_suscripcion`.`Rut_Cliente`)) AS `estado_sus`,`Pac_suscripcion`.`estadopac` AS `estadopac` from `crmcubic_crm_asesor`.`Pac_suscripcion` where (`Pac_suscripcion`.`estadopac` = 1) order by `estado_sus` desc */;
/*!50001 DROP VIEW IF EXISTS `suscripcionPac_ventademanda`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `suscripcionPac_ventademanda` AS select concat(`crmcubic_crm_asesor`.`vtiger_cliente`.`nombre`,' ',`crmcubic_crm_asesor`.`vtiger_cliente`.`apellido`) AS `Cliente`,`crmcubic_crm_asesor`.`vtiger_cliente`.`cliente` AS `Rut`,`crmcubic_crm_asesor`.`vtiger_cliente`.`movil` AS `Telefono`,`crmcubic_crm_asesor`.`vtiger_cliente`.`email` AS `Email`,concat(`crmcubic_crm_asesor`.`vtiger_users`.`first_name`,' ',`crmcubic_crm_asesor`.`vtiger_users`.`last_name`) AS `Captador`,`crmcubic_crm_asesor`.`vtiger_users`.`user_name` AS `user_ame`,`crmcubic_crm_asesor`.`vtiger_suscripciondemanda`.`fechaemifact` AS `fechaemifact`,(select `crmcubic_fintoc`.`fintoc_transact_det_sus`.`status_subscription_sus_ftds` from `crmcubic_fintoc`.`fintoc_transact_det_sus` where ((`crmcubic_fintoc`.`fintoc_transact_det_sus`.`status_subscription_sus_ftds` = 'pending') and (`crmcubic_fintoc`.`fintoc_transact_det_sus`.`holder_id_account_sus_ftds` = replace(`crmcubic_crm_asesor`.`vtiger_cliente`.`cliente`,'-','')))) AS `status_sus` from ((((`crmcubic_crm_asesor`.`vtiger_suscripciondemanda` join `crmcubic_crm_asesor`.`vtiger_crmentity` on((`crmcubic_crm_asesor`.`vtiger_suscripciondemanda`.`suscripciondemandaid` = `crmcubic_crm_asesor`.`vtiger_crmentity`.`crmid`))) join `crmcubic_crm_asesor`.`vtiger_users` on((`crmcubic_crm_asesor`.`vtiger_crmentity`.`smownerid` = `crmcubic_crm_asesor`.`vtiger_users`.`id`))) join `crmcubic_crm_asesor`.`vtiger_ventadedemandas` on((`crmcubic_crm_asesor`.`vtiger_ventadedemandas`.`ventadedemandasid` = `crmcubic_crm_asesor`.`vtiger_suscripciondemanda`.`idventadedemanda`))) join `crmcubic_crm_asesor`.`vtiger_cliente` on((`crmcubic_crm_asesor`.`vtiger_suscripciondemanda`.`clienteid` = `crmcubic_crm_asesor`.`vtiger_cliente`.`clienteid`))) where ((`crmcubic_crm_asesor`.`vtiger_crmentity`.`deleted` = 0) and (`crmcubic_crm_asesor`.`vtiger_suscripciondemanda`.`nrofactura` is not null) and (`crmcubic_crm_asesor`.`vtiger_suscripciondemanda`.`nrofactura` <> '') and (`crmcubic_crm_asesor`.`vtiger_suscripciondemanda`.`fechaemifact` is not null) and (`crmcubic_crm_asesor`.`vtiger_suscripciondemanda`.`fechaemifact` <> '') and (`crmcubic_crm_asesor`.`vtiger_ventadedemandas`.`contratofirmado` = 1)) */;
/*!50001 DROP VIEW IF EXISTS `toku_monflow_multiselect`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `toku_monflow_multiselect` AS select `vtiger_ventadedemandas`.`ventadedemandasid` AS `id`,`vtiger_users`.`user_name` AS `user_name`,concat(`vtiger_users`.`first_name`,' ',`vtiger_users`.`last_name`) AS `Vendedor`,`vtiger_cliente`.`cliente` AS `Rut`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Nombre`,`vtiger_siniestro`.`siniestro` AS `nro_caso`,`vtiger_suscripciondemanda`.`nrocuotas` AS `nro_cuotas`,`vtiger_cliente`.`movil` AS `movil`,`vtiger_cliente`.`email` AS `email`,`vtiger_ventadedemandas`.`planaslegal` AS `plan` from (((((`vtiger_ventadedemandas` join `vtiger_crmentity` on((`vtiger_ventadedemandas`.`ventadedemandasid` = `vtiger_crmentity`.`crmid`))) join `vtiger_users` on((`vtiger_users`.`id` = `vtiger_crmentity`.`smownerid`))) join `vtiger_cliente` on((`vtiger_ventadedemandas`.`clienteid` = `vtiger_cliente`.`clienteid`))) join `vtiger_siniestro` on((`vtiger_ventadedemandas`.`idsiniestro` = `vtiger_siniestro`.`siniestroid`))) join `vtiger_suscripciondemanda` on((`vtiger_ventadedemandas`.`ventadedemandasid` = `vtiger_suscripciondemanda`.`idventadedemanda`))) where ((`vtiger_ventadedemandas`.`planaslegal` = '180000') and (`vtiger_crmentity`.`deleted` = 0)) */;
/*!50001 DROP VIEW IF EXISTS `visitas_programas`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `visitas_programas` AS select `eventos_calendario_agendados`.`activityid` AS `activityid`,`eventos_calendario_agendados`.`subject` AS `subject`,`eventos_calendario_agendados`.`activitytype` AS `activitytype`,`eventos_calendario_agendados`.`date_start` AS `date_start`,`eventos_calendario_agendados`.`due_date` AS `due_date`,`eventos_calendario_agendados`.`status` AS `status`,`eventos_calendario_agendados`.`siniestro` AS `siniestro`,`eventos_calendario_agendados`.`comunacaso` AS `comunacaso`,`eventos_calendario_agendados`.`direccionsiniestro` AS `direccionsiniestro`,`eventos_calendario_agendados`.`latitud_sini` AS `latitud_sini`,`eventos_calendario_agendados`.`longitud_sini` AS `longitud_sini`,`eventos_calendario_agendados`.`nombrecliente` AS `nombrecliente`,`eventos_calendario_agendados`.`nrocaso` AS `nrocaso`,`eventos_calendario_agendados`.`cliente` AS `cliente`,`eventos_calendario_agendados`.`nombre` AS `nombre`,`eventos_calendario_agendados`.`apellido` AS `apellido`,`eventos_calendario_agendados`.`smcreatorid` AS `smcreatorid`,`eventos_calendario_agendados`.`smownerid` AS `smownerid`,`eventos_calendario_agendados`.`modifiedby` AS `modifiedby`,`eventos_calendario_agendados`.`createdtime` AS `createdtime`,`eventos_calendario_agendados`.`modifiedtime` AS `modifiedtime`,`eventos_calendario_agendados`.`Creado_por` AS `Creado_por`,`eventos_calendario_agendados`.`Asignado_a` AS `Asignado_a`,`eventos_calendario_agendados`.`Ultima_mod_por` AS `Ultima_mod_por`,`eventos_calendario_agendados`.`time_start` AS `time_start`,`eventos_calendario_agendados`.`time_end` AS `time_end`,`eventos_calendario_agendados`.`Estado_caso` AS `Estado_caso`,`eventos_calendario_agendados`.`movil` AS `movil`,`eventos_calendario_agendados`.`email` AS `email`,`eventos_calendario_agendados`.`captador` AS `captador` from `eventos_calendario_agendados` where (`eventos_calendario_agendados`.`status` = 'PLL_PLANNED') order by `eventos_calendario_agendados`.`createdtime` desc */;
/*!50001 DROP VIEW IF EXISTS `vista_casos_clientes`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `vista_casos_clientes` AS select `vtiger_siniestro`.`siniestroid` AS `siniestroid`,`vtiger_siniestro`.`siniestro` AS `siniestro`,concat(`vtiger_cliente`.`nombre`,' ',`vtiger_cliente`.`apellido`) AS `Nombre_Cliente`,`vtiger_siniestro`.`estado_` AS `estado_`,`vtiger_cliente`.`cliente` AS `cliente`,`vtiger_siniestro`.`comunacaso` AS `comunacaso`,`vtiger_crmentity`.`createdtime` AS `fecha_creacion`,`vtiger_cliente`.`movil` AS `Celular`,`vtiger_cliente`.`email` AS `Email`,`vtiger_siniestro`.`entliquidadora` AS `Entidad_Liquidadora`,`vtiger_siniestro`.`tiposiniestro` AS `Tipo_Siniestro` from ((`vtiger_siniestro` join `vtiger_cliente` on((`vtiger_cliente`.`clienteid` = `vtiger_siniestro`.`nombrecliente`))) join `vtiger_crmentity` on((`vtiger_siniestro`.`siniestroid` = `vtiger_crmentity`.`crmid`))) where ((`vtiger_siniestro`.`estado_` in ('Ingresado a CRM (CP)','Abierto (CP)','Preinspección a Reprogramar','Visita a Reprogramar','Liquidador Asignado')) and (`vtiger_crmentity`.`createdtime` >= '2021-01-01')) */;
/*!50001 DROP VIEW IF EXISTS `vista_casos_clientes_detalle`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `vista_casos_clientes_detalle` AS select `crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestroid` AS `siniestroid`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestro` AS `siniestro`,concat(`crmcubic_crm_asesor`.`vtiger_cliente`.`nombre`,' ',`crmcubic_crm_asesor`.`vtiger_cliente`.`apellido`) AS `Nombre_Cliente`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`estado_` AS `estado_`,`crmcubic_crm_asesor`.`vtiger_cliente`.`cliente` AS `cliente`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`comunacaso` AS `comunacaso`,`crmcubic_crm_asesor`.`vtiger_cliente`.`movil` AS `Celular`,`crmcubic_crm_asesor`.`vtiger_cliente`.`email` AS `Email`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`entliquidadora` AS `Entidad_Liquidadora`,`crmcubic_crm_asesor`.`vtiger_siniestro`.`tiposiniestro` AS `Tipo_Siniestro`,`crmcubic_tablas`.`Ingreso_crm`.`Rango_Horario_PREINSPECCION` AS `Rango_Horario_PREINSPECCION`,`crmcubic_tablas`.`Ingreso_crm`.`Dias_Disponibles_Preinspeccion` AS `Dias_Disponibles_Preinspeccion`,`crmcubic_tablas`.`Ingreso_crm`.`Bloquefecha1` AS `Bloquefecha1`,`crmcubic_tablas`.`Ingreso_crm`.`Bloquefecha2` AS `Bloquefecha2`,`crmcubic_tablas`.`Ingreso_crm`.`Lunes` AS `Lunes`,`crmcubic_tablas`.`Ingreso_crm`.`Martes` AS `Martes`,`crmcubic_tablas`.`Ingreso_crm`.`Miercoles` AS `Miercoles`,`crmcubic_tablas`.`Ingreso_crm`.`Jueves` AS `Jueves`,`crmcubic_tablas`.`Ingreso_crm`.`Viernes` AS `Viernes`,`crmcubic_tablas`.`Ingreso_crm`.`Coordenada_completa` AS `Coordenada_completa`,`crmcubic_tablas`.`Ingreso_crm`.`ejecutivo` AS `ejecutivo`,`crmcubic_tablas`.`Ingreso_crm`.`region_caso` AS `region_caso`,`crmcubic_tablas`.`Ingreso_crm`.`comuna_caso` AS `comuna_caso`,`crmcubic_tablas`.`Ingreso_crm`.`tipo_propiedad` AS `tipo_propiedad` from ((`crmcubic_crm_asesor`.`vtiger_siniestro` join `crmcubic_crm_asesor`.`vtiger_cliente` on((`crmcubic_crm_asesor`.`vtiger_cliente`.`clienteid` = `crmcubic_crm_asesor`.`vtiger_siniestro`.`nombrecliente`))) join `crmcubic_tablas`.`Ingreso_crm` on((`crmcubic_tablas`.`Ingreso_crm`.`id` = `crmcubic_crm_asesor`.`vtiger_siniestro`.`siniestro`))) where (`crmcubic_crm_asesor`.`vtiger_siniestro`.`estado_` in ('Ingresado a CRM (CP)','Abierto (CP)','Preinspección a Reprogramar','Visita a Reprogramar')) */;
/*!50001 DROP VIEW IF EXISTS `vista_gestionvendedor`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `vista_gestionvendedor` AS select `vtiger_campanasmktdigital`.`campanasmktdigitalid` AS `campanasmktdigitalid`,`vtiger_campanasmktdigital`.`id` AS `id`,`vtiger_campanasmktdigital`.`number` AS `number`,`vtiger_campanasmktdigital`.`tienescrehip` AS `tienescrehip`,`vtiger_campanasmktdigital`.`comuna` AS `comuna`,`vtiger_campanasmktdigital`.`nombrecompleto` AS `nombrecompleto`,`vtiger_campanasmktdigital`.`telefono` AS `telefono`,`vtiger_campanasmktdigital`.`correo` AS `correo`,`vtiger_campanasmktdigital`.`campana` AS `campana`,`vtiger_campanasmktdigital`.`conjuntodeanuncios` AS `conjuntodeanuncios`,`vtiger_campanasmktdigital`.`anuncio` AS `anuncio`,`vtiger_campanasmktdigital`.`mediodigital` AS `mediodigital`,`vtiger_campanasmktdigital`.`motivorechazo` AS `motivorechazo`,`vtiger_campanasmktdigital`.`fechaultimallamada` AS `fechaultimallamada`,`vtiger_campanasmktdigital`.`fechaproximallamada` AS `fechaproximallamada`,`vtiger_campanasmktdigital`.`estadolead` AS `estadolead`,`vtiger_campanasmktdigital`.`estadollamada` AS `estadollamada`,`vtiger_campanasmktdigital`.`codigocampana` AS `codigocampana`,`vtiger_campanasmktdigital`.`mescampana` AS `mescampana`,`vtiger_campanasmktdigital`.`anocampana` AS `anocampana`,`vtiger_campanasmktdigital`.`last_update` AS `last_update`,`vtiger_campanasmktdigital`.`idfacebook` AS `idfacebook`,`vtiger_campanasmktdigital`.`gestionadopor` AS `gestionadopor`,`vtiger_campanasmktdigital`.`obsrechazo` AS `obsrechazo`,`vtiger_campanasmktdigital`.`obslead` AS `obslead`,`vtiger_campanasmktdigital`.`fecha_asignado` AS `fecha_asignado`,`vtiger_campanasmktdigital`.`fecha_leads` AS `fecha_leads`,`vtiger_campanasmktdigital`.`leadan` AS `leadan`,`vtiger_campanasmktdigital`.`Gestion_leads` AS `Gestion_leads`,`vtiger_users`.`user_name` AS `user_name` from (`vtiger_campanasmktdigital` join `vtiger_users` on((`vtiger_campanasmktdigital`.`gestionadopor` = `vtiger_users`.`id`))) */;
/*!50001 DROP VIEW IF EXISTS `vista_sus_all_graf`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `vista_sus_all_graf` AS select `porsuscribir_all`.`Clinete` AS `Clinete`,`porsuscribir_all`.`Rut` AS `Rut`,`porsuscribir_all`.`telefono` AS `telefono`,`porsuscribir_all`.`email` AS `email`,`porsuscribir_all`.`Captador` AS `Captador`,`porsuscribir_all`.`Suscripcion_sini_VGTE` AS `Suscripcion_sini_VGTE`,`porsuscribir_all`.`Clinete_id` AS `Clinete_id`,`porsuscribir_all`.`Fecha_Factura` AS `Fecha_Factura`,`porsuscribir_all`.`status_sus` AS `status_sus`,concat(`crmcubic_crm_asesor`.`vtiger_users`.`first_name`,' ',`crmcubic_crm_asesor`.`vtiger_users`.`last_name`) AS `Captador_asignado` from (((`crmcubic_crm_asesor`.`porsuscribir_all` join `crmcubic_crm_asesor`.`vtiger_cliente` on((`porsuscribir_all`.`Rut` = `crmcubic_crm_asesor`.`vtiger_cliente`.`cliente`))) join `crmcubic_crm_asesor`.`asignacion_cli_user_PAC` on((`crmcubic_crm_asesor`.`asignacion_cli_user_PAC`.`idcliente` = `crmcubic_crm_asesor`.`vtiger_cliente`.`clienteid`))) join `crmcubic_crm_asesor`.`vtiger_users` on((`crmcubic_crm_asesor`.`asignacion_cli_user_PAC`.`user_crm` = `crmcubic_crm_asesor`.`vtiger_users`.`user_name`))) where ((`porsuscribir_all`.`Suscripcion_sini_VGTE` <> 0) and (`porsuscribir_all`.`Fecha_Factura` between (select `crmcubic_crm_asesor`.`config_sus_pac`.`Desde` from `crmcubic_crm_asesor`.`config_sus_pac` where ((`crmcubic_crm_asesor`.`config_sus_pac`.`id` = 11) and (`crmcubic_crm_asesor`.`config_sus_pac`.`Estado` = 1) and (`crmcubic_crm_asesor`.`config_sus_pac`.`id_mod` = 1))) and (select `crmcubic_crm_asesor`.`config_sus_pac`.`Hasta` from `crmcubic_crm_asesor`.`config_sus_pac` where ((`crmcubic_crm_asesor`.`config_sus_pac`.`id` = 11) and (`crmcubic_crm_asesor`.`config_sus_pac`.`Estado` = 1) and (`crmcubic_crm_asesor`.`config_sus_pac`.`id_mod` = 1))))) group by `porsuscribir_all`.`Rut` */;
/*!50001 DROP VIEW IF EXISTS `vistacaulculodeudas`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`crmcubic_asesor`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `vistacaulculodeudas` AS select `vtiger_siniestro`.`nombrecliente` AS `id_cliente`,`vtiger_suscripcion`.`ffactura` AS `Fecha_factura`,`vtiger_suscripcion`.`valortotal` AS `Valor_plan`,`vtiger_suscripcion`.`abono` AS `Abono`,`vtiger_suscripcion`.`nrofactura` AS `Nro_factura`,`vtiger_suscripcion`.`primeracuota` AS `Primera_cuota`,`vtiger_suscripcion`.`segundacuota` AS `Segunda_cuota`,`vtiger_suscripcion`.`nrocuotas` AS `Nro_cuotas`,`vtiger_suscripcion`.`abonopagado` AS `Abono_pagado`,`vtiger_suscripcion`.`1cuotapagada` AS `Pra_cuota_pagada`,`vtiger_suscripcion`.`2cuotapagada` AS `Sda_cuota_pagada`,`vtiger_siniestro`.`siniestro` AS `siniestro`,`vtiger_cliente`.`cliente` AS `cliente`,`vtiger_siniestro`.`estado_` AS `estado_`,`vtiger_cliente`.`nombre` AS `nombre`,`vtiger_cliente`.`apellido` AS `apellido` from ((`vtiger_siniestro` join `vtiger_suscripcion` on((`vtiger_siniestro`.`siniestroid` = `vtiger_suscripcion`.`siniestro`))) join `vtiger_cliente` on((`vtiger_siniestro`.`nombrecliente` = `vtiger_cliente`.`clienteid`))) */;
