120 lines
3.9 KiB
PHP
120 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\ProcesoAcabadoResource\RelationManagers;
|
|
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\RelationManagers\RelationManager;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Forms\Components\DateTimePicker;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Tables\Actions\DeleteAction;
|
|
use Filament\Tables\Actions\EditAction;
|
|
use Filament\Tables\Actions\CreateAction;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class CobrosRelationManager extends RelationManager
|
|
{
|
|
protected static string $relationship = 'cobros';
|
|
protected static ?string $recordTitleAttribute = 'id';
|
|
protected static ?string $title = 'Cobros por Defectos';
|
|
|
|
public function form(Forms\Form $form): Forms\Form
|
|
{
|
|
return $form->schema([
|
|
TextInput::make('cantidad')
|
|
->label('Cantidad de Prendas')
|
|
->numeric()
|
|
->required()
|
|
->minValue(1)
|
|
->helperText('Cantidad de prendas con defectos que se cobrarán al proveedor'),
|
|
|
|
TextInput::make('valor')
|
|
->label('Valor a Cobrar')
|
|
->numeric()
|
|
->required()
|
|
->minValue(0)
|
|
->prefix('$')
|
|
->helperText('Monto total a descontar al proveedor'),
|
|
|
|
DateTimePicker::make('fecha')
|
|
->label('Fecha del Cobro')
|
|
->required()
|
|
->default(now()),
|
|
|
|
Textarea::make('notas')
|
|
->label('Motivo del Cobro')
|
|
->rows(3)
|
|
->maxLength(65535)
|
|
->helperText('Describe los defectos encontrados'),
|
|
]);
|
|
}
|
|
|
|
public function table(Tables\Table $table): Tables\Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('id')
|
|
->label('#')
|
|
->sortable(),
|
|
|
|
TextColumn::make('cantidad')
|
|
->label('Cantidad')
|
|
->sortable()
|
|
->badge()
|
|
->color('danger'),
|
|
|
|
TextColumn::make('valor')
|
|
->label('Valor')
|
|
->money('COP')
|
|
->sortable(),
|
|
|
|
TextColumn::make('fecha')
|
|
->label('Fecha')
|
|
->dateTime('d/m/Y H:i')
|
|
->sortable(),
|
|
|
|
TextColumn::make('usuario.name')
|
|
->label('Usuario')
|
|
->searchable(),
|
|
|
|
TextColumn::make('notas')
|
|
->label('Motivo')
|
|
->limit(50)
|
|
->wrap()
|
|
->toggleable(),
|
|
|
|
TextColumn::make('created_at')
|
|
->label('Creado')
|
|
->dateTime('d/m/Y H:i')
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
])
|
|
->defaultSort('fecha', 'desc')
|
|
->headerActions([
|
|
CreateAction::make()
|
|
->label('Nuevo Cobro')
|
|
->icon('heroicon-o-minus-circle')
|
|
->mutateFormDataUsing(function (array $data): array {
|
|
$data['user_id'] = Auth::id();
|
|
return $data;
|
|
}),
|
|
])
|
|
->actions([
|
|
EditAction::make(),
|
|
DeleteAction::make(),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
]),
|
|
])
|
|
->emptyStateHeading('Sin cobros registrados')
|
|
->emptyStateDescription('Registra cobros por prendas defectuosas que no pasarán a inventario.')
|
|
->emptyStateIcon('heroicon-o-currency-dollar');
|
|
}
|
|
}
|