Added transaction details for the logged user
This commit is contained in:
@@ -8,7 +8,6 @@ use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\CoinTransaction;
|
||||
use App\Models\CoinTransactionType;
|
||||
|
||||
class StatisticsController extends Controller
|
||||
{
|
||||
@@ -86,7 +85,6 @@ class StatisticsController extends Controller
|
||||
->groupBy('type')
|
||||
->get();
|
||||
|
||||
// 3. Games Per Month (Line/Bar Chart)
|
||||
$gamesPerMonth = Game::select(
|
||||
DB::raw('DATE_FORMAT(began_at, "%Y-%m") as month'),
|
||||
DB::raw('count(*) as total')
|
||||
@@ -97,19 +95,13 @@ class StatisticsController extends Controller
|
||||
->limit(12)
|
||||
->get();
|
||||
|
||||
// 4. Financial/Coin Stats (Using the new Tables)
|
||||
// We calculate "Revenue" based on the volume of "Coin purchase" transactions
|
||||
|
||||
// Calculate Total Coins Purchased (All time)
|
||||
// We join with types table to filter by name "Coin purchase"
|
||||
|
||||
$totalCoinsPurchased = CoinTransaction::whereHas('type', function($q) {
|
||||
$q->where('name', 'Coin purchase');
|
||||
})
|
||||
->sum('coins');
|
||||
|
||||
// Calculate Purchases Per Month (Time Series)
|
||||
// Groups by 'transaction_datetime' (YYYY-MM)
|
||||
$purchasesPerMonth = \App\Models\CoinTransaction::join('coin_transaction_types', 'coin_transactions.coin_transaction_type_id', '=', 'coin_transaction_types.id')
|
||||
$purchasesPerMonth = CoinTransaction::join('coin_transaction_types', 'coin_transactions.coin_transaction_type_id', '=', 'coin_transaction_types.id')
|
||||
->where('coin_transaction_types.name', 'Coin purchase')
|
||||
->select(
|
||||
DB::raw('DATE_FORMAT(coin_transactions.transaction_datetime, "%Y-%m") as month'),
|
||||
|
||||
Reference in New Issue
Block a user