Faza 3.4: Finanțe — Plăți + Cheltuieli + Cashflow
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.
This commit is contained in:
@@ -13,7 +13,9 @@ use App\Models\Tenant\Lead;
|
||||
use App\Models\Tenant\Post;
|
||||
use App\Models\Tenant\User;
|
||||
use App\Models\Tenant\Vehicle;
|
||||
use App\Models\Tenant\Expense;
|
||||
use App\Models\Tenant\Part;
|
||||
use App\Models\Tenant\Payment;
|
||||
use App\Models\Tenant\Purchase;
|
||||
use App\Models\Tenant\PurchaseItem;
|
||||
use App\Models\Tenant\Supplier;
|
||||
@@ -415,6 +417,29 @@ class DatabaseSeeder extends Seeder
|
||||
}
|
||||
$purchase->refresh()->recalcTotal();
|
||||
|
||||
// ─── Plăți demo ──────────────────────────────────────────
|
||||
// Plată parțială pe fișa demo (BMW)
|
||||
Payment::firstOrCreate(
|
||||
['company_id' => $psauto->id, 'work_order_id' => $wo->id, 'paid_at' => today()->subDays(1), 'amount' => 200],
|
||||
['client_id' => $c1->id, 'method' => 'cash', 'reference' => 'CHIT-001', 'user_id' => $admin->id]
|
||||
);
|
||||
|
||||
// ─── Cheltuieli demo ────────────────────────────────────
|
||||
$expensesData = [
|
||||
['salary', 'Salariu Vasile Ivanov', 8000, today()->startOfMonth(), 'cash'],
|
||||
['salary', 'Salariu Andrei Popov', 7500, today()->startOfMonth(), 'cash'],
|
||||
['salary', 'Salariu Nicolae Lupu', 7000, today()->startOfMonth(), 'cash'],
|
||||
['rent', 'Chirie spațiu service (luna curentă)', 4500, today()->startOfMonth(), 'transfer'],
|
||||
['utilities', 'Electricitate', 850, today()->subDays(15), 'card'],
|
||||
['purchase', 'Achiziție stoc (P-26-0001)', 1036, today()->subDays(7), 'transfer'],
|
||||
];
|
||||
foreach ($expensesData as [$cat, $name, $amount, $date, $method]) {
|
||||
Expense::firstOrCreate(
|
||||
['company_id' => $psauto->id, 'name' => $name, 'paid_at' => $date],
|
||||
['category' => $cat, 'amount' => $amount, 'method' => $method, 'user_id' => $admin->id]
|
||||
);
|
||||
}
|
||||
|
||||
app(TenantManager::class)->clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user