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',