show total sum by filters

I have blade file where i'm showing my total sum and total part sum.. i want to show sum of all column table.
No description
20 Replies
gigiloouu
gigiloouuOP2w ago
Like in Total Sum i want show all total and in Total part Sum i want show all total part sum also i have filter and when i filter i want to re render and show new total sum of this showed columns anyone please (( ??
Hitesh Makwana
GitHub
demo/app/Filament/Resources/Shop/OrderResource.php at main · filame...
Source code for the demo.filamentphp.com website. Contribute to filamentphp/demo development by creating an account on GitHub.
gigiloouu
gigiloouuOP2w ago
this is my blade
<div class="flex justify-between">
<div class="flex flex-col space-y-4">
<h3 class="text-xl font-semibold">გადახდილი ჯამი: <span style="color: green" class="font-normal text-gray-700">{{ number_format($totalSum, 2) }}</span></h3>
<h3 class="text-xl font-semibold">დაგეგმილი ჯამი: <span style="color: green" class="font-normal text-gray-700">{{ number_format($totalPartSum, 2) }}</span></h3>
</div>

<div class="mt-6">
<a style="background-color: orange" href="{{ $createRoute }}" class="inline-block !bg-orange-500 text-white py-2 px-6 rounded-lg shadow-lg hover:bg-orange-600 focus:outline-none focus:ring-2 focus:ring-orange-400">
Create New Non-Commercial Expense
</a>
</div>
</div>
<div class="flex justify-between">
<div class="flex flex-col space-y-4">
<h3 class="text-xl font-semibold">გადახდილი ჯამი: <span style="color: green" class="font-normal text-gray-700">{{ number_format($totalSum, 2) }}</span></h3>
<h3 class="text-xl font-semibold">დაგეგმილი ჯამი: <span style="color: green" class="font-normal text-gray-700">{{ number_format($totalPartSum, 2) }}</span></h3>
</div>

<div class="mt-6">
<a style="background-color: orange" href="{{ $createRoute }}" class="inline-block !bg-orange-500 text-white py-2 px-6 rounded-lg shadow-lg hover:bg-orange-600 focus:outline-none focus:ring-2 focus:ring-orange-400">
Create New Non-Commercial Expense
</a>
</div>
</div>
and this is my list resource file
<?php

namespace App\Filament\Resources\NonCommercialExpenseResource\Pages;

use App\Filament\Resources\NonCommercialExpenseResource;
use App\Models\NonCommercial;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Contracts\View\View;

class ListNonCommercialExpenses extends ListRecords
{
protected static string $resource = NonCommercialExpenseResource::class;


public function getHeader(): ?View
{

return view('filament.custom-companysum', [
'totalSum' => $totalSum,
'totalPartSum' => $totalPartSum,
'createRoute' => url('/admin/non-commercial-expenses/create'),
]);
}
}
<?php

namespace App\Filament\Resources\NonCommercialExpenseResource\Pages;

use App\Filament\Resources\NonCommercialExpenseResource;
use App\Models\NonCommercial;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Contracts\View\View;

class ListNonCommercialExpenses extends ListRecords
{
protected static string $resource = NonCommercialExpenseResource::class;


public function getHeader(): ?View
{

return view('filament.custom-companysum', [
'totalSum' => $totalSum,
'totalPartSum' => $totalPartSum,
'createRoute' => url('/admin/non-commercial-expenses/create'),
]);
}
}
i just want to take totalSum and totalpartSum
gigiloouu
gigiloouuOP2w ago
i dont have total column in my table like in my table i have many inputs i just take all this input and make sum in my code this is my table btw
gigiloouu
gigiloouuOP2w ago
gigiloouu
gigiloouuOP2w ago
there is my table code
Hitesh Makwana
Tables\Columns\TextColumn::make('total')
->sortable()
->summarize([
Tables\Columns\Summarizers\Sum::make()
->money(),
]),
Tables\Columns\TextColumn::make('total')
->sortable()
->summarize([
Tables\Columns\Summarizers\Sum::make()
->money(),
]),
gigiloouu
gigiloouuOP2w ago
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'non_commercials.total' in 'field list' (Connection: mysql, SQL: select sum(non_commercials.total_part) as "lNxh3bBabCUXw2R8" from (select * from non_commercials) as non_commercials) i dont have total in my table is it nessesary ? like im saving total only in my code not db
Hitesh Makwana
use only
->summarize([
Tables\Columns\Summarizers\Sum::make()
->money(),
])
->summarize([
Tables\Columns\Summarizers\Sum::make()
->money(),
])
gigiloouu
gigiloouuOP2w ago
for table? or for textColumn for table i have error Method Filament\Tables\Table::summarize does not exist. and for textColumns its write to its doesnt exist ?
Hitesh Makwana
for column
gigiloouu
gigiloouuOP2w ago
gigiloouu
gigiloouuOP2w ago
like that?
Hitesh Makwana
yes test it once
gigiloouu
gigiloouuOP2w ago
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'non_commercials.total' in 'field list' (Connection: mysql, SQL: select sum(non_commercials.total) as "U6Cs8X2Up1514m57" from (select * from `non_commercials`) as `non_commercials`)
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'non_commercials.total' in 'field list' (Connection: mysql, SQL: select sum(non_commercials.total) as "U6Cs8X2Up1514m57" from (select * from `non_commercials`) as `non_commercials`)
i have this error without summarize its works btw
Hitesh Makwana
try with using function same as you use for get column record
gigiloouu
gigiloouuOP2w ago
how can u write it please? ?? i try ->summarize(function ($records) { return $records->sum('amount'); // Summing the 'amount' field from the records }) like this but not working
gigiloouu
gigiloouuOP2w ago
okay i wil ltry thanks thats working thanks! i just use custom summarize ->summarize(Summarizer::make() ->label('გადახდილი ჯამი') ->using(function (Builder $query) {}

Did you find this page helpful?