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ị'), ]), ]), ]); } }