Files
autocrm/app/Filament/Tenant/Resources/MarkupRuleResource.php
T
Vasyka 95aeecb932 i18n: fix widget heading, translate Select options from model consts, +40 keys
- LowStockTable: rename getHeading → getTableHeading (correct Filament API)
- Global I18n::opts() helper wraps Model::CONST values in __() so
  Select dropdowns show translated status/type/season/etc. labels
- Sed-transform ->options(X::CONST), ->options(array_combine(X::A,X::A)),
  and formatStateUsing(fn($s)=>X::CONST[$s]??$s) → wrap with __()
  (58 options + 10 combines + 7 formatStateUsing across 28 files)
- CalendarBoard: all 7 day names now via __() (was missing 4)
- calendar-board.blade: fix untranslated 'săptămâna curentă', 'capacitate',
  'rata confirmare', 'mediu', 'plin', 'Pod / Zi' / 'Mecanic / Zi'
- +40 RU/EN translations (Client & Auto, Maistru / Mecanic, Programat,
  Sosit, Finalizat, Anulat, Neprezentat, days of week, calendar KPIs)

All 306 tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-07-16 06:42:16 +00:00

149 lines
6.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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';
public static function getNavigationLabel(): string
{
return __('nav.label.Procentaj');
}
public static function getNavigationGroup(): ?string
{
return __('nav.group.Depozit');
}
protected static ?string $modelLabel = null;
public static function getModelLabel(): string
{
return __('regulă');
}
protected static ?string $pluralModelLabel = null;
public static function getPluralModelLabel(): string
{
return __('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(\App\Support\I18n::opts(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(\App\Support\I18n::opts(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'),
];
}
}