feat(client): add financial reports and ledger management
- Add trial balance and general ledger pages to client resource with interactive tables - Implement sales and expenses relation managers for client-specific transactions - Enhance transaction handling with proper tax and withholding calculations - Add date casting to Transaction model and define client relationships - Configure super admin role bypass in AppServiceProvider - Update Filament components and fix JavaScript formatting issues
This commit is contained in:
100
app/Filament/Resources/ClientResource/Pages/TrialBalance.php
Normal file
100
app/Filament/Resources/ClientResource/Pages/TrialBalance.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ClientResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ClientResource;
|
||||
use App\Models\Account;
|
||||
use Filament\Resources\Pages\Page;
|
||||
use Filament\Tables\Concerns\InteractsWithTable;
|
||||
use Filament\Tables\Contracts\HasTable;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\Summarizers\Summarizer;
|
||||
use Filament\Tables\Columns\Summarizers\Sum;
|
||||
use Filament\Resources\Pages\Concerns\InteractsWithRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class TrialBalance extends Page implements HasTable
|
||||
{
|
||||
use InteractsWithTable;
|
||||
use InteractsWithRecord;
|
||||
|
||||
protected static string $resource = ClientResource::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-scale';
|
||||
|
||||
protected static string $view = 'filament.resources.client-resource.pages.trial-balance';
|
||||
|
||||
public function mount(int | string $record): void
|
||||
{
|
||||
$this->record = $this->resolveRecord($record);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->query(
|
||||
Account::query()
|
||||
->where('client_id', $this->getRecord()->id)
|
||||
->with(['accountType', 'latestBalance'])
|
||||
)
|
||||
->columns([
|
||||
TextColumn::make('account')
|
||||
->label('Account Name')
|
||||
->sortable()
|
||||
->searchable(),
|
||||
TextColumn::make('debit')
|
||||
->label('Debit')
|
||||
->money('PHP')
|
||||
->state(function (Account $record) {
|
||||
$balance = $record->latestBalance?->balance ?? 0;
|
||||
$normal = strtolower($record->accountType->normal_balance ?? 'debit');
|
||||
|
||||
return ($normal == 'debit' && $balance >= 0) || ($normal == 'credit' && $balance < 0)
|
||||
? abs($balance) : 0;
|
||||
})
|
||||
->summarize(Summarizer::make()
|
||||
->label('Total Debit')
|
||||
->money('PHP')
|
||||
->using(function ($query) {
|
||||
return Account::query()
|
||||
->whereIn('id', $query->clone()->pluck('accounts.id'))
|
||||
->with(['accountType', 'latestBalance'])
|
||||
->get()
|
||||
->sum(function ($record) {
|
||||
$balance = $record->latestBalance?->balance ?? 0;
|
||||
$normal = strtolower($record->accountType->normal_balance ?? 'debit');
|
||||
return ($normal == 'debit' && $balance >= 0) || ($normal == 'credit' && $balance < 0)
|
||||
? abs($balance) : 0;
|
||||
});
|
||||
})
|
||||
),
|
||||
TextColumn::make('credit')
|
||||
->label('Credit')
|
||||
->money('PHP')
|
||||
->state(function (Account $record) {
|
||||
$balance = $record->latestBalance?->balance ?? 0;
|
||||
$normal = strtolower($record->accountType->normal_balance ?? 'debit');
|
||||
|
||||
return ($normal == 'credit' && $balance >= 0) || ($normal == 'debit' && $balance < 0)
|
||||
? abs($balance) : 0;
|
||||
})
|
||||
->summarize(Summarizer::make()
|
||||
->label('Total Credit')
|
||||
->money('PHP')
|
||||
->using(function ($query) {
|
||||
return Account::query()
|
||||
->whereIn('id', $query->clone()->pluck('accounts.id'))
|
||||
->with(['accountType', 'latestBalance'])
|
||||
->get()
|
||||
->sum(function ($record) {
|
||||
$balance = $record->latestBalance?->balance ?? 0;
|
||||
$normal = strtolower($record->accountType->normal_balance ?? 'debit');
|
||||
return ($normal == 'credit' && $balance >= 0) || ($normal == 'debit' && $balance < 0)
|
||||
? abs($balance) : 0;
|
||||
});
|
||||
})
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user