f0f9fdd555
Schema: - payments: client_id, work_order_id, user_id (operator), paid_at, amount, method (cash/card/transfer/mobile), reference, notes - expenses: supplier_id, purchase_id, paid_at, category (salary/purchase/rent/ utilities/advance/tax/fuel/tools/marketing/other), name, amount, method, ref Logică auto: - Payment::saved/deleted recalculează automat work_order.pay_status (unpaid → partial → paid) based on suma totală vs work_order.total - WO model are noi metode: payments(), paidAmount(), balanceDue() Filament resources (group Finanțe): - PaymentResource: form cu legare opțională la WO + client; tabel cu Sum summary, filtre azi/luna_curentă/method - ExpenseResource: 10 categorii preset, badge categ, total summary, filtru luna curentă - PaymentsRelationManager pe WO: "Plăți" tab cu auto-fill client_id + user_id la creare Widget FinanceOverview: - Încasări (luna), Cheltuieli (luna), Profit (luna), Datorii clienți - color coded: profit verde sau roșu, datorii galben/verde Settings page fix (Filament v5): - mount() folosește acum $this->form->fill([...]) în loc de $this->data direct - Filament v5 cere fill explicit pentru a inițializa state-ul schemei Seed: - 1 plată parțială pe fișa BMW (200 din 750) - 6 cheltuieli demo: 3 salarii, chirie, electricitate, achiziție piese Total Filament tenant routes: 69.
52 lines
1.9 KiB
PHP
52 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Tenant\Widgets;
|
|
|
|
use App\Models\Tenant\Expense;
|
|
use App\Models\Tenant\Payment;
|
|
use App\Models\Tenant\WorkOrder;
|
|
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
|
|
use Filament\Widgets\StatsOverviewWidget\Stat;
|
|
|
|
class FinanceOverview extends BaseWidget
|
|
{
|
|
protected static ?int $sort = 2;
|
|
|
|
protected function getStats(): array
|
|
{
|
|
$start = now()->startOfMonth();
|
|
$end = now()->endOfMonth();
|
|
|
|
$income = (float) Payment::whereBetween('paid_at', [$start, $end])->sum('amount');
|
|
$expenses = (float) Expense::whereBetween('paid_at', [$start, $end])->sum('amount');
|
|
$profit = $income - $expenses;
|
|
|
|
$debtTotal = (float) WorkOrder::where('pay_status', '!=', 'paid')
|
|
->whereNotIn('status', ['cancelled'])
|
|
->sum('total');
|
|
$paidOnDebt = (float) Payment::whereIn('work_order_id',
|
|
WorkOrder::where('pay_status', '!=', 'paid')->pluck('id')
|
|
)->sum('amount');
|
|
$debt = max(0, $debtTotal - $paidOnDebt);
|
|
|
|
return [
|
|
Stat::make('Încasări (luna)', number_format($income, 2, '.', ' ') . ' MDL')
|
|
->icon('heroicon-o-arrow-trending-up')
|
|
->color('success')
|
|
->description(now()->translatedFormat('F Y')),
|
|
|
|
Stat::make('Cheltuieli (luna)', number_format($expenses, 2, '.', ' ') . ' MDL')
|
|
->icon('heroicon-o-arrow-trending-down')
|
|
->color('danger'),
|
|
|
|
Stat::make('Profit (luna)', number_format($profit, 2, '.', ' ') . ' MDL')
|
|
->icon('heroicon-o-banknotes')
|
|
->color($profit >= 0 ? 'success' : 'danger'),
|
|
|
|
Stat::make('Datorii clienți', number_format($debt, 2, '.', ' ') . ' MDL')
|
|
->icon('heroicon-o-exclamation-circle')
|
|
->color($debt > 0 ? 'warning' : 'success'),
|
|
];
|
|
}
|
|
}
|