class InstrumentsInAccounts extends BaseWidget
{
protected int | string | array $columnSpan = 'full';
protected static ?int $sort = 2;
public int | string $perPage = 20;
public function table(Table $table): Table
{
return $table
->query(
TransactionResource::getEloquentQuery()
->where('number','>',0)
->groupBy('account_id', 'instrument_id')
->select(
'id',
'account_id',
'instrument_id',
'transaction_type',
DB::raw('SUM(number) as number'),
DB::raw('SUM(value) * -1 as value'),
DB::raw('AVG(price) as price')
)
)
->columns([
TextColumn::make('account.name')->sortable(),
TextColumn::make('instrument.name'),
TextColumn::make('instrument.ticker_google_finanse')
->label(__('Ticker')),
TextColumn::make('price')
->label(__('AVG Price'))
->money('PLN', locale: 'pl')
->alignRight(),
TextColumn::make('number')
->label(__('Quantity available'))
->alignRight()
->summarize(Sum::make()),
TextColumn::make('value')
->label(__('Purchase equity'))
->money('PLN', locale: 'pl')
->alignRight()
->summarize(Sum::make()->label('Total value')),
]);
}
}