This commit is contained in:
Lizandro Guarnizo
2026-01-29 23:23:26 -05:00
parent 4ca27a3a81
commit b9fea47770
2 changed files with 22 additions and 2 deletions
+11 -1
View File
@@ -40,7 +40,17 @@ class Ojal extends Model
static::creating(function ($p) {
// Validar disponibilidad desde confecciones
$opId = $p->orden_produccion_id;
$totalProducido = \App\Models\Confeccion::where('orden_produccion_id', $opId)->sum('cantidad_recibida');
$totalRecibido = \App\Models\Confeccion::where('orden_produccion_id', $opId)
->sum(\DB::raw('COALESCE(cantidad_recibida, 0)'));
$totalArreglos = \App\Models\Ajuste::where('ajustable_type', \App\Models\Confeccion::class)
->whereHas('ajustable', function($q) use ($opId) {
$q->where('orden_produccion_id', $opId);
})->where('tipo', 'arreglo')->sum('cantidad');
$totalCobros = \App\Models\Cobro::where('cobreable_type', \App\Models\Confeccion::class)
->whereHas('cobreable', function($q) use ($opId) {
$q->where('orden_produccion_id', $opId);
})->sum('cantidad');
$totalProducido = $totalRecibido - $totalArreglos - $totalCobros;
$yaAsignado = \App\Models\Prensilla::where('orden_produccion_id', $opId)->sum('cantidad_enviada')
+ \App\Models\Ojal::where('orden_produccion_id', $opId)->sum('cantidad_enviada');
+11 -1
View File
@@ -38,7 +38,17 @@ class Prensilla extends Model
static::creating(function ($p) {
// Validar disponibilidad desde confecciones
$opId = $p->orden_produccion_id;
$totalProducido = \App\Models\Confeccion::where('orden_produccion_id', $opId)->sum('cantidad_recibida');
$totalRecibido = \App\Models\Confeccion::where('orden_produccion_id', $opId)
->sum(\DB::raw('COALESCE(cantidad_recibida, 0)'));
$totalArreglos = \App\Models\Ajuste::where('ajustable_type', \App\Models\Confeccion::class)
->whereHas('ajustable', function($q) use ($opId) {
$q->where('orden_produccion_id', $opId);
})->where('tipo', 'arreglo')->sum('cantidad');
$totalCobros = \App\Models\Cobro::where('cobreable_type', \App\Models\Confeccion::class)
->whereHas('cobreable', function($q) use ($opId) {
$q->where('orden_produccion_id', $opId);
})->sum('cantidad');
$totalProducido = $totalRecibido - $totalArreglos - $totalCobros;
$yaAsignado = \App\Models\Prensilla::where('orden_produccion_id', $opId)->sum('cantidad_enviada')
+ \App\Models\Ojal::where('orden_produccion_id', $opId)->sum('cantidad_enviada');