Files
ladill-transfer/app/Http/Controllers/Transfer/OverviewController.php
T
isaaccladandCursor e76955eaa4
Deploy Ladill Transfer / deploy (push) Successful in 40s
Reduce Transfer storage price to GHS 0.15 per GB per month.
Updates config default, env examples, and removes hardcoded GHS 1.00 copy on the dashboard.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-08 10:45:12 +00:00

78 lines
2.5 KiB
PHP

<?php
namespace App\Http\Controllers\Transfer;
use App\Http\Controllers\Controller;
use App\Models\Transfer;
use App\Models\TransferDownloadEvent;
use App\Services\Billing\BillingClient;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\View\View;
use Throwable;
class OverviewController extends Controller
{
public function __construct(private BillingClient $billing) {}
public function index(Request $request): View
{
$account = ladill_account();
$transfers = Transfer::query()
->where('user_id', $account->id)
->where('status', Transfer::STATUS_ACTIVE);
$activeCount = (clone $transfers)->count();
$storageBytes = (int) (clone $transfers)->sum('storage_bytes');
$transferIds = Transfer::query()
->where('user_id', $account->id)
->pluck('id');
$downloads30d = TransferDownloadEvent::query()
->whereIn('transfer_id', $transferIds)
->where('downloaded_at', '>=', now()->subDays(30))
->count();
$expiringSoon = Transfer::query()
->where('user_id', $account->id)
->where('status', Transfer::STATUS_ACTIVE)
->whereNotNull('expires_at')
->whereBetween('expires_at', [now(), now()->addDays(7)])
->count();
$recentTransfers = Transfer::query()
->where('user_id', $account->id)
->where('status', Transfer::STATUS_ACTIVE)
->with('qrCode')
->latest()
->limit(6)
->get();
$balanceMinor = 0;
try {
$balanceMinor = $this->billing->balanceMinor($account->public_id);
} catch (Throwable $e) {
Log::warning('Transfer dashboard could not load wallet balance', [
'user' => $account->public_id,
'error' => $e->getMessage(),
]);
}
$storageGb = round($storageBytes / (1024 * 1024 * 1024), 2);
$monthlyEstimateGhs = round($storageGb * (float) config('transfer.price_per_gb_month', 0.15), 2);
return view('transfer.dashboard', [
'activeCount' => $activeCount,
'storageBytes' => $storageBytes,
'storageGb' => $storageGb,
'downloads30d' => $downloads30d,
'expiringSoon' => $expiringSoon,
'recentTransfers' => $recentTransfers,
'balanceMinor' => $balanceMinor,
'monthlyEstimateGhs' => $monthlyEstimateGhs,
]);
}
}