Files
hqland-app/app/Filament/Resources/Payments/Schemas/PaymentForm.php
2026-04-24 08:58:53 +00:00

99 lines
4.5 KiB
PHP

<?php
namespace App\Filament\Resources\Payments\Schemas;
use App\Models\PaymentScheduleItem;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\KeyValue;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\Grid;
use Filament\Schemas\Schema;
use Filament\Schemas\Components\Utilities\Set;
class PaymentForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
Grid::make(3)
->schema([
Section::make('Thông tin phiếu thu')
->columnSpan(2)
->columns(2)
->schema([
Select::make('contract_id')
->label('Hợp đồng')
->relationship('contract', 'contract_number')
->searchable()
->preload()
->required()
->live()
->afterStateUpdated(function (Set $set) {
$set('schedule_item_id', null);
}),
Select::make('schedule_item_id')
->label('Đợt thanh toán')
->placeholder('Để trống nếu là tạm ứng / không đối soát đợt')
->options(function (callable $get) {
$contractId = $get('contract_id');
if (! $contractId) {
return [];
}
return PaymentScheduleItem::query()
->whereHas('schedule', fn ($q) => $q->where('contract_id', $contractId))
->get()
->mapWithKeys(function ($item) {
$label = 'Đợt '.$item->installment_no.' - '.$item->type;
if ($item->amount) {
$label .= ' ('.number_format($item->amount).' VNĐ)';
}
return [$item->id => $label];
});
})
->searchable(),
TextInput::make('amount')
->label('Số tiền thu')
->numeric()
->prefix('VND')
->required(),
DatePicker::make('paid_date')
->label('Ngày thu')
->required()
->default(now()),
TextInput::make('receipt_number')
->label('Số phiếu thu / Mã giao dịch'),
Select::make('method')
->label('Phương thức thanh toán')
->options([
'Chuyển khoản' => 'Chuyển khoản',
'Tiền mặt' => 'Tiền mặt',
'Thẻ' => 'Thẻ',
'Khác' => 'Khác',
])
->default('Chuyển khoản')
->required(),
]),
Section::make('Bổ sung')
->columnSpan(1)
->schema([
KeyValue::make('metadata')
->label('Dữ liệu bổ sung (nếu có)')
->keyLabel('Thông tin')
->valueLabel('Giá trị'),
]),
]),
]);
}
}