Files
bot_palmas/setup/seed_palmas.php
T

539 lines
34 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
require_once dirname(__DIR__) . '/config/env.php';
require_once dirname(__DIR__) . '/config/db.php';
$db = db();
// ─── CONFIG JSON completo (Company 2 y 3 comparten la misma base) ────────────
$configJson = [
'greeting' => '¡Bienvenido a Palmas360! Escribe *menu* para ver las opciones disponibles.',
'fallback' => 'No entendí. Escribe *menu* para ver las opciones disponibles.',
'nlu_enabled' => true,
'commands' => [
'menu' => 'show_main_menu',
'informes' => 'descargar_informes',
'info' => 'enviar_informacion',
'inicio' => 'show_main_menu',
'volver' => 'show_main_menu',
'salir' => 'show_main_menu',
],
// ── Menus globales ──────────────────────────────────────────────────────
'menus' => [
// Menú modo trabajo (para per_type=3 tras seleccionar finca)
'menu_modo_trabajo' => [
'type' => 'list',
'header' => '🌴 Palmas360',
'body' => '¿Qué deseas hacer?',
'footer' => 'Palmas360',
'button' => 'Ver opciones',
'sections' => [
[
'title' => 'Opciones',
'rows' => [
['id' => 'descargar_informes', 'title' => '📥 Descargar informes', 'description' => 'Ciclos, Producción, Ausentismos'],
['id' => 'enviar_informacion', 'title' => '📤 Enviar información', 'description' => 'Subir ciclos y datos'],
],
],
],
],
// Menú cat2 (descargar informes) — accesible globalmente
'show_menu_cat2' => [
'type' => 'list',
'header' => '📋 Informes',
'body' => '¿Qué informe deseas?',
'footer' => 'Palmas360',
'button' => 'Ver opciones',
'sections' => [
[
'title' => 'Informes',
'rows' => [
['id' => 'submenu_produccion', 'title' => '🌿 Producción', 'description' => 'Informes de producción'],
['id' => 'submenu_ciclos', 'title' => '🔄 Ciclos', 'description' => 'Ciclos de campo'],
['id' => 'submenu_ausentismos', 'title' => '👥 Ausentismos', 'description' => 'Faltas y novedades'],
],
],
],
],
// Submenú producción
'submenu_produccion' => [
'type' => 'list',
'header' => '🌿 Producción',
'body' => 'Selecciona el informe:',
'footer' => 'Palmas360',
'button' => 'Ver opciones',
'sections' => [
[
'title' => 'Producción',
'rows' => [
['id' => 'produccion_total', 'title' => '📊 Totales facturados', 'description' => 'Resumen y PDF del año'],
['id' => 'produccion_lotes', 'title' => '📋 Por lotes (Excel)', 'description' => 'Detalle por lote'],
],
],
],
],
// Submenú ciclos
'submenu_ciclos' => [
'type' => 'list',
'header' => '🔄 Ciclos',
'body' => 'Selecciona el tipo de ciclo:',
'footer' => 'Palmas360',
'button' => 'Ver ciclos',
'sections' => [
[
'title' => 'Ciclos',
'rows' => [
['id' => 'ciclo_cosecha', 'title' => '🌾 Cosecha', 'description' => 'Ciclos de cosecha'],
['id' => 'ciclo_polinizacion', 'title' => '🌸 Polinización', 'description' => 'Ciclos de polinización'],
['id' => 'submenu_ciclos_sanidad','title' => '🧪 Sanidad', 'description' => 'Plagas, Censo, Palmarum, Tratamientos'],
['id' => 'ciclo_mantenimiento', 'title' => '🔧 Mantenimiento', 'description' => 'Ciclos de mantenimiento'],
],
],
],
],
// Sub-menús por ciclo (3 botones: más largos / todos / histórico)
'submenu_ciclo_cosecha' => ['type'=>'button','body'=>'Ciclos de Cosecha — ¿Qué deseas ver?','buttons'=>[
['id'=>'ciclo_cosecha_top', 'title'=>'🏆 Más largos'],
['id'=>'ciclo_cosecha_todos', 'title'=>'📋 Todos los lotes'],
['id'=>'ciclo_cosecha_historico','title'=>'📅 Histórico 30d'],
]],
'submenu_ciclo_polinizacion' => ['type'=>'button','body'=>'Ciclos de Polinización — ¿Qué deseas ver?','buttons'=>[
['id'=>'ciclo_polinizacion_top', 'title'=>'🏆 Más largos'],
['id'=>'ciclo_polinizacion_todos', 'title'=>'📋 Todos los lotes'],
['id'=>'ciclo_polinizacion_historico','title'=>'📅 Histórico 30d'],
]],
'submenu_ciclo_plagas' => ['type'=>'button','body'=>'Ciclos de Plagas — ¿Qué deseas ver?','buttons'=>[
['id'=>'ciclo_plagas_top', 'title'=>'🏆 Más largos'],
['id'=>'ciclo_plagas_todos', 'title'=>'📋 Todos los lotes'],
['id'=>'ciclo_plagas_historico','title'=>'📅 Histórico 30d'],
]],
'submenu_ciclo_censo' => ['type'=>'button','body'=>'Ciclos de Censo — ¿Qué deseas ver?','buttons'=>[
['id'=>'ciclo_censo_top', 'title'=>'🏆 Más largos'],
['id'=>'ciclo_censo_todos', 'title'=>'📋 Todos los lotes'],
['id'=>'ciclo_censo_historico','title'=>'📅 Histórico 30d'],
]],
'submenu_ciclo_palm' => ['type'=>'button','body'=>'Ciclos de Palmarum — ¿Qué deseas ver?','buttons'=>[
['id'=>'ciclo_palm_top', 'title'=>'🏆 Más largos'],
['id'=>'ciclo_palm_todos', 'title'=>'📋 Todos los lotes'],
['id'=>'ciclo_palm_historico','title'=>'📅 Histórico 30d'],
]],
'submenu_ciclo_tratamiento' => ['type'=>'button','body'=>'Ciclos de Tratamientos — ¿Qué deseas ver?','buttons'=>[
['id'=>'ciclo_tratamiento_top', 'title'=>'🏆 Más largos'],
['id'=>'ciclo_tratamiento_todos', 'title'=>'📋 Todos los lotes'],
['id'=>'ciclo_tratamiento_historico','title'=>'📅 Histórico 30d'],
]],
'submenu_ciclo_mantenimiento' => ['type'=>'button','body'=>'Ciclos de Mantenimiento — ¿Qué deseas ver?','buttons'=>[
['id'=>'ciclo_mantenimiento_top', 'title'=>'🏆 Más largos'],
['id'=>'ciclo_mantenimiento_todos', 'title'=>'📋 Todos los lotes'],
]],
// Submenú sanidad vegetal (orden: Censo, Plagas, Rincofurus, Tratamiento)
'submenu_ciclos_sanidad' => [
'type' => 'list',
'header' => '🧪 Sanidad Vegetal',
'body' => 'Selecciona el ciclo de sanidad:',
'footer' => 'Palmas360',
'button' => 'Ver opciones',
'sections' => [
[
'title' => 'Sanidad',
'rows' => [
['id' => 'ciclo_censo', 'title' => '📝 Censo', 'description' => 'Ciclos de censo'],
['id' => 'ciclo_plagas', 'title' => '🐛 Plagas', 'description' => 'Ciclos de plagas'],
['id' => 'ciclo_palm', 'title' => '🌴 Palmarum', 'description' => 'Rhynchophorus Palmarum'],
['id' => 'ciclo_tratamiento', 'title' => '💊 Tratamiento', 'description' => 'Ciclos de tratamientos'],
],
],
],
],
// Submenú ausentismos
'submenu_ausentismos' => [
'type' => 'list',
'header' => '👥 Ausentismos',
'body' => 'Selecciona el período:',
'footer' => 'Palmas360',
'button' => 'Ver opciones',
'sections' => [
[
'title' => 'Período',
'rows' => [
['id' => 'ausentismos_hoy', 'title' => '📅 Hoy', 'description' => '¿Quién faltó hoy?'],
['id' => 'ausentismos_semana', 'title' => '📆 Esta semana', 'description' => '¿Quién faltó esta semana?'],
['id' => 'ausentismos_mes', 'title' => '📋 Mes (PDF)', 'description' => 'Reporte mensual PDF'],
],
],
],
],
// Submenú subir ciclos (para per_type=3)
'submenu_subir_ciclos' => [
'type' => 'list',
'header' => '📤 Enviar información',
'body' => 'Selecciona qué deseas enviar:',
'footer' => 'Palmas360',
'button' => 'Ver opciones',
'sections' => [
[
'title' => 'Opciones',
'rows' => [
['id' => 'subir_ciclo_cosecha', 'title' => '🌾 Ciclo cosecha', 'description' => 'Subir ciclo de cosecha'],
],
],
],
],
],
// ── Flows globales ──────────────────────────────────────────────────────
'flows' => [
// Selección de finca (dynamic_list — guarda finca_id en meta)
'ask_finca' => [
'type' => 'dynamic_list',
'source_endpoint_key' => 'fincas_dn',
'value_field' => 'id',
'label_field' => 'label',
'header' => '🌴 Palmas360',
'body' => '¿En qué finca trabajas?',
'section_title' => 'Fincas disponibles',
'meta_group' => 'finca',
'meta_key' => 'finca_id',
'next_node' => 'show_main_menu',
'nlu_description' => 'Seleccionar o cambiar la finca de trabajo',
],
// Acción NLU: limpiar finca y volver a ask_finca
'reset_finca' => [
'type' => 'function',
'function' => 'reset_finca',
'nlu_description' => 'Cambiar de finca o seleccionar una finca diferente',
],
// Producción (texto del mes + PDF encadenado)
'produccion_total' => ['type' => 'function', 'function' => 'api_report', 'nlu_description' => 'Producción total facturada del mes actual con PDF del año', 'params' => [
'endpoint_key' => 'produccion_total_bot_dn',
'date_mode' => 'current_month',
'next_endpoint_key' => 'produccion_total_pdf_bot_dn',
'next_caption' => '📊 Producción del año (PDF)',
'next_filename' => 'produccion_año.pdf',
]],
'produccion_lotes' => ['type' => 'function', 'function' => 'api_report', 'nlu_description' => 'Producción detallada por lotes en Excel', 'params' => [
'endpoint_key' => 'produccion_lotes_bot_dn',
'filename' => 'produccion_lotes.xlsx',
'caption' => 'Producción por lotes del año',
]],
// Ausentismos
'ausentismos_hoy' => ['type' => 'function', 'function' => 'api_report', 'nlu_description' => 'Ausentismos de hoy, quién faltó hoy', 'params' => [
'endpoint_key' => 'ausentismos_bot_texto_dn',
'date_mode' => 'today',
]],
'ausentismos_semana' => ['type' => 'function', 'function' => 'api_report', 'nlu_description' => 'Ausentismos de esta semana', 'params' => [
'endpoint_key' => 'ausentismos_bot_texto_dn',
'date_mode' => 'last_7',
]],
'ausentismos_mes' => ['type' => 'function', 'function' => 'api_report', 'nlu_description' => 'Reporte PDF de ausentismos del mes', 'params' => [
'endpoint_key' => 'ausentismos_bot_pdf_dn',
'date_mode' => 'current_month',
'filename' => 'ausentismos_mes.pdf',
'caption' => 'Ausentismos del mes',
]],
// Menus de sección (nlu_skip: navegación interna, no exponer al NLU)
'submenu_produccion' => ['type' => 'menu', 'menu' => 'submenu_produccion', 'nlu_skip' => true],
'submenu_ciclos' => ['type' => 'menu', 'menu' => 'submenu_ciclos', 'nlu_skip' => true],
'submenu_ciclos_sanidad' => ['type' => 'menu', 'menu' => 'submenu_ciclos_sanidad', 'nlu_skip' => true],
'submenu_ausentismos' => ['type' => 'menu', 'menu' => 'submenu_ausentismos', 'nlu_skip' => true],
// Ciclos — cada uno abre un sub-menú de 3 opciones
'ciclo_cosecha' => ['type' => 'menu', 'menu' => 'submenu_ciclo_cosecha', 'nlu_description' => 'Ver ciclos de cosecha (lotes más largos o todos)'],
'ciclo_polinizacion' => ['type' => 'menu', 'menu' => 'submenu_ciclo_polinizacion', 'nlu_description' => 'Ver ciclos de polinización'],
'ciclo_plagas' => ['type' => 'menu', 'menu' => 'submenu_ciclo_plagas', 'nlu_description' => 'Ver ciclos de plagas'],
'ciclo_censo' => ['type' => 'menu', 'menu' => 'submenu_ciclo_censo', 'nlu_description' => 'Ver ciclos de censo'],
'ciclo_palm' => ['type' => 'menu', 'menu' => 'submenu_ciclo_palm', 'nlu_description' => 'Ver ciclos de Palmarum (Rhynchophorus)'],
'ciclo_tratamiento' => ['type' => 'menu', 'menu' => 'submenu_ciclo_tratamiento', 'nlu_description' => 'Ver ciclos de tratamientos'],
// Sub-opciones: cosecha
'ciclo_cosecha_top' => ['type'=>'function','function'=>'api_report','nlu_description'=>'Lotes de cosecha con ciclos más largos','params'=>['endpoint_key'=>'cosecha_top_texto_bot_dn','date_mode'=>'last_30']],
'ciclo_cosecha_todos' => ['type'=>'function','function'=>'api_report','nlu_description'=>'PDF de ciclos de cosecha todos los lotes','params'=>['endpoint_key'=>'cosecha_todos_dn','date_mode'=>'today','filename'=>'ciclos_cosecha.pdf','caption'=>'Ciclos de Cosecha — todos los lotes']],
'ciclo_cosecha_historico'=> ['type'=>'function','function'=>'api_report','nlu_description'=>'Histórico de cosecha últimos 30 días','params'=>['endpoint_key'=>'cosecha_historico_bot_dn','date_mode'=>'last_30','filename'=>'historico_cosecha.pdf','caption'=>'Histórico Cosecha — últimos 30 días']],
// Sub-opciones: polinizacion
'ciclo_polinizacion_top' => ['type'=>'function','function'=>'api_report','nlu_description'=>'Lotes de polinización con ciclos más largos','params'=>['endpoint_key'=>'polinizacion_top_texto_bot_dn','date_mode'=>'last_30']],
'ciclo_polinizacion_todos' => ['type'=>'function','function'=>'api_report','nlu_description'=>'PDF de ciclos de polinización todos los lotes','params'=>['endpoint_key'=>'polinizacion_todos_dn','date_mode'=>'today','filename'=>'ciclos_polinizacion.pdf','caption'=>'Ciclos de Polinización — todos los lotes']],
'ciclo_polinizacion_historico'=> ['type'=>'function','function'=>'api_report','nlu_description'=>'Histórico de polinización últimos 30 días','params'=>['endpoint_key'=>'polinizacion_historico_bot_dn','date_mode'=>'last_30','filename'=>'historico_polinizacion.pdf','caption'=>'Histórico Polinización — últimos 30 días']],
// Sub-opciones: plagas
'ciclo_plagas_top' => ['type'=>'function','function'=>'api_report','nlu_description'=>'Lotes de plagas con ciclos más largos','params'=>['endpoint_key'=>'plagas_top_texto_bot_dn','date_mode'=>'last_30']],
'ciclo_plagas_todos' => ['type'=>'function','function'=>'api_report','nlu_description'=>'PDF de ciclos de plagas todos los lotes','params'=>['endpoint_key'=>'plagas_todos_dn','date_mode'=>'today','filename'=>'ciclos_plagas.pdf','caption'=>'Ciclos de Plagas — todos los lotes']],
'ciclo_plagas_historico'=> ['type'=>'function','function'=>'api_report','nlu_description'=>'Histórico de plagas últimos 30 días','params'=>['endpoint_key'=>'plagas_historico_bot_dn','date_mode'=>'last_30','filename'=>'historico_plagas.pdf','caption'=>'Histórico Plagas — últimos 30 días']],
// Sub-opciones: censo
'ciclo_censo_top' => ['type'=>'function','function'=>'api_report','nlu_description'=>'Lotes de censo con ciclos más largos','params'=>['endpoint_key'=>'censo_top_texto_bot_dn','date_mode'=>'last_30']],
'ciclo_censo_todos' => ['type'=>'function','function'=>'api_report','nlu_description'=>'PDF de ciclos de censo todos los lotes','params'=>['endpoint_key'=>'censo_todos_dn','date_mode'=>'today','filename'=>'ciclos_censo.pdf','caption'=>'Ciclos de Censo — todos los lotes']],
'ciclo_censo_historico'=> ['type'=>'function','function'=>'api_report','nlu_description'=>'Histórico de censo últimos 30 días','params'=>['endpoint_key'=>'censo_historico_bot_dn','date_mode'=>'last_30','filename'=>'historico_censo.pdf','caption'=>'Histórico Censo — últimos 30 días']],
// Sub-opciones: palm
'ciclo_palm_top' => ['type'=>'function','function'=>'api_report','nlu_description'=>'Lotes de Palmarum con ciclos más largos','params'=>['endpoint_key'=>'palm_top_texto_bot_dn','date_mode'=>'last_30']],
'ciclo_palm_todos' => ['type'=>'function','function'=>'api_report','nlu_description'=>'PDF de ciclos de Palmarum todos los lotes','params'=>['endpoint_key'=>'palm_todos_dn','date_mode'=>'today','filename'=>'ciclos_palmarum.pdf','caption'=>'Ciclos de Palmarum — todos los lotes']],
'ciclo_palm_historico'=> ['type'=>'function','function'=>'api_report','nlu_description'=>'Histórico de Palmarum últimos 30 días','params'=>['endpoint_key'=>'palm_historico_bot_dn','date_mode'=>'last_30','filename'=>'historico_palmarum.pdf','caption'=>'Histórico Palmarum — últimos 30 días']],
// Sub-opciones: tratamiento
'ciclo_tratamiento_top' => ['type'=>'function','function'=>'api_report','nlu_description'=>'Lotes de tratamiento con ciclos más largos','params'=>['endpoint_key'=>'tratamiento_top_texto_bot_dn','date_mode'=>'last_30']],
'ciclo_tratamiento_todos' => ['type'=>'function','function'=>'api_report','nlu_description'=>'PDF de ciclos de tratamientos todos los lotes','params'=>['endpoint_key'=>'tratamiento_todos_dn','date_mode'=>'today','filename'=>'ciclos_tratamientos.pdf','caption'=>'Ciclos de Tratamientos — todos los lotes']],
'ciclo_tratamiento_historico'=> ['type'=>'function','function'=>'api_report','nlu_description'=>'Histórico de tratamientos últimos 30 días','params'=>['endpoint_key'=>'tratamiento_historico_bot_dn','date_mode'=>'last_30','filename'=>'historico_tratamientos.pdf','caption'=>'Histórico Tratamientos — últimos 30 días']],
// ciclo_mantenimiento → selección dinámica de grupo (top3 + "Otro")
'ciclo_mantenimiento' => [
'type' => 'dynamic_list',
'source_endpoint_key' => 'mantenimiento_grupos_top3_dn',
'value_field' => 'id',
'label_field' => 'label',
'header' => '🔧 Mantenimiento',
'body' => 'Selecciona el grupo de mantenimiento:',
'section_title' => 'Grupos frecuentes',
'meta_group' => 'grupo_mant',
'meta_key' => 'grupo_id',
'next_node' => 'submenu_ciclo_mantenimiento',
'append_options' => [['id' => 'select_grupo_mant_otros', 'title' => ' Otro grupo']],
'nlu_description' => 'Ver ciclos de mantenimiento por grupo (plateo, corona, poda, etc.)',
],
'select_grupo_mant_otros' => [
'type' => 'dynamic_list',
'source_endpoint_key' => 'mantenimiento_grupos_otros_dn',
'value_field' => 'id',
'label_field' => 'label',
'header' => '🔧 Mantenimiento',
'body' => 'Selecciona el grupo:',
'section_title' => 'Otros grupos',
'meta_group' => 'grupo_mant',
'meta_key' => 'grupo_id',
'next_node' => 'submenu_ciclo_mantenimiento',
'nlu_skip' => true,
],
// Sub-opciones: mantenimiento
'ciclo_mantenimiento_top' => ['type'=>'function','function'=>'api_report','nlu_description'=>'Lotes de mantenimiento con ciclos más largos (texto)','params'=>['endpoint_key'=>'mantenimiento_top_texto_bot_dn','date_mode'=>'today']],
'ciclo_mantenimiento_todos' => ['type'=>'function','function'=>'api_report','nlu_description'=>'PDF de mantenimiento todos los lotes del grupo seleccionado','params'=>['endpoint_key'=>'mantenimiento_todos_bot_dn','date_mode'=>'today','filename'=>'mantenimiento_todos.pdf','caption'=>'Mantenimiento — todos los lotes']],
// Upload
'enviar_informacion' => ['type' => 'menu', 'menu' => 'submenu_subir_ciclos', 'nlu_skip' => true],
'subir_ciclo_cosecha' => ['type' => 'function', 'function' => 'upload_ciclo', 'nlu_description' => 'Subir o enviar un ciclo de cosecha', 'params' => ['ciclo' => 'cosecha']],
// Alias globales (nlu_skip: son alias de navegación)
'show_main_menu' => ['type' => 'menu', 'menu' => 'show_menu_cat2', 'nlu_skip' => true],
'descargar_informes' => ['type' => 'menu', 'menu' => 'show_menu_cat2', 'nlu_skip' => true],
],
// ── Per-type config ─────────────────────────────────────────────────────
'per_type' => [
// Cat 1: solo reporta (envía info, no descarga)
'1' => [
'greeting_flow' => 'show_menu_cat1',
'fallback_flow' => 'show_menu_cat1',
'greeting' => null,
'fallback' => null,
'commands' => ['menu' => 'show_menu_cat1'],
'menus' => [
'show_menu_cat1' => [
'type' => 'list',
'header' => '🌴 Palmas360',
'body' => '¿Qué deseas hacer?',
'footer' => 'Palmas360',
'button' => 'Ver opciones',
'sections' => [
[
'title' => 'Opciones',
'rows' => [
['id' => 'subir_ciclo_cosecha', 'title' => '🌾 Subir cosecha', 'description' => 'Enviar ciclo de cosecha'],
],
],
],
],
],
'flows' => [
'show_menu_cat1' => ['type' => 'menu', 'menu' => 'show_menu_cat1'],
'show_main_menu' => ['type' => 'menu', 'menu' => 'show_menu_cat1'],
'subir_ciclo_cosecha' => ['type' => 'function', 'function' => 'upload_ciclo', 'params' => ['ciclo' => 'cosecha']],
],
],
// Cat 2: solo descarga
'2' => [
'greeting_flow' => 'ask_finca',
'fallback_flow' => 'show_menu_cat2',
'greeting' => '',
'fallback' => null,
'commands' => ['menu' => 'show_menu_cat2'],
'menus' => [
'show_menu_cat2' => [
'type' => 'list',
'header' => '📋 Informes',
'body' => '¿Qué informe deseas?',
'footer' => 'Palmas360',
'button' => 'Ver opciones',
'sections' => [
[
'title' => 'Informes',
'rows' => [
['id' => 'submenu_produccion', 'title' => '🌿 Producción', 'description' => 'Informes de producción'],
['id' => 'submenu_ciclos', 'title' => '🔄 Ciclos', 'description' => 'Ciclos de campo'],
['id' => 'submenu_ausentismos', 'title' => '👥 Ausentismos', 'description' => 'Faltas y novedades'],
],
],
],
],
],
'flows' => [
'show_menu_cat2' => ['type' => 'menu', 'menu' => 'show_menu_cat2'],
'show_main_menu' => ['type' => 'menu', 'menu' => 'show_menu_cat2'],
'descargar_informes' => ['type' => 'menu', 'menu' => 'show_menu_cat2'],
],
],
// Cat 3: descarga + envío
'3' => [
'greeting_flow' => 'ask_finca',
'fallback_flow' => 'show_main_menu',
'greeting' => '',
'fallback' => null,
'commands' => ['menu' => 'show_main_menu'],
'menus' => [],
'flows' => [
'show_main_menu' => ['type' => 'menu', 'menu' => 'menu_modo_trabajo'],
'descargar_informes' => ['type' => 'menu', 'menu' => 'show_menu_cat2'],
'enviar_informacion' => ['type' => 'menu', 'menu' => 'submenu_subir_ciclos'],
],
],
],
];
// ─── Endpoints ─────────────────────────────────────────────────────────────────
$BASE = 'https://app.palmas360.com/rosablanca/php/controller/controller_api_externa.php';
$endpoints = [
['key' => 'produccion_total_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=produccion_total_bot&finca_id={finca_id}'],
['key' => 'produccion_total_pdf_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=produccion_total_pdf_bot&finca_id={finca_id}'],
['key' => 'produccion_lotes_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=produccion_lotes_bot&finca_id={finca_id}'],
['key' => 'ausentismos_bot_texto_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=ausentismos_bot_texto'],
['key' => 'ausentismos_bot_pdf_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=ausentismos_bot_pdf'],
['key' => 'cosecha_top_texto_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=cosecha_top_texto_bot&finca_id={finca_id}'],
['key' => 'polinizacion_top_texto_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=polinizacion_top_texto_bot&finca_id={finca_id}'],
['key' => 'censo_top_texto_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=censo_top_texto_bot&finca_id={finca_id}'],
['key' => 'plagas_top_texto_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=plagas_top_texto_bot&finca_id={finca_id}'],
['key' => 'palm_top_texto_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=palm_top_texto_bot&finca_id={finca_id}'],
['key' => 'tratamiento_top_texto_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=tratamiento_top_texto_bot&finca_id={finca_id}'],
['key' => 'cosecha_historico_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=cosecha_historico_bot&finca_id={finca_id}'],
['key' => 'polinizacion_historico_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=polinizacion_historico_bot&finca_id={finca_id}'],
['key' => 'censo_historico_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=censo_historico_bot&finca_id={finca_id}'],
['key' => 'plagas_historico_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=plagas_historico_bot&finca_id={finca_id}'],
['key' => 'palm_historico_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=palm_historico_bot&finca_id={finca_id}'],
['key' => 'tratamiento_historico_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=tratamiento_historico_bot&finca_id={finca_id}'],
['key' => 'fincas_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=fincas'],
['key' => 'numeros_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=whatsapp_numeros&estado=1'],
// Todos los lotes (PDF) por ciclo
['key' => 'cosecha_todos_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=ciclos_cosecha_dn&finca_id={finca_id}'],
['key' => 'polinizacion_todos_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=ciclos_polinizacion_dn&finca_id={finca_id}'],
['key' => 'plagas_todos_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=ciclos_plagas_dn&finca_id={finca_id}'],
['key' => 'censo_todos_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=ciclos_censo_dn&finca_id={finca_id}'],
['key' => 'palm_todos_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=ciclos_palm_dn&finca_id={finca_id}'],
['key' => 'tratamiento_todos_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=ciclos_tratamientos_dn&finca_id={finca_id}'],
['key' => 'mantenimiento_grupos_top3_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=grupos_mantenimiento&limit=3'],
['key' => 'mantenimiento_grupos_otros_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=grupos_mantenimiento&limit=10&offset=3'],
['key' => 'mantenimiento_top_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=mantenimiento_dn&top_lotes=10&grupo={grupo_id}&finca_id={finca_id}'],
['key' => 'mantenimiento_top_texto_bot_dn','dir' => 'download', 'url' => $BASE . '?peticion=mantenimiento_top_texto_bot&grupo={grupo_id}&finca_id={finca_id}'],
['key' => 'mantenimiento_todos_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=mantenimiento_dn&grupo={grupo_id}&finca_id={finca_id}'],
];
// ─── Companies ─────────────────────────────────────────────────────────────────
$companies = [
[
'id' => 2,
'name' => 'rosablanca',
'display_name' => 'Rosa Blanca',
'phone_number_id' => '1168511569675820',
'display_phone' => '',
'api_base_url' => 'https://graph.facebook.com/v22.0',
'api_key' => 'EAAqbNQQekwUBRm8ZAAfCvXZAsxcM1BTkiHjVJYeOfXYCg5t4qYtBL7ap2IdHGa1iXclZBO47gZBshYZBAlQRuUvgSib2Owh7gPnAWfNlHXZAT61ccElXoihuXuEuy0qLiB95tDhLMWPqoKYuDwAHCU78RQxoi1nzz1OsOY40EK7U2tKZBVuZABQZCJctZBrLK7rRiC7AZDZD',
'bot_type' => 'normal',
'requires_approval' => 0,
'is_active' => 1,
],
[
'id' => 3,
'name' => 'palmas360_test',
'display_name' => 'Palmas360 Test',
'phone_number_id' => '1168511569675820',
'display_phone' => '',
'api_base_url' => 'https://graph.facebook.com/v22.0',
'api_key' => 'EAAqbNQQekwUBRm8ZAAfCvXZAsxcM1BTkiHjVJYeOfXYCg5t4qYtBL7ap2IdHGa1iXclZBO47gZBshYZBAlQRuUvgSib2Owh7gPnAWfNlHXZAT61ccElXoihuXuEuy0qLiB95tDhLMWPqoKYuDwAHCU78RQxoi1nzz1OsOY40EK7U2tKZBVuZABQZCJctZBrLK7rRiC7AZDZD',
'bot_type' => 'normal',
'requires_approval' => 0,
'is_active' => 1,
],
];
$configJsonStr = json_encode($configJson, JSON_UNESCAPED_UNICODE);
// ─── Insert / update companies ────────────────────────────────────────────────
$stmtCo = $db->prepare("
INSERT INTO companies (id, name, display_name, phone_number_id, display_phone, api_base_url, api_key, bot_type, requires_approval, is_active, config_json)
VALUES (:id, :name, :display_name, :phone_number_id, :display_phone, :api_base_url, :api_key, :bot_type, :requires_approval, :is_active, :config_json)
ON DUPLICATE KEY UPDATE
display_name = VALUES(display_name),
phone_number_id = VALUES(phone_number_id),
api_base_url = VALUES(api_base_url),
bot_type = VALUES(bot_type),
is_active = VALUES(is_active),
config_json = VALUES(config_json)
");
foreach ($companies as $co) {
$stmtCo->execute([
':id' => $co['id'],
':name' => $co['name'],
':display_name' => $co['display_name'],
':phone_number_id' => $co['phone_number_id'],
':display_phone' => $co['display_phone'],
':api_base_url' => $co['api_base_url'],
':api_key' => $co['api_key'],
':bot_type' => $co['bot_type'],
':requires_approval'=> $co['requires_approval'],
':is_active' => $co['is_active'],
':config_json' => $configJsonStr,
]);
echo "✔ Company {$co['id']} ({$co['display_name']}) OK\n";
}
// ─── Insert / update endpoints ────────────────────────────────────────────────
$stmtEp = $db->prepare("
INSERT INTO company_endpoints (company_id, endpoint_key, direction, url)
VALUES (:company_id, :endpoint_key, :direction, :url)
ON DUPLICATE KEY UPDATE url = VALUES(url), direction = VALUES(direction)
");
foreach ($companies as $co) {
foreach ($endpoints as $ep) {
$stmtEp->execute([
':company_id' => $co['id'],
':endpoint_key' => $ep['key'],
':direction' => $ep['dir'],
':url' => $ep['url'],
]);
}
echo "✔ " . count($endpoints) . " endpoints OK para company {$co['id']}\n";
}
echo "\n✅ Seed completo.\n";