text: -- phpMyAdmin SQL Dump
  -- version 5.1.1
  -- https://www.phpmyadmin.net/
  --
  -- Servidor: localhost:8889
  -- Tiempo de generación: 28-09-2021 a las 03:40:58
  -- Versión del servidor: 5.7.34
  -- Versión de PHP: 7.4.21
  
  SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
  START TRANSACTION;
  SET time_zone = "+00:00";
  
  
  /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
  /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
  /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
  /*!40101 SET NAMES utf8mb4 */;
  
  --
  -- Base de datos: `Clickealo`
  --
  
  -- --------------------------------------------------------
  
  --
  -- Estructura de tabla para la tabla `failed_jobs`
  --
  
  CREATE TABLE `failed_jobs` (
    `id` bigint(20) UNSIGNED NOT NULL,
    `connection` text COLLATE utf8mb4_unicode_ci NOT NULL,
    `queue` text COLLATE utf8mb4_unicode_ci NOT NULL,
    `payload` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
    `exception` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
    `failed_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  
  -- --------------------------------------------------------
  
  --
  -- Estructura de tabla para la tabla `migrations`
  --
  
  CREATE TABLE `migrations` (
    `id` int(10) UNSIGNED NOT NULL,
    `migration` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
    `batch` int(11) NOT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  
  --
  -- Volcado de datos para la tabla `migrations`
  --
  
  INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES
  (1, '2014_10_12_000000_create_users_table', 1),
  (2, '2014_10_12_100000_create_password_resets_table', 1),
  (3, '2019_08_19_000000_create_failed_jobs_table', 1),
  (4, '2021_09_27_155126_create_social_profiles_table', 1);
  
  -- --------------------------------------------------------
  
  --
  -- Estructura de tabla para la tabla `password_resets`
  --
  
  CREATE TABLE `password_resets` (
    `email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
    `token` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
    `created_at` timestamp NULL DEFAULT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  
  -- --------------------------------------------------------
  
  --
  -- Estructura de tabla para la tabla `social_profiles`
  --
  
  CREATE TABLE `social_profiles` (
    `id` bigint(20) UNSIGNED NOT NULL,
    `created_at` timestamp NULL DEFAULT NULL,
    `updated_at` timestamp NULL DEFAULT NULL,
    `user_id` bigint(20) UNSIGNED NOT NULL,
    `social_id` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
    `social_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
    `social_avatar` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  
  -- --------------------------------------------------------
  
  --
  -- Estructura de tabla para la tabla `users`
  --
  
  CREATE TABLE `users` (
    `id` bigint(20) UNSIGNED NOT NULL,
    `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
    `email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
    `email_verified_at` timestamp NULL DEFAULT NULL,
    `password` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
    `remember_token` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
    `created_at` timestamp NULL DEFAULT NULL,
    `updated_at` timestamp NULL DEFAULT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  
  -- --------------------------------------------------------
  
  --
  -- Estructura Stand-in para la vista `view_cliente_plan`
  -- (Véase abajo para la vista actual)
  --
  CREATE TABLE `view_cliente_plan` (
  );
  
  -- --------------------------------------------------------
  
  --
  -- Estructura Stand-in para la vista `view_count_respuesta_cliente`
  -- (Véase abajo para la vista actual)
  --
  CREATE TABLE `view_count_respuesta_cliente` (
  );
  
  -- --------------------------------------------------------
  
  --
  -- Estructura Stand-in para la vista `view_current_plan`
  -- (Véase abajo para la vista actual)
  --
  CREATE TABLE `view_current_plan` (
  );
  
  -- --------------------------------------------------------
  
  --
  -- Estructura Stand-in para la vista `view_iva`
  -- (Véase abajo para la vista actual)
  --
  CREATE TABLE `view_iva` (
  );
  
  -- --------------------------------------------------------
  
  --
  -- Estructura Stand-in para la vista `view_reservas`
  -- (Véase abajo para la vista actual)
  --
  CREATE TABLE `view_reservas` (
  );
  
  -- --------------------------------------------------------
  
  --
  -- Estructura Stand-in para la vista `view_sum_nota_cliente_producto`
  -- (Véase abajo para la vista actual)
  --
  CREATE TABLE `view_sum_nota_cliente_producto` (
  );
  
  -- --------------------------------------------------------
  
  --
  -- Estructura para la vista `view_cliente_plan`
  --
  DROP TABLE IF EXISTS `view_cliente_plan`;
  
  CREATE ALGORITHM=UNDEFINED DEFINER=`clickeal`@`localhost` SQL SECURITY DEFINER VIEW `view_cliente_plan`  AS SELECT `a`.`id` AS `id_cliente`, `a`.`email` AS `email`, `a`.`name` AS `name`, `a`.`rutAux` AS `rutAux`, `c`.`id` AS `id_plan`, `c`.`nom` AS `nom_plan`, `c`.`valor` AS `valor_plan` FROM ((`clientes` `a` left join `tbl_cliente_plan` `b` on((`a`.`id` = `b`.`id_cliente`))) left join `m_planes` `c` on((`b`.`id_plan` = `c`.`id`))) ORDER BY `b`.`id` DESC LIMIT 0, 1 ;
  
  -- --------------------------------------------------------
  
  --
  -- Estructura para la vista `view_count_respuesta_cliente`
  --
  DROP TABLE IF EXISTS `view_count_respuesta_cliente`;
  
  CREATE ALGORITHM=UNDEFINED DEFINER=`clickeal`@`localhost` SQL SECURITY DEFINER VIEW `view_count_respuesta_cliente`  AS SELECT `a`.`id` AS `id_cliente`, (case when isnull(count(`b`.`id`)) then 0 else count(`b`.`id`) end) AS `count_respuestas` FROM (`clientes` `a` left join `tbl_respuesta` `b` on((`a`.`id` = `b`.`id_cliente`))) GROUP BY `a`.`id` ;
  
  -- --------------------------------------------------------
  
  --
  -- Estructura para la vista `view_current_plan`
  --
  DROP TABLE IF EXISTS `view_current_plan`;
  
  CREATE ALGORITHM=UNDEFINED DEFINER=`clickeal`@`localhost` SQL SECURITY DEFINER VIEW `view_current_plan`  AS SELECT `a`.`id` AS `id_reg`, `a`.`id_usuario` AS `id_cliente`, `a`.`id_plan` AS `id_plan`, `b`.`nom` AS `plan`, `b`.`valor` AS `valor`, `a`.`mes` AS `mes`, `a`.`total` AS `total`, `a`.`fechaInicio` AS `fechaInicio`, `a`.`fechaFin` AS `fechaFin`, `b`.`jerarquia` AS `jerarquia`, `b`.`factor` AS `factor`, (case when (curdate() between `a`.`fechaInicio` and `a`.`fechaFin`) then 1 else 0 end) AS `activo` FROM (`soldespacho` `a` left join `m_planes` `b` on((`a`.`id_plan` = `b`.`id`))) WHERE ((curdate() <= cast(`a`.`fechaFin` as date)) AND (`a`.`bool_active_plan` = 1) AND (`a`.`sys_respuesta` = 1)) ORDER BY `a`.`fechaFin` ASC ;
  
  -- --------------------------------------------------------
  
  --
  -- Estructura para la vista `view_iva`
  --
  DROP TABLE IF EXISTS `view_iva`;
  
  CREATE ALGORITHM=UNDEFINED DEFINER=`clickeal`@`localhost` SQL SECURITY DEFINER VIEW `view_iva`  AS SELECT (`m_iva`.`iva` / 100) AS `iva` FROM `m_iva` ORDER BY `m_iva`.`id` DESC LIMIT 0, 1 ;
  
  -- --------------------------------------------------------
  
  --
  -- Estructura para la vista `view_reservas`
  --
  DROP TABLE IF EXISTS `view_reservas`;
  
  CREATE ALGORITHM=UNDEFINED DEFINER=`clickeal`@`localhost` SQL SECURITY DEFINER VIEW `view_reservas`  AS SELECT `a`.`id` AS `id_cliente`, `b`.`id` AS `id_prod`, `d`.`estado` AS `estado`, `e`.`id` AS `id_usuario`, `e`.`email` AS `email`, `e`.`fono` AS `fono`, `e`.`name` AS `name`, `d`.`created_at` AS `created_at`, `d`.`obs` AS `obs`, `d`.`comentario` AS `comentario`, `d`.`valoracion` AS `valoracion` FROM ((((`clientes` `a` left join `tbl_producto` `b` on((`a`.`id` = `b`.`id_cliente`))) left join `m_producto_agenda` `c` on(((`b`.`id_cliente` = `c`.`id_cliente`) and (`b`.`id` = `c`.`id_prod`)))) join `tbl_reserva` `d` on((`c`.`id` = `d`.`id_agenda`))) left join `usuarios` `e` on((`d`.`id_usuario` = `e`.`id`))) ;
  
  -- --------------------------------------------------------
  
  --
  -- Estructura para la vista `view_sum_nota_cliente_producto`
  --
  DROP TABLE IF EXISTS `view_sum_nota_cliente_producto`;
  
  CREATE ALGORITHM=UNDEFINED DEFINER=`clickeal`@`localhost` SQL SECURITY DEFINER VIEW `view_sum_nota_cliente_producto`  AS SELECT `a`.`id` AS `id_cliente`, `b`.`id` AS `id_prod`, (case when isnull(sum(`d`.`valoracion`)) then 0 else sum(`d`.`valoracion`) end) AS `sum_valoracion`, (case when isnull(cast(avg(`d`.`valoracion`) as decimal(1,0))) then 0 else cast(avg(`d`.`valoracion`) as decimal(1,0)) end) AS `prom_valoracion` FROM (((`clientes` `a` left join `tbl_producto` `b` on((`a`.`id` = `b`.`id_cliente`))) left join `m_producto_agenda` `c` on(((`b`.`id_cliente` = `c`.`id_cliente`) and (`b`.`id` = `c`.`id_prod`)))) left join `tbl_reserva` `d` on((`c`.`id` = `d`.`id_agenda`))) GROUP BY `a`.`id`, `b`.`id` ;
  
  --
  -- Índices para tablas volcadas
  --
  
  --
  -- Indices de la tabla `failed_jobs`
  --
  ALTER TABLE `failed_jobs`
    ADD PRIMARY KEY (`id`);
  
  --
  -- Indices de la tabla `migrations`
  --
  ALTER TABLE `migrations`
    ADD PRIMARY KEY (`id`);
  
  --
  -- Indices de la tabla `password_resets`
  --
  ALTER TABLE `password_resets`
    ADD KEY `password_resets_email_index` (`email`);
  
  --
  -- Indices de la tabla `social_profiles`
  --
  ALTER TABLE `social_profiles`
    ADD PRIMARY KEY (`id`),
    ADD UNIQUE KEY `social_profiles_social_id_unique` (`social_id`),
    ADD KEY `social_profiles_user_id_foreign` (`user_id`);
  
  --
  -- Indices de la tabla `users`
  --
  ALTER TABLE `users`
    ADD PRIMARY KEY (`id`),
    ADD UNIQUE KEY `users_email_unique` (`email`);
  
  --
  -- AUTO_INCREMENT de las tablas volcadas
  --
  
  --
  -- AUTO_INCREMENT de la tabla `failed_jobs`
  --
  ALTER TABLE `failed_jobs`
    MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;
  
  --
  -- AUTO_INCREMENT de la tabla `migrations`
  --
  ALTER TABLE `migrations`
    MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
  
  --
  -- AUTO_INCREMENT de la tabla `social_profiles`
  --
  ALTER TABLE `social_profiles`
    MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;
  
  --
  -- AUTO_INCREMENT de la tabla `users`
  --
  ALTER TABLE `users`
    MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;
  
  --
  -- Restricciones para tablas volcadas
  --
  
  --
  -- Filtros para la tabla `social_profiles`
  --
  ALTER TABLE `social_profiles`
    ADD CONSTRAINT `social_profiles_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;
  COMMIT;
  
  /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
  /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
  /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
  