Batch 1: Procentaj + Finanțe consolidat + Recomandări
═══ Procentaj (markup rules) ═══
- markup_rules table cu type (category/brand/range), key, range_from/to, markup_pct, priority
- MarkupRule::bestForPart($part) — rezolvare brand → category → range → 30% default
- MarkupRule::applyToPart($part) — recalc sell_price = buy_price × (1 + pct/100)
- Filament resource sub Depozit cu form dinamic per tip
- Action 'Aplică toate regulile la stoc' — recalc tot catalogul (chunk 100)
═══ Finanțe consolidat ═══
- Custom Page /app/finance cu 4 tab-uri:
• Overview: încasări/cheltuieli/profit/datorii (4 cards)
• Cashflow: bar chart per zi (verde=in, roșu=out) + Net total
• P&L: venituri (manopere + piese) vs costuri (cost piese + cheltuieli pe categorie)
+ profit net + marjă %
• Balance: active (cash net + datorii + stoc), all-time totals
- Period filter: lună / luna trecută / an / 30 zile
═══ Recomandări ═══
- Custom Page /app/recommendations 4 sectiuni:
• Clienți pierduți (>6 luni fără WO + are istoric)
• Mașini km>100k (sugestie revizie)
• Fișe neplătite (rest > 0)
• VIP fără contact >30 zile
Total tenant routes: 100.
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Pages;
|
||||
|
||||
use App\Models\Tenant\Expense;
|
||||
use App\Models\Tenant\Payment;
|
||||
use App\Models\Tenant\WorkOrder;
|
||||
use App\Models\Tenant\WorkOrderPart;
|
||||
use App\Models\Tenant\WorkOrderWork;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Pages\Page;
|
||||
|
||||
class Finance extends Page
|
||||
{
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-currency-dollar';
|
||||
|
||||
protected static ?string $navigationLabel = 'Finanțe (consolidat)';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Finanțe';
|
||||
|
||||
protected static ?int $navigationSort = 49;
|
||||
|
||||
protected static ?string $title = 'Finanțe';
|
||||
|
||||
protected string $view = 'filament.tenant.pages.finance';
|
||||
|
||||
public string $tab = 'overview';
|
||||
|
||||
public string $period = 'this_month';
|
||||
|
||||
public function setTab(string $tab): void { $this->tab = $tab; }
|
||||
public function setPeriod(string $p): void { $this->period = $p; }
|
||||
|
||||
public function tabs(): array
|
||||
{
|
||||
return [
|
||||
'overview' => '📊 Overview',
|
||||
'cashflow' => '💸 Cashflow',
|
||||
'pnl' => '📈 P&L',
|
||||
'balance' => '⚖️ Balanță',
|
||||
];
|
||||
}
|
||||
|
||||
public function periods(): array
|
||||
{
|
||||
return [
|
||||
'this_month' => 'Luna curentă',
|
||||
'last_month' => 'Luna trecută',
|
||||
'this_year' => 'Anul curent',
|
||||
'last_30' => 'Ultimele 30 zile',
|
||||
];
|
||||
}
|
||||
|
||||
public function dateRange(): array
|
||||
{
|
||||
return match ($this->period) {
|
||||
'last_month' => [Carbon::now()->subMonthNoOverflow()->startOfMonth(), Carbon::now()->subMonthNoOverflow()->endOfMonth()],
|
||||
'this_year' => [Carbon::now()->startOfYear(), Carbon::now()->endOfYear()],
|
||||
'last_30' => [Carbon::now()->subDays(30)->startOfDay(), Carbon::now()->endOfDay()],
|
||||
default => [Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth()],
|
||||
};
|
||||
}
|
||||
|
||||
public function data(): array
|
||||
{
|
||||
[$start, $end] = $this->dateRange();
|
||||
|
||||
return match ($this->tab) {
|
||||
'overview' => $this->overview($start, $end),
|
||||
'cashflow' => $this->cashflow($start, $end),
|
||||
'pnl' => $this->pnl($start, $end),
|
||||
'balance' => $this->balance($start, $end),
|
||||
default => [],
|
||||
};
|
||||
}
|
||||
|
||||
protected function overview($start, $end): array
|
||||
{
|
||||
$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'])
|
||||
->get()
|
||||
->sum(fn ($w) => max(0, (float) $w->total - (float) $w->payments()->sum('amount')));
|
||||
|
||||
return compact('income', 'expenses', 'profit', 'debtTotal');
|
||||
}
|
||||
|
||||
protected function cashflow($start, $end): array
|
||||
{
|
||||
// Aggregate per day.
|
||||
$byDay = [];
|
||||
$cur = $start->copy();
|
||||
while ($cur <= $end) {
|
||||
$key = $cur->format('Y-m-d');
|
||||
$byDay[$key] = ['date' => $cur->format('d.m'), 'in' => 0, 'out' => 0];
|
||||
$cur->addDay();
|
||||
}
|
||||
|
||||
Payment::whereBetween('paid_at', [$start, $end])
|
||||
->selectRaw('DATE(paid_at) d, SUM(amount) total')
|
||||
->groupBy('d')->get()
|
||||
->each(fn ($r) => $byDay[$r->d]['in'] = (float) $r->total);
|
||||
|
||||
Expense::whereBetween('paid_at', [$start, $end])
|
||||
->selectRaw('DATE(paid_at) d, SUM(amount) total')
|
||||
->groupBy('d')->get()
|
||||
->each(fn ($r) => $byDay[$r->d]['out'] = (float) $r->total);
|
||||
|
||||
// Totals + max (for bar chart scale).
|
||||
$totalIn = array_sum(array_column($byDay, 'in'));
|
||||
$totalOut = array_sum(array_column($byDay, 'out'));
|
||||
$maxAbs = max(0.001, max(...array_map(fn ($d) => max($d['in'], $d['out']), $byDay)));
|
||||
|
||||
return [
|
||||
'rows' => array_values($byDay),
|
||||
'totalIn' => $totalIn,
|
||||
'totalOut' => $totalOut,
|
||||
'net' => $totalIn - $totalOut,
|
||||
'maxAbs' => $maxAbs,
|
||||
];
|
||||
}
|
||||
|
||||
protected function pnl($start, $end): array
|
||||
{
|
||||
// Revenue split: works vs parts vs other (manually entered payments without WO link).
|
||||
$worksRevenue = (float) WorkOrderWork::whereHas('workOrder', fn ($q) => $q->whereBetween('opened_at', [$start, $end]))
|
||||
->where('status', 'done')
|
||||
->sum('total');
|
||||
$partsRevenue = (float) WorkOrderPart::whereHas('workOrder', fn ($q) => $q->whereBetween('opened_at', [$start, $end]))
|
||||
->where('status', 'installed')
|
||||
->sum('total');
|
||||
$partsCost = (float) WorkOrderPart::whereHas('workOrder', fn ($q) => $q->whereBetween('opened_at', [$start, $end]))
|
||||
->where('status', 'installed')
|
||||
->get()->sum(fn ($p) => (float) $p->buy_price * (float) $p->qty);
|
||||
$partsMargin = $partsRevenue - $partsCost;
|
||||
|
||||
$expensesByCat = Expense::whereBetween('paid_at', [$start, $end])
|
||||
->selectRaw('category, SUM(amount) total')
|
||||
->groupBy('category')->orderByDesc('total')->get();
|
||||
|
||||
$totalExpenses = (float) $expensesByCat->sum('total');
|
||||
$totalRevenue = $worksRevenue + $partsRevenue;
|
||||
$netProfit = $totalRevenue - $partsCost - $totalExpenses;
|
||||
$marginPct = $totalRevenue > 0 ? round($netProfit / $totalRevenue * 100, 1) : 0;
|
||||
|
||||
return compact(
|
||||
'worksRevenue', 'partsRevenue', 'partsCost', 'partsMargin',
|
||||
'expensesByCat', 'totalExpenses', 'totalRevenue', 'netProfit', 'marginPct'
|
||||
);
|
||||
}
|
||||
|
||||
protected function balance($start, $end): array
|
||||
{
|
||||
$allPayments = (float) Payment::sum('amount');
|
||||
$allExpenses = (float) Expense::sum('amount');
|
||||
|
||||
$debt = (float) WorkOrder::where('pay_status', '!=', 'paid')
|
||||
->whereNotIn('status', ['cancelled'])
|
||||
->get()
|
||||
->sum(fn ($w) => max(0, (float) $w->total - (float) $w->payments()->sum('amount')));
|
||||
|
||||
$stockValue = (float) \App\Models\Tenant\Part::where('is_active', true)
|
||||
->get()
|
||||
->sum(fn ($p) => (float) $p->qty * (float) $p->buy_price);
|
||||
|
||||
return [
|
||||
'allTimePayments' => $allPayments,
|
||||
'allTimeExpenses' => $allExpenses,
|
||||
'debt' => $debt,
|
||||
'stockValue' => $stockValue,
|
||||
'netCash' => $allPayments - $allExpenses,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Pages;
|
||||
|
||||
use App\Models\Tenant\Client;
|
||||
use App\Models\Tenant\Vehicle;
|
||||
use App\Models\Tenant\WorkOrder;
|
||||
use Filament\Pages\Page;
|
||||
|
||||
class Recommendations extends Page
|
||||
{
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-light-bulb';
|
||||
|
||||
protected static ?string $navigationLabel = 'Recomandări';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Analiză';
|
||||
|
||||
protected static ?int $navigationSort = 72;
|
||||
|
||||
protected static ?string $title = 'Recomandări — clienți de urmărit';
|
||||
|
||||
protected string $view = 'filament.tenant.pages.recommendations';
|
||||
|
||||
public function lostClients(): \Illuminate\Support\Collection
|
||||
{
|
||||
// Clients with no WO in last 6 months and previously >= 1 visit.
|
||||
$cutoff = now()->subMonths(6);
|
||||
return Client::with(['workOrders' => fn ($q) => $q->latest('opened_at')->limit(1)])
|
||||
->whereHas('workOrders', fn ($q) => $q->where('opened_at', '<', $cutoff))
|
||||
->whereDoesntHave('workOrders', fn ($q) => $q->where('opened_at', '>=', $cutoff))
|
||||
->where('status', '!=', 'lost')
|
||||
->limit(30)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function highMileageVehicles(): \Illuminate\Support\Collection
|
||||
{
|
||||
return Vehicle::with('client')
|
||||
->where('mileage', '>', 100000)
|
||||
->orderByDesc('mileage')
|
||||
->limit(20)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function unpaidWO(): \Illuminate\Support\Collection
|
||||
{
|
||||
return WorkOrder::with(['client', 'vehicle'])
|
||||
->where('pay_status', '!=', 'paid')
|
||||
->whereNotIn('status', ['cancelled'])
|
||||
->where('total', '>', 0)
|
||||
->orderByDesc('opened_at')
|
||||
->limit(30)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function vipNeedingTouchup(): \Illuminate\Support\Collection
|
||||
{
|
||||
// VIP clients with no contact in 30+ days.
|
||||
return Client::where('status', 'vip')
|
||||
->where(fn ($q) => $q->whereNull('last_contact_at')->orWhere('last_contact_at', '<', now()->subDays(30)))
|
||||
->limit(20)
|
||||
->get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources;
|
||||
|
||||
use App\Filament\Tenant\Resources\MarkupRuleResource\Pages;
|
||||
use App\Models\Tenant\MarkupRule;
|
||||
use App\Models\Tenant\Part;
|
||||
use Filament\Actions;
|
||||
use Filament\Forms;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class MarkupRuleResource extends Resource
|
||||
{
|
||||
protected static ?string $model = MarkupRule::class;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-percent-badge';
|
||||
|
||||
protected static ?string $navigationLabel = 'Procentaj';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Depozit';
|
||||
|
||||
protected static ?string $modelLabel = 'regulă';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'reguli markup';
|
||||
|
||||
protected static ?int $navigationSort = 44;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Schemas\Components\Section::make('Regulă')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Forms\Components\Select::make('type')
|
||||
->label('Tip')
|
||||
->options(MarkupRule::TYPES)
|
||||
->default('category')
|
||||
->required()
|
||||
->live(),
|
||||
Forms\Components\Select::make('key')
|
||||
->label(fn (Get $get) => $get('type') === 'brand' ? 'Brand' : 'Categorie')
|
||||
->options(fn (Get $get) => $get('type') === 'brand'
|
||||
? Part::distinct()->pluck('brand', 'brand')->filter()->toArray()
|
||||
: array_combine(Part::CATEGORIES, Part::CATEGORIES))
|
||||
->visible(fn (Get $get) => in_array($get('type'), ['category', 'brand'], true))
|
||||
->searchable()
|
||||
->required(fn (Get $get) => in_array($get('type'), ['category', 'brand'], true)),
|
||||
Forms\Components\TextInput::make('range_from')
|
||||
->label('De la (preț achiziție)')
|
||||
->numeric()
|
||||
->visible(fn (Get $get) => $get('type') === 'range'),
|
||||
Forms\Components\TextInput::make('range_to')
|
||||
->label('Până la (gol = ∞)')
|
||||
->numeric()
|
||||
->visible(fn (Get $get) => $get('type') === 'range'),
|
||||
Forms\Components\TextInput::make('markup_pct')
|
||||
->label('Markup %')
|
||||
->numeric()
|
||||
->required()
|
||||
->suffix('%')
|
||||
->helperText('Ex 30 → preț vânzare = preț achiziție × 1.30'),
|
||||
Forms\Components\TextInput::make('priority')
|
||||
->label('Prioritate')
|
||||
->numeric()
|
||||
->default(100)
|
||||
->helperText('Mai mic = aplicat primul.'),
|
||||
Forms\Components\Toggle::make('is_active')->label('Activă')->default(true),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('priority')->label('#')->sortable(),
|
||||
Tables\Columns\TextColumn::make('type')
|
||||
->formatStateUsing(fn ($s) => MarkupRule::TYPES[$s] ?? $s)
|
||||
->badge(),
|
||||
Tables\Columns\TextColumn::make('key')->label('Cheie')->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('range_from')->label('De la')->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('range_to')->label('Până la')->placeholder('∞'),
|
||||
Tables\Columns\TextColumn::make('markup_pct')
|
||||
->label('Markup')
|
||||
->formatStateUsing(fn ($s) => '+' . $s . '%')
|
||||
->color('success')
|
||||
->weight('bold'),
|
||||
Tables\Columns\IconColumn::make('is_active')->boolean(),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('type')->options(MarkupRule::TYPES),
|
||||
])
|
||||
->headerActions([
|
||||
Actions\Action::make('apply_all')
|
||||
->label('Aplică toate regulile la stoc')
|
||||
->icon('heroicon-m-bolt')
|
||||
->color('warning')
|
||||
->requiresConfirmation()
|
||||
->modalDescription('Va recalcula sell_price pentru TOATE piesele active. Continui?')
|
||||
->action(function () {
|
||||
$count = 0;
|
||||
Part::where('is_active', true)->where('buy_price', '>', 0)->chunk(100, function ($parts) use (&$count) {
|
||||
foreach ($parts as $part) {
|
||||
MarkupRule::applyToPart($part);
|
||||
$count++;
|
||||
}
|
||||
});
|
||||
Notification::make()->title("Recalculat preț pentru {$count} piese")->success()->send();
|
||||
}),
|
||||
])
|
||||
->actions([
|
||||
Actions\EditAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
])
|
||||
->defaultSort('priority');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListMarkupRules::route('/'),
|
||||
'create' => Pages\CreateMarkupRule::route('/create'),
|
||||
'edit' => Pages\EditMarkupRule::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\MarkupRuleResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\MarkupRuleResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateMarkupRule extends CreateRecord
|
||||
{
|
||||
protected static string $resource = MarkupRuleResource::class;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\MarkupRuleResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\MarkupRuleResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditMarkupRule extends EditRecord
|
||||
{
|
||||
protected static string $resource = MarkupRuleResource::class;
|
||||
|
||||
protected function getHeaderActions(): array { return [Actions\DeleteAction::make()]; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tenant\Resources\MarkupRuleResource\Pages;
|
||||
|
||||
use App\Filament\Tenant\Resources\MarkupRuleResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListMarkupRules extends ListRecords
|
||||
{
|
||||
protected static string $resource = MarkupRuleResource::class;
|
||||
|
||||
protected function getHeaderActions(): array { return [Actions\CreateAction::make()]; }
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Tenant;
|
||||
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MarkupRule extends Model
|
||||
{
|
||||
use BelongsToTenant;
|
||||
|
||||
public const TYPES = [
|
||||
'category' => 'Categorie',
|
||||
'brand' => 'Brand',
|
||||
'range' => 'Interval preț',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'company_id', 'type', 'key',
|
||||
'range_from', 'range_to', 'markup_pct',
|
||||
'priority', 'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'range_from' => 'decimal:2',
|
||||
'range_to' => 'decimal:2',
|
||||
'markup_pct' => 'decimal:2',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Find best matching rule for a given Part. Priority order:
|
||||
* 1) brand match 2) category match 3) range (buy_price intersect) 4) default 30%.
|
||||
*/
|
||||
public static function bestForPart(Part $part): ?self
|
||||
{
|
||||
// Brand exact
|
||||
if ($part->brand) {
|
||||
$r = static::where('type', 'brand')
|
||||
->where('is_active', true)
|
||||
->where('key', $part->brand)
|
||||
->orderBy('priority')->first();
|
||||
if ($r) return $r;
|
||||
}
|
||||
// Category exact
|
||||
if ($part->category) {
|
||||
$r = static::where('type', 'category')
|
||||
->where('is_active', true)
|
||||
->where('key', $part->category)
|
||||
->orderBy('priority')->first();
|
||||
if ($r) return $r;
|
||||
}
|
||||
// Range (buy_price ∈ [from, to))
|
||||
$price = (float) $part->buy_price;
|
||||
$r = static::where('type', 'range')
|
||||
->where('is_active', true)
|
||||
->where('range_from', '<=', $price)
|
||||
->where(function ($q) use ($price) {
|
||||
$q->whereNull('range_to')->orWhere('range_to', '>', $price);
|
||||
})
|
||||
->orderBy('priority')->orderByDesc('range_from')->first();
|
||||
return $r;
|
||||
}
|
||||
|
||||
public static function applyToPart(Part $part): bool
|
||||
{
|
||||
$rule = static::bestForPart($part);
|
||||
$pct = $rule?->markup_pct ?? 30;
|
||||
$part->sell_price = round((float) $part->buy_price * (1 + (float) $pct / 100), 2);
|
||||
return $part->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?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('markup_rules', function (Blueprint $t) {
|
||||
$t->id();
|
||||
$t->foreignId('company_id')->constrained()->cascadeOnDelete();
|
||||
$t->string('type'); // category / brand / range
|
||||
$t->string('key')->nullable(); // pentru type=category|brand: numele
|
||||
$t->decimal('range_from', 10, 2)->default(0); // pentru type=range: limita inf
|
||||
$t->decimal('range_to', 10, 2)->nullable(); // pentru type=range: limita sup
|
||||
$t->decimal('markup_pct', 5, 2); // ex 30 = +30%
|
||||
$t->unsignedSmallInteger('priority')->default(100);
|
||||
$t->boolean('is_active')->default(true);
|
||||
$t->timestamps();
|
||||
|
||||
$t->index(['company_id', 'type', 'is_active', 'priority']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('markup_rules');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,135 @@
|
||||
<x-filament-panels::page>
|
||||
@php
|
||||
$data = $this->data();
|
||||
$tabs = $this->tabs();
|
||||
$periods = $this->periods();
|
||||
@endphp
|
||||
|
||||
<style>
|
||||
.fn-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
|
||||
.fn-pill { padding: 6px 12px; border-radius: 6px; font-size: 13px; background: #fff; border: 1px solid #e5e7eb; cursor: pointer; color: #374151; }
|
||||
.dark .fn-pill { background: #1f2937; border-color: #374151; color: #d1d5db; }
|
||||
.fn-pill.active { background: #3b82f6; color: #fff; border-color: #3b82f6; }
|
||||
.fn-tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid #e5e7eb; margin-bottom: 16px; }
|
||||
.fn-tab { padding: 10px 16px; font-size: 14px; font-weight: 500; border: none; background: transparent; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; color: #6b7280; }
|
||||
.fn-tab.active { color: #3b82f6; border-bottom-color: #3b82f6; }
|
||||
.fn-grid { display: grid; gap: 16px; }
|
||||
.fn-grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
|
||||
.fn-grid-2 { grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }
|
||||
.fn-card { background: #fff; border: 1px solid #e5e7eb; border-radius: 10px; padding: 16px; }
|
||||
.dark .fn-card { background: #1f2937; border-color: #374151; }
|
||||
.fn-stat-l { font-size: 11px; color: #6b7280; text-transform: uppercase; letter-spacing: .5px; }
|
||||
.fn-stat-v { font-size: 26px; font-weight: 700; margin-top: 6px; }
|
||||
.fn-success { color: #059669; }
|
||||
.fn-danger { color: #dc2626; }
|
||||
.fn-warning { color: #d97706; }
|
||||
.fn-h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
|
||||
.fn-tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
|
||||
.fn-tbl thead th { text-align: left; padding: 8px 4px; border-bottom: 1px solid #e5e7eb; font-weight: 600; color: #6b7280; }
|
||||
.fn-tbl tbody td { padding: 8px 4px; border-bottom: 1px solid #f3f4f6; }
|
||||
.fn-r { text-align: right; }
|
||||
.fn-bold { font-weight: 600; }
|
||||
|
||||
/* Cashflow bar chart */
|
||||
.fn-chart { display: flex; align-items: flex-end; gap: 2px; height: 220px; padding-top: 16px; }
|
||||
.fn-chart-day { flex: 1; min-width: 16px; display: flex; flex-direction: column; align-items: stretch; gap: 2px; position: relative; }
|
||||
.fn-chart-day-label { text-align: center; font-size: 9px; color: #9ca3af; padding-top: 4px; height: 16px; }
|
||||
.fn-bar-in { background: #10b981; min-height: 1px; border-radius: 2px 2px 0 0; }
|
||||
.fn-bar-out { background: #ef4444; min-height: 1px; border-radius: 0 0 2px 2px; }
|
||||
</style>
|
||||
|
||||
<div class="fn-bar">
|
||||
<span style="font-size:13px;font-weight:500;">Perioadă:</span>
|
||||
@foreach ($periods as $key => $label)
|
||||
<button type="button" wire:click="setPeriod('{{ $key }}')"
|
||||
class="fn-pill {{ $period === $key ? 'active' : '' }}">{{ $label }}</button>
|
||||
@endforeach
|
||||
</div>
|
||||
|
||||
<div class="fn-tabs">
|
||||
@foreach ($tabs as $key => $label)
|
||||
<button type="button" wire:click="setTab('{{ $key }}')"
|
||||
class="fn-tab {{ $tab === $key ? 'active' : '' }}">{{ $label }}</button>
|
||||
@endforeach
|
||||
</div>
|
||||
|
||||
@if ($tab === 'overview')
|
||||
<div class="fn-grid fn-grid-4">
|
||||
<div class="fn-card"><div class="fn-stat-l">Încasări</div><div class="fn-stat-v fn-success">{{ number_format($data['income'], 2, '.', ' ') }} MDL</div></div>
|
||||
<div class="fn-card"><div class="fn-stat-l">Cheltuieli</div><div class="fn-stat-v fn-danger">{{ number_format($data['expenses'], 2, '.', ' ') }} MDL</div></div>
|
||||
<div class="fn-card"><div class="fn-stat-l">Profit</div><div class="fn-stat-v {{ $data['profit'] >= 0 ? 'fn-success' : 'fn-danger' }}">{{ number_format($data['profit'], 2, '.', ' ') }} MDL</div></div>
|
||||
<div class="fn-card"><div class="fn-stat-l">Datorii clienți</div><div class="fn-stat-v fn-warning">{{ number_format($data['debtTotal'], 2, '.', ' ') }} MDL</div></div>
|
||||
</div>
|
||||
|
||||
@elseif ($tab === 'cashflow')
|
||||
<div class="fn-grid fn-grid-2" style="margin-bottom: 16px;">
|
||||
<div class="fn-card"><div class="fn-stat-l">Total intrări</div><div class="fn-stat-v fn-success">{{ number_format($data['totalIn'], 2, '.', ' ') }} MDL</div></div>
|
||||
<div class="fn-card"><div class="fn-stat-l">Total ieșiri</div><div class="fn-stat-v fn-danger">{{ number_format($data['totalOut'], 2, '.', ' ') }} MDL</div></div>
|
||||
</div>
|
||||
<div class="fn-card">
|
||||
<div class="fn-h3">Cashflow zilnic — verde = încasări, roșu = cheltuieli</div>
|
||||
<div class="fn-chart">
|
||||
@foreach ($data['rows'] as $r)
|
||||
<div class="fn-chart-day" title="{{ $r['date'] }}: in {{ number_format($r['in']) }} / out {{ number_format($r['out']) }}">
|
||||
<div class="fn-bar-in" style="height: {{ ($r['in'] / $data['maxAbs']) * 100 }}px;"></div>
|
||||
<div class="fn-bar-out" style="height: {{ ($r['out'] / $data['maxAbs']) * 100 }}px;"></div>
|
||||
@if (count($data['rows']) <= 31)
|
||||
<div class="fn-chart-day-label">{{ $r['date'] }}</div>
|
||||
@endif
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<div style="text-align:right;margin-top:12px;font-size:14px;">
|
||||
Net: <b class="{{ $data['net'] >= 0 ? 'fn-success' : 'fn-danger' }}">{{ number_format($data['net'], 2, '.', ' ') }} MDL</b>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@elseif ($tab === 'pnl')
|
||||
<div class="fn-grid fn-grid-2" style="margin-bottom: 16px;">
|
||||
<div class="fn-card">
|
||||
<div class="fn-h3">Venituri</div>
|
||||
<table class="fn-tbl">
|
||||
<tr><td>Manopere</td><td class="fn-r">{{ number_format($data['worksRevenue'], 2, '.', ' ') }}</td></tr>
|
||||
<tr><td>Piese (vânzare)</td><td class="fn-r">{{ number_format($data['partsRevenue'], 2, '.', ' ') }}</td></tr>
|
||||
<tr style="border-top:2px solid #e5e7eb;"><td class="fn-bold">Total venituri</td><td class="fn-r fn-bold fn-success">{{ number_format($data['totalRevenue'], 2, '.', ' ') }}</td></tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="fn-card">
|
||||
<div class="fn-h3">Costuri</div>
|
||||
<table class="fn-tbl">
|
||||
<tr><td>Cost piese (achiziție)</td><td class="fn-r fn-danger">{{ number_format($data['partsCost'], 2, '.', ' ') }}</td></tr>
|
||||
@foreach ($data['expensesByCat'] as $row)
|
||||
<tr><td>{{ \App\Models\Tenant\Expense::CATEGORIES[$row->category] ?? $row->category }}</td><td class="fn-r fn-danger">{{ number_format((float) $row->total, 2, '.', ' ') }}</td></tr>
|
||||
@endforeach
|
||||
<tr style="border-top:2px solid #e5e7eb;"><td class="fn-bold">Total costuri</td><td class="fn-r fn-bold fn-danger">{{ number_format($data['partsCost'] + $data['totalExpenses'], 2, '.', ' ') }}</td></tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="fn-card" style="text-align:right;">
|
||||
<div class="fn-stat-l">Profit net</div>
|
||||
<div class="fn-stat-v {{ $data['netProfit'] >= 0 ? 'fn-success' : 'fn-danger' }}">{{ number_format($data['netProfit'], 2, '.', ' ') }} MDL</div>
|
||||
<div style="font-size:12px;color:#6b7280;margin-top:4px;">Marjă: {{ $data['marginPct'] }}%</div>
|
||||
<div style="font-size:11px;color:#9ca3af;margin-top:4px;">Marjă piese: {{ number_format($data['partsMargin'], 2, '.', ' ') }} MDL</div>
|
||||
</div>
|
||||
|
||||
@elseif ($tab === 'balance')
|
||||
<div class="fn-grid fn-grid-2">
|
||||
<div class="fn-card">
|
||||
<div class="fn-h3">Active</div>
|
||||
<table class="fn-tbl">
|
||||
<tr><td>Numerar net (toate plățile - cheltuieli)</td><td class="fn-r fn-bold fn-success">{{ number_format($data['netCash'], 2, '.', ' ') }} MDL</td></tr>
|
||||
<tr><td>Datorii clienți (de încasat)</td><td class="fn-r fn-warning">{{ number_format($data['debt'], 2, '.', ' ') }} MDL</td></tr>
|
||||
<tr><td>Stoc piese (la preț achiziție)</td><td class="fn-r">{{ number_format($data['stockValue'], 2, '.', ' ') }} MDL</td></tr>
|
||||
<tr style="border-top:2px solid #e5e7eb;"><td class="fn-bold">Total active</td><td class="fn-r fn-bold">{{ number_format($data['netCash'] + $data['debt'] + $data['stockValue'], 2, '.', ' ') }}</td></tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="fn-card">
|
||||
<div class="fn-h3">Toate timpurile</div>
|
||||
<table class="fn-tbl">
|
||||
<tr><td>Total încasat</td><td class="fn-r fn-success">{{ number_format($data['allTimePayments'], 2, '.', ' ') }} MDL</td></tr>
|
||||
<tr><td>Total cheltuit</td><td class="fn-r fn-danger">{{ number_format($data['allTimeExpenses'], 2, '.', ' ') }} MDL</td></tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</x-filament-panels::page>
|
||||
@@ -0,0 +1,105 @@
|
||||
<x-filament-panels::page>
|
||||
<style>
|
||||
.rc-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
|
||||
.rc-card { background: #fff; border: 1px solid #e5e7eb; border-radius: 10px; padding: 16px; }
|
||||
.dark .rc-card { background: #1f2937; border-color: #374151; }
|
||||
.rc-h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
|
||||
.rc-count { font-size: 11px; padding: 2px 8px; background: #f3f4f6; border-radius: 999px; color: #6b7280; }
|
||||
.dark .rc-count { background: #374151; }
|
||||
.rc-tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
|
||||
.rc-tbl td { padding: 6px 4px; border-bottom: 1px solid #f3f4f6; }
|
||||
.rc-r { text-align: right; }
|
||||
.rc-empty { color: #9ca3af; text-align: center; padding: 16px 0; font-size: 12px; }
|
||||
</style>
|
||||
|
||||
@php
|
||||
$lost = $this->lostClients();
|
||||
$highMileage = $this->highMileageVehicles();
|
||||
$unpaid = $this->unpaidWO();
|
||||
$vip = $this->vipNeedingTouchup();
|
||||
@endphp
|
||||
|
||||
<div class="rc-grid">
|
||||
<div class="rc-card">
|
||||
<div class="rc-h3">😴 Clienți pierduți <span class="rc-count">{{ $lost->count() }}</span></div>
|
||||
<div style="font-size:11px;color:#6b7280;margin-bottom:12px;">Clienți care n-au mai venit de peste 6 luni — bun moment pentru un mesaj de revenire.</div>
|
||||
<table class="rc-tbl">
|
||||
@forelse ($lost as $c)
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{{ route('filament.tenant.resources.clients.edit', ['record' => $c->id]) }}" style="color:inherit;text-decoration:underline;">{{ $c->name }}</a>
|
||||
<div style="font-size:10px;color:#9ca3af;">{{ $c->phone }}</div>
|
||||
</td>
|
||||
<td class="rc-r" style="color:#9ca3af;font-size:11px;">
|
||||
ultima fișă<br>{{ $c->workOrders->first()?->opened_at?->diffForHumans() ?? '—' }}
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td colspan="2" class="rc-empty">Niciun client pierdut. 🎉</td></tr>
|
||||
@endforelse
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="rc-card">
|
||||
<div class="rc-h3">🚗 Mașini cu kilometraj mare <span class="rc-count">{{ $highMileage->count() }}</span></div>
|
||||
<div style="font-size:11px;color:#6b7280;margin-bottom:12px;">Sugerează revizie / piese de uzură.</div>
|
||||
<table class="rc-tbl">
|
||||
@forelse ($highMileage as $v)
|
||||
<tr>
|
||||
<td>
|
||||
{{ $v->make }} {{ $v->model }} {{ $v->year }}
|
||||
@if ($v->plate) <b>[{{ $v->plate }}]</b> @endif
|
||||
<div style="font-size:10px;color:#9ca3af;">{{ $v->client?->name }}</div>
|
||||
</td>
|
||||
<td class="rc-r" style="font-weight:600;color:#d97706;">
|
||||
{{ number_format($v->mileage, 0, '.', ' ') }} km
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td colspan="2" class="rc-empty">—</td></tr>
|
||||
@endforelse
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="rc-card">
|
||||
<div class="rc-h3">💰 Fișe neplătite <span class="rc-count">{{ $unpaid->count() }}</span></div>
|
||||
<div style="font-size:11px;color:#6b7280;margin-bottom:12px;">Sună-i sau trimite-le un email cu suma datorată.</div>
|
||||
<table class="rc-tbl">
|
||||
@forelse ($unpaid as $w)
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{{ route('filament.tenant.resources.work-orders.edit', ['record' => $w->id]) }}" style="color:inherit;text-decoration:underline;">{{ $w->number }}</a>
|
||||
— {{ $w->client?->name }}
|
||||
<div style="font-size:10px;color:#9ca3af;">{{ $w->vehicle?->make }} {{ $w->vehicle?->model }} {{ $w->vehicle?->plate ? '[' . $w->vehicle->plate . ']' : '' }}</div>
|
||||
</td>
|
||||
<td class="rc-r" style="color:#dc2626;font-weight:600;">
|
||||
{{ number_format(max(0, (float) $w->total - (float) $w->payments->sum('amount')), 2, '.', ' ') }} MDL
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td colspan="2" class="rc-empty">Niciun rest de încasat. 🎉</td></tr>
|
||||
@endforelse
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="rc-card">
|
||||
<div class="rc-h3">⭐ VIP fără contact recent <span class="rc-count">{{ $vip->count() }}</span></div>
|
||||
<div style="font-size:11px;color:#6b7280;margin-bottom:12px;">Clienți VIP cu care nu s-a vorbit de peste 30 zile.</div>
|
||||
<table class="rc-tbl">
|
||||
@forelse ($vip as $c)
|
||||
<tr>
|
||||
<td>
|
||||
{{ $c->name }}
|
||||
<div style="font-size:10px;color:#9ca3af;">{{ $c->phone }}</div>
|
||||
</td>
|
||||
<td class="rc-r" style="color:#9ca3af;font-size:11px;">
|
||||
{{ $c->last_contact_at?->diffForHumans() ?? 'niciodată' }}
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td colspan="2" class="rc-empty">Toți VIP-ii sunt în contact recent.</td></tr>
|
||||
@endforelse
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</x-filament-panels::page>
|
||||
Reference in New Issue
Block a user