Files
hub/app/Filament/Widgets/SalesMetrics.php
Jon Leopard 7e5ea2bc10 checkpoint: marketplace and operational features complete, ready for Week 4 data migration
Summary of completed work:
- Complete buyer portal (browse, cart, checkout, orders, invoices)
- Complete seller portal (orders, manifests, fleet, picking)
- Business onboarding wizards (buyer 4-step, seller 5-step)
- Email verification and registration flows
- Notification system for buyers and sellers
- Payment term surcharges and pickup/delivery workflows
- Filament admin resources (Business, Brand, Product, Order, Invoice, User)
- 51 migrations executed successfully

Renamed Company -> Business throughout codebase for consistency.
Unified authentication flows with password reset.
Added audit trail and telescope for debugging.

Next: Week 4 Data Migration (Days 22-28)
- Product migration (883 products from cannabrands_crm)
- Company migration (81 buyer companies)
- User migration (preserve password hashes)
- Order history migration
2025-10-15 11:17:15 -07:00

70 lines
2.7 KiB
PHP

<?php
namespace App\Filament\Widgets;
use App\Models\Order;
use Filament\Widgets\StatsOverviewWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
class SalesMetrics extends StatsOverviewWidget
{
protected static ?int $sort = 1;
protected ?string $pollingInterval = '60s';
protected function getCards(): array
{
// Total Revenue (all delivered orders)
$totalRevenue = Order::where('status', 'delivered')->sum('total');
// This Month Revenue
$thisMonthRevenue = Order::where('status', 'delivered')
->whereMonth('created_at', now()->month)
->whereYear('created_at', now()->year)
->sum('total');
// Last Month Revenue (for comparison)
$lastMonthRevenue = Order::where('status', 'delivered')
->whereMonth('created_at', now()->subMonth()->month)
->whereYear('created_at', now()->subMonth()->year)
->sum('total');
// Calculate percentage change
$percentageChange = 0;
if ($lastMonthRevenue > 0) {
$percentageChange = (($thisMonthRevenue - $lastMonthRevenue) / $lastMonthRevenue) * 100;
}
// Average Order Value
$deliveredOrders = Order::where('status', 'delivered')->count();
$avgOrderValue = $deliveredOrders > 0 ? $totalRevenue / $deliveredOrders : 0;
// This Week Revenue
$thisWeekRevenue = Order::where('status', 'delivered')
->whereBetween('created_at', [now()->startOfWeek(), now()->endOfWeek()])
->sum('total');
return [
Stat::make('Total Revenue', '$' . number_format($totalRevenue, 2))
->description("From {$deliveredOrders} delivered orders")
->descriptionIcon('heroicon-o-banknotes')
->color('success')
->chart([7, 3, 4, 5, 6, 3, 5, 3]),
Stat::make('Revenue This Month', '$' . number_format($thisMonthRevenue, 2))
->description(
$percentageChange > 0
? number_format($percentageChange, 1) . '% increase from last month'
: number_format(abs($percentageChange), 1) . '% decrease from last month'
)
->descriptionIcon($percentageChange >= 0 ? 'heroicon-o-arrow-trending-up' : 'heroicon-o-arrow-trending-down')
->color($percentageChange >= 0 ? 'success' : 'danger'),
Stat::make('This Week', '$' . number_format($thisWeekRevenue, 2))
->description('Average Order: $' . number_format($avgOrderValue, 2))
->descriptionIcon('heroicon-o-shopping-cart')
->color('info'),
];
}
}