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:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('payments', function (Blueprint $t) {
|
||||
$t->id();
|
||||
$t->foreignId('company_id')->constrained()->cascadeOnDelete();
|
||||
$t->foreignId('client_id')->nullable()->constrained()->nullOnDelete();
|
||||
$t->foreignId('work_order_id')->nullable()->constrained()->nullOnDelete();
|
||||
$t->foreignId('user_id')->nullable()->constrained()->nullOnDelete(); // operator înregistrare
|
||||
|
||||
$t->date('paid_at')->default(now());
|
||||
$t->decimal('amount', 12, 2);
|
||||
$t->string('method')->default('cash'); // cash / card / transfer / mobile
|
||||
$t->string('reference')->nullable(); // nr. chitanță / tranzacție
|
||||
$t->text('notes')->nullable();
|
||||
|
||||
$t->timestamps();
|
||||
$t->softDeletes();
|
||||
|
||||
$t->index(['company_id', 'paid_at']);
|
||||
$t->index(['company_id', 'work_order_id']);
|
||||
$t->index(['company_id', 'method']);
|
||||
});
|
||||
|
||||
Schema::create('expenses', function (Blueprint $t) {
|
||||
$t->id();
|
||||
$t->foreignId('company_id')->constrained()->cascadeOnDelete();
|
||||
$t->foreignId('supplier_id')->nullable()->constrained()->nullOnDelete();
|
||||
$t->foreignId('purchase_id')->nullable()->constrained()->nullOnDelete();
|
||||
$t->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
|
||||
|
||||
$t->date('paid_at')->default(now());
|
||||
$t->string('category'); // salary / purchase / rent / utilities / advance / tax / other
|
||||
$t->string('name'); // descriere
|
||||
$t->decimal('amount', 12, 2);
|
||||
$t->string('method')->default('cash');
|
||||
$t->string('reference')->nullable();
|
||||
$t->text('notes')->nullable();
|
||||
|
||||
$t->timestamps();
|
||||
$t->softDeletes();
|
||||
|
||||
$t->index(['company_id', 'paid_at']);
|
||||
$t->index(['company_id', 'category']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('expenses');
|
||||
Schema::dropIfExists('payments');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user