Skip to content

Commit

Permalink
Account detail page added
Browse files Browse the repository at this point in the history
  • Loading branch information
afsakar committed May 26, 2023
1 parent e33b435 commit 9ac0795
Show file tree
Hide file tree
Showing 17 changed files with 500 additions and 7 deletions.
3 changes: 1 addition & 2 deletions app/Filament/Pages/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@ protected function getWidgets(): array
{
return [
AccountWidget::class,
FilamentInfoWidget::class,
RevenueWidget::class,
];
}

protected function getColumns(): int | string | array
{
return 2;
return 1;
}

protected function getTitle(): string
Expand Down
14 changes: 14 additions & 0 deletions app/Filament/Resources/AccountResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
use App\Filament\Resources\AccountResource\RelationManagers;
use App\Models\Account;
use App\Models\AccountType;
use Filament\Tables\Actions\Action;
use App\Models\Currency;
use Filament\Forms;
use Filament\Forms\Components\Card;
use Filament\Forms\Components\Grid;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class AccountResource extends Resource
Expand All @@ -22,6 +25,8 @@ class AccountResource extends Resource

protected static ?string $navigationIcon = 'heroicon-o-cash';

public ?Model $record = null;

public static function form(Form $form): Form
{
return $form
Expand Down Expand Up @@ -71,6 +76,14 @@ public static function table(Table $table): Table
Tables\Filters\TrashedFilter::make(),
])
->actions([
Action::make('detail')
->label('Detail')
->color('blue')
->icon('heroicon-s-document')
->hidden(fn ($record) => !$record->has_any_relation)
->url(function ($record) {
return route('filament.resources.accounts.detail', ['record' => $record]);
}),
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make()
Expand All @@ -85,6 +98,7 @@ public static function getPages(): array
{
return [
'index' => Pages\ManageAccounts::route('/'),
'detail' => Pages\AccountDetail::route('/{record}/detail'),
];
}

Expand Down
34 changes: 34 additions & 0 deletions app/Filament/Resources/AccountResource/Pages/AccountDetail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Filament\Resources\AccountResource\Pages;

use App\Filament\Resources\AccountResource;
use App\Models\Account;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Filament\Resources\Pages\Page;
use Illuminate\Database\Eloquent\Model;
use Filament\Tables;
use Illuminate\Contracts\View\View;
use Webbingbrasil\FilamentDateFilter\DateFilter;
use Filament\Forms;
use Filament\Tables\Filters\Filter;

class AccountDetail extends Page implements Tables\Contracts\HasTable
{
use Tables\Concerns\InteractsWithTable;

protected static string $resource = AccountResource::class;

protected static string $view = 'filament.resources.account-resource.pages.account-detail';

public $record;

public $account;

public function mount($record)
{
$this->record = $record;
$this->account = Account::find($record);
}
}
1 change: 1 addition & 0 deletions app/Filament/Resources/RevenueResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Filament\Resources\RevenueResource\Widgets\RevenueWidget;
use App\Models\Account;
use App\Models\Company;
use App\Models\Invoice;
use App\Models\Revenue;
use Carbon\Carbon;
use Closure;
Expand Down
105 changes: 105 additions & 0 deletions app/Http/Livewire/Account/ExpenseTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

namespace App\Http\Livewire\Account;

use Carbon\Carbon;
use Filament\Forms;
use Filament\Tables;
use App\Models\Account;
use App\Models\Expense;
use Livewire\Component;
use Filament\Tables\Filters\Filter;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;

class ExpenseTable extends Component implements Tables\Contracts\HasTable
{
use Tables\Concerns\InteractsWithTable;

public $accountID;

protected function getTableQuery(): Builder
{
return Expense::query()->where('account_id', $this->accountID);
}

protected function getTableColumns(): array
{
return [
Tables\Columns\TextColumn::make('due_at')
->label('Date')
->sortable()
->dateTime('d/m/Y'),
Tables\Columns\TextColumn::make('description')
->searchable(),
Tables\Columns\TextColumn::make('company.name')
->searchable()
->label('Company'),
Tables\Columns\TextColumn::make('corporation.name')
->searchable()
->label('Corporation'),
Tables\Columns\TextColumn::make('amount_with_currency')
->label('Amount')
->formatStateUsing(fn ($state) => '-' . $state)
->sortable(),
];
}

protected function getTableFilters(): array
{
return [
Filter::make('due_at')
->form([
Forms\Components\DatePicker::make('due_from')
->default(Carbon::now()->subYear())
->closeOnDateSelection()
->timezone('Europe/Istanbul')
->label('From Date'),
Forms\Components\DatePicker::make('due_until')
->closeOnDateSelection()
->timezone('Europe/Istanbul')
->label('To Date')
])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['due_from'],
fn (Builder $query, $date): Builder => $query->whereDate('due_at', '>=', $date),
)
->when(
$data['due_until'],
fn (Builder $query, $date): Builder => $query->whereDate('due_at', '<=', $date),
);
}),
Filter::make('amount')
->form([
Forms\Components\TextInput::make('min_amount')
->label('Min Amount'),
Forms\Components\TextInput::make('max_amount')
->label('Max Amount')
])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['min_amount'],
fn (Builder $query, $amount): Builder => $query->where('amount', '>=', $amount),
)
->when(
$data['max_amount'],
fn (Builder $query, $amount): Builder => $query->where('amount', '<=', $amount),
);
}),
];
}

