SebboRR
SebboRR
FFilament
Created by SebboRR on 3/17/2024 in #❓┊help
How to GrpupBy and Sum in Widget Table.
Ok, it took me a while to get it to work, but it's working now
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')),
]);
}
}
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')),
]);
}
}
3 replies
FFilament
Created by SebboRR on 2/28/2024 in #❓┊help
How to set custom badge color based on color picker.
Ok i definied colors from tailwind default color palette in boot():
FilamentColor::register([
'gray' => Color::Gray,
'zinc' => Color::Zinc,
'neutral' => Color::Neutral,
'stone' => Color::Stone,
'red' => Color::Red,
'orange' => Color::Orange,
'amber' => Color::Amber,
'yellow' => Color::Yellow,
'lime' => Color::Lime,
'green' => Color::Green,
'emerald' => Color::Emerald,
'teal' => Color::Teal,
'cyan' => Color::Cyan,
'sky' => Color::Sky,
'blue' => Color::Blue,
'indigo' => Color::Indigo,
'violet' => Color::Violet,
'purple' => Color::Purple,
'fuchsia' => Color::Fuchsia,
'pink' => Color::Pink,
'rose' => Color::Rose,
]);
FilamentColor::register([
'gray' => Color::Gray,
'zinc' => Color::Zinc,
'neutral' => Color::Neutral,
'stone' => Color::Stone,
'red' => Color::Red,
'orange' => Color::Orange,
'amber' => Color::Amber,
'yellow' => Color::Yellow,
'lime' => Color::Lime,
'green' => Color::Green,
'emerald' => Color::Emerald,
'teal' => Color::Teal,
'cyan' => Color::Cyan,
'sky' => Color::Sky,
'blue' => Color::Blue,
'indigo' => Color::Indigo,
'violet' => Color::Violet,
'purple' => Color::Purple,
'fuchsia' => Color::Fuchsia,
'pink' => Color::Pink,
'rose' => Color::Rose,
]);
Then i can use it in badge color()
9 replies
FFilament
Created by SebboRR on 2/28/2024 in #❓┊help
How to set custom badge color based on color picker.
Thank you for your answer, but the function ->color() seems to only accept arguments: 'primary', 'success' , etc... . I probably need to write my own template for bage.
9 replies
FFilament
Created by SebboRR on 2/28/2024 in #❓┊help
How to set custom badge color based on color picker.
Color is in crm_level table in color_picker column
9 replies
FFilament
Created by SebboRR on 2/28/2024 in #❓┊help
How to set custom badge color based on color picker.
I want to have custom color based on $record->crm_level->color_picker
9 replies
FFilament
Created by SebboRR on 2/28/2024 in #❓┊help
How to set custom badge color based on color picker.
In table:
Tables\Columns\TextColumn::make('crm_level.name')
->searchable()
->sortable()
->badge()
->color(fn (Company $record): string => match ($record->crm_level->id) {
1 => 'success',
2 => 'warning',
3 => 'gray',
default => 'gray',
})
Tables\Columns\TextColumn::make('crm_level.name')
->searchable()
->sortable()
->badge()
->color(fn (Company $record): string => match ($record->crm_level->id) {
1 => 'success',
2 => 'warning',
3 => 'gray',
default => 'gray',
})
9 replies
FFilament
Created by SebboRR on 2/20/2024 in #❓┊help
Many to Many (Polymorphic) in Table View
Thank you very much, it worked 😉
5 replies