upgrade to filament v4
This commit is contained in:
11
app/Filament/Resources/Clients/Pages/CreateClient.php
Normal file
11
app/Filament/Resources/Clients/Pages/CreateClient.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ClientResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ClientResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateClient extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ClientResource::class;
|
||||
}
|
||||
20
app/Filament/Resources/Clients/Pages/EditClient.php
Normal file
20
app/Filament/Resources/Clients/Pages/EditClient.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ClientResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ClientResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditClient extends EditRecord
|
||||
{
|
||||
protected static string $resource = ClientResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make()->icon('heroicon-s-trash')->requiresConfirmation(),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
142
app/Filament/Resources/Clients/Pages/GeneralLedger.php
Normal file
142
app/Filament/Resources/Clients/Pages/GeneralLedger.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ClientResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ClientResource;
|
||||
use App\Models\Ledger;
|
||||
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\Filters\SelectFilter;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Filament\Resources\Pages\Concerns\InteractsWithRecord;
|
||||
use pxlrbt\FilamentExcel\Actions\Tables\ExportAction;
|
||||
use pxlrbt\FilamentExcel\Exports\ExcelExport;
|
||||
use pxlrbt\FilamentExcel\Columns\Column;
|
||||
|
||||
class GeneralLedger extends Page implements HasTable
|
||||
{
|
||||
use InteractsWithTable;
|
||||
use InteractsWithRecord;
|
||||
|
||||
protected static string $resource = ClientResource::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document-text';
|
||||
|
||||
protected static string $view = 'filament.resources.client-resource.pages.general-ledger';
|
||||
|
||||
public function mount(int | string $record): void
|
||||
{
|
||||
$this->record = $this->resolveRecord($record);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->query(
|
||||
Ledger::query()
|
||||
->where('client_id', $this->getRecord()->id)
|
||||
->with(['account', 'transaction', 'journal'])
|
||||
)
|
||||
->columns([
|
||||
TextColumn::make('date')
|
||||
->label('Date')
|
||||
->state(function (Ledger $record) {
|
||||
return $record->transaction?->happened_on?->format('Y-m-d')
|
||||
?? $record->journal?->happened_on?->format('Y-m-d')
|
||||
?? $record->created_at->format('Y-m-d');
|
||||
})
|
||||
->sortable(),
|
||||
TextColumn::make('account.account')
|
||||
->label('Account')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('description')
|
||||
->limit(50)
|
||||
->tooltip(function (TextColumn $column): ?string {
|
||||
$state = $column->getState();
|
||||
if (strlen($state) <= $column->getCharacterLimit()) {
|
||||
return null;
|
||||
}
|
||||
return $state;
|
||||
}),
|
||||
TextColumn::make('debit_amount')
|
||||
->label('Debit')
|
||||
->money('PHP')
|
||||
->sortable(),
|
||||
TextColumn::make('credit_amount')
|
||||
->label('Credit')
|
||||
->money('PHP')
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('account')
|
||||
->relationship('account', 'account', fn (Builder $query) => $query->where('client_id', $this->getRecord()->id))
|
||||
->searchable()
|
||||
->preload(),
|
||||
Filter::make('date_range')
|
||||
->form([
|
||||
DatePicker::make('from'),
|
||||
DatePicker::make('to'),
|
||||
])
|
||||
->query(function (Builder $query, array $data): Builder {
|
||||
return $query
|
||||
->when(
|
||||
$data['from'],
|
||||
fn (Builder $query, $date): Builder => $query->where(function ($q) use ($date) {
|
||||
$q->whereHas('transaction', fn ($q) => $q->whereDate('happened_on', '>=', $date))
|
||||
->orWhereHas('journal', fn ($q) => $q->whereDate('happened_on', '>=', $date))
|
||||
->orWhere(fn($q) => $q->whereDoesntHave('transaction')->whereDoesntHave('journal')->whereDate('created_at', '>=', $date));
|
||||
})
|
||||
)
|
||||
->when(
|
||||
$data['to'],
|
||||
fn (Builder $query, $date): Builder => $query->where(function ($q) use ($date) {
|
||||
$q->whereHas('transaction', fn ($q) => $q->whereDate('happened_on', '<=', $date))
|
||||
->orWhereHas('journal', fn ($q) => $q->whereDate('happened_on', '<=', $date))
|
||||
->orWhere(fn($q) => $q->whereDoesntHave('transaction')->whereDoesntHave('journal')->whereDate('created_at', '<=', $date));
|
||||
})
|
||||
);
|
||||
})
|
||||
])
|
||||
->defaultSort('created_at', 'desc')
|
||||
->groups([
|
||||
'account.account',
|
||||
])
|
||||
->headerActions([
|
||||
ExportAction::make()
|
||||
->label('Export General Ledger')
|
||||
->exports([
|
||||
ExcelExport::make()
|
||||
->fromTable()
|
||||
->withFilename(fn () => $this->getRecord()->name . ' - General Ledger - ' . date('Y-m-d'))
|
||||
->withColumns([
|
||||
Column::make('date')
|
||||
->heading('Date')
|
||||
->formatStateUsing(fn ($record) => $record->transaction?->happened_on?->format('Y-m-d')
|
||||
?? $record->journal?->happened_on?->format('Y-m-d')
|
||||
?? $record->created_at->format('Y-m-d')),
|
||||
Column::make('reference')
|
||||
->heading('Reference')
|
||||
->formatStateUsing(fn ($record) => match(true) {
|
||||
$record->transaction && $record->transaction->transactionable =>
|
||||
$record->transaction->transactionable->voucher_number
|
||||
?? $record->transaction->transactionable->reference_number
|
||||
?? 'TR-'.$record->transaction->id,
|
||||
$record->transaction => 'TR-'.$record->transaction->id,
|
||||
$record->journal => $record->journal->series ?? 'JV-'.$record->journal->id,
|
||||
default => 'L-'.$record->id,
|
||||
}),
|
||||
Column::make('account.account')->heading('Account'),
|
||||
Column::make('description')->heading('Description'),
|
||||
Column::make('debit_amount')->heading('Debit'),
|
||||
Column::make('credit_amount')->heading('Credit'),
|
||||
])
|
||||
])
|
||||
]);
|
||||
}
|
||||
}
|
||||
25
app/Filament/Resources/Clients/Pages/ListClients.php
Normal file
25
app/Filament/Resources/Clients/Pages/ListClients.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ClientResource\Pages;
|
||||
|
||||
use App\Filament\Exports\ClientExporter;
|
||||
use App\Filament\Resources\ClientResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListClients extends ListRecords
|
||||
{
|
||||
protected static string $resource = ClientResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\ExportAction::make('Export clients')
|
||||
->exporter(ClientExporter::class)
|
||||
->formats([
|
||||
Actions\Exports\Enums\ExportFormat::Csv,
|
||||
]),
|
||||
Actions\CreateAction::make()->slideOver(),
|
||||
];
|
||||
}
|
||||
}
|
||||
100
app/Filament/Resources/Clients/Pages/TrialBalance.php
Normal file
100
app/Filament/Resources/Clients/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;
|
||||
});
|
||||
})
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
49
app/Filament/Resources/Clients/Pages/ViewClient.php
Normal file
49
app/Filament/Resources/Clients/Pages/ViewClient.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ClientResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ClientResource;
|
||||
use Filament\Infolists\Components\Grid;
|
||||
use Filament\Infolists\Components\Section;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Infolists\Infolist;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewClient extends ViewRecord
|
||||
{
|
||||
protected static string $resource = ClientResource::class;
|
||||
|
||||
public function infolist(Infolist $infolist): Infolist
|
||||
{
|
||||
return $infolist
|
||||
->schema([
|
||||
Section::make()->schema([
|
||||
Grid::make()->schema([
|
||||
TextEntry::make('firstname')->label('First Name'),
|
||||
TextEntry::make('middlename')->label('Middle Name'),
|
||||
TextEntry::make('lastname')->label('Last Name'),
|
||||
TextEntry::make('company')->label('Company'),
|
||||
TextEntry::make('type.type')->label('Type'),
|
||||
])->columns(3),
|
||||
]),
|
||||
|
||||
// Section::make('Branches')->schema([
|
||||
// RepeatableEntry::make('branches')
|
||||
// ->schema([
|
||||
// TextEntry::make('code')->label('Branch Code'),
|
||||
// TextEntry::make('current_series')->label('Branch Current Series'),
|
||||
// ])
|
||||
// ->hiddenLabel()
|
||||
// ->grid(2),
|
||||
// ])->collapsible(),
|
||||
]);
|
||||
}
|
||||
|
||||
// public function getRelationManagers(): array
|
||||
// {
|
||||
// return [
|
||||
// AccountsRelationManager::class,
|
||||
// TransmittalsRelationManager::class,
|
||||
// ];
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user