143 lines
6.2 KiB
PHP
143 lines
6.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\PricelistFiles\RelationManagers;
|
|
|
|
use App\Enums\PricelistFileLineStatusEnum;
|
|
use App\Enums\PricelistFileStatusEnum;
|
|
use Filament\Actions\ViewAction;
|
|
use Filament\Forms\Components\KeyValue;
|
|
use Filament\Forms\Components\Placeholder;
|
|
use Filament\Infolists\Components\TextEntry;
|
|
use Filament\Resources\RelationManagers\RelationManager;
|
|
use Filament\Schemas\Components\Grid;
|
|
use Filament\Schemas\Components\Section;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Support\HtmlString;
|
|
|
|
class LinesRelationManager extends RelationManager
|
|
{
|
|
protected static string $relationship = 'lines';
|
|
|
|
protected static ?string $title = 'Feldolgozott sorok';
|
|
|
|
public function form(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->components([
|
|
Grid::make(2)
|
|
->schema([
|
|
TextEntry::make('row_number')
|
|
->label('Sor száma'),
|
|
TextEntry::make('status')
|
|
->label('Státusz')
|
|
->badge()
|
|
->color(fn (PricelistFileLineStatusEnum $state) => $state->color())
|
|
->formatStateUsing(fn (PricelistFileLineStatusEnum $state) => $state->label()),
|
|
]),
|
|
Section::make('Adatok')
|
|
->schema([
|
|
KeyValue::make('payload')
|
|
->label('Excel adatok')
|
|
->columnSpanFull(),
|
|
]),
|
|
Section::make('Validációs üzenetek')
|
|
->schema([
|
|
Placeholder::make('validation_messages_list')
|
|
->label(false)
|
|
->content(fn ($record) => new HtmlString(
|
|
'<ul class="list-disc ml-5">' .
|
|
collect($record->validation_messages ?? [])->map(fn ($msg) => "<li>$msg</li>")->join('') .
|
|
'</ul>'
|
|
)),
|
|
])
|
|
->visible(fn ($record) => !empty($record->validation_messages)),
|
|
]);
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->recordTitleAttribute('id')
|
|
->columns([
|
|
TextColumn::make('row_number')
|
|
->label('#')
|
|
->sortable()
|
|
->width('50px'),
|
|
|
|
TextColumn::make('status')
|
|
->label('Státusz')
|
|
->badge()
|
|
->color(fn (PricelistFileLineStatusEnum $state) => $state->color())
|
|
->formatStateUsing(fn (PricelistFileLineStatusEnum $state) => $state->label())
|
|
->icon(fn (PricelistFileLineStatusEnum $state) => $state->icon())
|
|
->sortable(),
|
|
|
|
TextColumn::make('product_info')
|
|
->label('Termék')
|
|
->description(fn ($record) => $record->payload['Termék megnevezése'] ?? '')
|
|
->getStateUsing(fn ($record) => $record->payload['Szállítói cikkszám'] ?? 'N/A')
|
|
->searchable(query: function ($query, string $search) {
|
|
$query->where('payload->Szállítói cikkszám', 'like', "%{$search}%")
|
|
->orWhere('payload->Termék megnevezése', 'like', "%{$search}%");
|
|
}),
|
|
|
|
TextColumn::make('price_diff')
|
|
->label('Árváltozás')
|
|
->html()
|
|
->getStateUsing(function ($record) {
|
|
$oldPrice = $record->diff['changes']['price']['old'] ?? null;
|
|
$newPrice = $record->payload['Új számlázási nettó ár'] ?? null;
|
|
|
|
if ($oldPrice === null) {
|
|
return number_format((float)$newPrice, 2, ',', ' ') . ' Ft';
|
|
}
|
|
|
|
$diffPercent = (($newPrice / $oldPrice) - 1) * 100;
|
|
$colorClass = $diffPercent > 0 ? 'text-danger-600' : ($diffPercent < 0 ? 'text-success-600' : 'text-gray-600');
|
|
$icon = $diffPercent > 0 ? '↑' : ($diffPercent < 0 ? '↓' : '');
|
|
|
|
return sprintf(
|
|
'<div class="flex flex-col">
|
|
<span class="text-xs text-gray-500 line-through">%s Ft</span>
|
|
<span class="font-bold">%s Ft <span class="%s">%s %s%%</span></span>
|
|
</div>',
|
|
number_format($oldPrice, 2, ',', ' '),
|
|
number_format((float)$newPrice, 2, ',', ' '),
|
|
$colorClass,
|
|
$icon,
|
|
number_format(abs($diffPercent), 1, ',', ' ')
|
|
);
|
|
})
|
|
->visible(fn ($livewire) => $livewire->getOwnerRecord()->status !== PricelistFileStatusEnum::todo),
|
|
|
|
TextColumn::make('validation_messages')
|
|
->label('Megjegyzés')
|
|
->listWithLineBreaks()
|
|
->bulleted()
|
|
->color(fn ($state) => collect($state)->contains(fn ($msg) => str_contains($msg, 'Hiányzó') || str_contains($msg, 'Ismeretlen') || str_contains($msg, 'Érvénytelen')) ? 'danger' : 'info')
|
|
->getStateUsing(fn ($record) => $record->validation_messages ?? []),
|
|
])
|
|
->filters([
|
|
SelectFilter::make('status')
|
|
->label('Státusz')
|
|
->options(collect(PricelistFileLineStatusEnum::cases())->mapWithKeys(fn ($e) => [$e->value => $e->label()])),
|
|
])
|
|
->headerActions([
|
|
//
|
|
])
|
|
->actions([
|
|
ViewAction::make()
|
|
->slideOver(),
|
|
])
|
|
->bulkActions([
|
|
//
|
|
])
|
|
->defaultSort('row_number', 'asc')
|
|
->striped()
|
|
->poll('5s');
|
|
}
|
|
}
|