Introduce a comprehensive design system across WordPress and Laravel to ensure visual consistency. Implement new financial reporting capabilities and Excel export functionality within the Filament admin panel. - Add `DESIGN_SYSTEM.md` to define brand colors, typography, and spacing - Implement `FinancialReport` page in Filament for transaction and shipment summaries - Add Excel export support for `ShipmentResource` and `WalletTransactionResource` using Laravel Excel - Refactor WordPress plugin and Filament CSS to utilize the new design system variables - Update project status to reflect new reporting and design milestones
165 lines
6.9 KiB
PHP
165 lines
6.9 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\WalletTransactionResource\Pages;
|
|
use App\Models\WalletTransaction;
|
|
use App\Enums\TransactionType;
|
|
use App\Enums\TransactionStatus;
|
|
use App\Enums\PaymentGateway;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use App\Exports\WalletTransactionsExport;
|
|
use Filament\Tables\Actions\ExportAction;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
|
|
class WalletTransactionResource extends Resource
|
|
{
|
|
protected static ?string $model = WalletTransaction::class;
|
|
protected static ?string $navigationIcon = 'heroicon-o-arrows-right-left';
|
|
protected static ?string $navigationLabel = 'تراکنشها';
|
|
protected static ?string $navigationGroup = 'مالی';
|
|
protected static ?int $navigationSort = 2;
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form->schema([
|
|
Forms\Components\Section::make('اطلاعات تراکنش')
|
|
->schema([
|
|
Forms\Components\Select::make('wallet_id')
|
|
->relationship('wallet', 'id')
|
|
->searchable()
|
|
->preload()
|
|
->required()
|
|
->label('کیف پول'),
|
|
Forms\Components\TextInput::make('amount')
|
|
->numeric()
|
|
->suffix('ریال')
|
|
->required()
|
|
->label('مبلغ'),
|
|
Forms\Components\Select::make('type')
|
|
->options(TransactionType::class)
|
|
->required()
|
|
->label('نوع'),
|
|
Forms\Components\Select::make('status')
|
|
->options(TransactionStatus::class)
|
|
->required()
|
|
->label('وضعیت'),
|
|
Forms\Components\Select::make('gateway')
|
|
->options(PaymentGateway::class)
|
|
->label('درگاه'),
|
|
Forms\Components\TextInput::make('gateway_reference_id')
|
|
->label('کد پیگیری'),
|
|
Forms\Components\Textarea::make('description')
|
|
->label('توضیحات')
|
|
->maxLength(1000),
|
|
Forms\Components\Textarea::make('admin_notes')
|
|
->label('یادداشت ادمین')
|
|
->maxLength(2000),
|
|
])
|
|
->columns(2),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('id')
|
|
->label('شناسه')
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('wallet.user.name')
|
|
->label('کاربر')
|
|
->searchable(),
|
|
Tables\Columns\TextColumn::make('amount')
|
|
->label('مبلغ')
|
|
->money('IRR', divideBy: 1)
|
|
->color(fn ($record) => $record->amount >= 0 ? 'success' : 'danger')
|
|
->sortable(),
|
|
Tables\Columns\BadgeColumn::make('type')
|
|
->label('نوع')
|
|
->getStateUsing(fn ($record) => $record->type->label())
|
|
->colors([
|
|
'success' => TransactionType::DEPOSIT,
|
|
'danger' => TransactionType::WITHDRAWAL,
|
|
'warning' => TransactionType::ORDER_PAYMENT,
|
|
'info' => TransactionType::REFUND,
|
|
]),
|
|
Tables\Columns\BadgeColumn::make('status')
|
|
->label('وضعیت')
|
|
->getStateUsing(fn ($record) => $record->status->label())
|
|
->colors([
|
|
'success' => TransactionStatus::COMPLETED,
|
|
'warning' => TransactionStatus::PENDING,
|
|
'danger' => TransactionStatus::FAILED,
|
|
'info' => TransactionStatus::REFUNDED,
|
|
]),
|
|
Tables\Columns\BadgeColumn::make('gateway')
|
|
->label('درگاه')
|
|
->getStateUsing(fn ($record) => $record->gateway?->label() ?? '-')
|
|
->colors([
|
|
'primary' => PaymentGateway::ZARINPAL,
|
|
'success' => PaymentGateway::MANUAL,
|
|
'gray' => PaymentGateway::SYSTEM,
|
|
]),
|
|
Tables\Columns\TextColumn::make('gateway_reference_id')
|
|
->label('کد پیگیری')
|
|
->searchable()
|
|
->toggleable(),
|
|
Tables\Columns\TextColumn::make('description')
|
|
->label('توضیحات')
|
|
->limit(50)
|
|
->toggleable(),
|
|
Tables\Columns\TextColumn::make('creator.name')
|
|
->label('ایجادکننده')
|
|
->toggleable(),
|
|
Tables\Columns\TextColumn::make('created_at')
|
|
->dateTime('Y/m/d H:i', 'Asia/Tehran')
|
|
->label('تاریخ')
|
|
->sortable(),
|
|
])
|
|
->defaultSort('created_at', 'desc')
|
|
->filters([
|
|
Tables\Filters\SelectFilter::make('type')
|
|
->options(TransactionType::class)
|
|
->label('نوع تراکنش'),
|
|
Tables\Filters\SelectFilter::make('status')
|
|
->options(TransactionStatus::class)
|
|
->label('وضعیت'),
|
|
Tables\Filters\SelectFilter::make('gateway')
|
|
->options(PaymentGateway::class)
|
|
->label('درگاه'),
|
|
])
|
|
->actions([
|
|
Tables\Actions\ViewAction::make(),
|
|
])
|
|
->headerActions([
|
|
ExportAction::make()
|
|
->label('خروجی Excel')
|
|
->icon('heroicon-o-arrow-down-tray')
|
|
->color('success')
|
|
->export(fn ($query) => new WalletTransactionsExport([
|
|
'type' => request()->input('filters.type'),
|
|
'status' => request()->input('filters.status'),
|
|
'gateway' => request()->input('filters.gateway'),
|
|
]))
|
|
->fileName('transactions_' . now()->format('Y-m-d_H-i')),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListWalletTransactions::route('/'),
|
|
'view' => Pages\ViewWalletTransaction::route('/{record}'),
|
|
];
|
|
}
|
|
} |