up
This commit is contained in:
@@ -21,6 +21,7 @@ class OjalPresillaResource extends Resource
|
||||
protected static ?string $navigationLabel = 'Ojales y Prensillas';
|
||||
protected static ?string $pluralModelLabel = 'Ojales y Prensillas';
|
||||
protected static ?int $navigationSort = 4;
|
||||
protected static bool $shouldRegisterNavigation = false;
|
||||
|
||||
public static function canViewAny(): bool
|
||||
{
|
||||
|
||||
@@ -5,6 +5,8 @@ namespace App\Filament\Resources\OjalPresillaResource\Pages;
|
||||
use App\Filament\Resources\OjalPresillaResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Filament\Tables;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ListOjalPresillas extends ListRecords
|
||||
{
|
||||
@@ -20,14 +22,19 @@ class ListOjalPresillas extends ListRecords
|
||||
|
||||
protected function getTableQuery(): ?\Illuminate\Database\Eloquent\Builder
|
||||
{
|
||||
// Combinar registros de ojales y prensillas
|
||||
$ojales = \App\Models\Ojal::query()
|
||||
->selectRaw("id, 'ojales' as table_name, proveedor_id, orden_produccion_id, tipo, fecha_envio, cantidad_enviada, fecha_recepcion, cantidad_recibida, terminada, created_at, updated_at");
|
||||
|
||||
$prensillas = \App\Models\Prensilla::query()
|
||||
->selectRaw("id, 'prensillas' as table_name, proveedor_id, orden_produccion_id, tipo, fecha_envio, cantidad_enviada, fecha_recepcion, cantidad_recibida, terminada, created_at, updated_at");
|
||||
|
||||
// Unir ambas queries y ordenar por fecha de creación
|
||||
return $ojales->union($prensillas)->orderByDesc('created_at');
|
||||
// Solo mostrar ojales (los otros recursos muestran prensillas)
|
||||
return \App\Models\Ojal::query();
|
||||
}
|
||||
|
||||
public function getTableRecordUrlUsing(): ?\Closure
|
||||
{
|
||||
return function (Model $record): ?string {
|
||||
// Determinar a qué recurso redirigir según el tipo
|
||||
if ($record instanceof \App\Models\Ojal) {
|
||||
return \App\Filament\Resources\OjalResource::getUrl('edit', ['record' => $record]);
|
||||
} else {
|
||||
return \App\Filament\Resources\PrensillaResource::getUrl('edit', ['record' => $record]);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -14,9 +14,10 @@ use Filament\Forms\Components\DatePicker;
|
||||
class PrensillaResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Prensilla::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 = 'Prensillas';
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
public static function canViewAny(): bool
|
||||
{
|
||||
@@ -26,28 +27,112 @@ class PrensillaResource 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ón')
|
||||
->options(function () {
|
||||
return \App\Models\OrdenProduccion::whereHas('ojales', function ($q) {
|
||||
$q->where('terminada', true);
|
||||
})->get()->mapWithKeys(function ($op) {
|
||||
$ojalesTerminados = \App\Models\Ojal::where('orden_produccion_id', $op->id)
|
||||
->where('terminada', true)
|
||||
->sum('cantidad_enviada');
|
||||
$yaEnviado = \App\Models\Prensilla::where('orden_produccion_id', $op->id)
|
||||
->sum('cantidad_enviada');
|
||||
$disponible = $ojalesTerminados - $yaEnviado;
|
||||
if ($disponible > 0) {
|
||||
return [$op->id => "{$op->numero_orden} - {$op->referencia} (Disponible: {$disponible})"];
|
||||
}
|
||||
return [];
|
||||
})->filter();
|
||||
})
|
||||
->searchable()
|
||||
->required()
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, $set) {
|
||||
if ($state) {
|
||||
$op = \App\Models\OrdenProduccion::find($state);
|
||||
if ($op) {
|
||||
$ojalesTerminados = \App\Models\Ojal::where('orden_produccion_id', $state)
|
||||
->where('terminada', true)
|
||||
->sum('cantidad_enviada');
|
||||
$yaEnviado = \App\Models\Prensilla::where('orden_produccion_id', $state)
|
||||
->sum('cantidad_enviada');
|
||||
$cantidadDisponible = $ojalesTerminados - $yaEnviado;
|
||||
$set('cantidad_enviada', max(0, $cantidadDisponible));
|
||||
$set('prenda_nombre_info', $op->prenda_modelo ?? 'Sin especificar');
|
||||
}
|
||||
}
|
||||
})->helperText('⚠️ Solo se muestran órdenes con Ojales terminados disponibles'),
|
||||
|
||||
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('✓ Al terminar Prensillas, las prendas quedarán disponibles para Tintorería')
|
||||
->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