Files
Verde-Web/database/migrations/2026_05_11_100000_create_aggregation_tables.php
admin 0a2e187f45 feat(backend): complete Module 13 reports + analytics
daily_collection_stats, weekly_route_performance, monthly_store_sales
aggregation tables. Aggregator service is idempotent — wipes the slice
and re-inserts. php artisan reports:aggregate (default: yesterday) for
the nightly cron. Admin endpoints: daily-collection / trip-performance
/ store-sales chart series + totals, compliance.csv stream of dumpsite
releases (DENR-style), POST rebuild for on-demand aggregation.

Payments, notifications, and live tracking sub-modules of Module 13
are deferred per scope.

164 feature tests passing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 02:58:09 +08:00

57 lines
2.3 KiB
PHP

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('daily_collection_stats', function (Blueprint $table) {
$table->id();
$table->date('date');
$table->foreignId('barangay_id')->nullable()->constrained('barangays')->nullOnDelete();
$table->unsignedInteger('total_scans')->default(0);
$table->unsignedBigInteger('total_weight_kg')->default(0);
$table->unsignedInteger('unique_households')->default(0);
$table->unsignedInteger('missed_pickups')->default(0);
$table->timestamps();
$table->unique(['date', 'barangay_id'], 'dcs_date_brgy_uniq');
});
Schema::create('weekly_route_performance', function (Blueprint $table) {
$table->id();
$table->date('week_start_date');
$table->foreignId('route_id')->constrained('routes')->cascadeOnDelete();
$table->unsignedTinyInteger('on_time_rate_percent')->default(0);
$table->unsignedInteger('avg_trip_duration_minutes')->default(0);
$table->unsignedTinyInteger('completion_rate_percent')->default(0);
$table->unsignedInteger('trips_count')->default(0);
$table->timestamps();
$table->unique(['week_start_date', 'route_id'], 'wrp_week_route_uniq');
});
Schema::create('monthly_store_sales', function (Blueprint $table) {
$table->id();
$table->date('month_start_date');
$table->foreignId('store_id')->constrained('partner_stores')->cascadeOnDelete();
$table->unsignedInteger('total_quantity_sold')->default(0);
$table->unsignedBigInteger('total_retail_centavos')->default(0);
$table->unsignedBigInteger('total_commission_centavos')->default(0);
$table->timestamps();
$table->unique(['month_start_date', 'store_id'], 'mss_month_store_uniq');
});
}
public function down(): void
{
Schema::dropIfExists('monthly_store_sales');
Schema::dropIfExists('weekly_route_performance');
Schema::dropIfExists('daily_collection_stats');
}
};