From 6616b636831d00f4db43ddd1c5400d3a557f85a7 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Thu, 20 Aug 2026 22:53:03 -0500 Subject: [PATCH] fix: la fecha final del ausentismo mira hacia adelante MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit El selector ofrecia Hoy/Ayer/Anteayer tambien para el "hasta", cuando una novedad que se registra hoy termina hoy o mas adelante. Ahora ese campo ofrece Hoy/Manana/Pasado manana, y "Otra fecha" sigue aceptando cualquiera. date_quick gana 'quick' => 'futuro'; sin esa clave se comporta igual que antes, asi que las fechas de labores y ciclos —siempre pasadas— no cambian. Co-Authored-By: Claude Sonnet 4.6 --- services/NormalBot.php | 25 ++++++++++++++++++------- setup/seed_palmas.php | 2 ++ setup/tests/test_flujos.php | 10 ++++++++++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/services/NormalBot.php b/services/NormalBot.php index 5506683..1ad2181 100644 --- a/services/NormalBot.php +++ b/services/NormalBot.php @@ -1525,11 +1525,13 @@ class NormalBot } } - // ── date_quick: Hoy / Ayer / Anteayer / Otra ──────────────────────── + // ── date_quick: atajos hacia atras o hacia adelante segun 'quick' ─── if ($type === 'date_quick') { $hoy = date('Y-m-d'); $ayer = date('Y-m-d', strtotime('-1 day')); $ant = date('Y-m-d', strtotime('-2 days')); + $man = date('Y-m-d', strtotime('+1 day')); + $pas = date('Y-m-d', strtotime('+2 days')); return self::enqueueInteractive($to, [ 'type' => 'list', 'header' => ['type' => 'text', 'text' => mb_substr($cap['header'], 0, 60)], @@ -1537,12 +1539,21 @@ class NormalBot 'footer' => ['text' => ''], 'action' => ['button' => 'Ver fechas', 'sections' => [[ 'title' => 'Fecha', - 'rows' => [ - ['id' => $hoy, 'title' => '📅 Hoy', 'description' => $hoy], - ['id' => $ayer, 'title' => '📅 Ayer', 'description' => $ayer], - ['id' => $ant, 'title' => '📅 Anteayer', 'description' => $ant], - ['id' => '__cap_other', 'title' => '✏️ Otra fecha', 'description' => 'Escribe la fecha'], - ], + // Una fecha de cierre cae hoy o mas adelante: ofrecer ayer y + // anteayer ahi no tenia sentido. 'futuro' invierte los atajos. + 'rows' => (($field['quick'] ?? 'pasado') === 'futuro') + ? [ + ['id' => $hoy, 'title' => '📅 Hoy', 'description' => $hoy], + ['id' => $man, 'title' => '📅 Mañana', 'description' => $man], + ['id' => $pas, 'title' => '📅 Pasado mañana', 'description' => $pas], + ['id' => '__cap_other', 'title' => '✏️ Otra fecha', 'description' => 'Escribe la fecha'], + ] + : [ + ['id' => $hoy, 'title' => '📅 Hoy', 'description' => $hoy], + ['id' => $ayer, 'title' => '📅 Ayer', 'description' => $ayer], + ['id' => $ant, 'title' => '📅 Anteayer', 'description' => $ant], + ['id' => '__cap_other', 'title' => '✏️ Otra fecha', 'description' => 'Escribe la fecha'], + ], ]]], ], $company); } diff --git a/setup/seed_palmas.php b/setup/seed_palmas.php index 63e1afe..110a965 100644 --- a/setup/seed_palmas.php +++ b/setup/seed_palmas.php @@ -478,6 +478,8 @@ $configJson = [ 'key' => 'fecha_final', 'label' => 'Hasta', 'type' => 'date_quick', + // Una novedad termina hoy o mas adelante, nunca anteayer + 'quick' => 'futuro', 'prompt' => '📅 ¿Hasta qué fecha? (si es un solo día, elige la misma)', 'other_validate' => 'date', 'other_prompt' => 'Escribe la fecha final (YYYY-MM-DD):', diff --git a/setup/tests/test_flujos.php b/setup/tests/test_flujos.php index f9ee913..faecca6 100644 --- a/setup/tests/test_flujos.php +++ b/setup/tests/test_flujos.php @@ -62,11 +62,21 @@ check('y el nombre completo va en la descripción', $r = NormalBot::processInteractive($co, $ctx, '46'); check('sigue la fecha inicial', str_contains(textoDe($r), 'Desde qué fecha')); +check('la fecha inicial sí mira hacia atrás', + isset(filasDe($r)[date('Y-m-d', strtotime('-1 day'))])); $hoy = date('Y-m-d'); $ayer = date('Y-m-d', strtotime('-1 day')); +$manana = date('Y-m-d', strtotime('+1 day')); $r = NormalBot::processInteractive($co, $ctx, $hoy); check('sigue la fecha final', str_contains(textoDe($r), 'Hasta qué fecha')); +// Una novedad termina hoy o despues: los atajos van hacia adelante +$atajos = filasDe($r); +check('ofrece hoy, mañana y pasado — no ayer', + array_map('strval', array_keys($atajos)), + [$hoy, $manana, date('Y-m-d', strtotime('+2 days')), '__cap_other']); +check('sin atajos hacia atrás', !isset($atajos[$ayer])); + WhatsAppSender::$enviados = []; $r = NormalBot::processInteractive($co, $ctx, $ayer); check('rechaza el rango invertido',