diff --git a/admin/DashboardController.php b/admin/DashboardController.php index 87043fb..25bbcf1 100644 --- a/admin/DashboardController.php +++ b/admin/DashboardController.php @@ -1960,6 +1960,33 @@ HTML; if ($url === '') { echo json_encode(['ok' => false, 'error' => 'URL vacĂ­a']); exit; } + // Resolve {var} placeholders using params config + $stmt = db()->prepare("SELECT params FROM company_endpoints WHERE company_id=? AND endpoint_key=?"); + $stmt->execute([$companyId, $key]); + $paramsJson = $stmt->fetchColumn(); + $varConfigs = is_string($paramsJson) ? (json_decode($paramsJson, true) ?? []) : []; + $presets = [ + 'current_date' => date('Y-m-d'), + 'month_start' => date('Y-m-01'), + 'month_end' => date('Y-m-t'), + 'last_7_start' => date('Y-m-d', strtotime('-7 days')), + 'last_30_start' => date('Y-m-d', strtotime('-30 days')), + 'year_start' => date('Y-01-01'), + ]; + foreach ($varConfigs as $cfg) { + $k = $cfg['key'] ?? ''; + if (!$k) continue; + if (($cfg['mode'] ?? '') === 'fixed') { + $val = $cfg['value'] ?? 'current_date'; + $url = str_replace('{' . $k . '}', $presets[$val] ?? $val, $url); + } else { + // ponytail: ask-mode vars get today as test default + $url = str_replace('{' . $k . '}', date('Y-m-d'), $url); + } + } + // Replace any remaining unresolved {vars} with today + $url = preg_replace('/\{[^}]+\}/', date('Y-m-d'), $url); + $company = CompanyRepository::findById($companyId); $apiKey = $company['api_key'] ?? '';