This commit is contained in:
lizandrogd
2026-01-19 22:09:14 -05:00
parent 7b017114b5
commit 2e5f0a4dba
4 changed files with 49 additions and 12 deletions
+18 -6
View File
@@ -49,7 +49,11 @@ class ConfeccionResource extends Resource
Select::make('orden_produccion_id') Select::make('orden_produccion_id')
->label('Orden de Producción') ->label('Orden de Producción')
->relationship('ordenProduccion', 'numero_orden') ->options(fn () => \App\Models\OrdenProduccion::whereRaw('(
cantidad_total - (
select coalesce(sum(cantidad_enviada),0) from confeccions where confeccions.orden_produccion_id = orden_produccions.id and confeccions.fecha_recepcion is null
)
) > 0')->pluck('numero_orden', 'id')->toArray())
->searchable() ->searchable()
->preload() ->preload()
->reactive() ->reactive()
@@ -57,10 +61,14 @@ class ConfeccionResource extends Resource
->afterStateUpdated(function ($state, $set) { ->afterStateUpdated(function ($state, $set) {
if ($state) { if ($state) {
$orden = \App\Models\OrdenProduccion::find($state); $orden = \App\Models\OrdenProduccion::find($state);
if ($orden) { $sentInProcess = \App\Models\Confeccion::where('orden_produccion_id', $state)
$set('cantidad_enviada', $orden->cantidad_total); ->whereNull('fecha_recepcion')
$set('fecha_envio', now()->toDateString()); ->sum('cantidad_enviada');
}
$pending = max(0, (int)($orden->cantidad_total ?? 0) - (int)$sentInProcess);
$set('cantidad_enviada', $pending ?: 0);
$set('fecha_envio', now()->toDateString());
} }
}), }),
@@ -159,7 +167,11 @@ class ConfeccionResource extends Resource
->money('COP'), ->money('COP'),
]) ])
->filters([ ->filters([
// Tables\Filters\SelectFilter::make('orden_produccion_id')
->label('Orden de Producción')
->relationship('ordenProduccion', 'numero_orden')
->searchable()
->preload(),
]) ])
->actions([ ->actions([
Tables\Actions\EditAction::make(), Tables\Actions\EditAction::make(),
@@ -166,7 +166,11 @@ class InventarioPrendaResource extends Resource
]), ]),
]) ])
->filters([ ->filters([
// Tables\Filters\SelectFilter::make('orden_produccion_id')
->label('Orden de Producción')
->relationship('ordenProduccion', 'numero_orden')
->searchable()
->preload(),
]) ])
->actions([ ->actions([
Tables\Actions\EditAction::make(), Tables\Actions\EditAction::make(),
@@ -40,15 +40,28 @@ class ProcesoAcabadoResource extends Resource
->schema([ ->schema([
Select::make('orden_produccion_id') Select::make('orden_produccion_id')
->label('Orden de Producción') ->label('Orden de Producción')
->relationship('ordenProduccion', 'numero_orden') ->options(fn () => \App\Models\OrdenProduccion::whereRaw('(
(select coalesce(sum(cantidad_recibida),0) from tintorerias where tintorerias.orden_produccion_id = orden_produccions.id)
- (
select coalesce(sum(cantidad_enviada),0) from proceso_acabados where proceso_acabados.orden_produccion_id = orden_produccions.id and proceso_acabados.fecha_recepcion is null
)
) > 0')->pluck('numero_orden', 'id')->toArray())
->searchable() ->searchable()
->reactive() ->reactive()
->required() ->required()
->afterStateUpdated(function ($state, $set) { ->afterStateUpdated(function ($state, $set) {
if ($state) { if ($state) {
// Sumar lo recibido en Tintorería para esta OP // Sumar lo recibido en Tintorería
$sumTint = \App\Models\Tintoreria::where('orden_produccion_id', $state)->sum('cantidad_recibida'); $sumTint = \App\Models\Tintoreria::where('orden_produccion_id', $state)->sum('cantidad_recibida');
$set('cantidad_enviada', $sumTint ?: 0);
// Restar lo ya enviado a acabados y aún en proceso
$sentInProcess = \App\Models\ProcesoAcabado::where('orden_produccion_id', $state)
->whereNull('fecha_recepcion')
->sum('cantidad_enviada');
$pending = max(0, (int)$sumTint - (int)$sentInProcess);
$set('cantidad_enviada', $pending ?: 0);
$set('fecha_envio', now()->toDateString()); $set('fecha_envio', now()->toDateString());
} }
}), }),
@@ -132,7 +145,11 @@ class ProcesoAcabadoResource extends Resource
]), ]),
]) ])
->filters([ ->filters([
// Tables\Filters\SelectFilter::make('orden_produccion_id')
->label('Orden de Producción')
->relationship('ordenProduccion', 'numero_orden')
->searchable()
->preload(),
]) ])
->actions([ ->actions([
Tables\Actions\EditAction::make(), Tables\Actions\EditAction::make(),
@@ -150,7 +150,11 @@ class TintoreriaResource extends Resource
->date(), ->date(),
]) ])
->filters([ ->filters([
// Tables\Filters\SelectFilter::make('orden_produccion_id')
->label('Orden de Producción')
->relationship('ordenProduccion', 'numero_orden')
->searchable()
->preload(),
]) ])
->actions([ ->actions([
Tables\Actions\EditAction::make(), Tables\Actions\EditAction::make(),