Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/Admin/StatsController.php
Show First 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | protected function chartIncome(): array | ||||
$labels = array_reverse($labels); | $labels = array_reverse($labels); | ||||
$start->startOfWeek(Carbon::MONDAY); | $start->startOfWeek(Carbon::MONDAY); | ||||
// FIXME: We're using wallets.currency instead of payments.currency and payments.currency_amount | // FIXME: We're using wallets.currency instead of payments.currency and payments.currency_amount | ||||
// as I believe this way we have more precise amounts for this use-case (and default currency) | // as I believe this way we have more precise amounts for this use-case (and default currency) | ||||
$query = DB::table('payments') | $query = DB::table('payments') | ||||
->selectRaw("date_format(updated_at, '%Y-%v') as period, sum(amount) as amount, wallets.currency") | ->selectRaw("date_format(updated_at, '%Y-%v') as period, sum(credit_amount) as amount, wallets.currency") | ||||
->join('wallets', 'wallets.id', '=', 'wallet_id') | ->join('wallets', 'wallets.id', '=', 'wallet_id') | ||||
->where('updated_at', '>=', $start->toDateString()) | ->where('updated_at', '>=', $start->toDateString()) | ||||
->where('status', PaymentProvider::STATUS_PAID) | ->where('status', PaymentProvider::STATUS_PAID) | ||||
->whereIn('type', [PaymentProvider::TYPE_ONEOFF, PaymentProvider::TYPE_RECURRING]) | ->whereIn('type', [PaymentProvider::TYPE_ONEOFF, PaymentProvider::TYPE_RECURRING]) | ||||
->groupByRaw('period, wallets.currency'); | ->groupByRaw('period, wallets.currency'); | ||||
$addTenantScope = function ($builder, $tenantId) { | $addTenantScope = function ($builder, $tenantId) { | ||||
$where = sprintf( | $where = sprintf( | ||||
▲ Show 20 Lines • Show All 392 Lines • Show Last 20 Lines |