Files
ladill-transfer/app/Http/Controllers/Transfer/OverviewController.php
T
isaaccladandCursor 311b5b40bb
Deploy Ladill Transfer / deploy (push) Successful in 51s
Bill transfer storage monthly with a 15-day grace period before deletion.
Files stay available while wallet renewals succeed each month. Failed renewals
keep files for TRANSFER_GRACE_PERIOD_DAYS (default 15) before automatic cleanup.

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

78 lines
2.4 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)
->accessible();
$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)
->accessible()
->whereNotNull('paid_until')
->whereBetween('paid_until', [now(), now()->addDays(7)])
->count();
$recentTransfers = Transfer::query()
->where('user_id', $account->id)
->accessible()
->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.30), 2);
return view('transfer.dashboard', [
'activeCount' => $activeCount,
'storageBytes' => $storageBytes,
'storageGb' => $storageGb,
'downloads30d' => $downloads30d,
'expiringSoon' => $expiringSoon,
'recentTransfers' => $recentTransfers,
'balanceMinor' => $balanceMinor,
'monthlyEstimateGhs' => $monthlyEstimateGhs,
]);
}
}