Integrate multi-currency debt visibility across the platform by adding support for foreign currency credits in the user profile shortcode, improving the admin dashboard with unsettled credits widgets, and enhancing the Filament admin panel with navigation badges and relation managers. - Add multi-currency debt table to WordPress user profile shortcode - Implement `UnsettledCreditsWidget` for Filament dashboard - Add navigation badge to `CustomerCreditResource` for open credits - Add `CreditsRelationManager` to `UserResource` - Update `CustomerOrderController` API to include `foreign_credits` - Add concurrency check in `CustomerCreditService` during settlement
116 lines
4.3 KiB
PHP
116 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\UserResource\RelationManagers;
|
|
|
|
use App\Models\CustomerCredit;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\RelationManagers\RelationManager;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
|
|
class CreditsRelationManager extends RelationManager
|
|
{
|
|
protected static string $relationship = 'credits';
|
|
|
|
protected static ?string $title = 'اعتبارها و بدهیهای چندارزی';
|
|
|
|
protected static ?string $modelLabel = 'اعتبار';
|
|
protected static ?string $pluralModelLabel = 'اعتبارها';
|
|
|
|
public function form(Form $form): Form
|
|
{
|
|
return $form->schema([
|
|
Forms\Components\TextInput::make('currency_code')
|
|
->label('ارز')
|
|
->disabled(),
|
|
Forms\Components\TextInput::make('amount')
|
|
->label('مبلغ کل')
|
|
->disabled(),
|
|
Forms\Components\TextInput::make('settled_amount')
|
|
->label('تسویهشده')
|
|
->disabled(),
|
|
]);
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('currency_code')
|
|
->label('ارز')
|
|
->badge()
|
|
->color('info'),
|
|
|
|
Tables\Columns\TextColumn::make('amount')
|
|
->label('مبلغ کل')
|
|
->numeric(2)
|
|
->sortable(),
|
|
|
|
Tables\Columns\TextColumn::make('settled_amount')
|
|
->label('تسویهشده')
|
|
->numeric(2)
|
|
->color('success'),
|
|
|
|
Tables\Columns\TextColumn::make('balance')
|
|
->label('مانده')
|
|
->numeric(2)
|
|
->badge()
|
|
->color(fn ($record) => $record->balance > 0 ? 'danger' : 'gray'),
|
|
|
|
Tables\Columns\TextColumn::make('status')
|
|
->label('وضعیت')
|
|
->badge()
|
|
->formatStateUsing(fn (string $state) => match ($state) {
|
|
'open' => 'باز',
|
|
'partially_settled' => 'نیمهتسویه',
|
|
'settled' => 'تسویهشده',
|
|
default => $state,
|
|
})
|
|
->color(fn (string $state) => match ($state) {
|
|
'open' => 'danger',
|
|
'partially_settled' => 'warning',
|
|
'settled' => 'success',
|
|
default => 'gray',
|
|
}),
|
|
|
|
Tables\Columns\TextColumn::make('reason')
|
|
->label('دلیل')
|
|
->limit(40)
|
|
->toggleable(),
|
|
|
|
Tables\Columns\TextColumn::make('granted_at')
|
|
->label('تاریخ اعطا')
|
|
->dateTime('Y/m/d')
|
|
->sortable(),
|
|
])
|
|
->filters([
|
|
Tables\Filters\SelectFilter::make('status')
|
|
->label('وضعیت')
|
|
->options([
|
|
'open' => 'باز',
|
|
'partially_settled' => 'نیمهتسویه',
|
|
'settled' => 'تسویهشده',
|
|
]),
|
|
Tables\Filters\SelectFilter::make('currency_code')
|
|
->label('ارز')
|
|
->options(fn () => CustomerCredit::select('currency_code')
|
|
->distinct()
|
|
->orderBy('currency_code')
|
|
->pluck('currency_code', 'currency_code')
|
|
->toArray()),
|
|
])
|
|
->headerActions([
|
|
// ایجاد اعتبار فقط از طریق CustomerCreditResource (با Policy)
|
|
Tables\Actions\Action::make('manage_credits')
|
|
->label('مدیریت اعتبارها')
|
|
->icon('heroicon-o-arrow-left')
|
|
->url(fn () => route('filament.admin.resources.customer-credits.index'))
|
|
->color('primary'),
|
|
])
|
|
->actions([
|
|
Tables\Actions\ViewAction::make(),
|
|
])
|
|
->defaultSort('created_at', 'desc');
|
|
}
|
|
} |