true, CURLOPT_TIMEOUT => 20, CURLOPT_HTTPHEADER => ["Authorization: Bearer {$key}", 'Accept: application/json'], ]); $body = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); $err = curl_error($ch); curl_close($ch); if ($err) { echo "❌ [{$label}] cURL: {$err}\n"; return; } $isPdf = str_contains($type, 'pdf'); $isXls = str_contains($type, 'spreadsheet') || str_contains($type, 'excel'); $isJson = str_contains($type, 'json'); if ($isPdf || $isXls) { $ext = $isPdf ? 'PDF' : 'EXCEL'; $size = round(strlen($body) / 1024, 1); echo "✅ [{$label}] HTTP {$code} → {$ext} {$size} KB\n"; return; } $d = json_decode($body, true); $status = $d['status'] ?? '?'; if ($code === 200 && in_array($status, ['1', 'sin_datos'])) { $msg = $d['message'] ?? $d['mensaje'] ?? $d['mensaje'] ?? ''; echo "✅ [{$label}] HTTP {$code} status={$status} " . mb_substr($msg, 0, 80) . "\n"; } else { $msg = $d['mensaje'] ?? $d['message'] ?? mb_substr($body, 0, 120); echo "❌ [{$label}] HTTP {$code} → {$msg}\n"; } } // ── 1. Fincas (para obtener un finca_id real) ───────────────────────────── echo "\n── Fincas ──\n"; $ch = curl_init("{$BASE}?peticion=fincas"); curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>10, CURLOPT_HTTPHEADER=>["Authorization: Bearer {$KEY}"]]); $raw = curl_exec($ch); curl_close($ch); $fincas = json_decode($raw, true); $fincaId = 0; if (!empty($fincas['datos'])) { foreach ($fincas['datos'] as $f) { echo " id={$f['id']} {$f['label']}\n"; if ($fincaId === 0 && (int)$f['id'] > 0) $fincaId = (int)$f['id']; // skip id=0 (Todas) } } else { echo " " . mb_substr($raw, 0, 200) . "\n"; } echo " → Usando finca_id={$fincaId} para los tests filtrados\n"; // ── 2. Ausentismos texto ────────────────────────────────────────────────── echo "\n── Ausentismos texto ──\n"; hit('hoy', "{$BASE}?peticion=ausentismos_bot_texto&fecha_desde={$TODAY}&fecha_hasta={$TODAY}", $KEY); hit('semana', "{$BASE}?peticion=ausentismos_bot_texto&fecha_desde=" . date('Y-m-d', strtotime('-7 days')) . "&fecha_hasta={$TODAY}", $KEY); // ── 3. Ausentismos PDF ──────────────────────────────────────────────────── echo "\n── Ausentismos PDF (mes) ──\n"; hit('mes_pdf', "{$BASE}?peticion=ausentismos_bot_pdf&fecha_desde={$M1}&fecha_hasta={$TODAY}", $KEY); // ── 4. Producción total texto ───────────────────────────────────────────── echo "\n── Producción total texto ──\n"; hit('sin_finca', "{$BASE}?peticion=produccion_total_bot&fecha_desde={$M1}&fecha_hasta={$TODAY}", $KEY); if ($fincaId > 0) hit("finca_{$fincaId}", "{$BASE}?peticion=produccion_total_bot&fecha_desde={$M1}&fecha_hasta={$TODAY}&finca_id={$fincaId}", $KEY); // ── 5. Producción total PDF ─────────────────────────────────────────────── echo "\n── Producción total PDF ──\n"; if ($fincaId > 0) hit("finca_{$fincaId}", "{$BASE}?peticion=produccion_total_pdf_bot&fecha_desde={$M1}&fecha_hasta={$TODAY}&finca_id={$fincaId}", $KEY); // ── 6. Producción por lotes Excel ───────────────────────────────────────── echo "\n── Producción lotes Excel ──\n"; hit('lotes', "{$BASE}?peticion=produccion_kilos_lotes&fecha_desde={$M1}&fecha_hasta={$TODAY}", $KEY); // ── 7. Ciclos existentes ────────────────────────────────────────────────── echo "\n── Ciclos (spot check) ──\n"; hit('cosecha', "{$BASE}?peticion=ciclos_cosecha_dn&fecha_desde={$M1}&finca_id={$fincaId}", $KEY); hit('polinizacion',"{$BASE}?peticion=ciclos_polinizacion_dn&fecha_desde={$M1}&finca_id={$fincaId}", $KEY); hit('mantenimiento',"{$BASE}?peticion=mantenimiento_dn&fecha_desde={$M1}&grupo=0&finca_id={$fincaId}", $KEY); // ── 8. Top texto (lotes con ciclos más largos) ─────────────────────────── echo "\n── Top texto (sin finca) ──\n"; hit('cosecha_top', "{$BASE}?peticion=cosecha_top_texto_bot", $KEY); hit('polinizacion_top', "{$BASE}?peticion=polinizacion_top_texto_bot", $KEY); hit('censo_top', "{$BASE}?peticion=censo_top_texto_bot", $KEY); hit('plagas_top', "{$BASE}?peticion=plagas_top_texto_bot", $KEY); hit('palm_top', "{$BASE}?peticion=palm_top_texto_bot", $KEY); hit('tratamiento_top', "{$BASE}?peticion=tratamiento_top_texto_bot", $KEY); hit('mant_top', "{$BASE}?peticion=mantenimiento_top_texto_bot&grupo=0", $KEY); if ($fincaId > 0) { echo "\n── Top texto (con finca_id={$fincaId}) ──\n"; hit('cosecha_top', "{$BASE}?peticion=cosecha_top_texto_bot&finca_id={$fincaId}", $KEY); hit('polinizacion_top', "{$BASE}?peticion=polinizacion_top_texto_bot&finca_id={$fincaId}", $KEY); hit('censo_top', "{$BASE}?peticion=censo_top_texto_bot&finca_id={$fincaId}", $KEY); hit('plagas_top', "{$BASE}?peticion=plagas_top_texto_bot&finca_id={$fincaId}", $KEY); hit('palm_top', "{$BASE}?peticion=palm_top_texto_bot&finca_id={$fincaId}", $KEY); hit('tratamiento_top', "{$BASE}?peticion=tratamiento_top_texto_bot&finca_id={$fincaId}", $KEY); hit('mant_top', "{$BASE}?peticion=mantenimiento_top_texto_bot&grupo=0&finca_id={$fincaId}", $KEY); } // ── 9. Histórico 30 días (PDF) ──────────────────────────────────────────── echo "\n── Histórico bot PDF (sin finca) ──\n"; hit('cosecha_hist', "{$BASE}?peticion=cosecha_historico_bot&fecha_hasta={$TODAY}&finca_id=0", $KEY); hit('polinizacion_hist', "{$BASE}?peticion=polinizacion_historico_bot&fecha_hasta={$TODAY}&finca_id=0", $KEY); hit('censo_hist', "{$BASE}?peticion=censo_historico_bot&fecha_hasta={$TODAY}&finca_id=0", $KEY); hit('plagas_hist', "{$BASE}?peticion=plagas_historico_bot&fecha_hasta={$TODAY}&finca_id=0", $KEY); hit('palm_hist', "{$BASE}?peticion=palm_historico_bot&fecha_hasta={$TODAY}&finca_id=0", $KEY); hit('tratamiento_hist', "{$BASE}?peticion=tratamiento_historico_bot&fecha_hasta={$TODAY}&finca_id=0", $KEY); if ($fincaId > 0) { echo "\n── Histórico bot PDF (con finca_id={$fincaId}) ──\n"; hit('cosecha_hist', "{$BASE}?peticion=cosecha_historico_bot&fecha_hasta={$TODAY}&finca_id={$fincaId}", $KEY); hit('polinizacion_hist', "{$BASE}?peticion=polinizacion_historico_bot&fecha_hasta={$TODAY}&finca_id={$fincaId}", $KEY); hit('censo_hist', "{$BASE}?peticion=censo_historico_bot&fecha_hasta={$TODAY}&finca_id={$fincaId}", $KEY); hit('plagas_hist', "{$BASE}?peticion=plagas_historico_bot&fecha_hasta={$TODAY}&finca_id={$fincaId}", $KEY); hit('palm_hist', "{$BASE}?peticion=palm_historico_bot&fecha_hasta={$TODAY}&finca_id={$fincaId}", $KEY); hit('tratamiento_hist', "{$BASE}?peticion=tratamiento_historico_bot&fecha_hasta={$TODAY}&finca_id={$fincaId}", $KEY); } echo "\n── Fin del test ──\n";