Hoan thien core finance v2
This commit is contained in:
46
app/Filament/Widgets/ContractStatsOverview.php
Normal file
46
app/Filament/Widgets/ContractStatsOverview.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Contract;
|
||||
use App\Models\PaymentScheduleItem;
|
||||
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
|
||||
class ContractStatsOverview extends BaseWidget
|
||||
{
|
||||
protected function getStats(): array
|
||||
{
|
||||
$totalRevenue = (float) Contract::sum('total_value');
|
||||
$totalPaid = (float) Contract::sum('paid_amount');
|
||||
$totalRemaining = (float) Contract::sum('remaining_amount');
|
||||
$activeContracts = Contract::where('status', 'Đang hiệu lực')->count();
|
||||
$upcomingPayments = PaymentScheduleItem::whereNull('schedule_id')
|
||||
->orWhereHas('schedule', fn ($q) => $q->whereHas('contract'))
|
||||
->whereDate('due_date', '<=', now()->addDays(30))
|
||||
->whereDate('due_date', '>=', now())
|
||||
->count();
|
||||
|
||||
return [
|
||||
Stat::make('Tổng doanh thu', number_format($totalRevenue) . ' VNĐ')
|
||||
->description('Tổng giá trị tất cả HĐ')
|
||||
->color('primary'),
|
||||
|
||||
Stat::make('Đã thu', number_format($totalPaid) . ' VNĐ')
|
||||
->description('Tổng tiền đã thanh toán')
|
||||
->color('success'),
|
||||
|
||||
Stat::make('Công nợ phải thu', number_format($totalRemaining) . ' VNĐ')
|
||||
->description('Tổng tiền chưa thu')
|
||||
->color('danger'),
|
||||
|
||||
Stat::make('HĐ hiệu lực', $activeContracts)
|
||||
->description('Số hợp đồng đang hiệu lực')
|
||||
->color('warning'),
|
||||
|
||||
Stat::make('Đợt TT sắp đến hạn', $upcomingPayments)
|
||||
->description('Trong 30 ngày tới')
|
||||
->color('info'),
|
||||
];
|
||||
}
|
||||
}
|
||||
47
app/Filament/Widgets/UpcomingPaymentsTable.php
Normal file
47
app/Filament/Widgets/UpcomingPaymentsTable.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\PaymentScheduleItem;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Widgets\TableWidget as BaseWidget;
|
||||
|
||||
class UpcomingPaymentsTable extends BaseWidget
|
||||
{
|
||||
protected int | string | array $columnSpan = 'full';
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->query(
|
||||
PaymentScheduleItem::query()
|
||||
->whereHas('schedule.contract')
|
||||
->whereDate('due_date', '>=', now())
|
||||
->whereDate('due_date', '<=', now()->addDays(30))
|
||||
->orderBy('due_date')
|
||||
)
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('schedule.contract.contract_number')
|
||||
->label('Số HĐ')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('installment_no')
|
||||
->label('Đợt')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('type')
|
||||
->label('Loại')
|
||||
->badge(),
|
||||
Tables\Columns\TextColumn::make('amount')
|
||||
->label('Số tiền')
|
||||
->money('VND'),
|
||||
Tables\Columns\TextColumn::make('due_date')
|
||||
->label('Ngày đến hạn')
|
||||
->date('d/m/Y')
|
||||
->color('danger'),
|
||||
Tables\Columns\TextColumn::make('remaining_amount')
|
||||
->label('Còn thiếu')
|
||||
->money('VND'),
|
||||
])
|
||||
->paginated([10, 25, 50]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user