up
This commit is contained in:
@@ -14,9 +14,10 @@ use Filament\Forms\Components\DatePicker;
|
||||
class OjalResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Ojal::class;
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
protected static ?string $navigationGroup = 'Producción';
|
||||
protected static bool $shouldRegisterNavigation = false; // Ocultar del menú
|
||||
protected static ?string $navigationIcon = 'heroicon-o-scissors';
|
||||
protected static ?string $navigationGroup = 'Gestión';
|
||||
protected static ?string $navigationLabel = 'Ojales';
|
||||
protected static ?int $navigationSort = 4;
|
||||
|
||||
public static function canViewAny(): bool
|
||||
{
|
||||
@@ -26,28 +27,125 @@ class OjalResource extends Resource
|
||||
public static function form(Forms\Form $form): Forms\Form
|
||||
{
|
||||
return $form->schema([
|
||||
Select::make('proveedor_id')->relationship('proveedor', 'nombre', fn(\Illuminate\Database\Eloquent\Builder $q) => $q->where('categoria', 'empleado'))->searchable()->preload()->nullable(),
|
||||
Select::make('orden_produccion_id')->relationship('ordenProduccion', 'numero_orden')->searchable()->preload()->required(),
|
||||
DatePicker::make('fecha_envio')->default(now()),
|
||||
TextInput::make('cantidad_enviada')->numeric()->required()->minValue(1),
|
||||
DatePicker::make('fecha_recepcion'),
|
||||
TextInput::make('cantidad_recibida')->numeric()->nullable(),
|
||||
TextInput::make('perdidas')->numeric()->default(0),
|
||||
Select::make('orden_produccion_id')
|
||||
->label('Orden de Producci\u00f3n')
|
||||
->options(function () {
|
||||
return \App\Models\OrdenProducci\u00f3n::whereHas('confecciones', function ($q) {
|
||||
$q->where('cantidad_recibida', '>', 0);
|
||||
})->get()->mapWithKeys(function ($op) {
|
||||
$cantidadRecibida = $op->confecciones->sum('cantidad_recibida');
|
||||
$arreglos = \App\Models\Ajuste::where('referencia_type', \App\Models\Confeccion::class)
|
||||
->whereHas('referencia', function($q) use ($op) {
|
||||
$q->where('orden_produccion_id', $op->id);
|
||||
})->where('tipo', 'arreglo')->sum('cantidad');
|
||||
$cobros = \App\Models\Cobro::where('referencia_type', \App\Models\Confeccion::class)
|
||||
->whereHas('referencia', function($q) use ($op) {
|
||||
$q->where('orden_produccion_id', $op->id);
|
||||
})->sum('cantidad');
|
||||
$cantidadConfecciones = $cantidadRecibida - $arreglos - $cobros;
|
||||
$cantidadEnOjales = \App\Models\Ojal::where('orden_produccion_id', $op->id)
|
||||
->sum('cantidad_enviada');
|
||||
$saldoDisponible = $cantidadConfecciones - $cantidadEnOjales;
|
||||
if ($saldoDisponible > 0) {
|
||||
return [$op->id => \"{$op->numero_orden} - {$op->referencia} (Disponible: {$saldoDisponible})\"];
|
||||
}
|
||||
return [];
|
||||
})->filter();
|
||||
})
|
||||
->searchable()
|
||||
->required()
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, $set) {
|
||||
if ($state) {
|
||||
$op = \App\Models\OrdenProduccion::find($state);
|
||||
if ($op) {
|
||||
$cantidadRecibida = $op->confecciones->sum('cantidad_recibida');
|
||||
$arreglos = \App\Models\Ajuste::where('referencia_type', \App\Models\Confeccion::class)
|
||||
->whereHas('referencia', function($q) use ($state) {
|
||||
$q->where('orden_produccion_id', $state);
|
||||
})->where('tipo', 'arreglo')->sum('cantidad');
|
||||
$cobros = \App\Models\Cobro::where('referencia_type', \App\Models\Confeccion::class)
|
||||
->whereHas('referencia', function($q) use ($state) {
|
||||
$q->where('orden_produccion_id', $state);
|
||||
})->sum('cantidad');
|
||||
$cantidadConfecciones = $cantidadRecibida - $arreglos - $cobros;
|
||||
$cantidadEnOjales = \App\Models\Ojal::where('orden_produccion_id', $state)->sum('cantidad_enviada');
|
||||
$cantidadDisponible = $cantidadConfecciones - $cantidadEnOjales;
|
||||
$set('cantidad_enviada', max(0, $cantidadDisponible));
|
||||
$set('prenda_nombre_info', $op->prenda_modelo ?? 'Sin especificar');
|
||||
}
|
||||
}
|
||||
})->helperText('Solo se muestran órdenes con prendas disponibles desde Confección'),
|
||||
|
||||
TextInput::make('prenda_nombre_info')
|
||||
->label('Prenda')
|
||||
->disabled()
|
||||
->dehydrated(false)
|
||||
->visible(fn ($get) => $get('orden_produccion_id') !== null),
|
||||
|
||||
Select::make('proveedor_id')
|
||||
->label('Empleado Responsable')
|
||||
->options(fn() => \App\Models\Proveedor::where('categoria', 'empleado')->pluck('nombre', 'id'))
|
||||
->searchable()
|
||||
->preload()
|
||||
->required()
|
||||
->helperText('Selecciona el empleado responsable del proceso'),
|
||||
|
||||
TextInput::make('cantidad_enviada')
|
||||
->label('Cantidad')
|
||||
->numeric()
|
||||
->required()
|
||||
->minValue(1),
|
||||
|
||||
Forms\Components\Checkbox::make('terminada')
|
||||
->label('Marcar como terminado')
|
||||
->helperText('\u2713 Al terminar Ojales, las prendas quedar\u00e1n disponibles para Prensillas')
|
||||
->reactive(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Tables\Table $table): Tables\Table
|
||||
{
|
||||
return $table->columns([
|
||||
Tables\Columns\TextColumn::make('id')->label('#'),
|
||||
Tables\Columns\TextColumn::make('proveedor.nombre')->label('Proveedor'),
|
||||
Tables\Columns\TextColumn::make('ordenProduccion.numero_orden')->label('OP'),
|
||||
Tables\Columns\TextColumn::make('cantidad_enviada'),
|
||||
Tables\Columns\TextColumn::make('cantidad_recibida'),
|
||||
Tables\Columns\TextColumn::make('perdidas'),
|
||||
Tables\Columns\TextColumn::make('fecha_envio')->date(),
|
||||
Tables\Columns\TextColumn::make('fecha_recepcion')->date(),
|
||||
])->defaultSort('created_at', 'desc');
|
||||
Tables\Columns\TextColumn::make('ordenProduccion.numero_orden')
|
||||
->label('OP')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('ordenProduccion.referencia')
|
||||
->label('Referencia')
|
||||
->searchable()
|
||||
->toggleable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('ordenProduccion.prenda_modelo')
|
||||
->label('Prenda')
|
||||
->searchable()
|
||||
->limit(30)
|
||||
->toggleable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('proveedor.nombre')
|
||||
->label('Empleado')
|
||||
->searchable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('cantidad_enviada')
|
||||
->label('Cantidad'),
|
||||
|
||||
Tables\Columns\IconColumn::make('terminada')
|
||||
->label('Terminado')
|
||||
->boolean(),
|
||||
|
||||
Tables\Columns\TextColumn::make('fecha_envio')
|
||||
->date()
|
||||
->sortable(),
|
||||
])
|
||||
->defaultSort('created_at', 'desc')
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('terminada')
|
||||
->options([
|
||||
'1' => 'Terminados',
|
||||
'0' => 'En proceso',
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
|
||||
Reference in New Issue
Block a user