31 lines
1.0 KiB
PHP
31 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use App\Models\SettlementBatch;
|
|
|
|
final class SettlementBatchFinancialSummary
|
|
{
|
|
/**
|
|
* @return array{total_bet_amount: int, total_actual_deduct: int, platform_profit: int}
|
|
*/
|
|
public static function forBatch(SettlementBatch $batch): array
|
|
{
|
|
$totals = $batch->details()
|
|
->join('ticket_items', 'ticket_items.id', '=', 'ticket_settlement_details.ticket_item_id')
|
|
->selectRaw('COALESCE(SUM(ticket_items.total_bet_amount), 0) as total_bet_amount')
|
|
->selectRaw('COALESCE(SUM(ticket_items.actual_deduct_amount), 0) as total_actual_deduct')
|
|
->first();
|
|
|
|
$totalBet = (int) ($totals?->total_bet_amount ?? 0);
|
|
$totalActualDeduct = (int) ($totals?->total_actual_deduct ?? 0);
|
|
$totalPayout = (int) $batch->total_payout_amount;
|
|
|
|
return [
|
|
'total_bet_amount' => $totalBet,
|
|
'total_actual_deduct' => $totalActualDeduct,
|
|
'platform_profit' => $totalActualDeduct - $totalPayout,
|
|
];
|
|
}
|
|
}
|