Fix: Data inconsistency pada transisi tahun/bulan dan setup API lokal

- Implementasi fallback mechanism untuk daily_summary (threshold 5%)
- Auto-detect base path untuk subdirectory installation
- Perbaikan query dengan CAST(? AS DATE) untuk semua tanggal
- Script utilities: check_daily_summary.php dan check_and_fix_hourly_summary.php
- Setup .htaccess untuk routing Slim Framework
- Test script untuk verifikasi API lokal
- Dokumentasi SETUP_LOCAL_API.md
This commit is contained in:
BTekno Dev
2026-01-01 23:38:13 +07:00
parent d05fa2f4cd
commit 19926b30e3
8 changed files with 704 additions and 43 deletions

22
public/.htaccess Normal file
View File

@@ -0,0 +1,22 @@
# Slim Framework 4 .htaccess
# Pastikan semua request diarahkan ke index.php
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect to index.php if file doesn't exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
</IfModule>
# Security headers
<IfModule mod_headers.c>
Header set X-Content-Type-Options "nosniff"
Header set X-Frame-Options "SAMEORIGIN"
Header set X-XSS-Protection "1; mode=block"
</IfModule>
# Disable directory browsing
Options -Indexes

62
public/test.php Normal file
View File

@@ -0,0 +1,62 @@
<?php
/**
* Test script untuk cek apakah API bisa diakses
* Akses: http://localhost/api-btekno/public/test.php
*/
require __DIR__ . '/../vendor/autoload.php';
use App\Config\AppConfig;
use App\Support\Database;
echo "<h1>API Test</h1>";
echo "<p>PHP Version: " . phpversion() . "</p>";
echo "<p>Document Root: " . __DIR__ . "</p>";
echo "<p>Request URI: " . ($_SERVER['REQUEST_URI'] ?? 'N/A') . "</p>";
// Test database connection
try {
AppConfig::loadEnv(__DIR__ . '/..');
$db = Database::getConnection(
AppConfig::get('DB_HOST'),
AppConfig::get('DB_NAME'),
AppConfig::get('DB_USER'),
AppConfig::get('DB_PASS')
);
echo "<p style='color: green;'>✓ Database connection: OK</p>";
// Test query
$stmt = $db->query("SELECT COUNT(*) as count FROM entry_events");
$result = $stmt->fetch();
echo "<p>Total entry_events: " . ($result['count'] ?? 0) . "</p>";
// Test daily_summary untuk 2026-01-01
$stmt = $db->prepare("SELECT SUM(total_count) as total FROM daily_summary WHERE summary_date = CAST(? AS DATE)");
$stmt->execute(['2026-01-01']);
$dailyResult = $stmt->fetch();
echo "<p>daily_summary for 2026-01-01: " . ($dailyResult['total'] ?? 0) . " events</p>";
} catch (Exception $e) {
echo "<p style='color: red;'>✗ Database connection: FAILED</p>";
echo "<p>Error: " . htmlspecialchars($e->getMessage()) . "</p>";
}
// Test health endpoint
echo "<hr>";
echo "<h2>Test Health Endpoint</h2>";
echo "<p><a href='health' target='_blank'>Click here to test /health endpoint</a></p>";
echo "<p>Or access directly: <code>http://localhost/api-btekno/public/health</code></p>";
// Test dengan curl jika tersedia
echo "<hr>";
echo "<h2>Manual Test Commands</h2>";
echo "<pre>";
echo "curl http://localhost/api-btekno/public/health\n";
echo "curl -X POST http://localhost/api-btekno/public/auth/v1/login \\\n";
echo " -H \"Content-Type: application/json\" \\\n";
echo " -H \"X-API-KEY: POKOKEIKISEKOYOLO\" \\\n";
echo " -d '{\"username\":\"admin\",\"password\":\"password\"}'\n";
echo "</pre>";