This commit is contained in:
Lizandro Guarnizo
2026-01-28 23:38:21 -05:00
parent 861d507536
commit 622b99ecd5
50 changed files with 1646 additions and 19 deletions
@@ -72,6 +72,74 @@ class EditConfeccion extends EditRecord
// Refrescar la página para ver cambios (redirigir explicitando el record para evitar error de ruta)
$this->redirect(route('filament.admin.resources.confeccions.edit', ['record' => $record->id]));
}),
// Arreglos: restar cantidad del total recibido y crear traslado de reparaciones
Actions\Action::make('arreglos')
->label('Arreglos')
->modalHeading('Registrar Arreglo')
->form([
Forms\Components\TextInput::make('cantidad')
->label('Cantidad a arreglar')
->numeric()
->required()
->minValue(1)
->maxValue(fn () => $this->getRecord()->cantidad_recibida ?? 0)
->helperText(fn () => 'Máximo: ' . ($this->getRecord()->cantidad_recibida ?? 0)),
Forms\Components\Textarea::make('notas'),
])
->action(function (array $data): void {
$record = $this->getRecord();
$cantidad = (int) ($data['cantidad'] ?? 0);
try {
$record->registerArreglo($cantidad, $data['notas'] ?? null, auth()->id() ?? null);
\Filament\Notifications\Notification::make()->success()->title('Arreglo registrado')->body('Se registró el arreglo correctamente.')->send();
} catch (\Illuminate\Validation\ValidationException $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->validator->errors()->first() ?? 'Error al registrar arreglo.')->send();
} catch (\Throwable $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->getMessage())->send();
}
$this->redirect(route('filament.admin.resources.confeccions.edit', ['record' => $record->id]));
}),
// Cobros: descontar inventario y descontar valor del total a pagar
Actions\Action::make('cobros')
->label('Cobros')
->modalHeading('Registrar Cobro')
->form([
Forms\Components\TextInput::make('cantidad')
->label('Cantidad')
->numeric()
->required()
->minValue(1),
Forms\Components\TextInput::make('valor')
->label('Valor a descontar')
->numeric()
->required()
->minValue(0),
Forms\Components\Textarea::make('notas'),
])
->action(function (array $data): void {
$record = $this->getRecord();
$cantidad = (int) ($data['cantidad'] ?? 0);
$valor = (float) ($data['valor'] ?? 0);
try {
$record->registerCobro($cantidad, $valor, $data['notas'] ?? null, auth()->id() ?? null);
\Filament\Notifications\Notification::make()->success()->title('Cobro registrado')->body('Se descontó del inventario y se aplicó el descuento al valor a pagar.')->send();
} catch (\Illuminate\Validation\ValidationException $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->validator->errors()->first() ?? 'Error al registrar cobro.')->send();
} catch (\Throwable $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->getMessage())->send();
}
$this->redirect(route('filament.admin.resources.confeccions.edit', ['record' => $record->id]));
}),
];
}
}
@@ -0,0 +1,44 @@
<?php
namespace App\Filament\Resources\ConfeccionResource\RelationManagers;
use Filament\Forms;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
class AjustesRelationManager extends RelationManager
{
protected static string $relationship = 'ajustes';
protected static ?string $recordTitleAttribute = 'id';
public function table(Tables\Table $table): Tables\Table
{
return $table
->columns([
TextColumn::make('id')->label('#'),
TextColumn::make('tipo')->label('Tipo'),
TextColumn::make('cantidad')->label('Cantidad'),
TextColumn::make('usuario.name')->label('Usuario'),
TextColumn::make('notas')->limit(80)->wrap(),
TextColumn::make('created_at')->label('Fecha')->dateTime(),
])
->filters([])
->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->registerArreglo((int)$data['cantidad'], $data['notas'] ?? null, auth()->id() ?? null);
\Filament\Notifications\Notification::make()->success()->title('Arreglo registrado')->send();
} catch (\Throwable $e) {
\Filament\Notifications\Notification::make()->danger()->title('Error')->body($e->getMessage())->send();
}
}),
])
->actions([])
->bulkActions([]);
}
}
@@ -0,0 +1,45 @@
<?php
namespace App\Filament\Resources\ConfeccionResource\RelationManagers;
use Filament\Forms;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
class CobrosRelationManager extends RelationManager
{
protected static string $relationship = 'cobros';
protected static ?string $recordTitleAttribute = 'id';
public function table(Tables\Table $table): Tables\Table
{
return $table
->columns([
TextColumn::make('id')->label('#'),
TextColumn::make('cantidad')->label('Cantidad'),
TextColumn::make('valor')->label('Valor')->money('USD'),
TextColumn::make('usuario.name')->label('Usuario'),
TextColumn::make('notas')->limit(80)->wrap(),
TextColumn::make('created_at')->label('Fecha')->dateTime(),
])
->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();
}
}),
])
->actions([])
->bulkActions([]);
}
}
@@ -31,6 +31,7 @@ class RecepcionesRelationManager extends RelationManager
->helperText(fn () => 'Máximo: ' . ($this->getOwnerRecord()?->faltantes ?? 0)),
TextInput::make('prendas_defectuosas')
->label('Faltantes')
->numeric()
->minValue(0)
->maxValue(fn ($get) => (int) ($get('cantidad') ?? 0))
@@ -47,7 +48,7 @@ class RecepcionesRelationManager extends RelationManager
TextColumn::make('id')->label('#'),
TextColumn::make('fecha_recepcion')->dateTime()->label('Fecha'),
TextColumn::make('cantidad')->label('Cantidad'),
TextColumn::make('prendas_defectuosas')->label('Defectos'),
TextColumn::make('prendas_defectuosas')->label('Faltantes'),
TextColumn::make('usuario.name')->label('Usuario'),
TextColumn::make('notas')->limit(50)->wrap(),
TextColumn::make('created_at')->dateTime()->label('Creado'),