Files
autocrm/app/Models/Tenant/Expense.php
T
Vasyka f0f9fdd555 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.
2026-05-06 22:55:50 +00:00

54 lines
1.3 KiB
PHP

<?php
namespace App\Models\Tenant;
use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class Expense extends Model
{
use BelongsToTenant, SoftDeletes;
public const CATEGORIES = [
'salary' => 'Salariu',
'purchase' => 'Achiziție piese',
'rent' => 'Chirie',
'utilities' => 'Utilități',
'advance' => 'Avans',
'tax' => 'Taxe',
'fuel' => 'Combustibil',
'tools' => 'Scule / consumabile',
'marketing' => 'Marketing',
'other' => 'Altele',
];
public const METHODS = [
'cash' => 'Numerar',
'card' => 'Card',
'transfer' => 'Virament',
'mobile' => 'Mobile pay',
];
protected $fillable = [
'company_id', 'supplier_id', 'purchase_id', 'user_id',
'paid_at', 'category', 'name', 'amount', 'method', 'reference', 'notes',
];
protected $casts = [
'paid_at' => 'date',
'amount' => 'decimal:2',
];
public function supplier(): BelongsTo
{
return $this->belongsTo(Supplier::class);
}
public function purchase(): BelongsTo
{
return $this->belongsTo(Purchase::class);
}
}