ifnex/04_Laravel/app/Filament/Resources/CommitmentFormResource.php
Kazem Alghasi 02c29db696 feat(core): implement order approval flow, credit system, and import invoicing
Introduce a comprehensive set of commercial features including a multi-step
order approval workflow, customer credit management, and specialized
import service invoicing.

Key changes:
- Implement `pending_approval` and `approved` shipment statuses to allow
  staff verification before customer payment.
- Add a credit system to `User` model with `credit_limit` and `credit_used`
  to manage customer balances and debts.
- Develop a new `importInvoice` PDF generation service following the
  "Sheet ENG Invoice" specification for import services.
- Add Filament resources for managing Audit Logs, Commitment Forms,
  Customer Credits, and Shipment Checklists.
- Implement staff-specific APIs for order approval/rejection and
  customer financial status monitoring.
- Integrate Kavenegar SMS service for mobile verification and notifications.
- Add bulk tracking import functionality via CSV/Excel.
- Update WordPress bridge assets (CSS/JS) to support the new multi-step
  order form UI and updated redirection logic.
- Update deployment configurations and documentation to reflect new
  production domains and feature sets.
2026-09-03 06:04:20 +03:30

158 lines
6.5 KiB
PHP

<?php
namespace App\Filament\Resources;
use App\Filament\Resources\CommitmentFormResource\Pages;
use App\Models\CommitmentForm;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Filament\Forms\Components\FileUpload;
use Illuminate\Support\Facades\Storage;
class CommitmentFormResource extends Resource
{
protected static ?string $model = CommitmentForm::class;
protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static ?string $navigationLabel = 'فایل‌های تعهدنامه';
protected static ?string $navigationGroup = 'تنظیمات';
protected static ?int $navigationSort = 5;
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Section::make('اطلاعات تعهدنامه')
->schema([
Forms\Components\TextInput::make('title')
->required()
->maxLength(255)
->label('عنوان'),
Forms\Components\Textarea::make('description')
->nullable()
->rows(3)
->label('توضیحات'),
Forms\Components\Select::make('direction')
->options([
'export' => 'صادرات',
'import' => 'واردات',
'both' => 'هر دو',
])
->default('both')
->required()
->label('جهت ارسال'),
Forms\Components\Toggle::make('is_active')
->default(true)
->label('فعال'),
Forms\Components\TextInput::make('sort_order')
->numeric()
->default(0)
->label('ترتیب نمایش'),
])->columns(2),
Forms\Components\Section::make('فایل')
->schema([
FileUpload::make('file_path')
->label('فایل تعهدنامه')
->disk('public')
->directory('commitment-forms')
->acceptedFileTypes(['application/pdf', 'image/png', 'image/jpeg'])
->maxSize(10240) // 10MB
->required()
->columnSpanFull()
->extraAttributes(['class' => 'w-full'])
->getUploadedFileNameForStorageUsing(function ($file): string {
$extension = $file->getClientOriginalExtension();
$filename = time() . '_' . uniqid() . '.' . $extension;
return $filename;
}),
Forms\Components\Placeholder::make('file_info')
->label('اطلاعات فایل')
->content(function ($record) {
if (!$record) return 'فایلی آپلود نشده';
$type = strtoupper(pathinfo($record->file_path, PATHINFO_EXTENSION));
$size = $record->formatted_size;
return "فرمت: {$type} | حجم: {$size}";
}),
]),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('title')
->searchable()
->label('عنوان'),
Tables\Columns\TextColumn::make('direction')
->badge()
->color(fn (string $state): string => match ($state) {
'export' => 'success',
'import' => 'info',
'both' => 'warning',
})
->formatStateUsing(fn (string $state): string => match ($state) {
'export' => 'صادرات',
'import' => 'واردات',
'both' => 'هر دو',
})
->label('جهت'),
Tables\Columns\IconColumn::make('is_active')
->boolean()
->label('فعال'),
Tables\Columns\TextColumn::make('sort_order')
->sortable()
->label('ترتیب'),
Tables\Columns\TextColumn::make('uploader.name')
->label('آپلود کننده'),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->label('تاریخ ایجاد'),
])
->filters([
Tables\Filters\SelectFilter::make('direction')
->options([
'export' => 'صادرات',
'import' => 'واردات',
'both' => 'هر دو',
]),
Tables\Filters\TernaryFilter::make('is_active')
->label('فعال'),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
Tables\Actions\Action::make('download')
->label('دانلود')
->icon('heroicon-o-arrow-down-tray')
->color('info')
->url(fn ($record) => $record->file_url)
->openUrlInNewTab(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function getPages(): array
{
return [
'index' => Pages\ListCommitmentForms::route('/'),
'create' => Pages\CreateCommitmentForm::route('/create'),
'edit' => Pages\EditCommitmentForm::route('/{record}/edit'),
];
}
}