This commit is contained in:
Lizandro Guarnizo
2026-01-29 21:15:11 -05:00
parent f183512bc8
commit ba211d21d8
4 changed files with 118 additions and 77 deletions
@@ -10,6 +10,7 @@ class AjustesRelationManager extends RelationManager
{
protected static string $relationship = 'ajustes';
protected static ?string $recordTitleAttribute = 'id';
protected static ?string $title = 'Reprocesos';
public function table(Tables\Table $table): Tables\Table
{
@@ -22,20 +23,35 @@ class AjustesRelationManager extends RelationManager
TextColumn::make('notas')->limit(80)->wrap(),
TextColumn::make('created_at')->label('Fecha')->dateTime(),
])
->filters([])
->filters([
Tables\Filters\SelectFilter::make('tipo')
->options([
'reproceso' => 'Reproceso',
])
->default('reproceso')
])
->modifyQueryUsing(fn ($query) => $query->where('tipo', 'reproceso'))
->headerActions([
Tables\Actions\CreateAction::make()->form([
\Filament\Forms\Components\TextInput::make('cantidad')->numeric()->required()->minValue(1),
\Filament\Forms\Components\Textarea::make('notas'),
])->action(function (array $data) {
$owner = $this->getOwnerRecord();
try {
$owner->registerReproceso((int)$data['cantidad'], $data['notas'] ?? null, auth()->id() ?? null);
\Filament\Notifications\Notification::make()->success()->title('Reproceso registrado')->send();
} catch (\Throwable $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->getMessage())->send();
}
}),
Tables\Actions\CreateAction::make()
->label('Agregar reproceso')
->form([
\Filament\Forms\Components\TextInput::make('cantidad')
->numeric()
->required()
->minValue(1)
->helperText('Prendas que llegaron defectuosas y necesitan reparación'),
\Filament\Forms\Components\Textarea::make('notas'),
])->action(function (array $data) {
$owner = $this->getOwnerRecord();
try {
$owner->registerReproceso((int)$data['cantidad'], $data['notas'] ?? null, auth()->id() ?? null);
\Filament\Notifications\Notification::make()->success()->title('Reproceso registrado')->body('Estas prendas podrán re-recibirse cuando regresen reparadas.')->send();
} catch (\Illuminate\Validation\ValidationException $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->validator->errors()->first())->send();
} catch (\Throwable $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->getMessage())->send();
}
}),
])
->actions([])
->bulkActions([]);
@@ -24,19 +24,31 @@ class CobrosRelationManager extends RelationManager
])
->filters([])
->headerActions([
Tables\Actions\CreateAction::make()->form([
\Filament\Forms\Components\TextInput::make('cantidad')->numeric()->required()->minValue(1),
\Filament\Forms\Components\TextInput::make('valor')->numeric()->required()->minValue(0),
\Filament\Forms\Components\Textarea::make('notas'),
])->action(function (array $data) {
$owner = $this->getOwnerRecord();
try {
$owner->registerCobro((int)$data['cantidad'], (float)$data['valor'], $data['notas'] ?? null, auth()->id() ?? null);
\Filament\Notifications\Notification::make()->success()->title('Cobro registrado')->send();
} catch (\Throwable $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->getMessage())->send();
}
}),
Tables\Actions\CreateAction::make()
->label('Agregar cobro')
->form([
\Filament\Forms\Components\TextInput::make('cantidad')
->numeric()
->required()
->minValue(1)
->helperText('Prendas que NO llegaron y se cobran a la tintorería'),
\Filament\Forms\Components\TextInput::make('valor')
->numeric()
->required()
->minValue(0)
->label('Valor a descontar'),
\Filament\Forms\Components\Textarea::make('notas'),
])->action(function (array $data) {
$owner = $this->getOwnerRecord();
try {
$owner->registerCobro((int)$data['cantidad'], (float)$data['valor'], $data['notas'] ?? null, auth()->id() ?? null);
\Filament\Notifications\Notification::make()->success()->title('Cobro registrado')->send();
} catch (\Illuminate\Validation\ValidationException $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->validator->errors()->first())->send();
} catch (\Throwable $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->getMessage())->send();
}
}),
])
->actions([])
->bulkActions([]);