protected function getTableFiltersFormColumns(): int
{
return 2;
}

public function render()
{
return view('livewire.account.expense-table');
}
}
104 changes: 104 additions & 0 deletions app/Http/Livewire/Account/RevenueTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

namespace App\Http\Livewire\Account;

use Carbon\Carbon;
use Filament\Forms;
use Filament\Tables;
use App\Models\Account;
use App\Models\Revenue;
use Livewire\Component;
use Filament\Tables\Filters\Filter;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;

class RevenueTable extends Component implements Tables\Contracts\HasTable
{
use Tables\Concerns\InteractsWithTable;

public $accountID;

protected function getTableQuery(): Builder
{
return Revenue::query()->where('account_id', $this->accountID);
}

protected function getTableColumns(): array
{
return [
Tables\Columns\TextColumn::make('due_at')
->label('Date')
->sortable()
->dateTime('d/m/Y'),
Tables\Columns\TextColumn::make('description')
->searchable(),
Tables\Columns\TextColumn::make('company.name')
->searchable()
->label('Company'),
Tables\Columns\TextColumn::make('corporation.name')
->searchable()
->label('Corporation'),
Tables\Columns\TextColumn::make('amount_with_currency')
->label('Amount')
->sortable(),
];
}

protected function getTableFilters(): array
{
return [
Filter::make('due_at')
->form([
Forms\Components\DatePicker::make('due_from')
->default(Carbon::now()->subYear())
->closeOnDateSelection()
->timezone('Europe/Istanbul')
->label('From Date'),
Forms\Components\DatePicker::make('due_until')
->closeOnDateSelection()
->timezone('Europe/Istanbul')
->label('To Date')
])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['due_from'],
fn (Builder $query, $date): Builder => $query->whereDate('due_at', '>=', $date),
)
->when(
$data['due_until'],
fn (Builder $query, $date): Builder => $query->whereDate('due_at', '<=', $date),
);
}),
Filter::make('amount')
->form([
Forms\Components\TextInput::make('min_amount')
->label('Min Amount'),
Forms\Components\TextInput::make('max_amount')
->label('Max Amount')
])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['min_amount'],
fn (Builder $query, $amount): Builder => $query->where('amount', '>=', $amount),
)
->when(
$data['max_amount'],
fn (Builder $query, $amount): Builder => $query->where('amount', '<=', $amount),
);
}),
];
}

protected function getTableFiltersFormColumns(): int
{
return 2;
}

public function render(): View
{
return view('livewire.account.revenue-table');
}
}
Loading

0 comments on commit 9ac0795

Please sign in to comment.