Update TintoreriaResource.php
This commit is contained in:
@@ -50,15 +50,25 @@ class TintoreriaResource extends Resource
|
||||
|
||||
Select::make('orden_produccion_id')
|
||||
->label('Orden de Producción')
|
||||
->relationship('ordenProduccion', 'numero_orden')
|
||||
->options(fn () => \App\Models\OrdenProduccion::whereRaw('(
|
||||
select coalesce(sum(cantidad_recibida),0) from confeccions where confeccions.orden_produccion_id = orden_produccions.id
|
||||
) - (
|
||||
select coalesce(sum(cantidad_enviada),0) from tintorerias where tintorerias.orden_produccion_id = orden_produccions.id and tintorerias.fecha_recepcion is null
|
||||
) > 0')->pluck('numero_orden', 'id')->toArray())
|
||||
->searchable()
|
||||
->preload()
|
||||
->reactive()
|
||||
->required()
|
||||
->afterStateUpdated(function ($state, $set) {
|
||||
if ($state) {
|
||||
$sum = \App\Models\Confeccion::where('orden_produccion_id', $state)->sum('cantidad_recibida');
|
||||
$set('cantidad_enviada', $sum ?: 0);
|
||||
$totalRecibido = \App\Models\Confeccion::where('orden_produccion_id', $state)->sum('cantidad_recibida');
|
||||
$enviadasEnTint = \App\Models\Tintoreria::where('orden_produccion_id', $state)
|
||||
->whereNull('fecha_recepcion')
|
||||
->sum('cantidad_enviada');
|
||||
|
||||
$pending = max(0, (int)$totalRecibido - (int)$enviadasEnTint);
|
||||
|
||||
$set('cantidad_enviada', $pending ?: 0);
|
||||
$set('fecha_envio', now()->toDateString());
|
||||
}
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user