Kimi chinh sua
This commit is contained in:
11
app/Filament/Resources/Payments/Pages/CreatePayment.php
Normal file
11
app/Filament/Resources/Payments/Pages/CreatePayment.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Payments\Pages;
|
||||
|
||||
use App\Filament\Resources\Payments\PaymentResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreatePayment extends CreateRecord
|
||||
{
|
||||
protected static string $resource = PaymentResource::class;
|
||||
}
|
||||
19
app/Filament/Resources/Payments/Pages/EditPayment.php
Normal file
19
app/Filament/Resources/Payments/Pages/EditPayment.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Payments\Pages;
|
||||
|
||||
use App\Filament\Resources\Payments\PaymentResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditPayment extends EditRecord
|
||||
{
|
||||
protected static string $resource = PaymentResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/Payments/Pages/ListPayments.php
Normal file
19
app/Filament/Resources/Payments/Pages/ListPayments.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Payments\Pages;
|
||||
|
||||
use App\Filament\Resources\Payments\PaymentResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListPayments extends ListRecords
|
||||
{
|
||||
protected static string $resource = PaymentResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
42
app/Filament/Resources/Payments/PaymentResource.php
Normal file
42
app/Filament/Resources/Payments/PaymentResource.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Payments;
|
||||
|
||||
use App\Filament\Resources\Payments\Pages;
|
||||
use App\Models\Payment;
|
||||
use App\Enums\NavigationGroup;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables\Table;
|
||||
use App\Filament\Resources\Payments\Schemas\PaymentForm;
|
||||
use App\Filament\Resources\Payments\Tables\PaymentsTable;
|
||||
|
||||
class PaymentResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Payment::class;
|
||||
protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-banknotes';
|
||||
protected static string | \UnitEnum | null $navigationGroup = NavigationGroup::FINANCE->value;
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
protected static ?string $modelLabel = 'Phiếu thu';
|
||||
protected static ?string $pluralModelLabel = 'Phiếu thu';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return PaymentForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return PaymentsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListPayments::route('/'),
|
||||
'create' => Pages\CreatePayment::route('/create'),
|
||||
'edit' => Pages\EditPayment::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
98
app/Filament/Resources/Payments/Schemas/PaymentForm.php
Normal file
98
app/Filament/Resources/Payments/Schemas/PaymentForm.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?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ị'),
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
59
app/Filament/Resources/Payments/Tables/PaymentsTable.php
Normal file
59
app/Filament/Resources/Payments/Tables/PaymentsTable.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Payments\Tables;
|
||||
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class PaymentsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('contract.contract_number')
|
||||
->label('Hợp đồng')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('amount')
|
||||
->label('Số tiền')
|
||||
->money('VND')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('paid_date')
|
||||
->label('Ngày thu')
|
||||
->date('d/m/Y')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('method')
|
||||
->label('Phương thức')
|
||||
->badge(),
|
||||
Tables\Columns\TextColumn::make('receipt_number')
|
||||
->label('Số phiếu thu')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('scheduleItem.installment_no')
|
||||
->label('Đợt TT')
|
||||
->placeholder('Tạm ứng'),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('method')
|
||||
->label('Phương thức')
|
||||
->options([
|
||||
'Chuyển khoản' => 'Chuyển khoản',
|
||||
'Tiền mặt' => 'Tiền mặt',
|
||||
'Thẻ' => 'Thẻ',
|
||||
'Khác' => 'Khác',
|
||||
]),
|
||||
Tables\Filters\Filter::make('paid_date')
|
||||
->label('Ngày thu')
|
||||
->form([
|
||||
\Filament\Forms\Components\DatePicker::make('from')->label('Từ ngày'),
|
||||
\Filament\Forms\Components\DatePicker::make('to')->label('Đến ngày'),
|
||||
])
|
||||
->query(function ($query, array $data) {
|
||||
return $query
|
||||
->when($data['from'], fn ($q) => $q->whereDate('paid_date', '>=', $data['from']))
|
||||
->when($data['to'], fn ($q) => $q->whereDate('paid_date', '<=', $data['to']));
|
||||
}),
|
||||
])
|
||||
->defaultSort('paid_date', 'desc');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user