Đóng gói cuối tuần

This commit is contained in:
2026-04-18 04:46:01 +00:00
parent 761b34916b
commit 3cef1c40df
37 changed files with 1266 additions and 301 deletions

View File

@@ -4,6 +4,9 @@ namespace App\Filament\Resources\Contracts;
use App\Filament\Resources\Contracts\Pages;
use App\Models\Contract;
use App\Models\Product;
use App\Models\PaymentTemplate;
use App\Enums\NavigationGroup;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\DatePicker;
@@ -12,40 +15,38 @@ use Filament\Schemas\Schema;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Filament\Schemas\Components\Utilities\Get;
use App\Filament\Resources\Contracts\ContractResource\RelationManagers\ScheduleItemsRelationManager;
class ContractResource extends Resource
{
protected static ?string $model = Contract::class;
protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-document-text';
protected static string | \UnitEnum | null $navigationGroup = 'Quản lý Giao dịch';
protected static string | \UnitEnum | null $navigationGroup = NavigationGroup::TRANSACTION->value;
protected static ?int $navigationSort = 4;
protected static ?string $modelLabel = 'Hợp đồng';
protected static ?string $pluralModelLabel = 'Hợp đồng';
public static function form(Schema $schema): Schema
{
return $schema
->components([
Section::make('Thông tin Liên kết')
Section::make('Liên kết & Mẫu thanh toán')
->columns(2)
->schema([
Select::make('product_id')->label('Sản phẩm')->relationship('product', 'code')->searchable()->preload()->required(),
Select::make('customers')->label('Khách hàng')->relationship('customers', 'full_name')->multiple()->searchable()->preload()->required(),
Select::make('product_id')->label('Sản phẩm')->relationship('product', 'code')->required()->live(),
Select::make('payment_template_id')->label('Mẫu thanh toán')
->options(fn (Get $get) => PaymentTemplate::pluck('name', 'id'))
->required()->dehydrated(false),
Select::make('customers')->label('Khách hàng')->relationship('customers', 'full_name')->multiple()->required()->columnSpanFull(),
]),
Section::make('Chi tiết Hợp đồng')
->columns(2)
->schema([
TextInput::make('contract_number')->label('Số Hợp đồng')->required()->unique(ignoreRecord: true),
Select::make('contract_type')->label('Loại Hợp đồng')->options(['HĐMB' => 'HĐ Mua bán', 'HĐĐC' => 'HĐ Đặt cọc', 'HĐGV' => 'HĐ Góp vốn', 'VBCN' => 'VBCN'])->default('HĐMB'),
DatePicker::make('signing_date')->label('Ngày ký')->displayFormat('d/m/Y'),
TextInput::make('transfer_order')->label('Thứ tự chuyển nhượng')->numeric()->default(0),
Select::make('status')->label('Trạng thái')
->options(['Đang hiệu lực' => 'Đang hiệu lực', 'Đã thanh lý' => 'Đã thanh lý', 'Đã chuyển nhượng' => 'Đã chuyển nhượng'])
->default('Đang hiệu lực'),
]),
Section::make('Tài chính')
->columns(2)
->schema([
TextInput::make('total_value')->label('Tổng giá trị (VND)')->numeric()->required(),
TextInput::make('paid_amount')->label('Đã thanh toán (VND)')->numeric()->default(0),
]),
TextInput::make('contract_number')->label('Số HĐ')->required(),
DatePicker::make('signing_date')->label('Ngày ký')->required(),
])
]);
}
@@ -54,23 +55,13 @@ class ContractResource extends Resource
return $table
->columns([
Tables\Columns\TextColumn::make('contract_number')->label('Số HĐ')->searchable(),
Tables\Columns\TextColumn::make('contract_type')->label('Loại HĐ')->badge(),
Tables\Columns\TextColumn::make('product.code')->label('Mã SP')->searchable(),
Tables\Columns\TextColumn::make('customers.full_name')->label('Khách hàng')->badge(),
Tables\Columns\TextColumn::make('status')->label('Trạng thái')
->color(fn (string $state): string => match ($state) {
'Đang hiệu lực' => 'success',
'Đã thanh lý' => 'warning',
'Đã chuyển nhượng' => 'gray',
default => 'gray',
})->badge(),
Tables\Columns\TextColumn::make('total_value')->label('Tổng giá trị')->money('VND'),
Tables\Columns\TextColumn::make('paid_amount')->label('Đã TT')->money('VND'),
Tables\Columns\TextColumn::make('remaining_amount')->label('Còn lại')->money('VND')->color('danger'),
])
->defaultSort('created_at', 'desc');
Tables\Columns\TextColumn::make('product.code')->label('Sản phẩm'),
Tables\Columns\TextColumn::make('total_value')->label('Giá trị')->money('VND'),
]);
}
public static function getRelations(): array { return [ScheduleItemsRelationManager::class]; }
public static function getPages(): array
{
return [