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,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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user